|
@@ -11,9 +11,7 @@ import cn.efunbox.manage.common.utils.SnowflakeIdUtil;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Objects;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
* DepartmentServiceImpl
|
|
* DepartmentServiceImpl
|
|
@@ -44,7 +42,6 @@ public class DepartmentServiceImpl implements DepartmentService {
|
|
if(department ==null){
|
|
if(department ==null){
|
|
return ApiResult.error(ApiCode.PARAMETER_ERROR);
|
|
return ApiResult.error(ApiCode.PARAMETER_ERROR);
|
|
}
|
|
}
|
|
- department.setId(SnowflakeIdUtil.getSnowflakeIdUtil().nextId());
|
|
|
|
department = departmentRepository.save(department);
|
|
department = departmentRepository.save(department);
|
|
if(Objects.nonNull(department)){
|
|
if(Objects.nonNull(department)){
|
|
return ApiResult.ok(department);
|
|
return ApiResult.ok(department);
|
|
@@ -69,7 +66,21 @@ public class DepartmentServiceImpl implements DepartmentService {
|
|
public ApiResult getDeptChild(Long deptId) {
|
|
public ApiResult getDeptChild(Long deptId) {
|
|
List<Department> departments = new ArrayList<>();
|
|
List<Department> departments = new ArrayList<>();
|
|
departments = deptChild(deptId,departments);
|
|
departments = deptChild(deptId,departments);
|
|
- departments.add(departmentRepository.find(deptId));
|
|
|
|
|
|
+ List<Long> deptIds = new ArrayList<>();
|
|
|
|
+ departments.stream().forEach(department -> {
|
|
|
|
+ deptIds.add(department.getId());
|
|
|
|
+ });
|
|
|
|
+ Map<Long, Department> departmentMap = new HashMap<>();
|
|
|
|
+ List<Department> departmentList = departmentRepository.findByIds(deptIds);
|
|
|
|
+ departmentList.stream().forEach(department -> {
|
|
|
|
+ departmentMap.put(department.getId(), department);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ departments.stream().forEach(department -> {
|
|
|
|
+ department.setFather(departmentMap.get(department.getPath()));
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+// departments.add(departmentRepository.find(deptId));
|
|
return ApiResult.ok(departments);
|
|
return ApiResult.ok(departments);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -90,7 +101,7 @@ public class DepartmentServiceImpl implements DepartmentService {
|
|
DeptTreeVO node = new DeptTreeVO();
|
|
DeptTreeVO node = new DeptTreeVO();
|
|
node.setLabel(department.getName());
|
|
node.setLabel(department.getName());
|
|
node.setId(department.getId());
|
|
node.setId(department.getId());
|
|
- List<Department> childTreeNodes = departmentRepository.findByPath(cid);
|
|
|
|
|
|
+ List<Department> childTreeNodes = departmentRepository.findByPathOrderBySortDesc(cid);
|
|
for(Department child : childTreeNodes){
|
|
for(Department child : childTreeNodes){
|
|
DeptTreeVO n = recursiveTree(child.getId()); //递归
|
|
DeptTreeVO n = recursiveTree(child.getId()); //递归
|
|
node.getChildren().add(n);
|
|
node.getChildren().add(n);
|
|
@@ -99,7 +110,7 @@ public class DepartmentServiceImpl implements DepartmentService {
|
|
}
|
|
}
|
|
|
|
|
|
private List<Department> deptChild(Long cid, List<Department> departments) {
|
|
private List<Department> deptChild(Long cid, List<Department> departments) {
|
|
- List<Department> childTreeNodes = departmentRepository.findByPath(cid);
|
|
|
|
|
|
+ List<Department> childTreeNodes = departmentRepository.findByPathOrderBySortDesc(cid);
|
|
departments.addAll(childTreeNodes);
|
|
departments.addAll(childTreeNodes);
|
|
for(Department child : childTreeNodes){
|
|
for(Department child : childTreeNodes){
|
|
deptChild(child.getId(), departments); //递归
|
|
deptChild(child.getId(), departments); //递归
|