|
|
@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.njuzr.eaibackend.dto.AssignmentDTO;
|
|
|
import com.njuzr.eaibackend.dto.AssignmentQueryDTO;
|
|
|
import com.njuzr.eaibackend.dto.AssignmentUpdateDTO;
|
|
|
+import com.njuzr.eaibackend.dto.CorrectDTO;
|
|
|
import com.njuzr.eaibackend.enums.AssignmentCompletionStatus;
|
|
|
import com.njuzr.eaibackend.enums.AssignmentStatus;
|
|
|
import com.njuzr.eaibackend.enums.Role;
|
|
|
@@ -13,20 +14,19 @@ import com.njuzr.eaibackend.exception.MyException;
|
|
|
import com.njuzr.eaibackend.mapper.AssignmentMapper;
|
|
|
import com.njuzr.eaibackend.mapper.CourseMapper;
|
|
|
import com.njuzr.eaibackend.mapper.StudentAssignmentMapper;
|
|
|
-import com.njuzr.eaibackend.po.Assignment;
|
|
|
-import com.njuzr.eaibackend.po.Course;
|
|
|
-import com.njuzr.eaibackend.po.Engagement;
|
|
|
-import com.njuzr.eaibackend.po.MyUserDetails;
|
|
|
+import com.njuzr.eaibackend.mapper.UserMapper;
|
|
|
+import com.njuzr.eaibackend.po.*;
|
|
|
import com.njuzr.eaibackend.service.AssignmentService;
|
|
|
import com.njuzr.eaibackend.utils.*;
|
|
|
import com.njuzr.eaibackend.vo.AssignmentVO;
|
|
|
+import com.njuzr.eaibackend.vo.EngagementDetailVO;
|
|
|
import com.njuzr.eaibackend.vo.EngagementVO;
|
|
|
+import com.njuzr.eaibackend.vo.UserVO;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.io.ByteArrayInputStream;
|
|
|
import java.io.InputStream;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.Date;
|
|
|
@@ -47,14 +47,17 @@ public class AssignmentServiceImpl implements AssignmentService {
|
|
|
|
|
|
private final StudentAssignmentMapper studentAssignmentMapper;
|
|
|
|
|
|
+ private final UserMapper userMapper;
|
|
|
+
|
|
|
private final OssUtil ossUtil;
|
|
|
|
|
|
private final FileUtil fileUtil = new FileUtil();
|
|
|
|
|
|
- public AssignmentServiceImpl(AssignmentMapper assignmentMapper, CourseMapper courseMapper, StudentAssignmentMapper studentAssignmentMapper, OssUtil ossUtil) {
|
|
|
+ public AssignmentServiceImpl(AssignmentMapper assignmentMapper, CourseMapper courseMapper, StudentAssignmentMapper studentAssignmentMapper, UserMapper userMapper, OssUtil ossUtil) {
|
|
|
this.assignmentMapper = assignmentMapper;
|
|
|
this.courseMapper = courseMapper;
|
|
|
this.studentAssignmentMapper = studentAssignmentMapper;
|
|
|
+ this.userMapper = userMapper;
|
|
|
this.ossUtil = ossUtil;
|
|
|
}
|
|
|
|
|
|
@@ -214,6 +217,34 @@ public class AssignmentServiceImpl implements AssignmentService {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
+ public EngagementDetailVO getDetailEngagement(Long studentId, Long assignmentId) {
|
|
|
+ // 1 获取用户详细信息
|
|
|
+ User student = userMapper.selectById(studentId);
|
|
|
+ if (student == null)
|
|
|
+ throw MyException.create(HttpStatus.BAD_REQUEST, "学生不存在");
|
|
|
+
|
|
|
+ // 2 获取作业详细信息
|
|
|
+ Assignment assignment = assignmentMapper.selectById(assignmentId);
|
|
|
+ if (assignment == null)
|
|
|
+ throw MyException.create(HttpStatus.BAD_REQUEST, "作业不存在");
|
|
|
+
|
|
|
+ // 3 获取作业参与详细信息
|
|
|
+ Engagement engagement = studentAssignmentMapper.findEngagementByStudentIdAndAssignmentId(studentId, assignmentId);
|
|
|
+ if (engagement == null)
|
|
|
+ throw MyException.create(HttpStatus.BAD_REQUEST, "参与作业情况不存在");
|
|
|
+
|
|
|
+
|
|
|
+ EngagementDetailVO detailVO = ModelMapperUtil.map(engagement, EngagementDetailVO.class);
|
|
|
+ detailVO.setUserVO(ModelMapperUtil.map(student, UserVO.class));
|
|
|
+ detailVO.setAssignmentVO(convertToVO(assignment));
|
|
|
+ detailVO.setFileKey(assignmentId+"_"+studentId+"_"+engagement.getVersion());
|
|
|
+
|
|
|
+ log.info("请求到详细信息:"+detailVO.toString());
|
|
|
+
|
|
|
+ return detailVO;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 作业提交,更新文件版本和作业状态
|
|
|
* @param studentId
|
|
|
@@ -260,6 +291,34 @@ public class AssignmentServiceImpl implements AssignmentService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void engagementCorrect(Long teacherId, Long studentId, Long assignmentId, CorrectDTO correctDTO) {
|
|
|
+ Engagement engagement = studentAssignmentMapper.findEngagementByStudentIdAndAssignmentId(studentId, assignmentId);
|
|
|
+ if (engagement == null)
|
|
|
+ throw MyException.create(HttpStatus.BAD_REQUEST, "参与作业情况不存在");
|
|
|
+
|
|
|
+ Assignment assignment = assignmentMapper.selectById(assignmentId);
|
|
|
+ if (assignment == null)
|
|
|
+ throw MyException.create(HttpStatus.BAD_REQUEST, "作业不存在");
|
|
|
+
|
|
|
+ if (!Objects.equals(assignment.getTeacherId(), teacherId))
|
|
|
+ throw MyException.create(HttpStatus.BAD_REQUEST, "无权限批改");
|
|
|
+
|
|
|
+ engagement.setStatus(AssignmentCompletionStatus.CORRECTED); // 第一步,修改状态,改为已批改
|
|
|
+ engagement.setScore(correctDTO.getScore());
|
|
|
+ engagement.setRemark(correctDTO.getRemark());
|
|
|
+
|
|
|
+ try {
|
|
|
+ int code = studentAssignmentMapper.updateById(engagement);
|
|
|
+ if (code == 0)
|
|
|
+ throw MyException.create(HttpStatus.INTERNAL_SERVER_ERROR, "批改作业失败");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ throw MyException.create(HttpStatus.INTERNAL_SERVER_ERROR, "批改作业失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
private Assignment convertToPO(AssignmentDTO assignmentDTO) {
|
|
|
Assignment assignment = new Assignment();
|
|
|
BeanUtils.copyProperties(assignmentDTO, assignment);
|