Compare commits

..

2 Commits

Author SHA1 Message Date
GoCo
b4c0be4051 feat: 🎸 修复查询课程列表字段名错误 2025-09-13 18:22:44 +08:00
GoCo
44b025f686 feat: 🎸 新增课程 多个分类班级 2025-09-13 13:54:14 +08:00
4 changed files with 99 additions and 72 deletions

View File

@ -118,77 +118,97 @@ public class AiolCourseController extends JeecgController<AiolCourse, IAiolCours
* @return * @return
*/ */
@AutoLog(value = "课程-教师端添加") @AutoLog(value = "课程-教师端添加")
@Operation(summary = "课程-教师端添加", description = "添加课程并关联分类同时根据班级ID将班级学生添加到课程报名表") @Operation(summary = "课程-教师端添加", description = "添加课程并关联分类同时根据班级ID将班级学生添加到课程报名表。支持多个分类ID和班级ID用英文逗号分割")
@RequiresPermissions("aiol:aiol_course:add") @RequiresPermissions("aiol:aiol_course:add")
@PostMapping(value = "/teacher_add") @PostMapping(value = "/teacher_add")
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Result<String> teacherAdd(@RequestBody AiolCourseSaveDTO dto) { public Result<String> teacherAdd(@RequestBody AiolCourseSaveDTO dto) {
aiolCourseService.save(dto); aiolCourseService.save(dto);
// 处理多个分类ID
String categoryId = dto.getCategoryId(); String categoryId = dto.getCategoryId();
if (categoryId != null && !categoryId.trim().isEmpty()) { if (categoryId != null && !categoryId.trim().isEmpty()) {
AiolEntityLink link = new AiolEntityLink(); String[] categoryIds = categoryId.split(",");
link.setSourceType("course_category"); for (String catId : categoryIds) {
link.setSourceId(categoryId); if (catId != null && !catId.trim().isEmpty()) {
link.setTargetType("course"); AiolEntityLink link = new AiolEntityLink();
link.setTargetId(dto.getId()); link.setSourceType("course_category");
link.setCreateBy(dto.getCreateBy()); link.setSourceId(catId.trim());
link.setCreateTime(new Date()); link.setTargetType("course");
entityLinkMapper.insert(link); link.setTargetId(dto.getId());
link.setCreateBy(dto.getCreateBy());
link.setCreateTime(new Date());
entityLinkMapper.insert(link);
}
}
} }
// 如果提供了班级ID将班级学生添加到课程报名表 // 处理多个班级ID将班级学生添加到课程报名表
String classId = dto.getClassId(); String classId = dto.getClassId();
if (classId != null && !classId.trim().isEmpty()) { if (classId != null && !classId.trim().isEmpty()) {
try { String[] classIds = classId.split(",");
// 1. 根据班级ID查询学生列表 int totalNewStudents = 0;
QueryWrapper<AiolClassStudent> studentWrapper = new QueryWrapper<>();
studentWrapper.eq("class_id", classId); for (String clsId : classIds) {
List<AiolClassStudent> classStudents = classStudentMapper.selectList(studentWrapper); if (clsId == null || clsId.trim().isEmpty()) {
continue;
if (!classStudents.isEmpty()) {
// 2. 检查已存在的报名记录避免重复添加
List<String> studentIds = classStudents.stream()
.map(AiolClassStudent::getStudentId)
.collect(Collectors.toList());
QueryWrapper<AiolCourseSignup> existingWrapper = new QueryWrapper<>();
existingWrapper.eq("course_id", dto.getId())
.in("user_id", studentIds);
List<AiolCourseSignup> existingSignups = courseSignupMapper.selectList(existingWrapper);
// 3. 过滤掉已存在的学生ID
Set<String> existingStudentIds = existingSignups.stream()
.map(AiolCourseSignup::getUserId)
.collect(Collectors.toSet());
List<String> newStudentIds = studentIds.stream()
.filter(id -> !existingStudentIds.contains(id))
.collect(Collectors.toList());
// 4. 为未报名的学生创建报名记录
if (!newStudentIds.isEmpty()) {
for (String studentId : newStudentIds) {
AiolCourseSignup signup = new AiolCourseSignup();
signup.setCourseId(dto.getId());
signup.setUserId(studentId);
signup.setCreateBy(dto.getCreateBy());
signup.setCreateTime(new Date());
courseSignupMapper.insert(signup);
}
log.info("成功为课程 {} 添加班级 {} 的学生,新增报名记录 {} 条",
dto.getId(), classId, newStudentIds.size());
} else {
log.info("班级 {} 的所有学生已报名课程 {}", classId, dto.getId());
}
} else {
log.warn("班级 {} 中没有找到学生", classId);
} }
} catch (Exception e) { try {
log.error("为课程 {} 添加班级 {} 学生失败: {}", dto.getId(), classId, e.getMessage(), e); // 1. 根据班级ID查询学生列表
// 不抛出异常避免影响课程创建 QueryWrapper<AiolClassStudent> studentWrapper = new QueryWrapper<>();
studentWrapper.eq("class_id", clsId.trim());
List<AiolClassStudent> classStudents = classStudentMapper.selectList(studentWrapper);
if (!classStudents.isEmpty()) {
// 2. 检查已存在的报名记录避免重复添加
List<String> studentIds = classStudents.stream()
.map(AiolClassStudent::getStudentId)
.collect(Collectors.toList());
QueryWrapper<AiolCourseSignup> existingWrapper = new QueryWrapper<>();
existingWrapper.eq("course_id", dto.getId())
.in("user_id", studentIds);
List<AiolCourseSignup> existingSignups = courseSignupMapper.selectList(existingWrapper);
// 3. 过滤掉已存在的学生ID
Set<String> existingStudentIds = existingSignups.stream()
.map(AiolCourseSignup::getUserId)
.collect(Collectors.toSet());
List<String> newStudentIds = studentIds.stream()
.filter(id -> !existingStudentIds.contains(id))
.collect(Collectors.toList());
// 4. 为未报名的学生创建报名记录
if (!newStudentIds.isEmpty()) {
for (String studentId : newStudentIds) {
AiolCourseSignup signup = new AiolCourseSignup();
signup.setCourseId(dto.getId());
signup.setUserId(studentId);
signup.setCreateBy(dto.getCreateBy());
signup.setCreateTime(new Date());
courseSignupMapper.insert(signup);
}
totalNewStudents += newStudentIds.size();
log.info("成功为课程 {} 添加班级 {} 的学生,新增报名记录 {} 条",
dto.getId(), clsId.trim(), newStudentIds.size());
} else {
log.info("班级 {} 的所有学生已报名课程 {}", clsId.trim(), dto.getId());
}
} else {
log.warn("班级 {} 中没有找到学生", clsId.trim());
}
} catch (Exception e) {
log.error("为课程 {} 添加班级 {} 学生失败: {}", dto.getId(), clsId.trim(), e.getMessage(), e);
// 不抛出异常避免影响课程创建
}
}
if (totalNewStudents > 0) {
log.info("课程 {} 总共新增学生报名记录 {} 条", dto.getId(), totalNewStudents);
} }
} }
@ -209,21 +229,28 @@ public class AiolCourseController extends JeecgController<AiolCourse, IAiolCours
public Result<String> edit(@RequestBody AiolCourseSaveDTO dto) { public Result<String> edit(@RequestBody AiolCourseSaveDTO dto) {
aiolCourseService.updateById(dto); aiolCourseService.updateById(dto);
// 删除旧的分类关联
QueryWrapper<AiolEntityLink> deleteWrapper = new QueryWrapper<>(); QueryWrapper<AiolEntityLink> deleteWrapper = new QueryWrapper<>();
deleteWrapper.eq("target_type", "course").eq("target_id", dto.getId()) deleteWrapper.eq("target_type", "course").eq("target_id", dto.getId())
.eq("source_type", "course_category"); .eq("source_type", "course_category");
entityLinkMapper.delete(deleteWrapper); entityLinkMapper.delete(deleteWrapper);
// 处理多个分类ID
String categoryId = dto.getCategoryId(); String categoryId = dto.getCategoryId();
if (categoryId != null && !categoryId.trim().isEmpty()) { if (categoryId != null && !categoryId.trim().isEmpty()) {
AiolEntityLink link = new AiolEntityLink(); String[] categoryIds = categoryId.split(",");
link.setSourceType("course_category"); for (String catId : categoryIds) {
link.setSourceId(categoryId); if (catId != null && !catId.trim().isEmpty()) {
link.setTargetType("course"); AiolEntityLink link = new AiolEntityLink();
link.setTargetId(dto.getId()); link.setSourceType("course_category");
link.setCreateBy(dto.getUpdateBy()); link.setSourceId(catId.trim());
link.setCreateTime(new Date()); link.setTargetType("course");
entityLinkMapper.insert(link); link.setTargetId(dto.getId());
link.setCreateBy(dto.getUpdateBy());
link.setCreateTime(new Date());
entityLinkMapper.insert(link);
}
}
} }
return Result.OK("编辑成功!"); return Result.OK("编辑成功!");

View File

@ -10,10 +10,10 @@ import org.jeecg.modules.aiol.entity.AiolCourse;
@Schema(description = "课程保存DTO扩展课程分类和班级") @Schema(description = "课程保存DTO扩展课程分类和班级")
public class AiolCourseSaveDTO extends AiolCourse { public class AiolCourseSaveDTO extends AiolCourse {
@Schema(description = "课程分类ID") @Schema(description = "课程分类ID,支持多个,用英文逗号分割")
private String categoryId; private String categoryId;
@Schema(description = "班级ID") @Schema(description = "班级ID,支持多个,用英文逗号分割")
private String classId; private String classId;
} }

View File

@ -22,7 +22,7 @@ import lombok.experimental.Accessors;
/** /**
* @Description: 课程 * @Description: 课程
* @Author: jeecg-boot * @Author: jeecg-boot
* @Date: 2025-09-12 * @Date: 2025-09-13
* @Version: V1.0 * @Version: V1.0
*/ */
@Data @Data
@ -121,9 +121,9 @@ public class AiolCourse implements Serializable {
@Excel(name = "常见问题", width = 15) @Excel(name = "常见问题", width = 15)
@Schema(description = "常见问题") @Schema(description = "常见问题")
private java.lang.String question; private java.lang.String question;
/**是否ai伴学模式*/ /**是否ai伴学模式1*/
@Excel(name = "是否ai伴学模式", width = 15) @Excel(name = "是否ai伴学模式1", width = 15)
@Schema(description = "是否ai伴学模式") @Schema(description = "是否ai伴学模式1")
private java.lang.Integer izAi; private java.lang.Integer izAi;
/**离开页面是否暂停视频播放*/ /**离开页面是否暂停视频播放*/
@Excel(name = "离开页面是否暂停视频播放", width = 15) @Excel(name = "离开页面是否暂停视频播放", width = 15)

View File

@ -261,7 +261,7 @@ public class AiolCourseServiceImpl extends ServiceImpl<AiolCourseMapper, AiolCou
} }
// 只查询已上架的课程 // 只查询已上架的课程
queryWrapper.eq("publishStatus", 1); queryWrapper.eq("publish_status", 1);
List<AiolCourse> courseList = courseMapper.selectList(queryWrapper); List<AiolCourse> courseList = courseMapper.selectList(queryWrapper);