|
@@ -3,7 +3,7 @@ package com.yaoxiang.diagnosis.service;
|
|
|
import com.yaoxiang.diagnosis.config.Constants;
|
|
|
import com.yaoxiang.diagnosis.entity.Issue;
|
|
|
import com.yaoxiang.diagnosis.entity.IssueOption;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
+import com.yaoxiang.diagnosis.word.WordUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
|
|
import org.slf4j.Logger;
|
|
@@ -12,6 +12,7 @@ import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.Assert;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.regex.Matcher;
|
|
@@ -27,8 +28,8 @@ public class IssueParseWordHandler extends IssueParseAdapter implements IssuePar
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Issue parse(String issueIndex, List<XWPFParagraph> list, Long subjectId, Long chapterId) {
|
|
|
- Issue issue = init(subjectId, chapterId, getSection());
|
|
|
+ public Issue parse(String issueIndex, List<XWPFParagraph> list, Long subjectId, String grade, Long chapterId) {
|
|
|
+ Issue issue = init(subjectId, grade,chapterId, getSection());
|
|
|
Map<String, List<XWPFParagraph>> group = initGroup(list, TOPIC1);
|
|
|
|
|
|
Matcher matcher = issuePattern.matcher(issueIndex);
|
|
@@ -51,21 +52,44 @@ public class IssueParseWordHandler extends IssueParseAdapter implements IssuePar
|
|
|
int i = 0;
|
|
|
StringBuilder content = new StringBuilder();
|
|
|
boolean hasFormula = false;
|
|
|
+ String index = "";
|
|
|
+ Map<String, List<XWPFParagraph>> indexMap = new LinkedHashMap<>();
|
|
|
+ boolean isQuestion = true;
|
|
|
for (XWPFParagraph p : ps) {
|
|
|
|
|
|
String text = p.getText();
|
|
|
+ if (WordUtil.notContent(p, text)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
text = text.replaceAll(PICTURE_PATTERN, "");
|
|
|
if (text.matches(OPTION_PATTERN)) {
|
|
|
-
|
|
|
- IssueOption option = initOption(i++,issue.getSection(), text);
|
|
|
- String optionNoContent = String.format("parseQuestion,题号为%s的题目选项 %s 未检测到内容,题目内容为“%s”,请检查选项结构", code, text, content);
|
|
|
- Assert.hasText(option.getContent(), optionNoContent);
|
|
|
- options.add(option);
|
|
|
- } else {
|
|
|
+ isQuestion = false;
|
|
|
+ index = text;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isQuestion) {
|
|
|
content.append("<p>").append(text).append("</p>");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<XWPFParagraph> list = indexMap.getOrDefault(index, new ArrayList<>());
|
|
|
+ list.add(p);
|
|
|
+ indexMap.put(index, list);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Map.Entry<String, List<XWPFParagraph>> entry : indexMap.entrySet()) {
|
|
|
+ StringBuilder builder = new StringBuilder();
|
|
|
+ for (XWPFParagraph p : entry.getValue()) {
|
|
|
+ builder.append("<p>").append(p.getText()).append("</p>");
|
|
|
}
|
|
|
+ String text = builder.toString();
|
|
|
+ IssueOption option = initOption(i++, issue.getSection(), text);
|
|
|
+ String optionNoContent = String.format("parseQuestion,题号为%s的题目选项 %s 未检测到内容,题目内容为“%s”,请检查选项结构", code, text, content);
|
|
|
+ Assert.hasText(option.getContent(), optionNoContent);
|
|
|
+ options.add(option);
|
|
|
}
|
|
|
+
|
|
|
String noContent = String.format("parseQuestion,题号为 %s 的题目未检测到题干,题目内容为 “%s” ,请检查", code, content);
|
|
|
String noOptions = String.format("parseQuestion,题号为 %s 的题目未检测到选项,题目内容为 “%s” ,请检查", code, content);
|
|
|
String lostOptions = String.format("parseQuestion,题号为 %s 的题目检测到选项数量为 %s ,题目内容为 “%s” ,请检查选项换行情况", code, options.size(), content);
|