he2802 2 anos atrás
pai
commit
dddbb3bdd1

+ 6 - 5
zhongzheng-system/src/main/java/com/zhongzheng/modules/top/system/service/impl/TopCostCategoryServiceImpl.java

@@ -99,12 +99,13 @@ public class TopCostCategoryServiceImpl extends ServiceImpl<TopCostCategoryMappe
      */
     private void validEntityBeforeSave(TopCostCategory entity){
         //TODO 做一些数据校验,如唯一约束
+        if(iTopCostTpItemService.count(new LambdaQueryWrapper<TopCostTpItem>()
+                .eq(TopCostTpItem::getItemCategory, entity.getCategoryId())
+                .ne(TopCostTpItem::getStatus, -1))>0){
+            throw new CustomException("该分类已被使用,无法编辑和删除");
+        }
         if(Validator.isNotEmpty(entity.getStatus())&&entity.getStatus()==-1){
-            if(iTopCostTpItemService.count(new LambdaQueryWrapper<TopCostTpItem>()
-                    .eq(TopCostTpItem::getItemCategory, entity.getCategoryId())
-                    .ne(TopCostTpItem::getStatus, -1))>0){
-                throw new CustomException("该分类已被使用,无法编辑和删除");
-            }
+
         }else{
             if(checkNameUnique(entity)){
                 throw new CustomException("名称重复");

+ 6 - 5
zhongzheng-system/src/main/java/com/zhongzheng/modules/top/system/service/impl/TopInstCategoryServiceImpl.java

@@ -99,12 +99,13 @@ public class TopInstCategoryServiceImpl extends ServiceImpl<TopInstCategoryMappe
      */
     private void validEntityBeforeSave(TopInstCategory entity){
         //TODO 做一些数据校验,如唯一约束
+        if(iTopCostInstTpItemService.count(new LambdaQueryWrapper<TopCostInstTpItem>()
+                .eq(TopCostInstTpItem::getCostCatId, entity.getCostCatId())
+                .ne(TopCostInstTpItem::getStatus, -1))>0){
+            throw new CustomException("该分类已被使用,无法编辑和删除");
+        }
         if(Validator.isNotEmpty(entity.getStatus())&&entity.getStatus()==-1){
-            if(iTopCostInstTpItemService.count(new LambdaQueryWrapper<TopCostInstTpItem>()
-                    .eq(TopCostInstTpItem::getCostCatId, entity.getCostCatId())
-                    .ne(TopCostInstTpItem::getStatus, -1))>0){
-                throw new CustomException("该分类已被使用,无法编辑和删除");
-            }
+
         }else{
             if(checkNameUnique(entity)){
                 throw new CustomException("名称重复");