Commit 4b7737845839f58b56b9e34a1b69955eed1f3ba3

Authored by RuoYi
1 parent 066d3f3f

添加校验部门包含未停用的子部门

ruoyi/src/main/java/com/ruoyi/common/constant/UserConstants.java
... ... @@ -19,13 +19,16 @@ public class UserConstants
19 19 public static final String EXCEPTION = "1";
20 20  
21 21 /** 用户封禁状态 */
22   - public static final String USER_BLOCKED = "1";
  22 + public static final String USER_DISABLE = "1";
23 23  
24 24 /** 角色封禁状态 */
25   - public static final String ROLE_BLOCKED = "1";
  25 + public static final String ROLE_DISABLE = "1";
26 26  
27 27 /** 部门正常状态 */
28 28 public static final String DEPT_NORMAL = "0";
  29 +
  30 + /** 部门停用状态 */
  31 + public static final String DEPT_DISABLE = "1";
29 32  
30 33 /** 字典正常状态 */
31 34 public static final String DICT_NORMAL = "0";
... ...
ruoyi/src/main/java/com/ruoyi/project/system/controller/SysDeptController.java
... ... @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
14 14 import org.springframework.web.bind.annotation.RestController;
15 15 import com.ruoyi.common.constant.UserConstants;
16 16 import com.ruoyi.common.utils.SecurityUtils;
  17 +import com.ruoyi.common.utils.StringUtils;
17 18 import com.ruoyi.framework.aspectj.lang.annotation.Log;
18 19 import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
19 20 import com.ruoyi.framework.web.controller.BaseController;
... ... @@ -109,6 +110,11 @@ public class SysDeptController extends BaseController
109 110 {
110 111 return AjaxResult.error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己");
111 112 }
  113 + else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus())
  114 + && deptService.selectNormalChildrenDeptById(dept.getDeptId()) > 0)
  115 + {
  116 + return AjaxResult.error("该部门包含未停用的子部门!");
  117 + }
112 118 dept.setUpdateBy(SecurityUtils.getUsername());
113 119 return toAjax(deptService.updateDept(dept));
114 120 }
... ...
ruoyi/src/main/java/com/ruoyi/project/system/mapper/SysDeptMapper.java
... ... @@ -44,6 +44,14 @@ public interface SysDeptMapper
44 44 public List<SysDept> selectChildrenDeptById(Long deptId);
45 45  
46 46 /**
  47 + * 根据ID查询所有子部门(正常状态)
  48 + *
  49 + * @param deptId 部门ID
  50 + * @return 子部门数
  51 + */
  52 + public int selectNormalChildrenDeptById(Long deptId);
  53 +
  54 + /**
47 55 * 是否存在子节点
48 56 *
49 57 * @param deptId 部门ID
... ...
ruoyi/src/main/java/com/ruoyi/project/system/service/ISysDeptService.java
... ... @@ -52,6 +52,14 @@ public interface ISysDeptService
52 52 public SysDept selectDeptById(Long deptId);
53 53  
54 54 /**
  55 + * 根据ID查询所有子部门(正常状态)
  56 + *
  57 + * @param deptId 部门ID
  58 + * @return 子部门数
  59 + */
  60 + public int selectNormalChildrenDeptById(Long deptId);
  61 +
  62 + /**
55 63 * 是否存在部门子节点
56 64 *
57 65 * @param deptId 部门ID
... ...
ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysDeptServiceImpl.java
... ... @@ -109,6 +109,17 @@ public class SysDeptServiceImpl implements ISysDeptService
109 109 }
110 110  
111 111 /**
  112 + * 根据ID查询所有子部门(正常状态)
  113 + *
  114 + * @param deptId 部门ID
  115 + * @return 子部门数
  116 + */
  117 + public int selectNormalChildrenDeptById(Long deptId)
  118 + {
  119 + return deptMapper.selectNormalChildrenDeptById(deptId);
  120 + }
  121 +
  122 + /**
112 123 * 是否存在子节点
113 124 *
114 125 * @param deptId 部门ID
... ...
ruoyi/src/main/resources/mybatis/system/SysDeptMapper.xml
... ... @@ -71,6 +71,10 @@ PUBLIC &quot;-//mybatis.org//DTD Mapper 3.0//EN&quot;
71 71 select * from sys_dept where find_in_set(#{deptId}, ancestors)
72 72 </select>
73 73  
  74 + <select id="selectNormalChildrenDeptById" parameterType="Long" resultType="java.lang.Integer">
  75 + select count(*) from sys_dept where status = 0 and del_flag = '0' and find_in_set(#{deptId}, ancestors)
  76 + </select>
  77 +
74 78 <select id="checkDeptNameUnique" resultMap="SysDeptResult">
75 79 <include refid="selectDeptVo"/>
76 80 where dept_name=#{deptName} and parent_id = #{parentId}
... ...