From 8546b3d285af4235a0ef615a0c6e89486ae2c806 Mon Sep 17 00:00:00 2001 From: fuliqi <fuliqi@qq.com> Date: 星期四, 17 十月 2024 21:01:37 +0800 Subject: [PATCH] 达梦不支持value改为values --- src/main/java/com/ycl/jxkg/service/impl/ExamServiceImpl.java | 860 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 796 insertions(+), 64 deletions(-) diff --git a/src/main/java/com/ycl/jxkg/service/impl/ExamServiceImpl.java b/src/main/java/com/ycl/jxkg/service/impl/ExamServiceImpl.java index 921cff5..904e0e2 100644 --- a/src/main/java/com/ycl/jxkg/service/impl/ExamServiceImpl.java +++ b/src/main/java/com/ycl/jxkg/service/impl/ExamServiceImpl.java @@ -1,36 +1,56 @@ package com.ycl.jxkg.service.impl; import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONArray; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 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.service.impl.ServiceImpl; +import com.ycl.jxkg.base.Result; +import com.ycl.jxkg.base.SystemCode; +import com.ycl.jxkg.constants.ExamScoreConstant; import com.ycl.jxkg.context.WebContext; -import com.ycl.jxkg.domain.entity.Exam; -import com.ycl.jxkg.domain.entity.ExamSubmitTemp; -import com.ycl.jxkg.domain.entity.Question; -import com.ycl.jxkg.domain.vo.DoQuestionVO; -import com.ycl.jxkg.domain.vo.ExamSubmitVO; +import com.ycl.jxkg.domain.base.AbsVo; +import com.ycl.jxkg.domain.entity.*; +import com.ycl.jxkg.domain.exam.PaperFixQuestionDTO; +import com.ycl.jxkg.domain.exam.PaperQuestion; +import com.ycl.jxkg.domain.exam.PaperQuestionSettingDTO; +import com.ycl.jxkg.domain.exam.PaperSettingItem; +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.QuestionItemObject; +import com.ycl.jxkg.domain.question.QuestionObject; +import com.ycl.jxkg.domain.vo.*; +import com.ycl.jxkg.domain.vo.admin.exam.ExamPaperMarkNavbarVO; +import com.ycl.jxkg.domain.vo.admin.exam.ExamPaperMarkVO; +import com.ycl.jxkg.enums.DeductTypeEnum; +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.ExamMapper; -import com.ycl.jxkg.mapper.ExamSubmitTempMapper; -import com.ycl.jxkg.mapper.QuestionMapper; +import com.ycl.jxkg.mapper.*; +import com.ycl.jxkg.rabbitmq.msg.ExamStatusMsg; +import com.ycl.jxkg.rabbitmq.product.Producer; +import com.ycl.jxkg.server.WebsocketServer; +import com.ycl.jxkg.service.ExamPaperScoreService; +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.vo.ExamVO; -import com.ycl.jxkg.domain.query.ExamQuery; -import org.springframework.stereotype.Service; -import lombok.RequiredArgsConstructor; +import com.ycl.jxkg.utils.DateTimeUtil; 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; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.*; import java.util.stream.Collectors; /** @@ -43,10 +63,21 @@ @RequiredArgsConstructor public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements ExamService { + private static final String ANSWER_SPLIT = ","; + private final ExamMapper examMapper; private final WebContext webContext; private final QuestionMapper questionMapper; private final ExamSubmitTempMapper examSubmitTempMapper; + private final ClassesUserMapper classesUserMapper; + private final ExamPaperMapper examPaperMapper; + private final ExamPaperService examPaperService; + private final WebsocketServer websocketServer; + private final UserMapper userMapper; + private final ExamPaperScoreMapper examPaperScoreMapper; + private final ExamPaperScoreService examPaperScoreService; + + private final Producer producer; /** * 娣诲姞 @@ -59,7 +90,11 @@ Exam entity = ExamForm.getEntityByForm(form, null); entity.setStatus(ExamStatusEnum.getStatusByTime(form.getStartTime(), form.getEndTime(), null)); entity.setTeacherId(webContext.getCurrentUser().getId()); - baseMapper.insert(entity); + // 璁剧疆涔愯閿佺増鏈� + entity.setUpdateVersion(0); + if (baseMapper.insert(entity) > 0) { + this.sendMQ(entity, 0); + } return Result.ok("娣诲姞鎴愬姛"); } @@ -74,10 +109,62 @@ Exam entity = baseMapper.selectById(form.getId()); // 涓虹┖鎶汭llegalArgumentException锛屽仛鍏ㄥ眬寮傚父澶勭悊 Assert.notNull(entity, "璁板綍涓嶅瓨鍦�"); + // 鍒ゆ柇鑰冭瘯鐘舵�� + if (!ExamStatusEnum.NOT_START.equals(entity.getStatus())) { + throw new RuntimeException("鍙兘淇敼杩樻湭寮�濮嬬殑鑰冭瘯"); + } BeanUtils.copyProperties(form, entity); entity.setStatus(ExamStatusEnum.getStatusByTime(form.getStartTime(), form.getEndTime(), null)); - baseMapper.updateById(entity); + // 濡傛灉淇敼鎴愬姛鍙戦�乵q娑堟伅 + if (baseMapper.updateById(entity) > 0) { + this.sendMQ(entity, entity.getUpdateVersion()); + } return Result.ok("淇敼鎴愬姛"); + } + + /** + * 鍙戦�乵q娑堟伅 + * + * @param entity 鑰冭瘯瀹炰綋绫� + * @param version 涔愯閿佺増鏈� + */ + public void sendMQ(Exam entity, Integer version) { + // 濡傛灉褰撳墠鐘舵�佷负鏈紑濮嬶紝鍒欏彂閫佷袱鏉q娑堟伅锛屼竴鏉¤缃姸鎬佷负杩涜涓紝涓�鏉¤缃姸鎬佷负宸茬粨鏉� + if (ExamStatusEnum.NOT_START.equals(entity.getStatus())) { + // 杩涜鐘舵�佹秷鎭� + ExamStatusMsg ingMsg = new ExamStatusMsg(); + ingMsg.setVersion(version); + ingMsg.setExamId(entity.getId()); + ingMsg.setTargetStatus(ExamStatusEnum.ING); + producer.examMsg(entity.getId(), JSON.toJSONString(ingMsg), DateTimeUtil.getTwoTimeDiffMS(entity.getStartTime(), new Date())); + // 缁撴潫鐘舵�佹秷鎭� + ExamStatusMsg finishedMsg = new ExamStatusMsg(); + finishedMsg.setVersion(version); + finishedMsg.setExamId(entity.getId()); + finishedMsg.setTargetStatus(ExamStatusEnum.FINISHED); + producer.examMsg(entity.getId(), JSON.toJSONString(finishedMsg), DateTimeUtil.getTwoTimeDiffMS(entity.getEndTime(), new Date())); + } else if (ExamStatusEnum.ING.equals(entity.getStatus())) { // 褰撳墠鏄繘琛屼腑鐘舵�佸垯鍙渶鍙戦�佺粨鏉熸秷鎭� + // 缁撴潫鐘舵�佹秷鎭� + ExamStatusMsg finishedMsg = new ExamStatusMsg(); + finishedMsg.setVersion(0); + finishedMsg.setExamId(entity.getId()); + finishedMsg.setTargetStatus(ExamStatusEnum.FINISHED); + producer.examMsg(entity.getId(), JSON.toJSONString(finishedMsg), DateTimeUtil.getTwoTimeDiffMS(entity.getEndTime(), new Date())); + } + } + + /** + * 鏍规嵁鑰冭瘯鐨勫綋鍓嶇姸鎬侊紝寰楀埌涓嬩竴涓姸鎬� + * + * @param currentStatus + * @return + */ + public ExamStatusEnum getNextStatus(ExamStatusEnum currentStatus) { + if (ExamStatusEnum.NOT_START.equals(currentStatus)) { + return ExamStatusEnum.ING; + } else { + return ExamStatusEnum.FINISHED; + } } /** @@ -113,8 +200,221 @@ @Override public Result page(ExamQuery query) { IPage<ExamVO> page = PageUtil.getPage(query, ExamVO.class); - baseMapper.getPage(page, query); + baseMapper.getPage(page, query, webContext.getCurrentUser().getId()); + page.getRecords().stream().forEach(item -> { + if (!StringUtils.hasText(item.getClassName())) { + item.setClassName("鐝骇涓嶅瓨鍦ㄦ垨琚垹闄�"); + item.setClassesId(null); + } + if (!StringUtils.hasText(item.getExamPaperName())) { + item.setExamPaperName("璇曞嵎涓嶅瓨鍦ㄦ垨琚垹闄�"); + item.setExamPaperId(null); + } + }); return Result.ok().data(page.getRecords()).total(page.getTotal()); + } + + + @Override + public Result studentPage(ExamQuery query) { + IPage<ExamVO> page = PageUtil.getPage(query, ExamVO.class); + baseMapper.studentPage(page, query, webContext.getCurrentUser().getId()); + return Result.ok().data(page.getRecords()).total(page.getTotal()); + } + + + @Override + @Transactional(rollbackFor = Exception.class) + public Result start(Integer id) { + Exam exam = baseMapper.selectById(id); + if (Objects.isNull(exam)) { + throw new RuntimeException("璇ヨ�冭瘯涓嶅瓨鍦�"); + } + if (Objects.isNull(exam.getExamPaperId())) { + throw new RuntimeException("鑰冭瘯鏈粦瀹氳瘯鍗�"); + } + if (ExamStatusEnum.NOT_START.equals(exam.getStatus())) { + throw new RuntimeException("鑰冭瘯杩樻湭寮�濮�"); + } + if (ExamStatusEnum.FINISHED.equals(exam.getStatus())) { + throw new RuntimeException("鑰冭瘯宸茬粡缁撴潫"); + } + // 鏌ュ嚭鑰冭瘯璇曞嵎 + 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)) { + // 鍏佽鎻愪氦鍚庣户缁綔绛� +// if(ExamSubmitTempStatusEnum.finish.equals(hasJoin.getStatus())){ +// throw new RuntimeException("鎮ㄥ凡鎻愪氦璇曞嵎锛岃鍕块噸澶嶄綔绛�"); +// } + 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); + } + // 鍝嶅簲鏁版嵁 + StartExamVO startExamVO = new StartExamVO(); + startExamVO.setExamName(exam.getExamName()); + startExamVO.setId(exam.getId()); + startExamVO.setSuggestTime(examPaper.getSuggestTime()); + // 璇曞嵎鍐呭 + List<PaperFixQuestionVO> examData = new ArrayList<>(); + // 鎷垮埌棰樼洰鍓湰鏁版嵁 + List<QuestionAnswerCopyVO> questionAnswerCopyVOList = new ArrayList<>(32); + // 灏嗛鐩浆鎹负鍙复鏃朵繚瀛樼殑棰樼洰缁撴瀯銆傚浐瀹氳瘯鍗峰拰闅忓簭璇曞嵎鐨勯鐩槸鐩存帴淇濆瓨鍒癱ontent瀛楁鐨� + if (ExamPaperTypeEnum.Fixed.getCode().equals(examPaper.getPaperType()) + || ExamPaperTypeEnum.RandomOrder.getCode().equals(examPaper.getPaperType())) { + if (!StringUtils.hasText(examPaper.getContent())) { + throw new RuntimeException("璇曞嵎棰樼洰涓虹┖"); + } + // 杞崲 + examData = this.coverTo(examPaper, questionAnswerCopyVOList); + } else if (ExamPaperTypeEnum.Random.getCode().equals(examPaper.getPaperType())) { + // 鏍规嵁闅忔満璇曞嵎鐨勯厤缃紝闅忔満鐢熸垚瀵瑰簲棰樼洰 + if (!StringUtils.hasText(examPaper.getContent())) { + throw new RuntimeException("璇曞嵎閰嶇疆寮傚父锛岃鑱旂郴鑰佸笀"); + } + List<PaperQuestionSettingDTO> paperSettingList = JSON.parseArray(examPaper.getContent(), PaperQuestionSettingDTO.class); + examData = new ArrayList<>(8); + for (PaperQuestionSettingDTO paperSetting : paperSettingList) { + PaperFixQuestionVO paperFixQuestionVO = new PaperFixQuestionVO(); + paperFixQuestionVO.setTitle(paperSetting.getTitle()); + paperFixQuestionVO.setQuestionType(paperSetting.getQuestionType()); + //涓�涓被鍨嬬殑棰樼洰list + List<DoQuestionVO> childQuestionList = new ArrayList<>(); + List<PaperSettingItem> settingList = paperSetting.getSettingList(); + for (PaperSettingItem settingItem : settingList) { + Integer num = settingItem.getNum(); + Integer difficult = settingItem.getDifficult(); + //闇�瑕侀厤缃殑棰樼洰鏁伴噺涓�0鍒欒烦杩� + if (num == null || num == 0) continue; + List<Question> questions = questionMapper.getRandomQuestion(settingItem.getSubjectId(), paperSetting.getQuestionType(), difficult, settingItem.getNum()); + if (org.springframework.util.CollectionUtils.isEmpty(questions) || settingItem.getNum() > questions.size()) { + throw new RuntimeException("閰嶇疆鐨勯鐩暟涓嶈冻浠ョ敓鎴愯瘯鍗�"); + } + // 鎷垮埌棰樼洰鍚庣粍瑁呬负鍙复鏃朵繚瀛樼殑棰樼洰缁撴瀯 + List<DoQuestionVO> childQuestions = questions.stream().map(item -> { + DoQuestionVO doQuestionVO = new DoQuestionVO(); + doQuestionVO.setQuestionType(item.getQuestionType()); + //浠庨厤缃噷鎷块鐩垎鏁� + doQuestionVO.setQuestionScore(settingItem.getScore()); + if (StringUtils.hasText(item.getContent())) { + QuestionObject questionObject = JSON.parseObject(item.getContent(), QuestionObject.class); + doQuestionVO.setQuestionItemList(questionObject.getQuestionItemObjects()); + doQuestionVO.setTitle(questionObject.getTitleContent()); + } + doQuestionVO.setId(item.getId()); + doQuestionVO.setOriginalFile(item.getOriginalFile()); + doQuestionVO.setAudioFile(item.getAudioFile()); + + // 棰樼洰鍓湰 + QuestionAnswerCopyVO copy = new QuestionAnswerCopyVO(); + copy.setId(item.getId()); + copy.setDifficult(item.getDifficult()); + copy.setAnalyze(JSON.parseObject(item.getContent(), PaperQuestion.class).getAnalyze()); + //濉┖鐨勭瓟妗堝湪Json閲� + if (QuestionTypeEnum.GapFilling.getCode().equals(item.getQuestionType())) { + List<String> gapAnswer = new ArrayList<>(); + for (QuestionItemObject questionItemObject : doQuestionVO.getQuestionItemList()) { + gapAnswer.add(questionItemObject.getContent()); + } + copy.setCorrect(String.join(ANSWER_SPLIT, gapAnswer)); + } else { + copy.setCorrect(item.getCorrect()); + } + questionAnswerCopyVOList.add(copy); + + return doQuestionVO; + }).collect(Collectors.toList()); + //娣诲姞鍒拌繖涓被鍨嬬殑list涓� + childQuestionList.addAll(childQuestions); + } + paperFixQuestionVO.setQuestionList(childQuestionList); + examData.add(paperFixQuestionVO); + } + } + 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); + examSubmitTemp.setQuestionAnswerCopy(JSON.toJSONString(questionAnswerCopyVOList)); + examSubmitTempMapper.insert(examSubmitTemp); + startExamVO.setTitleList(examData); + return Result.ok(startExamVO); + } + + /** + * 灏嗘暟鎹簱瀛樺偍鐨勯鐩紝杞负鍙复鏃朵繚瀛樼殑棰樼洰缁撴瀯 + * + * @param examPaper 璇曞嵎 + * @param questionAnswerCopyVOList 棰樼洰鍓湰闆嗗悎 + * @return + */ + private List<PaperFixQuestionVO> coverTo(ExamPaper examPaper, List<QuestionAnswerCopyVO> questionAnswerCopyVOList) { + if (!StringUtils.hasText(examPaper.getContent())) { + throw new RuntimeException("璇曞嵎鏈厤缃鐩紝璇疯仈绯昏�佸笀"); + } + List<PaperFixQuestionDTO> questionWarpList = JSON.parseArray(examPaper.getContent(), PaperFixQuestionDTO.class); + return questionWarpList.stream().map(item -> { + PaperFixQuestionVO vo = new PaperFixQuestionVO(); + vo.setTitle(item.getTitle()); + vo.setQuestionType(item.getQuestionType()); + List<DoQuestionVO> doQuestionVOS = item.getQuestionList().stream().map(question -> { + DoQuestionVO doQuestionVO = new DoQuestionVO(); + doQuestionVO.setTitle(question.getTitle()); + doQuestionVO.setQuestionType(item.getQuestionType()); + //澧炲姞棰樼洰鍒嗘暟 + doQuestionVO.setQuestionScore(question.getScore()); + + // 棰樼洰鍓湰 + QuestionAnswerCopyVO copy = new QuestionAnswerCopyVO(); + copy.setId(question.getId()); + copy.setAnalyze(question.getAnalyze()); + copy.setDifficult(question.getDifficult()); + //濉┖鐨勭瓟妗堝湪Json閲� + if (QuestionTypeEnum.GapFilling.getCode().equals(item.getQuestionType())) { + List<String> gapAnswer = new ArrayList<>(); + for (QuestionItemObject questionItemObject : question.getItems()) { + gapAnswer.add(questionItemObject.getContent()); + } + copy.setCorrect(String.join(ANSWER_SPLIT, gapAnswer)); + } else { + copy.setCorrect(question.getCorrect()); + } + questionAnswerCopyVOList.add(copy); + + // 濉┖棰橀渶瑕佹姽闄ontent(鍥犱负鏄瓟妗�) + 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()); + doQuestionVO.setAudioFile(question.getAudioFile()); + return doQuestionVO; + }).collect(Collectors.toList()); + if (ExamPaperTypeEnum.RandomOrder.getCode().equals(examPaper.getPaperType())) { + // 闅忓簭璇曞嵎鎵撲贡椤哄簭 + Collections.shuffle(doQuestionVOS); + } + vo.setQuestionList(doQuestionVOS); + return vo; + }).collect(Collectors.toList()); } /** @@ -144,75 +444,507 @@ return Result.ok().data(vos); } + /** + * 涓诲姩鎻愪氦璇曞嵎 + * + * @param submitData 璇曞嵎鍋氶鎻愪氦鏁版嵁 + * @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("璇ヨ�冭瘯涓嶅瓨鍦�"); } - // 鍒ゆ柇鍗曢�夈�佸閫夈�佸垽鏂瀵归敊 - List<Integer> questionIds = submitData.getQuestionList().stream().map(DoQuestionVO::getId).collect(Collectors.toList()); - List<Question> questionList = questionMapper.getAnswerInfo(questionIds); - Map<Integer, Question> answerMap = questionList.stream().collect(Collectors.toMap(Question::getId, entity -> entity)); - submitData.getQuestionList().stream().forEach(item -> { - Question question = answerMap.get(item.getId()); - if (Objects.nonNull(question) - && (QuestionTypeEnum.SingleChoice.getCode().equals(question.getQuestionType()) - || QuestionTypeEnum.MultipleChoice.getCode().equals(question.getQuestionType()) - || QuestionTypeEnum.TrueFalse.getCode().equals(question.getQuestionType()) - )) { - String correct = question.getCorrect(); - if (QuestionTypeEnum.MultipleChoice.getCode().equals(question.getQuestionType())) { - // 濡傛灉鏄�夋嫨棰橈紝閭d箞灏嗙瓟妗堣浆涓簂ist - List<String> answerList = JSON.parseArray(correct, String.class); - item.setRight(answerList.containsAll(item.getAnswerList())); - } else { - item.setRight(question.getCorrect().equals(item.getAnswer())); - } - } - }); +// // 鍒ゆ柇鍗曢�夈�佸閫夈�佸垽鏂瀵归敊 +// List<Integer> questionIds = new ArrayList<>(24); +// submitData.getPaperQuestionList().forEach(item -> { +// List<Integer> ids = item.getQuestionList().stream().map(DoQuestionVO::getId).collect(Collectors.toList()); +// questionIds.addAll(ids); +// }); +// List<Question> questionList = questionMapper.getAnswerInfo(questionIds); +// Map<Integer, Question> answerMap = questionList.stream().collect(Collectors.toMap(Question::getId, entity -> entity)); +// submitData.getQuestionList().stream().forEach(item -> { +// Question question = answerMap.get(item.getId()); +// if (Objects.nonNull(question) +// && (QuestionTypeEnum.SingleChoice.getCode().equals(question.getQuestionType()) +// || QuestionTypeEnum.MultipleChoice.getCode().equals(question.getQuestionType()) +// || QuestionTypeEnum.TrueFalse.getCode().equals(question.getQuestionType()) +// )) { +// String correct = question.getCorrect(); +// if (QuestionTypeEnum.MultipleChoice.getCode().equals(question.getQuestionType())) { +// // 濡傛灉鏄�夋嫨棰橈紝閭d箞灏嗙瓟妗堣浆涓簂ist +// List<String> answerList = JSON.parseArray(correct, String.class); +// item.setRight(answerList.containsAll(item.getAnswerList())); +// } else { +// item.setRight(question.getCorrect().equals(item.getAnswer())); +// } +// } +// }); // 闃呭嵎鍚庢墠寰�exam_paper_answer淇濆瓨鑰冭瘯鎴愮哗銆佷互鍙婁繚瀛樺埌exam_paper_customer_answer // 鐜板湪鍙渶瑕佷繚瀛樺埌涓�寮犱复鏃惰〃 // 璇ユ帴鍙f槸涓诲姩鎻愪氦锛屾墍浠ョ姸鎬侀兘璁剧疆涓哄畬鎴愶紝浠ヤ究鍚庣画鑰佸笀闃呭嵎 - saveTempExam(submitData, ExamSubmitTempStatusEnum.FINISH); - return Result.ok(); - } - - @Override - public Result timingSubmit(ExamSubmitVO submitData) { - saveTempExam(submitData, ExamSubmitTempStatusEnum.TEMP); + saveTempExam(submitData, ExamSubmitTempStatusEnum.finish); return Result.ok(); } /** - * 淇濆瓨涓存椂璇曞嵎 + * 涓存椂淇濆瓨璇曞嵎 * - * @param submitData 鍓嶇浼犻�掔殑璇曞嵎鏁版嵁 - * @param status 璇曞嵎鐨勭姸鎬� + * @param submitData + * @return */ - public void saveTempExam(ExamSubmitVO submitData, ExamSubmitTempStatusEnum status) { + @Override + public Result timingSubmit(StartExamVO submitData) { + saveTempExam(submitData, ExamSubmitTempStatusEnum.temp); + return Result.ok(); + } + + /** + * 淇濆瓨璇曞嵎锛氬鏋滄帴鍙f槸瀹氭椂淇濆瓨閭d箞鏄复鏃惰瘯鍗枫�傚鏋滄帴鍙f槸鑷富鎻愪氦閭d箞鏄畬鎴愯瘯鍗� + * + * @param submitData 鍓嶇浼犻�掔殑璇曞嵎鏁版嵁 + * @param 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()) + .eq(ExamSubmitTemp::getDeleted, 0) .one(); + if (Objects.nonNull(one)) { - if (ExamSubmitTempStatusEnum.FINISH.equals(one.getStatus())) { + if (ExamSubmitTempStatusEnum.finish.equals(one.getStatus())) { return; } - one.setDoTime(submitData.getDoTime()); - one.setExamSubmit(JSON.toJSONString(submitData.getQuestionList())); - one.setCreateTime(new Date()); + Date now = new Date(); + one.setExamSubmit(JSON.toJSONString(submitData.getTitleList())); + one.setUpdateTime(now); + int doTimeInSeconds = (int) (now.getTime() - one.getCreateTime().getTime()) / 1000; + one.setDoTime(doTimeInSeconds); one.setStatus(status); examSubmitTempMapper.updateById(one); } else { ExamSubmitTemp examSubmitTemp = new ExamSubmitTemp(); - examSubmitTemp.setExamId(submitData.getExamId()); - examSubmitTemp.setDoTime(submitData.getDoTime()); + examSubmitTemp.setExamId(submitData.getId()); + examSubmitTemp.setDoTime(0); examSubmitTemp.setStatus(status); examSubmitTemp.setUserId(webContext.getCurrentUser().getId()); - examSubmitTemp.setExamSubmit(JSON.toJSONString(submitData.getQuestionList())); + examSubmitTemp.setExamSubmit(JSON.toJSONString(submitData.getTitleList())); + examSubmitTemp.setMarkPaperStatus(ExamSubmitTempStatusEnum.temp); examSubmitTempMapper.insert(examSubmitTemp); } } + + @Override + public Result getMarkResultInfo(Integer id) { + Exam exam = baseMapper.selectById(id); + if (Objects.isNull(exam)) { + throw new RuntimeException("璇ヨ�冭瘯涓嶅瓨鍦�"); + } + ExamPaper examPaper = examPaperMapper.selectById(exam.getExamPaperId()); + if (Objects.isNull(examPaper)) { + throw new RuntimeException("鑰冭瘯璇曞嵎涓嶅瓨鍦�"); + } + List<ExamSubmitTemp> examSubmitTempList = new LambdaQueryChainWrapper<>(examSubmitTempMapper) + .eq(ExamSubmitTemp::getDeleted, 0) + .eq(ExamSubmitTemp::getExamId, id) + .list(); + // 鍙傝�冧汉鏁� + Integer joinExamNum = examSubmitTempList.size(); + // 鍙傝�冧絾鏈畬鎴愭彁浜や汉鏁� + Integer joinButNotFinishedNum = Math.toIntExact(examSubmitTempList.stream().filter(item -> ExamSubmitTempStatusEnum.temp.equals(item.getStatus())).count()); + + List<StudentExamInfoVO> studentExamList = classesUserMapper.getClassesUserList(exam.getClassesId()); + // 搴旇�冧汉鏁� + Integer shouldUserNum = studentExamList.size(); + for (StudentExamInfoVO studentExamInfoVO : studentExamList) { + Integer userId = studentExamInfoVO.getUserId(); + Optional<ExamSubmitTemp> first = examSubmitTempList.stream().filter(examSubmitTemp -> examSubmitTemp.getUserId().equals(userId)).findFirst(); + if (first.isPresent()) { + ExamSubmitTemp examSubmitTemp = first.get(); + studentExamInfoVO.setMarkPaperStatus(examSubmitTemp.getMarkPaperStatus()); + studentExamInfoVO.setStatus(examSubmitTemp.getStatus()); + studentExamInfoVO.setDoTime(examSubmitTemp.getDoTime()); + } else { + //涓嶅瓨鍦ㄨ�冭瘯璁板綍 + 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); + } + } + + MarkPaperVO markPaperVO = new MarkPaperVO(); + markPaperVO.setExamName(exam.getExamName()); + markPaperVO.setExamId(exam.getId()); + markPaperVO.setJoinButNotFinishNum(joinButNotFinishedNum); + markPaperVO.setShouldJoinNum(shouldUserNum); + markPaperVO.setStudentExamInfoVOList(studentExamList); + markPaperVO.setMissJoinNum(shouldUserNum - joinExamNum); + markPaperVO.setJoinNum(joinExamNum); + markPaperVO.setExamPaperName(examPaper.getName()); + markPaperVO.setSuggestTime(examPaper.getSuggestTime()); + return Result.ok().data(markPaperVO); + } + + + @Override + public Result getMarkPaperInfo(Integer examId, Integer userId) { + User student = userMapper.getUserById(userId); + //濡傛灉宸茬粡闃呰繃鍗蜂簡锛屾煡鎴愮哗琛� + Result<ExamPaperMarkVO> paperMarkVO1 = checkHasJudge(examId, student); + if (paperMarkVO1 != null) return paperMarkVO1; + + ExamVO exam = examMapper.getById(examId); + //瀛︾敓绛旈琛� + ExamSubmitTemp userExam = new LambdaQueryChainWrapper<>(examSubmitTempMapper) + .eq(ExamSubmitTemp::getExamId, examId) + .eq(ExamSubmitTemp::getUserId, userId) + .one(); + if (Objects.isNull(userExam)) { + //缂鸿�冿紝瀛︾敓娌℃湁鍋氶淇℃伅 + ExamPaperMarkVO paperMarkVO = createVO(null, exam, student); + return Result.ok(paperMarkVO); + } + //灏佽闃呭嵎鍩烘湰鏁版嵁 + ExamPaperMarkVO paperMarkVO = createVO(userExam, exam, student); + List<QuestionAnswerCopyVO> answerList = JSONArray.parseArray(userExam.getQuestionAnswerCopy(), QuestionAnswerCopyVO.class); + //琛ュ厖棰樼洰绛旀銆佽В鏋� + addAnswer(paperMarkVO, answerList); + //闃呭嵎锛屽瑙傞鎵撳垎 + Result InnerError = markPaper(paperMarkVO); + if (InnerError != null) return InnerError; + + return Result.ok(paperMarkVO); + } + + //琛ュ厖棰樼洰绛旀銆佽В鏋� + private void addAnswer(ExamPaperMarkVO paperMarkVO, List<QuestionAnswerCopyVO> answerList) { + List<PaperFixQuestionVO> titleItems = paperMarkVO.getTitleItems(); + for (PaperFixQuestionVO titleItem : titleItems) { + for (DoQuestionVO doQuestionVO : titleItem.getQuestionList()) { + Integer questionId = doQuestionVO.getId(); + Optional<QuestionAnswerCopyVO> first = answerList.stream().filter(answer -> questionId.equals(answer.getId())).findFirst(); + if (first.isPresent()) { + QuestionAnswerCopyVO answerCopyVO = first.get(); + doQuestionVO.setQuestionAnswer(answerCopyVO.getCorrect()); + doQuestionVO.setAnalyze(answerCopyVO.getAnalyze()); + doQuestionVO.setDifficult(answerCopyVO.getDifficult()); + } + } + } + } + + //妫�鏌ユ槸鍚﹂槄鍗� + 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())) { + List<PaperFixQuestionVO> paperFixQuestionVOS = JSONArray.parseArray(examPaperScore.getPaperContent(), PaperFixQuestionVO.class); + paperMarkVO.setTitleItems(paperFixQuestionVOS); + } + if (!StringUtils.isEmpty(examPaperScore.getNavbar())) { + paperMarkVO.setNavbar(JSONArray.parseArray(examPaperScore.getNavbar(), ExamPaperMarkNavbarVO.class)); + } + return Result.ok(paperMarkVO); + } + return null; + } + + + //闃呭嵎 + private Result markPaper(ExamPaperMarkVO paperMarkVO) { + List<PaperFixQuestionVO> titleItems = paperMarkVO.getTitleItems(); + //鍒濆鍖栭鐩簭鍙� + Integer num = 1; + BigDecimal score = BigDecimal.ZERO; + //鍓嶇瀵艰埅鏁扮粍 + List<ExamPaperMarkNavbarVO> navbar = new ArrayList<>(); + //杩囨护鎺夐鐩负绌虹殑棰樼洰绫诲瀷 + titleItems = titleItems.stream().filter(paperFixQuestionVO -> !CollectionUtils.isEmpty(paperFixQuestionVO.getQuestionList())).collect(Collectors.toList()); + + for (PaperFixQuestionVO titleItem : titleItems) { + for (DoQuestionVO doQuestionVO : titleItem.getQuestionList()) { + //鍑嗗棰樼洰搴忓彿渚涘墠绔烦杞娇鐢� + ExamPaperMarkNavbarVO navbarVO = new ExamPaperMarkNavbarVO(); + //鑾峰彇璇曞嵎绫诲瀷 + Integer questionType = doQuestionVO.getQuestionType(); + /* 濡傛灉鏄畝绛斻�佽绠椼�佸垎鏋愶紝涓嶈缃畆ight鍙缃鐩簭鍙� */ + if (QuestionTypeEnum.ShortAnswer.getCode().equals(questionType) || QuestionTypeEnum.Calculate.getCode().equals(questionType) || QuestionTypeEnum.Analysis.getCode().equals(questionType)) { + navbarVO.setItemOrder(num); + doQuestionVO.setItemOrder(num); + } + /* 濡傛灉鏄崟閫夈�佽闊炽�佸垽鏂�(鍒ゆ柇绛旀鏄疉銆丅) */ + else if (QuestionTypeEnum.SingleChoice.getCode().equals(questionType) || QuestionTypeEnum.Audio.getCode().equals(questionType) || QuestionTypeEnum.TrueFalse.getCode().equals(questionType)) { + navbarVO.setItemOrder(num); + doQuestionVO.setItemOrder(num); + if (StringUtils.isEmpty(doQuestionVO.getQuestionAnswer())) { + return Result.fail(SystemCode.InnerError.getCode(), "棰樼洰id涓猴細" + doQuestionVO.getId() + "鐨勯鐩己灏戠瓟妗堬紝璇峰厛瀹屽杽"); + } + score = trueOrFalse(score, doQuestionVO, navbarVO, doQuestionVO.getQuestionAnswer().equals(doQuestionVO.getAnswer())); + } + /* 濡傛灉鏄閫� */ + else if (QuestionTypeEnum.MultipleChoice.getCode().equals(questionType)) { + navbarVO.setItemOrder(num); + doQuestionVO.setItemOrder(num); + if (StringUtils.isEmpty(doQuestionVO.getQuestionAnswer())) { + return Result.fail(SystemCode.InnerError.getCode(), "棰樼洰id涓猴細" + doQuestionVO.getId() + "鐨勯鐩己灏戠瓟妗堬紝璇峰厛瀹屽杽"); + } + //瀛︾敓绛旀 + List<String> answerList = doQuestionVO.getAnswerList(); + String questionAnswer = doQuestionVO.getQuestionAnswer(); + //棰樼洰绛旀 + List<String> questionAnswerList = Arrays.asList(questionAnswer.split(",")); + //瀛︾敓绛旀涓虹┖锛屽垽鏂负閿� + if (CollectionUtils.isEmpty(answerList)) { + score = trueOrFalse(score, doQuestionVO, navbarVO, false); + num++; + navbar.add(navbarVO); + continue; + } + //绛旀鏁伴噺锛屼笉闇�瑕佽�冭檻椤哄簭 + int answerCount = answerList.size(); + Set<String> set1 = new HashSet<>(answerList); + Set<String> set2 = new HashSet<>(questionAnswerList); + //绛旀瀹屽叏涓�鑷达紝婊″垎 + if (set1.equals(set2)) { + score = trueOrFalse(score, doQuestionVO, navbarVO, true); + num++; + navbar.add(navbarVO); + continue; + } + if (paperMarkVO.getDeductType() == null) { + return Result.fail(SystemCode.InnerError.getCode(), "璇曞嵎娌℃湁閰嶇疆澶氶�夊緱鍒嗙被鍨嬶紝璇疯仈绯荤鐞嗗憳"); + } + //濡傛灉澶氶�夊緱鍒嗙被鍨嬩负 绛旈敊涓嶅緱鍒� + if (Integer.valueOf(DeductTypeEnum.AllCorrect.getCode()).equals(paperMarkVO.getDeductType())) { + score = trueOrFalse(score, doQuestionVO, navbarVO, false); + } + //濡傛灉澶氶�夊緱鍒嗙被鍨嬩负 婕忛�夊緱鍥哄畾鍒嗗��,鍖呭惈閿欒閫夐」涓嶅緱鍒� + else if (Integer.valueOf(DeductTypeEnum.PartCorrect.getCode()).equals(paperMarkVO.getDeductType())) { + //瀛︾敓绛旀绉婚櫎鎵�鏈夋纭瓟妗堬紝濡傛灉杩樻湁鍏冪礌璇存槑鍖呭惈閿欒閫夐」 + answerList.removeAll(questionAnswerList); + if (!CollectionUtils.isEmpty(answerList)) { + score = trueOrFalse(score, doQuestionVO, navbarVO, false); + } else { + navbarVO.setRight(false); + doQuestionVO.setRight(false); + //婕忛�夊緱鍥哄畾鍒� + doQuestionVO.setScore(paperMarkVO.getDeductScore()); + score = score.add(doQuestionVO.getScore()); + } + } + //濡傛灉澶氶�夊緱鍒嗙被鍨嬩负 姣忓涓�棰樺緱鐩稿簲鍒嗗��,鍖呭惈閿欒閫夐」涓嶅緱鍒� + else if (Integer.valueOf(DeductTypeEnum.EachCorrect.getCode()).equals(paperMarkVO.getDeductType())) { + //瀛︾敓绛旀绉婚櫎鎵�鏈夋纭瓟妗堬紝濡傛灉杩樻湁鍏冪礌璇存槑鍖呭惈閿欒閫夐」 + answerList.removeAll(questionAnswerList); + if (!CollectionUtils.isEmpty(answerList)) { + score = trueOrFalse(score, doQuestionVO, navbarVO, false); + } else { + navbarVO.setRight(false); + doQuestionVO.setRight(false); + //婕忛�夊緱鍒� + doQuestionVO.setScore(paperMarkVO.getDeductScore().multiply(new BigDecimal(answerCount))); + score = score.add(doQuestionVO.getScore()); + } + } + } + /* 濡傛灉鏄~绌� */ + else if (QuestionTypeEnum.GapFilling.getCode().equals(questionType)) { + navbarVO.setItemOrder(num); + doQuestionVO.setItemOrder(num); + if (StringUtils.isEmpty(doQuestionVO.getQuestionAnswer())) { + return Result.fail(SystemCode.InnerError.getCode(), "棰樼洰id涓猴細" + doQuestionVO.getId() + "鐨勯鐩己灏戠瓟妗堬紝璇峰厛瀹屽杽"); + } + //瀛︾敓绛旀 + List<String> answerList = doQuestionVO.getAnswerList(); + String questionAnswer = doQuestionVO.getQuestionAnswer(); + //棰樼洰绛旀 + List<String> questionAnswerList = Arrays.asList(questionAnswer.split(",")); + //瀛︾敓绛旀涓虹┖锛屽垽鏂负閿� + if (CollectionUtils.isEmpty(answerList)) { + score = trueOrFalse(score, doQuestionVO, navbarVO, false); + num++; + navbar.add(navbarVO); + continue; + } + //鎬荤┖鐨勬暟閲� + int questionAnswerCount = questionAnswerList.size(); + //绛旀瀹屽叏涓�鑷达紝婊″垎 + if (answerList.equals(questionAnswerList)) { + score = trueOrFalse(score, doQuestionVO, navbarVO, true); + } else { + navbarVO.setRight(false); + doQuestionVO.setRight(false); + //鍋氬鐨勬暟閲�,闇�瑕佹寜椤哄簭姣旇緝 + int count = 0; + for (int i = 0; i < answerList.size(); i++) { + if (answerList.get(i).equals(questionAnswerList.get(i))) { + count++; + } + } + //杩欎釜棰樼殑鎬诲垎 + BigDecimal questionScore = doQuestionVO.getQuestionScore(); + //姣忎釜绌虹殑鍒嗘暟 + BigDecimal scoreEach = questionScore.divide(new BigDecimal(questionAnswerCount), 1, RoundingMode.DOWN); + //濉┖寰楀垎 + BigDecimal gapScore = scoreEach.multiply(new BigDecimal(count)); + doQuestionVO.setScore(gapScore); + score = score.add(doQuestionVO.getScore()); + } + + } + num++; + navbar.add(navbarVO); + } + } + paperMarkVO.setTitleItems(titleItems); + paperMarkVO.setNavbar(navbar); + paperMarkVO.setScore(score + ""); + return null; + } + + //璁剧疆鍏ㄥ鎴栧叏閿� + private BigDecimal trueOrFalse(BigDecimal score, DoQuestionVO doQuestionVO, ExamPaperMarkNavbarVO orderVO, Boolean isCorrect) { + if (isCorrect) { + //姝g‘ + orderVO.setRight(isCorrect); + doQuestionVO.setRight(isCorrect); + doQuestionVO.setScore(doQuestionVO.getQuestionScore()); + score = score.add(doQuestionVO.getQuestionScore()); + } else { + //閿欒 + orderVO.setRight(isCorrect); + doQuestionVO.setRight(isCorrect); + doQuestionVO.setScore(BigDecimal.ZERO); + } + return score; + } + + //灏佽闃呭嵎杩斿洖鏁版嵁 + private ExamPaperMarkVO createVO(ExamSubmitTemp userExam, ExamVO exam, User student) { + ExamPaperMarkVO paperMarkVO = new ExamPaperMarkVO(); + if (userExam != null) { + BeanUtils.copyProperties(userExam, paperMarkVO); + paperMarkVO.setSubmitTime(userExam.getUpdateTime()); + paperMarkVO.setTitleItems(JSON.parseArray(userExam.getExamSubmit(), PaperFixQuestionVO.class)); + } else { + //缂鸿�冿紝瀛︾敓娌℃湁鍋氶淇℃伅 + paperMarkVO.setExamId(exam.getId()); + paperMarkVO.setUserId(student.getId()); + paperMarkVO.setScore(BigDecimal.ZERO + ""); + paperMarkVO.setDoTime(0); + } + paperMarkVO.setUserName(student.getRealName()); + paperMarkVO.setExamName(exam.getExamName()); + paperMarkVO.setPaperId(exam.getExamPaperId()); + paperMarkVO.setPaperType(exam.getExamPaperType()); + ExamPaper examPaper = examPaperMapper.selectById(exam.getExamPaperId()); + paperMarkVO.setTotalScore(examPaper.getScore() + ""); + paperMarkVO.setDeductType(examPaper.getDeductType()); + paperMarkVO.setDeductScore(examPaper.getDeductTypeScore()); + return paperMarkVO; + } + + //鎻愪氦鎵规敼 + @Override + @Transactional(rollbackFor = Exception.class) + public Result submitMarkPaper(ExamPaperMarkVO examPaperMark) { + Integer userId = webContext.getCurrentUser().getId(); + //鎻掑叆exam_paper_answer(鎴愮哗琛�) + ExamPaperScore examPaperScore = new ExamPaperScore(); + BeanUtils.copyProperties(examPaperMark, examPaperScore); + examPaperScore.setScore(new BigDecimal(examPaperMark.getScore())); + examPaperScore.setTotalScore(new BigDecimal(examPaperMark.getTotalScore())); + examPaperScore.setJudgeUser(userId); + examPaperScore.setJudgeTime(new Date()); + if (!StringUtils.isEmpty(examPaperMark.getTitleItems())) { + examPaperScore.setPaperContent(JSON.toJSONString(examPaperMark.getTitleItems())); + } + if (!StringUtils.isEmpty(examPaperMark.getNavbar())) { + examPaperScore.setNavbar(JSON.toJSONString(examPaperMark.getNavbar())); + } + long questionCorrect = 0; + long questionCount = 0; + if (!CollectionUtils.isEmpty(examPaperMark.getNavbar())) { + examPaperScore.setStatus(ExamScoreConstant.PRESENT); + questionCorrect = examPaperMark.getNavbar().stream().filter(vo -> vo.getRight() != null && vo.getRight()).count(); + questionCount = examPaperMark.getNavbar().size(); + } else { + //缂鸿�冩煡璇曞嵎閰嶇疆 + Integer paperId = examPaperMark.getPaperId(); + ExamPaper examPaper = examPaperMapper.selectById(paperId); + questionCount = examPaper.getNum(); + examPaperScore.setStatus(ExamScoreConstant.ABSENT); + } + examPaperScore.setQuestionCorrect(Integer.valueOf(questionCorrect + "")); + examPaperScore.setQuestionCount(Integer.valueOf(questionCount + "")); + //鎵句箣鍓嶆湁鏃犳壒鏀硅褰� + ExamPaperScore score = examPaperScoreMapper.getByExamIdUserId(examPaperMark.getExamId(), examPaperMark.getUserId()); + if (score != null) { + examPaperScore.setId(score.getId()); + examPaperScoreMapper.updateById(examPaperScore); + } else { + examPaperScoreMapper.insert(examPaperScore); + //淇敼鑰冭瘯閲岃瘯鍗风姸鎬佷负宸查槄鍗� + ExamSubmitTemp userExam = new LambdaQueryChainWrapper<>(examSubmitTempMapper) + .eq(ExamSubmitTemp::getExamId, examPaperMark.getExamId()) + .eq(ExamSubmitTemp::getUserId, examPaperMark.getUserId()) + .one(); + if (userExam != null) { + userExam.setMarkPaperStatus(ExamSubmitTempStatusEnum.finish); + examSubmitTempMapper.updateById(userExam); + } + } + return Result.ok(); + } + + + @Override + public Result monitorList(ExamQuery query) { + IPage<ExamSubmitTempVO> page = PageUtil.getPage(query, ExamSubmitTempVO.class); + IPage<ExamSubmitTempVO> vo = examSubmitTempMapper.monitorList(page, query); + + return Result.ok(vo); + } + + @Override + public Result addTime(AddTimeForm form) { + if (!websocketServer.checkUserOnline(form.getUserId())) { + throw new RuntimeException("璇ュ鍛樹笉鍦ㄧ嚎锛屾棤娉曟墽琛岃鎿嶄綔"); + } + WebsocketDataVO websocket = new WebsocketDataVO(); + websocket.setCommend(WebsocketCommendEnum.DELAYED.getCommand()); + BigDecimal sed = BigDecimal.valueOf(60).multiply(form.getAddTimeM()); + form.setAddTimeM(sed); + websocket.setData(form); + // 鍙戦�亀ebsocket娑堟伅 + websocketServer.sendOneMessage(form.getUserId(), JSON.toJSONString(websocket)); + return Result.ok("鎿嶄綔鎴愬姛"); + } + + @Override + public Result forceSubmit(ForceSubmitForm form) { + if (!websocketServer.checkUserOnline(form.getUserId())) { + throw new RuntimeException("璇ュ鍛樹笉鍦ㄧ嚎锛屾棤娉曟墽琛岃鎿嶄綔"); + } + WebsocketDataVO websocket = new WebsocketDataVO(); + websocket.setCommend(WebsocketCommendEnum.FORCE_SUBMIT.getCommand()); + websocket.setData(form); + // 鍙戦�亀ebsocket娑堟伅 + websocketServer.sendOneMessage(form.getUserId(), JSON.toJSONString(websocket)); + return Result.ok("鎿嶄綔鎴愬姛"); + } } -- Gitblit v1.8.0