fix: 上课页面数据与进度保存优化
- 授课记录详情接口返回完整课程和班级:新增 LessonDetailResponse,含 course(courseLessons+steps)、class - 课程环节增加 steps:CourseLessonResponse 新增 steps 字段,getCourseByIdWithLessons 填充教学步骤 - 进度保存反序列化修复:LessonProgressRequest 的 lessonIds/completedLessonIds 改为 List<Long>,progressData 改为 Object - LessonStepResponse 增加 NoArgsConstructor/AllArgsConstructor Made-with: Cursor
This commit is contained in:
parent
c8ecbe277c
commit
a9ee650f66
@ -1,6 +1,7 @@
|
||||
package com.reading.platform.controller.teacher;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.reading.platform.common.mapper.ClassMapper;
|
||||
import com.reading.platform.common.mapper.LessonMapper;
|
||||
import com.reading.platform.common.mapper.StudentRecordMapper;
|
||||
import com.reading.platform.common.response.PageResult;
|
||||
@ -10,6 +11,9 @@ import com.reading.platform.dto.request.LessonCreateRequest;
|
||||
import com.reading.platform.dto.request.LessonProgressRequest;
|
||||
import com.reading.platform.dto.request.LessonUpdateRequest;
|
||||
import com.reading.platform.dto.request.StudentRecordRequest;
|
||||
import com.reading.platform.dto.response.ClassResponse;
|
||||
import com.reading.platform.dto.response.CourseResponse;
|
||||
import com.reading.platform.dto.response.LessonDetailResponse;
|
||||
import com.reading.platform.dto.response.LessonResponse;
|
||||
import com.reading.platform.dto.response.StudentRecordResponse;
|
||||
import com.reading.platform.entity.Clazz;
|
||||
@ -19,6 +23,7 @@ import com.reading.platform.entity.LessonFeedback;
|
||||
import com.reading.platform.entity.StudentRecord;
|
||||
import com.reading.platform.mapper.ClazzMapper;
|
||||
import com.reading.platform.mapper.CourseMapper;
|
||||
import com.reading.platform.service.CourseService;
|
||||
import com.reading.platform.service.LessonService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@ -41,6 +46,8 @@ public class TeacherLessonController {
|
||||
private final StudentRecordMapper studentRecordMapper;
|
||||
private final CourseMapper courseMapper;
|
||||
private final ClazzMapper clazzMapper;
|
||||
private final ClassMapper classMapper;
|
||||
private final CourseService courseService;
|
||||
|
||||
@Operation(summary = "Create lesson")
|
||||
@PostMapping
|
||||
@ -59,13 +66,31 @@ public class TeacherLessonController {
|
||||
return Result.success(lessonMapper.toVO(lesson));
|
||||
}
|
||||
|
||||
@Operation(summary = "Get lesson by ID")
|
||||
@Operation(summary = "Get lesson by ID(含课程、班级,供上课页面使用)")
|
||||
@GetMapping("/{id}")
|
||||
public Result<LessonResponse> getLesson(@PathVariable Long id) {
|
||||
public Result<LessonDetailResponse> getLesson(@PathVariable Long id) {
|
||||
Lesson lesson = lessonService.getLessonById(id);
|
||||
LessonResponse vo = lessonMapper.toVO(lesson);
|
||||
enrichWithCourseAndClass(vo);
|
||||
return Result.success(vo);
|
||||
LessonResponse lessonVo = lessonMapper.toVO(lesson);
|
||||
enrichWithCourseAndClass(lessonVo);
|
||||
|
||||
LessonDetailResponse detail = new LessonDetailResponse();
|
||||
detail.setLesson(lessonVo);
|
||||
|
||||
if (lesson.getCourseId() != null) {
|
||||
try {
|
||||
CourseResponse courseResp = courseService.getCourseByIdWithLessons(lesson.getCourseId());
|
||||
detail.setCourse(courseResp);
|
||||
} catch (Exception e) {
|
||||
// 课程不存在时留空
|
||||
}
|
||||
}
|
||||
if (lesson.getClassId() != null) {
|
||||
Clazz clazz = clazzMapper.selectById(lesson.getClassId());
|
||||
if (clazz != null) {
|
||||
detail.setClassInfo(classMapper.toVO(clazz));
|
||||
}
|
||||
}
|
||||
return Result.success(detail);
|
||||
}
|
||||
|
||||
@Operation(summary = "Get my lessons")
|
||||
|
||||
@ -3,6 +3,8 @@ package com.reading.platform.dto.request;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 课程进度保存请求
|
||||
*/
|
||||
@ -16,13 +18,13 @@ public class LessonProgressRequest {
|
||||
@Schema(description = "当前步骤 ID")
|
||||
private Integer currentStepId;
|
||||
|
||||
@Schema(description = "课程 ID 列表 (JSON)")
|
||||
private String lessonIds;
|
||||
@Schema(description = "课程 ID 列表")
|
||||
private List<Long> lessonIds;
|
||||
|
||||
@Schema(description = "已完成课程 ID 列表 (JSON)")
|
||||
private String completedLessonIds;
|
||||
@Schema(description = "已完成课程 ID 列表")
|
||||
private List<Long> completedLessonIds;
|
||||
|
||||
@Schema(description = "进度数据 (JSON)")
|
||||
private String progressData;
|
||||
@Schema(description = "进度数据 (JSON 对象)")
|
||||
private Object progressData;
|
||||
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import lombok.NoArgsConstructor;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 课程环节响应
|
||||
@ -76,6 +77,9 @@ public class CourseLessonResponse {
|
||||
@Schema(description = "排序号")
|
||||
private Integer sortOrder;
|
||||
|
||||
@Schema(description = "教学环节列表")
|
||||
private List<LessonStepResponse> steps;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
|
||||
@ -0,0 +1,23 @@
|
||||
package com.reading.platform.dto.response;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 授课记录详情响应(含课程、班级,供上课页面使用)
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "授课记录详情响应")
|
||||
public class LessonDetailResponse {
|
||||
|
||||
@Schema(description = "授课记录基本信息")
|
||||
private LessonResponse lesson;
|
||||
|
||||
@Schema(description = "课程信息(含 courseLessons 及 steps)")
|
||||
private CourseResponse course;
|
||||
|
||||
@JsonProperty("class")
|
||||
@Schema(description = "班级信息")
|
||||
private ClassResponse classInfo;
|
||||
}
|
||||
@ -1,8 +1,10 @@
|
||||
package com.reading.platform.dto.response;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@ -12,6 +14,8 @@ import java.time.LocalDateTime;
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "教学环节响应")
|
||||
public class LessonStepResponse {
|
||||
|
||||
|
||||
@ -10,8 +10,10 @@ import com.reading.platform.dto.request.CourseCreateRequest;
|
||||
import com.reading.platform.dto.request.CourseUpdateRequest;
|
||||
import com.reading.platform.dto.response.CourseLessonResponse;
|
||||
import com.reading.platform.dto.response.CourseResponse;
|
||||
import com.reading.platform.dto.response.LessonStepResponse;
|
||||
import com.reading.platform.entity.Course;
|
||||
import com.reading.platform.entity.CourseLesson;
|
||||
import com.reading.platform.entity.LessonStep;
|
||||
import com.reading.platform.mapper.CourseMapper;
|
||||
import com.reading.platform.service.CourseLessonService;
|
||||
import com.reading.platform.service.CourseService;
|
||||
@ -305,12 +307,21 @@ public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course>
|
||||
CourseResponse response = new CourseResponse();
|
||||
BeanUtils.copyProperties(course, response);
|
||||
|
||||
// 查询关联的课程环节
|
||||
// 查询关联的课程环节及教学步骤
|
||||
List<CourseLesson> lessons = courseLessonService.findByCourseId(id);
|
||||
List<CourseLessonResponse> lessonResponses = lessons.stream()
|
||||
.map(lesson -> {
|
||||
CourseLessonResponse res = new CourseLessonResponse();
|
||||
BeanUtils.copyProperties(lesson, res);
|
||||
List<LessonStep> steps = courseLessonService.findSteps(lesson.getId());
|
||||
List<LessonStepResponse> stepResponses = steps.stream()
|
||||
.map(step -> {
|
||||
LessonStepResponse sr = new LessonStepResponse();
|
||||
BeanUtils.copyProperties(step, sr);
|
||||
return sr;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
res.setSteps(stepResponses);
|
||||
return res;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.reading.platform.common.enums.ErrorCode;
|
||||
import com.reading.platform.common.exception.BusinessException;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.reading.platform.dto.request.LessonCreateRequest;
|
||||
import com.reading.platform.dto.request.LessonUpdateRequest;
|
||||
import com.reading.platform.dto.request.LessonProgressRequest;
|
||||
@ -328,14 +329,14 @@ public class LessonServiceImpl extends ServiceImpl<LessonMapper, Lesson>
|
||||
if (request.getCurrentStepId() != null) {
|
||||
lesson.setCurrentStepId(request.getCurrentStepId());
|
||||
}
|
||||
if (StringUtils.hasText(request.getLessonIds())) {
|
||||
lesson.setLessonIds(request.getLessonIds());
|
||||
if (request.getLessonIds() != null) {
|
||||
lesson.setLessonIds(JSON.toJSONString(request.getLessonIds()));
|
||||
}
|
||||
if (StringUtils.hasText(request.getCompletedLessonIds())) {
|
||||
lesson.setCompletedLessonIds(request.getCompletedLessonIds());
|
||||
if (request.getCompletedLessonIds() != null) {
|
||||
lesson.setCompletedLessonIds(JSON.toJSONString(request.getCompletedLessonIds()));
|
||||
}
|
||||
if (StringUtils.hasText(request.getProgressData())) {
|
||||
lesson.setProgressData(request.getProgressData());
|
||||
if (request.getProgressData() != null) {
|
||||
lesson.setProgressData(JSON.toJSONString(request.getProgressData()));
|
||||
}
|
||||
|
||||
lessonMapper.updateById(lesson);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user