瀏覽代碼

内控字典增加限制

qianxb 1 年之前
父節點
當前提交
f071c18492

+ 44 - 8
blade-service/blade-control/src/main/java/org/springblade/control/controller/DictInfoController.java

@@ -25,6 +25,7 @@ import lombok.AllArgsConstructor;
 import javax.validation.Valid;
 import javax.validation.Valid;
 
 
 import org.springblade.control.entity.UserContractInfo;
 import org.springblade.control.entity.UserContractInfo;
+import org.springblade.control.mapper.DictInfoMapper;
 import org.springblade.core.cache.utils.CacheUtil;
 import org.springblade.core.cache.utils.CacheUtil;
 import org.springblade.core.log.exception.ServiceException;
 import org.springblade.core.log.exception.ServiceException;
 import org.springblade.core.mp.support.Condition;
 import org.springblade.core.mp.support.Condition;
@@ -48,6 +49,7 @@ import org.springblade.control.service.IDictInfoService;
 import org.springblade.core.boot.ctrl.BladeController;
 import org.springblade.core.boot.ctrl.BladeController;
 import springfox.documentation.annotations.ApiIgnore;
 import springfox.documentation.annotations.ApiIgnore;
 
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
 
 
@@ -70,6 +72,8 @@ public class DictInfoController extends BladeController {
 
 
     private final IDictInfoService dictInfoService;
     private final IDictInfoService dictInfoService;
 
 
+    private final DictInfoMapper dictInfoMapper;
+
     /**
     /**
      * 新增或修改 参数信息表
      * 新增或修改 参数信息表
      */
      */
@@ -77,22 +81,47 @@ public class DictInfoController extends BladeController {
     @ApiOperationSupport(order = 1)
     @ApiOperationSupport(order = 1)
     @ApiOperation(value = "新增或修改", notes = "传入dictInfo")
     @ApiOperation(value = "新增或修改", notes = "传入dictInfo")
     public R submit(@Valid @RequestBody DictInfo dictInfo) {
     public R submit(@Valid @RequestBody DictInfo dictInfo) {
-
+        List<DictInfo> list = new ArrayList<>();
         if (ObjectUtil.isNotEmpty(dictInfo.getId())) {
         if (ObjectUtil.isNotEmpty(dictInfo.getId())) {
             DictInfo dictInfo1 = dictInfoService.getBaseMapper().selectById(dictInfo.getId());
             DictInfo dictInfo1 = dictInfoService.getBaseMapper().selectById(dictInfo.getId());
             if (dictInfo1 != null && dictInfo1.getType().equals(6)) {
             if (dictInfo1 != null && dictInfo1.getType().equals(6)) {
                 throw new ServiceException("没有权限,请联系管理员");
                 throw new ServiceException("没有权限,请联系管理员");
             }
             }
+            list = dictInfoService.list(new LambdaQueryWrapper<DictInfo>()
+                    .eq(DictInfo::getParentId,dictInfo.getParentId() == null ? 0 : dictInfo.getParentId())
+                    .eq(DictInfo::getType,dictInfo.getType())
+                    .ne(DictInfo::getId,dictInfo.getId()));
+            //存在id,校验是否已经被引用过,目前只校验成本测算
+            if (dictInfo.getType() == 5) {
+                Integer linkTotal = dictInfoMapper.getLinkTotal(dictInfo1);
+                if (linkTotal > 0){
+                    return R.fail("编辑失败,当前字典已经被引用过");
+                }
+            }
+        }else {
+            list = dictInfoService.list(new LambdaQueryWrapper<DictInfo>()
+                    .eq(DictInfo::getParentId,dictInfo.getParentId() == null ? 0 : dictInfo.getParentId())
+                    .eq(DictInfo::getType,dictInfo.getType()));
+        }
+        //校验科目值是否与同等级重复
+        if (dictInfo.getType() == 5) {
+            for (DictInfo info : list) {
+                if (info.getDictValue().equals(dictInfo.getDictValue())) {
+                    return R.fail("编辑失败,字典值与其他科目重复");
+                }
+            }
         }
         }
 
 
-        DictInfo dictInfoOne = dictInfoService.getOne(new LambdaQueryWrapper<DictInfo>()
-                        .eq(DictInfo::getDictName, dictInfo.getDictName())
-                        .eq(DictInfo::getType, dictInfo.getType())
-                        .eq(DictInfo::getIsDeleted, 0));
+//        DictInfo dictInfoOne = dictInfoService.getOne(new LambdaQueryWrapper<DictInfo>()
+//                        .eq(DictInfo::getDictName, dictInfo.getDictName())
+//                        .eq(DictInfo::getType, dictInfo.getType())
+//                        .eq(DictInfo::getIsDeleted, 0));
+//
+//        if(dictInfoOne !=null && StringUtil.isNotBlank(dictInfoOne.getId()+"")) {
+//            dictInfoOne.setId(dictInfoOne.getId());
+//        }
 
 
-        if(dictInfoOne !=null && StringUtil.isNotBlank(dictInfoOne.getId()+"")) {
-            dictInfoOne.setId(dictInfoOne.getId());
-        }
+        //判断是新增
 
 
         CacheUtil.clear(DICT_CACHE, Boolean.FALSE);
         CacheUtil.clear(DICT_CACHE, Boolean.FALSE);
         return R.status(dictInfoService.saveOrUpdate(dictInfo));
         return R.status(dictInfoService.saveOrUpdate(dictInfo));
@@ -111,6 +140,13 @@ public class DictInfoController extends BladeController {
         if (dictInfo1 != null && dictInfo1.getType().equals(6)) {
         if (dictInfo1 != null && dictInfo1.getType().equals(6)) {
             throw new ServiceException("没有权限,请联系管理员");
             throw new ServiceException("没有权限,请联系管理员");
         }
         }
+        if (dictInfo1.getType() == 5) {
+            //成本测算校验是否被引用过
+            Integer linkTotal = dictInfoMapper.getLinkTotal(dictInfo1);
+            if (linkTotal > 0) {
+                return R.fail("删除失败,当前字典已经被引用过");
+            }
+        }
         CacheUtil.clear(DICT_CACHE, Boolean.FALSE);
         CacheUtil.clear(DICT_CACHE, Boolean.FALSE);
         return R.status(dictInfoService.removeBatchByIds(Func.toLongList(ids)));
         return R.status(dictInfoService.removeBatchByIds(Func.toLongList(ids)));
     }
     }

+ 4 - 0
blade-service/blade-control/src/main/java/org/springblade/control/mapper/DictInfoMapper.java

@@ -51,4 +51,8 @@ public interface DictInfoMapper extends BaseMapper<DictInfo> {
     List<DictInfo> getDictInfo(@Param("code") String code, @Param("notRoot") String notRoot);
     List<DictInfo> getDictInfo(@Param("code") String code, @Param("notRoot") String notRoot);
 
 
     List<UserVO> selectUserTabPage(IPage page, @Param("excelTab") UserVO userinfo);
     List<UserVO> selectUserTabPage(IPage page, @Param("excelTab") UserVO userinfo);
+
+    Integer getLinkTotal(@Param("dictInfo") DictInfo dictInfo);
+
+
 }
 }

+ 12 - 0
blade-service/blade-control/src/main/java/org/springblade/control/mapper/DictInfoMapper.xml

@@ -35,4 +35,16 @@
         from blade_user
         from blade_user
         where is_deleted = 0
         where is_deleted = 0
     </select>
     </select>
+    <select id="getLinkTotal" resultType="java.lang.Integer">
+        SELECT count(1)
+        from c_project_cost_budget
+        where is_deleted = 0
+        <if test="dictInfo.parentId == 0">
+            and  budget_type = floor(#{dictInfo.dictValue})
+        </if>
+        <if test="dictInfo.parentId != 0">
+            and  budget_type = (select floor(dict_value) from c_dict_info where id = #{dictInfo.parentId})
+            and task_detail = floor(#{dictInfo.dictValue})
+        </if>
+    </select>
 </mapper>
 </mapper>