mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-21 11:22:41 +08:00
优化学员课程api接口
This commit is contained in:
parent
1fdbc2fdca
commit
d19aa8d2ee
@ -1,5 +1,6 @@
|
|||||||
package xyz.playedu.api.controller.frontend;
|
package xyz.playedu.api.controller.frontend;
|
||||||
|
|
||||||
|
import org.apache.commons.collections4.MapUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@ -17,6 +18,7 @@ import xyz.playedu.api.types.JsonResponse;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author 杭州白书科技有限公司
|
* @Author 杭州白书科技有限公司
|
||||||
@ -54,20 +56,31 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/courses")
|
@GetMapping("/courses")
|
||||||
public JsonResponse courses() {
|
public JsonResponse courses(@RequestParam HashMap<String, Object> params) {
|
||||||
|
Integer depId = MapUtils.getInteger(params, "dep_id");
|
||||||
|
if (depId == null || depId == 0) {
|
||||||
|
return JsonResponse.error("请选择部门");
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Integer> userJoinDepIds = userService.getDepIdsByUserId(PlayEduFCtx.getUserId());
|
||||||
|
if (userJoinDepIds == null) {
|
||||||
|
return JsonResponse.error("当前学员未加入任何部门");
|
||||||
|
}
|
||||||
|
if (!userJoinDepIds.contains(depId)) {
|
||||||
|
return JsonResponse.error("当前学员未加入所选择部门");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取部门课
|
||||||
|
List<Course> depCourses = courseService.depCoursesAndShow(new ArrayList<>() {{
|
||||||
|
add(depId);
|
||||||
|
}});
|
||||||
|
|
||||||
// 公开课
|
// 公开课
|
||||||
List<Course> openCourses = courseService.openCoursesAndShow(200);
|
List<Course> openCourses = courseService.openCoursesAndShow(200);
|
||||||
|
|
||||||
// 部门课
|
|
||||||
List<Course> depCourses = new ArrayList<>();
|
|
||||||
List<Integer> userJoinDepIds = userService.getDepIdsByUserId(PlayEduFCtx.getUserId());
|
|
||||||
if (userJoinDepIds != null && userJoinDepIds.size() > 0) {
|
|
||||||
depCourses = courseService.depCoursesAndShow(userJoinDepIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
HashMap<String, Object> data = new HashMap<>();
|
HashMap<String, Object> data = new HashMap<>();
|
||||||
data.put("open", openCourses);
|
data.put("open", openCourses.stream().collect(Collectors.groupingBy(Course::getIsRequired)));
|
||||||
data.put("department", depCourses);
|
data.put("department", depCourses.stream().collect(Collectors.groupingBy(Course::getIsRequired)));
|
||||||
|
|
||||||
return JsonResponse.data(data);
|
return JsonResponse.data(data);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user