You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sdny-jxpt/dxhy-extend/src/main/java/com/dxhy/extend/controller/VouncherSyncController.java

108 lines
3.9 KiB

package com.dxhy.extend.controller;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import com.alibaba.druid.support.json.JSONUtils;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.common.http.HttpUtils;
import com.dxhy.common.constant.CommonConstants;
import com.dxhy.common.utils.R;
import com.dxhy.extend.model.SNSAPObject;
import com.dxhy.extend.service.bb.VouncherSyncService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.annotation.Resource;
import java.util.*;
/**
* @Author wangzhikun
* @Date 2023/3/30 2023/3/30
*/
@Controller
@RequestMapping("vouncherSync")
@Slf4j
public class VouncherSyncController {
@Resource
private VouncherSyncService vouncherSyncService;
@PostMapping("getSapData")
public Object getSapData(@RequestBody Map<String,String> map){
//是否全量 X为全量推送,空为增量推送。
//全量推送逻辑为 查询出的符合条件的凭证全部推送,全量推送不再检查是否在自定义表中已传输。
//增量推送,已传输的凭证数据不再推送(检查传输记录表是否已传输成功)
try{
String companyCode = map.get("companyCode");
String[] split = companyCode.split(",");
StringBuilder sb = new StringBuilder();
for (String str:split){
/**
* 传参逻辑 年 月 必传 期间只能传一个月的
*
*/
String ifAll=map.get("ifAll");
//公司代码
//开始日期
String startTime= map.get("startTime");
String endTime = map.get("endTime");
if(startTime!=null && startTime!=""){
startTime=startTime.replace("-","");
}
if(endTime!=null && endTime!=""){
endTime=endTime.replace("-","");
}
//结束日期
String month=map.get("monat");
//GJAHR nian
String gjahr=map.get("gjahr");
SNSAPObject object = new SNSAPObject();
object.setSYSID("FPXT");
object.setIFYWID("FI842");
object.setBSKEY(UUID.randomUUID().toString().replace("-", ""));
//object.setSAPKEY("");
// object.setZFILED1("");
// object.setZFILED2("");
// object.setZFILED3("");
// object.setZFILED4("");
object.setZFILED5("200");
Map<String,String> requestMap = new HashMap<>();
List<Object> list = new ArrayList<>();
requestMap.put("ZGSDM",companyCode);
requestMap.put("GJAHR",gjahr);
requestMap.put("MONAT",month);
requestMap.put("ZDATEF",startTime);
requestMap.put("ZDATET",endTime);
requestMap.put("ZFLAG",ifAll);
object.setZDATA(JSONObject.toJSONString(requestMap));
JSONObject request = new JSONObject();
request.put("IS_INPUT",object);
String s = vouncherSyncService.sendPo(JSONObject.toJSONString(request));
Map map1 = JSONObject.parseObject(s, Map.class);
Map output = (Map)map1.get("ES_OUTPUT");
String ztype =(String) output.get("ZTYPE");
if(ztype.equals("S")){
}else {
sb.append(str+output.get("ZDATA"));
}
}
if(sb.length()>0){
return ResponseEntity.ok(R.ok().put("data",sb));
}else{
return ResponseEntity.ok(R.ok().put("data","拉取成功"));
}
}catch (Exception e ){
e.printStackTrace();
return ResponseEntity.ok(R.error(CommonConstants.MSG_ERR_DEFAULT));
}
}
}