|
@@ -17,6 +17,7 @@ import com.yntravelsky.buss.exam.questionanswer.entity.QuestionAnswer;
|
|
|
import com.yntravelsky.buss.exam.questionanswer.service.IQuestionAnswerService;
|
|
|
import com.yntravelsky.buss.exam.repository.entity.Repository;
|
|
|
import com.yntravelsky.buss.exam.repository.service.IRepositoryService;
|
|
|
+import com.yntravelsky.common.utils.CharUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.jeecg.common.exception.JeecgBootException;
|
|
@@ -191,8 +192,8 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
if (StringUtils.isBlank(String.valueOf(map.get("题型")))) {
|
|
|
throw new JeecgBootException("第【" + index + "】行题型不能为空!");
|
|
|
}
|
|
|
- if (!"单选题".equals(map.get("题型")) && !"多选题".equals(map.get("题型"))
|
|
|
- && !"判断题".equals(map.get("题型")) && !"简答题".equals(map.get("题型"))) {
|
|
|
+ if (!"单选题".equals(map.get("题型")) && !"多选题".equals(map.get("题型")) && !"判断题".equals(map.get("题型"))
|
|
|
+ && !"简答题".equals(map.get("题型")) && !"填空题".equals(map.get("题型"))) {
|
|
|
throw new JeecgBootException("第【" + index + "】行题型不符合要求!");
|
|
|
}
|
|
|
if (StringUtils.isBlank(String.valueOf(map.get("所属题库名称")))) {
|
|
@@ -205,7 +206,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
throw new JeecgBootException("第【" + index + "】行题干不能为空!");
|
|
|
}
|
|
|
//单选题和多选题检查选项
|
|
|
- if ("单选题".equals(map.get("题型")) || "多选题".equals(map.get("题型"))) {
|
|
|
+ if ("单选题".equals(map.get("题型")) || "多选题".equals(map.get("题型")) || "填空题".equals(map.get("题型"))) {
|
|
|
List<String> optionList = new ArrayList<>();
|
|
|
for (Map.Entry<String, Object> entity : map.entrySet()) {
|
|
|
String key = entity.getKey();
|
|
@@ -220,7 +221,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
throw new JeecgBootException("第【" + index + "】行至少包含一个选项!");
|
|
|
}
|
|
|
}
|
|
|
- if (!QuestionType.SIMPLE.getValue().equals("简答题")) {
|
|
|
+ if (!("简答题".equals(map.get("题型")) || "填空题".equals(map.get("题型")))) {//填空题和简答题不检查答案
|
|
|
if (StringUtils.isBlank(String.valueOf(map.get("答案")))) {
|
|
|
throw new JeecgBootException("第【" + index + "】行答案不能为空!");
|
|
|
}
|
|
@@ -249,11 +250,18 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
String key = entity.getKey();
|
|
|
Object value = entity.getValue();
|
|
|
if (key.contains("选项")) {
|
|
|
- if (("单选题".equals(map.get("题型")) || "多选题".equals(map.get("题型"))) && StringUtils.isNotBlank(value.toString())) {
|
|
|
- QuestionAnswer answer = new QuestionAnswer();
|
|
|
- answer.setContent(String.valueOf(value));
|
|
|
- answer.setTag(key.replaceAll("选项", ""));
|
|
|
- answers.add(answer);
|
|
|
+ if (("单选题".equals(map.get("题型")) || "多选题".equals(map.get("题型"))) ||
|
|
|
+ "填空题".equals(map.get("题型")) && StringUtils.isNotBlank(value.toString())) {
|
|
|
+ if (!Objects.isNull(value) && StringUtils.isNotBlank(String.valueOf(value).trim())) {
|
|
|
+ QuestionAnswer answer = new QuestionAnswer();
|
|
|
+ answer.setContent(String.valueOf(value));
|
|
|
+ if ("填空题".equals(map.get("题型"))) {
|
|
|
+ answer.setTag(String.valueOf(CharUtil.getZmIndex(key.replaceAll("选项", ""))));
|
|
|
+ } else {
|
|
|
+ answer.setTag(key.replaceAll("选项", ""));
|
|
|
+ }
|
|
|
+ answers.add(answer);
|
|
|
+ }
|
|
|
} else if ("判断题".equals(map.get("题型")) && CollectionUtils.isEmpty(answers)) {
|
|
|
QuestionAnswer answerYes = new QuestionAnswer();
|
|
|
answerYes.setContent("正确");
|
|
@@ -275,6 +283,8 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
question.setType(QuestionType.JUDGE.getCode());
|
|
|
} else if ("简答题".equals(value)) {
|
|
|
question.setType(QuestionType.SIMPLE.getCode());
|
|
|
+ } else if ("填空题".equals(value)) {
|
|
|
+ question.setType(QuestionType.BLANK.getCode());
|
|
|
}
|
|
|
break;
|
|
|
case "难易程度":
|
|
@@ -320,6 +330,10 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ if (QuestionType.BLANK.getCode().equals(question.getType())) {
|
|
|
+ //填空题重新设置内容中的填空,替换题目中的括号
|
|
|
+ question.setContent(replaceBlankContent(question.getContent()));
|
|
|
+ }
|
|
|
questionList.add(question);
|
|
|
int sort = 1;
|
|
|
List<QuestionAnswer> answerGroupList = new ArrayList<>();
|
|
@@ -329,6 +343,8 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
answer.setIsRight(String.valueOf(map.get("答案")).contains(answer.getTag()) ? true : false);
|
|
|
} else if (QuestionType.JUDGE.getCode().equals(question.getType())) {
|
|
|
answer.setIsRight(String.valueOf(map.get("答案")).contains(answer.getContent()) ? true : false);
|
|
|
+ } else if (QuestionType.BLANK.getCode().equals(question.getType())) {
|
|
|
+ answer.setIsRight(true);
|
|
|
}
|
|
|
answer.setSort(sort);
|
|
|
answerGroupList.add(answer);
|
|
@@ -345,6 +361,34 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
log.info("成功导入:{}个题目,耗时:{}", dataList.size(), (System.currentTimeMillis() - beginTime) / 1000 + "秒");
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 导入的填空题重新设置内容
|
|
|
+ *
|
|
|
+ * @param s
|
|
|
+ */
|
|
|
+ public String replaceBlankContent(String s) {
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ int index = 1;
|
|
|
+ int preIndex = 0;
|
|
|
+ for (int i = 0; i < s.length(); i++) {
|
|
|
+ if (s.charAt(i) == '(') {//若为左括号,则向右寻找右括号的位置
|
|
|
+ int j = i;
|
|
|
+ while (s.charAt(j) != ')') {
|
|
|
+ j++;
|
|
|
+ }
|
|
|
+ sb.append(s, preIndex, i).append("<span contenteditable=\"false\" class=\"xe-blanknumber\" " +
|
|
|
+ "data-name=\"blanknumber\" data-content=\"{"content":"" + index + ""}\">" + index + "</span>");
|
|
|
+ i = j;
|
|
|
+ preIndex = j + 1;
|
|
|
+ index++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (preIndex > 0 && s.length() > preIndex) {
|
|
|
+ sb.append(s.substring(preIndex));
|
|
|
+ }
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 新建题库
|
|
|
*
|