mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-26 23:22:44 +08:00
学员部门包含子部门所有学员数量
This commit is contained in:
parent
4d527cff77
commit
7c84e185a6
@ -38,6 +38,7 @@ import xyz.playedu.common.domain.Department;
|
|||||||
import xyz.playedu.common.domain.User;
|
import xyz.playedu.common.domain.User;
|
||||||
import xyz.playedu.common.exception.NotFoundException;
|
import xyz.playedu.common.exception.NotFoundException;
|
||||||
import xyz.playedu.common.service.DepartmentService;
|
import xyz.playedu.common.service.DepartmentService;
|
||||||
|
import xyz.playedu.common.service.UserDepartmentService;
|
||||||
import xyz.playedu.common.service.UserService;
|
import xyz.playedu.common.service.UserService;
|
||||||
import xyz.playedu.common.types.JsonResponse;
|
import xyz.playedu.common.types.JsonResponse;
|
||||||
import xyz.playedu.common.types.paginate.PaginationResult;
|
import xyz.playedu.common.types.paginate.PaginationResult;
|
||||||
@ -71,12 +72,39 @@ public class DepartmentController {
|
|||||||
|
|
||||||
@Autowired private LDAPBus ldapBus;
|
@Autowired private LDAPBus ldapBus;
|
||||||
|
|
||||||
|
@Autowired private UserDepartmentService userDepartmentService;
|
||||||
|
|
||||||
@GetMapping("/index")
|
@GetMapping("/index")
|
||||||
@Log(title = "部门-列表", businessType = BusinessTypeConstant.GET)
|
@Log(title = "部门-列表", businessType = BusinessTypeConstant.GET)
|
||||||
public JsonResponse index() {
|
public JsonResponse index() {
|
||||||
HashMap<String, Object> data = new HashMap<>();
|
HashMap<String, Object> data = new HashMap<>();
|
||||||
data.put("departments", departmentService.groupByParent());
|
data.put("departments", departmentService.groupByParent());
|
||||||
data.put("dep_user_count", departmentService.getDepartmentsUserCount());
|
|
||||||
|
HashMap<Integer, Integer> depUserCount = new HashMap<>();
|
||||||
|
List<Department> allDepartmentList = departmentService.all();
|
||||||
|
if (StringUtil.isNotEmpty(allDepartmentList)) {
|
||||||
|
for (Department dep : allDepartmentList) {
|
||||||
|
List<Integer> depIds = new ArrayList<>();
|
||||||
|
depIds.add(dep.getId());
|
||||||
|
String parentChain = "";
|
||||||
|
if (StringUtil.isEmpty(dep.getParentChain())) {
|
||||||
|
parentChain = dep.getId() + "";
|
||||||
|
} else {
|
||||||
|
parentChain = dep.getParentChain() + "," + dep.getId();
|
||||||
|
}
|
||||||
|
// 获取所有子部门ID
|
||||||
|
List<Department> childDepartmentList =
|
||||||
|
departmentService.getChildDepartmentsByParentChain(
|
||||||
|
dep.getId(), parentChain);
|
||||||
|
if (StringUtil.isNotEmpty(childDepartmentList)) {
|
||||||
|
depIds.addAll(childDepartmentList.stream().map(Department::getId).toList());
|
||||||
|
}
|
||||||
|
List<Integer> departmentUserIds = userDepartmentService.getUserIdsByDepIds(depIds);
|
||||||
|
depUserCount.put(
|
||||||
|
dep.getId(), departmentUserIds.stream().distinct().toList().size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data.put("dep_user_count", depUserCount);
|
||||||
data.put("user_total", userService.total());
|
data.put("user_total", userService.total());
|
||||||
return JsonResponse.data(data);
|
return JsonResponse.data(data);
|
||||||
}
|
}
|
||||||
|
@ -107,11 +107,31 @@ public class UserController {
|
|||||||
String createdAt = MapUtils.getString(params, "created_at");
|
String createdAt = MapUtils.getString(params, "created_at");
|
||||||
String depIdsStr = MapUtils.getString(params, "dep_ids");
|
String depIdsStr = MapUtils.getString(params, "dep_ids");
|
||||||
List<Integer> depIds = null;
|
List<Integer> depIds = null;
|
||||||
if (depIdsStr != null && !depIdsStr.trim().isEmpty()) {
|
if (StringUtil.isNotEmpty(depIdsStr)) {
|
||||||
if ("0".equals(depIdsStr)) {
|
depIds = new ArrayList<>();
|
||||||
depIds = new ArrayList<>();
|
if (!"0".equals(depIdsStr)) {
|
||||||
} else {
|
List<Department> departmentList =
|
||||||
depIds = Arrays.stream(depIdsStr.split(",")).map(Integer::valueOf).toList();
|
departmentService.chunk(
|
||||||
|
Arrays.stream(depIdsStr.split(",")).map(Integer::valueOf).toList());
|
||||||
|
if (StringUtil.isNotEmpty(departmentList)) {
|
||||||
|
for (Department dep : departmentList) {
|
||||||
|
depIds.add(dep.getId());
|
||||||
|
String parentChain = "";
|
||||||
|
if (StringUtil.isEmpty(dep.getParentChain())) {
|
||||||
|
parentChain = dep.getId() + "";
|
||||||
|
} else {
|
||||||
|
parentChain = dep.getParentChain() + "," + dep.getId();
|
||||||
|
}
|
||||||
|
// 获取所有子部门ID
|
||||||
|
List<Department> childDepartmentList =
|
||||||
|
departmentService.getChildDepartmentsByParentChain(
|
||||||
|
dep.getId(), parentChain);
|
||||||
|
if (StringUtil.isNotEmpty(childDepartmentList)) {
|
||||||
|
depIds.addAll(
|
||||||
|
childDepartmentList.stream().map(Department::getId).toList());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,4 +70,6 @@ public interface DepartmentService extends IService<Department> {
|
|||||||
Department findByName(String name, Integer parentId);
|
Department findByName(String name, Integer parentId);
|
||||||
|
|
||||||
List<Department> getChildDepartmentsByParentId(Integer parentId);
|
List<Department> getChildDepartmentsByParentId(Integer parentId);
|
||||||
|
|
||||||
|
List<Department> getChildDepartmentsByParentChain(Integer parentId, String parentChain);
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ import xyz.playedu.common.mapper.DepartmentMapper;
|
|||||||
import xyz.playedu.common.service.DepartmentService;
|
import xyz.playedu.common.service.DepartmentService;
|
||||||
import xyz.playedu.common.service.UserDepartmentService;
|
import xyz.playedu.common.service.UserDepartmentService;
|
||||||
import xyz.playedu.common.types.mapper.DepartmentsUserCountMapRes;
|
import xyz.playedu.common.types.mapper.DepartmentsUserCountMapRes;
|
||||||
|
import xyz.playedu.common.util.StringUtil;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -302,4 +303,16 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|||||||
.or()
|
.or()
|
||||||
.likeRight("parent_chain", parentId + ","));
|
.likeRight("parent_chain", parentId + ","));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Department> getChildDepartmentsByParentChain(Integer parentId, String parentChain) {
|
||||||
|
if (StringUtil.isEmpty(parentChain)) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
return list(
|
||||||
|
query().getWrapper()
|
||||||
|
.eq("parent_id", parentId)
|
||||||
|
.or()
|
||||||
|
.likeRight("parent_chain", parentChain + ","));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user