package com.walker.etaa;
|
|
import com.walker.infrastructure.utils.StringUtils;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* 试题抽取条件选项对象,<br>
|
* 业务可以创建该对象完成抽取范围设置。
|
* @author 时克英
|
* @date 2023-03-07
|
*/
|
public class QuestionExtractOptions {
|
|
protected static final Logger logger = LoggerFactory.getLogger(QuestionExtractOptions.class);
|
|
private String ownerId;
|
private String deptId;
|
private String rootCatalog;
|
private long extractTotal = 0;
|
private List<ExtractOptionItem> optionItemList = null;
|
|
private ExtractStrategy extractStrategy = ExtractStrategy.Random;
|
|
public ExtractStrategy getExtractStrategy() {
|
return extractStrategy;
|
}
|
|
/**
|
* 设置抽取策略。
|
* @param extractStrategy
|
* @date 2023-03-08
|
*/
|
public void setExtractStrategy(ExtractStrategy extractStrategy) {
|
this.extractStrategy = extractStrategy;
|
}
|
|
/**
|
* 返回归属对象,一般指顶级机构ID,可选
|
* @return
|
*/
|
public String getOwnerId() {
|
return ownerId;
|
}
|
|
/**
|
* 返回部门机构ID,表明抽取机构范围,可选
|
* @return
|
*/
|
public String getDeptId() {
|
return deptId;
|
}
|
|
/**
|
* 返回试题库主分类,通常表示一个根目录,如:化学、数学等,可选。
|
* @return
|
*/
|
public String getRootCatalog() {
|
return rootCatalog;
|
}
|
|
/**
|
* 返回抽取试题总数量。
|
* @return
|
*/
|
public long getExtractTotal() {
|
return extractTotal;
|
}
|
|
/**
|
* 返回抽取明细规则列表,包含多种选项,如:选择题10道、三角方程分类下判断题10道等,可选。<p></p>
|
* 如果为空,则表示仅按照全局配置抽取即可。
|
* @return
|
*/
|
public List<ExtractOptionItem> getOptionItemList() {
|
return optionItemList;
|
}
|
|
public QuestionExtractOptions setGlobalConfig(String ownerId
|
, String deptId, String rootCatalog, long extractTotal){
|
if(extractTotal <= 0){
|
throw new IllegalArgumentException("抽取试题数量必须大于0!");
|
}
|
this.ownerId = ownerId;
|
this.deptId = deptId;
|
this.rootCatalog = rootCatalog;
|
this.extractTotal = extractTotal;
|
return this;
|
}
|
|
/**
|
* 添加一个抽取明细配置,去掉了'minorCatalog',该属性废弃。
|
* @param majorCatalog 题目分类二级目录
|
* @param questionType 试题类型
|
* @param difficultLevel 难度级别,暂未使用
|
* @param count 抽取数量
|
* @return
|
* @date 2023-03-08
|
*/
|
public QuestionExtractOptions addOption(String majorCatalog
|
// , String minorCatalog
|
, QuestionType questionType, DifficultLevel difficultLevel, long count){
|
if(StringUtils.isEmpty(majorCatalog)){
|
// throw new IllegalArgumentException("major(主类)必须设置");
|
logger.warn("抽取试题'主分类'未设置,目前系统支持该操作。");
|
}
|
// if(questionType == null){
|
// throw new IllegalArgumentException("试题类型必须设置!");
|
// }
|
if(count <= 0){
|
throw new IllegalArgumentException("试题数量必须大于0!");
|
}
|
if(this.optionItemList == null){
|
this.optionItemList = new ArrayList<>(4);
|
}
|
|
ExtractOptionItem extractOptionItem
|
= new ExtractOptionItem(majorCatalog, null, questionType, difficultLevel, count);
|
if(this.optionItemList.contains(extractOptionItem)){
|
throw new IllegalArgumentException("添加的条件已经存在!");
|
}
|
this.optionItemList.add(extractOptionItem);
|
return this;
|
}
|
|
@Override
|
public String toString(){
|
return new StringBuilder("[owner=").append(this.ownerId)
|
.append(", deptId=").append(this.deptId)
|
.append(", rootCatalog=").append(this.rootCatalog)
|
.append(", extractTotal=").append(this.extractTotal)
|
.append(", optionItemList=").append(this.optionItemList)
|
.append("]").toString();
|
}
|
|
public class ExtractOptionItem {
|
|
public ExtractOptionItem(String majorCatalog, String minorCatalog
|
, QuestionType questionType, DifficultLevel difficultLevel, long count){
|
this.majorCatalog = majorCatalog;
|
this.minorCatalog = minorCatalog;
|
this.questionType = questionType;
|
this.difficultLevel = difficultLevel;
|
this.count = count;
|
}
|
|
@Override
|
public boolean equals(Object obj){
|
if(obj == null){
|
return false;
|
}
|
if(obj instanceof ExtractOptionItem){
|
ExtractOptionItem item = (ExtractOptionItem) obj;
|
if(item.hashCode == this.hashCode){
|
return true;
|
}
|
}
|
return false;
|
}
|
|
@Override
|
public int hashCode(){
|
if(this.hashCode == -1){
|
this.hashCode = this.getId().hashCode();
|
}
|
return this.hashCode;
|
}
|
|
private String getId(){
|
StringBuilder sb = new StringBuilder();
|
if(StringUtils.isNotEmpty(this.majorCatalog)){
|
sb.append(this.majorCatalog);
|
}
|
if(StringUtils.isNotEmpty(this.minorCatalog)){
|
sb.append(this.minorCatalog);
|
}
|
sb.append(questionType.getIndex());
|
if(this.difficultLevel != null){
|
sb.append(this.difficultLevel.getIndex());
|
}
|
sb.append(this.count);
|
return sb.toString();
|
}
|
|
public String getMajorCatalog() {
|
return majorCatalog;
|
}
|
|
public void setMajorCatalog(String majorCatalog) {
|
this.majorCatalog = majorCatalog;
|
}
|
|
/**
|
* 该属性废弃,试题分类只有:root_catalog 和 major_catalog
|
* @return
|
* @date 2023-03-08
|
*/
|
@Deprecated
|
public String getMinorCatalog() {
|
return minorCatalog;
|
}
|
|
public void setMinorCatalog(String minorCatalog) {
|
this.minorCatalog = minorCatalog;
|
}
|
|
public QuestionType getQuestionType() {
|
return questionType;
|
}
|
|
public void setQuestionType(QuestionType questionType) {
|
this.questionType = questionType;
|
}
|
|
public DifficultLevel getDifficultLevel() {
|
return difficultLevel;
|
}
|
|
public void setDifficultLevel(DifficultLevel difficultLevel) {
|
this.difficultLevel = difficultLevel;
|
}
|
|
public long getCount() {
|
return count;
|
}
|
|
public void setCount(long count) {
|
this.count = count;
|
}
|
|
@Override
|
public String toString(){
|
return new StringBuilder("[hashCode=").append(this.hashCode)
|
.append(", majorCatalog=").append(this.majorCatalog)
|
.append(", minorCatalog=").append(this.minorCatalog)
|
.append(", questionType=").append(this.questionType)
|
.append(", level=").append(this.difficultLevel)
|
.append(", count=").append(this.count)
|
.append("]").toString();
|
}
|
|
private int hashCode = -1;
|
private String majorCatalog;
|
private String minorCatalog;
|
private QuestionType questionType;
|
private DifficultLevel difficultLevel;
|
private long count = 0;
|
}
|
}
|