Sfoglia il codice sorgente

优化部门父级启用状态

RuoYi 4 anni fa
parent
commit
41b7e62b02

+ 3 - 3
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java

@@ -96,11 +96,11 @@ public interface SysDeptMapper
96 96
     public int updateDept(SysDept dept);
97 97
 
98 98
     /**
99
-     * 修改所在部门的父级部门状态
99
+     * 修改所在部门正常状态
100 100
      * 
101
-     * @param dept 部门
101
+     * @param deptIds 部门ID组
102 102
      */
103
-    public void updateDeptStatus(SysDept dept);
103
+    public void updateDeptStatusNormal(Long[] deptIds);
104 104
 
105 105
     /**
106 106
      * 修改子元素关系

+ 6 - 6
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java

@@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
8 8
 import org.springframework.stereotype.Service;
9 9
 import com.ruoyi.common.core.constant.UserConstants;
10 10
 import com.ruoyi.common.core.exception.CustomException;
11
+import com.ruoyi.common.core.text.Convert;
11 12
 import com.ruoyi.common.core.utils.StringUtils;
12 13
 import com.ruoyi.common.datascope.annotation.DataScope;
13 14
 import com.ruoyi.system.api.domain.SysDept;
@@ -211,7 +212,7 @@ public class SysDeptServiceImpl implements ISysDeptService
211 212
         if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()))
212 213
         {
213 214
             // 如果该部门是启用状态,则启用该部门的所有上级部门
214
-            updateParentDeptStatus(dept);
215
+            updateParentDeptStatusNormal(dept);
215 216
         }
216 217
         return result;
217 218
     }
@@ -221,12 +222,11 @@ public class SysDeptServiceImpl implements ISysDeptService
221 222
      * 
222 223
      * @param dept 当前部门
223 224
      */
224
-    private void updateParentDeptStatus(SysDept dept)
225
+    private void updateParentDeptStatusNormal(SysDept dept)
225 226
     {
226
-        String updateBy = dept.getUpdateBy();
227
-        dept = deptMapper.selectDeptById(dept.getDeptId());
228
-        dept.setUpdateBy(updateBy);
229
-        deptMapper.updateDeptStatus(dept);
227
+        String ancestors = dept.getAncestors();
228
+        Long[] deptIds = Convert.toLongArray(ancestors);
229
+        deptMapper.updateDeptStatusNormal(deptIds);
230 230
     }
231 231
 
232 232
     /**

+ 5 - 8
ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml

@@ -140,14 +140,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
140 140
 	    </foreach>
141 141
 	</update>
142 142
 	 
143
-	 <update id="updateDeptStatus" parameterType="SysDept">
144
- 	    update sys_dept
145
- 	    <set>
146
- 	        <if test="status != null and status != ''">status = #{status},</if>
147
- 	        <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
148
- 	        update_time = sysdate()
149
-        </set>
150
- 	    where find_in_set(#{deptId}, ancestors)
143
+	<update id="updateDeptStatusNormal" parameterType="Long">
144
+ 	    update sys_dept set status = '0' where dept_id in 
145
+ 	    <foreach collection="array" item="deptId" open="(" separator="," close=")">
146
+        	#{deptId}
147
+        </foreach>
151 148
 	</update>
152 149
 	
153 150
 	<delete id="deleteDeptById" parameterType="Long">