拉取sap凭证数据请求接口开发

release
wangzhikun 2 years ago
parent ac4ff77bec
commit 5c2ab865c7
  1. 106
      dxhy-extend/src/main/java/com/dxhy/extend/controller/VouncherSyncController.java
  2. 76
      dxhy-extend/src/main/java/com/dxhy/extend/model/SNSAPObject.java
  3. 9
      dxhy-extend/src/main/java/com/dxhy/extend/service/bb/VouncherSyncService.java
  4. 36
      dxhy-extend/src/main/java/com/dxhy/extend/service/bb/impl/VouncherSyncServiceImpl.java

@ -0,0 +1,106 @@
package com.dxhy.extend.controller;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
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.HashMap;
import java.util.Map;
import java.util.UUID;
/**
* @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为全量推送,空为增量推送。
//全量推送逻辑为 查询出的符合条件的凭证全部推送,全量推送不再检查是否在自定义表中已传输。
//增量推送,已传输的凭证数据不再推送(检查传输记录表是否已传输成功)
String ifAll=map.get("ifAll");
//公司代码
String companyCode = map.get("companyCode");
//开始日期
String startTime= map.get("startTime");
//结束日期
String month=map.get("endTime");
SNSAPObject object = new SNSAPObject();
object.setSYSID("FPXT");
object.setIFYWID("FI845");
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<>();
requestMap.put("ZGSDM",companyCode);
requestMap.put("GJAHR","");
requestMap.put("MONAT",month);
requestMap.put("ZDATEF",startTime);
requestMap.put("ZFLAG",ifAll);
object.setZDATA(requestMap);
JSONObject request = new JSONObject();
request.put("IS_INPUT",object);
try{
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")){
return ResponseEntity.ok(R.ok().put("data","数据拉取成功"));
}else {
return ResponseEntity.ok(R.error(CommonConstants.MSG_ERR_DEFAULT));
}
}catch (Exception e ){
e.printStackTrace();
return ResponseEntity.ok(R.error(CommonConstants.MSG_ERR_DEFAULT));
}
}
public static void main(String[] args) {
SNSAPObject object = new SNSAPObject();
object.setSYSID("FPXT");
object.setIFYWID("FI845");
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<>();
requestMap.put("ZGSDM","123");
requestMap.put("GJAHR","");
requestMap.put("MONAT","");
requestMap.put("ZDATEF","2023");
requestMap.put("ZFLAG","X");
object.setZDATA(requestMap);
JSONObject request = new JSONObject();
request.put("IS_INPUT",object);
System.out.println(JSONObject.toJSONString(request));
}
}

@ -0,0 +1,76 @@
package com.dxhy.extend.model;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
@Data
public class SNSAPObject {
/**
* 外围系统标识
*/
@JSONField(name = "SYSID")
private String SYSID;
/**
* 接口业务ID
*/
@JSONField(name = "IFYWID")
private String IFYWID;
/**
* 外围系统数据唯一标识
*/
@JSONField(name = "BSKEY")
private String BSKEY;
/**
* SAP数据唯一标识
*/
@JSONField(name = "SAPKEY")
private String SAPKEY;
/**
* 组织机构代码
*/
@JSONField(name = "ZORG")
private String ZORG;
/**
* SAP模块编码OA用
*/
@JSONField(name = "ZFILED1")
private String ZFILED1;
/**
* 预留字段
*/
@JSONField(name = "ZFILED2")
private String ZFILED2;
/**
* 预留字段
*/
@JSONField(name = "ZFILED3")
private String ZFILED3;
/**
* 预留字段
*/
@JSONField(name = "ZFILED4")
private String ZFILED4;
/**
* SAP Client
*/
@JSONField(name = "ZFILED5")
private String ZFILED5;
/**
* 外围系统标识
*/
@JSONField(name = "ZDATA")
private Object ZDATA;
}

@ -0,0 +1,9 @@
package com.dxhy.extend.service.bb;
/**
* @Author wangzhikun
* @Date 2023/3/30 2023/3/30
*/
public interface VouncherSyncService {
String sendPo(String toJSONString);
}

@ -0,0 +1,36 @@
package com.dxhy.extend.service.bb.impl;
import cn.hutool.http.HttpRequest;
import com.dxhy.extend.service.bb.VouncherSyncService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
/**
* @Author wangzhikun
* @Date 2023/3/30 2023/3/30
*/
@Service
@Slf4j
public class VouncherSyncServiceImpl implements VouncherSyncService {
@Value("${sdny.snYxUrl}")
private String url;
@Value("${po.userName}")
private String userName;
@Value("${po.password}")
private String password;
@Override
public String sendPo(String request) {
long startTime = System.currentTimeMillis();
log.info("请求同步凭证号数据{}",request);
HttpRequest httpRequest = new HttpRequest(url);
httpRequest.basicAuth(userName,password);
String body = httpRequest.body(request).timeout(300000).execute().body();
long endTime = System.currentTimeMillis();
log.debug("以字符串调用post请求url:{},耗时:{},返回参数{}", url, endTime - startTime,body);
return body;
}
}
Loading…
Cancel
Save