From 1e8b71fbea8e82d63162fe04098d38ed866003ba Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=A7=A6=E9=B8=BF=E5=B1=95?= <18031053041@163.com>
Date: Fri, 27 Feb 2026 14:50:13 +0800
Subject: [PATCH] =?UTF-8?q?BMS=E5=90=88=E5=90=8C=E7=AE=A1=E7=90=86?=
=?UTF-8?q?=E7=94=9F=E6=95=88=E7=8A=B6=E6=80=81=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../ContractManageApplicationService.java | 32 ++++++++++++++++---
.../mapper/basic/ContractManageMapper.xml | 6 ++--
2 files changed, 31 insertions(+), 7 deletions(-)
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 a855cffd9..091a772e5 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
@@ -164,11 +164,25 @@ public class ContractManageApplicationService {
* 处理数据
*/
private void handleData(ContractManageDO contractManageDO) {
- //根据合同生效时间判断合同是否生效
- if (DateUtil.compare(contractManageDO.getEffectiveDate(), new Date()) > 0) {
- contractManageDO.setContractState(2);
- } else {
- contractManageDO.setContractState(1);
+ // 如果前端未传合同状态,则根据生效/到期时间自动计算;
+ // 如果前端已经传了 contractState,则尊重前端值
+ if (contractManageDO.getContractState() == null) {
+ // 合同状态(1-未生效,2-使用中,3-已过期,4-已作废)
+ Date now = DateUtil.beginOfDay(new Date());
+ Date effectiveDate = contractManageDO.getEffectiveDate();
+ Date expirationDate = contractManageDO.getExpirationDate();
+ if (effectiveDate != null && expirationDate != null) {
+ if (DateUtil.compare(now, effectiveDate) < 0) {
+ // 当前时间早于生效日期:未生效
+ contractManageDO.setContractState(1);
+ } else if (DateUtil.compare(now, expirationDate) > 0) {
+ // 当前时间晚于到期日期:已过期
+ contractManageDO.setContractState(3);
+ } else {
+ // 生效日期 <= 当前时间 <= 到期日期:使用中
+ contractManageDO.setContractState(2);
+ }
+ }
}
if(StringUtils.isNotEmpty(contractManageDO.getSettlementCustomersCode())){
AjaxResult ajaxResult = bmsServiceFeign.getCustomersInfoByCode(contractManageDO.getSettlementCustomersCode());
@@ -190,11 +204,19 @@ public class ContractManageApplicationService {
* @param contractManageDO
*/
private void checkContract(ContractManageDO contractManageDO) {
+ // 通用/特殊合同的唯一性应在“同一组织”内生效,不同组织之间互不影响
+ LoginUser loginUser = SecurityUtils.getLoginUser();
+ if (ObjectUtil.isNull(loginUser) || loginUser.getUserPo() == null) {
+ throw new DigitalLogisticsException(UserError.TIMEOUT);
+ }
ContractManageDO commonQueryParam = new ContractManageDO();
commonQueryParam.setContractType(contractManageDO.getContractType());
commonQueryParam.setSettlementCustomersCode(contractManageDO.getSettlementCustomersCode());
commonQueryParam.setEffectiveDateString(DateUtil.format(contractManageDO.getEffectiveDate(),"yyyy-MM-dd"));
commonQueryParam.setExpirationDateString(DateUtil.format(contractManageDO.getExpirationDate(),"yyyy-MM-dd"));
+ // 按当前登录人的组织维度进行唯一性校验:不同组织下的通用/特殊合同互不影响
+ commonQueryParam.setOrganizationId(loginUser.getUserPo().getOrganizationId());
+ commonQueryParam.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());
//通用合同
if(contractManageDO.getCommonContractFlag()==1){
commonQueryParam.setCommonContractFlag(1);
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 14d09a526..76d2a0d1d 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
@@ -178,11 +178,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND date_format(expiration_date,'%Y-%m-%d') #{contractManageDO.expirationDateEnd}
+
AND (
- date_format(effective_date,'%Y-%m-%d') =]]> #{contractManageDO.effectiveDateString}
- OR date_format(expiration_date,'%Y-%m-%d') #{contractManageDO.expirationDateString}
+ date_format(effective_date,'%Y-%m-%d') #{contractManageDO.expirationDateString}
+ AND date_format(expiration_date,'%Y-%m-%d') =]]> #{contractManageDO.effectiveDateString}
)