理论试题管理代码调整

This commit is contained in:
tiger_zhou 2022-09-27 14:20:29 +08:00
parent d8079d98f2
commit 3489df9245
7 changed files with 109 additions and 54 deletions

View File

@ -1,14 +1,16 @@
-- 新题库 -- 新题库
DROP TABLE IF EXISTS `race_question2`; DROP TABLE IF EXISTS `paper_question`;
CREATE TABLE `race_question2` ( CREATE TABLE `paper_question` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT 'id', `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', `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_user_id` bigint DEFAULT NULL COMMENT '创建者id',
`create_time` datetime DEFAULT NULL COMMENT '创建时间', `create_time` datetime DEFAULT NULL COMMENT '创建时间',
`project_code` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '项目code', `project_code` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '项目code',
`company_id` bigint DEFAULT NULL COMMENT '公司组织id', `company_id` bigint DEFAULT NULL COMMENT '公司组织id',
`race_lable` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '标签', `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`) 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;

View File

@ -1,4 +1,4 @@
package club.joylink.rtss.controller.competition.question; package club.joylink.rtss.controller.paper;
import club.joylink.rtss.services.papger.PagerQuestionService; import club.joylink.rtss.services.papger.PagerQuestionService;

View File

@ -50,8 +50,9 @@ public class PaperQuestion implements Serializable {
* 是否删除0=1= * 是否删除0=1=
*/ */
private Integer isDel; private Integer isDel;
private String topic; private String question;
private String questions; private String questionOption;
private String questionAnswer;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
} }

View File

@ -116,22 +116,28 @@ public class PagerQuestionService {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(!CollectionUtils.isEmpty(answerIds),"题目答案不能为空"); BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(!CollectionUtils.isEmpty(answerIds),"题目答案不能为空");
PaperQuestionVO vo = this.getQuestion(questionId,true); PaperQuestionVO vo = this.getQuestion(questionId,true);
List<Integer> newAnswerList = answerIds.stream().filter(Objects::nonNull)/*.map(String::trim)*/.distinct().collect(Collectors.toList()); List<Integer> newAnswerList = answerIds.stream().filter(Objects::nonNull)/*.map(String::trim)*/.distinct().collect(Collectors.toList());
List<Integer> optionList = vo.getOptionList().stream().filter(PaperQuestionOptionVO2::getCorrect).map(d->d.getId()).collect(Collectors.toList()); // List<Integer> optionList = vo.getOptionList().stream().filter(PaperQuestionOptionVO2::getCorrect).map(d->d.getId()).collect(Collectors.toList());
if(Objects.equals(BusinessConsts.TheoryType.select.name(),vo.getType()) if(Objects.equals(BusinessConsts.TheoryType.select.name(),vo.getType())
|| Objects.equals(BusinessConsts.TheoryType.judge.name(),vo.getType())){ || Objects.equals(BusinessConsts.TheoryType.judge.name(),vo.getType())){
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(newAnswerList.size() == 1 ,"单选,判断题答案只能有一个!"); BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(newAnswerList.size() == 1 ,"单选,判断题答案只能有一个!");
}else if(Objects.equals(BusinessConsts.TheoryType.multi.name(),vo.getType())){ }else if(Objects.equals(BusinessConsts.TheoryType.multi.name(),vo.getType())){
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(newAnswerList.size() > 2 ,"多选题答案最少需要2个"); 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<Integer> sourceOptionList = Lists.newArrayList(); // List<Integer> sourceOptionList = Lists.newArrayList();
sourceOptionList.addAll(optionList); // sourceOptionList.addAll(optionList);
optionList.removeAll(newAnswerList); // optionList.removeAll(newAnswerList);
if(CollectionUtils.isEmpty(optionList)){ // if(CollectionUtils.isEmpty(optionList)){
// return true;
// }
Collections.sort(answerIds);
String answerStr = Joiner.on(",").join(answerIds);
if(Objects.equals(answerStr,vo.getQuestionAnswer())){
return true; 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; return false;
} }
@ -230,7 +236,7 @@ public class PagerQuestionService {
public void importProjectQuestion(List<PaperQuestionVO> questions, String projectCode, Long companyId, AccountVO accountVO) { public void importProjectQuestion(List<PaperQuestionVO> questions, String projectCode, Long companyId, AccountVO accountVO) {
questions.forEach(questionVO -> { questions.forEach(questionVO -> {
String topic = questionVO.getTopic(); String topic = questionVO.getQuestion();
this.checkQuestionType(questionVO,String.format("题库目前只支持单选,多选和判断,题序[%s]",questionVO.getId())); this.checkQuestionType(questionVO,String.format("题库目前只支持单选,多选和判断,题序[%s]",questionVO.getId()));
if (questionVO.isSelect() || questionVO.isJudge()) { if (questionVO.isSelect() || questionVO.isJudge()) {
this.checkQuestionTypeForSelectAndJudge(questionVO,String.format("题序[%s]:单选或判断题[%s]正确答案应当有且只有一个!", questionVO.getId(),topic)); this.checkQuestionTypeForSelectAndJudge(questionVO,String.format("题序[%s]:单选或判断题[%s]正确答案应当有且只有一个!", questionVO.getId(),topic));

View File

@ -1,6 +1,7 @@
package club.joylink.rtss.vo.client.pager.question; package club.joylink.rtss.vo.client.pager.question;
import club.joylink.rtss.entity.RaceQuestionOption; import club.joylink.rtss.entity.RaceQuestionOption;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
@ -30,6 +31,7 @@ public class PaperQuestionOptionVO2 implements Cloneable {
* 正确的 * 正确的
*/ */
@NotNull(message = "题目没有设置正确选项") @NotNull(message = "题目没有设置正确选项")
// @JsonIgnore
private Boolean correct; private Boolean correct;
public PaperQuestionOptionVO2(RaceQuestionOption questionOption) { public PaperQuestionOptionVO2(RaceQuestionOption questionOption) {

View File

@ -5,14 +5,18 @@ import club.joylink.rtss.constants.Project;
import club.joylink.rtss.entity.paper.question.PaperQuestion; import club.joylink.rtss.entity.paper.question.PaperQuestion;
import club.joylink.rtss.util.JsonUtils; import club.joylink.rtss.util.JsonUtils;
import com.fasterxml.jackson.annotation.JsonIgnore; 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.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -24,7 +28,6 @@ import java.util.stream.Collectors;
@NoArgsConstructor @NoArgsConstructor
public class PaperQuestionVO implements Cloneable { public class PaperQuestionVO implements Cloneable {
private Long id; private Long id;
/** /**
@ -37,7 +40,7 @@ public class PaperQuestionVO implements Cloneable {
*题目 *题目
*/ */
@NotBlank(message = "题目不能为空") @NotBlank(message = "题目不能为空")
private String topic; private String question;
/** /**
*选项列表 *选项列表
@ -51,6 +54,9 @@ public class PaperQuestionVO implements Cloneable {
private String projectCode; private String projectCode;
private Long companyId; private Long companyId;
private String raceLable; private String raceLable;
private String questionAnswer;
private String answer;
/** /**
*分值 *分值
*/ */
@ -60,33 +66,55 @@ public class PaperQuestionVO implements Cloneable {
public PaperQuestionVO(PaperQuestion question) { public PaperQuestionVO(PaperQuestion question) {
this.id = question.getId(); this.id = question.getId();
this.type = question.getType(); this.type = question.getType();
this.topic = question.getTopic(); this.question = question.getQuestion();
this.projectCode = question.getProjectCode(); this.projectCode = question.getProjectCode();
this.companyId = question.getCompanyId(); this.companyId = question.getCompanyId();
this.raceLable = question.getRaceLable(); 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<String> answerList = Splitter.on(",").splitToList(dd);
for (PaperQuestionOptionVO2 vo : this.optionList) {
vo.setCorrect(false);
if(answerList.contains(vo.getId() + "")){
vo.setCorrect(true);
}
}
} }
public PaperQuestion convert2DB() { public PaperQuestion convert2DB() {
PaperQuestion question = new PaperQuestion(); PaperQuestion question = new PaperQuestion();
question.setId(this.id); question.setId(this.id);
question.setType(type); question.setType(type);
question.setTopic(topic); question.setQuestion(this.question);
question.setProjectCode(Project.isDefault(Project.valueOf(projectCode)) ? null : projectCode); question.setProjectCode(Project.isDefault(Project.valueOf(projectCode)) ? null : projectCode);
question.setCompanyId(companyId); question.setCompanyId(companyId);
this.setOptionId(); this.setOptionId(question);
question.setQuestions(JsonUtils.writeValueAsString(this.optionList));
String dd = JsonUtils.writeValueAsString(this.optionList);
List<Map> listMap = JsonUtils.readCollection(dd,List.class,Map.class);
listMap.forEach(d->d.remove("correct"));
question.setQuestionOption(JsonUtils.writeValueAsString(listMap));
question.setRaceLable(this.raceLable); question.setRaceLable(this.raceLable);
question.setIsDel(BusinessConsts.DBLogicDelete.NORMAL.ordinal()); question.setIsDel(BusinessConsts.DBLogicDelete.NORMAL.ordinal());
// question.setQuestionAnswer(this.answer);
return question; return question;
} }
private void setOptionId(){ private void setOptionId(PaperQuestion pq){
int i = 0; int i = 0;
List<String> answerList = Lists.newArrayList();
for (PaperQuestionOptionVO2 vo : this.optionList) { for (PaperQuestionOptionVO2 vo : this.optionList) {
vo.setId(i++); vo.setId(i++);
if(vo.getCorrect()){
answerList.add(vo.getId() + "");
} }
} }
pq.setQuestionAnswer(Joiner.on(",").join(answerList));
}
public static List<PaperQuestionVO> convert2VOList(List<PaperQuestion> questions){ public static List<PaperQuestionVO> convert2VOList(List<PaperQuestion> questions){
List<PaperQuestionVO> voList = new ArrayList<>(); List<PaperQuestionVO> voList = new ArrayList<>();

View File

@ -10,8 +10,9 @@
<result column="company_id" jdbcType="BIGINT" property="companyId" /> <result column="company_id" jdbcType="BIGINT" property="companyId" />
<result column="race_lable" jdbcType="VARCHAR" property="raceLable" /> <result column="race_lable" jdbcType="VARCHAR" property="raceLable" />
<result column="is_del" jdbcType="INTEGER" property="isDel" /> <result column="is_del" jdbcType="INTEGER" property="isDel" />
<result column="topic" jdbcType="LONGVARCHAR" property="topic" /> <result column="question" jdbcType="LONGVARCHAR" property="question" />
<result column="questions" jdbcType="LONGVARCHAR" property="questions" /> <result column="question_option" jdbcType="LONGVARCHAR" property="questionOption" />
<result column="question_answer" jdbcType="VARCHAR" property="questionAnswer" />
</resultMap> </resultMap>
<!-- <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="club.joylink.rtss.entity.race2.PaperQuestionWithBLOBs"> <!-- <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="club.joylink.rtss.entity.race2.PaperQuestionWithBLOBs">
<result column="topic" jdbcType="LONGVARCHAR" property="topic" /> <result column="topic" jdbcType="LONGVARCHAR" property="topic" />
@ -76,10 +77,10 @@
</where> </where>
</sql> </sql>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, `type`, create_user_id, create_time, project_code, company_id, race_lable, is_del id, `type`, create_user_id, create_time, project_code, company_id, race_lable, is_del,question_answer
</sql> </sql>
<sql id="Blob_Column_List"> <sql id="Blob_Column_List">
topic, questions question, question_option
</sql> </sql>
<!--<select id="selectByExampleWithBLOBs" parameterType="club.joylink.rtss.entity.race2.PaperQuestionExample" resultMap="ResultMapWithBLOBs"> <!--<select id="selectByExampleWithBLOBs" parameterType="club.joylink.rtss.entity.race2.PaperQuestionExample" resultMap="ResultMapWithBLOBs">
select select
@ -150,12 +151,13 @@
<insert id="insert" parameterType="club.joylink.rtss.entity.paper.question.PaperQuestionWithBLOBs"> <insert id="insert" parameterType="club.joylink.rtss.entity.paper.question.PaperQuestionWithBLOBs">
insert into paper_question (id, `type`, create_user_id, insert into paper_question (id, `type`, create_user_id,
create_time, project_code, company_id, create_time, project_code, company_id,
race_lable, is_del, topic, race_lable, is_del, question,
questions) question_option,question_answer)
values (#{id,jdbcType=BIGINT}, #{type,jdbcType=VARCHAR}, #{createUserId,jdbcType=BIGINT}, values (#{id,jdbcType=BIGINT}, #{type,jdbcType=VARCHAR}, #{createUserId,jdbcType=BIGINT},
#{createTime,jdbcType=TIMESTAMP}, #{projectCode,jdbcType=VARCHAR}, #{companyId,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP}, #{projectCode,jdbcType=VARCHAR}, #{companyId,jdbcType=BIGINT},
#{raceLable,jdbcType=VARCHAR}, #{isDel,jdbcType=INTEGER}, #{topic,jdbcType=LONGVARCHAR}, #{raceLable,jdbcType=VARCHAR}, #{isDel,jdbcType=INTEGER}, #{question,jdbcType=LONGVARCHAR},
#{questions,jdbcType=LONGVARCHAR}) #{questionOption,jdbcType=LONGVARCHAR},#{questionAnswer,jdbcType=VARCHAR})
</insert> </insert>
<insert id="insertSelective" parameterType="club.joylink.rtss.entity.paper.question.PaperQuestionWithBLOBs"> <insert id="insertSelective" parameterType="club.joylink.rtss.entity.paper.question.PaperQuestionWithBLOBs">
insert into paper_question insert into paper_question
@ -184,11 +186,14 @@
<if test="isDel != null"> <if test="isDel != null">
is_del, is_del,
</if> </if>
<if test="topic != null"> <if test="question != null">
topic, question,
</if> </if>
<if test="questions != null"> <if test="questionOption != null">
questions, question_option,
</if>
<if test="questionAnswer != null">
question_answer,
</if> </if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
@ -216,11 +221,14 @@
<if test="isDel != null"> <if test="isDel != null">
#{isDel,jdbcType=INTEGER}, #{isDel,jdbcType=INTEGER},
</if> </if>
<if test="topic != null"> <if test="question != null">
#{topic,jdbcType=LONGVARCHAR}, #{question,jdbcType=LONGVARCHAR},
</if> </if>
<if test="questions != null"> <if test="questionOption != null">
#{questions,jdbcType=LONGVARCHAR}, #{questionOption,jdbcType=LONGVARCHAR},
</if>
<if test="questionAnswer != null">
#{questionAnswer,jdbcType=VARCHAR},
</if> </if>
</trim> </trim>
</insert> </insert>
@ -257,11 +265,14 @@
<if test="record.isDel != null"> <if test="record.isDel != null">
is_del = #{record.isDel,jdbcType=INTEGER}, is_del = #{record.isDel,jdbcType=INTEGER},
</if> </if>
<if test="record.topic != null"> <if test="record.question != null">
topic = #{record.topic,jdbcType=LONGVARCHAR}, question = #{record.question,jdbcType=LONGVARCHAR},
</if> </if>
<if test="record.questions != null"> <if test="record.questionOption != null">
questions = #{record.questions,jdbcType=LONGVARCHAR}, question_option = #{record.questionOption,jdbcType=LONGVARCHAR},
</if>
<if test="record.questionAnswer != null">
question_answer = #{record.questionAnswer,jdbcType=VARCHAR},
</if> </if>
</set> </set>
<if test="_parameter != null"> <if test="_parameter != null">
@ -294,8 +305,9 @@
company_id = #{record.companyId,jdbcType=BIGINT}, company_id = #{record.companyId,jdbcType=BIGINT},
race_lable = #{record.raceLable,jdbcType=VARCHAR}, race_lable = #{record.raceLable,jdbcType=VARCHAR},
is_del = #{record.isDel,jdbcType=INTEGER}, is_del = #{record.isDel,jdbcType=INTEGER},
topic = #{record.topic,jdbcType=LONGVARCHAR}, question = #{record.question,jdbcType=LONGVARCHAR},
questions = #{record.questions,jdbcType=LONGVARCHAR} question_option = #{record.questionOption,jdbcType=LONGVARCHAR},
question_answer = #{record.questionAnswer,jdbcType=VARCHAR}
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause" />
@ -325,11 +337,14 @@
<if test="isDel != null"> <if test="isDel != null">
is_del = #{isDel,jdbcType=INTEGER}, is_del = #{isDel,jdbcType=INTEGER},
</if> </if>
<if test="topic != null"> <if test="question != null">
topic = #{topic,jdbcType=LONGVARCHAR}, question = #{question,jdbcType=LONGVARCHAR},
</if> </if>
<if test="questions != null"> <if test="questionOption != null">
questions = #{questions,jdbcType=LONGVARCHAR}, question_option = #{questionOption,jdbcType=LONGVARCHAR},
</if>
<if test="questionAnswer != null">
question_answer = #{questionAnswer,jdbcType=VARCHAR},
</if> </if>
</set> </set>
where id = #{id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}
@ -356,8 +371,9 @@
company_id = #{companyId,jdbcType=BIGINT}, company_id = #{companyId,jdbcType=BIGINT},
race_lable = #{raceLable,jdbcType=VARCHAR}, race_lable = #{raceLable,jdbcType=VARCHAR},
is_del = #{isDel,jdbcType=INTEGER}, is_del = #{isDel,jdbcType=INTEGER},
topic = #{topic,jdbcType=LONGVARCHAR}, question = #{question,jdbcType=LONGVARCHAR},
questions = #{questions,jdbcType=LONGVARCHAR} question_option = #{questionOption,jdbcType=LONGVARCHAR},
question_answer = #{questionAnswer,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}
</update> </update>
</mapper> </mapper>