mirror of https://gitee.com/y_project/RuoYi.git
部门修改同步ancestor
parent
f67d7179cd
commit
fd75ee49d6
|
@ -1,6 +1,7 @@
|
||||||
package com.ruoyi.project.system.dept.mapper;
|
package com.ruoyi.project.system.dept.mapper;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
import com.ruoyi.project.system.dept.domain.Dept;
|
import com.ruoyi.project.system.dept.domain.Dept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,6 +66,14 @@ public interface DeptMapper
|
||||||
*/
|
*/
|
||||||
public int updateDept(Dept dept);
|
public int updateDept(Dept dept);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改子元素关系
|
||||||
|
*
|
||||||
|
* @param depts 子元素
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int updateDeptChildren(@Param("depts") List<Dept> depts);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据部门ID查询信息
|
* 根据部门ID查询信息
|
||||||
*
|
*
|
||||||
|
|
|
@ -135,11 +135,34 @@ public class DeptServiceImpl implements IDeptService
|
||||||
public int updateDept(Dept dept)
|
public int updateDept(Dept dept)
|
||||||
{
|
{
|
||||||
Dept info = deptMapper.selectDeptById(dept.getParentId());
|
Dept info = deptMapper.selectDeptById(dept.getParentId());
|
||||||
|
String ancestors = info.getAncestors() + "," + dept.getParentId();
|
||||||
dept.setUpdateBy(ShiroUtils.getLoginName());
|
dept.setUpdateBy(ShiroUtils.getLoginName());
|
||||||
dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
|
dept.setAncestors(ancestors);
|
||||||
|
updateDeptChildren(dept.getDeptId(), ancestors);
|
||||||
return deptMapper.updateDept(dept);
|
return deptMapper.updateDept(dept);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改子元素关系
|
||||||
|
*
|
||||||
|
* @param deptId 部门ID
|
||||||
|
* @param ancestors 元素列表
|
||||||
|
*/
|
||||||
|
public void updateDeptChildren(Long deptId, String ancestors)
|
||||||
|
{
|
||||||
|
Dept dept = new Dept();
|
||||||
|
dept.setParentId(deptId);
|
||||||
|
List<Dept> childrens = deptMapper.selectDeptList(dept);
|
||||||
|
for (Dept children : childrens)
|
||||||
|
{
|
||||||
|
children.setAncestors(ancestors + "," + dept.getParentId());
|
||||||
|
}
|
||||||
|
if (childrens.size() > 0)
|
||||||
|
{
|
||||||
|
deptMapper.updateDeptChildren(childrens);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据部门ID查询信息
|
* 根据部门ID查询信息
|
||||||
*
|
*
|
||||||
|
|
|
@ -32,6 +32,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<select id="selectDeptList" parameterType="Dept" resultMap="DeptResult">
|
<select id="selectDeptList" parameterType="Dept" resultMap="DeptResult">
|
||||||
<include refid="selectDeptVo"/>
|
<include refid="selectDeptVo"/>
|
||||||
<where>
|
<where>
|
||||||
|
<if test="parentId != null and parentId != 0">
|
||||||
|
AND parent_id = #{parentId}
|
||||||
|
</if>
|
||||||
<if test="deptName != null and deptName != ''">
|
<if test="deptName != null and deptName != ''">
|
||||||
AND dept_name like concat('%', #{deptName}, '%')
|
AND dept_name like concat('%', #{deptName}, '%')
|
||||||
</if>
|
</if>
|
||||||
|
@ -110,6 +113,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
where dept_id = #{deptId}
|
where dept_id = #{deptId}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
|
||||||
<delete id="deleteDeptById" parameterType="Long">
|
<delete id="deleteDeptById" parameterType="Long">
|
||||||
delete from sys_dept where dept_id = #{deptId}
|
delete from sys_dept where dept_id = #{deptId}
|
||||||
</delete>
|
</delete>
|
||||||
|
|
Loading…
Reference in New Issue