fix(ruoyi-system):修复修改部门层级BUG

Closes https://gitee.com/y_project/RuoYi/issues/IW1SB
dep_wangsr
zbz 6 years ago committed by Limy
parent 26be7a7bd1
commit 00bf5aa847

@ -98,4 +98,11 @@ public interface SysDeptMapper
* @param dept * @param dept
*/ */
public void updateDeptStatus(SysDept dept); public void updateDeptStatus(SysDept dept);
/**
* ID
* @param id
* @return
*/
public List<SysDept> selectChildrenDeptById(Long id);
} }

@ -185,15 +185,17 @@ public class SysDeptServiceImpl implements ISysDeptService
* @return * @return
*/ */
@Override @Override
@Transactional @Transactional(rollbackFor = Exception.class)
public int updateDept(SysDept dept) public int updateDept(SysDept dept)
{ {
SysDept info = deptMapper.selectDeptById(dept.getParentId()); SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId());
if (StringUtils.isNotNull(info)) SysDept oldDept = selectDeptById(dept.getDeptId());
if (StringUtils.isNotNull(newParentDept) && StringUtils.isNotNull(oldDept))
{ {
String ancestors = info.getAncestors() + "," + info.getDeptId(); String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId();
dept.setAncestors(ancestors); String oldAncestors = oldDept.getAncestors();
updateDeptChildren(dept.getDeptId(), ancestors); dept.setAncestors(newAncestors);
updateDeptChildren(dept.getDeptId(), newAncestors,oldAncestors);
} }
int result = deptMapper.updateDept(dept); int result = deptMapper.updateDept(dept);
if (UserConstants.DEPT_NORMAL.equals(dept.getStatus())) if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()))
@ -219,22 +221,20 @@ public class SysDeptServiceImpl implements ISysDeptService
/** /**
* *
* * @param deptId ID
* @param deptId ID * @param newAncestors ID
* @param ancestors * @param oldAncestors ID
*/ */
public void updateDeptChildren(Long deptId, String ancestors) public void updateDeptChildren(Long deptId, String newAncestors,String oldAncestors)
{ {
SysDept dept = new SysDept(); List<SysDept> children = deptMapper.selectChildrenDeptById(deptId);
dept.setParentId(deptId); for (SysDept child : children)
List<SysDept> childrens = deptMapper.selectDeptList(dept);
for (SysDept children : childrens)
{ {
children.setAncestors(ancestors + "," + dept.getParentId()); child.setAncestors(child.getAncestors().replace(oldAncestors,newAncestors));
} }
if (childrens.size() > 0) if (children.size() > 0)
{ {
deptMapper.updateDeptChildren(childrens); deptMapper.updateDeptChildren(children);
} }
} }

@ -75,6 +75,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where d.dept_id = #{deptId} where d.dept_id = #{deptId}
</select> </select>
<select id="selectChildrenDeptById" parameterType="Long" resultMap="SysDeptResult">
select * from sys_dept
<where>
FIND_IN_SET(#{id},ancestors)
</where>
</select>
<insert id="insertDept" parameterType="SysDept"> <insert id="insertDept" parameterType="SysDept">
insert into sys_dept( insert into sys_dept(
<if test="deptId != null and deptId != 0">dept_id,</if> <if test="deptId != null and deptId != 0">dept_id,</if>

Loading…
Cancel
Save