diff --git a/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolCommentController.java b/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolCommentController.java index 63386e01..5cb181ca 100644 --- a/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolCommentController.java +++ b/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolCommentController.java @@ -394,4 +394,32 @@ public class AiolCommentController extends JeecgController untopComment(@PathVariable("commentId") String commentId) { + try { + // 1. 查询评论是否存在 + AiolComment comment = aiolCommentService.getById(commentId); + if (comment == null) { + return Result.error("评论不存在"); + } + + // 2. 取消置顶状态 + comment.setIzTop(0); + boolean updated = aiolCommentService.updateById(comment); + if (!updated) { + return Result.error("取消置顶失败"); + } + + log.info("评论取消置顶成功: commentId={}", commentId); + return Result.OK("取消置顶成功!"); + + } catch (Exception e) { + log.error("评论取消置顶失败: commentId={}, error={}", commentId, e.getMessage(), e); + return Result.error("取消置顶失败: " + e.getMessage()); + } + } } diff --git a/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolCourseSectionController.java b/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolCourseSectionController.java index 114ade77..b48e1d3a 100644 --- a/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolCourseSectionController.java +++ b/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolCourseSectionController.java @@ -16,8 +16,10 @@ import org.jeecg.common.system.query.QueryRuleEnum; import org.jeecg.common.util.oConvertUtils; import org.jeecg.modules.aiol.entity.AiolCourseSection; import org.jeecg.modules.aiol.entity.AiolEntityLink; +import org.jeecg.modules.aiol.constant.EntityLinkConst; import org.jeecg.modules.aiol.dto.AiolCourseSectionDTO; import org.jeecg.modules.aiol.service.IAiolCourseSectionService; +import org.jeecg.modules.aiol.service.IAiolEntityLinkService; import org.jeecg.modules.aiol.mapper.AiolEntityLinkMapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -58,6 +60,8 @@ public class AiolCourseSectionController extends JeecgController deleteWrapper = new QueryWrapper<>(); - deleteWrapper.eq("source_type", "course_section") + deleteWrapper.eq("source_type", EntityLinkConst.SourceType.COURSE_SECTION) .eq("source_id", sectionDTO.getId()); aiolEntityLinkMapper.delete(deleteWrapper); // 创建新的关联关系 - AiolEntityLink entityLink = new AiolEntityLink(); - entityLink.setSourceType("course_section"); - entityLink.setSourceId(sectionDTO.getId()); - entityLink.setTargetType(sectionDTO.getTargetType()); - entityLink.setTargetId(sectionDTO.getTargetId()); - entityLink.setCreateBy(sectionDTO.getUpdateBy()); - entityLink.setCreateTime(new Date()); - - aiolEntityLinkMapper.insert(entityLink); + aiolEntityLinkService.save(EntityLinkConst.SourceType.COURSE_SECTION, sectionDTO.getId(), sectionDTO.getTargetType(), sectionDTO.getTargetId()); } else { // 如果没有提供资源信息,删除所有关联关系 QueryWrapper deleteWrapper = new QueryWrapper<>(); - deleteWrapper.eq("source_type", "course_section") + deleteWrapper.eq("source_type", EntityLinkConst.SourceType.COURSE_SECTION) .eq("source_id", sectionDTO.getId()); aiolEntityLinkMapper.delete(deleteWrapper); } diff --git a/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolHomeworkController.java b/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolHomeworkController.java index 30ceb9c6..0ee312e7 100644 --- a/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolHomeworkController.java +++ b/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolHomeworkController.java @@ -36,6 +36,7 @@ import org.jeecg.modules.aiol.mapper.AiolClassStudentMapper; import org.jeecg.modules.aiol.mapper.AiolCourseSignupMapper; import org.jeecg.modules.aiol.entity.AiolClassStudent; import org.jeecg.modules.aiol.entity.AiolCourseSignup; +import org.jeecg.modules.aiol.entity.AiolEntityLink; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -388,6 +389,106 @@ public class AiolHomeworkController extends JeecgController teacherEdit(@RequestBody AiolHomeworkSaveDTO homeworkSaveDTO) { + try { + // 1. 校验ID并查询原记录 + if (homeworkSaveDTO.getId() == null || homeworkSaveDTO.getId().trim().isEmpty()) { + return Result.error("作业ID不能为空"); + } + AiolHomework origin = aiolHomeworkService.getById(homeworkSaveDTO.getId()); + if (origin == null) { + return Result.error("作业不存在"); + } + + // 2. 覆盖更新作业基础信息 + AiolHomework toUpdate = new AiolHomework(); + org.springframework.beans.BeanUtils.copyProperties(homeworkSaveDTO, toUpdate); + boolean updated = aiolHomeworkService.updateById(toUpdate); + if (!updated) { + return Result.error("更新作业失败"); + } + + final String homeworkId = homeworkSaveDTO.getId(); + final String classId = homeworkSaveDTO.getClassId(); + final String courseId = homeworkSaveDTO.getCourseId(); + final String sectionId = homeworkSaveDTO.getSectionId(); + + // 3. 处理章节关联:先清除旧关联,再新增(若提供) + try { + QueryWrapper delWrapper = new QueryWrapper<>(); + delWrapper.eq("target_type", EntityLinkConst.TargetType.HOMEWORK) + .eq("target_id", homeworkId) + .eq("source_type", EntityLinkConst.SourceType.COURSE_SECTION); + entityLinkBizService.remove(delWrapper); + + if (sectionId != null && !sectionId.trim().isEmpty()) { + entityLinkBizService.save( + EntityLinkConst.SourceType.COURSE_SECTION, + sectionId.trim(), + EntityLinkConst.TargetType.HOMEWORK, + homeworkId + ); + } + } catch (Exception e) { + log.warn("更新作业章节关联失败但不影响主体更新: homeworkId={}, error={}", homeworkId, e.getMessage()); + } + + // 4. 依据新的班级/课程范围为缺失的学生补齐提交记录(不删除已有) + try { + List needStudentIds = new ArrayList<>(); + if (classId != null && !classId.trim().isEmpty()) { + String[] classIds = classId.split(","); + for (String singleClassId : classIds) { + if (singleClassId == null || singleClassId.trim().isEmpty()) { continue; } + QueryWrapper csWrapper = new QueryWrapper<>(); + csWrapper.eq("class_id", singleClassId.trim()); + List classStudents = aiolClassStudentMapper.selectList(csWrapper); + for (AiolClassStudent cs : classStudents) { + String sid = cs.getStudentId(); + if (sid != null && !sid.isEmpty() && !needStudentIds.contains(sid)) { + needStudentIds.add(sid); + } + } + } + } else if (courseId != null && !courseId.trim().isEmpty()) { + QueryWrapper suWrapper = new QueryWrapper<>(); + suWrapper.eq("course_id", courseId.trim()); + List signups = aiolCourseSignupMapper.selectList(suWrapper); + for (AiolCourseSignup su : signups) { + String sid = su.getUserId(); + if (sid != null && !sid.isEmpty() && !needStudentIds.contains(sid)) { + needStudentIds.add(sid); + } + } + } + + // 补齐缺失提交记录 + if (!needStudentIds.isEmpty()) { + for (String sid : needStudentIds) { + QueryWrapper existWrapper = new QueryWrapper<>(); + existWrapper.eq("homework_id", homeworkId).eq("student_id", sid); + long exist = homeworkSubmitService.count(existWrapper); + if (exist == 0) { + homeworkSubmitService.createEmptySubmit(homeworkId, sid); + } + } + } + } catch (Exception e) { + log.warn("补齐作业提交记录失败但不影响主体更新: homeworkId={}, error={}", homeworkId, e.getMessage()); + } + + log.info("教师编辑作业成功: homeworkId={}", homeworkId); + return Result.OK("编辑成功!"); + } catch (Exception e) { + log.error("教师编辑作业失败: homeworkSaveDTO={}, error={}", homeworkSaveDTO, e.getMessage(), e); + return Result.error("编辑作业失败: " + e.getMessage()); + } + } + @AutoLog(value = "作业-批阅") @Operation(summary = "作业批阅", description = "教师批阅作业,更新作业提交记录的分数和状态") @RequiresPermissions("aiol:aiol_homework:edit")