封装erp接口

This commit is contained in:
liss
2025-09-23 16:38:37 +08:00
parent 204e2ea510
commit b998dade75
8 changed files with 104 additions and 40 deletions

View File

@@ -23,7 +23,6 @@ public class ErpSubmitReqDTO {
* "sign": 签名uuid+srcsys+密码MD5 32位小写签名密码另行约定
* "req": {具体参数参见RFC功能列表}
*/
private String uuid;
private String srcsys;
private String funcnr;
private String bskey;

View File

@@ -85,20 +85,22 @@ public class ErpConfig {
/**
* 调用ERP接口更新erp数据
*/
public ResponseEntity<String> pushDataToErp(ErpSubmitReqDTO reqDTO) {
public ResponseEntity<String> pushDataToErp(ErpSubmitReqDTO reqDTO) {
try {
// 构建完整URL
String url = "http://" + erpAddress + "/api/rfc/post";
// 构建请求参数
JSONObject requestBody = new JSONObject();
requestBody.put("uuid", reqDTO.getUuid());
requestBody.put("uuid", UUID.randomUUID().toString());
requestBody.put("sapsys", sapsys);
requestBody.put("srcsys", reqDTO.getSrcsys());
requestBody.put("funcnr", reqDTO.getFuncnr());
requestBody.put("bskey", reqDTO.getBskey());
requestBody.put("usrid", reqDTO.getUsrid());
requestBody.put("usrnm", reqDTO.getUsrnm());
if (reqDTO.getSign() != null){
requestBody.put("sign", reqDTO.getSign());
}
if (reqDTO.getReq() != null) {
requestBody.put("req", reqDTO.getReq());
}
@@ -115,10 +117,10 @@ public class ErpConfig {
return response;
} catch (Exception e) {
log.error("调用ERP RFC接口失败: {}", e);
log.error("调用ERP RFC接口失败:"+e.getMessage(), e);
return ResponseEntity.status(500).body("调用ERP接口失败: " + e.getMessage());
}
}
}
//list
public Map<String, List<String>> numbers(JSONArray dataArray, String key, String dataKey) {

View File

@@ -103,9 +103,17 @@ public class ErpBomController {
@PostMapping("/getErpBomTask")
@Operation(summary = "定时获得erp更新物料清单(BOM)")
@PreAuthorize("@ss.hasPermission('sply:erp-bom:query')")
@PreAuthorize("@ss.hasPermission('sply:erp-bom:create')")
public void getErpBomTask() {
erpBomService.callErpRfcInterface();
}
@PostMapping("/submitDataToErp")
@Operation(summary = "推送")
@PreAuthorize("@ss.hasPermission('sply:erp-bom:create')")
public void submitDataToErp() {
erpBomService.submitDataToErp();
}
}

View File

@@ -103,7 +103,7 @@ public class ErpCompanyController {
@PostMapping("/getErpCompanyTask")
@Operation(summary = "定时获得erp更新公司")
@PreAuthorize("@ss.hasPermission('sply:erp-company:query')")
@PreAuthorize("@ss.hasPermission('sply:erp-company:create')")
public void getErpCompanyTask() {
erpCompanyService.callErpRfcInterface();
}

View File

@@ -103,7 +103,7 @@ public class ErpContractController {
@PostMapping("/getErpContractTask")
@Operation(summary = "定时获得erp更新合同")
@PreAuthorize("@ss.hasPermission('sply:erp-contract:query')")
@PreAuthorize("@ss.hasPermission('sply:erp-contract:create')")
public void getErpContractTask() {
erpContractService.callErpRfcInterface();
}

View File

@@ -103,7 +103,7 @@ public class ErpCostcenterController {
@PostMapping("/getErpCostcenterTask")
@Operation(summary = "定时获得erp更新成本中心")
@PreAuthorize("@ss.hasPermission('sply:erp-costcenter:query')")
@PreAuthorize("@ss.hasPermission('sply:erp-costcenter:create')")
public void getErpCostcenterTask() {
erpCostcenterService.callErpRfcInterface();
}

View File

@@ -62,4 +62,6 @@ public interface ErpBomService {
PageResult<ErpBomDO> getErpBomPage(ErpBomPageReqVO pageReqVO);
void callErpRfcInterface();
void submitDataToErp();
}

View File

@@ -3,6 +3,8 @@ package com.zt.plat.module.erp.service.erp;
import cn.hutool.core.collection.CollUtil;
import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.common.util.object.BeanUtils;
import com.zt.plat.module.erp.api.ErpExternalApi;
import com.zt.plat.module.erp.api.dto.ErpSubmitReqDTO;
import com.zt.plat.module.erp.common.conf.ErpConfig;
import com.zt.plat.module.erp.common.enums.OftenEnum;
import com.zt.plat.module.erp.controller.admin.erp.vo.ErpBomPageReqVO;
@@ -16,14 +18,13 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xxl.job.core.handler.annotation.XxlJob;
import jakarta.annotation.Resource;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.zt.plat.module.erp.enums.ErrorCodeConstants.ERP_BOM_NOT_EXISTS;
@@ -44,6 +45,9 @@ public class ErpBomServiceImpl implements ErpBomService {
@Resource
private ErpConfig erpConfig;
@Resource
public ErpExternalApi erpExternalApi;
@Override
public ErpBomRespVO createErpBom(ErpBomSaveReqVO createReqVO) {
// 插入
@@ -226,4 +230,53 @@ public class ErpBomServiceImpl implements ErpBomService {
this.allnumbers = allnumbers;
}
}
@Override
public void submitDataToErp() {
ErpSubmitReqDTO reqDTO = new ErpSubmitReqDTO();
reqDTO.setSrcsys("MOM");
reqDTO.setFuncnr("061");
reqDTO.setBskey("POTEST011");
reqDTO.setUsrid("cuibin");
reqDTO.setUsrnm("崔斌");
Map<String, Object> req = new HashMap<>();
Map<String, String> exte = new HashMap<>();
exte.put("zzhth", "成品采购合同0406-1-xt");
req.put("exte", exte);
Map<String, Object> head = new HashMap<>();
head.put("pur_group", "120");
head.put("purch_org", "3017");
head.put("comp_code", "3017");
head.put("vendor", "0000003162");
head.put("doc_date", "20230406");
head.put("currency", "CNY");
head.put("exch_rate", 1.00000000);
head.put("doc_type", "PO01");
head.put("zzhth", "成品采购合同0406-1-xt");
req.put("head", head);
List<Map<String, Object>> items = new ArrayList<>();
Map<String, Object> item = new HashMap<>();
item.put("material", "000000000000226986");
item.put("net_price", 40000.00);
item.put("plant", "3026");
item.put("po_item", 1);
item.put("po_unit", "TON");
item.put("price_unit", 1);
item.put("quantity", 2000.000);
item.put("stge_loc", "4011");
item.put("tax_code", "J0");
item.put("unlimited_dlv", "X");
items.add(item);
req.put("item", items);
reqDTO.setReq(req);
ResponseEntity<String> response = erpExternalApi.submitDataToErp(reqDTO);
if (response.getStatusCode() == HttpStatus.OK){
log.info("ERP数据提交成功");
}
}
}