作业提交、查询,教师批改
This commit is contained in:
parent
4080fa4ce5
commit
bf96853b68
@ -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<Homework>> list(@PathVariable String courseId) {
|
||||
return Result.OK(homeworkBizService.listByCourseId(courseId));
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("submit")
|
||||
@Operation(summary = "提交作业")
|
||||
public Result<String> submit(@RequestBody StudentSubmitHomework studentSubmitHomework) {
|
||||
return Result.OK(homeworkSubmitService.submit(studentSubmitHomework)?"提交成功":"提交失败");
|
||||
}
|
||||
|
||||
@GetMapping("submitted/{studentId}")
|
||||
@Operation(summary = "查询我已提交的作业")
|
||||
public Result<List<HomeworkSubmit>> submitted(@PathVariable String studentId) {
|
||||
return Result.OK(homeworkSubmitService.submitted(studentId));
|
||||
}
|
||||
|
||||
@PostMapping("correct/{homeworkSubmitId}")
|
||||
@Operation(summary = "教师批改作业")
|
||||
public Result<Integer> correct(@PathVariable String homeworkSubmitId, @RequestParam Integer score,
|
||||
@RequestParam String comment,@RequestParam String teacherId) {
|
||||
return Result.OK(homeworkSubmitService.correct(homeworkSubmitId, score,comment, teacherId));
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
|
||||
}
|
@ -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<HomeworkSubmit> {
|
||||
|
||||
}
|
||||
|
@ -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<HomeworkSubmit> {
|
||||
|
||||
boolean submit(StudentSubmitHomework studentSubmitHomework);
|
||||
|
||||
List<HomeworkSubmit> submitted(String studentId);
|
||||
|
||||
Integer correct(String homeworkSubmitId, Integer score, String comment, String teacherId);
|
||||
|
||||
}
|
||||
|
@ -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<HomeworkSubmitMapper, HomeworkSubmit> 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<HomeworkSubmit> 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<HomeworkSubmit> submitted(String studentId) {
|
||||
return homeworkSubmitMapper.
|
||||
selectList(
|
||||
new LambdaQueryWrapper<HomeworkSubmit>().
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user