|
@@ -1,8 +1,11 @@
|
|
|
package cn.com.qmth.scancloud.tools.service.impl;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.HashSet;
|
|
|
import java.util.List;
|
|
@@ -12,13 +15,13 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
|
-import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
+import com.qmth.boot.tools.excel.ExcelReader;
|
|
|
+import com.qmth.boot.tools.excel.enums.ExcelType;
|
|
|
+import com.qmth.boot.tools.excel.model.DataMap;
|
|
|
|
|
|
import cn.com.qmth.scancloud.tools.config.SysProperty;
|
|
|
import cn.com.qmth.scancloud.tools.enums.ExamStatus;
|
|
@@ -38,6 +41,9 @@ public class ObjectiveQuestionExportTask extends AbstractTask {
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(ObjectiveQuestionExportTask.class);
|
|
|
|
|
|
+ private static final String[] EXCEL_HEADER = new String[] { "科目名称", "科目代码", "试卷类型", "条形码值", "奇数考场评卷点", "奇数考场评卷点代码",
|
|
|
+ "偶数考场评卷点", "偶数考场评卷点代码" };
|
|
|
+
|
|
|
@Override
|
|
|
protected String getTaskName() {
|
|
|
return TaskType.OBJECTIVE_QUESTION_EXPORT.getTitle();
|
|
@@ -75,7 +81,7 @@ public class ObjectiveQuestionExportTask extends AbstractTask {
|
|
|
params.put("pageSize", 100);
|
|
|
int pageNumber = 0;
|
|
|
int sum = 0;
|
|
|
- Set<String> examNumbers=new HashSet<>();
|
|
|
+ Set<String> examNumbers = new HashSet<>();
|
|
|
while (true) {
|
|
|
params.put("pageNumber", ++pageNumber);
|
|
|
String queryJson = JsonHelper.toJson(params);
|
|
@@ -86,8 +92,8 @@ public class ObjectiveQuestionExportTask extends AbstractTask {
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- exportMarking(list, filePath, cms,examNumbers);
|
|
|
- exportAnswer(list, answerFilePath, cms,examNumbers);
|
|
|
+ exportMarking(list, filePath, cms, examNumbers);
|
|
|
+ exportAnswer(list, answerFilePath, cms, examNumbers);
|
|
|
sum += list.size();
|
|
|
float rate = sum * 100f / total;
|
|
|
log.info("已处理数:{} 进度:{}%", sum, rate);
|
|
@@ -95,11 +101,12 @@ public class ObjectiveQuestionExportTask extends AbstractTask {
|
|
|
|
|
|
log.info("导出文件:" + filePath);
|
|
|
}
|
|
|
-
|
|
|
- private void exportAnswer(List<ExportCetVo> list, String filePath, Map<String, CetMarking> cms,Set<String> examNumbers) {
|
|
|
+
|
|
|
+ private void exportAnswer(List<ExportCetVo> list, String filePath, Map<String, CetMarking> cms,
|
|
|
+ Set<String> examNumbers) {
|
|
|
List<String> lines = new ArrayList<>();
|
|
|
for (ExportCetVo data : list) {
|
|
|
- if(examNumbers.contains(data.getExamNumber())) {
|
|
|
+ if (examNumbers.contains(data.getExamNumber())) {
|
|
|
log.warn("有重复数据,准考证号:{}", data.getExamNumber());
|
|
|
continue;
|
|
|
}
|
|
@@ -107,27 +114,27 @@ public class ObjectiveQuestionExportTask extends AbstractTask {
|
|
|
List<String> line = new ArrayList<>();
|
|
|
line.add(data.getExamNumber());
|
|
|
line.add(data.getName());
|
|
|
- if(ExamStatus.ABSENT.equals(data.getExamStatus())) {
|
|
|
+ if (ExamStatus.ABSENT.equals(data.getExamStatus())) {
|
|
|
line.add("1");
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
line.add("0");
|
|
|
}
|
|
|
line.add(data.getSubjectCode());
|
|
|
line.add(data.getAnswer());
|
|
|
- line.add(data.getCardFirst()+"");
|
|
|
- line.add(data.getCardSecond()+"");
|
|
|
+ line.add(data.getCardFirst() + "");
|
|
|
+ line.add(data.getCardSecond() + "");
|
|
|
line.add(data.getBreachCode());
|
|
|
line.add(data.getPaperType());
|
|
|
int subjectCode = Integer.valueOf(data.getExamNumber().substring(9, 10));
|
|
|
String markingCode;
|
|
|
if (subjectCode >= 3 && subjectCode <= 9) {
|
|
|
markingCode = "88";
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
int site = Integer.valueOf(data.getExamNumber().substring(10, 13));
|
|
|
- if(site%2==0) {
|
|
|
- markingCode=cms.get(data.getPaperType()).getEvenNumber();
|
|
|
- }else {
|
|
|
- markingCode=cms.get(data.getPaperType()).getOddNumber();
|
|
|
+ if (site % 2 == 0) {
|
|
|
+ markingCode = cms.get(data.getPaperType()).getEvenNumber();
|
|
|
+ } else {
|
|
|
+ markingCode = cms.get(data.getPaperType()).getOddNumber();
|
|
|
}
|
|
|
}
|
|
|
line.add(markingCode);
|
|
@@ -141,12 +148,13 @@ public class ObjectiveQuestionExportTask extends AbstractTask {
|
|
|
FileHelper.writeLines(file, lines, true);
|
|
|
}
|
|
|
|
|
|
- private void exportMarking(List<ExportCetVo> list, String filePath, Map<String, CetMarking> cms,Set<String> examNumbers) {
|
|
|
+ private void exportMarking(List<ExportCetVo> list, String filePath, Map<String, CetMarking> cms,
|
|
|
+ Set<String> examNumbers) {
|
|
|
String template = "%s,%s,%s";
|
|
|
|
|
|
List<String> lines = new ArrayList<>();
|
|
|
for (ExportCetVo data : list) {
|
|
|
- if(examNumbers.contains(data.getExamNumber())) {
|
|
|
+ if (examNumbers.contains(data.getExamNumber())) {
|
|
|
continue;
|
|
|
}
|
|
|
examNumbers.add(data.getExamNumber());
|
|
@@ -154,12 +162,12 @@ public class ObjectiveQuestionExportTask extends AbstractTask {
|
|
|
String markingCode;
|
|
|
if (subjectCode >= 3 && subjectCode <= 9) {
|
|
|
markingCode = "88";
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
int site = Integer.valueOf(data.getExamNumber().substring(10, 13));
|
|
|
- if(site%2==0) {
|
|
|
- markingCode=cms.get(data.getPaperType()).getEvenNumber();
|
|
|
- }else {
|
|
|
- markingCode=cms.get(data.getPaperType()).getOddNumber();
|
|
|
+ if (site % 2 == 0) {
|
|
|
+ markingCode = cms.get(data.getPaperType()).getEvenNumber();
|
|
|
+ } else {
|
|
|
+ markingCode = cms.get(data.getPaperType()).getOddNumber();
|
|
|
}
|
|
|
}
|
|
|
lines.add(String.format(template, data.getExamNumber(), markingCode,
|
|
@@ -173,51 +181,77 @@ public class ObjectiveQuestionExportTask extends AbstractTask {
|
|
|
FileHelper.writeLines(file, lines, true);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private Map<String, CetMarking> readCetMarking() {
|
|
|
if (StringUtils.isBlank(SysProperty.MARKING_PLACE)) {
|
|
|
throw new StatusException("【scan.tool.marking-place】未配置!");
|
|
|
}
|
|
|
- File file = new File(SysProperty.MARKING_PLACE);
|
|
|
+ File file = new File(SysProperty.DATA_DIR + "/" + SysProperty.MARKING_PLACE);
|
|
|
if (!file.exists()) {
|
|
|
throw new StatusException("文件不存在:" + SysProperty.MARKING_PLACE);
|
|
|
}
|
|
|
List<CetMarking> list = new ArrayList<CetMarking>();
|
|
|
- XSSFWorkbook wb = null;
|
|
|
+ InputStream inputStream = null;
|
|
|
try {
|
|
|
- wb = new XSSFWorkbook(SysProperty.MARKING_PLACE);
|
|
|
- XSSFSheet sheet = wb.getSheetAt(0);
|
|
|
- int rows = sheet.getLastRowNum();
|
|
|
- for (int i = 1; i <= rows; i++) {
|
|
|
- CetMarking cm = new CetMarking();
|
|
|
- list.add(cm);
|
|
|
- XSSFRow row = sheet.getRow(i);
|
|
|
- if (StringUtils.isBlank(row.getCell(3).getStringCellValue())
|
|
|
- || StringUtils.isBlank(row.getCell(5).getStringCellValue())
|
|
|
- || StringUtils.isBlank(row.getCell(6).getStringCellValue())) {
|
|
|
- throw new StatusException("评卷点文件中第" + (i + 1) + "行,条形码值、奇数考场评卷点代码、偶数考场评卷点代码都不能为空");
|
|
|
+ inputStream = new FileInputStream(file);
|
|
|
+ ExcelReader reader = ExcelReader.create(ExcelType.XLSX, inputStream, 0);
|
|
|
+ List<DataMap> lineList = reader.getDataMapList();
|
|
|
+ if (!Arrays.equals(EXCEL_HEADER, reader.getColumnNames())) {
|
|
|
+ throw new StatusException(SysProperty.MARKING_PLACE + "表头错误");
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isEmpty(lineList)) {
|
|
|
+ throw new StatusException(SysProperty.MARKING_PLACE + "无内容");
|
|
|
+ }
|
|
|
+ for (int i = 0; i < lineList.size(); i++) {
|
|
|
+ DataMap line = lineList.get(i);
|
|
|
+
|
|
|
+ CetMarking imp = new CetMarking();
|
|
|
+ String paperType = trimAndNullIfBlank(line.getValue(3));
|
|
|
+ if (StringUtils.isBlank(paperType)) {
|
|
|
+ throw new StatusException(newError(i + 1, "条形码值不能为空"));
|
|
|
+ }
|
|
|
+ imp.setPaperType(paperType);
|
|
|
+
|
|
|
+ String oddNumber = trimAndNullIfBlank(line.getValue(5));
|
|
|
+ if (StringUtils.isBlank(oddNumber)) {
|
|
|
+ throw new StatusException(newError(i + 1, "奇数考场评卷点代码不能为空"));
|
|
|
}
|
|
|
- cm.setPaperType(row.getCell(3).getStringCellValue());
|
|
|
- cm.setOddNumber(row.getCell(5).getStringCellValue());
|
|
|
- cm.setEvenNumber(row.getCell(7).getStringCellValue());
|
|
|
+ imp.setOddNumber(oddNumber);
|
|
|
+
|
|
|
+ String evenNumber = trimAndNullIfBlank(line.getValue(7));
|
|
|
+ if (StringUtils.isBlank(evenNumber)) {
|
|
|
+ throw new StatusException(newError(i + 1, "偶数考场评卷点代码不能为空"));
|
|
|
+ }
|
|
|
+ imp.setEvenNumber(evenNumber);
|
|
|
+
|
|
|
}
|
|
|
- } catch (IOException e) {
|
|
|
- log.error("系统错误", e);
|
|
|
- throw new StatusException("系统错误");
|
|
|
+ if (list.size() == 0) {
|
|
|
+ throw new StatusException("文件内容为空:" + SysProperty.MARKING_PLACE);
|
|
|
+ }
|
|
|
+ Map<String, CetMarking> map = list.stream()
|
|
|
+ .collect(Collectors.toMap(CetMarking::getPaperType, c -> c, (key1, key2) -> key2));
|
|
|
+
|
|
|
+ return map;
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("系统错误", e);
|
|
|
} finally {
|
|
|
- if (wb != null) {
|
|
|
+ if (inputStream != null) {
|
|
|
try {
|
|
|
- wb.close();
|
|
|
+ inputStream.close();
|
|
|
} catch (IOException e) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if (list.size() == 0) {
|
|
|
- throw new StatusException("文件内容为空:" + SysProperty.MARKING_PLACE);
|
|
|
- }
|
|
|
- Map<String, CetMarking> map = list.stream()
|
|
|
- .collect(Collectors.toMap(CetMarking::getPaperType, c -> c, (key1, key2) -> key2));
|
|
|
+ }
|
|
|
|
|
|
- return map;
|
|
|
+ private String trimAndNullIfBlank(String s) {
|
|
|
+ if (StringUtils.isBlank(s)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return s.trim();
|
|
|
}
|
|
|
|
|
|
+ private String newError(int lineNum, String msg) {
|
|
|
+ return SysProperty.MARKING_PLACE + "第" + lineNum + "行" + msg;
|
|
|
+ }
|
|
|
}
|