This commit is contained in:
王奎兴
2026-07-02 15:04:20 +08:00
parent 193db96e63
commit b178e79c8f
6 changed files with 162 additions and 48 deletions
@@ -268,12 +268,25 @@ public class ContractManageApplicationService {
Long organizationId = contractManageDTO.getOrganizationId();
String sunjectCode = contractManageDTO.getSubjectCode();
Long topOrganizationId = contractManageDTO.getTopOrganizationId();
List<ContractManage> UserContractManages = contractManageMapper.selectList(new LambdaQueryWrapper<ContractManage>()
.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<ContractManagePO> contractManagePOS = contractManageMapper.queryList(contractManageDO);
if (contractManagePOS != null && contractManagePOS.size() > 1) {
throw new RuntimeException("同一费用科目存在多条合同,请检查");
}
List<ContractManage> 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<ContractManagePO> contractManagePOList = contractManageDomainService.queryList(queryParam);
List<ContractManagePO> 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<ContractManageDetailPO> contractManageDetailPOList = contractManageDetailDomainService.queryListByManageId(resultContract.getContractManageId());
List<ContractManageDetailPO> 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<ContractManageDetailPO> 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
@@ -214,4 +214,6 @@ public class ContractManageDO extends BaseVOEntity{
@ApiModelProperty(name = "是否包含运输费用(1-包含,2-包含)")
private Integer transportationCosts;
@ApiModelProperty("一级费用科目code")
private String firstSubjectCode;
}
@@ -71,12 +71,15 @@ public class StorageSectionDomainService {
String storageCode = storageSectionDO.getStorageCode();
String storageName = storageSectionDO.getStorageName();
Long warehouseId = storageSectionDO.getWarehouseId();
List<StorageSection> list = storageSectionService.list(new QueryWrapper<StorageSection>().lambda()
List<StorageSection> codelist = storageSectionService.list(new QueryWrapper<StorageSection>().lambda()
.eq(StorageSection::getStorageCode, storageCode)
.eq(StorageSection::getWarehouseId, warehouseId)
.eq(StorageSection::getDelFlag, 1));
List<StorageSection> namelist = storageSectionService.list(new QueryWrapper<StorageSection>().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<StorageSection> list = storageSectionService.list(new QueryWrapper<StorageSection>().lambda()
List<StorageSection> codelist = storageSectionService.list(new QueryWrapper<StorageSection>().lambda()
.eq(StorageSection::getStorageCode, storageCode)
.eq(StorageSection::getWarehouseId, warehouseId)
.ne(StorageSection::getStorageSectionId, storageSectionDO.getStorageSectionId())
.eq(StorageSection::getDelFlag, 1));
List<StorageSection> namelist = storageSectionService.list(new QueryWrapper<StorageSection>().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);
@@ -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)
@@ -6,107 +6,111 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<sql id="selectContractManagePo">
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
</sql>
<sql id="selectContractManagePo1">
<where>
<if test="createByName != null and createByName != ''">
and create_by_name like concat('%', #{createByName}, '%')
and a.create_by_name like concat('%', #{createByName}, '%')
</if>
<if test="updateByName != null and updateByName != ''">
and update_by_name like concat('%', #{updateByName}, '%')
and a.update_by_name like concat('%', #{updateByName}, '%')
</if>
<if test="topOrganizationId != null ">
and top_organization_id = #{topOrganizationId}
and a.top_organization_id = #{topOrganizationId}
</if>
<if test="organizationId != null ">
and organization_id = #{organizationId}
and a.organization_id = #{organizationId}
</if>
<if test="organizationName != null and organizationName != ''">
and organization_name like concat('%', #{organizationName}, '%')
and a.organization_name like concat('%', #{organizationName}, '%')
</if>
<if test="contractNumber != null and contractNumber != ''">
and contract_number = #{contractNumber}
and a.contract_number = #{contractNumber}
</if>
<if test="contractName != null and contractName != ''">
and contract_name like concat('%', #{contractName}, '%')
and a.contract_name like concat('%', #{contractName}, '%')
</if>
<if test="commonContractFlag != null ">
and common_contract_flag = #{commonContractFlag}
and a.common_contract_flag = #{commonContractFlag}
</if>
<if test="contractType != null ">
and contract_type = #{contractType}
and a.contract_type = #{contractType}
</if>
<if test="contractState != null ">
and contract_state = #{contractState}
and a.contract_state = #{contractState}
</if>
<if test="signingUnit != null and signingUnit != ''">
and signing_unit = #{signingUnit}
and a.signing_unit = #{signingUnit}
</if>
<if test="settlementCustomers != null and settlementCustomers != ''">
and settlement_customers = #{settlementCustomers}
and a.settlement_customers = #{settlementCustomers}
</if>
<if test="settlementCustomersId != null ">
and settlement_customers_id = #{settlementCustomersId}
and a.settlement_customers_id = #{settlementCustomersId}
</if>
<if test="settlementCustomersCode != null and settlementCustomersCode != ''">
and settlement_customers_code = #{settlementCustomersCode}
and a.settlement_customers_code = #{settlementCustomersCode}
</if>
<if test="ourIdentity != null ">
and our_identity = #{ourIdentity}
and a.our_identity = #{ourIdentity}
</if>
<if test="accountingPeriod != null ">
and accounting_period = #{accountingPeriod}
and a.accounting_period = #{accountingPeriod}
</if>
<if test="signingDate != null ">
and signing_date = #{signingDate}
and a.signing_date = #{signingDate}
</if>
<if test="effectiveDate != null ">
and effective_date = #{effectiveDate}
and a.effective_date = #{effectiveDate}
</if>
<if test="expirationDate != null ">
and expiration_date = #{expirationDate}
and a.expiration_date = #{expirationDate}
</if>
<if test="contractOriginalUrl != null and contractOriginalUrl != ''">
and contract_original_url = #{contractOriginalUrl}
and a.contract_original_url = #{contractOriginalUrl}
</if>
<if test="integrityAgreementUrl != null and integrityAgreementUrl != ''">
and integrity_agreement_url = #{integrityAgreementUrl}
and a.integrity_agreement_url = #{integrityAgreementUrl}
</if>
<if test="securityProtocolUrl != null and securityProtocolUrl != ''">
and security_protocol_url = #{securityProtocolUrl}
and a.security_protocol_url = #{securityProtocolUrl}
</if>
<if test="otherAttachmentsUrl != null and otherAttachmentsUrl != ''">
and other_attachments_url = #{otherAttachmentsUrl}
and a.other_attachments_url = #{otherAttachmentsUrl}
</if>
<if test="ourSinged != null and ourSinged != ''">
and our_singed = #{ourSinged}
and a.our_singed = #{ourSinged}
</if>
<if test="ourSingedPhone != null and ourSingedPhone != ''">
and our_singed_phone = #{ourSingedPhone}
and a.our_singed_phone = #{ourSingedPhone}
</if>
<if test="ourOperator != null and ourOperator != ''">
and our_operator = #{ourOperator}
and a.our_operator = #{ourOperator}
</if>
<if test="ourOperatorPhone != null and ourOperatorPhone != ''">
and our_operator_phone = #{ourOperatorPhone}
and a.our_operator_phone = #{ourOperatorPhone}
</if>
<if test="theySinged != null and theySinged != ''">
and they_singed = #{theySinged}
and a.they_singed = #{theySinged}
</if>
<if test="theySingedPhone != null and theySingedPhone != ''">
and they_singed_phone = #{theySingedPhone}
and a.they_singed_phone = #{theySingedPhone}
</if>
<if test="theyOperator != null and theyOperator != ''">
and they_operator = #{theyOperator}
and a.they_operator = #{theyOperator}
</if>
<if test="theyOperatorPhone != null and theyOperatorPhone != ''">
and they_operator_phone = #{theyOperatorPhone}
and a.they_operator_phone = #{theyOperatorPhone}
</if>
<if test="firstSubjectCode != null and firstSubjectCode != ''">
and b.FIRST_SUBJECT_CODE = #{firstSubjectCode}
</if>
</where>
</sql>
@@ -201,4 +205,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if>
</sql>
</mapper>
</mapper>