From 4b7737845839f58b56b9e34a1b69955eed1f3ba3 Mon Sep 17 00:00:00 2001
From: RuoYi <yzz_ivy@163.com>
Date: Thu, 7 May 2020 12:00:09 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=A0=A1=E9=AA=8C=E9=83=A8?=
 =?UTF-8?q?=E9=97=A8=E5=8C=85=E5=90=AB=E6=9C=AA=E5=81=9C=E7=94=A8=E7=9A=84?=
 =?UTF-8?q?=E5=AD=90=E9=83=A8=E9=97=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../java/com/ruoyi/common/constant/UserConstants.java |  7 +++++--
 .../project/system/controller/SysDeptController.java  |  6 ++++++
 .../ruoyi/project/system/mapper/SysDeptMapper.java    |  8 ++++++++
 .../ruoyi/project/system/service/ISysDeptService.java |  8 ++++++++
 .../system/service/impl/SysDeptServiceImpl.java       | 11 +++++++++++
 .../main/resources/mybatis/system/SysDeptMapper.xml   |  4 ++++
 6 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/ruoyi/src/main/java/com/ruoyi/common/constant/UserConstants.java b/ruoyi/src/main/java/com/ruoyi/common/constant/UserConstants.java
index 9164cd2..03f12e7 100644
--- a/ruoyi/src/main/java/com/ruoyi/common/constant/UserConstants.java
+++ b/ruoyi/src/main/java/com/ruoyi/common/constant/UserConstants.java
@@ -19,13 +19,16 @@ 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/src/main/java/com/ruoyi/project/system/controller/SysDeptController.java b/ruoyi/src/main/java/com/ruoyi/project/system/controller/SysDeptController.java
index 686748a..21b0576 100644
--- a/ruoyi/src/main/java/com/ruoyi/project/system/controller/SysDeptController.java
+++ b/ruoyi/src/main/java/com/ruoyi/project/system/controller/SysDeptController.java
@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 import com.ruoyi.common.constant.UserConstants;
 import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.framework.aspectj.lang.annotation.Log;
 import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
 import com.ruoyi.framework.web.controller.BaseController;
@@ -109,6 +110,11 @@ public class SysDeptController extends BaseController
         {
             return AjaxResult.error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己");
         }
+        else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus())
+                && deptService.selectNormalChildrenDeptById(dept.getDeptId()) > 0)
+        {
+            return AjaxResult.error("该部门包含未停用的子部门!");
+        }
         dept.setUpdateBy(SecurityUtils.getUsername());
         return toAjax(deptService.updateDept(dept));
     }
diff --git a/ruoyi/src/main/java/com/ruoyi/project/system/mapper/SysDeptMapper.java b/ruoyi/src/main/java/com/ruoyi/project/system/mapper/SysDeptMapper.java
index 7dac0cb..113db29 100644
--- a/ruoyi/src/main/java/com/ruoyi/project/system/mapper/SysDeptMapper.java
+++ b/ruoyi/src/main/java/com/ruoyi/project/system/mapper/SysDeptMapper.java
@@ -43,6 +43,14 @@ public interface SysDeptMapper
      */
     public List<SysDept> selectChildrenDeptById(Long deptId);
 
+    /**
+     * 根据ID查询所有子部门(正常状态)
+     * 
+     * @param deptId 部门ID
+     * @return 子部门数
+     */
+    public int selectNormalChildrenDeptById(Long deptId);
+
     /**
      * 是否存在子节点
      * 
diff --git a/ruoyi/src/main/java/com/ruoyi/project/system/service/ISysDeptService.java b/ruoyi/src/main/java/com/ruoyi/project/system/service/ISysDeptService.java
index 1d8a306..5f59b8a 100644
--- a/ruoyi/src/main/java/com/ruoyi/project/system/service/ISysDeptService.java
+++ b/ruoyi/src/main/java/com/ruoyi/project/system/service/ISysDeptService.java
@@ -51,6 +51,14 @@ public interface ISysDeptService
      */
     public SysDept selectDeptById(Long deptId);
 
+    /**
+     * 根据ID查询所有子部门(正常状态)
+     * 
+     * @param deptId 部门ID
+     * @return 子部门数
+     */
+    public int selectNormalChildrenDeptById(Long deptId);
+
     /**
      * 是否存在部门子节点
      * 
diff --git a/ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysDeptServiceImpl.java b/ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysDeptServiceImpl.java
index 338e2a6..3834898 100644
--- a/ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysDeptServiceImpl.java
+++ b/ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysDeptServiceImpl.java
@@ -108,6 +108,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/src/main/resources/mybatis/system/SysDeptMapper.xml b/ruoyi/src/main/resources/mybatis/system/SysDeptMapper.xml
index 247bb69..220572d 100644
--- a/ruoyi/src/main/resources/mybatis/system/SysDeptMapper.xml
+++ b/ruoyi/src/main/resources/mybatis/system/SysDeptMapper.xml
@@ -71,6 +71,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		select * from sys_dept where find_in_set(#{deptId}, ancestors)
 	</select>
 	
+	<select id="selectNormalChildrenDeptById" parameterType="Long" resultType="java.lang.Integer">
+		select count(*) from sys_dept where status = 0 and del_flag = '0' and find_in_set(#{deptId}, ancestors)
+	</select>
+	
 	<select id="checkDeptNameUnique" resultMap="SysDeptResult">
 	    <include refid="selectDeptVo"/>
 		where dept_name=#{deptName} and parent_id = #{parentId}