国贸2.0系统推送合同:处理结果异步返回

This commit is contained in:
guojunyun
2025-11-10 11:21:30 +08:00
parent e757aa4904
commit 65d11fdc47
6 changed files with 182 additions and 96 deletions

View File

@@ -9,6 +9,7 @@ import com.zt.plat.module.contractorder.api.dto.order.PurchaseOrderWithDetailsDT
import com.zt.plat.module.contractorder.api.dto.order.SalesOrdDtlDTO;
import com.zt.plat.module.contractorder.api.vo.contract.international.IntContract;
import com.zt.plat.module.contractorder.api.vo.contract.international.IntContractPageReq;
import com.zt.plat.module.contractorder.api.vo.contract.international.IntPushContractReqVO;
import com.zt.plat.module.contractorder.enums.ApiConstants;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -44,7 +45,7 @@ public interface ContractApi {
@PostMapping(PREFIX + "/push")
@Operation(summary = "国贸2.0系统推送合同")
CommonResult<Boolean> push(@Valid @RequestBody IntContract reqVO);
void push(@Valid @RequestBody IntPushContractReqVO pushReqVO);
@GetMapping(PREFIX + "/logistics/list/page")
@Operation(summary = "国贸2.0系统合同分页查询")

View File

@@ -0,0 +1,24 @@
package com.zt.plat.module.contractorder.api.vo.contract.international;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "国贸2.0系统推送合同 Request VO")
@Data
public class IntPushContractReqVO {
@Schema(description = "接口请求号")
private String __requestId_;
@Schema(description = "接口类型")
private String __interfaceType__;
@Schema(description = "操作标志")
private String operateFlag;
@Schema(description = "发送时间 yyyyMMddHHmmss")
private String datetime;
@Schema(description = "单据号")
private String busiBillCode;
@Schema(description = "发送方系统")
private String system;
@Schema(description = "发送数据")
private IntContract data;
}

View File

@@ -0,0 +1,29 @@
package com.zt.plat.module.contractorder.api.vo.contract.international;
import cn.hutool.json.JSONObject;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "国贸2.0系统推送合同 Response VO")
@Data
public class IntPushContractRespVO {
@Schema(description = "接口请求号")
private String __requestId_;
@Schema(description = "接口类型")
private String __interfaceType__;
@Schema(description = "单据号")
private String busiBillCode;
@Schema(description = "返回状态")
private Integer code;
@Schema(description = "返回信息")
private String message;
@Schema(description = "返回时间 yyyyMMddHHmmss")
private String datetime;
@Schema(description = "返回方系统")
private String system;
@Schema(description = "操作标志")
private String operateFlag;
@Schema(description = "返回数据")
private JSONObject data;
}

View File

