|
@@ -25,6 +25,7 @@ import org.springframework.util.Assert;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
+import java.util.concurrent.ConcurrentLinkedQueue;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -243,12 +244,13 @@ public class PaperService {
|
|
|
}
|
|
|
|
|
|
private Map<String, List<XWPFParagraph>> initSections(Paper paper, String sectionPattern, String questionPattern, List<XWPFParagraph> paragraphs) {
|
|
|
- Map<String, List<XWPFParagraph>> sections = new ConcurrentHashMap<>();
|
|
|
+ //保证顺序
|
|
|
+ Map<String, List<XWPFParagraph>> sections = new LinkedHashMap<>();
|
|
|
String tag = "";
|
|
|
boolean betweenSectionAndQuestion = false;
|
|
|
StringBuilder material = new StringBuilder();
|
|
|
int section = 0;
|
|
|
- List<Section> ss = new ArrayList<>();
|
|
|
+ List<Section> sectionList = new ArrayList<>();
|
|
|
logger.info("initSections start");
|
|
|
boolean hasFormula = false;
|
|
|
for (XWPFParagraph paragraph : paragraphs) {
|
|
@@ -272,7 +274,7 @@ public class PaperService {
|
|
|
}
|
|
|
if (betweenSectionAndQuestion && text.matches(questionPattern)) {
|
|
|
Section s = initSection(section, material.toString());
|
|
|
- ss.add(s);
|
|
|
+ sectionList.add(s);
|
|
|
//清空背景材料
|
|
|
material = new StringBuilder();
|
|
|
betweenSectionAndQuestion = false;
|
|
@@ -291,8 +293,8 @@ public class PaperService {
|
|
|
sections.put(tag, list);
|
|
|
}
|
|
|
}
|
|
|
- paper.setSections(ss);
|
|
|
- logger.info("initSections end,sections num is {}", ss.size());
|
|
|
+ paper.setSections(sectionList);
|
|
|
+ logger.info("initSections end,sections num is {}", sectionList.size());
|
|
|
return sections;
|
|
|
}
|
|
|
|
|
@@ -314,17 +316,23 @@ public class PaperService {
|
|
|
// sections.values().parallelStream().forEach(ps -> {
|
|
|
// initQuestions(paper, questionPattern, ps);
|
|
|
// });
|
|
|
- Map<String, List<Question>> qs = new HashMap<>();
|
|
|
+ Map<String, List<Question>> qs = new LinkedHashMap<>();
|
|
|
List<String> abilities = subjectAbilityService.list(paper.getSubjectId())
|
|
|
.stream().map(SubjectAbility::getCode).collect(Collectors.toList());
|
|
|
- sections.keySet().forEach(s -> {
|
|
|
+ int currentNumber = 0;
|
|
|
+ //此处section应该是顺序的
|
|
|
+ for (String s : sections.keySet()) {
|
|
|
List<XWPFParagraph> ps = sections.get(s);
|
|
|
// Section current = ss.stream().filter(section -> s.contains(section.getNumber().toString())).findFirst().orElse(null);
|
|
|
Section current = sectionMap.get(s);
|
|
|
Map<String, List<XWPFParagraph>> questions = initQuestions(current, questionPattern, ps);
|
|
|
+ current.setStartNumber(currentNumber);
|
|
|
List<Question> list = parseQuestions(questions, current, template, topic, abilities);
|
|
|
+ current.setNums(list.size());
|
|
|
+ currentNumber = currentNumber + list.size();
|
|
|
qs.put(s, list);
|
|
|
- });
|
|
|
+ }
|
|
|
+ ;
|
|
|
List<Question> list = new ArrayList<>();
|
|
|
qs.values().forEach(list::addAll);
|
|
|
paper.setQuestions(list);
|
|
@@ -361,8 +369,8 @@ public class PaperService {
|
|
|
questions.forEach((k, v) -> {
|
|
|
Matcher matcher = pattern.matcher(k);
|
|
|
if (k.matches(template.getQuestion()) && matcher.find()) {
|
|
|
- String number = matcher.group();
|
|
|
- Question question = questionService.initQuestion(section.getNumber(), Integer.valueOf(number));
|
|
|
+ String code= matcher.group();
|
|
|
+ Question question = questionService.initQuestion(section.getNumber(), section.getStartNumber(), Integer.valueOf(code));
|
|
|
wordService.parseQuestion(question, v, topic, template, abilities);
|
|
|
list.add(question);
|
|
|
}
|
|
@@ -401,11 +409,11 @@ public class PaperService {
|
|
|
|
|
|
private Section initSection(int number, String material) {
|
|
|
Section section = new Section();
|
|
|
- section.setStartNumber(1);
|
|
|
+ section.setStartNumber(Constants.DEFAULT_SECTION_START_NUMBER);
|
|
|
section.setNumber(number);
|
|
|
section.setMaterial(material);
|
|
|
- section.setDuration(20);
|
|
|
- section.setRest(2);
|
|
|
+ section.setDuration(Constants.DEFAULT_SECTION_DURATION);
|
|
|
+ section.setRest(Constants.DEFAULT_SECTION_REST);
|
|
|
return section;
|
|
|
}
|
|
|
|