部门修改同步ancestor

master
RuoYi 6 years ago committed by Limy
parent 7766f83d0a
commit 5dfc09eefc

@ -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>
@ -109,6 +112,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</set> </set>
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}

Loading…
Cancel
Save