@@ -11,9 +11,7 @@ import com.zt.plat.module.contractorder.api.dto.contract.ContractRespDTO;
import com.zt.plat.module.contractorder.api.dto.order.PrchOrdDtlDTO;
import com.zt.plat.module.contractorder.api.dto.order.PurchaseOrderWithDetailsDTO;
import com.zt.plat.module.contractorder.api.dto.order.SalesOrdDtlDTO;
import com.zt.plat.module.contractorder.api.vo.contract.international.IntContract;
import com.zt.plat.module.contractorder.api.vo.contract.international.IntContractPageReq;
import com.zt.plat.module.contractorder.api.vo.contract.international.Partner;
import com.zt.plat.module.contractorder.api.vo.contract.international.*;
import com.zt.plat.module.contractorder.controller.admin.purchaseorder.vo.PurchaseOrderDetailsRespVO;
import com.zt.plat.module.contractorder.dal.dataobject.contract.ContractMainDO;
import com.zt.plat.module.contractorder.dal.dataobject.contract.ContractOtherFieldDO;
@@ -33,10 +31,12 @@ import com.zt.plat.module.contractorder.dal.mysql.salesorder.SalesOrderMapper;
import com.zt.plat.module.contractorder.enums.contract.DictEnum;
import com.zt.plat.module.contractorder.service.contract.ContractService;
import com.zt.plat.module.contractorder.service.purchaseorder.PurchaseOrderService;
import com.zt.plat.module.contractorder.util.ShareServiceUtil;
import com.zt.plat.module.erp.controller.admin.erp.vo.ErpContractSaveReqVO;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
@@ -73,6 +73,8 @@ public class ContractApiImpl implements ContractApi {
private ContractOtherFieldMapper contractOtherFieldMapper;
@Resource
private SystemRelativityMapper systemRelativityMapper;
@Autowired
private ShareServiceUtil shareServiceUtil;
@Override
public ContractRespDTO getContractByPaperNumber(String contractPaperNumber) {
@@ -158,16 +160,18 @@ public class ContractApiImpl implements ContractApi {
@Transactional
@Override
public CommonResult<Boolean> push(@RequestBody IntContract reqVO) {
public void push(@RequestBody IntPushContractReqVO pushReqVO) {
log.info("接受到国贸2.0系统推送合同数据:{}", new JSONObject(pushReqVO));
try {
// 合同主信息表映射
ContractMainDO contractMainDO = internationalToMainDO(reqVO);
ContractMainDO contractMainDO = internationalToMainDO(pushReqVO.getData());
// 逻辑处理
// 操作标志 I 新增/更新D 删除
String operateFlag = reqVO.getOperateFlag();
String operateFlag = pushReqVO.getData().getOperateFlag();
// 合同唯一键
String externalId = reqVO.getContractId();
String externalId = pushReqVO.getData().getContractId();
// 系统合同ID
Long contractId = null;
// 查询系统关联合同
@@ -196,13 +200,13 @@ public class ContractApiImpl implements ContractApi {
// 删除动态条款信息
contractOtherFormMapper.delete("CTRT_MAIN_ID", contractId.toString());
contractOtherFieldMapper.delete("CTRT_MAIN_ID", contractId.toString());
return success(true);
pushResult(pushReqVO, 1, null);
} else {
throw exception(CONTRACT_UNKNOWN_OPERATE);
}
// 根据客商信息列表提交多个合同映射到erp
if (reqVO.getPartnerList() == null || reqVO.getPartnerList().isEmpty()) {
if (pushReqVO.getData().getPartnerList() == null || pushReqVO.getData().getPartnerList().isEmpty()) {
throw exception(CONTRACT_PARTNER_NOT_EXISTS);
}
@@ -210,13 +214,13 @@ public class ContractApiImpl implements ContractApi {
String contractPaperNumber = contractMainDO.getContractPaperNumber();
// 合同主信息-合同名称
String contractName = contractMainDO.getContractName();
for (int i = 0; i < reqVO.getPartnerList().size(); i++) {
Partner partner = reqVO.getPartnerList().get(i);
for (int i = 0; i < pushReqVO.getData().getPartnerList().size(); i++) {
Partner partner = pushReqVO.getData().getPartnerList().get(i);
// 根据客商信息设置合同信息
// 合同编号
contractMainDO.setContractPaperNumber(contractPaperNumber + "_" + String.format("%03d", (i+1)));
reqVO.getPartnerList().get(i)
pushReqVO.getData().getPartnerList().get(i)
.setErpContractPaperNumber(contractPaperNumber + "_" + String.format("%03d", (i+1)));
// 合同名称
contractMainDO.setContractName(contractName + "_" + String.format("%03d", (i+1)));
@@ -249,9 +253,12 @@ public class ContractApiImpl implements ContractApi {
contractOtherFieldMapper.delete("CTRT_MAIN_ID", contractId.toString());
// 请求参数保存到动态条款
saveIntContractFields(reqVO, contractId);
saveIntContractFields(pushReqVO.getData(), contractId);
return success(true);
pushResult(pushReqVO, 1, null);
} catch (Exception e) {
pushResult(pushReqVO, -1, e.getMessage());
}
}
/**
@@ -365,6 +372,32 @@ public class ContractApiImpl implements ContractApi {
}
}
private void pushResult(IntPushContractReqVO pushReqVO, Integer code, String msg) {
// 返回数据
IntPushContractRespVO body = new IntPushContractRespVO();
body.set__requestId_(pushReqVO.get__requestId_());
body.set__interfaceType__(pushReqVO.get__interfaceType__());
body.setBusiBillCode(pushReqVO.getBusiBillCode());
body.setCode(code);
body.setMessage(String.format("推送合同[%s]%s", pushReqVO.getData().getContractCode(), code >= 0 ? "成功" : "失败:" + msg));
body.setDatetime(DateTimeFormatter.ofPattern("yyyyMMddHHmmss").format(LocalDateTime.now()));
body.setSystem("JYGK");
body.setOperateFlag(pushReqVO.getOperateFlag());
// 回调参数
JSONObject req = new JSONObject();
req.set("messageKey", pushReqVO.getBusiBillCode());
req.set("messageBody", body.toString());
try {
log.info("国贸2.0系统推送合同回调参数:{}",req);
String res = shareServiceUtil.callShareService("S_EPLAT_04", req.toString());
log.info("国贸2.0系统推送合同回调成功:{}",res);
} catch (Exception e) {
log.error("国贸2.0系统推送合同回调失败:{}",e.getMessage(), e);
}
}
@Override
public CommonResult<PageResult<IntContract>> logisticsListPage(IntContractPageReq pageReq) {

View File

@@ -9,6 +9,7 @@ import com.zt.plat.module.contractorder.api.ContractApi;
import com.zt.plat.module.contractorder.api.vo.contract.*;
import com.zt.plat.module.contractorder.api.vo.contract.international.IntContract;
import com.zt.plat.module.contractorder.api.vo.contract.international.IntContractPageReq;
import com.zt.plat.module.contractorder.api.vo.contract.international.IntPushContractReqVO;
import com.zt.plat.module.contractorder.dal.dataobject.contract.ContractMainDO;
import com.zt.plat.module.contractorder.service.contract.ContractService;
import io.swagger.v3.oas.annotations.Operation;
@@ -195,14 +196,14 @@ public class ContractController implements BusinessControllerMarker {
@PostMapping("/push")
@Operation(summary = "国贸2.0系统推送合同")
@PreAuthorize("@ss.hasPermission('base:contract:create')")
CommonResult<Boolean> push(@Valid @RequestBody IntContract reqVO) {
return contractApi.push(reqVO);
public void push(@Valid @RequestBody IntPushContractReqVO pushReqVO) {
contractApi.push(pushReqVO);
}
@PostMapping("/logistics/list/page")
@Operation(summary = "国贸2.0系统合同分页查询")
@PreAuthorize("@ss.hasPermission('base:contract:query')")
CommonResult<PageResult<IntContract>> logisticsListPage(IntContractPageReq pageReq) {
public CommonResult<PageResult<IntContract>> logisticsListPage(IntContractPageReq pageReq) {
return contractApi.logisticsListPage(pageReq);
}
}

View File

@@ -14,8 +14,6 @@ import org.springframework.web.client.RestTemplate;
/**
* ePlat共享服务调用工具类
* @author ChenZhaoxue
* @date 2025/3/27
*/
@Slf4j
@Configuration
@@ -43,7 +41,7 @@ public class ShareServiceUtil {
* ePlat共享服务调用
* @param serviceNo 服务号
* @param request 请求json字符串
* @return
* @return 调用结果
*/
public String callShareService(String serviceNo, String request) {
String url = String.format("%s/service/%s", urlPrex, serviceNo);