Преглед изворни кода

修改bug:
报价配置-协议管理,在协议名称重复的前提下还要再次判断协议的生效时间

jiakai пре 4 месеци
родитељ
комит
c527e21759

+ 49 - 14
tenant/organization/src/main/java/com/jzg/organization/controller/AgreementController.java

@@ -77,14 +77,22 @@ public class AgreementController extends BaseController {
     @Operation(summary = "协议添加")
     @PostMapping("/agreementAdd")
     public HttpResult agreementAdd(@Validated @RequestBody AgreementAddParam param) {
-
-        boolean nameExists = agreementService.isExistsName(param.getAgreementTitle(), null, 0);
-        AssertionUtils.isFail(nameExists,"协议名称重复!");
         LocalDateTime startDate = param.getStartDate();
         LocalDateTime endDate = param.getEndDate();
+        // 1. 时间合法性校验
         if(endDate.isBefore(startDate) || startDate.isEqual(endDate)){
             AssertionUtils.isFail(false,"协议生效时间不能大于失效时间!");
         }
+        // 2. 通用名称+时间查重(内部=0)
+        boolean nameExists = agreementService.checkNameExistsWithDate(
+                param.getAgreementTitle(),
+                null,        // 新增传 null
+                0,           // 内部协议
+                startDate
+        );
+        AssertionUtils.isFail(nameExists,"协议名称已存在,请输入其他名称");
+
+        // 3. 执行新增
         agreementService.agreementAdd(param);
         return HttpResult.ok("新增成功");
     }
@@ -98,14 +106,22 @@ public class AgreementController extends BaseController {
     @Operation(summary = "协议修改")
     @PostMapping("/agreementEdit")
     public HttpResult agreementEdit(@Validated @RequestBody AgreementEditParam param) {
-
-        boolean nameExists = agreementService.isExistsName(param.getAgreementTitle(), param.getId(), 0);
-        AssertionUtils.isFail(nameExists,"协议名称重复!");
         LocalDateTime startDate = param.getStartDate();
         LocalDateTime endDate = param.getEndDate();
+        // 1. 时间合法性校验
         if(endDate.isBefore(startDate) || startDate.isEqual(endDate)){
             AssertionUtils.isFail(false,"协议生效时间不能大于失效时间!");
         }
+        // 2. 通用名称+时间查重(内部=0,编辑排除自身)
+        boolean nameExists = agreementService.checkNameExistsWithDate(
+                param.getAgreementTitle(),
+                param.getId(), // 修改传自身ID
+                0,             // 内部协议
+                startDate
+        );
+        AssertionUtils.isFail(nameExists,"协议名称已存在,请输入其他名称");
+
+        // 3. 执行修改
         agreementService.agreementEdit(param);
         return HttpResult.ok("修改成功");
     }
@@ -205,14 +221,23 @@ public class AgreementController extends BaseController {
     @Operation(summary = "外部协议添加")
     @PostMapping("/contactAdd")
     public HttpResult contactAdd(@Validated @RequestBody AgreementContactAddParam param) {
-
-        boolean nameExists = agreementService.isExistsName(param.getAgreementTitle(), null,1);
-        AssertionUtils.isFail(nameExists,"协议名称重复!");
         LocalDateTime startDate = param.getStartDate();
         LocalDateTime endDate = param.getEndDate();
+        // 1. 时间合法性校验
         if(endDate.isBefore(startDate) || startDate.isEqual(endDate)){
-            AssertionUtils.isFail(nameExists,"协议生效时间不能大于失效时间!");
+            AssertionUtils.isFail(false,"协议生效时间不能大于失效时间!");
         }
+
+        // 2. 名称+时间双重查重(外部=1)
+        boolean nameExists = agreementService.checkNameExistsWithDate(
+                param.getAgreementTitle(),
+                null,        // 新增传null
+                1,           // 外部协议
+                startDate
+        );
+        AssertionUtils.isFail(nameExists,"协议名称已存在,请输入其他名称");
+
+        // 3. 执行保存
         agreementService.contactAdd(param);
         return HttpResult.ok("新增成功");
     }
@@ -226,14 +251,24 @@ public class AgreementController extends BaseController {
     @Operation(summary = "外部协议修改")
     @PostMapping("/contactEdit")
     public HttpResult contactEdit(@Validated @RequestBody AgreementContactEditParam param) {
-
-        boolean nameExists = agreementService.isExistsName(param.getAgreementTitle(), param.getId(),1);
-        AssertionUtils.isFail(nameExists,"协议名称重复!");
         LocalDateTime startDate = param.getStartDate();
         LocalDateTime endDate = param.getEndDate();
+
+        // 1. 时间合法性校验
         if(endDate.isBefore(startDate) || startDate.isEqual(endDate)){
-            AssertionUtils.isFail(nameExists,"协议生效时间不能大于失效时间!");
+            AssertionUtils.isFail(false,"协议生效时间不能大于失效时间!");
         }
+
+        // 2. 名称+时间双重查重(外部=1,编辑排除自身)
+        boolean nameExists = agreementService.checkNameExistsWithDate(
+                param.getAgreementTitle(),
+                param.getId(), // 编辑传自身ID
+                1,            // 外部协议
+                startDate
+        );
+        AssertionUtils.isFail(nameExists,"协议名称已存在,请输入其他名称");
+
+        // 3. 执行修改
         agreementService.contactEdit(param);
         return HttpResult.ok("修改成功");
     }

+ 11 - 0
tenant/organization/src/main/java/com/jzg/organization/service/PtlAgreementService.java

@@ -11,6 +11,7 @@ import com.jzg.commons.entity.vo.AgreementUserVo;
 import com.jzg.commons.entity.vo.AgreementVo;
 import com.jzg.commons.entity.vo.UpAndDownVo;
 
+import java.time.LocalDateTime;
 import java.util.List;
 import java.util.Map;
 
@@ -59,6 +60,16 @@ public interface PtlAgreementService extends IService<PtlAgreement> {
      */
     boolean isExistsName(String agreementTitle, String id, int isExternal);
 
+    /**
+     * 通用:协议名称+有效期查重(支持新增/修改、内部/外部)
+     * @param agreementTitle 协议名称
+     * @param id 协议id(新增传null,修改传当前id)
+     * @param isExternal 内外标识 0内部 1外部
+     * @param newStartDate 新的生效时间
+     * @return true=重复不可用,false=可用
+     */
+    boolean checkNameExistsWithDate(String agreementTitle, String id, Integer isExternal, LocalDateTime newStartDate);
+
     /**
      * 协议新增
      * @param param

+ 37 - 0
tenant/organization/src/main/java/com/jzg/organization/service/impl/PtlAgreementServiceImpl.java

@@ -189,6 +189,43 @@ public class PtlAgreementServiceImpl extends ServiceImpl<PtlAgreementMapper, Ptl
         return count > 0;
     }
 
+    /**
+     * 通用:协议名称+有效期查重(支持新增/修改、内部/外部)
+     * @param agreementTitle 协议名称
+     * @param id 协议id(新增传null,修改传当前id)
+     * @param isExternal 内外标识 0内部 1外部
+     * @param newStartDate 新的生效时间
+     * @return true=重复不可用,false=可用
+     */
+    @Override
+    public boolean checkNameExistsWithDate(String agreementTitle, String id, Integer isExternal, LocalDateTime newStartDate) {
+        // 1. 构造查询条件:同名称、同类型、未删除
+        LambdaQueryWrapper<PtlAgreement> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(PtlAgreement::getAgreementTitle, agreementTitle)
+                .eq(PtlAgreement::getIsExternal, isExternal)
+                .eq(PtlAgreement::getIsDelete, 0);
+
+        // 2. 编辑时:排除自身ID
+        if (StringUtils.isNotNull(id)) {
+            wrapper.ne(PtlAgreement::getId, id);
+        }
+
+        // 只查一条,性能最优
+        wrapper.last("LIMIT 1");
+        PtlAgreement existAgreement = this.getOne(wrapper);
+
+        // 无重名 → 直接可用
+        if (existAgreement == null) {
+            return false;
+        }
+
+        // 3. 有重名 → 判断时间是否冲突
+        // 已存在止期 >= 新的起期 → 冲突(不可用)
+        LocalDateTime existEndDate = existAgreement.getEndDate();
+        return !existEndDate.isBefore(newStartDate);
+    }
+
+
     @Override
     @GlobalTransactional(rollbackFor = Exception.class)
     public void agreementAdd(AgreementAddParam param) {