部门列表api返回部门的学员数量

This commit is contained in:
none
2023-04-12 13:55:22 +08:00
parent 3fda4b6926
commit 9344f81772
7 changed files with 63 additions and 36 deletions

View File

@@ -25,13 +25,11 @@ public interface DepartmentService extends IService<Department> {
Department findOrFail(Integer id) throws NotFoundException;
void deleteById(Integer id) throws NotFoundException;
void destroy(Integer id) throws NotFoundException;
void update(Department department, String name, Integer parentId, Integer sort)
throws NotFoundException;
List<Integer> allIds();
String compParentChain(Integer parentId) throws NotFoundException;
String childrenParentChain(Department department);
@@ -53,4 +51,6 @@ public interface DepartmentService extends IService<Department> {
Map<Integer, String> id2name();
Long total();
Map<Integer, Integer> getDepartmentsUserCount();
}

View File

@@ -21,6 +21,7 @@ import xyz.playedu.api.mapper.DepartmentMapper;
import xyz.playedu.api.service.CourseDepartmentService;
import xyz.playedu.api.service.DepartmentService;
import xyz.playedu.api.service.internal.UserDepartmentService;
import xyz.playedu.api.types.mapper.DepartmentsUserCountMapRes;
import java.util.*;
import java.util.stream.Collectors;
@@ -60,7 +61,7 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
@Override
@Transactional
public void deleteById(Integer id) throws NotFoundException {
public void destroy(Integer id) throws NotFoundException {
Department department = findOrFail(id);
updateParentChain(department.getParentChain(), childrenParentChain(department));
removeById(department.getId());
@@ -136,16 +137,6 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
updateBatchById(updateRows);
}
@Override
public List<Integer> allIds() {
List<Department> departments = list(query().getWrapper().eq("1", "1").select("id"));
List<Integer> ids = new ArrayList<>();
for (Department department : departments) {
ids.add(department.getId());
}
return ids;
}
@Override
public String compParentChain(Integer parentId) throws NotFoundException {
String parentChain = "";
@@ -257,4 +248,13 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
public Long total() {
return count();
}
@Override
public Map<Integer, Integer> getDepartmentsUserCount() {
return getBaseMapper().getDepartmentsUserCount().stream()
.collect(
Collectors.toMap(
DepartmentsUserCountMapRes::getDepId,
DepartmentsUserCountMapRes::getTotal));
}
}