Compare commits

...

2 Commits

3 changed files with 136 additions and 11 deletions

View File

@ -394,4 +394,32 @@ public class AiolCommentController extends JeecgController<AiolComment, IAiolCom
return Result.error("置顶失败: " + e.getMessage()); return Result.error("置顶失败: " + e.getMessage());
} }
} }
@AutoLog(value = "评论-取消置顶")
@Operation(summary = "取消置顶评论", description = "将指定评论取消置顶设置iz_top字段为0")
@RequiresPermissions("aiol:aiol_comment:edit")
@GetMapping(value = "/untop/{commentId}")
public Result<String> 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());
}
}
} }

View File

@ -16,8 +16,10 @@ import org.jeecg.common.system.query.QueryRuleEnum;
import org.jeecg.common.util.oConvertUtils; import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.aiol.entity.AiolCourseSection; import org.jeecg.modules.aiol.entity.AiolCourseSection;
import org.jeecg.modules.aiol.entity.AiolEntityLink; 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.dto.AiolCourseSectionDTO;
import org.jeecg.modules.aiol.service.IAiolCourseSectionService; import org.jeecg.modules.aiol.service.IAiolCourseSectionService;
import org.jeecg.modules.aiol.service.IAiolEntityLinkService;
import org.jeecg.modules.aiol.mapper.AiolEntityLinkMapper; import org.jeecg.modules.aiol.mapper.AiolEntityLinkMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -58,6 +60,8 @@ public class AiolCourseSectionController extends JeecgController<AiolCourseSecti
private IAiolCourseSectionService aiolCourseSectionService; private IAiolCourseSectionService aiolCourseSectionService;
@Autowired @Autowired
private AiolEntityLinkMapper aiolEntityLinkMapper; private AiolEntityLinkMapper aiolEntityLinkMapper;
@Autowired
private IAiolEntityLinkService aiolEntityLinkService;
/** /**
* 分页列表查询 * 分页列表查询
@ -143,24 +147,16 @@ public class AiolCourseSectionController extends JeecgController<AiolCourseSecti
// 先删除旧的关联关系 // 先删除旧的关联关系
QueryWrapper<AiolEntityLink> deleteWrapper = new QueryWrapper<>(); QueryWrapper<AiolEntityLink> deleteWrapper = new QueryWrapper<>();
deleteWrapper.eq("source_type", "course_section") deleteWrapper.eq("source_type", EntityLinkConst.SourceType.COURSE_SECTION)
.eq("source_id", sectionDTO.getId()); .eq("source_id", sectionDTO.getId());
aiolEntityLinkMapper.delete(deleteWrapper); aiolEntityLinkMapper.delete(deleteWrapper);
// 创建新的关联关系 // 创建新的关联关系
AiolEntityLink entityLink = new AiolEntityLink(); aiolEntityLinkService.save(EntityLinkConst.SourceType.COURSE_SECTION, sectionDTO.getId(), sectionDTO.getTargetType(), sectionDTO.getTargetId());
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);
} else { } else {
// 如果没有提供资源信息删除所有关联关系 // 如果没有提供资源信息删除所有关联关系
QueryWrapper<AiolEntityLink> deleteWrapper = new QueryWrapper<>(); QueryWrapper<AiolEntityLink> deleteWrapper = new QueryWrapper<>();
deleteWrapper.eq("source_type", "course_section") deleteWrapper.eq("source_type", EntityLinkConst.SourceType.COURSE_SECTION)
.eq("source_id", sectionDTO.getId()); .eq("source_id", sectionDTO.getId());
aiolEntityLinkMapper.delete(deleteWrapper); aiolEntityLinkMapper.delete(deleteWrapper);
} }

View File

@ -36,6 +36,7 @@ import org.jeecg.modules.aiol.mapper.AiolClassStudentMapper;
import org.jeecg.modules.aiol.mapper.AiolCourseSignupMapper; import org.jeecg.modules.aiol.mapper.AiolCourseSignupMapper;
import org.jeecg.modules.aiol.entity.AiolClassStudent; import org.jeecg.modules.aiol.entity.AiolClassStudent;
import org.jeecg.modules.aiol.entity.AiolCourseSignup; 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.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
@ -388,6 +389,106 @@ public class AiolHomeworkController extends JeecgController<AiolHomework, IAiolH
} }
} }
@AutoLog(value = "作业-教师编辑")
@Operation(summary = "作业-教师编辑", description = "教师编辑作业,更新作业基础信息、章节关联,并为新范围内学生补齐提交记录")
@RequiresPermissions("aiol:aiol_homework:edit")
@PostMapping(value = "/teacher_edit")
public Result<String> 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<AiolEntityLink> 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<String> 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<AiolClassStudent> csWrapper = new QueryWrapper<>();
csWrapper.eq("class_id", singleClassId.trim());
List<AiolClassStudent> 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<AiolCourseSignup> suWrapper = new QueryWrapper<>();
suWrapper.eq("course_id", courseId.trim());
List<AiolCourseSignup> 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<AiolHomeworkSubmit> 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 = "作业-批阅") @AutoLog(value = "作业-批阅")
@Operation(summary = "作业批阅", description = "教师批阅作业,更新作业提交记录的分数和状态") @Operation(summary = "作业批阅", description = "教师批阅作业,更新作业提交记录的分数和状态")
@RequiresPermissions("aiol:aiol_homework:edit") @RequiresPermissions("aiol:aiol_homework:edit")