|
|
|
@ -22,7 +22,6 @@ import com.ibeetl.jlw.service.strategy.StrategyContext;
|
|
|
|
|
import com.ibeetl.jlw.validator.QuestionValidator;
|
|
|
|
|
import com.ibeetl.jlw.web.query.CourseInfoQuery;
|
|
|
|
|
import com.ibeetl.jlw.web.query.ResourcesQuestionQuery;
|
|
|
|
|
import lombok.SneakyThrows;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.apache.logging.log4j.util.Strings;
|
|
|
|
@ -789,8 +788,17 @@ public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion>
|
|
|
|
|
return g;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SneakyThrows
|
|
|
|
|
public JsonResult importQBankWordTemplate(@NotEmpty List<FileEntity> fileEntityList, CoreUser coreUser, String referer) {
|
|
|
|
|
/**
|
|
|
|
|
* 功能描述: <br>
|
|
|
|
|
* word方式导入题目
|
|
|
|
|
*
|
|
|
|
|
* @param fileEntityList 文件列表
|
|
|
|
|
* @param coreUser 传入的用户,使用机构ID和用户ID
|
|
|
|
|
* @return {@link JsonResult}
|
|
|
|
|
* @Author: lx
|
|
|
|
|
* @Date: 2023/1/8 22:49
|
|
|
|
|
*/
|
|
|
|
|
public JsonResult importQuestionByWordTemplate(@NotEmpty List<FileEntity> fileEntityList, CoreUser coreUser) {
|
|
|
|
|
/** 找出段落, 逐段落处理 */
|
|
|
|
|
AtomicReference<FileInputStream> inputStream = new AtomicReference<>();
|
|
|
|
|
AtomicReference<XWPFDocument> xDocument = new AtomicReference<>();
|
|
|
|
@ -873,25 +881,22 @@ public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion>
|
|
|
|
|
questionAnswer.set(Strings.EMPTY);
|
|
|
|
|
|
|
|
|
|
/** 带有编号的段落,是主题干。需要创建新的题目对象 */
|
|
|
|
|
ResourcesQuestion qs = new ResourcesQuestion();
|
|
|
|
|
ResourcesQuestion resourcesQuestion = new ResourcesQuestion();
|
|
|
|
|
/** 题目类型,查询插入操作 */
|
|
|
|
|
QuestionType questionType = selectOrInsert(typeConcatEnum.get(), coreUser);
|
|
|
|
|
qs.setQuestionTypeId(questionType.getQuestionTypeId());
|
|
|
|
|
qs.putQuestionTypeConcat(questionType.getQuestionTypeConcat());
|
|
|
|
|
qs.putQuestionTypeName(questionType.getQuestionTypeName());
|
|
|
|
|
qs.setQuestionScore(questionScore.get());
|
|
|
|
|
ResourcesQuestionTypeEnum questionType = selectQuestionType(typeConcatEnum.get());
|
|
|
|
|
resourcesQuestion.setQuestionType(questionType.getCode());
|
|
|
|
|
resourcesQuestion.setQuestionScore(questionScore.get());
|
|
|
|
|
resourcesQuestion.setQuestionStatus(1);
|
|
|
|
|
resourcesQuestion.setUserId(coreUser.getId());
|
|
|
|
|
resourcesQuestion.setOrgId(coreUser.getOrgId());
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(questionStem.get())){
|
|
|
|
|
qs.setQuestionStem(questionStem.get().replace("<","<").replace(">",">"));
|
|
|
|
|
resourcesQuestion.setQuestionStem(questionStem.get().replace("<","<").replace(">",">"));
|
|
|
|
|
}else {
|
|
|
|
|
qs.setQuestionStem(questionStem.get());
|
|
|
|
|
resourcesQuestion.setQuestionStem(questionStem.get());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qs.setQuestionStatus(1);
|
|
|
|
|
qs.setUserId(coreUser.getId());
|
|
|
|
|
qs.setOrgId(coreUser.getOrgId());
|
|
|
|
|
|
|
|
|
|
question.set(qs);
|
|
|
|
|
question.set(resourcesQuestion);
|
|
|
|
|
questionList.add(question.get());
|
|
|
|
|
}
|
|
|
|
|
} break;
|
|
|
|
@ -915,14 +920,10 @@ public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion>
|
|
|
|
|
titleStb.append(recordsCount.get());
|
|
|
|
|
titleStb.append(" 道题目</font>");
|
|
|
|
|
|
|
|
|
|
Object ids[] = getCourseIdsNew(title[0], groupByCourseId.get(), groupByCourseName.get());
|
|
|
|
|
final Long courseId = (Long)ids[0];
|
|
|
|
|
final Long chapterId = (Long)ids[1];
|
|
|
|
|
String finalTitle = !referer.contains(publicReferer)? titleStb.toString(): titleStb.append(ids[2] + Strings.EMPTY).toString();
|
|
|
|
|
String finalTitle = titleStb.toString();
|
|
|
|
|
|
|
|
|
|
/** 最后检测属性, 并行处理,没有向外部非线程安全的变量写入东西,无需担心丢数据 */
|
|
|
|
|
questionList.parallelStream().forEach(item -> {
|
|
|
|
|
item.set("chapterId", ObjectUtil.defaultIfNull(chapterId, courseId));
|
|
|
|
|
questionValidator.checkQuestion(item);
|
|
|
|
|
checkUnique(item);
|
|
|
|
|
});
|
|
|
|
@ -931,11 +932,11 @@ public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion>
|
|
|
|
|
checkLocalQuestionsUnique(questionList);
|
|
|
|
|
|
|
|
|
|
/** 拼成前端需要的数据 */
|
|
|
|
|
resultMap.put(url2HttpUrl(fileEntity.getUrl()),new Object[]{finalTitle,questionList});
|
|
|
|
|
resultMap.put(fileEntity.getUrl(), new Object[]{ finalTitle, questionList });
|
|
|
|
|
} catch (Exception ex) { ex.printStackTrace(); }
|
|
|
|
|
finally {
|
|
|
|
|
try {inputStream.get().close();xDocument.get().close();}
|
|
|
|
|
catch (Exception ioe) {ioe.printStackTrace();}
|
|
|
|
|
try {inputStream.get().close(); xDocument.get().close(); }
|
|
|
|
|
catch (Exception ioe) { ioe.printStackTrace(); }
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -957,29 +958,77 @@ public class ResourcesQuestionService extends CoreBaseService<ResourcesQuestion>
|
|
|
|
|
}
|
|
|
|
|
Matcher matcher = optionPattern.matcher(text);
|
|
|
|
|
if(matcher.find()){
|
|
|
|
|
QuestionOption questionOption = new QuestionOption();
|
|
|
|
|
questionOption.setQuestionOptionContent(text.substring(2));
|
|
|
|
|
if(null != question.takeQuestionOptionList()){
|
|
|
|
|
List<QuestionOption> questionOptionList = question.takeQuestionOptionList();
|
|
|
|
|
questionOptionList.add(questionOption);
|
|
|
|
|
question.putQuestionOptionList(questionOptionList);
|
|
|
|
|
}else {
|
|
|
|
|
List<QuestionOption> questionOptionList = new ArrayList<>();
|
|
|
|
|
String questionOption = text.substring(2);
|
|
|
|
|
// 在现有的列表中添加
|
|
|
|
|
if(null != question.getQuestionOptionList()){
|
|
|
|
|
List<String> questionOptionList = question.getQuestionOptionList();
|
|
|
|
|
questionOptionList.add(questionOption);
|
|
|
|
|
question.putQuestionOptionList(questionOptionList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(null != question.takeQuestionOptionConcatList()){
|
|
|
|
|
List<String> questionOptionConcatList = question.takeQuestionOptionConcatList();
|
|
|
|
|
questionOptionConcatList.add(text.substring(2));
|
|
|
|
|
question.putQuestionOptionConcatList(questionOptionConcatList);
|
|
|
|
|
}else {
|
|
|
|
|
List<String> questionOptionConcatList = new ArrayList<>();
|
|
|
|
|
questionOptionConcatList.add(text.substring(2));
|
|
|
|
|
question.putQuestionOptionConcatList(questionOptionConcatList);
|
|
|
|
|
// 新建
|
|
|
|
|
else {
|
|
|
|
|
question.putQuestionOptionList(Collections.singletonList(questionOption));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 插入到对应的段落中.
|
|
|
|
|
* 直接在引用的数据上进行修改数据
|
|
|
|
|
* 换行追加的方法
|
|
|
|
|
*
|
|
|
|
|
* @param typeConcatEnum 题型枚举
|
|
|
|
|
* @param paragraphType 段落类型
|
|
|
|
|
* @param v 当前段落文本
|
|
|
|
|
* @param question 问题实体
|
|
|
|
|
*/
|
|
|
|
|
private void insertCorrespondingParagraph(final AtomicReference<StrategyContext.QuestionTypeConcatEnum> typeConcatEnum,
|
|
|
|
|
final StrategyContext.QuestionParagraphTypeEnum paragraphType,
|
|
|
|
|
final String v,
|
|
|
|
|
final AtomicReference<ResourcesQuestion> question,
|
|
|
|
|
final AtomicReference<String> questionStem,
|
|
|
|
|
final AtomicReference<String> questionAnswer) {
|
|
|
|
|
if(null == paragraphType) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch(paragraphType) {
|
|
|
|
|
/** 题干 */
|
|
|
|
|
case STEM: {
|
|
|
|
|
questionStem.set(questionStem.get().concat(v));
|
|
|
|
|
question.get().setQuestionStem(questionStem.get());
|
|
|
|
|
} break;
|
|
|
|
|
/** 选项 */
|
|
|
|
|
case OPTION: {
|
|
|
|
|
List<String> optionList = question.get().takeQuestionOptionConcatList();
|
|
|
|
|
if (ObjectUtil.isNotEmpty(optionList)) {
|
|
|
|
|
final int[] index = { 0 };
|
|
|
|
|
optionList.forEach(str-> {
|
|
|
|
|
if(index[0] == optionList.size() -1) {
|
|
|
|
|
str = str.concat(v);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
// if (ObjectUtil.isNotEmpty(questionOptions)) {
|
|
|
|
|
// QuestionOption questionOption = questionOptions.get(questionOptions.size() - 1);
|
|
|
|
|
// questionOption.setQuestionOptionContent(questionOption.getQuestionOptionContent().concat(v));
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
/** 答案 */
|
|
|
|
|
case ANSWER: {
|
|
|
|
|
questionAnswer.set(secondFormat(questionAnswer.get().concat(v), typeConcatEnum.get()));
|
|
|
|
|
question.get().setQuestionAnswer(questionAnswer.get());
|
|
|
|
|
} break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询是否存在,不存在则插入新数据
|
|
|
|
|
* @param typeConcatEnum
|
|
|
|
|
*/
|
|
|
|
|
public ResourcesQuestionTypeEnum selectQuestionType(StrategyContext.QuestionTypeConcatEnum typeConcatEnum) {
|
|
|
|
|
return EnumUtil.likeValueOf(ResourcesQuestionTypeEnum.class, typeConcatEnum.getTypeConcat());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|