public void updateWithChild(SysDept before, SysDept after) {
String newLevelPrefix = after.getLevel();
String oldLevelPrefix = before.getLevel();
if (!after.getLevel().equals(before.getLevel())) {
String curLevel = before.getLevel() + "." + before.getId();
List<SysDept> deptList = sysDeptMapper.getChildDeptListByLevel(curLevel + "%");
if (CollectionUtils.isNotEmpty(deptList)) {
for (SysDept dept : deptList) {
String level = dept.getLevel();
if (level.equals(curLevel) || level.indexOf(curLevel + ".") == 0) {
// getChildAclModuleListByLevel可能会取出多余的内容,因此需要加个判断
// 比如0.1* 可能取出0.1、0.1.3、0.11、0.11.3,而期望取出 0.1、0.1.3, 因此呢需要判断等于0.1或者以0.1.为前缀才满足条件
level = newLevelPrefix + level.substring(oldLevelPrefix.length());
dept.setLevel(level);
}
}
sysDeptMapper.batchUpdateLevel(deptList);
}
}
sysDeptMapper.updateByPrimaryKey(after);
}
<select id="getChildDeptListByLevel" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from sys_dept
WHERE level like #{level}
</select>