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

Closes https://gitee.com/y_project/RuoYi/issues/IW1SB
pull/86/head
zbz 6 years ago
parent b8d1b54e22
commit 962ab735b5

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

@ -74,6 +74,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
from sys_dept d
where d.dept_id = #{deptId}
</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 into sys_dept(

Loading…
Cancel
Save