From 8092599fbdd7988b84d25d112a3af032c276629c Mon Sep 17 00:00:00 2001 From: xusd Date: Sat, 11 May 2024 11:17:24 +0800 Subject: [PATCH] =?UTF-8?q?=E8=80=83=E6=A0=B8=E8=AF=84=E4=BC=B0-=E6=88=91?= =?UTF-8?q?=E7=9A=84=E8=80=83=E8=AF=95=20=E7=94=9F=E6=88=90=E8=80=83?= =?UTF-8?q?=E8=AF=95=E9=A2=98=E5=92=8C=E6=9F=A5=E7=9C=8B=E8=80=83=E8=AF=95?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../examine/domain/ExamPaperQuestion.java | 5 + .../examine/domain/ExamQuestionBank.java | 5 + .../com/inspur/examine/dto/SubmitExamDTO.java | 3 +- .../mapper/ExamPaperQuestionMapper.java | 9 ++ .../service/IExamPaperQuestionService.java | 9 ++ .../impl/ExamPaperQuestionServiceImpl.java | 12 ++ .../service/impl/MyExamineServiceImpl.java | 126 +++++++++++------- .../examine/vo/MyExamPaperQuestionVO.java | 5 + .../mapper/ExamPaperQuestionMapper.xml | 8 +- .../main/resources/mapper/MyExamineMapper.xml | 2 + 10 files changed, 136 insertions(+), 48 deletions(-) diff --git a/inspur-service/inspur-examine/src/main/java/com/inspur/examine/domain/ExamPaperQuestion.java b/inspur-service/inspur-examine/src/main/java/com/inspur/examine/domain/ExamPaperQuestion.java index ac44309..14cf516 100644 --- a/inspur-service/inspur-examine/src/main/java/com/inspur/examine/domain/ExamPaperQuestion.java +++ b/inspur-service/inspur-examine/src/main/java/com/inspur/examine/domain/ExamPaperQuestion.java @@ -36,4 +36,9 @@ public class ExamPaperQuestion { @Excel(name = "考生答案") private String examineAnswer; + /** + * 排序 + */ + private Integer sorted; + } diff --git a/inspur-service/inspur-examine/src/main/java/com/inspur/examine/domain/ExamQuestionBank.java b/inspur-service/inspur-examine/src/main/java/com/inspur/examine/domain/ExamQuestionBank.java index 62dfaa4..d369c5e 100644 --- a/inspur-service/inspur-examine/src/main/java/com/inspur/examine/domain/ExamQuestionBank.java +++ b/inspur-service/inspur-examine/src/main/java/com/inspur/examine/domain/ExamQuestionBank.java @@ -68,4 +68,9 @@ public class ExamQuestionBank extends BaseEntity { */ @Excel(name = "状态", dictType = "sys_normal_disable") private String status; + + /** + * 排序 + */ + private Integer sorted; } diff --git a/inspur-service/inspur-examine/src/main/java/com/inspur/examine/dto/SubmitExamDTO.java b/inspur-service/inspur-examine/src/main/java/com/inspur/examine/dto/SubmitExamDTO.java index 4e2ff98..a7f3078 100644 --- a/inspur-service/inspur-examine/src/main/java/com/inspur/examine/dto/SubmitExamDTO.java +++ b/inspur-service/inspur-examine/src/main/java/com/inspur/examine/dto/SubmitExamDTO.java @@ -3,6 +3,7 @@ package com.inspur.examine.dto; import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; +import javax.validation.Valid; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; @@ -41,7 +42,7 @@ public class SubmitExamDTO { /** * 答案 */ - @NotEmpty + @Valid private List answerList; } diff --git a/inspur-service/inspur-examine/src/main/java/com/inspur/examine/mapper/ExamPaperQuestionMapper.java b/inspur-service/inspur-examine/src/main/java/com/inspur/examine/mapper/ExamPaperQuestionMapper.java index f5aef29..2a4d512 100644 --- a/inspur-service/inspur-examine/src/main/java/com/inspur/examine/mapper/ExamPaperQuestionMapper.java +++ b/inspur-service/inspur-examine/src/main/java/com/inspur/examine/mapper/ExamPaperQuestionMapper.java @@ -78,4 +78,13 @@ public interface ExamPaperQuestionMapper * @Date 11:33 2024/5/10 */ void batchUpdatePaperQuestion(@Param("answerList") List answerList); + + /** + * 根据考试id批量设置作答是否正确 + * + * @param paperId 考试id + * @Author xusd + * @Date 10:22 2024/5/11 + */ + void updateIsSureByPaperId(String paperId); } diff --git a/inspur-service/inspur-examine/src/main/java/com/inspur/examine/service/IExamPaperQuestionService.java b/inspur-service/inspur-examine/src/main/java/com/inspur/examine/service/IExamPaperQuestionService.java index f318c9b..7978445 100644 --- a/inspur-service/inspur-examine/src/main/java/com/inspur/examine/service/IExamPaperQuestionService.java +++ b/inspur-service/inspur-examine/src/main/java/com/inspur/examine/service/IExamPaperQuestionService.java @@ -77,4 +77,13 @@ public interface IExamPaperQuestionService * @Date 11:33 2024/5/10 */ void batchUpdatePaperQuestion(List answerList); + + /** + * 根据考试id批量设置作答是否正确 + * + * @param paperId 考试id + * @Author xusd + * @Date 10:22 2024/5/11 + */ + void updateIsSureByPaperId(String paperId); } diff --git a/inspur-service/inspur-examine/src/main/java/com/inspur/examine/service/impl/ExamPaperQuestionServiceImpl.java b/inspur-service/inspur-examine/src/main/java/com/inspur/examine/service/impl/ExamPaperQuestionServiceImpl.java index 753f46e..8de8ef3 100644 --- a/inspur-service/inspur-examine/src/main/java/com/inspur/examine/service/impl/ExamPaperQuestionServiceImpl.java +++ b/inspur-service/inspur-examine/src/main/java/com/inspur/examine/service/impl/ExamPaperQuestionServiceImpl.java @@ -116,4 +116,16 @@ public class ExamPaperQuestionServiceImpl implements IExamPaperQuestionService public void batchUpdatePaperQuestion(List answerList) { examPaperQuestionMapper.batchUpdatePaperQuestion(answerList); } + + /** + * 根据考试id批量设置作答是否正确 + * + * @param paperId 考试id + * @Author xusd + * @Date 10:22 2024/5/11 + */ + @Override + public void updateIsSureByPaperId(String paperId) { + examPaperQuestionMapper.updateIsSureByPaperId(paperId); + } } diff --git a/inspur-service/inspur-examine/src/main/java/com/inspur/examine/service/impl/MyExamineServiceImpl.java b/inspur-service/inspur-examine/src/main/java/com/inspur/examine/service/impl/MyExamineServiceImpl.java index 3a9c2f8..9f7db8d 100644 --- a/inspur-service/inspur-examine/src/main/java/com/inspur/examine/service/impl/MyExamineServiceImpl.java +++ b/inspur-service/inspur-examine/src/main/java/com/inspur/examine/service/impl/MyExamineServiceImpl.java @@ -144,6 +144,7 @@ public class MyExamineServiceImpl implements IMyExamineService { paperQuestion.setId(IdUtils.fastSimpleUUID()); paperQuestion.setPaperId(examPaperInfoId); paperQuestion.setQuestionId(item.getId()); + paperQuestion.setSorted(item.getSorted()); paperQuestionList.add(paperQuestion); }); //批量新增 @@ -164,15 +165,25 @@ public class MyExamineServiceImpl implements IMyExamineService { */ private List createRandoms(List source, int n) { Map map = new HashMap<>(); + int i = 0; List news = new ArrayList<>(); if (source.size() == n){ + if (StringUtils.isNotEmpty(source)){ + for (ExamQuestionBank item : source) { + i++; + item.setSorted(i); + } + } return source; }else { while (map.size() < n){ int random = (int) (Math.random() * source.size()); if (!map.containsKey(random)){ map.put(random,""); - news.add(source.get(random)); + i++; + ExamQuestionBank examQuestionBank = source.get(random); + examQuestionBank.setSorted(i); + news.add(examQuestionBank); } } return news; @@ -215,18 +226,45 @@ public class MyExamineServiceImpl implements IMyExamineService { } //考试题 List allPaperQuestionList = myExamineMapper.selectHistoryPaperQuestionNoAnswerListByPaperId(id); + assembleQuestionList(allPaperQuestionList, myExam); + return myExam; + } + + /** + * 组装考试题并排序 + * + * @Author xusd + * @Date 9:50 2024/5/11 + * @param allPaperQuestionList 考试题 + * @param myExam 考试信息 + */ + private static void assembleQuestionList(List allPaperQuestionList, MyExamVO myExam) { if (StringUtils.isEmpty(allPaperQuestionList)){ throw new ServiceException("未查询到考试题目"); } //试题类型 0 单选,1 多选,2 判断 Map> allPaperQuestionMap = allPaperQuestionList.stream().collect(Collectors.groupingBy(MyExamPaperQuestionVO::getQuestionType)); //单选 - myExam.setSingleChoiceList(allPaperQuestionMap.get("0")); + List singleChoiceList = allPaperQuestionMap.get("0"); + if (StringUtils.isNotEmpty(singleChoiceList)){ + //排序 + List collect = singleChoiceList.stream().sorted(Comparator.comparingInt(MyExamPaperQuestionVO::getSorted)).collect(Collectors.toList()); + myExam.setSingleChoiceList(collect); + } //多选 - myExam.setMultiChoiceList(allPaperQuestionMap.get("1")); + List multiChoiceList = allPaperQuestionMap.get("1"); + if (StringUtils.isNotEmpty(multiChoiceList)){ + //排序 + List collect = multiChoiceList.stream().sorted(Comparator.comparingInt(MyExamPaperQuestionVO::getSorted)).collect(Collectors.toList()); + myExam.setMultiChoiceList(collect); + } //判断 - myExam.setJudgeList(allPaperQuestionMap.get("2")); - return myExam; + List judgeList = allPaperQuestionMap.get("2"); + if (StringUtils.isNotEmpty(judgeList)){ + //排序 + List collect = judgeList.stream().sorted(Comparator.comparingInt(MyExamPaperQuestionVO::getSorted)).collect(Collectors.toList()); + myExam.setJudgeList(collect); + } } /** @@ -250,17 +288,7 @@ public class MyExamineServiceImpl implements IMyExamineService { } //考试题 List allPaperQuestionList = myExamineMapper.selectPaperQuestionNoAnswerListByPaperId(id); - if (StringUtils.isEmpty(allPaperQuestionList)){ - throw new ServiceException("未查询到考试题目"); - } - //试题类型 0 单选,1 多选,2 判断 - Map> allPaperQuestionMap = allPaperQuestionList.stream().collect(Collectors.groupingBy(MyExamPaperQuestionVO::getQuestionType)); - //单选 - myExam.setSingleChoiceList(allPaperQuestionMap.get("0")); - //多选 - myExam.setMultiChoiceList(allPaperQuestionMap.get("1")); - //判断 - myExam.setJudgeList(allPaperQuestionMap.get("2")); + assembleQuestionList(allPaperQuestionList,myExam); return myExam; } @@ -284,16 +312,11 @@ public class MyExamineServiceImpl implements IMyExamineService { if (Objects.isNull(examInfo)){ throw new ServiceException("未查询到考试信息"); } - //计算成绩 - //考生答案 - List userAnswerList = submitExamDTO.getAnswerList(); //正确答案 List correctAnswerList = myExamineMapper.selectPaperQuestionHaveAnswerListByPaperId(submitExamDTO.getPaperId()); if (StringUtils.isEmpty(correctAnswerList)){ throw new ServiceException("未查询到考试试题信息"); } - //判断答案是否正确,未作答也是回答错误 - Map correctAnswerMap = correctAnswerList.stream().collect(Collectors.toMap(CorrectAnswerDTO::getId, item->item)); //考试关联证书 String attestationId = examInfo.getAttestationId(); //通过分数 @@ -310,35 +333,48 @@ public class MyExamineServiceImpl implements IMyExamineService { int multipleChoice = 0; //判断题回答正确数量 int judge = 0; - for (SubmitExamPaperQuestionDTO item : userAnswerList) { - //是否正确 0:正确,1:错误 - //试题类型 0 单选,1 多选,2 判断 - CorrectAnswerDTO correctAnswerDTO = correctAnswerMap.get(item.getId()); - if (Objects.nonNull(correctAnswerDTO)){ - String correctAnswer = correctAnswerDTO.getQuestionAnswer(); - String questionType = correctAnswerDTO.getQuestionType(); - if (StringUtils.isEmpty(item.getExamineAnswer())){ - item.setIsSure("1"); - }else { - if (correctAnswer.replace("\\s","").equals(item.getExamineAnswer().replace("\\s",""))){ - item.setIsSure("0"); - if ("0".equals(questionType)){ - singleChoice++; - }else if ("1".equals(questionType)){ - multipleChoice++; - }else if ("2".equals(questionType)){ - judge++; - } - }else { + //考生分数 + BigDecimal score; + //计算成绩 + //考生答案 + List userAnswerList = submitExamDTO.getAnswerList(); + if (StringUtils.isNotEmpty(userAnswerList)){ + //判断答案是否正确,未作答也是回答错误 + Map correctAnswerMap = correctAnswerList.stream().collect(Collectors.toMap(CorrectAnswerDTO::getId, item->item)); + for (SubmitExamPaperQuestionDTO item : userAnswerList) { + //是否正确 0:正确,1:错误 + //试题类型 0 单选,1 多选,2 判断 + CorrectAnswerDTO correctAnswerDTO = correctAnswerMap.get(item.getId()); + if (Objects.nonNull(correctAnswerDTO)){ + String correctAnswer = correctAnswerDTO.getQuestionAnswer(); + String questionType = correctAnswerDTO.getQuestionType(); + if (StringUtils.isEmpty(item.getExamineAnswer())){ item.setIsSure("1"); + }else { + if (correctAnswer.replace("\\s","").equals(item.getExamineAnswer().replace("\\s",""))){ + item.setIsSure("0"); + if ("0".equals(questionType)){ + singleChoice++; + }else if ("1".equals(questionType)){ + multipleChoice++; + }else if ("2".equals(questionType)){ + judge++; + } + }else { + item.setIsSure("1"); + } } } } + //考生分数 + score = (singleChoiceScore.multiply(new BigDecimal(singleChoice))).add(multipleChoiceScore.multiply(new BigDecimal(multipleChoice))).add(judgeScore.multiply(new BigDecimal(judge))); + //批量设置答案和是否答对 + examPaperQuestionService.batchUpdatePaperQuestion(userAnswerList); + }else { + score = BigDecimal.ZERO; + //无任何作答时设置全部为回答错误 + examPaperQuestionService.updateIsSureByPaperId(submitExamDTO.getPaperId()); } - //考生分数 - BigDecimal score = (singleChoiceScore.multiply(new BigDecimal(singleChoice))).add(multipleChoiceScore.multiply(new BigDecimal(multipleChoice))).add(judgeScore.multiply(new BigDecimal(judge))); - //批量设置答案和是否答对 - examPaperQuestionService.batchUpdatePaperQuestion(userAnswerList); ExamPaperInfo examPaperInfo = new ExamPaperInfo(); examPaperInfo.setId(submitExamDTO.getPaperId()); examPaperInfo.setScore(score); diff --git a/inspur-service/inspur-examine/src/main/java/com/inspur/examine/vo/MyExamPaperQuestionVO.java b/inspur-service/inspur-examine/src/main/java/com/inspur/examine/vo/MyExamPaperQuestionVO.java index 4df9148..f3c7adb 100644 --- a/inspur-service/inspur-examine/src/main/java/com/inspur/examine/vo/MyExamPaperQuestionVO.java +++ b/inspur-service/inspur-examine/src/main/java/com/inspur/examine/vo/MyExamPaperQuestionVO.java @@ -52,4 +52,9 @@ public class MyExamPaperQuestionVO { */ private String isSure; + /** + * 排序 + */ + private Integer sorted; + } diff --git a/inspur-service/inspur-examine/src/main/resources/mapper/ExamPaperQuestionMapper.xml b/inspur-service/inspur-examine/src/main/resources/mapper/ExamPaperQuestionMapper.xml index 36dacf2..342a632 100644 --- a/inspur-service/inspur-examine/src/main/resources/mapper/ExamPaperQuestionMapper.xml +++ b/inspur-service/inspur-examine/src/main/resources/mapper/ExamPaperQuestionMapper.xml @@ -46,10 +46,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - insert into exam_paper_question(id,paper_id,question_id) + insert into exam_paper_question(id,paper_id,question_id,sorted) values - (#{item.id},#{item.paperId},#{item.questionId}) + (#{item.id},#{item.paperId},#{item.questionId},#{item.sorted}) @@ -84,6 +84,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + update exam_paper_question set is_sure = '1' where paper_id = #{paperId} + + delete from exam_paper_question where id = #{id} diff --git a/inspur-service/inspur-examine/src/main/resources/mapper/MyExamineMapper.xml b/inspur-service/inspur-examine/src/main/resources/mapper/MyExamineMapper.xml index 1056567..2e15aaf 100644 --- a/inspur-service/inspur-examine/src/main/resources/mapper/MyExamineMapper.xml +++ b/inspur-service/inspur-examine/src/main/resources/mapper/MyExamineMapper.xml @@ -187,6 +187,7 @@