From 027cde89bbd242f88c7d71ff602a12747b477ac5 Mon Sep 17 00:00:00 2001
From: luohairen <3399054449@qq.com>
Date: 星期四, 07 十一月 2024 15:53:40 +0800
Subject: [PATCH] 完成教师端,考试列表展示
---
src/main/java/com/ycl/jxkg/service/impl/ExamServiceImpl.java | 479 +++++++++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 361 insertions(+), 118 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 f89bf62..70f5f85 100644
--- a/src/main/java/com/ycl/jxkg/service/impl/ExamServiceImpl.java
+++ b/src/main/java/com/ycl/jxkg/service/impl/ExamServiceImpl.java
@@ -2,17 +2,24 @@
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+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.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;
@@ -26,12 +33,14 @@
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;
@@ -71,7 +80,6 @@
private final UserMapper userMapper;
private final ExamPaperScoreMapper examPaperScoreMapper;
private final ExamPaperScoreService examPaperScoreService;
- private static final String ANSWER_SPLIT = ",";
private final Producer producer;
@@ -86,10 +94,20 @@
Exam entity = ExamForm.getEntityByForm(form, null);
entity.setStatus(ExamStatusEnum.getStatusByTime(form.getStartTime(), form.getEndTime(), null));
entity.setTeacherId(webContext.getCurrentUser().getId());
- // 璁剧疆涔愯閿佺増鏈�
- entity.setUpdateVersion(0);
- if (baseMapper.insert(entity) > 0) {
- this.sendMQ(entity, 0);
+
+ // 鏌ュ嚭鑰冭瘯璇曞嵎
+ ExamPaper examPaper = examPaperMapper.selectById(entity.getExamPaperId());
+ // 鏍¢獙鑳藉惁鐢熸垚涓�寮犺瘯鍗�
+ try {
+ this.checkGenExam(examPaper);
+ // 璁剧疆涔愯閿佺増鏈�
+ entity.setUpdateVersion(0);
+ if (baseMapper.insert(entity) > 0) {
+ this.sendMQ(entity, 0);
+ }
+ } catch (RuntimeException e) {
+ e.printStackTrace();
+ return Result.fail(500, e.getMessage());
}
return Result.ok("娣诲姞鎴愬姛");
}
@@ -106,14 +124,23 @@
// 涓虹┖鎶汭llegalArgumentException锛屽仛鍏ㄥ眬寮傚父澶勭悊
Assert.notNull(entity, "璁板綍涓嶅瓨鍦�");
// 鍒ゆ柇鑰冭瘯鐘舵��
- if (! ExamStatusEnum.NOT_START.equals(entity.getStatus())) {
+ if (!ExamStatusEnum.NOT_START.equals(entity.getStatus())) {
throw new RuntimeException("鍙兘淇敼杩樻湭寮�濮嬬殑鑰冭瘯");
}
BeanUtils.copyProperties(form, entity);
- entity.setStatus(ExamStatusEnum.getStatusByTime(form.getStartTime(), form.getEndTime(), null));
- // 濡傛灉淇敼鎴愬姛鍙戦�乵q娑堟伅
- if (baseMapper.updateById(entity) > 0) {
- this.sendMQ(entity, entity.getUpdateVersion() + 1);
+ entity.setStatus(ExamStatusEnum.getStatusByTime(form.getStartTime(), form.getEndTime(), new Date()));
+
+ // 鏌ュ嚭鑰冭瘯璇曞嵎
+ ExamPaper examPaper = examPaperMapper.selectById(entity.getExamPaperId());
+ try {
+ this.checkGenExam(examPaper);
+ // 濡傛灉淇敼鎴愬姛鍙戦�乵q娑堟伅
+ if (baseMapper.updateById(entity) > 0) {
+ this.sendMQ(entity, entity.getUpdateVersion());
+ }
+ } catch (RuntimeException e) {
+ e.printStackTrace();
+ return Result.fail(500, e.getMessage());
}
return Result.ok("淇敼鎴愬姛");
}
@@ -121,7 +148,7 @@
/**
* 鍙戦�乵q娑堟伅
*
- * @param entity 鑰冭瘯瀹炰綋绫�
+ * @param entity 鑰冭瘯瀹炰綋绫�
* @param version 涔愯閿佺増鏈�
*/
public void sendMQ(Exam entity, Integer version) {
@@ -207,6 +234,7 @@
item.setExamPaperId(null);
}
});
+ //
return Result.ok().data(page.getRecords()).total(page.getTotal());
}
@@ -215,9 +243,103 @@
public Result studentPage(ExamQuery query) {
IPage<ExamVO> page = PageUtil.getPage(query, ExamVO.class);
baseMapper.studentPage(page, query, webContext.getCurrentUser().getId());
+ for (ExamVO record : page.getRecords()) {
+ ExamSubmitTemp one = new LambdaQueryChainWrapper<>(examSubmitTempMapper)
+ .eq(ExamSubmitTemp::getExamId, record.getId())
+ .eq(ExamSubmitTemp::getUserId, webContext.getCurrentUser().getId())
+ .one();
+ record.setIsContinue(Objects.isNull(one) || ExamSubmitTempStatusEnum.temp.equals(one.getExamSubmit()));
+ }
return Result.ok().data(page.getRecords()).total(page.getTotal());
}
+ /**
+ * 娴嬭瘯璇曞嵎閰嶇疆鑳藉惁鐢熸垚璇曞嵎
+ *
+ * @param examPaper
+ */
+ public void checkGenExam(ExamPaper examPaper) throws RuntimeException {
+ // 璇曞嵎鍐呭
+ List<PaperFixQuestionVO> examData = new ArrayList<>();
+ // 鎷垮埌棰樼洰鍓湰鏁版嵁
+ List<QuestionAnswerCopyVO> questionAnswerCopyVOList = new ArrayList<>(32);
+ 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();
+ if(0 == difficult) {
+ difficult = null;
+ }
+ //闇�瑕侀厤缃殑棰樼洰鏁伴噺涓�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);
+ if (! CollectionUtils.isEmpty(childQuestionList)) {
+ examData.add(paperFixQuestionVO);
+ }
+ }
+ }
+ }
@Override
@Transactional(rollbackFor = Exception.class)
@@ -246,6 +368,10 @@
.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());
@@ -282,50 +408,63 @@
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());
- //浠庨厤缃噷鎷块鐩垎鏁�
- doQuestionVO.setQuestionScore(paperSetting.getScore());
- 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();
+ if(0 == difficult){
+ difficult = null;
}
- 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());
+ //闇�瑕侀厤缃殑棰樼洰鏁伴噺涓�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());
}
- copy.setCorrect(String.join(ANSWER_SPLIT, gapAnswer));
- } else {
- copy.setCorrect(item.getCorrect());
- }
- questionAnswerCopyVOList.add(copy);
+ doQuestionVO.setId(item.getId());
+ doQuestionVO.setOriginalFile(item.getOriginalFile());
+ doQuestionVO.setAudioFile(item.getAudioFile());
- return doQuestionVO;
- }).collect(Collectors.toList());
- paperFixQuestionVO.setQuestionList(childQuestions);
- examData.add(paperFixQuestionVO);
+ // 棰樼洰鍓湰
+ 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);
+ if (! CollectionUtils.isEmpty(childQuestionList)) {
+ examData.add(paperFixQuestionVO);
+ }
}
- return Result.ok(startExamVO);
}
ExamSubmitTemp examSubmitTemp = new ExamSubmitTemp();
examSubmitTemp.setExamId(id);
@@ -362,6 +501,23 @@
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 -> {
@@ -372,24 +528,6 @@
doQuestionVO.setId(question.getId());
doQuestionVO.setOriginalFile(question.getOriginalFile());
doQuestionVO.setAudioFile(question.getAudioFile());
-
- // 棰樼洰鍓湰
- 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 : doQuestionVO.getQuestionItemList()) {
- gapAnswer.add(questionItemObject.getContent());
- }
- copy.setCorrect(String.join(ANSWER_SPLIT, gapAnswer));
- } else {
- copy.setCorrect(question.getCorrect());
- }
- questionAnswerCopyVOList.add(copy);
-
return doQuestionVO;
}).collect(Collectors.toList());
if (ExamPaperTypeEnum.RandomOrder.getCode().equals(examPaper.getPaperType())) {
@@ -420,10 +558,21 @@
* @return
*/
@Override
- public Result all() {
- List<Exam> entities = baseMapper.selectList(null);
+ public Result all(ExamQuery query) {
+ List<Exam> entities;
+ // 鍒ゆ柇濡傛灉examName涓虹┖鎴栫┖瀛楃涓诧紝鍒欐煡璇㈡墍鏈�
+ if (query.getExamName() == null || query.getExamName().isEmpty()) {
+ entities = baseMapper.selectList(null);
+ }else {
+ entities = baseMapper.selectList(new LambdaQueryWrapper<>(Exam.class).like(Exam::getExamName,query.getExamName()));
+ }
List<ExamVO> vos = entities.stream()
- .map(entity -> ExamVO.getVoByEntity(entity, null))
+ .map(entity -> {
+ ExamVO vo = new ExamVO();
+ vo = ExamVO.getVoByEntity(entity, vo);
+ vo.setStatus(entity.getStatus().getDesc());
+ return vo;
+ })
.collect(Collectors.toList());
return Result.ok().data(vos);
}
@@ -470,9 +619,6 @@
// 鐜板湪鍙渶瑕佷繚瀛樺埌涓�寮犱复鏃惰〃
// 璇ユ帴鍙f槸涓诲姩鎻愪氦锛屾墍浠ョ姸鎬侀兘璁剧疆涓哄畬鎴愶紝浠ヤ究鍚庣画鑰佸笀闃呭嵎
saveTempExam(submitData, ExamSubmitTempStatusEnum.finish);
-
- //TODO:鑰冭瘯鐘舵�佽瀹氫负缁撴潫
-
return Result.ok();
}
@@ -498,7 +644,6 @@
ExamSubmitTemp one = new LambdaQueryChainWrapper<>(examSubmitTempMapper)
.eq(ExamSubmitTemp::getExamId, submitData.getId())
.eq(ExamSubmitTemp::getUserId, webContext.getCurrentUser().getId())
- .eq(ExamSubmitTemp::getDeleted, 0)
.one();
if (Objects.nonNull(one)) {
@@ -535,7 +680,7 @@
throw new RuntimeException("鑰冭瘯璇曞嵎涓嶅瓨鍦�");
}
List<ExamSubmitTemp> examSubmitTempList = new LambdaQueryChainWrapper<>(examSubmitTempMapper)
- .eq(ExamSubmitTemp::getDeleted,0)
+ .eq(ExamSubmitTemp::getDeleted, 0)
.eq(ExamSubmitTemp::getExamId, id)
.list();
// 鍙傝�冧汉鏁�
@@ -543,15 +688,30 @@
// 鍙傝�冧絾鏈畬鎴愭彁浜や汉鏁�
Integer joinButNotFinishedNum = Math.toIntExact(examSubmitTempList.stream().filter(item -> ExamSubmitTempStatusEnum.temp.equals(item.getStatus())).count());
- List<StudentExamInfoVO> studentExamList = classesUserMapper.getClassesUserList(exam.getId(), exam.getClassesId());
+ 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());
@@ -569,20 +729,22 @@
@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);
}
- //濡傛灉宸茬粡闃呰繃鍗蜂簡锛屾煡鎴愮哗琛�
- Result<ExamPaperMarkVO> paperMarkVO1 = checkHasJudge(examId, userId, userExam);
- if (paperMarkVO1 != null) return paperMarkVO1;
-
- User student = userMapper.getUserById(userId);
- ExamVO exam = examMapper.getById(examId);
//灏佽闃呭嵎鍩烘湰鏁版嵁
ExamPaperMarkVO paperMarkVO = createVO(userExam, exam, student);
List<QuestionAnswerCopyVO> answerList = JSONArray.parseArray(userExam.getQuestionAnswerCopy(), QuestionAnswerCopyVO.class);
@@ -601,28 +763,35 @@
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());
+ if(questionId!=null) {
+ 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, Integer userId, ExamSubmitTemp userExam) {
- if (ExamSubmitTempStatusEnum.finish.equals(userExam.getMarkPaperStatus())) {
- 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() + "");
- List<PaperFixQuestionVO> paperFixQuestionVOS = JSONArray.parseArray(examPaperScore.getPaperContent(), PaperFixQuestionVO.class);
- paperMarkVO.setTitleItems(paperFixQuestionVOS);
- paperMarkVO.setNavbar(JSONArray.parseArray(examPaperScore.getNavbar(), ExamPaperMarkNavbarVO.class));
+ 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;
@@ -800,16 +969,23 @@
//灏佽闃呭嵎杩斿洖鏁版嵁
private ExamPaperMarkVO createVO(ExamSubmitTemp userExam, ExamVO exam, User student) {
- Integer paperId = exam.getExamPaperId();
- ExamPaper examPaper = examPaperMapper.selectById(paperId);
ExamPaperMarkVO paperMarkVO = new ExamPaperMarkVO();
- BeanUtils.copyProperties(userExam, paperMarkVO);
- paperMarkVO.setPaperId(exam.getExamPaperId());
- paperMarkVO.setExamName(exam.getExamName());
- paperMarkVO.setPaperType(exam.getExamPaperType());
- paperMarkVO.setSubmitTime(userExam.getUpdateTime());
+ 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.setTitleItems(JSON.parseArray(userExam.getExamSubmit(), PaperFixQuestionVO.class));
+ 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());
@@ -828,13 +1004,24 @@
examPaperScore.setTotalScore(new BigDecimal(examPaperMark.getTotalScore()));
examPaperScore.setJudgeUser(userId);
examPaperScore.setJudgeTime(new Date());
- examPaperScore.setPaperContent(JSON.toJSONString(examPaperMark.getTitleItems()));
- examPaperScore.setNavbar(JSON.toJSONString(examPaperMark.getNavbar()));
+ 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())) {
- questionCorrect = examPaperMark.getNavbar().stream().filter(vo -> vo.getRight()!=null && vo.getRight()).count();
+ 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 + ""));
@@ -845,6 +1032,15 @@
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();
}
@@ -853,26 +1049,73 @@
@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