|
@@ -0,0 +1,175 @@
|
|
|
+package cn.com.qmth.scancloud.tools.service.impl;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+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 cn.com.qmth.scancloud.tools.config.SysProperty;
|
|
|
+import cn.com.qmth.scancloud.tools.enums.TaskType;
|
|
|
+import cn.com.qmth.scancloud.tools.model.CetMarking;
|
|
|
+import cn.com.qmth.scancloud.tools.model.ExportCetMarkingVo;
|
|
|
+import cn.com.qmth.scancloud.tools.service.AbstractTask;
|
|
|
+import cn.com.qmth.scancloud.tools.utils.FileHelper;
|
|
|
+import cn.com.qmth.scancloud.tools.utils.HttpHelper;
|
|
|
+import cn.com.qmth.scancloud.tools.utils.JsonHelper;
|
|
|
+import cn.com.qmth.scancloud.tools.utils.StatusException;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 考生打包文件导出
|
|
|
+ */
|
|
|
+public class SliceDataExportTask extends AbstractTask {
|
|
|
+
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(SliceDataExportTask.class);
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected String getTaskName() {
|
|
|
+ return TaskType.SLICE_DATA_EXPORT.getTitle();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void execute() {
|
|
|
+ Long examId = SysProperty.EXAM_ID;
|
|
|
+ if (examId == null) {
|
|
|
+ throw new StatusException("【scan.tool.examId】未配置!");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询参数:{"examId":null,"subjectCode":"","examNumber":"","name":"","studentCode":"","packageCode":"",
|
|
|
+ // "seatNumber":"","campusName":"","examSite":"","examRoom":""}
|
|
|
+ Map<String, Object> params = JsonHelper.toMap(SysProperty.MORE_PARAMS, Object.class);
|
|
|
+ if (params == null) {
|
|
|
+ params = new HashMap<>();
|
|
|
+ }
|
|
|
+ params.put("examId", examId);
|
|
|
+
|
|
|
+ String url = SysProperty.SCAN_SERVER_URL + "/api/tool/exam/student/count";
|
|
|
+ String json = JsonHelper.toJson(params);
|
|
|
+ String result = HttpHelper.post(url, json);
|
|
|
+ log.info("查询考生参数:{},结果:{}", json, result);
|
|
|
+
|
|
|
+ int total = 0;
|
|
|
+ JsonNode props = JsonHelper.getNode(result);
|
|
|
+ if (props != null && props.has("count")) {
|
|
|
+ total = props.get("count").asInt();
|
|
|
+ }
|
|
|
+ if (total == 0) {
|
|
|
+ log.warn("未查询到相关考生!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<String, CetMarking> cms = readCetMarking();
|
|
|
+ // 分批处理
|
|
|
+ String filePath = String.format("%s/export-slice-data.txt", SysProperty.DATA_DIR);
|
|
|
+ String queryUrl = SysProperty.SCAN_SERVER_URL + "/api/tool/export/cet/marking";
|
|
|
+ params.put("pageSize", 100);
|
|
|
+ int pageNumber = 0;
|
|
|
+ int sum = 0;
|
|
|
+
|
|
|
+ while (true) {
|
|
|
+ params.put("pageNumber", ++pageNumber);
|
|
|
+ String queryJson = JsonHelper.toJson(params);
|
|
|
+ String queryResult = HttpHelper.post(queryUrl, queryJson);
|
|
|
+
|
|
|
+ List<ExportCetMarkingVo> list = JsonHelper.toList(queryResult, ExportCetMarkingVo.class);
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.export(list, filePath, cms);
|
|
|
+
|
|
|
+ sum += list.size();
|
|
|
+ float rate = sum * 100f / total;
|
|
|
+ log.info("已处理数:{} 进度:{}%", sum, rate);
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("导出文件:" + filePath);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void export(List<ExportCetMarkingVo> list, String filePath, Map<String, CetMarking> cms) {
|
|
|
+ String template = "%s,%s,%s";
|
|
|
+
|
|
|
+ List<String> lines = new ArrayList<>();
|
|
|
+ for (ExportCetMarkingVo data : list) {
|
|
|
+ int subjectCode = Integer.valueOf(data.getExamNumber().substring(9, 10));
|
|
|
+ String markingCode;
|
|
|
+ if (subjectCode >= 3 && subjectCode <= 9) {
|
|
|
+ markingCode = "88";
|
|
|
+ }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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ lines.add(String.format(template, data.getExamNumber(), markingCode,
|
|
|
+ StringUtils.join(data.getSliceImageInfo(), ";")));
|
|
|
+ }
|
|
|
+
|
|
|
+ File file = new File(filePath);
|
|
|
+ if (file.exists()) {
|
|
|
+ file.delete();
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ if (!file.exists()) {
|
|
|
+ throw new StatusException("文件不存在:" + SysProperty.MARKING_PLACE);
|
|
|
+ }
|
|
|
+ List<CetMarking> list = new ArrayList<CetMarking>();
|
|
|
+ XSSFWorkbook wb = 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) + "行,条形码值、奇数考场评卷点代码、偶数考场评卷点代码都不能为空");
|
|
|
+ }
|
|
|
+ cm.setPaperType(row.getCell(3).getStringCellValue());
|
|
|
+ cm.setOddNumber(row.getCell(5).getStringCellValue());
|
|
|
+ cm.setEvenNumber(row.getCell(7).getStringCellValue());
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("系统错误", e);
|
|
|
+ throw new StatusException("系统错误");
|
|
|
+ } finally {
|
|
|
+ if (wb != null) {
|
|
|
+ try {
|
|
|
+ wb.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;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|