|
|
@@ -0,0 +1,91 @@
|
|
|
+package com.train.controller;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.train.common.Result;
|
|
|
+import com.train.entity.TrainClass;
|
|
|
+import com.train.entity.TrainCourse;
|
|
|
+import com.train.entity.TrainUser;
|
|
|
+import com.train.mapper.TrainClassMapper;
|
|
|
+import com.train.mapper.TrainCourseMapper;
|
|
|
+import com.train.mapper.TrainUserMapper;
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestAttribute;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 训练营课程(L0/L1/L2/L3/L4)相关接口。
|
|
|
+ *
|
|
|
+ * - /api/course/list 列出所有课程
|
|
|
+ * - /api/course/current 当前学员所修课程(按 user.class_id -> train_class.course_id 解析)
|
|
|
+ *
|
|
|
+ * 注意:当前学员所修课程未写入 user,而是从 class_id 反查,因此响应里附带 class 信息。
|
|
|
+ */
|
|
|
+@Tag(name = "课程", description = "训练营课程(L0/L1/.../L4)")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/course")
|
|
|
+public class CourseController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TrainCourseMapper trainCourseMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TrainClassMapper trainClassMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TrainUserMapper trainUserMapper;
|
|
|
+
|
|
|
+ @Operation(summary = "列出所有课程")
|
|
|
+ @PostMapping("/list")
|
|
|
+ public Result<List<TrainCourse>> list() {
|
|
|
+ List<TrainCourse> courses = trainCourseMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<TrainCourse>().orderByAsc(TrainCourse::getLevel));
|
|
|
+ return Result.success(courses);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "当前学员所修课程")
|
|
|
+ @PostMapping("/current")
|
|
|
+ public Result<Map<String, Object>> current(@RequestAttribute("userId") Long userId) {
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
+
|
|
|
+ TrainUser user = trainUserMapper.selectById(userId);
|
|
|
+ if (user == null) {
|
|
|
+ return Result.error("用户不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ TrainCourse course = null;
|
|
|
+ TrainClass trainClass = null;
|
|
|
+ if (user.getClassId() != null) {
|
|
|
+ trainClass = trainClassMapper.selectById(user.getClassId());
|
|
|
+ if (trainClass != null && trainClass.getCourseId() != null) {
|
|
|
+ course = trainCourseMapper.selectById(trainClass.getCourseId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (course == null) {
|
|
|
+ // 兜底:未进班或课程未关联时,返回首个 active 课程(一般是 L0)
|
|
|
+ course = trainCourseMapper.selectOne(
|
|
|
+ new LambdaQueryWrapper<TrainCourse>()
|
|
|
+ .eq(TrainCourse::getStatus, "active")
|
|
|
+ .orderByAsc(TrainCourse::getLevel)
|
|
|
+ .last("LIMIT 1"));
|
|
|
+ }
|
|
|
+
|
|
|
+ data.put("course", course);
|
|
|
+ if (trainClass != null) {
|
|
|
+ data.put("classId", trainClass.getId());
|
|
|
+ data.put("className", trainClass.getName());
|
|
|
+ data.put("classCode", trainClass.getCode());
|
|
|
+ data.put("classTime", trainClass.getTime());
|
|
|
+ data.put("classPlace", trainClass.getPlace());
|
|
|
+ }
|
|
|
+ return Result.success(data);
|
|
|
+ }
|
|
|
+}
|