部门代码优化

This commit is contained in:
none
2023-02-25 11:18:09 +08:00
parent bfa1040a54
commit 5672c70ccb
7 changed files with 69 additions and 83 deletions

View File

@@ -1,41 +0,0 @@
package xyz.playedu.api.bus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import xyz.playedu.api.domain.Department;
import xyz.playedu.api.exception.NotFoundException;
import xyz.playedu.api.service.DepartmentService;
/**
* @Author 杭州白书科技有限公司
* @create 2023/2/19 11:02
*/
@Component
public class DepartmentBus {
@Autowired
private DepartmentService departmentService;
public String compParentChain(Integer parentId) throws NotFoundException {
String parentChain = "";
if (parentId != 0) {
Department parentDepartment = departmentService.getById(parentId);
if (parentDepartment == null) {
throw new NotFoundException("父级部门不存在");
}
String pc = parentDepartment.getParentChain();
parentChain = pc == null || pc.length() == 0 ? parentId + "" : pc + "," + parentId;
}
return parentChain;
}
public static String childrenParentChain(Department department) {
String prefix = department.getId() + "";
if (department.getParentChain() != null && department.getParentChain().length() > 0) {
prefix = department.getParentChain() + "," + prefix;
}
return prefix;
}
}