|
|
package com.ibeetl.jlw.entity;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.util.EnumUtil;
|
|
|
import cn.hutool.core.util.ReUtil;
|
|
|
import cn.hutool.core.util.ReflectUtil;
|
|
|
import cn.jlw.validate.ValidateConfig;
|
|
|
import com.ibeetl.admin.core.annotation.Dict;
|
|
|
import com.ibeetl.admin.core.annotation.DictEnum;
|
|
|
import com.ibeetl.admin.core.entity.BaseEntity;
|
|
|
import com.ibeetl.jlw.enums.AddTypeEnum;
|
|
|
import com.ibeetl.jlw.enums.ResourcesQuestionTypeEnum;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.beetl.sql.annotation.entity.AutoID;
|
|
|
import org.beetl.sql.annotation.entity.InsertIgnore;
|
|
|
import org.beetl.sql.annotation.entity.UpdateIgnore;
|
|
|
|
|
|
import javax.validation.constraints.NotNull;
|
|
|
import java.lang.reflect.Field;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.concurrent.CopyOnWriteArrayList;
|
|
|
|
|
|
import static cn.hutool.core.util.ObjectUtil.defaultIfNull;
|
|
|
|
|
|
/*
|
|
|
* 资源管理 - 题库管理
|
|
|
* gen by Spring Boot2 Admin 2021-06-25
|
|
|
*/
|
|
|
@Slf4j
|
|
|
public class ResourcesQuestion extends BaseEntity{
|
|
|
|
|
|
//ID
|
|
|
@NotNull(message = "ID不能为空", groups =ValidateConfig.UPDATE.class)
|
|
|
// @SeqID(name = ORACLE_CORE_SEQ_NAME)
|
|
|
@AutoID
|
|
|
|
|
|
private Long resourcesQuestionId ;
|
|
|
|
|
|
//课程ID
|
|
|
|
|
|
private Long courseInfoId ;
|
|
|
|
|
|
//题型(1单选 2多选 3判断 4填空 5分析)
|
|
|
|
|
|
private Integer questionType ;
|
|
|
|
|
|
//分值
|
|
|
|
|
|
private BigDecimal questionScore ;
|
|
|
|
|
|
//题干
|
|
|
|
|
|
private String questionStem ;
|
|
|
|
|
|
//选项A
|
|
|
|
|
|
private String questionOptionA ;
|
|
|
|
|
|
//选项B
|
|
|
|
|
|
private String questionOptionB ;
|
|
|
|
|
|
//选项C
|
|
|
|
|
|
private String questionOptionC ;
|
|
|
|
|
|
//选项D
|
|
|
|
|
|
private String questionOptionD ;
|
|
|
|
|
|
//选项E
|
|
|
|
|
|
private String questionOptionE ;
|
|
|
|
|
|
//答案(单选是一个 多选是多个 判断是对错)
|
|
|
|
|
|
private String questionAnswer ;
|
|
|
|
|
|
//解析
|
|
|
|
|
|
private String questionAnalysis ;
|
|
|
|
|
|
// 上下架状态
|
|
|
|
|
|
private Integer questionStatus;
|
|
|
|
|
|
//组织机构ID
|
|
|
|
|
|
@Dict(type = "core_org.name.del_flag=0")
|
|
|
private Long orgId ;
|
|
|
|
|
|
//后台用户ID
|
|
|
|
|
|
private Long userId ;
|
|
|
|
|
|
// 来源类型
|
|
|
@DictEnum
|
|
|
|
|
|
private AddTypeEnum addType ;
|
|
|
|
|
|
//题库来源
|
|
|
private String addTypeText;
|
|
|
|
|
|
/**
|
|
|
* 试题来源 1 教师新增 2 系统新增
|
|
|
*/
|
|
|
private String sourceType;
|
|
|
|
|
|
/**
|
|
|
* 新增时间
|
|
|
*/
|
|
|
@InsertIgnore
|
|
|
private Date addTime;
|
|
|
|
|
|
public ResourcesQuestion(){
|
|
|
}
|
|
|
|
|
|
/**ID
|
|
|
*@return
|
|
|
*/
|
|
|
public Long getResourcesQuestionId(){
|
|
|
return resourcesQuestionId;
|
|
|
}
|
|
|
/**ID
|
|
|
*@param resourcesQuestionId
|
|
|
*/
|
|
|
public void setResourcesQuestionId(Long resourcesQuestionId){
|
|
|
this.resourcesQuestionId = resourcesQuestionId;
|
|
|
}
|
|
|
|
|
|
/**课程ID
|
|
|
*@return
|
|
|
*/
|
|
|
public Long getCourseInfoId(){
|
|
|
return courseInfoId;
|
|
|
}
|
|
|
/**课程ID
|
|
|
*@param courseInfoId
|
|
|
*/
|
|
|
public void setCourseInfoId(Long courseInfoId){
|
|
|
this.courseInfoId = courseInfoId;
|
|
|
}
|
|
|
|
|
|
/**题型(1单选 2多选 3判断 4填空 5分析)
|
|
|
*@return
|
|
|
*/
|
|
|
public Integer getQuestionType(){
|
|
|
return questionType;
|
|
|
}
|
|
|
/**题型(1单选 2多选 3判断 4)
|
|
|
*@param questionType
|
|
|
*/
|
|
|
public void setQuestionType(Integer questionType){
|
|
|
this.questionType = questionType;
|
|
|
}
|
|
|
|
|
|
/**分值
|
|
|
*@return
|
|
|
*/
|
|
|
public BigDecimal getQuestionScore(){
|
|
|
return questionScore;
|
|
|
}
|
|
|
/**分值
|
|
|
*@param questionScore
|
|
|
*/
|
|
|
public void setQuestionScore(BigDecimal questionScore){
|
|
|
this.questionScore = questionScore;
|
|
|
}
|
|
|
|
|
|
/**题干
|
|
|
*@return
|
|
|
*/
|
|
|
public String getQuestionStem(){
|
|
|
return questionStem;
|
|
|
}
|
|
|
/**题干
|
|
|
*@param questionStem
|
|
|
*/
|
|
|
public void setQuestionStem(String questionStem){
|
|
|
this.questionStem = questionStem;
|
|
|
}
|
|
|
|
|
|
/**选项A
|
|
|
*@return
|
|
|
*/
|
|
|
public String getQuestionOptionA(){
|
|
|
return questionOptionA;
|
|
|
}
|
|
|
/**选项A
|
|
|
*@param questionOptionA
|
|
|
*/
|
|
|
public void setQuestionOptionA(String questionOptionA){
|
|
|
this.questionOptionA = questionOptionA;
|
|
|
}
|
|
|
|
|
|
/**选项B
|
|
|
*@return
|
|
|
*/
|
|
|
public String getQuestionOptionB(){
|
|
|
return questionOptionB;
|
|
|
}
|
|
|
/**选项B
|
|
|
*@param questionOptionB
|
|
|
*/
|
|
|
public void setQuestionOptionB(String questionOptionB){
|
|
|
this.questionOptionB = questionOptionB;
|
|
|
}
|
|
|
|
|
|
/**选项C
|
|
|
*@return
|
|
|
*/
|
|
|
public String getQuestionOptionC(){
|
|
|
return questionOptionC;
|
|
|
}
|
|
|
/**选项C
|
|
|
*@param questionOptionC
|
|
|
*/
|
|
|
public void setQuestionOptionC(String questionOptionC){
|
|
|
this.questionOptionC = questionOptionC;
|
|
|
}
|
|
|
|
|
|
/**选项D
|
|
|
*@return
|
|
|
*/
|
|
|
public String getQuestionOptionD(){
|
|
|
return questionOptionD;
|
|
|
}
|
|
|
/**选项D
|
|
|
*@param questionOptionD
|
|
|
*/
|
|
|
public void setQuestionOptionD(String questionOptionD){
|
|
|
this.questionOptionD = questionOptionD;
|
|
|
}
|
|
|
|
|
|
/**选项E
|
|
|
*@return
|
|
|
*/
|
|
|
public String getQuestionOptionE(){
|
|
|
return questionOptionE;
|
|
|
}
|
|
|
/**选项E
|
|
|
*@param questionOptionE
|
|
|
*/
|
|
|
public void setQuestionOptionE(String questionOptionE){
|
|
|
this.questionOptionE = questionOptionE;
|
|
|
}
|
|
|
|
|
|
/**答案(单选是一个 多选是多个 判断是对错)
|
|
|
*@return
|
|
|
*/
|
|
|
public String getQuestionAnswer(){
|
|
|
return questionAnswer;
|
|
|
}
|
|
|
/**答案(单选是一个 多选是多个 判断是对错)
|
|
|
*@param questionAnswer
|
|
|
*/
|
|
|
public void setQuestionAnswer(String questionAnswer){
|
|
|
this.questionAnswer = questionAnswer;
|
|
|
}
|
|
|
|
|
|
/**解析
|
|
|
*@return
|
|
|
*/
|
|
|
public String getQuestionAnalysis(){
|
|
|
return questionAnalysis;
|
|
|
}
|
|
|
/**解析
|
|
|
*@param questionAnalysis
|
|
|
*/
|
|
|
public void setQuestionAnalysis(String questionAnalysis){
|
|
|
this.questionAnalysis = questionAnalysis;
|
|
|
}
|
|
|
|
|
|
/**组织机构ID
|
|
|
*@return
|
|
|
*/
|
|
|
public Long getOrgId(){
|
|
|
return orgId;
|
|
|
}
|
|
|
/**组织机构ID
|
|
|
*@param orgId
|
|
|
*/
|
|
|
public void setOrgId(Long orgId){
|
|
|
this.orgId = orgId;
|
|
|
}
|
|
|
|
|
|
/**后台用户ID
|
|
|
*@return
|
|
|
*/
|
|
|
public Long getUserId(){
|
|
|
return userId;
|
|
|
}
|
|
|
/**后台用户ID
|
|
|
*@param userId
|
|
|
*/
|
|
|
public void setUserId(Long userId){
|
|
|
this.userId = userId;
|
|
|
}
|
|
|
|
|
|
public Integer getQuestionStatus() {
|
|
|
return questionStatus;
|
|
|
}
|
|
|
|
|
|
public void setQuestionStatus(Integer questionStatus) {
|
|
|
this.questionStatus = questionStatus;
|
|
|
}
|
|
|
|
|
|
public AddTypeEnum getAddType() {
|
|
|
return addType;
|
|
|
}
|
|
|
|
|
|
public void setAddType(AddTypeEnum addType) {
|
|
|
this.addType = addType;
|
|
|
}
|
|
|
|
|
|
public String getAddTypeText() {
|
|
|
return addTypeText;
|
|
|
}
|
|
|
|
|
|
public void setAddTypeText(String addTypeText) {
|
|
|
this.addTypeText = addTypeText;
|
|
|
}
|
|
|
|
|
|
public Date getAddTime() {
|
|
|
return addTime;
|
|
|
}
|
|
|
|
|
|
public void setAddTime(Date addTime) {
|
|
|
this.addTime = addTime;
|
|
|
}
|
|
|
|
|
|
public String getSourceType() {
|
|
|
return sourceType;
|
|
|
}
|
|
|
|
|
|
public void setSourceType(String sourceType) {
|
|
|
this.sourceType = sourceType;
|
|
|
}
|
|
|
|
|
|
/**题干, 图片转换成正则
|
|
|
*@return
|
|
|
*/
|
|
|
public String getQuestionStemRegexp(){
|
|
|
return ReUtil.escape(questionStem)
|
|
|
.replaceAll("<img.*?[^<]/>", "<img.*?[^<]/>")
|
|
|
.replace("(","(").replace(")",")");
|
|
|
}
|
|
|
|
|
|
public List<String> takeQuestionOptionConcatList() {
|
|
|
|
|
|
List<String> result = new ArrayList<>();
|
|
|
|
|
|
for (Field field : optionFields) {
|
|
|
Object fieldValue = ReflectUtil.getFieldValue(this, field);
|
|
|
if (fieldValue != null) {
|
|
|
result.add(fieldValue.toString());
|
|
|
}
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 选项的属性
|
|
|
*/
|
|
|
private final static Field[] optionFields = ReflectUtil.getFields(ResourcesQuestion.class, f -> f.getName().startsWith("questionOption"));
|
|
|
|
|
|
/**
|
|
|
* 查找为Null的题目选项字段
|
|
|
* @return
|
|
|
*/
|
|
|
private Field findNullQuestionOptionField() {
|
|
|
for (Field field : optionFields) {
|
|
|
Object fieldValue = ReflectUtil.getFieldValue(this, field);
|
|
|
if (fieldValue == null) {
|
|
|
return field;
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 用于存放无限长度的题目答案
|
|
|
*/
|
|
|
@UpdateIgnore
|
|
|
@InsertIgnore
|
|
|
private List<String> resourcesQuestionOptionList;
|
|
|
|
|
|
public List<String> getResourcesQuestionOptionList() {
|
|
|
return resourcesQuestionOptionList;
|
|
|
}
|
|
|
|
|
|
public void setResourcesQuestionOptionList(CopyOnWriteArrayList<String> questionOptionList) {
|
|
|
this.resourcesQuestionOptionList = questionOptionList;
|
|
|
}
|
|
|
|
|
|
public static final String LINE_8 = "_{8,}";
|
|
|
public static final String SPLIT_ = "[---]";
|
|
|
|
|
|
/**
|
|
|
* 表设计缺陷,需要根据题目类型,进行值的转化,再存放到相应的位置
|
|
|
* @param questionOptionList
|
|
|
*/
|
|
|
public void putQuestionOptionList(List<String> questionOptionList) {
|
|
|
if (CollectionUtil.isEmpty(questionOptionList)) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (getResourcesQuestionOptionList() == null) {
|
|
|
setResourcesQuestionOptionList(new CopyOnWriteArrayList<>());
|
|
|
}
|
|
|
|
|
|
ResourcesQuestionTypeEnum questionTypeEnum = EnumUtil.likeValueOf(ResourcesQuestionTypeEnum.class, this.getQuestionType());
|
|
|
|
|
|
if (questionTypeEnum != null) {
|
|
|
switch (questionTypeEnum) {
|
|
|
case SINGLE_QUESTION:
|
|
|
case MULTIPLE_QUESTION: {
|
|
|
questionOptionList.forEach(item -> {
|
|
|
Field optionField = findNullQuestionOptionField();
|
|
|
getResourcesQuestionOptionList().add(item);
|
|
|
|
|
|
if (optionField != null) {
|
|
|
ReflectUtil.setFieldValue(this, optionField, item);
|
|
|
}
|
|
|
});
|
|
|
} break;
|
|
|
case FILL_QUESTION: {
|
|
|
|
|
|
} break;
|
|
|
case ANALYSIS_QUESTION: {
|
|
|
// 分析题 questionOptionA 存放的是[---] 空的长度
|
|
|
// 分析题 questionOptionB 存放的是带填空的题干
|
|
|
questionOptionList.forEach(text -> {
|
|
|
Integer count = Integer.valueOf(defaultIfNull(getQuestionOptionA(), "0"));
|
|
|
setQuestionOptionA((++count).toString());
|
|
|
|
|
|
String replacedText = text.replaceAll(LINE_8, SPLIT_);
|
|
|
setQuestionOptionB(defaultIfNull(getQuestionOptionB(), "").concat(replacedText));
|
|
|
});
|
|
|
} break;
|
|
|
default:
|
|
|
log.error("ResourcesQuestion.putQuestionOptionList 方法,未知的题目类型!");
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|