From 3489df9245d6b643844312f970c4d8be33de1f33 Mon Sep 17 00:00:00 2001 From: tiger_zhou <123456> Date: Tue, 27 Sep 2022 14:20:29 +0800 Subject: [PATCH] =?UTF-8?q?=E7=90=86=E8=AE=BA=E8=AF=95=E9=A2=98=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E4=BB=A3=E7=A0=81=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/20220921-zhouyin.sql | 12 ++-- .../PagerQuestionBankController.java | 2 +- .../entity/paper/question/PaperQuestion.java | 5 +- .../services/papger/PagerQuestionService.java | 22 +++--- .../question/PaperQuestionOptionVO2.java | 2 + .../pager/question/PaperQuestionVO.java | 48 ++++++++++--- .../mybatis/mapper/PaperQuestionDAO.xml | 72 +++++++++++-------- 7 files changed, 109 insertions(+), 54 deletions(-) rename src/main/java/club/joylink/rtss/controller/{competition/question => paper}/PagerQuestionBankController.java (98%) diff --git a/sql/20220921-zhouyin.sql b/sql/20220921-zhouyin.sql index fd2f68441..d89a99d66 100644 --- a/sql/20220921-zhouyin.sql +++ b/sql/20220921-zhouyin.sql @@ -1,14 +1,16 @@ -- 新题库 -DROP TABLE IF EXISTS `race_question2`; -CREATE TABLE `race_question2` ( +DROP TABLE IF EXISTS `paper_question`; +CREATE TABLE `paper_question` ( `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'id', `type` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '类型 选择题=select,判断题=judge,多选题=multi', - `topic` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT '问题内容', + `question` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT '问题内容', `create_user_id` bigint DEFAULT NULL COMMENT '创建者id', `create_time` datetime DEFAULT NULL COMMENT '创建时间', `project_code` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '项目code', `company_id` bigint DEFAULT NULL COMMENT '公司组织id', `race_lable` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '标签', - `questions` longtext, + `question_option` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT '问题选项', + `question_answer` varchar(255) DEFAULT NULL COMMENT '答案,号隔开', + `is_del` int DEFAULT '0' COMMENT '是否删除0=否,1=是', PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; diff --git a/src/main/java/club/joylink/rtss/controller/competition/question/PagerQuestionBankController.java b/src/main/java/club/joylink/rtss/controller/paper/PagerQuestionBankController.java similarity index 98% rename from src/main/java/club/joylink/rtss/controller/competition/question/PagerQuestionBankController.java rename to src/main/java/club/joylink/rtss/controller/paper/PagerQuestionBankController.java index b43038772..7883d4a8c 100644 --- a/src/main/java/club/joylink/rtss/controller/competition/question/PagerQuestionBankController.java +++ b/src/main/java/club/joylink/rtss/controller/paper/PagerQuestionBankController.java @@ -1,4 +1,4 @@ -package club.joylink.rtss.controller.competition.question; +package club.joylink.rtss.controller.paper; import club.joylink.rtss.services.papger.PagerQuestionService; diff --git a/src/main/java/club/joylink/rtss/entity/paper/question/PaperQuestion.java b/src/main/java/club/joylink/rtss/entity/paper/question/PaperQuestion.java index afab42b78..e81014141 100644 --- a/src/main/java/club/joylink/rtss/entity/paper/question/PaperQuestion.java +++ b/src/main/java/club/joylink/rtss/entity/paper/question/PaperQuestion.java @@ -50,8 +50,9 @@ public class PaperQuestion implements Serializable { * 是否删除0=否,1=是 */ private Integer isDel; - private String topic; + private String question; - private String questions; + private String questionOption; + private String questionAnswer; private static final long serialVersionUID = 1L; } diff --git a/src/main/java/club/joylink/rtss/services/papger/PagerQuestionService.java b/src/main/java/club/joylink/rtss/services/papger/PagerQuestionService.java index b19d7480f..e2aa8b881 100644 --- a/src/main/java/club/joylink/rtss/services/papger/PagerQuestionService.java +++ b/src/main/java/club/joylink/rtss/services/papger/PagerQuestionService.java @@ -116,22 +116,28 @@ public class PagerQuestionService { BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(!CollectionUtils.isEmpty(answerIds),"题目答案不能为空"); PaperQuestionVO vo = this.getQuestion(questionId,true); List newAnswerList = answerIds.stream().filter(Objects::nonNull)/*.map(String::trim)*/.distinct().collect(Collectors.toList()); - List optionList = vo.getOptionList().stream().filter(PaperQuestionOptionVO2::getCorrect).map(d->d.getId()).collect(Collectors.toList()); +// List optionList = vo.getOptionList().stream().filter(PaperQuestionOptionVO2::getCorrect).map(d->d.getId()).collect(Collectors.toList()); if(Objects.equals(BusinessConsts.TheoryType.select.name(),vo.getType()) || Objects.equals(BusinessConsts.TheoryType.judge.name(),vo.getType())){ BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(newAnswerList.size() == 1 ,"单选,判断题答案只能有一个!"); }else if(Objects.equals(BusinessConsts.TheoryType.multi.name(),vo.getType())){ BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(newAnswerList.size() > 2 ,"多选题答案最少需要2个"); - BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(newAnswerList.size() < optionList.size(),"多选题答案与标准答案数量不匹配"); +// BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(newAnswerList.size() < optionList.size(),"多选题答案与标准答案数量不匹配"); } - List sourceOptionList = Lists.newArrayList(); - sourceOptionList.addAll(optionList); - optionList.removeAll(newAnswerList); - if(CollectionUtils.isEmpty(optionList)){ +// List sourceOptionList = Lists.newArrayList(); +// sourceOptionList.addAll(optionList); +// optionList.removeAll(newAnswerList); +// if(CollectionUtils.isEmpty(optionList)){ +// return true; +// } + Collections.sort(answerIds); + String answerStr = Joiner.on(",").join(answerIds); + if(Objects.equals(answerStr,vo.getQuestionAnswer())){ return true; } - log.info("检查题目[{}]答案,获取原答案[{}],正确答案[{}] 有[{}]没有答对",questionId, Joiner.on(",").join(answerIds),Joiner.on(",").join(sourceOptionList),Joiner.on(",").join(optionList)); + log.info("检查题目[{}]答案,获取原答案[{}],正确答案[{}] ",questionId, answerStr,vo.getQuestionAnswer()); +// log.info("检查题目[{}]答案,获取原答案[{}],正确答案[{}] 有[{}]没有答对",questionId, Joiner.on(",").join(answerIds),Joiner.on(",").join(sourceOptionList),Joiner.on(",").join(optionList)); return false; } @@ -230,7 +236,7 @@ public class PagerQuestionService { public void importProjectQuestion(List questions, String projectCode, Long companyId, AccountVO accountVO) { questions.forEach(questionVO -> { - String topic = questionVO.getTopic(); + String topic = questionVO.getQuestion(); this.checkQuestionType(questionVO,String.format("题库目前只支持单选,多选和判断,题序[%s]",questionVO.getId())); if (questionVO.isSelect() || questionVO.isJudge()) { this.checkQuestionTypeForSelectAndJudge(questionVO,String.format("题序[%s]:单选或判断题[%s]正确答案应当有且只有一个!", questionVO.getId(),topic)); diff --git a/src/main/java/club/joylink/rtss/vo/client/pager/question/PaperQuestionOptionVO2.java b/src/main/java/club/joylink/rtss/vo/client/pager/question/PaperQuestionOptionVO2.java index 1eb69efba..671cf2ae6 100644 --- a/src/main/java/club/joylink/rtss/vo/client/pager/question/PaperQuestionOptionVO2.java +++ b/src/main/java/club/joylink/rtss/vo/client/pager/question/PaperQuestionOptionVO2.java @@ -1,6 +1,7 @@ package club.joylink.rtss.vo.client.pager.question; import club.joylink.rtss.entity.RaceQuestionOption; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -30,6 +31,7 @@ public class PaperQuestionOptionVO2 implements Cloneable { * 正确的 */ @NotNull(message = "题目没有设置正确选项") +// @JsonIgnore private Boolean correct; public PaperQuestionOptionVO2(RaceQuestionOption questionOption) { diff --git a/src/main/java/club/joylink/rtss/vo/client/pager/question/PaperQuestionVO.java b/src/main/java/club/joylink/rtss/vo/client/pager/question/PaperQuestionVO.java index c6cd782a5..d6554aad7 100644 --- a/src/main/java/club/joylink/rtss/vo/client/pager/question/PaperQuestionVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/pager/question/PaperQuestionVO.java @@ -5,14 +5,18 @@ import club.joylink.rtss.constants.Project; import club.joylink.rtss.entity.paper.question.PaperQuestion; import club.joylink.rtss.util.JsonUtils; import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.JavaType; +import com.google.common.base.Joiner; +import com.google.common.base.Splitter; +import com.google.common.collect.Lists; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.springframework.util.CollectionUtils; import javax.validation.constraints.NotBlank; -import java.util.ArrayList; -import java.util.List; +import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; @@ -24,7 +28,6 @@ import java.util.stream.Collectors; @NoArgsConstructor public class PaperQuestionVO implements Cloneable { - private Long id; /** @@ -37,7 +40,7 @@ public class PaperQuestionVO implements Cloneable { *题目 */ @NotBlank(message = "题目不能为空") - private String topic; + private String question; /** *选项列表 @@ -51,6 +54,9 @@ public class PaperQuestionVO implements Cloneable { private String projectCode; private Long companyId; private String raceLable; + private String questionAnswer; + private String answer; + /** *分值 */ @@ -60,31 +66,53 @@ public class PaperQuestionVO implements Cloneable { public PaperQuestionVO(PaperQuestion question) { this.id = question.getId(); this.type = question.getType(); - this.topic = question.getTopic(); + this.question = question.getQuestion(); this.projectCode = question.getProjectCode(); this.companyId = question.getCompanyId(); this.raceLable = question.getRaceLable(); - this.optionList = JsonUtils.readCollection(question.getQuestions(),ArrayList.class, PaperQuestionOptionVO2.class); + this.optionList = JsonUtils.readCollection(question.getQuestionOption(),ArrayList.class, PaperQuestionOptionVO2.class); + String dd = Objects.isNull(question.getQuestionAnswer()) ? "" : question.getQuestionAnswer(); + this.answer = dd; + List answerList = Splitter.on(",").splitToList(dd); + for (PaperQuestionOptionVO2 vo : this.optionList) { + vo.setCorrect(false); + if(answerList.contains(vo.getId() + "")){ + vo.setCorrect(true); + } + } } public PaperQuestion convert2DB() { PaperQuestion question = new PaperQuestion(); question.setId(this.id); question.setType(type); - question.setTopic(topic); + question.setQuestion(this.question); question.setProjectCode(Project.isDefault(Project.valueOf(projectCode)) ? null : projectCode); question.setCompanyId(companyId); - this.setOptionId(); - question.setQuestions(JsonUtils.writeValueAsString(this.optionList)); + this.setOptionId(question); + + String dd = JsonUtils.writeValueAsString(this.optionList); + + List listMap = JsonUtils.readCollection(dd,List.class,Map.class); + listMap.forEach(d->d.remove("correct")); + + question.setQuestionOption(JsonUtils.writeValueAsString(listMap)); question.setRaceLable(this.raceLable); question.setIsDel(BusinessConsts.DBLogicDelete.NORMAL.ordinal()); +// question.setQuestionAnswer(this.answer); return question; } - private void setOptionId(){ + private void setOptionId(PaperQuestion pq){ int i = 0; + List answerList = Lists.newArrayList(); for (PaperQuestionOptionVO2 vo : this.optionList) { vo.setId(i++); + if(vo.getCorrect()){ + answerList.add(vo.getId() + ""); + } } + + pq.setQuestionAnswer(Joiner.on(",").join(answerList)); } diff --git a/src/main/resources/mybatis/mapper/PaperQuestionDAO.xml b/src/main/resources/mybatis/mapper/PaperQuestionDAO.xml index 522007b5a..1d44ca1f7 100644 --- a/src/main/resources/mybatis/mapper/PaperQuestionDAO.xml +++ b/src/main/resources/mybatis/mapper/PaperQuestionDAO.xml @@ -10,8 +10,9 @@ - - + + +