From 3e0b0cab05ae8365b085c6f7faed4b71790b5246 Mon Sep 17 00:00:00 2001 From: guojunyun Date: Fri, 31 Oct 2025 15:21:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BD=E8=B4=B82.0=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E6=8E=A8=E9=80=81=E5=90=88=E5=90=8C=EF=BC=9A=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/contractorder/api/ContractApi.java | 2 +- .../enums/contract/DictEnum.java | 3 + .../contractorder/api/ContractApiImpl.java | 254 ++++++++---------- .../admin/contract/ContractController.java | 7 +- 4 files changed, 120 insertions(+), 146 deletions(-) diff --git a/zt-module-contract-order/zt-module-contract-order-api/src/main/java/com/zt/plat/module/contractorder/api/ContractApi.java b/zt-module-contract-order/zt-module-contract-order-api/src/main/java/com/zt/plat/module/contractorder/api/ContractApi.java index cbb52ad..097b75a 100644 --- a/zt-module-contract-order/zt-module-contract-order-api/src/main/java/com/zt/plat/module/contractorder/api/ContractApi.java +++ b/zt-module-contract-order/zt-module-contract-order-api/src/main/java/com/zt/plat/module/contractorder/api/ContractApi.java @@ -42,7 +42,7 @@ public interface ContractApi { @PostMapping(PREFIX + "/push") @Operation(summary = "国贸2.0系统推送合同") - CommonResult push(@Valid @RequestBody IntContract reqVO) throws Exception; + CommonResult push(@Valid @RequestBody IntContract reqVO); @GetMapping(PREFIX + "/logistics/list/page") @Operation(summary = "国贸2.0系统合同分页查询") diff --git a/zt-module-contract-order/zt-module-contract-order-api/src/main/java/com/zt/plat/module/contractorder/enums/contract/DictEnum.java b/zt-module-contract-order/zt-module-contract-order-api/src/main/java/com/zt/plat/module/contractorder/enums/contract/DictEnum.java index 4bf0faf..23eda81 100644 --- a/zt-module-contract-order/zt-module-contract-order-api/src/main/java/com/zt/plat/module/contractorder/enums/contract/DictEnum.java +++ b/zt-module-contract-order/zt-module-contract-order-api/src/main/java/com/zt/plat/module/contractorder/enums/contract/DictEnum.java @@ -8,6 +8,9 @@ import lombok.Getter; @Getter public enum DictEnum { + /** 方式系统 */ + BSE_SYS_REL_WY_EXTERNAL("系统外关联","EXTERNAL",null), + BSE_SYS_REL_WY_INTERNAL("内关联","INTERNAL",null), /** 供应链业务大类 */ SPLY_BSN_TP_03BX("货物保险","03BX",null), SPLY_BSN_TP_11CC("货物保管仓储","11CC",null), diff --git a/zt-module-contract-order/zt-module-contract-order-server/src/main/java/com/zt/plat/module/contractorder/api/ContractApiImpl.java b/zt-module-contract-order/zt-module-contract-order-server/src/main/java/com/zt/plat/module/contractorder/api/ContractApiImpl.java index 95bbc35..462409a 100644 --- a/zt-module-contract-order/zt-module-contract-order-server/src/main/java/com/zt/plat/module/contractorder/api/ContractApiImpl.java +++ b/zt-module-contract-order/zt-module-contract-order-server/src/main/java/com/zt/plat/module/contractorder/api/ContractApiImpl.java @@ -11,7 +11,9 @@ 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.*; +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.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; @@ -39,10 +41,12 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import java.lang.reflect.Field; +import java.lang.reflect.Method; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Arrays; +import java.util.Iterator; import java.util.List; import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -151,10 +155,10 @@ public class ContractApiImpl implements ContractApi { @Transactional @Override - public CommonResult push(@RequestBody IntContract reqVO) throws Exception { + public CommonResult push(@RequestBody IntContract reqVO) { // 合同主信息表映射 - ContractMainDO contractMainDO = getcontractMainDO(reqVO); + ContractMainDO contractMainDO = internationalToMainDO(reqVO); // 逻辑处理 // 操作标志 I 新增/更新;D 删除 @@ -178,7 +182,7 @@ public class ContractApiImpl implements ContractApi { SystemRelativityDO saveRelation = new SystemRelativityDO(); saveRelation.setUpId(Long.parseLong(externalId)); saveRelation.setDownId(contractId); - saveRelation.setWay("EXTERNAL"); + saveRelation.setWay(DictEnum.BSE_SYS_REL_WY_EXTERNAL.getCode()); saveRelation.setStatus(DictEnum.BSE_SYS_REL_TP_CONTRACT.getCode()); systemRelativityMapper.insert(saveRelation); } @@ -242,107 +246,116 @@ public class ContractApiImpl implements ContractApi { contractOtherFieldMapper.delete("CTRT_MAIN_ID", contractId.toString()); // 请求参数保存到动态条款 - Field[] fields = reqVO.getClass().getDeclaredFields(); - saveFields(fields, contractId, null, reqVO); - - // 明细部分保存 - // 附件清单列表 - ContractOtherFormDO otherFormDO = saveContractOtherForm(contractId, "attachList", - "附件清单列表", "附件清单列表"); - List otherFieldDOS = new ArrayList<>(); - if (reqVO.getAttachList() != null && !reqVO.getAttachList().isEmpty()) { - for (String attach : reqVO.getAttachList()) { - otherFieldDOS.add(getContractOtherField(contractId, otherFormDO.getId(), "attach", "附件", - attach, "附件", "java.lang.String")); - } - } - // 保存 - contractOtherFieldMapper.insertBatch(otherFieldDOS); - - //----- 嵌套列表 - // 客商信息 - if (reqVO.getPartnerList() != null && !reqVO.getPartnerList().isEmpty()) { - for (Partner partner : reqVO.getPartnerList()) { - otherFormDO = saveContractOtherForm(contractId, "partnerList", - "客商信息", "客商信息"); - fields = partner.getClass().getDeclaredFields(); - saveFields(fields, contractId, otherFormDO.getId(), partner); - } - } - - // 收发港/站点 - if (reqVO.getGoodsSiteList() != null && !reqVO.getGoodsSiteList().isEmpty()) { - for (GoodsSite goodsSite : reqVO.getGoodsSiteList()) { - otherFormDO = saveContractOtherForm(contractId, "goodsSiteList", - "收发港/站点", "收发港/站点"); - fields = goodsSite.getClass().getDeclaredFields(); - saveFields(fields, contractId, otherFormDO.getId(), goodsSite); - } - } - - // 货物装卸要求 - if (reqVO.getLoadingRequirementsList() != null && !reqVO.getLoadingRequirementsList().isEmpty()) { - for (LoadingRequirement loadingRequirement : reqVO.getLoadingRequirementsList()) { - otherFormDO = saveContractOtherForm(contractId, "loadingRequirementsList", - "货物装卸要求", "货物装卸要求"); - fields = loadingRequirement.getClass().getDeclaredFields(); - saveFields(fields, contractId, otherFormDO.getId(), loadingRequirement); - } - } - - // 收付款账号 - if (reqVO.getAccountList() != null && !reqVO.getAccountList().isEmpty()) { - for (Account account : reqVO.getAccountList()) { - otherFormDO = saveContractOtherForm(contractId, "accountList", - "收付款账号", "收付款账号"); - fields = account.getClass().getDeclaredFields(); - saveFields(fields, contractId, otherFormDO.getId(), account); - } - } - - // 费用明细 - if (reqVO.getFreightList() != null && !reqVO.getFreightList().isEmpty()) { - for (Freight freight : reqVO.getFreightList()) { - otherFormDO = saveContractOtherForm(contractId, "freightList", - "费用明细", "费用明细"); - fields = freight.getClass().getDeclaredFields(); - saveFields(fields, contractId, otherFormDO.getId(), freight); - } - } - - // 服务费用项目 - if (reqVO.getServiceFeeList() != null && !reqVO.getServiceFeeList().isEmpty()) { - for (ServiceFee serviceFee : reqVO.getServiceFeeList()) { - otherFormDO = saveContractOtherForm(contractId, "serviceFeeList", - "服务费用项目", "服务费用项目"); - fields = serviceFee.getClass().getDeclaredFields(); - saveFields(fields, contractId, otherFormDO.getId(), serviceFee); - } - } - - // 仓库明细 - if (reqVO.getStorgeList() != null && !reqVO.getStorgeList().isEmpty()) { - for (Storge storge : reqVO.getStorgeList()) { - otherFormDO = saveContractOtherForm(contractId, "storgeList", - "仓库明细", "仓库明细"); - fields = storge.getClass().getDeclaredFields(); - saveFields(fields, contractId, otherFormDO.getId(), storge); - } - } - - // 接货地址 - if (reqVO.getReceivingAddrList() != null && !reqVO.getReceivingAddrList().isEmpty()) { - for (ReceivingAddr receivingAddr : reqVO.getReceivingAddrList()) { - otherFormDO = saveContractOtherForm(contractId, "receivingAddrList", - "接货地址", "接货地址"); - fields = receivingAddr.getClass().getDeclaredFields(); - saveFields(fields, contractId, otherFormDO.getId(), receivingAddr); - } - } + saveIntContractFields(reqVO, contractId); return success(true); } + private void saveIntContractFields(IntContract reqVO, Long contractId) { + + try { + // 获取请求参数类结构 + Class reqClass = reqVO.getClass(); + // 请求参数字段 + Field[] reqClassFields = reqClass.getDeclaredFields(); + + // 条款明细表保存集合 + List saveFields = new ArrayList<>(); + + // 遍历字段 + for (Field reqClassField : reqClassFields) { + + reqClassField.setAccessible(true); + + // 获取字段说明 + Schema reqFieldSchema = reqClassField.getAnnotation(Schema.class); + String reqFieldDesc = reqFieldSchema.description(); + + // 获取字段对象 + Object reqFieldObj = reqClassField.get(reqVO); + if (reqFieldObj != null) { + if (!"java.util.List".equals(reqClassField.getType().getName())) { + // 基础类型字段保存到条款明细表 + ContractOtherFieldDO otherFieldDO = new ContractOtherFieldDO(); + otherFieldDO.setContractMainId(contractId.toString()); + otherFieldDO.setFieldNumber(reqClassField.getName()); + otherFieldDO.setFieldName(reqFieldDesc); + otherFieldDO.setFieldValue(reqFieldObj.toString()); + otherFieldDO.setFieldDescription(reqFieldDesc); + otherFieldDO.setType(reqClassField.getType().getName()); + saveFields.add(otherFieldDO); + } else { + // list类型字段保存到条款表,再将字段保存到条款明细表 + // 获取list类结构 + Class listClass = reqClassField.get(reqVO).getClass(); + // 获取list迭代方法 + Method iteratorMethod = listClass.getMethod("iterator"); + // 获取迭代器 + Iterator iterator = (Iterator) iteratorMethod.invoke(reqClassField.get(reqVO)); + // 遍历 + while (iterator.hasNext()) { + + // 条款表保存 + ContractOtherFormDO otherFormDO = new ContractOtherFormDO(); + otherFormDO.setContractMainId(contractId); + otherFormDO.setFormNumber(reqClassField.getName()); + otherFormDO.setFormName(reqFieldDesc); + otherFormDO.setFormDescription(reqFieldDesc); + contractOtherFormMapper.insert(otherFormDO); + + // 条款表ID + Long otherFormDOId = otherFormDO.getId(); + + // 获取明细对象 + Object detailObj = iterator.next(); + // 获取明细对象类结构 + Class detailClass = detailObj.getClass(); + + // 条款明细表 + if ("java.lang.String".equals(detailClass.getTypeName())) { + // 基础类型对应生成一条明细 + ContractOtherFieldDO otherFieldDO = new ContractOtherFieldDO(); + otherFieldDO.setContractMainId(contractId.toString()); + otherFieldDO.setRelativityId(otherFormDOId); + otherFieldDO.setFieldNumber(detailClass.getTypeName()); + otherFieldDO.setFieldName(reqFieldDesc); + otherFieldDO.setFieldValue(detailObj.toString()); + otherFieldDO.setFieldDescription(reqFieldDesc); + otherFieldDO.setType(detailClass.getTypeName()); + saveFields.add(otherFieldDO); + } else { + // 对象类型遍历字段保存对应明细 + Field[] detailClassFields = detailClass.getDeclaredFields(); + for (Field detailClassField : detailClassFields) { + detailClassField.setAccessible(true); + if (detailClassField.get(detailObj) != null) { + ContractOtherFieldDO otherFieldDO = new ContractOtherFieldDO(); + otherFieldDO.setContractMainId(contractId.toString()); + otherFieldDO.setRelativityId(otherFormDOId); + otherFieldDO.setFieldNumber(detailClassField.getName()); + otherFieldDO.setFieldName(detailClassField.getAnnotation(Schema.class).description()); + otherFieldDO.setFieldValue(detailClassField.get(detailObj).toString()); + otherFieldDO.setFieldDescription(detailClassField.getAnnotation(Schema.class).description()); + otherFieldDO.setType(detailClassField.getType().getName()); + saveFields.add(otherFieldDO); + } + } + } + } + } + } + } + + // 条款明细表集合批量保存 + if (!saveFields.isEmpty()) { + contractOtherFieldMapper.insertBatch(saveFields); + } + } catch (Exception e) { + log.error(e.getMessage(), e); + throw exception(CONTRACT_PUSH_FAIL, e.getMessage()); + } + } + @Override public CommonResult> logisticsListPage(IntContractPageReq pageReq) { @@ -496,7 +509,7 @@ public class ContractApiImpl implements ContractApi { return CommonResult.success(purchaseOrderDetails); } - private ContractMainDO getcontractMainDO(IntContract reqVO) { + private ContractMainDO internationalToMainDO(IntContract reqVO) { // 合同主信息表映射 ContractMainDO contractMainDO = new ContractMainDO(); @@ -575,43 +588,6 @@ public class ContractApiImpl implements ContractApi { return contractMainDO; } - private ContractOtherFormDO saveContractOtherForm(Long contractId, String formNumber, String formName, String formDescription) { - ContractOtherFormDO otherFormDO = new ContractOtherFormDO(); - otherFormDO.setContractMainId(contractId); - otherFormDO.setFormNumber(formNumber); - otherFormDO.setFormName(formName); - otherFormDO.setFormDescription(formDescription); - contractOtherFormMapper.insert(otherFormDO); - return otherFormDO; - } - - private ContractOtherFieldDO getContractOtherField(Long contractId, Long relativityId, String number, String name, - String value, String description, String type) { - ContractOtherFieldDO otherFieldDO = new ContractOtherFieldDO(); - otherFieldDO.setContractMainId(contractId.toString()); - otherFieldDO.setRelativityId(relativityId); - otherFieldDO.setFieldNumber(number); - otherFieldDO.setFieldName(name); - otherFieldDO.setFieldValue(value); - otherFieldDO.setFieldDescription(description); - otherFieldDO.setType(type); - return otherFieldDO; - } - - private void saveFields(Field[] fields, Long contractId, Long relativityId, T obj) throws Exception { - List otherFieldDOS = new ArrayList<>(); - for (Field field : fields) { - field.setAccessible(true); - if (!"java.util.List".equals(field.getType().getName()) && field.get(obj) != null) { - Schema annotation = field.getAnnotation(Schema.class); - otherFieldDOS.add(getContractOtherField(contractId, relativityId, field.getName(), - annotation.description(), field.get(obj).toString(),annotation.description(), - field.getType().getName())); - } - } - contractOtherFieldMapper.insertBatch(otherFieldDOS); - } - private List getSalesOrdDetailsByIds(List ids) { if (ids.isEmpty()) { return new ArrayList<>(); diff --git a/zt-module-contract-order/zt-module-contract-order-server/src/main/java/com/zt/plat/module/contractorder/controller/admin/contract/ContractController.java b/zt-module-contract-order/zt-module-contract-order-server/src/main/java/com/zt/plat/module/contractorder/controller/admin/contract/ContractController.java index 0f8e1d4..4d1f09d 100644 --- a/zt-module-contract-order/zt-module-contract-order-server/src/main/java/com/zt/plat/module/contractorder/controller/admin/contract/ContractController.java +++ b/zt-module-contract-order/zt-module-contract-order-server/src/main/java/com/zt/plat/module/contractorder/controller/admin/contract/ContractController.java @@ -26,7 +26,6 @@ import java.util.List; import static com.zt.plat.framework.common.pojo.CommonResult.error; import static com.zt.plat.framework.common.pojo.CommonResult.success; -import static com.zt.plat.module.contractorder.enums.ErrorCodeConstants.CONTRACT_PUSH_FAIL; import static com.zt.plat.module.contractorder.enums.ErrorCodeConstants.CONTRACT_SUBMIT_ERP_FAIL; @Slf4j @@ -197,11 +196,7 @@ public class ContractController implements BusinessControllerMarker { @Operation(summary = "国贸2.0系统推送合同") @PreAuthorize("@ss.hasPermission('base:contract:create')") CommonResult push(@Valid @RequestBody IntContract reqVO) { - try { - return contractApi.push(reqVO); - } catch (Exception e) { - return error(CONTRACT_PUSH_FAIL, e.getMessage()); - } + return contractApi.push(reqVO); } @PostMapping("/logistics/list/page")