Compare commits

...

2 Commits

Author SHA1 Message Date
GoCo
5da9d2135a Merge branch 'dev2' of http://110.42.96.64:19890/GoCo/OL-LearnPlatform-Backend into dev2
merge
2025-09-20 09:59:38 +08:00
GoCo
9dca80de0e feat: 🎸 接口补充 2025-09-20 09:59:29 +08:00
5 changed files with 366 additions and 0 deletions

View File

@ -223,6 +223,29 @@ public class AiolCommentController extends JeecgController<AiolComment, IAiolCom
}
}
@GetMapping("/discussion/{discussionId}/list")
@Operation(summary = "查询讨论评论列表", description = "根据讨论ID查询讨论评论列表包含用户信息和所有子评论支持多层嵌套所有子评论都放在顶级评论的replies中")
@IgnoreAuth
public Result<List<CommentWithUserInfo>> queryDiscussionCommentList(@PathVariable("discussionId") String discussionId) {
try {
// 1. 查询讨论的一级评论target_type=discussion, target_id=discussionId
List<CommentWithUserInfo> parentComments = aiolCommentService.getCommentList("discussion", discussionId);
// 2. 为每个一级评论查询其所有子评论递归查询所有层级
for (CommentWithUserInfo parentComment : parentComments) {
List<CommentWithUserInfo> allReplies = getAllRepliesRecursively(parentComment.getId());
parentComment.setReplies(allReplies);
}
log.info("查询讨论评论列表成功: discussionId={}, 一级评论数量={}", discussionId, parentComments.size());
return Result.OK(parentComments);
} catch (Exception e) {
log.error("查询讨论评论列表失败: discussionId={}, error={}", discussionId, e.getMessage(), e);
return Result.error("查询讨论评论列表失败: " + e.getMessage());
}
}
/**
* 递归查询评论的所有子评论
* @param commentId 评论ID

View File

@ -14,10 +14,15 @@ import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.query.QueryRuleEnum;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.config.shiro.IgnoreAuth;
import org.jeecg.modules.aiol.entity.AiolDiscussion;
import org.jeecg.modules.aiol.service.IAiolDiscussionService;
import org.jeecg.modules.aiol.service.IAiolEntityLinkService;
import org.jeecg.modules.aiol.constant.EntityLinkConst;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.constant.CommonConstant;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@ -55,6 +60,8 @@ public class AiolDiscussionController extends JeecgController<AiolDiscussion, IA
private IAiolDiscussionService aiolDiscussionService;
@Autowired
private IAiolEntityLinkService aiolEntityLinkService;
@Autowired
private ISysBaseAPI sysBaseApi;
/**
* 分页列表查询
@ -169,6 +176,7 @@ public class AiolDiscussionController extends JeecgController<AiolDiscussion, IA
//@AutoLog(value = "讨论-通过id查询")
@Operation(summary="讨论-通过id查询")
@GetMapping(value = "/queryById")
@IgnoreAuth
public Result<AiolDiscussion> queryById(@RequestParam(name="id",required=true) String id) {
AiolDiscussion aiolDiscussion = aiolDiscussionService.getById(id);
if(aiolDiscussion==null) {
@ -202,4 +210,34 @@ public class AiolDiscussionController extends JeecgController<AiolDiscussion, IA
return super.importExcel(request, response, AiolDiscussion.class);
}
@AutoLog(value = "讨论-查询用户讨论列表")
@Operation(summary = "查询用户讨论列表", description = "查询当前登录用户创建的讨论列表")
@GetMapping(value = "/teacher_list")
public Result<List<AiolDiscussion>> queryTeacherDiscussions(HttpServletRequest request) {
try {
// 1. 获取当前登录用户信息
String token = request.getHeader(CommonConstant.X_ACCESS_TOKEN);
String username = JwtUtil.getUsername(token);
LoginUser sysUser = sysBaseApi.getUserByName(username);
if (sysUser == null) {
return Result.error("用户未登录或登录已过期");
}
// 2. 查询当前用户创建的讨论列表
QueryWrapper<AiolDiscussion> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("create_by", sysUser.getUsername())
.orderByDesc("create_time");
List<AiolDiscussion> discussionList = aiolDiscussionService.list(queryWrapper);
log.info("查询用户讨论列表成功: userId={}, 讨论数量={}", sysUser.getId(), discussionList.size());
return Result.OK(discussionList);
} catch (Exception e) {
log.error("查询用户讨论列表失败: error={}", e.getMessage(), e);
return Result.error("查询用户讨论列表失败: " + e.getMessage());
}
}
}

View File

@ -15,6 +15,10 @@ import javax.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.query.QueryRuleEnum;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.aiol.dto.AiolHomeworkSaveDTO;
import org.jeecg.modules.aiol.dto.StudentSubmitHomework;
@ -204,6 +208,9 @@ public class AiolHomeworkController extends JeecgController<AiolHomework, IAiolH
@Autowired
private AiolCourseSignupMapper aiolCourseSignupMapper;
@Autowired
private ISysBaseAPI sysBaseApi;
@GetMapping("/course/{courseId}")
@Operation(summary = "查询课程作业")
@ -211,6 +218,36 @@ public class AiolHomeworkController extends JeecgController<AiolHomework, IAiolH
return Result.OK(aiolHomeworkService.listByCourseId(courseId));
}
@AutoLog(value = "作业-教师作业列表")
@Operation(summary = "查询教师作业列表", description = "查询当前登录教师创建的作业列表")
@GetMapping(value = "/teacher_list")
public Result<List<AiolHomework>> teacherList(HttpServletRequest request) {
try {
// 1. 获取当前登录用户信息
String token = request.getHeader(CommonConstant.X_ACCESS_TOKEN);
String username = JwtUtil.getUsername(token);
LoginUser sysUser = sysBaseApi.getUserByName(username);
if (sysUser == null) {
return Result.error("用户未登录或登录已过期");
}
// 2. 查询当前用户创建的作业列表
QueryWrapper<AiolHomework> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("create_by", sysUser.getUsername())
.orderByDesc("create_time");
List<AiolHomework> homeworkList = aiolHomeworkService.list(queryWrapper);
log.info("查询教师作业列表成功: teacherId={}, 作业数量={}", sysUser.getId(), homeworkList.size());
return Result.OK(homeworkList);
} catch (Exception e) {
log.error("查询教师作业列表失败: error={}", e.getMessage(), e);
return Result.error("查询教师作业列表失败: " + e.getMessage());
}
}
@PostMapping("submit")
@Operation(summary = "提交作业")
public Result<String> submit(@RequestBody StudentSubmitHomework studentSubmitHomework) {
@ -342,4 +379,58 @@ public class AiolHomeworkController extends JeecgController<AiolHomework, IAiolH
return Result.error("添加作业失败: " + e.getMessage());
}
}
@AutoLog(value = "作业-批阅")
@Operation(summary = "作业批阅", description = "教师批阅作业,更新作业提交记录的分数和状态")
@RequiresPermissions("aiol:aiol_homework:edit")
@PostMapping(value = "/review")
public Result<String> reviewHomework(@RequestBody Map<String, Object> reviewParams) {
try {
// 1. 从JSON参数中提取数据
String submitId = (String) reviewParams.get("submitId");
Integer score = (Integer) reviewParams.get("score");
String comment = (String) reviewParams.get("comment");
// 验证必填参数
if (submitId == null || submitId.trim().isEmpty()) {
return Result.error("submitId不能为空");
}
// 2. 查询作业提交记录
AiolHomeworkSubmit submit = homeworkSubmitService.getById(submitId);
if (submit == null) {
return Result.error("作业提交记录不存在");
}
// 3. 更新作业提交记录
AiolHomeworkSubmit updateSubmit = new AiolHomeworkSubmit();
updateSubmit.setId(submitId);
// 设置分数如果提供
if (score != null) {
updateSubmit.setScore(score);
}
// 设置评语如果提供
if (comment != null && !comment.trim().isEmpty()) {
updateSubmit.setComment(comment.trim());
}
// 更新状态为已批阅3
updateSubmit.setStatus(3);
// 4. 保存更新
boolean updated = homeworkSubmitService.updateById(updateSubmit);
if (!updated) {
return Result.error("批阅失败,更新作业提交记录失败");
}
log.info("作业批阅成功: submitId={}, score={}, status=3", submitId, score);
return Result.OK("批阅成功!");
} catch (Exception e) {
log.error("作业批阅失败: reviewParams={}, error={}", reviewParams, e.getMessage(), e);
return Result.error("批阅失败: " + e.getMessage());
}
}
}

View File

@ -15,7 +15,16 @@ import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.query.QueryRuleEnum;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.aiol.entity.AiolHomeworkSubmit;
import org.jeecg.modules.aiol.entity.AiolHomework;
import org.jeecg.modules.aiol.entity.AiolClass;
import org.jeecg.modules.aiol.entity.AiolClassStudent;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.aiol.service.IAiolHomeworkSubmitService;
import org.jeecg.modules.aiol.service.IAiolHomeworkService;
import org.jeecg.modules.aiol.service.IAiolClassService;
import org.jeecg.modules.aiol.mapper.AiolClassStudentMapper;
import org.jeecg.modules.system.service.ISysUserService;
import org.jeecg.modules.aiol.dto.HomeworkSubmitDetailDTO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@ -51,6 +60,18 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
public class AiolHomeworkSubmitController extends JeecgController<AiolHomeworkSubmit, IAiolHomeworkSubmitService> {
@Autowired
private IAiolHomeworkSubmitService aiolHomeworkSubmitService;
@Autowired
private IAiolHomeworkService aiolHomeworkService;
@Autowired
private IAiolClassService aiolClassService;
@Autowired
private AiolClassStudentMapper aiolClassStudentMapper;
@Autowired
private ISysUserService sysUserService;
/**
* 分页列表查询
@ -179,4 +200,129 @@ public class AiolHomeworkSubmitController extends JeecgController<AiolHomeworkSu
return super.importExcel(request, response, AiolHomeworkSubmit.class);
}
@AutoLog(value = "作业提交-查询作业提交情况")
@Operation(summary = "查询作业提交情况", description = "根据作业ID查询该作业的所有提交情况包含作业信息、学生信息、班级信息")
@GetMapping(value = "/homework/{homeworkId}/submits")
public Result<List<HomeworkSubmitDetailDTO>> queryHomeworkSubmits(@PathVariable("homeworkId") String homeworkId) {
try {
// 1. 查询指定作业的所有提交记录
QueryWrapper<AiolHomeworkSubmit> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("homework_id", homeworkId)
.orderByDesc("create_time");
List<AiolHomeworkSubmit> submitList = aiolHomeworkSubmitService.list(queryWrapper);
if (submitList.isEmpty()) {
log.info("查询作业提交情况成功: homeworkId={}, 提交数量=0", homeworkId);
return Result.OK(new java.util.ArrayList<>());
}
// 2. 查询作业信息
AiolHomework homework = aiolHomeworkService.getById(homeworkId);
if (homework == null) {
return Result.error("作业不存在");
}
// 3. 提取所有学生ID
List<String> studentIds = submitList.stream()
.map(AiolHomeworkSubmit::getStudentId)
.distinct()
.collect(Collectors.toList());
// 4. 批量查询学生信息
final Map<String, SysUser> studentMap;
if (!studentIds.isEmpty()) {
List<SysUser> students = sysUserService.listByIds(studentIds);
studentMap = students.stream()
.collect(Collectors.toMap(SysUser::getId, student -> student));
} else {
studentMap = new HashMap<>();
}
// 5. 查询学生班级关系
Map<String, AiolClass> studentClassMap = new HashMap<>();
if (!studentIds.isEmpty()) {
QueryWrapper<AiolClassStudent> classStudentWrapper = new QueryWrapper<>();
classStudentWrapper.in("student_id", studentIds);
List<AiolClassStudent> classStudents = aiolClassStudentMapper.selectList(classStudentWrapper);
if (!classStudents.isEmpty()) {
// 提取班级ID
List<String> classIds = classStudents.stream()
.map(AiolClassStudent::getClassId)
.distinct()
.collect(Collectors.toList());
// 批量查询班级信息
List<AiolClass> classes = aiolClassService.listByIds(classIds);
Map<String, AiolClass> classMap = classes.stream()
.collect(Collectors.toMap(AiolClass::getId, cls -> cls));
// 建立学生到班级的映射
for (AiolClassStudent classStudent : classStudents) {
AiolClass cls = classMap.get(classStudent.getClassId());
if (cls != null) {
studentClassMap.put(classStudent.getStudentId(), cls);
}
}
}
}
// 6. 组装结果
List<HomeworkSubmitDetailDTO> resultList = submitList.stream()
.map(submit -> {
HomeworkSubmitDetailDTO dto = new HomeworkSubmitDetailDTO();
// 复制提交信息
dto.setId(submit.getId());
dto.setHomeworkId(submit.getHomeworkId());
dto.setStudentId(submit.getStudentId());
dto.setContent(submit.getContent());
dto.setAttachment(submit.getAttachment());
dto.setScore(submit.getScore());
dto.setComment(submit.getComment());
dto.setStatus(submit.getStatus());
dto.setCreateTime(submit.getCreateTime());
dto.setUpdateTime(submit.getUpdateTime());
// 设置作业信息
dto.setHomeworkTitle(homework.getTitle());
dto.setHomeworkDescription(homework.getDescription());
dto.setHomeworkMaxScore(homework.getMaxScore());
dto.setHomeworkPassScore(homework.getPassScore());
dto.setHomeworkStartTime(homework.getStartTime());
dto.setHomeworkEndTime(homework.getEndTime());
dto.setHomeworkStatus(homework.getStatus());
dto.setHomeworkNotifyTime(homework.getNotifyTime());
dto.setHomeworkAllowMakeup(homework.getAllowMakeup());
dto.setHomeworkMakeupTime(homework.getMakeupTime());
// 设置学生信息
SysUser student = studentMap.get(submit.getStudentId());
if (student != null) {
dto.setStudentUsername(student.getUsername());
dto.setStudentRealname(student.getRealname());
dto.setStudentAvatar(student.getAvatar());
}
// 设置班级信息
AiolClass cls = studentClassMap.get(submit.getStudentId());
if (cls != null) {
dto.setClassId(cls.getId());
dto.setClassName(cls.getName());
}
return dto;
})
.collect(Collectors.toList());
log.info("查询作业提交情况成功: homeworkId={}, 提交数量={}", homeworkId, resultList.size());
return Result.OK(resultList);
} catch (Exception e) {
log.error("查询作业提交情况失败: homeworkId={}, error={}", homeworkId, e.getMessage(), e);
return Result.error("查询作业提交情况失败: " + e.getMessage());
}
}
}

View File

@ -0,0 +1,68 @@
package org.jeecg.modules.aiol.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.jeecg.modules.aiol.entity.AiolHomeworkSubmit;
import java.util.Date;
/**
* @Description: 作业提交详情DTO
* @Author: jeecg-boot
* @Date: 2025-01-16
* @Version: V1.0
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Schema(description = "作业提交详情")
public class HomeworkSubmitDetailDTO extends AiolHomeworkSubmit {
// 作业信息
@Schema(description = "作业标题")
private String homeworkTitle;
@Schema(description = "作业说明")
private String homeworkDescription;
@Schema(description = "作业满分")
private Integer homeworkMaxScore;
@Schema(description = "作业及格分数")
private Integer homeworkPassScore;
@Schema(description = "作业开始时间")
private Date homeworkStartTime;
@Schema(description = "作业结束时间")
private Date homeworkEndTime;
@Schema(description = "作业状态")
private Integer homeworkStatus;
@Schema(description = "作业通知时间")
private Integer homeworkNotifyTime;
@Schema(description = "是否允许补交")
private Integer homeworkAllowMakeup;
@Schema(description = "补交截止时间")
private Date homeworkMakeupTime;
// 学生用户信息
@Schema(description = "学生用户名")
private String studentUsername;
@Schema(description = "学生真实姓名")
private String studentRealname;
@Schema(description = "学生头像")
private String studentAvatar;
// 班级信息
@Schema(description = "班级ID")
private String classId;
@Schema(description = "班级名称")
private String className;
}