|
@@ -195,12 +195,12 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
if (!"单选题".equals(map.get("题型")) && !"多选题".equals(map.get("题型")) && !"判断题".equals(map.get("题型"))) {
|
|
|
throw new JeecgBootException("第【" + index + "】行题型不符合要求!");
|
|
|
}
|
|
|
+ if (StringUtils.isBlank(String.valueOf(map.get("所属题库名称")))) {
|
|
|
+ throw new JeecgBootException("第【" + index + "】行所属题库名称不能为空!");
|
|
|
+ }
|
|
|
if (StringUtils.isBlank(String.valueOf(map.get("所属题库编码")))) {
|
|
|
throw new JeecgBootException("第【" + index + "】行所属题库编码不能为空!");
|
|
|
}
|
|
|
- if (Objects.isNull(repositoryMap.get(String.valueOf(map.get("所属题库编码"))))) {
|
|
|
- throw new JeecgBootException("第【" + index + "】行所属题库编码不存在!");
|
|
|
- }
|
|
|
if (StringUtils.isBlank(String.valueOf(map.get("题干")))) {
|
|
|
throw new JeecgBootException("第【" + index + "】行题干不能为空!");
|
|
|
}
|
|
@@ -238,6 +238,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
if (!CollectionUtils.isEmpty(dataList)) {
|
|
|
List<Question> questionList = new ArrayList<>();
|
|
|
List<QuestionAnswer> answerList = new ArrayList<>();
|
|
|
+ List<Repository> repositoryList = new ArrayList<>();
|
|
|
for (Map<String, Object> map : dataList) {
|
|
|
Question question = new Question();
|
|
|
question.setId(IdUtil.getSnowflake(1, 1).nextIdStr());
|
|
@@ -289,7 +290,28 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
break;
|
|
|
case "所属题库编码":
|
|
|
//设置所属题库
|
|
|
- question.setRepositoryId(repositoryMap.get(String.valueOf(value)).getId());
|
|
|
+ //先从现有的题库找
|
|
|
+ Repository repository = repositoryMap.get(String.valueOf(value));
|
|
|
+ if (!Objects.isNull(repository)) {
|
|
|
+ question.setRepositoryId(repository.getId());
|
|
|
+ } else {
|
|
|
+ //没找到题库,从新建的题库去找
|
|
|
+ Repository r = null;
|
|
|
+ if (!CollectionUtils.isEmpty(repositoryList)) {
|
|
|
+ List<Repository> tmpList = repositoryList.stream().filter(o -> !Objects.isNull(o.getCode())
|
|
|
+ && o.getCode().equals(String.valueOf(value))).collect(Collectors.toList());
|
|
|
+ if (!CollectionUtils.isEmpty(tmpList)) {
|
|
|
+ r = tmpList.get(0);
|
|
|
+ } else {
|
|
|
+ //新建
|
|
|
+ r = createRepository(value, map, repositoryList);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //新建
|
|
|
+ r = createRepository(value, map, repositoryList);
|
|
|
+ }
|
|
|
+ question.setRepositoryId(r.getId());
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -312,10 +334,32 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
}
|
|
|
saveBatch(questionList);
|
|
|
questionAnswerService.saveBatch(answerList);
|
|
|
+ if (!CollectionUtils.isEmpty(repositoryList)) {
|
|
|
+ repositoryService.saveBatch(repositoryList);
|
|
|
+ }
|
|
|
}
|
|
|
log.info("成功导入:{}个题目,耗时:{}", dataList.size(), (System.currentTimeMillis() - beginTime) / 1000 + "秒");
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 新建题库
|
|
|
+ *
|
|
|
+ * @param value
|
|
|
+ * @param map
|
|
|
+ * @param repositoryList
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Repository createRepository(Object value, Map<String, Object> map, List<Repository> repositoryList) {
|
|
|
+ Repository r = new Repository();
|
|
|
+ r.setId(IdUtil.getSnowflake(1, 1).nextIdStr());
|
|
|
+ r.setCode(String.valueOf(value));
|
|
|
+ r.setTitle(String.valueOf(map.get("所属题库名称")));
|
|
|
+ if (!repositoryList.contains(r)) {
|
|
|
+ repositoryList.add(r);
|
|
|
+ }
|
|
|
+ return r;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 删除试题及试题选项
|
|
|
*
|