Explorar el Código

隐患分类已存在检查表

lin.liu hace 3 semanas
padre
commit
af16c8e88a

+ 16 - 6
secure-producting-business/src/main/java/com/customs/cq/datacenter/business/mapper/impl/DangerCheckFormMapperImpl.java

@@ -3,17 +3,17 @@ package com.customs.cq.datacenter.business.mapper.impl;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.customs.cq.datacenter.business.domain.DangerCheckFormPO;
+import com.customs.cq.datacenter.business.entity.search.SearchDangerCheckForm;
+import com.customs.cq.datacenter.business.mapper.DangerCheckFormMapper;
+import com.customs.cq.datacenter.common.core.mapper.BasicMapper;
 import com.customs.cq.datacenter.common.enums.EOrderBy;
 import com.customs.cq.datacenter.common.enums.EYesOrNo;
-import com.customs.cq.datacenter.common.utils.ListUtil;
-import com.customs.cq.datacenter.common.utils.NumericUtil;
-import com.customs.cq.datacenter.common.core.mapper.BasicMapper;
 import com.customs.cq.datacenter.common.model.OrderByDTO;
 import com.customs.cq.datacenter.common.model.SearchBasicDTO;
+import com.customs.cq.datacenter.common.utils.ListUtil;
+import com.customs.cq.datacenter.common.utils.NumericUtil;
 import org.springframework.stereotype.Repository;
-import com.customs.cq.datacenter.business.entity.search.SearchDangerCheckForm;
-import com.customs.cq.datacenter.business.domain.DangerCheckFormPO;
-import com.customs.cq.datacenter.business.mapper.DangerCheckFormMapper;
 
 /**
  * 隐患检查表
@@ -97,4 +97,14 @@ public class DangerCheckFormMapperImpl extends BasicMapper<DangerCheckFormPO> {
         }
         return mapper.selectPage(new Page<>(search.getPage(), search.getLimit()), queryWrapper);
     }
+
+    /**
+     * 根据隐患分类获取隐患检查表数量
+     * @param dangerCategory 隐患分类
+     */
+    public Long count4DangerCategory(Long dangerCategory) {
+        LambdaQueryWrapper<DangerCheckFormPO> where = this.getQuery();
+        where.eq(DangerCheckFormPO::getDangerCategory, dangerCategory);
+        return mapper.selectCount(where);
+    }
 }

+ 10 - 0
secure-producting-business/src/main/java/com/customs/cq/datacenter/business/service/DangerCheckFormService.java

@@ -73,6 +73,10 @@ public class DangerCheckFormService extends BasicService {
     
     public ExecutedResult<Long> create(ReqCreateDangerCheckForm request) {
         DangerCategoryPO dangerCategory = dangerCategoryService.check4IdExc(request.getDangerCategory());
+        Long checkExists = dao.count4DangerCategory(request.getDangerCategory());
+        if (NumericUtil.tryParseLong(checkExists, 0L).compareTo(0L) > 0) {
+            return ExecutedResult.failed("该隐患分类已存在检查表,请添加其他分类");
+        }
         // 转换po
         DangerCheckFormPO item = CopierUtil.mapTo(request, DangerCheckFormPO.class);
         // 设置主键
@@ -117,6 +121,12 @@ public class DangerCheckFormService extends BasicService {
         if (checkExists.isFailed()) {
             return ExecutedResult.failed(checkExists.getMsg());
         }
+        if (!Objects.equals(checkExists.getData().getDangerCategory(), request.getDangerCategory())) {
+            Long checkExistsCategory = dao.count4DangerCategory(request.getDangerCategory());
+            if (NumericUtil.tryParseLong(checkExistsCategory, 0L).compareTo(0L) > 0) {
+                return ExecutedResult.failed("该隐患分类已存在检查表,请添加其他分类");
+            }
+        }
         // 转换po
         DangerCheckFormPO item = CopierUtil.mapTo(request, DangerCheckFormPO.class);
         // 检查频率