理论试题管理代码调整
This commit is contained in:
parent
d8079d98f2
commit
3489df9245
@ -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;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package club.joylink.rtss.controller.competition.question;
|
||||
package club.joylink.rtss.controller.paper;
|
||||
|
||||
|
||||
import club.joylink.rtss.services.papger.PagerQuestionService;
|
@ -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;
|
||||
}
|
||||
|
@ -116,22 +116,28 @@ public class PagerQuestionService {
|
||||
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(!CollectionUtils.isEmpty(answerIds),"题目答案不能为空");
|
||||
PaperQuestionVO vo = this.getQuestion(questionId,true);
|
||||
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())
|
||||
|| 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<Integer> sourceOptionList = Lists.newArrayList();
|
||||
sourceOptionList.addAll(optionList);
|
||||
optionList.removeAll(newAnswerList);
|
||||
if(CollectionUtils.isEmpty(optionList)){
|
||||
// List<Integer> 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<PaperQuestionVO> 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));
|
||||
|
@ -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) {
|
||||
|
@ -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,33 +66,55 @@ 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<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() {
|
||||
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<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.setIsDel(BusinessConsts.DBLogicDelete.NORMAL.ordinal());
|
||||
// question.setQuestionAnswer(this.answer);
|
||||
return question;
|
||||
}
|
||||
private void setOptionId(){
|
||||
private void setOptionId(PaperQuestion pq){
|
||||
int i = 0;
|
||||
List<String> answerList = Lists.newArrayList();
|
||||
for (PaperQuestionOptionVO2 vo : this.optionList) {
|
||||
vo.setId(i++);
|
||||
if(vo.getCorrect()){
|
||||
answerList.add(vo.getId() + "");
|
||||
}
|
||||
}
|
||||
|
||||
pq.setQuestionAnswer(Joiner.on(",").join(answerList));
|
||||
}
|
||||
|
||||
|
||||
public static List<PaperQuestionVO> convert2VOList(List<PaperQuestion> questions){
|
||||
List<PaperQuestionVO> voList = new ArrayList<>();
|
||||
|
@ -10,8 +10,9 @@
|
||||
<result column="company_id" jdbcType="BIGINT" property="companyId" />
|
||||
<result column="race_lable" jdbcType="VARCHAR" property="raceLable" />
|
||||
<result column="is_del" jdbcType="INTEGER" property="isDel" />
|
||||
<result column="topic" jdbcType="LONGVARCHAR" property="topic" />
|
||||
<result column="questions" jdbcType="LONGVARCHAR" property="questions" />
|
||||
<result column="question" jdbcType="LONGVARCHAR" property="question" />
|
||||
<result column="question_option" jdbcType="LONGVARCHAR" property="questionOption" />
|
||||
<result column="question_answer" jdbcType="VARCHAR" property="questionAnswer" />
|
||||
</resultMap>
|
||||
<!-- <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="club.joylink.rtss.entity.race2.PaperQuestionWithBLOBs">
|
||||
<result column="topic" jdbcType="LONGVARCHAR" property="topic" />
|
||||
@ -76,10 +77,10 @@
|
||||
</where>
|
||||
</sql>
|
||||
<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 id="Blob_Column_List">
|
||||
topic, questions
|
||||
question, question_option
|
||||
</sql>
|
||||
<!--<select id="selectByExampleWithBLOBs" parameterType="club.joylink.rtss.entity.race2.PaperQuestionExample" resultMap="ResultMapWithBLOBs">
|
||||
select
|
||||
@ -150,12 +151,13 @@
|
||||
<insert id="insert" parameterType="club.joylink.rtss.entity.paper.question.PaperQuestionWithBLOBs">
|
||||
insert into paper_question (id, `type`, create_user_id,
|
||||
create_time, project_code, company_id,
|
||||
race_lable, is_del, topic,
|
||||
questions)
|
||||
race_lable, is_del, question,
|
||||
question_option,question_answer)
|
||||
|
||||
values (#{id,jdbcType=BIGINT}, #{type,jdbcType=VARCHAR}, #{createUserId,jdbcType=BIGINT},
|
||||
#{createTime,jdbcType=TIMESTAMP}, #{projectCode,jdbcType=VARCHAR}, #{companyId,jdbcType=BIGINT},
|
||||
#{raceLable,jdbcType=VARCHAR}, #{isDel,jdbcType=INTEGER}, #{topic,jdbcType=LONGVARCHAR},
|
||||
#{questions,jdbcType=LONGVARCHAR})
|
||||
#{raceLable,jdbcType=VARCHAR}, #{isDel,jdbcType=INTEGER}, #{question,jdbcType=LONGVARCHAR},
|
||||
#{questionOption,jdbcType=LONGVARCHAR},#{questionAnswer,jdbcType=VARCHAR})
|
||||
</insert>
|
||||
<insert id="insertSelective" parameterType="club.joylink.rtss.entity.paper.question.PaperQuestionWithBLOBs">
|
||||
insert into paper_question
|
||||
@ -184,11 +186,14 @@
|
||||
<if test="isDel != null">
|
||||
is_del,
|
||||
</if>
|
||||
<if test="topic != null">
|
||||
topic,
|
||||
<if test="question != null">
|
||||
question,
|
||||
</if>
|
||||
<if test="questions != null">
|
||||
questions,
|
||||
<if test="questionOption != null">
|
||||
question_option,
|
||||
</if>
|
||||
<if test="questionAnswer != null">
|
||||
question_answer,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
@ -216,11 +221,14 @@
|
||||
<if test="isDel != null">
|
||||
#{isDel,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="topic != null">
|
||||
#{topic,jdbcType=LONGVARCHAR},
|
||||
<if test="question != null">
|
||||
#{question,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
<if test="questions != null">
|
||||
#{questions,jdbcType=LONGVARCHAR},
|
||||
<if test="questionOption != null">
|
||||
#{questionOption,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
<if test="questionAnswer != null">
|
||||
#{questionAnswer,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
@ -257,11 +265,14 @@
|
||||
<if test="record.isDel != null">
|
||||
is_del = #{record.isDel,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="record.topic != null">
|
||||
topic = #{record.topic,jdbcType=LONGVARCHAR},
|
||||
<if test="record.question != null">
|
||||
question = #{record.question,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
<if test="record.questions != null">
|
||||
questions = #{record.questions,jdbcType=LONGVARCHAR},
|
||||
<if test="record.questionOption != null">
|
||||
question_option = #{record.questionOption,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
<if test="record.questionAnswer != null">
|
||||
question_answer = #{record.questionAnswer,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</set>
|
||||
<if test="_parameter != null">
|
||||
@ -294,8 +305,9 @@
|
||||
company_id = #{record.companyId,jdbcType=BIGINT},
|
||||
race_lable = #{record.raceLable,jdbcType=VARCHAR},
|
||||
is_del = #{record.isDel,jdbcType=INTEGER},
|
||||
topic = #{record.topic,jdbcType=LONGVARCHAR},
|
||||
questions = #{record.questions,jdbcType=LONGVARCHAR}
|
||||
question = #{record.question,jdbcType=LONGVARCHAR},
|
||||
question_option = #{record.questionOption,jdbcType=LONGVARCHAR},
|
||||
question_answer = #{record.questionAnswer,jdbcType=VARCHAR}
|
||||
|
||||
<if test="_parameter != null">
|
||||
<include refid="Update_By_Example_Where_Clause" />
|
||||
@ -325,11 +337,14 @@
|
||||
<if test="isDel != null">
|
||||
is_del = #{isDel,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="topic != null">
|
||||
topic = #{topic,jdbcType=LONGVARCHAR},
|
||||
<if test="question != null">
|
||||
question = #{question,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
<if test="questions != null">
|
||||
questions = #{questions,jdbcType=LONGVARCHAR},
|
||||
<if test="questionOption != null">
|
||||
question_option = #{questionOption,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
<if test="questionAnswer != null">
|
||||
question_answer = #{questionAnswer,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id,jdbcType=BIGINT}
|
||||
@ -356,8 +371,9 @@
|
||||
company_id = #{companyId,jdbcType=BIGINT},
|
||||
race_lable = #{raceLable,jdbcType=VARCHAR},
|
||||
is_del = #{isDel,jdbcType=INTEGER},
|
||||
topic = #{topic,jdbcType=LONGVARCHAR},
|
||||
questions = #{questions,jdbcType=LONGVARCHAR}
|
||||
question = #{question,jdbcType=LONGVARCHAR},
|
||||
question_option = #{questionOption,jdbcType=LONGVARCHAR},
|
||||
question_answer = #{questionAnswer,jdbcType=VARCHAR}
|
||||
where id = #{id,jdbcType=BIGINT}
|
||||
</update>
|
||||
</mapper>
|
||||
|
Loading…
Reference in New Issue
Block a user