|
@@ -14,6 +14,7 @@ import com.persagy.fm.common.constant.enums.BoolEnum;
|
|
|
import com.persagy.fm.common.constant.enums.ValidEnum;
|
|
|
import com.persagy.fm.common.context.DefaultAppContext;
|
|
|
import com.persagy.fm.common.model.dto.Sort;
|
|
|
+import com.persagy.fm.department.constant.DepConstants;
|
|
|
import com.persagy.fm.department.constant.enums.DepTypeEnum;
|
|
|
import com.persagy.fm.department.constant.enums.ResourceFromEnum;
|
|
|
import com.persagy.fm.department.dao.DepartmentMapper;
|
|
@@ -198,7 +199,7 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
!DepTypeEnum.GROUP.getType().equals(updateDepartmentDTO.getType())) {
|
|
|
throw new IllegalArgumentException("部门类型不可编辑");
|
|
|
}
|
|
|
- // 部门名称或者父部门id发生变化,需要更新子部门的全路径
|
|
|
+ // 部门名称或者父部门id发生变化,对上级部门进行校验,需要更新子部门的全路径。
|
|
|
String fullPathAfterChange = getFullPathAfterChange(updateDepartmentDTO, department);
|
|
|
updateSonDepsFullPath(department.getFullPath(), fullPathAfterChange);
|
|
|
|
|
@@ -226,6 +227,7 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 对上级部门进行校验
|
|
|
* 获取更新后的部门全路径
|
|
|
*
|
|
|
* @param updateDepartmentDTO 更新人员入参
|
|
@@ -250,14 +252,19 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
}
|
|
|
|
|
|
// 如果上级部门发生了变化,级联更新自己和子部门的全路径
|
|
|
- if (StringUtils.isNotBlank(updateDepartmentDTO.getParentId())) {
|
|
|
- if (updateDepartmentDTO.getParentId().equals(department.getId())) {
|
|
|
- throw new IllegalArgumentException("父部门不能选择自己");
|
|
|
+ String parentIdAfterChange = updateDepartmentDTO.getParentId();
|
|
|
+ if (StringUtils.isNotBlank(parentIdAfterChange)) {
|
|
|
+ // 上级部门不能是自己的子部门
|
|
|
+ Department parentDepAfterChange = queryDepartmentDetail(parentIdAfterChange);
|
|
|
+ String parentFullPathAfterChange = parentDepAfterChange.getFullPath();
|
|
|
+ if (parentFullPathAfterChange.equals(department.getFullPath()) ||
|
|
|
+ parentFullPathAfterChange.startsWith(department.getFullPath() + DepConstants.FULL_PATH_SEPARATOR)) {
|
|
|
+ throw new IllegalArgumentException("上级部门不能选择自己或自己的子部门(包括子部门的子部门)");
|
|
|
}
|
|
|
|
|
|
- if (!updateDepartmentDTO.getParentId().equals(parentIdBeforeChange)) {
|
|
|
+ if (!parentIdAfterChange.equals(parentIdBeforeChange)) {
|
|
|
fullPathAfterChange = getDepFullPathWhenParentIdChange(
|
|
|
- nameAfterChange, updateDepartmentDTO.getParentId());
|
|
|
+ nameAfterChange, parentIdAfterChange);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -274,7 +281,6 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
* @version V1.0 2021/4/11 7:30 下午
|
|
|
*/
|
|
|
private String getDepFullPathWhenParentIdChange(String depName, String parentIdAfterChange) {
|
|
|
- String separator = "-";
|
|
|
// 获取更新后的父部门的全路径
|
|
|
Department parentDep = queryDepartmentDetail(parentIdAfterChange);
|
|
|
String parentFullPath = parentDep.getFullPath();
|
|
@@ -282,7 +288,7 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
if (StringUtils.isBlank(parentFullPath)) {
|
|
|
return depName;
|
|
|
} else {
|
|
|
- return parentFullPath + separator + depName;
|
|
|
+ return parentFullPath + DepConstants.FULL_PATH_SEPARATOR + depName;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -336,16 +342,15 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
* @version V1.0 2021/4/11 7:27 下午
|
|
|
*/
|
|
|
private void updateSonDepsFullPath(String fullPathBeforeChange, String fullPathAfterChange) {
|
|
|
- String separator = "-";
|
|
|
// 根据部门全路径查询子部门
|
|
|
QueryDepartmentDTO queryDepartmentDTO = new QueryDepartmentDTO();
|
|
|
- queryDepartmentDTO.setFullPath(fullPathBeforeChange + separator);
|
|
|
+ queryDepartmentDTO.setFullPath(fullPathBeforeChange + DepConstants.FULL_PATH_SEPARATOR);
|
|
|
List<Department> sonDeps = queryDepartmentList(queryDepartmentDTO);
|
|
|
// 修改子部门全路径
|
|
|
for (Department sonDep : sonDeps) {
|
|
|
String tmpFullPath = sonDep.getFullPath();
|
|
|
- tmpFullPath = tmpFullPath.replaceFirst(fullPathBeforeChange + separator,
|
|
|
- fullPathAfterChange + separator);
|
|
|
+ tmpFullPath = tmpFullPath.replaceFirst(fullPathBeforeChange + DepConstants.FULL_PATH_SEPARATOR,
|
|
|
+ fullPathAfterChange + DepConstants.FULL_PATH_SEPARATOR);
|
|
|
sonDep.setFullPath(tmpFullPath);
|
|
|
}
|
|
|
|