mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-24 05:02:43 +08:00
部门列表api返回部门的学员数量
This commit is contained in:
parent
3fda4b6926
commit
9344f81772
@ -47,6 +47,7 @@ public class DepartmentController {
|
|||||||
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());
|
||||||
return JsonResponse.data(data);
|
return JsonResponse.data(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +134,7 @@ public class DepartmentController {
|
|||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
public JsonResponse destroy(@PathVariable Integer id) throws NotFoundException {
|
public JsonResponse destroy(@PathVariable Integer id) throws NotFoundException {
|
||||||
Department department = departmentService.findOrFail(id);
|
Department department = departmentService.findOrFail(id);
|
||||||
departmentService.deleteById(department.getId());
|
departmentService.destroy(department.getId());
|
||||||
ctx.publishEvent(new DepartmentDestroyEvent(this, BCtx.getId(), department.getId()));
|
ctx.publishEvent(new DepartmentDestroyEvent(this, BCtx.getId(), department.getId()));
|
||||||
return JsonResponse.success();
|
return JsonResponse.success();
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,7 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author 杭州白书科技有限公司
|
* @Author 杭州白书科技有限公司
|
||||||
|
*
|
||||||
* @create 2023/2/23 09:48
|
* @create 2023/2/23 09:48
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@ -45,17 +46,13 @@ import java.util.stream.Collectors;
|
|||||||
@RequestMapping("/backend/v1/user")
|
@RequestMapping("/backend/v1/user")
|
||||||
public class UserController {
|
public class UserController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired private UserService userService;
|
||||||
private UserService userService;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired private UserDepartmentService userDepartmentService;
|
||||||
private UserDepartmentService userDepartmentService;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired private DepartmentService departmentService;
|
||||||
private DepartmentService departmentService;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired private ApplicationContext context;
|
||||||
private ApplicationContext context;
|
|
||||||
|
|
||||||
@BackendPermissionMiddleware(slug = BPermissionConstant.USER_INDEX)
|
@BackendPermissionMiddleware(slug = BPermissionConstant.USER_INDEX)
|
||||||
@GetMapping("/index")
|
@GetMapping("/index")
|
||||||
|
@ -9,6 +9,9 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
import xyz.playedu.api.domain.Department;
|
import xyz.playedu.api.domain.Department;
|
||||||
|
import xyz.playedu.api.types.mapper.DepartmentsUserCountMapRes;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author tengteng
|
* @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
|
* @createDate 2023-02-19 12:19:45 @Entity xyz.playedu.api.domain.Department
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@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;
|
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)
|
void update(Department department, String name, Integer parentId, Integer sort)
|
||||||
throws NotFoundException;
|
throws NotFoundException;
|
||||||
|
|
||||||
List<Integer> allIds();
|
|
||||||
|
|
||||||
String compParentChain(Integer parentId) throws NotFoundException;
|
String compParentChain(Integer parentId) throws NotFoundException;
|
||||||
|
|
||||||
String childrenParentChain(Department department);
|
String childrenParentChain(Department department);
|
||||||
@ -53,4 +51,6 @@ public interface DepartmentService extends IService<Department> {
|
|||||||
Map<Integer, String> id2name();
|
Map<Integer, String> id2name();
|
||||||
|
|
||||||
Long total();
|
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.CourseDepartmentService;
|
||||||
import xyz.playedu.api.service.DepartmentService;
|
import xyz.playedu.api.service.DepartmentService;
|
||||||
import xyz.playedu.api.service.internal.UserDepartmentService;
|
import xyz.playedu.api.service.internal.UserDepartmentService;
|
||||||
|
import xyz.playedu.api.types.mapper.DepartmentsUserCountMapRes;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -60,7 +61,7 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void deleteById(Integer id) throws NotFoundException {
|
public void destroy(Integer id) throws NotFoundException {
|
||||||
Department department = findOrFail(id);
|
Department department = findOrFail(id);
|
||||||
updateParentChain(department.getParentChain(), childrenParentChain(department));
|
updateParentChain(department.getParentChain(), childrenParentChain(department));
|
||||||
removeById(department.getId());
|
removeById(department.getId());
|
||||||
@ -136,16 +137,6 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|||||||
updateBatchById(updateRows);
|
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
|
@Override
|
||||||
public String compParentChain(Integer parentId) throws NotFoundException {
|
public String compParentChain(Integer parentId) throws NotFoundException {
|
||||||
String parentChain = "";
|
String parentChain = "";
|
||||||
@ -257,4 +248,13 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|||||||
public Long total() {
|
public Long total() {
|
||||||
return count();
|
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,
|
parent_chain,sort,created_at,
|
||||||
updated_at
|
updated_at
|
||||||
</sql>
|
</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>
|
</mapper>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user