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")
|
||||
@ -200,7 +197,7 @@ public class UserController {
|
||||
String defaultAvatar = BCtx.getConfig().get(CConfig.MEMBER_DEFAULT_AVATAR);
|
||||
|
||||
List<String[]> errorLines = new ArrayList<>();
|
||||
errorLines.add(new String[]{"错误行", "错误信息"}); // 错误表-表头
|
||||
errorLines.add(new String[] {"错误行", "错误信息"}); // 错误表-表头
|
||||
|
||||
// 读取存在的部门
|
||||
List<Department> departments = departmentService.all();
|
||||
@ -240,14 +237,14 @@ public class UserController {
|
||||
i++; // 索引值
|
||||
|
||||
if (userItem.getEmail() == null || userItem.getEmail().trim().length() == 0) {
|
||||
errorLines.add(new String[]{"第" + (i + startLine) + "行", "未输入邮箱账号"});
|
||||
errorLines.add(new String[] {"第" + (i + startLine) + "行", "未输入邮箱账号"});
|
||||
} else {
|
||||
// 邮箱重复判断
|
||||
Integer repeatLine = emailRepeat.get(userItem.getEmail());
|
||||
if (repeatLine != null) {
|
||||
errorLines.add(
|
||||
new String[]{
|
||||
"第" + (i + startLine) + "行", "与第" + repeatLine + "行邮箱重复"
|
||||
new String[] {
|
||||
"第" + (i + startLine) + "行", "与第" + repeatLine + "行邮箱重复"
|
||||
});
|
||||
} else {
|
||||
emailRepeat.put(userItem.getEmail(), i + startLine);
|
||||
@ -257,7 +254,7 @@ public class UserController {
|
||||
|
||||
// 部门数据检测
|
||||
if (userItem.getDeps() == null || userItem.getDeps().trim().length() == 0) {
|
||||
errorLines.add(new String[]{"第" + (i + startLine) + "行", "未选择部门"});
|
||||
errorLines.add(new String[] {"第" + (i + startLine) + "行", "未选择部门"});
|
||||
} else {
|
||||
String[] tmpDepList = userItem.getDeps().trim().split("\\|");
|
||||
Integer[] tmpDepIds = new Integer[tmpDepList.length];
|
||||
@ -267,8 +264,8 @@ public class UserController {
|
||||
// 判断部门id是否存在
|
||||
if (tmpDepId == null || tmpDepId == 0) {
|
||||
errorLines.add(
|
||||
new String[]{
|
||||
"第" + (i + startLine) + "行", "部门『" + tmpDepList[j] + "』不存在"
|
||||
new String[] {
|
||||
"第" + (i + startLine) + "行", "部门『" + tmpDepList[j] + "』不存在"
|
||||
});
|
||||
continue;
|
||||
}
|
||||
@ -280,13 +277,13 @@ public class UserController {
|
||||
// 姓名为空检测
|
||||
String tmpName = userItem.getName();
|
||||
if (tmpName == null || tmpName.trim().length() == 0) {
|
||||
errorLines.add(new String[]{"第" + (i + startLine) + "行", "昵称为空"});
|
||||
errorLines.add(new String[] {"第" + (i + startLine) + "行", "昵称为空"});
|
||||
}
|
||||
|
||||
// 密码为空检测
|
||||
String tmpPassword = userItem.getPassword();
|
||||
if (tmpPassword == null || tmpPassword.trim().length() == 0) {
|
||||
errorLines.add(new String[]{"第" + (i + startLine) + "行", "密码为空"});
|
||||
errorLines.add(new String[] {"第" + (i + startLine) + "行", "密码为空"});
|
||||
}
|
||||
|
||||
// 待插入数据
|
||||
@ -314,7 +311,7 @@ public class UserController {
|
||||
List<String> existsEmails = userService.existsEmailsByEmails(emails);
|
||||
if (existsEmails.size() > 0) {
|
||||
for (String tmpEmail : existsEmails) {
|
||||
errorLines.add(new String[]{"第" + emailRepeat.get(tmpEmail) + "行", "邮箱已注册"});
|
||||
errorLines.add(new String[] {"第" + emailRepeat.get(tmpEmail) + "行", "邮箱已注册"});
|
||||
}
|
||||
}
|
||||
if (errorLines.size() > 1) {
|
||||
|
@ -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;
|
||||
}
|
@ -15,8 +15,13 @@
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,name,parent_id,
|
||||
parent_chain,sort,created_at,
|
||||
id,name,parent_id,
|
||||
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