作者 RuoYi

优化部门父级启用状态

@@ -94,11 +94,11 @@ public interface SysDeptMapper @@ -94,11 +94,11 @@ public interface SysDeptMapper
94 public int updateDept(SysDept dept); 94 public int updateDept(SysDept dept);
95 95
96 /** 96 /**
97 - * 修改所在部门的父级部门状态 97 + * 修改所在部门正常状态
98 * 98 *
99 - * @param dept 部门 99 + * @param deptIds 部门ID组
100 */ 100 */
101 - public void updateDeptStatus(SysDept dept); 101 + public void updateDeptStatusNormal(Long[] deptIds);
102 102
103 /** 103 /**
104 * 修改子元素关系 104 * 修改子元素关系
@@ -11,6 +11,7 @@ import com.ruoyi.common.constant.UserConstants; @@ -11,6 +11,7 @@ import com.ruoyi.common.constant.UserConstants;
11 import com.ruoyi.common.core.domain.TreeSelect; 11 import com.ruoyi.common.core.domain.TreeSelect;
12 import com.ruoyi.common.core.domain.entity.SysDept; 12 import com.ruoyi.common.core.domain.entity.SysDept;
13 import com.ruoyi.common.core.domain.entity.SysRole; 13 import com.ruoyi.common.core.domain.entity.SysRole;
  14 +import com.ruoyi.common.core.text.Convert;
14 import com.ruoyi.common.exception.CustomException; 15 import com.ruoyi.common.exception.CustomException;
15 import com.ruoyi.common.utils.StringUtils; 16 import com.ruoyi.common.utils.StringUtils;
16 import com.ruoyi.system.mapper.SysDeptMapper; 17 import com.ruoyi.system.mapper.SysDeptMapper;
@@ -211,7 +212,7 @@ public class SysDeptServiceImpl implements ISysDeptService @@ -211,7 +212,7 @@ public class SysDeptServiceImpl implements ISysDeptService
211 if (UserConstants.DEPT_NORMAL.equals(dept.getStatus())) 212 if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()))
212 { 213 {
213 // 如果该部门是启用状态,则启用该部门的所有上级部门 214 // 如果该部门是启用状态,则启用该部门的所有上级部门
214 - updateParentDeptStatus(dept); 215 + updateParentDeptStatusNormal(dept);
215 } 216 }
216 return result; 217 return result;
217 } 218 }
@@ -221,12 +222,11 @@ public class SysDeptServiceImpl implements ISysDeptService @@ -221,12 +222,11 @@ public class SysDeptServiceImpl implements ISysDeptService
221 * 222 *
222 * @param dept 当前部门 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 /**
@@ -140,14 +140,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -140,14 +140,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
140 </foreach> 140 </foreach>
141 </update> 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 </update> 148 </update>
152 149
153 <delete id="deleteDeptById" parameterType="Long"> 150 <delete id="deleteDeptById" parameterType="Long">