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 bc35f93..e34028f 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 @@ -155,11 +155,18 @@ public class ContractController implements BusinessControllerMarker { return success(contractService.submitErp(ids)); } - @GetMapping("/list/not-relation") - @Operation(summary = "获得未关联合同列表") + @GetMapping("/list/up-not-relation") + @Operation(summary = "获得上游未关联合同列表") @PreAuthorize("@ss.hasPermission('base:contract:get')") - public CommonResult> getListNotRelation(@RequestParam("id") Long id) { - return success(contractService.getListNotRelation(id)); + public CommonResult> getListUpNotRelation(@RequestParam("id") Long id) { + return success(contractService.getListUpNotRelation(id)); + } + + @GetMapping("/list/down-not-relation") + @Operation(summary = "获得下游未关联合同列表") + @PreAuthorize("@ss.hasPermission('base:contract:get')") + public CommonResult> getListDownNotRelation(@RequestParam("id") Long id) { + return success(contractService.getListDownNotRelation(id)); } @GetMapping("/get/up-relation") diff --git a/zt-module-contract-order/zt-module-contract-order-server/src/main/java/com/zt/plat/module/contractorder/service/contract/ContractService.java b/zt-module-contract-order/zt-module-contract-order-server/src/main/java/com/zt/plat/module/contractorder/service/contract/ContractService.java index 8d4aa19..7c43346 100644 --- a/zt-module-contract-order/zt-module-contract-order-server/src/main/java/com/zt/plat/module/contractorder/service/contract/ContractService.java +++ b/zt-module-contract-order/zt-module-contract-order-server/src/main/java/com/zt/plat/module/contractorder/service/contract/ContractService.java @@ -120,9 +120,35 @@ public interface ContractService { */ ContractRespVO getBySystemContractNumber(String systemContractNumber); - List getListNotRelation(Long id); + /** + * 获得上游未关联合同列表 + * + * @param id 合同ID + * @return 上游未关联的合同列表 + */ + List getListUpNotRelation(Long id); + /** + * 获得下游未关联合同列表 + * + * @param id 合同ID + * @return 下游未关联的合同列表 + */ + List getListDownNotRelation(Long id); + + /** + * 获得上游关联的合同数据 + * + * @param id 合同ID + * @return 关联的上游合同数据 + */ ContractRespVO getUpRelation(Long id); + /** + * 获得下游关联的合同数据 + * + * @param id 合同ID + * @return 关联的下游合同数据 + */ ContractRespVO getDownRelation(Long id); } diff --git a/zt-module-contract-order/zt-module-contract-order-server/src/main/java/com/zt/plat/module/contractorder/service/contract/ContractServiceImpl.java b/zt-module-contract-order/zt-module-contract-order-server/src/main/java/com/zt/plat/module/contractorder/service/contract/ContractServiceImpl.java index a4ab02d..95b61cd 100644 --- a/zt-module-contract-order/zt-module-contract-order-server/src/main/java/com/zt/plat/module/contractorder/service/contract/ContractServiceImpl.java +++ b/zt-module-contract-order/zt-module-contract-order-server/src/main/java/com/zt/plat/module/contractorder/service/contract/ContractServiceImpl.java @@ -42,6 +42,7 @@ import org.springframework.transaction.annotation.Transactional; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.ArrayList; +import java.util.LinkedHashSet; import java.util.List; import java.util.stream.Collectors; @@ -465,7 +466,7 @@ public class ContractServiceImpl implements ContractService { } @Override - public List getListNotRelation(Long id) { + public List getListUpNotRelation(Long id) { // 查询合同信息 ContractMainDO contractMainDO = contractMainMapper.selectById(id); @@ -480,15 +481,14 @@ public class ContractServiceImpl implements ContractService { // 乙方公司编号 String salesCompanyNumber = contractMainDO.getSalesCompanyNumber(); - // 已关联合同id集合 - /*List systemRelativityDOS = systemRelativityMapper.selectList(); + // 已关联的上游合同id集合 + List systemRelativityDOS = systemRelativityMapper.selectList(); LinkedHashSet relationIds = new LinkedHashSet<>(); if (systemRelativityDOS!= null && !systemRelativityDOS.isEmpty()) { systemRelativityDOS.forEach(systemRelativityDO -> { relationIds.add(systemRelativityDO.getUpId()); - relationIds.add(systemRelativityDO.getDownId()); }); - }*/ + } // 返回结果集 List result = new ArrayList<>(); @@ -501,6 +501,9 @@ public class ContractServiceImpl implements ContractService { // 查询条件 LambdaQueryWrapperX conditon = new LambdaQueryWrapperX<>(); conditon.eq(ContractMainDO::getSalesCompanyNumber, purchaseCompanyNumber); + if (!relationIds.isEmpty()) { + conditon.notIn(ContractMainDO::getId, relationIds); + } // 查询 List contractMainDOS = contractMainMapper.selectList(conditon); @@ -515,6 +518,77 @@ public class ContractServiceImpl implements ContractService { // 查询条件 LambdaQueryWrapperX conditon = new LambdaQueryWrapperX<>(); conditon.eq(ContractMainDO::getPurchaseCompanyNumber, salesCompanyNumber); + if (!relationIds.isEmpty()) { + conditon.notIn(ContractMainDO::getId, relationIds); + } + + // 查询 + List contractMainDOS = contractMainMapper.selectList(conditon); + result = BeanUtils.toBean(contractMainDOS, ContractRespVO.class); + } else { + // 不存在的收支类型或收支类型为空 + throw exception(CONTRACT_ERP_RCV_DLVY_NOT_EXISTS); + } + + return result; + } + + @Override + public List getListDownNotRelation(Long id) { + + // 查询合同信息 + ContractMainDO contractMainDO = contractMainMapper.selectById(id); + if (contractMainDO == null) { + throw exception(CONTRACT_NOT_EXISTS); + } + + // 收支性质 + String direction = contractMainDO.getDirection(); + // 甲方公司编号 + String purchaseCompanyNumber = contractMainDO.getPurchaseCompanyNumber(); + // 乙方公司编号 + String salesCompanyNumber = contractMainDO.getSalesCompanyNumber(); + + // 已关联的上游合同id集合 + List systemRelativityDOS = systemRelativityMapper.selectList(); + LinkedHashSet relationIds = new LinkedHashSet<>(); + if (systemRelativityDOS!= null && !systemRelativityDOS.isEmpty()) { + systemRelativityDOS.forEach(systemRelativityDO -> { + relationIds.add(systemRelativityDO.getDownId()); + }); + } + + // 返回结果集 + List result = new ArrayList<>(); + if (DictEnum.ERP_RCV_DLVY_INCOME.getCode().equals(direction)) { // 收入 + // 如果“收支性质”字段为收入,用“甲方公司编号”字段筛选“合同主信息”表中字段等于“乙方公司编号”的数据 + if (StringUtils.isEmpty(purchaseCompanyNumber)) { + // 甲方公司编号不存在 + throw exception(CONTRACT_DATA_NOT_EXISTS, TableFieldConstants.BSE_CTRT_MAIN_PRCH_CPN_NUM_LABEL); + } + // 查询条件 + LambdaQueryWrapperX conditon = new LambdaQueryWrapperX<>(); + conditon.eq(ContractMainDO::getSalesCompanyNumber, purchaseCompanyNumber); + if (!relationIds.isEmpty()) { + conditon.notIn(ContractMainDO::getId, relationIds); + } + + // 查询 + List contractMainDOS = contractMainMapper.selectList(conditon); + result = BeanUtils.toBean(contractMainDOS, ContractRespVO.class); + } else if (DictEnum.ERP_RCV_DLVY_EXPENSES.getCode().equals(direction)){ // 支出 + // 如果“收支性质”字段为支出,用“乙方公司编号”字段筛选“合同主信息”表中字段等于“甲方公司编号”的数据 + if (StringUtils.isEmpty(salesCompanyNumber)) { + // 乙方公司编号不存在 + throw exception(CONTRACT_DATA_NOT_EXISTS, TableFieldConstants.BSE_CTRT_MAIN_SALE_CPN_NUM_LABEL); + } + + // 查询条件 + LambdaQueryWrapperX conditon = new LambdaQueryWrapperX<>(); + conditon.eq(ContractMainDO::getPurchaseCompanyNumber, salesCompanyNumber); + if (!relationIds.isEmpty()) { + conditon.notIn(ContractMainDO::getId, relationIds); + } // 查询 List contractMainDOS = contractMainMapper.selectList(conditon); @@ -530,6 +604,11 @@ public class ContractServiceImpl implements ContractService { @Override public ContractRespVO getUpRelation(Long id) { + // 查询合同信息 + if (contractMainMapper.selectById(id) == null) { + throw exception(CONTRACT_NOT_EXISTS); + } + // 查询关联表 SystemRelativityDO systemRelativityDO = systemRelativityMapper.selectOne(TableFieldConstants.BSE_SYS_REL_DOWN_ID, id); if (systemRelativityDO == null) { @@ -551,6 +630,11 @@ public class ContractServiceImpl implements ContractService { @Override public ContractRespVO getDownRelation(Long id) { + // 查询合同信息 + if (contractMainMapper.selectById(id) == null) { + throw exception(CONTRACT_NOT_EXISTS); + } + // 查询关联表 SystemRelativityDO systemRelativityDO = systemRelativityMapper.selectOne(TableFieldConstants.BSE_SYS_REL_UP_ID, id); if (systemRelativityDO == null) {