封装erp接口
This commit is contained in:
@@ -23,7 +23,6 @@ public class ErpSubmitReqDTO {
|
|||||||
* "sign": 签名,uuid+srcsys+密码,MD5 32位小写签名,密码另行约定
|
* "sign": 签名,uuid+srcsys+密码,MD5 32位小写签名,密码另行约定
|
||||||
* "req": {具体参数,参见RFC功能列表}
|
* "req": {具体参数,参见RFC功能列表}
|
||||||
*/
|
*/
|
||||||
private String uuid;
|
|
||||||
private String srcsys;
|
private String srcsys;
|
||||||
private String funcnr;
|
private String funcnr;
|
||||||
private String bskey;
|
private String bskey;
|
||||||
|
|||||||
@@ -85,40 +85,42 @@ public class ErpConfig {
|
|||||||
/**
|
/**
|
||||||
* 调用ERP接口更新erp数据
|
* 调用ERP接口更新erp数据
|
||||||
*/
|
*/
|
||||||
public ResponseEntity<String> pushDataToErp(ErpSubmitReqDTO reqDTO) {
|
public ResponseEntity<String> pushDataToErp(ErpSubmitReqDTO reqDTO) {
|
||||||
try {
|
try {
|
||||||
// 构建完整URL
|
// 构建完整URL
|
||||||
String url = "http://" + erpAddress + "/api/rfc/post";
|
String url = "http://" + erpAddress + "/api/rfc/post";
|
||||||
// 构建请求参数
|
// 构建请求参数
|
||||||
JSONObject requestBody = new JSONObject();
|
JSONObject requestBody = new JSONObject();
|
||||||
requestBody.put("uuid", reqDTO.getUuid());
|
requestBody.put("uuid", UUID.randomUUID().toString());
|
||||||
requestBody.put("sapsys", sapsys);
|
requestBody.put("sapsys", sapsys);
|
||||||
requestBody.put("srcsys", reqDTO.getSrcsys());
|
requestBody.put("srcsys", reqDTO.getSrcsys());
|
||||||
requestBody.put("funcnr", reqDTO.getFuncnr());
|
requestBody.put("funcnr", reqDTO.getFuncnr());
|
||||||
requestBody.put("bskey", reqDTO.getBskey());
|
requestBody.put("bskey", reqDTO.getBskey());
|
||||||
requestBody.put("usrid", reqDTO.getUsrid());
|
requestBody.put("usrid", reqDTO.getUsrid());
|
||||||
requestBody.put("usrnm", reqDTO.getUsrnm());
|
requestBody.put("usrnm", reqDTO.getUsrnm());
|
||||||
|
if (reqDTO.getSign() != null){
|
||||||
requestBody.put("sign", reqDTO.getSign());
|
requestBody.put("sign", reqDTO.getSign());
|
||||||
if (reqDTO.getReq() != null) {
|
|
||||||
requestBody.put("req", reqDTO.getReq());
|
|
||||||
}
|
|
||||||
// 设置请求头
|
|
||||||
HttpHeaders headers = new HttpHeaders();
|
|
||||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
|
||||||
|
|
||||||
// 创建HTTP请求实体
|
|
||||||
HttpEntity<String> requestEntity = new HttpEntity<>(requestBody.toJSONString(), headers);
|
|
||||||
|
|
||||||
// 发送POST请求
|
|
||||||
RestTemplate restTemplate = new RestTemplate();
|
|
||||||
ResponseEntity<String> response = restTemplate.postForEntity(url, requestEntity, String.class);
|
|
||||||
|
|
||||||
return response;
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("调用ERP RFC接口失败: {}", e);
|
|
||||||
return ResponseEntity.status(500).body("调用ERP接口失败: " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
if (reqDTO.getReq() != null) {
|
||||||
|
requestBody.put("req", reqDTO.getReq());
|
||||||
|
}
|
||||||
|
// 设置请求头
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
|
||||||
|
// 创建HTTP请求实体
|
||||||
|
HttpEntity<String> requestEntity = new HttpEntity<>(requestBody.toJSONString(), headers);
|
||||||
|
|
||||||
|
// 发送POST请求
|
||||||
|
RestTemplate restTemplate = new RestTemplate();
|
||||||
|
ResponseEntity<String> response = restTemplate.postForEntity(url, requestEntity, String.class);
|
||||||
|
|
||||||
|
return response;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("调用ERP RFC接口失败:"+e.getMessage(), e);
|
||||||
|
return ResponseEntity.status(500).body("调用ERP接口失败: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//list
|
//list
|
||||||
public Map<String, List<String>> numbers(JSONArray dataArray, String key, String dataKey) {
|
public Map<String, List<String>> numbers(JSONArray dataArray, String key, String dataKey) {
|
||||||
|
|||||||
@@ -103,9 +103,17 @@ public class ErpBomController {
|
|||||||
|
|
||||||
@PostMapping("/getErpBomTask")
|
@PostMapping("/getErpBomTask")
|
||||||
@Operation(summary = "定时获得erp更新物料清单(BOM)")
|
@Operation(summary = "定时获得erp更新物料清单(BOM)")
|
||||||
@PreAuthorize("@ss.hasPermission('sply:erp-bom:query')")
|
@PreAuthorize("@ss.hasPermission('sply:erp-bom:create')")
|
||||||
public void getErpBomTask() {
|
public void getErpBomTask() {
|
||||||
erpBomService.callErpRfcInterface();
|
erpBomService.callErpRfcInterface();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/submitDataToErp")
|
||||||
|
@Operation(summary = "推送")
|
||||||
|
@PreAuthorize("@ss.hasPermission('sply:erp-bom:create')")
|
||||||
|
public void submitDataToErp() {
|
||||||
|
erpBomService.submitDataToErp();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -103,7 +103,7 @@ public class ErpCompanyController {
|
|||||||
|
|
||||||
@PostMapping("/getErpCompanyTask")
|
@PostMapping("/getErpCompanyTask")
|
||||||
@Operation(summary = "定时获得erp更新公司")
|
@Operation(summary = "定时获得erp更新公司")
|
||||||
@PreAuthorize("@ss.hasPermission('sply:erp-company:query')")
|
@PreAuthorize("@ss.hasPermission('sply:erp-company:create')")
|
||||||
public void getErpCompanyTask() {
|
public void getErpCompanyTask() {
|
||||||
erpCompanyService.callErpRfcInterface();
|
erpCompanyService.callErpRfcInterface();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ public class ErpContractController {
|
|||||||
|
|
||||||
@PostMapping("/getErpContractTask")
|
@PostMapping("/getErpContractTask")
|
||||||
@Operation(summary = "定时获得erp更新合同")
|
@Operation(summary = "定时获得erp更新合同")
|
||||||
@PreAuthorize("@ss.hasPermission('sply:erp-contract:query')")
|
@PreAuthorize("@ss.hasPermission('sply:erp-contract:create')")
|
||||||
public void getErpContractTask() {
|
public void getErpContractTask() {
|
||||||
erpContractService.callErpRfcInterface();
|
erpContractService.callErpRfcInterface();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ public class ErpCostcenterController {
|
|||||||
|
|
||||||
@PostMapping("/getErpCostcenterTask")
|
@PostMapping("/getErpCostcenterTask")
|
||||||
@Operation(summary = "定时获得erp更新成本中心")
|
@Operation(summary = "定时获得erp更新成本中心")
|
||||||
@PreAuthorize("@ss.hasPermission('sply:erp-costcenter:query')")
|
@PreAuthorize("@ss.hasPermission('sply:erp-costcenter:create')")
|
||||||
public void getErpCostcenterTask() {
|
public void getErpCostcenterTask() {
|
||||||
erpCostcenterService.callErpRfcInterface();
|
erpCostcenterService.callErpRfcInterface();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,4 +62,6 @@ public interface ErpBomService {
|
|||||||
PageResult<ErpBomDO> getErpBomPage(ErpBomPageReqVO pageReqVO);
|
PageResult<ErpBomDO> getErpBomPage(ErpBomPageReqVO pageReqVO);
|
||||||
|
|
||||||
void callErpRfcInterface();
|
void callErpRfcInterface();
|
||||||
|
|
||||||
|
void submitDataToErp();
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,8 @@ package com.zt.plat.module.erp.service.erp;
|
|||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import com.zt.plat.framework.common.pojo.PageResult;
|
import com.zt.plat.framework.common.pojo.PageResult;
|
||||||
import com.zt.plat.framework.common.util.object.BeanUtils;
|
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.conf.ErpConfig;
|
||||||
import com.zt.plat.module.erp.common.enums.OftenEnum;
|
import com.zt.plat.module.erp.common.enums.OftenEnum;
|
||||||
import com.zt.plat.module.erp.controller.admin.erp.vo.ErpBomPageReqVO;
|
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.alibaba.fastjson.JSONObject;
|
||||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static com.zt.plat.module.erp.enums.ErrorCodeConstants.ERP_BOM_NOT_EXISTS;
|
import static com.zt.plat.module.erp.enums.ErrorCodeConstants.ERP_BOM_NOT_EXISTS;
|
||||||
@@ -44,6 +45,9 @@ public class ErpBomServiceImpl implements ErpBomService {
|
|||||||
@Resource
|
@Resource
|
||||||
private ErpConfig erpConfig;
|
private ErpConfig erpConfig;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
public ErpExternalApi erpExternalApi;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ErpBomRespVO createErpBom(ErpBomSaveReqVO createReqVO) {
|
public ErpBomRespVO createErpBom(ErpBomSaveReqVO createReqVO) {
|
||||||
// 插入
|
// 插入
|
||||||
@@ -226,4 +230,53 @@ public class ErpBomServiceImpl implements ErpBomService {
|
|||||||
this.allnumbers = allnumbers;
|
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数据提交成功");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user