From c1d01fb1e1a0aadab46afd568f61f89bcd8bb9ad Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期五, 04 三月 2022 09:26:26 +0800
Subject: [PATCH] update 优化 部门修改子元素关系 使用批量更新
---
ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml | 13 -------------
ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java | 8 --------
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java | 11 ++++++++---
3 files changed, 8 insertions(+), 24 deletions(-)
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 dcd7ea7..7e7a441 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
@@ -37,12 +37,4 @@
*/
List<Long> selectDeptListByRoleId(@Param("roleId") Long roleId, @Param("deptCheckStrictly") boolean deptCheckStrictly);
- /**
- * 淇敼瀛愬厓绱犲叧绯�
- *
- * @param depts 瀛愬厓绱�
- * @return 缁撴灉
- */
- int updateDeptChildren(@Param("depts") List<SysDept> depts);
-
}
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 ac9f782..3875c91 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
@@ -21,6 +21,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -234,11 +235,15 @@
public void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors) {
List<SysDept> children = baseMapper.selectList(new LambdaQueryWrapper<SysDept>()
.apply("find_in_set({0},ancestors)", deptId));
+ List<SysDept> list = new ArrayList<>();
for (SysDept child : children) {
- child.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors));
+ SysDept dept = new SysDept();
+ dept.setDeptId(child.getDeptId());
+ dept.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors));
+ list.add(dept);
}
- if (children.size() > 0) {
- baseMapper.updateDeptChildren(children);
+ if (list.size() > 0) {
+ baseMapper.updateBatchById(list);
}
}
diff --git a/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml
index 35bd1ce..00493be 100644
--- a/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml
+++ b/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml
@@ -37,17 +37,4 @@
order by d.parent_id, d.order_num
</select>
- <update id="updateDeptChildren" parameterType="java.util.List">
- update sys_dept set ancestors =
- <foreach collection="depts" item="item" index="index"
- separator=" " open="case dept_id" close="end">
- when #{item.deptId} then #{item.ancestors}
- </foreach>
- where dept_id in
- <foreach collection="depts" item="item" index="index"
- separator="," open="(" close=")">
- #{item.deptId}
- </foreach>
- </update>
-
</mapper>
--
Gitblit v1.9.3