Commit fd75ee49 by RuoYi

部门修改同步ancestor

parent f67d7179
package com.ruoyi.project.system.dept.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.ruoyi.project.system.dept.domain.Dept;
/**
......@@ -66,6 +67,14 @@ public interface DeptMapper
public int updateDept(Dept dept);
/**
* 修改子元素关系
*
* @param depts 子元素
* @return 结果
*/
public int updateDeptChildren(@Param("depts") List<Dept> depts);
/**
* 根据部门ID查询信息
*
* @param deptId 部门ID
......
......@@ -135,12 +135,35 @@ public class DeptServiceImpl implements IDeptService
public int updateDept(Dept dept)
{
Dept info = deptMapper.selectDeptById(dept.getParentId());
String ancestors = info.getAncestors() + "," + dept.getParentId();
dept.setUpdateBy(ShiroUtils.getLoginName());
dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
dept.setAncestors(ancestors);
updateDeptChildren(dept.getDeptId(), ancestors);
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查询信息
*
* @param deptId 部门ID
......
......@@ -32,6 +32,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectDeptList" parameterType="Dept" resultMap="DeptResult">
<include refid="selectDeptVo"/>
<where>
<if test="parentId != null and parentId != 0">
AND parent_id = #{parentId}
</if>
<if test="deptName != null and deptName != ''">
AND dept_name like concat('%', #{deptName}, '%')
</if>
......@@ -109,6 +112,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</set>
where dept_id = #{deptId}
</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 from sys_dept where dept_id = #{deptId}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment