| | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.jxkg.base.Result; |
| | | import com.ycl.jxkg.context.WebContext; |
| | | import com.ycl.jxkg.domain.entity.*; |
| | | import com.ycl.jxkg.domain.entity.Exam; |
| | | import com.ycl.jxkg.domain.entity.ExamPaper; |
| | | import com.ycl.jxkg.domain.entity.ExamSubmitTemp; |
| | | import com.ycl.jxkg.domain.entity.Question; |
| | | import com.ycl.jxkg.domain.exam.PaperFixQuestionDTO; |
| | | import com.ycl.jxkg.domain.exam.PaperQuestionSettingDTO; |
| | | import com.ycl.jxkg.domain.form.AddTimeForm; |
| | | import com.ycl.jxkg.domain.form.ExamForm; |
| | | import com.ycl.jxkg.domain.form.ForceSubmitForm; |
| | | import com.ycl.jxkg.domain.query.ExamQuery; |
| | | import com.ycl.jxkg.domain.question.QuestionObject; |
| | | import com.ycl.jxkg.domain.vo.*; |
| | | import com.ycl.jxkg.domain.vo.admin.exam.ExamPaperEditRequestVO; |
| | | import com.ycl.jxkg.enums.ExamPaperTypeEnum; |
| | | import com.ycl.jxkg.enums.QuestionTypeEnum; |
| | | import com.ycl.jxkg.enums.WebsocketCommendEnum; |
| | | import com.ycl.jxkg.enums.general.ExamStatusEnum; |
| | | import com.ycl.jxkg.enums.general.ExamSubmitTempStatusEnum; |
| | | import com.ycl.jxkg.mapper.*; |
| | | import com.ycl.jxkg.server.WebsocketServer; |
| | | import com.ycl.jxkg.service.ExamPaperService; |
| | | import com.ycl.jxkg.service.ExamService; |
| | | import com.ycl.jxkg.base.Result; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.jxkg.domain.form.ExamForm; |
| | | import com.ycl.jxkg.domain.query.ExamQuery; |
| | | import org.springframework.stereotype.Service; |
| | | import lombok.RequiredArgsConstructor; |
| | | import com.ycl.jxkg.utils.PageUtil; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.Assert; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | |
| | | private final ClassesUserMapper classesUserMapper; |
| | | private final ExamPaperMapper examPaperMapper; |
| | | private final ExamPaperService examPaperService; |
| | | private final WebsocketServer websocketServer; |
| | | |
| | | /** |
| | | * 添加 |
| | |
| | | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result start(Integer id) { |
| | | Exam exam = baseMapper.selectById(id); |
| | | if (Objects.isNull(exam)) { |
| | |
| | | ExamPaper examPaper = examPaperMapper.selectById(exam.getExamPaperId()); |
| | | if (Objects.isNull(examPaper)) { |
| | | throw new RuntimeException("试卷不存在"); |
| | | } |
| | | // 如果已经参加过考试,直接返回数据 |
| | | ExamSubmitTemp hasJoin = new LambdaQueryChainWrapper<>(examSubmitTempMapper) |
| | | .eq(ExamSubmitTemp::getExamId, id) |
| | | .eq(ExamSubmitTemp::getUserId, webContext.getCurrentUser().getId()) |
| | | .one(); |
| | | if (Objects.nonNull(hasJoin)) { |
| | | StartExamVO startExamVO = new StartExamVO(); |
| | | startExamVO.setExamName(exam.getExamName()); |
| | | startExamVO.setId(hasJoin.getExamId()); |
| | | startExamVO.setTitleList(JSON.parseArray(hasJoin.getExamSubmit(), PaperFixQuestionVO.class)); |
| | | startExamVO.setSuggestTime(examPaper.getSuggestTime()); |
| | | startExamVO.setDoTime(hasJoin.getDoTime()); |
| | | return Result.ok(startExamVO); |
| | | } |
| | | // 将题目转换为可临时保存的题目结构。固定试卷和随序试卷的题目是直接保存到content字段的 |
| | | if (ExamPaperTypeEnum.Fixed.getCode().equals(examPaper.getPaperType()) |
| | |
| | | paperFixQuestionVO.setQuestionList(childQuestions); |
| | | examData.add(paperFixQuestionVO); |
| | | } |
| | | return Result.ok(examData); |
| | | ExamSubmitTemp examSubmitTemp = new ExamSubmitTemp(); |
| | | examSubmitTemp.setExamId(id); |
| | | examSubmitTemp.setStatus(ExamSubmitTempStatusEnum.TEMP); |
| | | examSubmitTemp.setExamSubmit(JSON.toJSONString(examData)); |
| | | examSubmitTemp.setCreateTime(new Date()); |
| | | examSubmitTemp.setUserId(webContext.getCurrentUser().getId()); |
| | | examSubmitTemp.setMarkPaperStatus(ExamSubmitTempStatusEnum.TEMP); |
| | | examSubmitTempMapper.insert(examSubmitTemp); |
| | | StartExamVO startExamVO = new StartExamVO(); |
| | | startExamVO.setExamName(exam.getExamName()); |
| | | startExamVO.setId(exam.getId()); |
| | | startExamVO.setTitleList(examData); |
| | | startExamVO.setSuggestTime(examPaper.getSuggestTime()); |
| | | return Result.ok(startExamVO); |
| | | } |
| | | return Result.ok(); |
| | | } |
| | |
| | | DoQuestionVO doQuestionVO = new DoQuestionVO(); |
| | | doQuestionVO.setTitle(question.getTitle()); |
| | | doQuestionVO.setQuestionType(item.getQuestionType()); |
| | | // 填空题需要抹除content(因为是答案) |
| | | if (QuestionTypeEnum.GapFilling.getCode().equals(doQuestionVO.getQuestionType())) { |
| | | question.getItems().stream().forEach(option -> { |
| | | option.setContent(""); |
| | | }); |
| | | } |
| | | doQuestionVO.setQuestionItemList(question.getItems()); |
| | | doQuestionVO.setId(question.getId()); |
| | | doQuestionVO.setOriginalFile(question.getOriginalFile()); |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result examSubmit(ExamSubmitVO submitData) { |
| | | public Result examSubmit(StartExamVO submitData) { |
| | | // 校验 |
| | | Exam exam = examMapper.selectById(submitData.getExamId()); |
| | | Exam exam = examMapper.selectById(submitData.getId()); |
| | | if (Objects.isNull(exam)) { |
| | | throw new RuntimeException("该考试不存在"); |
| | | } |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result timingSubmit(ExamSubmitVO submitData) { |
| | | public Result timingSubmit(StartExamVO submitData) { |
| | | saveTempExam(submitData, ExamSubmitTempStatusEnum.TEMP); |
| | | return Result.ok(); |
| | | } |
| | |
| | | * @param submitData 前端传递的试卷数据 |
| | | * @param status 试卷的状态 |
| | | */ |
| | | public void saveTempExam(ExamSubmitVO submitData, ExamSubmitTempStatusEnum status) { |
| | | public void saveTempExam(StartExamVO submitData, ExamSubmitTempStatusEnum status) { |
| | | ExamSubmitTemp one = new LambdaQueryChainWrapper<>(examSubmitTempMapper) |
| | | .eq(ExamSubmitTemp::getExamId, submitData.getExamId()) |
| | | .eq(ExamSubmitTemp::getExamId, submitData.getId()) |
| | | .eq(ExamSubmitTemp::getUserId, webContext.getCurrentUser().getId()) |
| | | .one(); |
| | | if (Objects.nonNull(one)) { |
| | |
| | | return; |
| | | } |
| | | one.setDoTime(submitData.getDoTime()); |
| | | one.setExamSubmit(JSON.toJSONString(submitData.getPaperQuestionList())); |
| | | one.setExamSubmit(JSON.toJSONString(submitData.getTitleList())); |
| | | one.setCreateTime(new Date()); |
| | | one.setStatus(status); |
| | | examSubmitTempMapper.updateById(one); |
| | | } else { |
| | | ExamSubmitTemp examSubmitTemp = new ExamSubmitTemp(); |
| | | examSubmitTemp.setExamId(submitData.getExamId()); |
| | | examSubmitTemp.setExamId(submitData.getId()); |
| | | examSubmitTemp.setDoTime(submitData.getDoTime()); |
| | | examSubmitTemp.setStatus(status); |
| | | examSubmitTemp.setUserId(webContext.getCurrentUser().getId()); |
| | | examSubmitTemp.setExamSubmit(JSON.toJSONString(submitData.getPaperQuestionList())); |
| | | examSubmitTemp.setExamSubmit(JSON.toJSONString(submitData.getTitleList())); |
| | | examSubmitTemp.setMarkPaperStatus(ExamSubmitTempStatusEnum.TEMP); |
| | | examSubmitTempMapper.insert(examSubmitTemp); |
| | | } |
| | |
| | | } |
| | | return Result.ok(vo); |
| | | } |
| | | |
| | | @Override |
| | | public Result monitorList(ExamQuery query) { |
| | | IPage<ExamSubmitTempVO> page = PageUtil.getPage(query, ExamSubmitTempVO.class); |
| | | return Result.ok((examSubmitTempMapper.monitorList(page, query))); |
| | | } |
| | | |
| | | @Override |
| | | public Result addTime(AddTimeForm form) { |
| | | WebsocketDataVO websocket = new WebsocketDataVO(); |
| | | websocket.setCommend(WebsocketCommendEnum.DELAYED.getCommend()); |
| | | websocket.setData(form); |
| | | // 发送websocket消息 |
| | | websocketServer.sendOneMessage(form.getUserId(), JSON.toJSONString(form)); |
| | | return Result.ok("操作成功"); |
| | | } |
| | | |
| | | @Override |
| | | public Result forceSubmit(ForceSubmitForm form) { |
| | | WebsocketDataVO websocket = new WebsocketDataVO(); |
| | | websocket.setCommend(WebsocketCommendEnum.FORCE_SUBMIT.getCommend()); |
| | | websocket.setData(form); |
| | | // 发送websocket消息 |
| | | websocketServer.sendOneMessage(form.getUserId(), JSON.toJSONString(form)); |
| | | return Result.ok("操作成功"); |
| | | } |
| | | } |