bug
lohir
2024-10-16 926f55cd895aa62d079ef18fee964d81bfae005e
src/main/java/com/ycl/jxkg/service/impl/ExamServiceImpl.java
@@ -3,9 +3,11 @@
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ycl.jxkg.base.Result;
import com.ycl.jxkg.base.SystemCode;
@@ -30,6 +32,7 @@
import com.ycl.jxkg.enums.ExamPaperTypeEnum;
import com.ycl.jxkg.enums.QuestionTypeEnum;
import com.ycl.jxkg.enums.WebsocketCommendEnum;
import com.ycl.jxkg.enums.general.ClassesStatusEnum;
import com.ycl.jxkg.enums.general.ExamStatusEnum;
import com.ycl.jxkg.enums.general.ExamSubmitTempStatusEnum;
import com.ycl.jxkg.mapper.*;
@@ -250,7 +253,7 @@
                .eq(ExamSubmitTemp::getUserId, webContext.getCurrentUser().getId())
                .one();
        if (Objects.nonNull(hasJoin)) {
            //TODO:开发环境先关闭
            // 允许提交后继续作答
//            if(ExamSubmitTempStatusEnum.finish.equals(hasJoin.getStatus())){
//                throw new RuntimeException("您已提交试卷,请勿重复作答");
//            }
@@ -568,8 +571,15 @@
                studentExamInfoVO.setStatus(examSubmitTemp.getStatus());
                studentExamInfoVO.setDoTime(examSubmitTemp.getDoTime());
            } else {
                studentExamInfoVO.setMarkPaperStatus(ExamSubmitTempStatusEnum.temp);
                //不存在考试记录
                studentExamInfoVO.setStatus(ExamSubmitTempStatusEnum.temp);
                //根据Score表判断
                ExamPaperScore paperScore = examPaperScoreMapper.getByExamIdUserId(exam.getId(), userId);
                if(paperScore==null) {
                    studentExamInfoVO.setMarkPaperStatus(ExamSubmitTempStatusEnum.temp);
                }else {
                    studentExamInfoVO.setMarkPaperStatus(ExamSubmitTempStatusEnum.finish);
                }
                studentExamInfoVO.setDoTime(0);
            }
        }
@@ -590,11 +600,11 @@
    @Override
    public Result getMarkPaperInfo(Integer examId, Integer userId) {
        User student = userMapper.getUserById(userId);
        //如果已经阅过卷了,查成绩表
        Result<ExamPaperMarkVO> paperMarkVO1 = checkHasJudge(examId, userId);
        Result<ExamPaperMarkVO> paperMarkVO1 = checkHasJudge(examId, student);
        if (paperMarkVO1 != null) return paperMarkVO1;
        User student = userMapper.getUserById(userId);
        ExamVO exam = examMapper.getById(examId);
        //学生答题表
        ExamSubmitTemp userExam = new LambdaQueryChainWrapper<>(examSubmitTempMapper)
@@ -636,11 +646,12 @@
    }
    //检查是否阅卷
    private Result<ExamPaperMarkVO> checkHasJudge(Integer examId, Integer userId) {
        ExamPaperScore examPaperScore = examPaperScoreMapper.getByExamIdUserId(examId, userId);
    private Result<ExamPaperMarkVO> checkHasJudge(Integer examId, User student) {
        ExamPaperScore examPaperScore = examPaperScoreMapper.getByExamIdUserId(examId, student.getId());
        if (examPaperScore != null) {
            ExamPaperMarkVO paperMarkVO = new ExamPaperMarkVO();
            BeanUtils.copyProperties(examPaperScore, paperMarkVO);
            paperMarkVO.setUserName(student.getRealName());
            paperMarkVO.setTotalScore(examPaperScore.getTotalScore() + "");
            paperMarkVO.setScore(examPaperScore.getScore() + "");
            if (!StringUtils.isEmpty(examPaperScore.getPaperContent())) {
@@ -834,7 +845,7 @@
            paperMarkVO.setTitleItems(JSON.parseArray(userExam.getExamSubmit(), PaperFixQuestionVO.class));
        } else {
            //缺考,学生没有做题信息
            paperMarkVO.setExamId(exam.getExamPaperId());
            paperMarkVO.setExamId(exam.getId());
            paperMarkVO.setUserId(student.getId());
            paperMarkVO.setScore(BigDecimal.ZERO + "");
            paperMarkVO.setDoTime(0);
@@ -907,7 +918,9 @@
    @Override
    public Result monitorList(ExamQuery query) {
        IPage<ExamSubmitTempVO> page = PageUtil.getPage(query, ExamSubmitTempVO.class);
        return Result.ok((examSubmitTempMapper.monitorList(page, query)));
        IPage<ExamSubmitTempVO> vo = examSubmitTempMapper.monitorList(page, query);
        return Result.ok(vo);
    }
    @Override
@@ -921,7 +934,7 @@
        form.setAddTimeM(sed);
        websocket.setData(form);
        // 发送websocket消息
        websocketServer.sendOneMessage(form.getUserId(), JSON.toJSONString(form));
        websocketServer.sendOneMessage(form.getUserId(), JSON.toJSONString(websocket));
        return Result.ok("操作成功");
    }
@@ -934,7 +947,49 @@
        websocket.setCommend(WebsocketCommendEnum.FORCE_SUBMIT.getCommand());
        websocket.setData(form);
        // 发送websocket消息
        websocketServer.sendOneMessage(form.getUserId(), JSON.toJSONString(form));
        websocketServer.sendOneMessage(form.getUserId(), JSON.toJSONString(websocket));
        return Result.ok("操作成功");
    }
    /**
     * 作废
     *
     * @param examId
     * @return {@link Result }
     * @author
     */
    @Override
    public Result cancel(Integer id) {
        new LambdaUpdateChainWrapper<>(examMapper)
                .eq(Exam::getId, id)
                .set(Exam::getStatus, ExamStatusEnum.CANCEL)
                .update();
        return Result.ok("作废成功");
    }
    @Override
    public Result recover(Integer id) {
        // 先查询当前考试记录的详细信息
        Exam examInfo = new LambdaQueryChainWrapper<>(examMapper)
                .eq(Exam::getId, id)
                .one();
        // 确定恢复后当前考试记录的状态
        Date currentTime = new Date();
        Date startTime = examInfo.getStartTime();
        Date endTime = examInfo.getEndTime();
        if (currentTime.before(startTime)) {
            examInfo.setStatus(ExamStatusEnum.NOT_START);
        } else if (currentTime.after(startTime) && currentTime.before(endTime)) {
            examInfo.setStatus(ExamStatusEnum.ING);
        } else {
            examInfo.setStatus(ExamStatusEnum.FINISHED);
        }
        // 修改当前的考试状态
        new LambdaUpdateChainWrapper<>(examMapper)
                .eq(Exam::getId, id)
                .set(Exam::getStatus, examInfo.getStatus())
                .update();
        // 还原班级的考试信息
        return Result.ok("考试记录已经恢复正常");
    }
}