mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-12-25 20:35:35 +08:00
完善/user/courses接口 && fixed: 后台学员top10
This commit is contained in:
@@ -68,7 +68,7 @@ public class DashboardController {
|
||||
data.put("user_learn_yesterday", userLearnDurationStatsService.yesterdayTotal());
|
||||
|
||||
List<UserLearnDurationStats> userLearnTop10 = userLearnDurationStatsService.top10();
|
||||
Map<Integer, User> top10Users = userService.chunks(userLearnTop10.stream().map(UserLearnDurationStats::getUserId).toList(), new ArrayList<String>() {{
|
||||
Map<Integer, User> top10Users = userService.chunks(userLearnTop10.stream().map(UserLearnDurationStats::getUserId).toList(), new ArrayList<>() {{
|
||||
add("id");
|
||||
add("name");
|
||||
add("avatar");
|
||||
|
||||
@@ -9,16 +9,16 @@ import xyz.playedu.api.FCtx;
|
||||
import xyz.playedu.api.domain.Course;
|
||||
import xyz.playedu.api.domain.Department;
|
||||
import xyz.playedu.api.domain.User;
|
||||
import xyz.playedu.api.domain.UserCourseRecord;
|
||||
import xyz.playedu.api.exception.ServiceException;
|
||||
import xyz.playedu.api.request.frontend.ChangePasswordRequest;
|
||||
import xyz.playedu.api.service.CourseService;
|
||||
import xyz.playedu.api.service.DepartmentService;
|
||||
import xyz.playedu.api.service.UserCourseRecordService;
|
||||
import xyz.playedu.api.service.UserService;
|
||||
import xyz.playedu.api.types.JsonResponse;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -39,6 +39,9 @@ public class UserController {
|
||||
@Autowired
|
||||
private CourseService courseService;
|
||||
|
||||
@Autowired
|
||||
private UserCourseRecordService userCourseRecordService;
|
||||
|
||||
@GetMapping("/detail")
|
||||
public JsonResponse detail() {
|
||||
User user = FCtx.getUser();
|
||||
@@ -77,20 +80,41 @@ public class UserController {
|
||||
return JsonResponse.error("当前学员未加入所选择部门");
|
||||
}
|
||||
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
data.put("learn_course_records", new HashMap<>());
|
||||
|
||||
// -------- 读取当前学员可以参加的课程 ----------
|
||||
List<Course> courses = new ArrayList<>();
|
||||
// 读取部门课
|
||||
List<Course> depCourses = courseService.getDepCoursesAndShow(new ArrayList<>() {{
|
||||
add(depId);
|
||||
}});
|
||||
// 全部部门课
|
||||
List<Course> openCourses = courseService.getOpenCoursesAndShow(500);
|
||||
if (depCourses != null && depCourses.size() > 0) {
|
||||
courses.addAll(depCourses);
|
||||
}
|
||||
if (openCourses != null && openCourses.size() > 0) {
|
||||
courses.addAll(openCourses);
|
||||
}
|
||||
|
||||
// 公开课
|
||||
List<Course> openCourses = courseService.getOpenCoursesAndShow(200);
|
||||
if (courses.size() > 0) {
|
||||
courses = courses.stream().sorted(Comparator.comparing(Course::getId).reversed()).toList();
|
||||
}
|
||||
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
data.put("open", openCourses.stream().collect(Collectors.groupingBy(Course::getIsRequired)));
|
||||
data.put("department", depCourses.stream().collect(Collectors.groupingBy(Course::getIsRequired)));
|
||||
data.put("courses", courses);
|
||||
|
||||
// -------- 读取学习进度 ----------
|
||||
Map<Integer, UserCourseRecord> learnCourseRecords = new HashMap<>();
|
||||
if (courses.size() > 0) {
|
||||
learnCourseRecords = userCourseRecordService
|
||||
.chunk(FCtx.getUserId(), courses.stream().map(Course::getId).toList())
|
||||
.stream()
|
||||
.collect(Collectors.toMap(UserCourseRecord::getCourseId, e -> e));
|
||||
}
|
||||
data.put("learn_course_records", learnCourseRecords);
|
||||
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user