diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java index bb17d9f3b..83a589274 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java @@ -112,6 +112,11 @@ public class SysDeptController extends BaseController { return error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己"); } + else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus()) + && deptService.selectNormalChildrenDeptById(dept.getDeptId()) > 0) + { + return AjaxResult.error("该部门包含未停用的子部门!"); + } dept.setUpdateBy(ShiroUtils.getLoginName()); return toAjax(deptService.updateDept(dept)); } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/constant/UserConstants.java b/ruoyi-common/src/main/java/com/ruoyi/common/constant/UserConstants.java index d768aa627..336652481 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/constant/UserConstants.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/constant/UserConstants.java @@ -19,14 +19,17 @@ public class UserConstants public static final String EXCEPTION = "1"; /** 用户封禁状态 */ - public static final String USER_BLOCKED = "1"; + public static final String USER_DISABLE = "1"; /** 角色封禁状态 */ - public static final String ROLE_BLOCKED = "1"; + public static final String ROLE_DISABLE = "1"; /** 部门正常状态 */ public static final String DEPT_NORMAL = "0"; + /** 部门停用状态 */ + public static final String DEPT_DISABLE = "1"; + /** 字典正常状态 */ public static final String DICT_NORMAL = "0"; diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java index 3dcc9713d..897400761 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java @@ -101,8 +101,17 @@ public interface SysDeptMapper /** * 根据ID查询所有子部门 + * * @param deptId 部门ID * @return 部门列表 */ public List selectChildrenDeptById(Long deptId); + + /** + * 根据ID查询所有子部门(正常状态) + * + * @param deptId 部门ID + * @return 子部门数 + */ + public int selectNormalChildrenDeptById(Long deptId); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java index 6e75df247..76c1169cf 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java @@ -84,6 +84,14 @@ public interface ISysDeptService */ public SysDept selectDeptById(Long deptId); + /** + * 根据ID查询所有子部门(正常状态) + * + * @param deptId 部门ID + * @return 子部门数 + */ + public int selectNormalChildrenDeptById(Long deptId); + /** * 校验部门名称是否唯一 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java index 422b33643..61528a306 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java @@ -251,6 +251,17 @@ public class SysDeptServiceImpl implements ISysDeptService return deptMapper.selectDeptById(deptId); } + /** + * 根据ID查询所有子部门(正常状态) + * + * @param deptId 部门ID + * @return 子部门数 + */ + public int selectNormalChildrenDeptById(Long deptId) + { + return deptMapper.selectNormalChildrenDeptById(deptId); + } + /** * 校验部门名称是否唯一 * diff --git a/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml index 02a1017c5..bb018a730 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml @@ -79,6 +79,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select * from sys_dept where find_in_set(#{deptId}, ancestors) + + insert into sys_dept( dept_id,