mirror of https://gitee.com/y_project/RuoYi.git
commit
06f2fa25c0
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,6 +74,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
from sys_dept d
|
from sys_dept d
|
||||||
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(
|
||||||
|
|
Loading…
Reference in New Issue