diff --git a/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/biz/controller/HomeworkBizController.java b/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/biz/controller/HomeworkBizController.java index 54fccb8a..a123367b 100644 --- a/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/biz/controller/HomeworkBizController.java +++ b/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/biz/controller/HomeworkBizController.java @@ -1,10 +1,10 @@ package org.jeecg.modules.biz.controller; +import org.jeecg.modules.biz.dto.StudentSubmitHomework; +import org.jeecg.modules.gen.homeworksubmit.entity.HomeworkSubmit; +import org.jeecg.modules.gen.homeworksubmit.service.IHomeworkSubmitService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.Operation; import lombok.extern.slf4j.Slf4j; @@ -22,10 +22,32 @@ public class HomeworkBizController { @Autowired private IHomeworkBizService homeworkBizService; + @Autowired + private IHomeworkSubmitService homeworkSubmitService; @GetMapping("/course/{courseId}") @Operation(summary = "查询课程作业") public Result> list(@PathVariable String courseId) { return Result.OK(homeworkBizService.listByCourseId(courseId)); } -} + + @PostMapping("submit") + @Operation(summary = "提交作业") + public Result submit(@RequestBody StudentSubmitHomework studentSubmitHomework) { + return Result.OK(homeworkSubmitService.submit(studentSubmitHomework)?"提交成功":"提交失败"); + } + + @GetMapping("submitted/{studentId}") + @Operation(summary = "查询我已提交的作业") + public Result> submitted(@PathVariable String studentId) { + return Result.OK(homeworkSubmitService.submitted(studentId)); + } + + @PostMapping("correct/{homeworkSubmitId}") + @Operation(summary = "教师批改作业") + public Result correct(@PathVariable String homeworkSubmitId, @RequestParam Integer score, + @RequestParam String comment,@RequestParam String teacherId) { + return Result.OK(homeworkSubmitService.correct(homeworkSubmitId, score,comment, teacherId)); + } + +} \ No newline at end of file diff --git a/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/biz/dto/StudentSubmitHomework.java b/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/biz/dto/StudentSubmitHomework.java new file mode 100644 index 00000000..21aab66f --- /dev/null +++ b/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/biz/dto/StudentSubmitHomework.java @@ -0,0 +1,25 @@ +package org.jeecg.modules.biz.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +@Schema(description = "学生提交作业") +public class StudentSubmitHomework { + /**作业id*/ + @Schema(description = "作业id") + private String homeworkId; + /**学生id*/ + @Schema(description = "学生id") + private String studentId; + /**作业内容*/ + @Schema(description = "作业内容") + private String content; + /**附件*/ + @Schema(description = "附件") + private String attachment; + /**状态*/ + @Schema(description = "状态") + private Integer status; + +} diff --git a/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/gen/homeworksubmit/mapper/HomeworkSubmitMapper.java b/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/gen/homeworksubmit/mapper/HomeworkSubmitMapper.java index 7c2bbb28..5d6b0730 100644 --- a/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/gen/homeworksubmit/mapper/HomeworkSubmitMapper.java +++ b/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/gen/homeworksubmit/mapper/HomeworkSubmitMapper.java @@ -2,6 +2,7 @@ package org.jeecg.modules.gen.homeworksubmit.mapper; import java.util.List; +import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.jeecg.modules.gen.homeworksubmit.entity.HomeworkSubmit; import com.baomidou.mybatisplus.core.mapper.BaseMapper; @@ -12,6 +13,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; * @Date: 2025-08-21 * @Version: V1.0 */ +@Mapper public interface HomeworkSubmitMapper extends BaseMapper { } diff --git a/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/gen/homeworksubmit/service/IHomeworkSubmitService.java b/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/gen/homeworksubmit/service/IHomeworkSubmitService.java index a8abe45b..c14708d4 100644 --- a/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/gen/homeworksubmit/service/IHomeworkSubmitService.java +++ b/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/gen/homeworksubmit/service/IHomeworkSubmitService.java @@ -1,8 +1,12 @@ package org.jeecg.modules.gen.homeworksubmit.service; +import org.jeecg.modules.biz.dto.StudentSubmitHomework; +import org.jeecg.modules.gen.homework.entity.Homework; import org.jeecg.modules.gen.homeworksubmit.entity.HomeworkSubmit; import com.baomidou.mybatisplus.extension.service.IService; +import java.util.List; + /** * @Description: 作业提交 * @Author: jeecg-boot @@ -11,4 +15,10 @@ import com.baomidou.mybatisplus.extension.service.IService; */ public interface IHomeworkSubmitService extends IService { + boolean submit(StudentSubmitHomework studentSubmitHomework); + + List submitted(String studentId); + + Integer correct(String homeworkSubmitId, Integer score, String comment, String teacherId); + } diff --git a/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/gen/homeworksubmit/service/impl/HomeworkSubmitServiceImpl.java b/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/gen/homeworksubmit/service/impl/HomeworkSubmitServiceImpl.java index a267a5ba..d8fe16ab 100644 --- a/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/gen/homeworksubmit/service/impl/HomeworkSubmitServiceImpl.java +++ b/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/gen/homeworksubmit/service/impl/HomeworkSubmitServiceImpl.java @@ -1,19 +1,84 @@ package org.jeecg.modules.gen.homeworksubmit.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import org.jeecg.modules.biz.dto.StudentSubmitHomework; import org.jeecg.modules.gen.homeworksubmit.entity.HomeworkSubmit; import org.jeecg.modules.gen.homeworksubmit.mapper.HomeworkSubmitMapper; import org.jeecg.modules.gen.homeworksubmit.service.IHomeworkSubmitService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import java.util.Date; +import java.util.List; + /** * @Description: 作业提交 * @Author: jeecg-boot - * @Date: 2025-08-21 + * @Date: 2025-08-21 * @Version: V1.0 */ @Service public class HomeworkSubmitServiceImpl extends ServiceImpl implements IHomeworkSubmitService { + @Autowired + private HomeworkSubmitMapper homeworkSubmitMapper; + + @Override + public boolean submit(StudentSubmitHomework studentSubmitHomework) { + // 创建 HomeworkSubmit 对象,将studentSubmitHomework中的数据赋值给homeworkSubmit + HomeworkSubmit homeworkSubmit = new HomeworkSubmit(); + homeworkSubmit.setStudentId(studentSubmitHomework.getStudentId()); + homeworkSubmit.setHomeworkId(studentSubmitHomework.getHomeworkId()); + homeworkSubmit.setContent(studentSubmitHomework.getContent()); + homeworkSubmit.setAttachment(studentSubmitHomework.getAttachment()); + homeworkSubmit.setStatus(studentSubmitHomework.getStatus()); + // 检查是否已存在该学生的作业提交记录 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(HomeworkSubmit::getStudentId, homeworkSubmit.getStudentId()) + .eq(HomeworkSubmit::getHomeworkId, homeworkSubmit.getHomeworkId()); + HomeworkSubmit existingSubmit = homeworkSubmitMapper.selectOne(queryWrapper); + + // 设置公共字段 + homeworkSubmit.setUpdateTime(new Date()); + homeworkSubmit.setUpdateBy(homeworkSubmit.getStudentId()); + + if (existingSubmit != null) { + // 更新现有记录 + homeworkSubmit.setId(existingSubmit.getId()); + homeworkSubmit.setCreateBy(existingSubmit.getCreateBy()); + homeworkSubmit.setCreateTime(existingSubmit.getCreateTime()); + return homeworkSubmitMapper.updateById(homeworkSubmit) > 0; + } else { + // 插入新记录 + homeworkSubmit.setCreateBy(homeworkSubmit.getStudentId()); + homeworkSubmit.setCreateTime(new Date()); + return homeworkSubmitMapper.insert(homeworkSubmit) > 0; + } + } + + @Override + public List submitted(String studentId) { + return homeworkSubmitMapper. + selectList( + new LambdaQueryWrapper(). + eq(HomeworkSubmit::getStudentId, studentId). + eq(HomeworkSubmit::getStatus, 1) + ); + } + + @Override + public Integer correct(String homeworkSubmitId, Integer score, String comment, String teacherId) { + HomeworkSubmit homeworkSubmit = homeworkSubmitMapper.selectById(homeworkSubmitId); + if (homeworkSubmit != null) { + homeworkSubmit.setScore(score); + homeworkSubmit.setComment(comment); + homeworkSubmit.setStatus(2); + homeworkSubmit.setUpdateTime(new Date()); + homeworkSubmit.setUpdateBy(teacherId); + } + return homeworkSubmitMapper.updateById(homeworkSubmit); + } } +