diff --git a/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/SystemServiceFeign.java b/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/SystemServiceFeign.java index 12993e41f..2c372f6b9 100644 --- a/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/SystemServiceFeign.java +++ b/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/SystemServiceFeign.java @@ -357,6 +357,10 @@ public interface SystemServiceFeign { @GetMapping("/contractManageApi/getInfoByCustomer") public AjaxResult getInfoByCustomer(@RequestParam("settlementCustomersCode") String settlementCustomersCode,@RequestParam("contractType") Integer contractType); + @ApiOperation("根据结算主体和费用科目获取合同信息") + @GetMapping(value = "/contractManageApi/getInfoByCustomerAndSecondSubjectCode") + public AjaxResult getInfoByCustomerAndSecondSubjectCode(@RequestParam("settlementCustomersCode") String settlementCustomersCode,@RequestParam("contractType") Integer contractType,@RequestParam("firstSubjectCode") String firstSubjectCode); + /** * 根据结算主体获取合同信息 */ diff --git a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/contractManage/ContractManageApplicationService.java b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/contractManage/ContractManageApplicationService.java index a7638c9a3..8c321d950 100644 --- a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/contractManage/ContractManageApplicationService.java +++ b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/contractManage/ContractManageApplicationService.java @@ -268,12 +268,25 @@ public class ContractManageApplicationService { Long organizationId = contractManageDTO.getOrganizationId(); String sunjectCode = contractManageDTO.getSubjectCode(); Long topOrganizationId = contractManageDTO.getTopOrganizationId(); - List UserContractManages = contractManageMapper.selectList(new LambdaQueryWrapper() - .eq(ContractManage::getSettlementCustomersId, settlementCustomersId) - .eq(ContractManage::getDelFlag, 1) - .eq(ContractManage::getOrganizationId, organizationId) - .eq(ContractManage::getTopOrganizationId, topOrganizationId) - .eq(ContractManage::getCommonContractFlag, 2)); + ContractManageDO contractManageDO = new ContractManageDO(); + contractManageDO.setOrganizationId(organizationId); + contractManageDO.setSettlementCustomersId(settlementCustomersId); + contractManageDO.setTopOrganizationId(topOrganizationId); + contractManageDO.setCommonContractFlag(2); + contractManageDO.setDelFlag(1); + contractManageDO.setFirstSubjectCode(sunjectCode); + List contractManagePOS = contractManageMapper.queryList(contractManageDO); + if (contractManagePOS != null && contractManagePOS.size() > 1) { + throw new RuntimeException("同一费用科目存在多条合同,请检查"); + } + List UserContractManages = new ArrayList<>(); + if (contractManagePOS != null) { + for (ContractManagePO po : contractManagePOS) { + ContractManage contractManage = new ContractManage(); + BeanUtils.copyProperties(po, contractManage); + UserContractManages.add(contractManage); + } + } if (UserContractManages != null && UserContractManages.size() > 0) { //用户合同计费策略 calucateSubjectAndPriceStrategy(UserContractManages, organizationId, topOrganizationId, sunjectCode, result); @@ -595,7 +608,8 @@ public class ContractManageApplicationService { 通用合同:同一时间段、同一合同类型,只能存在一个 特殊合同:同一结算主体、同一时间段、同一合同类型,只能存在一个 */ - checkContract(contractManageDO); + //20260702取消同一时间段不能有相同合同校验 + //checkContract(contractManageDO); handleData(contractManageDO); handleDict(contractManageDO); contractManageDO.setContractNumber(OrderSequence.getOrderCode("HT")); @@ -831,7 +845,7 @@ public class ContractManageApplicationService { @Transactional public Boolean update(ContractManageDO contractManageDO) { validateContractType(contractManageDO.getContractType()); - checkContract(contractManageDO); + //checkContract(contractManageDO); handleData(contractManageDO); handleDetils(contractManageDO); handleDict(contractManageDO); @@ -935,6 +949,81 @@ public class ContractManageApplicationService { return resultContract; } + public ContractManagePO getInfoByCustomerAndSecondSubjectCode(String settlementCustomersCode,Integer contractType, Long topOrganizationId,String firstSubjectCode) { + /* + 首先根据合同类型(仓储、运输、其他),以及结算客户,查询合同信息 + 如果传了结算主体,则根据结算主体以及当前时间查询有效的特殊合同,如果特殊合同没有,则查询通用合同 + */ + //获取当前登录人信息 + LoginUser loginUser = SecurityUtils.getLoginUser(); + if (ObjectUtil.isNull(loginUser) && topOrganizationId == null) { + throw new DigitalLogisticsException(UserError.TIMEOUT); + } + if(contractType==null){ + throw new ServiceException("合同类型不能为空"); + } + ContractManagePO resultContract = new ContractManagePO(); + //查询当前日期在有效期内的合同 + ContractManageDO queryParam = new ContractManageDO(); + queryParam.setNowDateString(DateUtil.format(new Date(),"yyyy-MM-dd")); + queryParam.setFirstSubjectCode(firstSubjectCode); + if (!ObjectUtil.isNull(loginUser)) { + queryParam.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId()); + }else { + queryParam.setTopOrganizationId(topOrganizationId); + } + List contractManagePOList = contractManageDomainService.queryList(queryParam); + List contractManagePOs = contractManagePOList.stream() + .filter(item -> item.getSettlementCustomersCode().equals(settlementCustomersCode) + && Objects.equals(item.getContractType(), contractType)) + .collect(Collectors.toList()); + if (contractManagePOs != null && contractManagePOs.size() > 1) { + throw new ServiceException("存在多条相同费用科目的合同,请检查"); + } + if(contractManagePOList != null && contractManagePOList.size()>0){ + if(StringUtils.isNotEmpty(settlementCustomersCode)){ + //根据结算对象,及合同的类型 查询对应合同信息 + ContractManagePO contractManagePO = contractManagePOList.stream() + .filter(item -> item.getSettlementCustomersCode().equals(settlementCustomersCode) && Objects.equals(item.getContractType(), contractType)).findFirst().orElse(null); + if(null == contractManagePO){ + resultContract = findGeneralContract(contractManagePOList, contractType); + }else { + resultContract = contractManagePO; + } + }else { + resultContract = findGeneralContract(contractManagePOList, contractType); + } + if(null == resultContract){ + throw new ServiceException("找不到匹配的合同,请重试"); + } + //得到合同后,查询合同明细 + List contractManageDetailPOList = contractManageDetailDomainService.queryListByManageId(resultContract.getContractManageId()); + List contractManageDetailSaveList = new ArrayList<>(); + if(contractManageDetailPOList != null && contractManageDetailPOList.size()>0){ + //将临时合同中没有,但是通用合同中有的数据过滤出(使用 ObjectUtil.equal 避免 firstSubjectCode/secondSubjectCode 为 null 时 NPE) + contractManageDetailSaveList = contractManageDetailPOList.stream().filter(item -> contractManageDetailPOList.stream().noneMatch(item1 -> ObjectUtil.equal(item1.getFirstSubjectCode(), item.getFirstSubjectCode()) && ObjectUtil.equal(item1.getSecondSubjectCode(), item.getSecondSubjectCode()) && item1.getSubjectType()==1)).collect(Collectors.toList()); + //首先根据结算科目类型将临时合同过滤出 + List tempContractManageDetailPOList = contractManageDetailPOList.stream().filter(item -> item.getSubjectType()==2).collect(Collectors.toList()); + //遍历两个集合,将相同费用科目code的数据,进行比较,如果结算科目类型是临时且合同有效期有效,则使用该条数据,将另一条移除 + for (ContractManageDetailPO manageDetailPO : tempContractManageDetailPOList) { + for (ContractManageDetailPO contractManageDetailPO : contractManageDetailPOList) { + if(ObjectUtil.equal(contractManageDetailPO.getFirstSubjectCode(), manageDetailPO.getFirstSubjectCode()) && ObjectUtil.equal(contractManageDetailPO.getSecondSubjectCode(), manageDetailPO.getSecondSubjectCode())){ + //判断如果是临时合同在有效期内,则将该条数据保存到集合contractManageDetailSaveList + DateTime start = DateUtil.parseDate(DateUtil.format(manageDetailPO.getSubjectEffectiveDate(),"yyyy-MM-dd")); + DateTime end = DateUtil.parseDateTime(DateUtil.format(manageDetailPO.getSubjectEffectiveDate(),"yyyy-MM-dd")); + DateTime now = DateUtil.beginOfDay(DateUtil.date()); + if (now.isAfterOrEquals(start) && now.isBefore(end)) { + contractManageDetailSaveList.add(manageDetailPO); + } + } + } + } + } + resultContract.setContractManageDetailPOList(contractManageDetailSaveList); + } + return resultContract; + } + /** * 根据结算主体获取合同信息 * @param settlementCustomersCode 结算主体code diff --git a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/domain/contractManage/repository/todo/ContractManageDO.java b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/domain/contractManage/repository/todo/ContractManageDO.java index 611e07714..541778197 100644 --- a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/domain/contractManage/repository/todo/ContractManageDO.java +++ b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/domain/contractManage/repository/todo/ContractManageDO.java @@ -214,4 +214,6 @@ public class ContractManageDO extends BaseVOEntity{ @ApiModelProperty(name = "是否包含运输费用(1-包含,2-包含)") private Integer transportationCosts; + @ApiModelProperty("一级费用科目code") + private String firstSubjectCode; } \ No newline at end of file diff --git a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/domain/storageSection/service/StorageSectionDomainService.java b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/domain/storageSection/service/StorageSectionDomainService.java index dc1df80dc..db2ba5435 100644 --- a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/domain/storageSection/service/StorageSectionDomainService.java +++ b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/domain/storageSection/service/StorageSectionDomainService.java @@ -71,12 +71,15 @@ public class StorageSectionDomainService { String storageCode = storageSectionDO.getStorageCode(); String storageName = storageSectionDO.getStorageName(); Long warehouseId = storageSectionDO.getWarehouseId(); - List list = storageSectionService.list(new QueryWrapper().lambda() + List codelist = storageSectionService.list(new QueryWrapper().lambda() .eq(StorageSection::getStorageCode, storageCode) + .eq(StorageSection::getWarehouseId, warehouseId) + .eq(StorageSection::getDelFlag, 1)); + List namelist = storageSectionService.list(new QueryWrapper().lambda() .eq(StorageSection::getStorageName, storageName) .eq(StorageSection::getWarehouseId, warehouseId) .eq(StorageSection::getDelFlag, 1)); - if (list != null && list.size() > 0) { + if ((codelist != null && codelist.size() > 0) || (namelist != null && namelist.size() > 0)) { throw new ServiceException("库区编码或名称已存在"); } return storageSectionService.insert(storageSectionDO); @@ -100,12 +103,17 @@ public class StorageSectionDomainService { String storageCode = storageSectionDO.getStorageCode(); String storageName = storageSectionDO.getStorageName(); Long warehouseId = storageSectionDO.getWarehouseId(); - List list = storageSectionService.list(new QueryWrapper().lambda() + List codelist = storageSectionService.list(new QueryWrapper().lambda() .eq(StorageSection::getStorageCode, storageCode) + .eq(StorageSection::getWarehouseId, warehouseId) + .ne(StorageSection::getStorageSectionId, storageSectionDO.getStorageSectionId()) + .eq(StorageSection::getDelFlag, 1)); + List namelist = storageSectionService.list(new QueryWrapper().lambda() .eq(StorageSection::getStorageName, storageName) .eq(StorageSection::getWarehouseId, warehouseId) + .ne(StorageSection::getStorageSectionId, storageSectionDO.getStorageSectionId()) .eq(StorageSection::getDelFlag, 1)); - if (list != null && list.size() > 0) { + if ((codelist != null && codelist.size() > 0) || (namelist != null && namelist.size() > 0)) { throw new ServiceException("库区编码或名称已存在"); } return storageSectionService.update(storageSectionDO); diff --git a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/interfaces/facade/contractManage/ContractManageApi.java b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/interfaces/facade/contractManage/ContractManageApi.java index 1e2039f0e..540650ae9 100644 --- a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/interfaces/facade/contractManage/ContractManageApi.java +++ b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/interfaces/facade/contractManage/ContractManageApi.java @@ -160,6 +160,13 @@ public class ContractManageApi extends BaseController{ return AjaxResult.success(contractManageApplicationService.getInfoByCustomer(settlementCustomersCode,contractType,null)); } + @ApiOperation("根据结算主体和费用科目获取合同信息") + @GetMapping(value = "/getInfoByCustomerAndSecondSubjectCode") + public AjaxResult getInfoByCustomerAndSecondSubjectCode(@RequestParam("settlementCustomersCode") String settlementCustomersCode,@RequestParam("contractType") Integer contractType,@RequestParam("firstSubjectCode") String firstSubjectCode) + { + return AjaxResult.success(contractManageApplicationService.getInfoByCustomerAndSecondSubjectCode(settlementCustomersCode,contractType,null,firstSubjectCode)); + } + @ApiOperation("根据结算主体获取合同信息") @GetMapping(value = "/getInfoByCustomer2") public AjaxResult getInfoByCustomer2(@RequestParam("settlementCustomersCode") String settlementCustomersCode,@RequestParam("contractType") Integer contractType,@RequestParam("topOrganizationId") Long topOrganizationId) diff --git a/mhd-modules/mhd-system/src/main/resources/mapper/basic/ContractManageMapper.xml b/mhd-modules/mhd-system/src/main/resources/mapper/basic/ContractManageMapper.xml index 3fabe03cc..ec8c105fa 100644 --- a/mhd-modules/mhd-system/src/main/resources/mapper/basic/ContractManageMapper.xml +++ b/mhd-modules/mhd-system/src/main/resources/mapper/basic/ContractManageMapper.xml @@ -6,107 +6,111 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select - * - from contract_manage + SELECT DISTINCT a.* + FROM CONTRACT_MANAGE a + INNER JOIN CONTRACT_MANAGE_DETAIL b + ON a.CONTRACT_MANAGE_ID = b.CONTRACT_MANAGE_ID where - del_flag = 1 + a.del_flag = 1 - and create_by_name like concat('%', #{createByName}, '%') + and a.create_by_name like concat('%', #{createByName}, '%') - and update_by_name like concat('%', #{updateByName}, '%') + and a.update_by_name like concat('%', #{updateByName}, '%') - and top_organization_id = #{topOrganizationId} + and a.top_organization_id = #{topOrganizationId} - and organization_id = #{organizationId} + and a.organization_id = #{organizationId} - and organization_name like concat('%', #{organizationName}, '%') + and a.organization_name like concat('%', #{organizationName}, '%') - and contract_number = #{contractNumber} + and a.contract_number = #{contractNumber} - and contract_name like concat('%', #{contractName}, '%') + and a.contract_name like concat('%', #{contractName}, '%') - and common_contract_flag = #{commonContractFlag} + and a.common_contract_flag = #{commonContractFlag} - and contract_type = #{contractType} + and a.contract_type = #{contractType} - and contract_state = #{contractState} + and a.contract_state = #{contractState} - and signing_unit = #{signingUnit} + and a.signing_unit = #{signingUnit} - and settlement_customers = #{settlementCustomers} + and a.settlement_customers = #{settlementCustomers} - and settlement_customers_id = #{settlementCustomersId} + and a.settlement_customers_id = #{settlementCustomersId} - and settlement_customers_code = #{settlementCustomersCode} + and a.settlement_customers_code = #{settlementCustomersCode} - and our_identity = #{ourIdentity} + and a.our_identity = #{ourIdentity} - and accounting_period = #{accountingPeriod} + and a.accounting_period = #{accountingPeriod} - and signing_date = #{signingDate} + and a.signing_date = #{signingDate} - and effective_date = #{effectiveDate} + and a.effective_date = #{effectiveDate} - and expiration_date = #{expirationDate} + and a.expiration_date = #{expirationDate} - and contract_original_url = #{contractOriginalUrl} + and a.contract_original_url = #{contractOriginalUrl} - and integrity_agreement_url = #{integrityAgreementUrl} + and a.integrity_agreement_url = #{integrityAgreementUrl} - and security_protocol_url = #{securityProtocolUrl} + and a.security_protocol_url = #{securityProtocolUrl} - and other_attachments_url = #{otherAttachmentsUrl} + and a.other_attachments_url = #{otherAttachmentsUrl} - and our_singed = #{ourSinged} + and a.our_singed = #{ourSinged} - and our_singed_phone = #{ourSingedPhone} + and a.our_singed_phone = #{ourSingedPhone} - and our_operator = #{ourOperator} + and a.our_operator = #{ourOperator} - and our_operator_phone = #{ourOperatorPhone} + and a.our_operator_phone = #{ourOperatorPhone} - and they_singed = #{theySinged} + and a.they_singed = #{theySinged} - and they_singed_phone = #{theySingedPhone} + and a.they_singed_phone = #{theySingedPhone} - and they_operator = #{theyOperator} + and a.they_operator = #{theyOperator} - and they_operator_phone = #{theyOperatorPhone} + and a.they_operator_phone = #{theyOperatorPhone} + + + and b.FIRST_SUBJECT_CODE = #{firstSubjectCode} @@ -201,4 +205,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + \ No newline at end of file