|
@@ -14,6 +14,7 @@ import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -77,20 +78,14 @@ public class ObjectiveQuestionExportTask extends AbstractTask {
|
|
|
}
|
|
|
Map<String, CetMarking> cms = readCetMarking();
|
|
|
// 分批处理
|
|
|
- String filePath = String.format("%s/export-slice-data.txt", SysProperty.DATA_DIR);
|
|
|
- String answerFilePath = String.format("%s/export-answer-data.txt", SysProperty.DATA_DIR);
|
|
|
String queryUrl = SysProperty.SCAN_SERVER_URL + "/api/tool/export/cet/data";
|
|
|
- File file = new File(filePath);
|
|
|
- if (file.exists()) {
|
|
|
- file.delete();
|
|
|
- }
|
|
|
- File sliceFile = new File(filePath);
|
|
|
- if (sliceFile.exists()) {
|
|
|
- sliceFile.delete();
|
|
|
- }
|
|
|
- File answerFile = new File(answerFilePath);
|
|
|
- if (answerFile.exists()) {
|
|
|
- answerFile.delete();
|
|
|
+ File rootDir = new File(SysProperty.DATA_DIR + "/export_data/");
|
|
|
+ if (rootDir.exists()) {
|
|
|
+ try {
|
|
|
+ FileUtils.deleteDirectory(rootDir);
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new StatusException("", e);
|
|
|
+ }
|
|
|
}
|
|
|
params.put("pageSize", 100000);
|
|
|
int pageNumber = 0;
|
|
@@ -106,18 +101,18 @@ public class ObjectiveQuestionExportTask extends AbstractTask {
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- exportMarking(list, sliceFile, cms, examNumbers);
|
|
|
- exportAnswer(list, answerFile, cms);
|
|
|
+ exportMarking(list, cms, examNumbers);
|
|
|
+ exportAnswer(list, cms);
|
|
|
sum += list.size();
|
|
|
float rate = sum * 100f / total;
|
|
|
log.info("已处理数:{} 进度:{}%", sum, rate);
|
|
|
}
|
|
|
|
|
|
- log.info("导出文件:" + filePath);
|
|
|
+ log.info("导出文件:" + rootDir.getAbsolutePath());
|
|
|
}
|
|
|
|
|
|
- private void exportAnswer(List<ExportCetVo> list, File file, Map<String, CetMarking> cms) {
|
|
|
- List<String> lines = new ArrayList<>();
|
|
|
+ private void exportAnswer(List<ExportCetVo> list, Map<String, CetMarking> cms) {
|
|
|
+ Map<String, List<String>> subjects = new HashMap<>();
|
|
|
for (ExportCetVo data : list) {
|
|
|
List<String> line = new ArrayList<>();
|
|
|
line.add(data.getExamNumber());
|
|
@@ -155,18 +150,20 @@ public class ObjectiveQuestionExportTask extends AbstractTask {
|
|
|
}
|
|
|
}
|
|
|
line.add(markingCode);
|
|
|
+ List<String> lines = subjects.get(data.getSubjectCode());
|
|
|
+ if (lines == null) {
|
|
|
+ lines = new ArrayList<>();
|
|
|
+ subjects.put(data.getSubjectCode(), lines);
|
|
|
+ }
|
|
|
lines.add(StringUtils.join(line, ","));
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- FileHelper.writeLines(file, lines, true);
|
|
|
+ writeResult(subjects, "answer-data.txt");
|
|
|
}
|
|
|
|
|
|
- private void exportMarking(List<ExportCetVo> list, File file, Map<String, CetMarking> cms,
|
|
|
+ private void exportMarking(List<ExportCetVo> list, Map<String, CetMarking> cms,
|
|
|
Set<String> examNumbers) {
|
|
|
+ Map<String, List<String>> subjects = new HashMap<>();
|
|
|
String template = "%s,%s,%s";
|
|
|
-
|
|
|
- List<String> lines = new ArrayList<>();
|
|
|
for (ExportCetVo data : list) {
|
|
|
if (examNumbers.contains(data.getExamNumber())) {
|
|
|
log.warn("有重复数据,准考证号:{}", data.getExamNumber());
|
|
@@ -182,20 +179,37 @@ public class ObjectiveQuestionExportTask extends AbstractTask {
|
|
|
} else {
|
|
|
int site = Integer.valueOf(data.getExamNumber().substring(10, 13));
|
|
|
if (site % 2 == 0) {
|
|
|
- try {
|
|
|
- markingCode = cms.get(data.getPaperType()).getEvenNumber();
|
|
|
- } catch (Exception e) {
|
|
|
- throw e;
|
|
|
- }
|
|
|
+ markingCode = cms.get(data.getPaperType()).getEvenNumber();
|
|
|
} else {
|
|
|
markingCode = cms.get(data.getPaperType()).getOddNumber();
|
|
|
}
|
|
|
}
|
|
|
+ List<String> lines = subjects.get(data.getSubjectCode());
|
|
|
+ if (lines == null) {
|
|
|
+ lines = new ArrayList<>();
|
|
|
+ subjects.put(data.getSubjectCode(), lines);
|
|
|
+ }
|
|
|
lines.add(String.format(template, data.getExamNumber(), markingCode,
|
|
|
StringUtils.join(data.getSliceImageInfo(), ";")));
|
|
|
}
|
|
|
|
|
|
- FileHelper.writeLines(file, lines, true);
|
|
|
+ writeResult(subjects, "slice-data.txt");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void writeResult(Map<String, List<String>> subjects, String fileName) {
|
|
|
+ String rootPath = SysProperty.DATA_DIR + "/export_data/";
|
|
|
+ for (String k : subjects.keySet()) {
|
|
|
+ File file = new File(rootPath + k + "/" + fileName);
|
|
|
+ file.getParentFile().mkdirs();
|
|
|
+ if (!file.exists()) {
|
|
|
+ try {
|
|
|
+ file.createNewFile();
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new StatusException("", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ FileHelper.writeLines(file, subjects.get(k), true);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private Map<String, CetMarking> readCetMarking() {
|