mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-22 20:02:42 +08:00
部门列表api返回部门的学员数量
This commit is contained in:
parent
3fda4b6926
commit
9344f81772
@ -47,6 +47,7 @@ public class DepartmentController {
|
||||
public JsonResponse index() {
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
data.put("departments", departmentService.groupByParent());
|
||||
data.put("dep_user_count", departmentService.getDepartmentsUserCount());
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
||||
@ -133,7 +134,7 @@ public class DepartmentController {
|
||||
@DeleteMapping("/{id}")
|
||||
public JsonResponse destroy(@PathVariable Integer id) throws NotFoundException {
|
||||
Department department = departmentService.findOrFail(id);
|
||||
departmentService.deleteById(department.getId());
|
||||
departmentService.destroy(department.getId());
|
||||
ctx.publishEvent(new DepartmentDestroyEvent(this, BCtx.getId(), department.getId()));
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
*
|
||||
* @create 2023/2/23 09:48
|
||||
*/
|
||||
@RestController
|
||||
@ -45,17 +46,13 @@ import java.util.stream.Collectors;
|
||||
@RequestMapping("/backend/v1/user")
|
||||
public class UserController {
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private UserDepartmentService userDepartmentService;
|
||||
@Autowired private UserDepartmentService userDepartmentService;
|
||||
|
||||
@Autowired
|
||||
private DepartmentService departmentService;
|
||||
@Autowired private DepartmentService departmentService;
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
@Autowired private ApplicationContext context;
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.USER_INDEX)
|
||||
@GetMapping("/index")
|
||||
|
@ -9,6 +9,9 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import xyz.playedu.api.domain.Department;
|
||||
import xyz.playedu.api.types.mapper.DepartmentsUserCountMapRes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
@ -16,4 +19,6 @@ import xyz.playedu.api.domain.Department;
|
||||
* @createDate 2023-02-19 12:19:45 @Entity xyz.playedu.api.domain.Department
|
||||
*/
|
||||
@Mapper
|
||||
public interface DepartmentMapper extends BaseMapper<Department> {}
|
||||
public interface DepartmentMapper extends BaseMapper<Department> {
|
||||
List<DepartmentsUserCountMapRes> getDepartmentsUserCount();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
/**
|
||||
* This file is part of the PlayEdu.
|
||||
* (c) 杭州白书科技有限公司
|
||||
*/
|
||||
package xyz.playedu.api.types.mapper;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
*
|
||||
* @create 2023/4/12 13:46
|
||||
*/
|
||||
@Data
|
||||
public class DepartmentsUserCountMapRes {
|
||||
private Integer depId;
|
||||
|
||||
private Integer total;
|
||||
}
|
@ -19,4 +19,9 @@
|
||||
parent_chain,sort,created_at,
|
||||
updated_at
|
||||
</sql>
|
||||
<select id="getDepartmentsUserCount" resultType="xyz.playedu.api.types.mapper.DepartmentsUserCountMapRes">
|
||||
SELECT `dep_id`, count(1) AS `total`
|
||||
FROM user_department
|
||||
GROUP BY dep_id;
|
||||
</select>
|
||||
</mapper>
|
||||
|
Loading…
x
Reference in New Issue
Block a user