From 1d23adb2fa62ab836aca1a6d47f8a5ab5b12938f Mon Sep 17 00:00:00 2001
From: lohir <3399054449@qq.com>
Date: 星期四, 17 十月 2024 15:35:11 +0800
Subject: [PATCH] 优化考试时间创建和修改会向后推8小时的问题
---
src/main/java/com/ycl/jxkg/service/impl/ExamServiceImpl.java | 705 +++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 615 insertions(+), 90 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 27d2974..e80229d 100644
--- a/src/main/java/com/ycl/jxkg/service/impl/ExamServiceImpl.java
+++ b/src/main/java/com/ycl/jxkg/service/impl/ExamServiceImpl.java
@@ -1,31 +1,48 @@
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.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;
+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.ExamPaper;
-import com.ycl.jxkg.domain.entity.ExamSubmitTemp;
-import com.ycl.jxkg.domain.entity.Question;
+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.ClassesStatusEnum;
import com.ycl.jxkg.enums.general.ExamStatusEnum;
import com.ycl.jxkg.enums.general.ExamSubmitTempStatusEnum;
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.utils.DateTimeUtil;
import com.ycl.jxkg.utils.PageUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
@@ -34,6 +51,8 @@
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;
@@ -47,6 +66,8 @@
@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;
@@ -55,6 +76,11 @@
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;
/**
* 娣诲姞
@@ -67,7 +93,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("娣诲姞鎴愬姛");
}
@@ -82,10 +112,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);
+ entity.setStatus(ExamStatusEnum.getStatusByTime(form.getStartTime(), form.getEndTime(), new Date()));
+ // 濡傛灉淇敼鎴愬姛鍙戦�乵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;
+ }
}
/**
@@ -123,15 +205,16 @@
IPage<ExamVO> page = PageUtil.getPage(query, ExamVO.class);
baseMapper.getPage(page, query, webContext.getCurrentUser().getId());
page.getRecords().stream().forEach(item -> {
- if (! StringUtils.hasText(item.getClassName())) {
+ if (!StringUtils.hasText(item.getClassName())) {
item.setClassName("鐝骇涓嶅瓨鍦ㄦ垨琚垹闄�");
item.setClassesId(null);
}
- if (! StringUtils.hasText(item.getExamPaperName())) {
+ if (!StringUtils.hasText(item.getExamPaperName())) {
item.setExamPaperName("璇曞嵎涓嶅瓨鍦ㄦ垨琚垹闄�");
item.setExamPaperId(null);
}
});
+ //
return Result.ok().data(page.getRecords()).total(page.getTotal());
}
@@ -165,76 +248,127 @@
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())) {
+ if (!StringUtils.hasText(examPaper.getContent())) {
throw new RuntimeException("璇曞嵎棰樼洰涓虹┖");
}
// 杞崲
- List<PaperFixQuestionVO> data = this.coverTo(examPaper);
- return Result.ok().data(data);
+ examData = this.coverTo(examPaper, questionAnswerCopyVOList);
} else if (ExamPaperTypeEnum.Random.getCode().equals(examPaper.getPaperType())) {
// 鏍规嵁闅忔満璇曞嵎鐨勯厤缃紝闅忔満鐢熸垚瀵瑰簲棰樼洰
- if (! StringUtils.hasText(examPaper.getContent())) {
+ if (!StringUtils.hasText(examPaper.getContent())) {
throw new RuntimeException("璇曞嵎閰嶇疆寮傚父锛岃鑱旂郴鑰佸笀");
}
List<PaperQuestionSettingDTO> paperSettingList = JSON.parseArray(examPaper.getContent(), PaperQuestionSettingDTO.class);
-
- // 璇曞嵎鍐呭
- List<PaperFixQuestionVO> examData = new ArrayList<>(8);
+ examData = new ArrayList<>(8);
for (PaperQuestionSettingDTO paperSetting : paperSettingList) {
PaperFixQuestionVO paperFixQuestionVO = new PaperFixQuestionVO();
paperFixQuestionVO.setTitle(paperSetting.getTitle());
paperFixQuestionVO.setQuestionType(paperSetting.getQuestionType());
- // 鎷垮埌璇剧洰涓嬫煇绫婚鍨嬬殑x閬撻殢鏈洪
- List<Question> questions = questionMapper.getRandomQuestion(examPaper.getSubjectId(), paperSetting.getQuestionType(), paperSetting.getNum());
- if (paperSetting.getNum() > questions.size()) {
- throw new RuntimeException("閰嶇疆鐨勯鐩暟涓嶈冻浠ョ敓鎴愯瘯鍗�");
- }
- // 鎷垮埌棰樼洰鍚庣粍瑁呬负鍙复鏃朵繚瀛樼殑棰樼洰缁撴瀯
- List<DoQuestionVO> childQuestions = questions.stream().map(item -> {
- DoQuestionVO doQuestionVO = new DoQuestionVO();
- doQuestionVO.setTitle(item.getTitle());
- doQuestionVO.setQuestionType(item.getQuestionType());
- if (StringUtils.hasText(item.getContent())) {
- QuestionObject questionObject = JSON.parseObject(item.getContent(), QuestionObject.class);
- doQuestionVO.setQuestionItemList(questionObject.getQuestionItemObjects());
+ //涓�涓被鍨嬬殑棰樼洰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("閰嶇疆鐨勯鐩暟涓嶈冻浠ョ敓鎴愯瘯鍗�");
}
- doQuestionVO.setId(item.getId());
- doQuestionVO.setOriginalFile(item.getOriginalFile());
- doQuestionVO.setAudioFile(item.getAudioFile());
- return doQuestionVO;
- }).collect(Collectors.toList());
- paperFixQuestionVO.setQuestionList(childQuestions);
+ // 鎷垮埌棰樼洰鍚庣粍瑁呬负鍙复鏃朵繚瀛樼殑棰樼洰缁撴瀯
+ 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);
- 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();
+ 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 examPaper 璇曞嵎
+ * @param questionAnswerCopyVOList 棰樼洰鍓湰闆嗗悎
* @return
*/
- private List<PaperFixQuestionVO> coverTo(ExamPaper examPaper) {
- if (! StringUtils.hasText(examPaper.getContent())) {
+ 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);
@@ -246,6 +380,32 @@
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());
@@ -295,9 +455,9 @@
* @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("璇ヨ�冭瘯涓嶅瓨鍦�");
}
@@ -329,7 +489,7 @@
// 闃呭嵎鍚庢墠寰�exam_paper_answer淇濆瓨鑰冭瘯鎴愮哗銆佷互鍙婁繚瀛樺埌exam_paper_customer_answer
// 鐜板湪鍙渶瑕佷繚瀛樺埌涓�寮犱复鏃惰〃
// 璇ユ帴鍙f槸涓诲姩鎻愪氦锛屾墍浠ョ姸鎬侀兘璁剧疆涓哄畬鎴愶紝浠ヤ究鍚庣画鑰佸笀闃呭嵎
- saveTempExam(submitData, ExamSubmitTempStatusEnum.FINISH);
+ saveTempExam(submitData, ExamSubmitTempStatusEnum.finish);
return Result.ok();
}
@@ -340,39 +500,43 @@
* @return
*/
@Override
- public Result timingSubmit(ExamSubmitVO submitData) {
- saveTempExam(submitData, ExamSubmitTempStatusEnum.TEMP);
+ public Result timingSubmit(StartExamVO submitData) {
+ saveTempExam(submitData, ExamSubmitTempStatusEnum.temp);
return Result.ok();
}
/**
* 淇濆瓨璇曞嵎锛氬鏋滄帴鍙f槸瀹氭椂淇濆瓨閭d箞鏄复鏃惰瘯鍗枫�傚鏋滄帴鍙f槸鑷富鎻愪氦閭d箞鏄畬鎴愯瘯鍗�
*
- * @param submitData 鍓嶇浼犻�掔殑璇曞嵎鏁版嵁
- * @param status 璇曞嵎鐨勭姸鎬�
+ * @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())
+ .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.getPaperQuestionList()));
- 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.getPaperQuestionList()));
- examSubmitTemp.setMarkPaperStatus(ExamSubmitTempStatusEnum.TEMP);
+ examSubmitTemp.setExamSubmit(JSON.toJSONString(submitData.getTitleList()));
+ examSubmitTemp.setMarkPaperStatus(ExamSubmitTempStatusEnum.temp);
examSubmitTempMapper.insert(examSubmitTemp);
}
}
@@ -388,22 +552,38 @@
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());
+ 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();
-
- studentExamList.stream().forEach(item -> {
- if (StringUtils.hasText(item.getExamSubmit())) {
- item.setQuestionList(JSON.parseArray(item.getExamSubmit(), DoQuestionVO.class));
+ 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());
@@ -421,46 +601,391 @@
@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)) {
- throw new RuntimeException("璇ュ鍛樿�冭瘯璁板綍涓嶅瓨鍦�");
+ //缂鸿�冿紝瀛︾敓娌℃湁鍋氶淇℃伅
+ ExamPaperMarkVO paperMarkVO = createVO(null, exam, student);
+ return Result.ok(paperMarkVO);
}
- ExamSubmitVO vo = new ExamSubmitVO();
- vo.setExamId(userExam.getExamId());
- vo.setDoTime(userExam.getDoTime());
- vo.setUpdateTime(userExam.getUpdateTime());
- if (StringUtils.hasText(userExam.getExamSubmit())) {
- vo.setPaperQuestionList(JSON.parseArray(userExam.getExamSubmit(), PaperFixQuestionVO.class));
- }
- return Result.ok(vo);
+ //灏佽闃呭嵎鍩烘湰鏁版嵁
+ 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);
- return Result.ok((examSubmitTempMapper.monitorList(page, query)));
+ 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.getCommend());
+ 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(form));
+ 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.getCommend());
+ websocket.setCommend(WebsocketCommendEnum.FORCE_SUBMIT.getCommand());
websocket.setData(form);
// 鍙戦�亀ebsocket娑堟伅
- websocketServer.sendOneMessage(form.getUserId(), JSON.toJSONString(form));
+ websocketServer.sendOneMessage(form.getUserId(), JSON.toJSONString(websocket));
return Result.ok("鎿嶄綔鎴愬姛");
}
+
+ /**
+ * 浣滃簾
+ *
+ * @param id
+ * @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();
+ ExamStatusEnum statusByTime = ExamStatusEnum.getStatusByTime(startTime, endTime, currentTime);
+ examInfo.setStatus(statusByTime);
+ // 淇敼褰撳墠鐨勮�冭瘯鐘舵��
+ new LambdaUpdateChainWrapper<>(examMapper)
+ .eq(Exam::getId, id)
+ .set(Exam::getStatus, examInfo.getStatus())
+ .update();
+ // 杩樺師鐝骇鐨勮�冭瘯淇℃伅
+ return Result.ok("鑰冭瘯璁板綍宸茬粡鎭㈠姝e父");
+ }
}
--
Gitblit v1.8.0