Browse Source

优化代码2

wangfeng 4 years ago
parent
commit
44fae7f423
1 changed files with 8 additions and 1 deletions
  1. 8 1
      src/main/java/com/diagbot/facade/PlanFacade.java

+ 8 - 1
src/main/java/com/diagbot/facade/PlanFacade.java

@@ -102,11 +102,18 @@ public class PlanFacade extends PlanServiceImpl {
                 .eq("is_deleted", IsDeleteEnum.N.getKey())
                 .eq("is_deleted", IsDeleteEnum.N.getKey())
                 .eq("hospital_id", hospitalPlanSaveVO.getHospitalId())
                 .eq("hospital_id", hospitalPlanSaveVO.getHospitalId())
                 .eq("plan_name", hospitalPlanSaveVO.getPlanName())
                 .eq("plan_name", hospitalPlanSaveVO.getPlanName())
-                .eq("plan_code", hospitalPlanSaveVO.getPlanCode())
                 .ne("id", hospitalPlanSaveVO.getId() == null ? -1 : hospitalPlanSaveVO.getId()));
                 .ne("id", hospitalPlanSaveVO.getId() == null ? -1 : hospitalPlanSaveVO.getId()));
         if (count > 0) {
         if (count > 0) {
             throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "相同【医院】下,方案名称已存在");
             throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "相同【医院】下,方案名称已存在");
         }
         }
+        int countTow = this.count(new QueryWrapper<Plan>()
+                .eq("is_deleted", IsDeleteEnum.N.getKey())
+                .eq("hospital_id", hospitalPlanSaveVO.getHospitalId())
+                .eq("plan_code", hospitalPlanSaveVO.getPlanCode())
+                .ne("id", hospitalPlanSaveVO.getId() == null ? -1 : hospitalPlanSaveVO.getId()));
+        if (countTow > 0) {
+            throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "相同【医院】下,方案编码已存在");
+        }
         if (hospitalPlanSaveVO.getId() != null) {
         if (hospitalPlanSaveVO.getId() != null) {
             UpdateWrapper<Plan> planQuery = new UpdateWrapper<>();
             UpdateWrapper<Plan> planQuery = new UpdateWrapper<>();
             planQuery.eq("is_deleted", IsDeleteEnum.N.getKey())
             planQuery.eq("is_deleted", IsDeleteEnum.N.getKey())