diff --git a/bonus-modules/bonus-system/src/main/java/com/bonus/system/service/impl/SysDeptServiceImpl.java b/bonus-modules/bonus-system/src/main/java/com/bonus/system/service/impl/SysDeptServiceImpl.java index 2245b67..a3c53d4 100644 --- a/bonus-modules/bonus-system/src/main/java/com/bonus/system/service/impl/SysDeptServiceImpl.java +++ b/bonus-modules/bonus-system/src/main/java/com/bonus/system/service/impl/SysDeptServiceImpl.java @@ -351,11 +351,8 @@ public class SysDeptServiceImpl implements ISysDeptService String oldAncestors = oldDept.getAncestors(); dept.setAncestors(newAncestors); updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors); - String newDeptFullNames = newParentDept.getDeptFullName() + "/" + dept.getDeptName(); - String oldDeptFullNames = oldDept.getDeptFullName(); - dept.setDeptFullName(newDeptFullNames); - updateDeptChildrenFullName(dept.getDeptId(), newDeptFullNames, oldDeptFullNames); } + updateDeptChildrenFullName(dept, newParentDept); int result = deptMapper.updateDept(dept); if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors()) && !StringUtils.equals("0", dept.getAncestors())) @@ -409,15 +406,34 @@ public class SysDeptServiceImpl implements ISysDeptService } } - public void updateDeptChildrenFullName(Long deptId, String newFullNames, String oldFullNames) + public void updateDeptChildrenFullName(SysDept dept, SysDept newParentDept) { - List children = deptMapper.selectChildrenDeptById(deptId); - for (SysDept child : children) - { - child.setDeptFullName(child.getDeptFullName().replaceFirst(oldFullNames, newFullNames)); + if (Objects.isNull(newParentDept)) { + dept.setDeptFullName(dept.getDeptName()); + } else { + dept.setDeptFullName(newParentDept.getDeptFullName() + "/" + dept.getDeptName()); } - if (children.size() > 0) - { + List children = deptMapper.selectChildrenDeptById(dept.getDeptId()); + List fullDeptList = deptMapper.selectDeptList(new SysDept()); + for (SysDept innerDept : fullDeptList) { + if (innerDept.getDeptId().equals(dept.getDeptId())) { + innerDept.setDeptName(dept.getDeptName()); + } + } + for (SysDept child : children) { + if (child.getDeptId().equals(dept.getDeptId())) { + child.setDeptName(dept.getDeptName()); + } + } + for (SysDept child : children) { + String deptAncestors = child.getAncestors(); + deptAncestors = deptAncestors.replaceFirst("0,", "").replaceAll(",", "/"); + for (SysDept innerDept : fullDeptList) { + deptAncestors = deptAncestors.replace(String.valueOf(innerDept.getDeptId()), innerDept.getDeptName()); + } + child.setDeptFullName(deptAncestors + "/" + child.getDeptName()); + } + if (children.size() > 0) { deptMapper.updateDeptChildrenFullName(children); } }