feat: 🎸 新增课程 添加班级
This commit is contained in:
parent
8f1fec0169
commit
132b020763
@ -29,6 +29,7 @@ import org.jeecg.modules.aiol.constant.EntityPermissionConst;
|
|||||||
import org.jeecg.modules.aiol.mapper.AiolCourseSignupMapper;
|
import org.jeecg.modules.aiol.mapper.AiolCourseSignupMapper;
|
||||||
import org.jeecg.modules.aiol.mapper.AiolCourseTeacherMapper;
|
import org.jeecg.modules.aiol.mapper.AiolCourseTeacherMapper;
|
||||||
import org.jeecg.modules.aiol.mapper.AiolEntityLinkMapper;
|
import org.jeecg.modules.aiol.mapper.AiolEntityLinkMapper;
|
||||||
|
import org.jeecg.modules.aiol.mapper.AiolClassStudentMapper;
|
||||||
import org.jeecg.modules.system.entity.SysUser;
|
import org.jeecg.modules.system.entity.SysUser;
|
||||||
import org.jeecg.modules.system.mapper.SysUserMapper;
|
import org.jeecg.modules.system.mapper.SysUserMapper;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
@ -104,7 +105,24 @@ public class AiolCourseController extends JeecgController<AiolCourse, IAiolCours
|
|||||||
@RequiresPermissions("aiol:aiol_course:add")
|
@RequiresPermissions("aiol:aiol_course:add")
|
||||||
@PostMapping(value = "/add")
|
@PostMapping(value = "/add")
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Result<String> add(@RequestBody AiolCourseSaveDTO dto) {
|
public Result<String> add(@RequestBody AiolCourse dto) {
|
||||||
|
aiolCourseService.save(dto);
|
||||||
|
|
||||||
|
return Result.OK("添加成功!");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加
|
||||||
|
*
|
||||||
|
* @param aiolCourse
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@AutoLog(value = "课程-教师端添加")
|
||||||
|
@Operation(summary = "课程-教师端添加", description = "添加课程并关联分类,同时根据班级ID将班级学生添加到课程报名表")
|
||||||
|
@RequiresPermissions("aiol:aiol_course:add")
|
||||||
|
@PostMapping(value = "/teacher_add")
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public Result<String> teacherAdd(@RequestBody AiolCourseSaveDTO dto) {
|
||||||
aiolCourseService.save(dto);
|
aiolCourseService.save(dto);
|
||||||
|
|
||||||
String categoryId = dto.getCategoryId();
|
String categoryId = dto.getCategoryId();
|
||||||
@ -119,6 +137,61 @@ public class AiolCourseController extends JeecgController<AiolCourse, IAiolCours
|
|||||||
entityLinkMapper.insert(link);
|
entityLinkMapper.insert(link);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果提供了班级ID,将班级学生添加到课程报名表
|
||||||
|
String classId = dto.getClassId();
|
||||||
|
if (classId != null && !classId.trim().isEmpty()) {
|
||||||
|
try {
|
||||||
|
// 1. 根据班级ID查询学生列表
|
||||||
|
QueryWrapper<AiolClassStudent> studentWrapper = new QueryWrapper<>();
|
||||||
|
studentWrapper.eq("class_id", classId);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("成功为课程 {} 添加班级 {} 的学生,新增报名记录 {} 条",
|
||||||
|
dto.getId(), classId, newStudentIds.size());
|
||||||
|
} else {
|
||||||
|
log.info("班级 {} 的所有学生已报名课程 {}", classId, dto.getId());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.warn("班级 {} 中没有找到学生", classId);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("为课程 {} 添加班级 {} 学生失败: {}", dto.getId(), classId, e.getMessage(), e);
|
||||||
|
// 不抛出异常,避免影响课程创建
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Result.OK("添加成功!");
|
return Result.OK("添加成功!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,6 +315,8 @@ public class AiolCourseController extends JeecgController<AiolCourse, IAiolCours
|
|||||||
private AiolCourseTeacherMapper courseTeacherMapper;
|
private AiolCourseTeacherMapper courseTeacherMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
private AiolEntityLinkMapper entityLinkMapper;
|
private AiolEntityLinkMapper entityLinkMapper;
|
||||||
|
@Autowired
|
||||||
|
private AiolClassStudentMapper classStudentMapper;
|
||||||
|
|
||||||
@GetMapping("/query_list")
|
@GetMapping("/query_list")
|
||||||
@Operation(summary = "学员端-查询课程列表", description = "可根据分类、难度、专题进行检索,三个参数可任意传递其中之一、之二或全部,每个参数可传递多个值,用英文逗号分割,不传参或传递all则查询所有课程,携带讲师信息")
|
@Operation(summary = "学员端-查询课程列表", description = "可根据分类、难度、专题进行检索,三个参数可任意传递其中之一、之二或全部,每个参数可传递多个值,用英文逗号分割,不传参或传递all则查询所有课程,携带讲师信息")
|
||||||
|
@ -7,11 +7,14 @@ import org.jeecg.modules.aiol.entity.AiolCourse;
|
|||||||
|
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
@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")
|
||||||
|
private String classId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user