diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java index a3f3acef..6f0b4518 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java @@ -37,12 +37,4 @@ public interface SysDeptMapper extends BaseMapperPlus selectDeptListByRoleId(@Param("roleId") Long roleId, @Param("deptCheckStrictly") boolean deptCheckStrictly); - /** - * 修改子元素关系 - * - * @param depts 子元素 - * @return 结果 - */ - int updateDeptChildren(@Param("depts") List depts); - } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java index f99bd455..ecf2de80 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java @@ -21,6 +21,7 @@ import com.ruoyi.system.service.ISysDeptService; 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 class SysDeptServiceImpl implements ISysDeptService { public void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors) { List children = baseMapper.selectList(new LambdaQueryWrapper() .apply("find_in_set({0},ancestors)", deptId)); + List 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-modules/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml index 9f5416f8..f599db02 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml @@ -37,17 +37,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" order by d.parent_id, d.order_num - - update sys_dept set ancestors = - - when #{item.deptId} then #{item.ancestors} - - where dept_id in - - #{item.deptId} - - -