|
@@ -1,30 +1,16 @@
|
|
|
package cn.com.qmth.examcloud.task.service.job;
|
|
|
|
|
|
-import java.io.File;
|
|
|
-import java.io.IOException;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Locale;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
-
|
|
|
-import org.apache.commons.collections.CollectionUtils;
|
|
|
-import org.apache.commons.io.FileUtils;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.apache.commons.lang3.math.NumberUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-
|
|
|
-import com.google.common.collect.Lists;
|
|
|
-import com.google.common.collect.Maps;
|
|
|
-import com.google.common.collect.Sets;
|
|
|
-
|
|
|
+import cn.com.qmth.examcloud.api.commons.enums.ExamSpecialSettingsType;
|
|
|
import cn.com.qmth.examcloud.commons.helpers.poi.ExcelReader;
|
|
|
import cn.com.qmth.examcloud.commons.util.BooleanUtil;
|
|
|
import cn.com.qmth.examcloud.commons.util.DateUtil;
|
|
|
import cn.com.qmth.examcloud.commons.util.PathUtil;
|
|
|
+import cn.com.qmth.examcloud.examwork.api.ExamStageCloudService;
|
|
|
+import cn.com.qmth.examcloud.examwork.api.bean.ExamStageBean;
|
|
|
+import cn.com.qmth.examcloud.examwork.api.request.GetExamStageReq;
|
|
|
+import cn.com.qmth.examcloud.examwork.api.response.GetExamStageResp;
|
|
|
+import cn.com.qmth.examcloud.support.cache.CacheHelper;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.ExamSettingsCacheBean;
|
|
|
import cn.com.qmth.examcloud.task.dao.ExamStudentImportRepo;
|
|
|
import cn.com.qmth.examcloud.task.dao.ExamStudentTempRepo;
|
|
|
import cn.com.qmth.examcloud.task.dao.entity.ExamStudentImportEntity;
|
|
@@ -34,6 +20,19 @@ import cn.com.qmth.examcloud.web.config.SystemProperties;
|
|
|
import cn.com.qmth.examcloud.web.task.AbstractTask;
|
|
|
import cn.com.qmth.examcloud.web.task.ScheduleJob;
|
|
|
import cn.com.qmth.examcloud.web.task.TaskTracker;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.google.common.collect.Maps;
|
|
|
+import com.google.common.collect.Sets;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.commons.lang3.math.NumberUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* 考生导入-文件解析
|
|
@@ -45,329 +44,374 @@ import cn.com.qmth.examcloud.web.task.TaskTracker;
|
|
|
@Component("examStudentImportParsingFileTask")
|
|
|
public class ExamStudentImportParsingFileTask extends AbstractTask {
|
|
|
|
|
|
- @Autowired
|
|
|
- SystemProperties systemConfig;
|
|
|
-
|
|
|
- private static final String EXAM_STUDENT_IMPORT_FILES = "exam_student_import_files";
|
|
|
-
|
|
|
- private static final String[] EXCEL_HEADER = new String[]{"姓名", "学号", "身份证号", "学习中心代码",
|
|
|
- "学习中心名称", "课程代码", "课程名称", "试卷类型", "专业", "考点", "信息采集人", "学生电话", "年级", "试卷袋编码", "考试开始时间",
|
|
|
- "考试结束时间"};
|
|
|
-
|
|
|
- @Autowired
|
|
|
- TaskTracker taskTracker;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- ExamStudentImportRepo examStudentImportRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- ExamStudentTempRepo examStudentTempRepo;
|
|
|
-
|
|
|
- @Override
|
|
|
- public void run(ScheduleJob scheduleJob) throws Exception {
|
|
|
-
|
|
|
- ExamStudentImportEntity importEntity = examStudentImportRepo
|
|
|
- .findFirstByStatusOrderByCreationTime(ExamStudentImportStatus.FILE_PARSING);
|
|
|
-
|
|
|
- if (null == importEntity) {
|
|
|
- importEntity = examStudentImportRepo
|
|
|
- .findFirstByStatusOrderByCreationTime(ExamStudentImportStatus.NONE);
|
|
|
- }
|
|
|
-
|
|
|
- if (null == importEntity) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- importEntity.setStatus(ExamStudentImportStatus.FILE_PARSING);
|
|
|
- examStudentImportRepo.saveAndFlush(importEntity);
|
|
|
-
|
|
|
- try {
|
|
|
- importExcel(importEntity);
|
|
|
- } catch (Exception e) {
|
|
|
- debugLog.error("文件解析异常", e);
|
|
|
- importEntity.setStatus(ExamStudentImportStatus.ERROR);
|
|
|
- importEntity.setErrorDesc("文件解析异常");
|
|
|
- examStudentImportRepo.saveAndFlush(importEntity);
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 方法注释
|
|
|
- *
|
|
|
- * @author WANGWEI
|
|
|
- * @param importEntity
|
|
|
- */
|
|
|
- private void importExcel(ExamStudentImportEntity importEntity) {
|
|
|
- String destFilePath = PathUtil.getCanonicalPath(systemConfig.getDataDir() + "/"
|
|
|
- + EXAM_STUDENT_IMPORT_FILES + "/" + importEntity.getFilePath());
|
|
|
- String resultFilePath = PathUtil.getCanonicalPath(systemConfig.getDataDir() + "/"
|
|
|
- + EXAM_STUDENT_IMPORT_FILES + "/" + importEntity.getResultFilePath());
|
|
|
-
|
|
|
- File file = new File(destFilePath);
|
|
|
-
|
|
|
- if (!file.exists()) {
|
|
|
- importEntity.setStatus(ExamStudentImportStatus.ERROR);
|
|
|
- importEntity.setErrorDesc("文件不存在");
|
|
|
- examStudentImportRepo.saveAndFlush(importEntity);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- List<String[]> lineList = ExcelReader.readSheetBySax(PathUtil.getCanonicalPath(file), 1,
|
|
|
- 16);
|
|
|
-
|
|
|
- if (CollectionUtils.isEmpty(lineList)) {
|
|
|
- importEntity.setStatus(ExamStudentImportStatus.ERROR);
|
|
|
- importEntity.setErrorDesc("Excel 没有内容");
|
|
|
- examStudentImportRepo.saveAndFlush(importEntity);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- Long batchId = importEntity.getBatchId();
|
|
|
- Long rootOrgId = importEntity.getRootOrgId();
|
|
|
- Long examId = importEntity.getExamId();
|
|
|
- List<ExamStudentTempEntity> list = Lists.newArrayList();
|
|
|
-
|
|
|
- Set<String> fullSet = Sets.newHashSet();
|
|
|
-
|
|
|
- List<Map<String, Object>> failRecords = Collections
|
|
|
- .synchronizedList(new ArrayList<Map<String, Object>>());
|
|
|
-
|
|
|
- StringBuilder sb = new StringBuilder();
|
|
|
- sb.append("====================重复数据\n");
|
|
|
- for (int i = 0; i < lineList.size(); i++) {
|
|
|
- String[] line = lineList.get(i);
|
|
|
- if (0 == i) {
|
|
|
- if (headerError(line)) {
|
|
|
- importEntity.setStatus(ExamStudentImportStatus.ERROR);
|
|
|
- importEntity.setErrorDesc("EXCEL表头错误");
|
|
|
- examStudentImportRepo.saveAndFlush(importEntity);
|
|
|
- return;
|
|
|
- }
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- ExamStudentTempEntity es = new ExamStudentTempEntity();
|
|
|
- es.setLineNum((long) 1 + i);
|
|
|
- es.setRootOrgId(rootOrgId);
|
|
|
- es.setExamId(examId);
|
|
|
- es.setBatchId(batchId);
|
|
|
- es.setName(trimAndNullIfBlank(line[0]));
|
|
|
- es.setStudentCode(trimAndNullIfBlank(line[1]));
|
|
|
- String identityNumber = trimAndNullIfBlank(line[2]);
|
|
|
- if (StringUtils.isNotBlank(identityNumber)) {
|
|
|
- identityNumber = identityNumber.toUpperCase(Locale.US);
|
|
|
- }
|
|
|
- es.setIdentityNumber(identityNumber);
|
|
|
- es.setOrgCode(trimAndNullIfBlank(line[3]));
|
|
|
- es.setOrgName(trimAndNullIfBlank(line[4]));
|
|
|
- es.setCourseCode(trimAndNullIfBlank(line[5]));
|
|
|
- es.setCourseName(trimAndNullIfBlank(line[6]));
|
|
|
- es.setPaperType(trimAndNullIfBlank(line[7]));
|
|
|
- es.setSpecialtyName(trimAndNullIfBlank(line[8]));
|
|
|
- es.setExamSite(trimAndNullIfBlank(line[9]));
|
|
|
- es.setInfoCollector(trimAndNullIfBlank(line[10]));
|
|
|
- es.setPhone(trimAndNullIfBlank(line[11]));
|
|
|
- es.setGrade(trimAndNullIfBlank(line[12]));
|
|
|
-
|
|
|
- es.setExt1(trimAndNullIfBlank(line[13]));
|
|
|
-
|
|
|
- String d1 = trimAndNullIfBlank(line[14]);
|
|
|
- String d2 = trimAndNullIfBlank(line[15]);
|
|
|
-
|
|
|
- if (!new Boolean(null == d1).equals(new Boolean(null == d2))) {
|
|
|
- failRecords.add(buildFailRecord(es.getLineNum(), "考试时间不匹配"));
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- int trueNum = BooleanUtil.countTrue(null != d1, null != d2);
|
|
|
- if (2 == trueNum) {
|
|
|
- Date specialBeginTime = null;
|
|
|
- Date specialEndTime = null;
|
|
|
- try {
|
|
|
- if (NumberUtils.isCreatable(d1)) {
|
|
|
- specialBeginTime = DateUtil.parseExcel(d1);
|
|
|
- } else {
|
|
|
- specialBeginTime = DateUtil.parseRandomly(d1);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- failRecords.add(buildFailRecord(es.getLineNum(), "考试开始时间格式错误"));
|
|
|
- continue;
|
|
|
- }
|
|
|
- try {
|
|
|
- if (NumberUtils.isCreatable(d2)) {
|
|
|
- specialEndTime = DateUtil.parseExcel(d2);
|
|
|
- } else {
|
|
|
- specialEndTime = DateUtil.parseRandomly(d2);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- failRecords.add(buildFailRecord(es.getLineNum(), "考试结束时间格式错误"));
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- if (specialBeginTime.after(specialEndTime)) {
|
|
|
- failRecords.add(buildFailRecord(es.getLineNum(), "考试开始时间不能大于考试结束时间"));
|
|
|
- continue;
|
|
|
- }
|
|
|
- es.setSpecialBeginTime(specialBeginTime);
|
|
|
- es.setSpecialEndTime(specialEndTime);
|
|
|
- }
|
|
|
-
|
|
|
- if (hasError(failRecords, es)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- list.add(es);
|
|
|
- String key = es.getIdentityNumber() + "____" + es.getCourseCode();
|
|
|
- if (fullSet.contains(key)) {
|
|
|
- sb.append("line ").append(es.getLineNum()).append(" 重复数据,执行更新").append("\n");
|
|
|
- } else {
|
|
|
- fullSet.add(key);
|
|
|
- }
|
|
|
- if (0 == i % 100) {
|
|
|
- examStudentTempRepo.saveAll(list);
|
|
|
-
|
|
|
- list = Lists.newArrayList();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- examStudentTempRepo.saveAll(list);
|
|
|
- sb.append("====================数据规格错误数据\n");
|
|
|
- for (Map<String, Object> cur : failRecords) {
|
|
|
- sb.append("line ").append(cur.get("lineNum")).append(cur.get("msg")).append("\n");
|
|
|
- }
|
|
|
-
|
|
|
- File resultFile = new File(resultFilePath);
|
|
|
-
|
|
|
- try {
|
|
|
- FileUtils.writeStringToFile(resultFile, sb.toString(), "UTF-8", true);
|
|
|
- } catch (IOException e) {
|
|
|
- importEntity.setStatus(ExamStudentImportStatus.ERROR);
|
|
|
- importEntity.setErrorDesc("导入报告写入失败");
|
|
|
- examStudentImportRepo.saveAndFlush(importEntity);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- importEntity.setStatus(ExamStudentImportStatus.FILE_PARSING_COMPLETE);
|
|
|
- examStudentImportRepo.saveAndFlush(importEntity);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 方法注释
|
|
|
- *
|
|
|
- * @author WANGWEI
|
|
|
- * @param failRecords
|
|
|
- * @param entity
|
|
|
- * @return
|
|
|
- */
|
|
|
- public boolean hasError(List<Map<String, Object>> failRecords, ExamStudentTempEntity entity) {
|
|
|
- boolean hasError = false;
|
|
|
- StringBuilder sb = new StringBuilder();
|
|
|
-
|
|
|
- String name = entity.getName();
|
|
|
- if (StringUtils.isBlank(name)) {
|
|
|
- sb.append(" 姓名不能为空");
|
|
|
- hasError = true;
|
|
|
- } else if (20 < name.length()) {
|
|
|
- sb.append(" 姓名不能超过20个字符");
|
|
|
- hasError = true;
|
|
|
- }
|
|
|
-
|
|
|
- String identityNumber = entity.getIdentityNumber();
|
|
|
- if (StringUtils.isBlank(identityNumber)) {
|
|
|
- sb.append(" 身份证号不能为空");
|
|
|
- hasError = true;
|
|
|
- } else if (identityNumber.length() < 6) {
|
|
|
- sb.append(" 身份证号至少为6个字符");
|
|
|
- hasError = true;
|
|
|
- } else if (identityNumber.length() > 30) {
|
|
|
- sb.append(" 身份证号不能超过30个字符");
|
|
|
- hasError = true;
|
|
|
- }
|
|
|
-
|
|
|
- String studentCode = entity.getStudentCode();
|
|
|
- if (StringUtils.isNotBlank(studentCode)) {
|
|
|
- if (studentCode.length() < 6) {
|
|
|
- sb.append(" 学号至少为6个字符");
|
|
|
- hasError = true;
|
|
|
- } else if (studentCode.length() > 30) {
|
|
|
- sb.append(" 学号不能超过30个字符");
|
|
|
- hasError = true;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- String courseCode = entity.getCourseCode();
|
|
|
- if (StringUtils.isBlank(courseCode)) {
|
|
|
- sb.append(" 课程代码不能为空");
|
|
|
- hasError = true;
|
|
|
- } else if (courseCode.length() > 30) {
|
|
|
- sb.append(" 课程代码不能超过30个字符");
|
|
|
- hasError = true;
|
|
|
- }
|
|
|
-
|
|
|
- String orgCode = entity.getOrgCode();
|
|
|
- if (StringUtils.isBlank(orgCode)) {
|
|
|
- sb.append(" 学习中心代码不能为空");
|
|
|
- hasError = true;
|
|
|
- } else if (orgCode.length() > 30) {
|
|
|
- sb.append(" 学习中心代码不能超过30个字符");
|
|
|
- hasError = true;
|
|
|
- }
|
|
|
-
|
|
|
- if (hasError) {
|
|
|
- failRecords.add(buildFailRecord(entity.getLineNum(), sb.toString()));
|
|
|
- }
|
|
|
-
|
|
|
- return hasError;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 构建错误信息
|
|
|
- *
|
|
|
- * @author WANGWEI
|
|
|
- * @param lineNum
|
|
|
- * @param msg
|
|
|
- * @return
|
|
|
- */
|
|
|
- private Map<String, Object> buildFailRecord(Long lineNum, String msg) {
|
|
|
- Map<String, Object> map = Maps.newHashMap();
|
|
|
- map.put("lineNum", lineNum);
|
|
|
- map.put("msg", msg);
|
|
|
- return map;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 方法注释
|
|
|
- *
|
|
|
- * @author WANGWEI
|
|
|
- * @param s
|
|
|
- * @return
|
|
|
- */
|
|
|
- private String trimAndNullIfBlank(String s) {
|
|
|
- if (StringUtils.isBlank(s)) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- return s.trim();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 方法注释
|
|
|
- *
|
|
|
- * @author WANGWEI
|
|
|
- * @param header
|
|
|
- */
|
|
|
- private boolean headerError(String[] header) {
|
|
|
- for (int i = 0; i < EXCEL_HEADER.length; i++) {
|
|
|
- if (null == header[i] || !EXCEL_HEADER[i].equals(header[i].trim())) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public TaskTracker getTaskTracker() {
|
|
|
- return taskTracker;
|
|
|
- }
|
|
|
+ @Autowired
|
|
|
+ SystemProperties systemConfig;
|
|
|
+
|
|
|
+ private static final String EXAM_STUDENT_IMPORT_FILES = "exam_student_import_files";
|
|
|
+
|
|
|
+ private static final String[] EXCEL_HEADER = new String[]{"姓名", "学号", "身份证号", "学习中心代码",
|
|
|
+ "学习中心名称", "课程代码", "课程名称", "试卷类型", "专业", "考点", "信息采集人", "学生电话", "年级", "试卷袋编码", "考试开始时间",
|
|
|
+ "考试结束时间", "场次"};
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ TaskTracker taskTracker;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamStudentImportRepo examStudentImportRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamStudentTempRepo examStudentTempRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamStageCloudService examStageCloudService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void run(ScheduleJob scheduleJob) throws Exception {
|
|
|
+
|
|
|
+ ExamStudentImportEntity importEntity = examStudentImportRepo
|
|
|
+ .findFirstByStatusOrderByCreationTime(ExamStudentImportStatus.FILE_PARSING);
|
|
|
+
|
|
|
+ if (null == importEntity) {
|
|
|
+ importEntity = examStudentImportRepo
|
|
|
+ .findFirstByStatusOrderByCreationTime(ExamStudentImportStatus.NONE);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (null == importEntity) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ importEntity.setStatus(ExamStudentImportStatus.FILE_PARSING);
|
|
|
+ examStudentImportRepo.saveAndFlush(importEntity);
|
|
|
+
|
|
|
+ try {
|
|
|
+ importExcel(importEntity);
|
|
|
+ } catch (Exception e) {
|
|
|
+ debugLog.error("文件解析异常", e);
|
|
|
+ importEntity.setStatus(ExamStudentImportStatus.ERROR);
|
|
|
+ importEntity.setErrorDesc("文件解析异常");
|
|
|
+ examStudentImportRepo.saveAndFlush(importEntity);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @param importEntity
|
|
|
+ * @author WANGWEI
|
|
|
+ */
|
|
|
+ private void importExcel(ExamStudentImportEntity importEntity) {
|
|
|
+ String destFilePath = PathUtil.getCanonicalPath(systemConfig.getDataDir() + "/"
|
|
|
+ + EXAM_STUDENT_IMPORT_FILES + "/" + importEntity.getFilePath());
|
|
|
+ String resultFilePath = PathUtil.getCanonicalPath(systemConfig.getDataDir() + "/"
|
|
|
+ + EXAM_STUDENT_IMPORT_FILES + "/" + importEntity.getResultFilePath());
|
|
|
+
|
|
|
+ File file = new File(destFilePath);
|
|
|
+
|
|
|
+ if (!file.exists()) {
|
|
|
+ importEntity.setStatus(ExamStudentImportStatus.ERROR);
|
|
|
+ importEntity.setErrorDesc("文件不存在");
|
|
|
+ examStudentImportRepo.saveAndFlush(importEntity);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String[]> lineList = ExcelReader.readSheetBySax(PathUtil.getCanonicalPath(file), 1,
|
|
|
+ EXCEL_HEADER.length);
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(lineList)) {
|
|
|
+ importEntity.setStatus(ExamStudentImportStatus.ERROR);
|
|
|
+ importEntity.setErrorDesc("Excel 没有内容");
|
|
|
+ examStudentImportRepo.saveAndFlush(importEntity);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Long batchId = importEntity.getBatchId();
|
|
|
+ Long rootOrgId = importEntity.getRootOrgId();
|
|
|
+ Long examId = importEntity.getExamId();
|
|
|
+ List<ExamStudentTempEntity> list = Lists.newArrayList();
|
|
|
+
|
|
|
+ Set<String> fullSet = Sets.newHashSet();
|
|
|
+
|
|
|
+ List<Map<String, Object>> failRecords = Collections
|
|
|
+ .synchronizedList(new ArrayList<Map<String, Object>>());
|
|
|
+
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ sb.append("====================重复数据\n");
|
|
|
+ for (int i = 0; i < lineList.size(); i++) {
|
|
|
+ String[] line = lineList.get(i);
|
|
|
+ if (0 == i) {
|
|
|
+ if (headerError(line)) {
|
|
|
+ importEntity.setStatus(ExamStudentImportStatus.ERROR);
|
|
|
+ importEntity.setErrorDesc("EXCEL表头错误");
|
|
|
+ examStudentImportRepo.saveAndFlush(importEntity);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ ExamStudentTempEntity es = new ExamStudentTempEntity();
|
|
|
+ es.setLineNum((long) 1 + i);
|
|
|
+ es.setRootOrgId(rootOrgId);
|
|
|
+ es.setExamId(examId);
|
|
|
+ es.setBatchId(batchId);
|
|
|
+ es.setName(trimAndNullIfBlank(line[0]));
|
|
|
+ es.setStudentCode(trimAndNullIfBlank(line[1]));
|
|
|
+ String identityNumber = trimAndNullIfBlank(line[2]);
|
|
|
+ if (StringUtils.isNotBlank(identityNumber)) {
|
|
|
+ identityNumber = identityNumber.toUpperCase(Locale.US);
|
|
|
+ }
|
|
|
+ es.setIdentityNumber(identityNumber);
|
|
|
+ es.setOrgCode(trimAndNullIfBlank(line[3]));
|
|
|
+ es.setOrgName(trimAndNullIfBlank(line[4]));
|
|
|
+ es.setCourseCode(trimAndNullIfBlank(line[5]));
|
|
|
+ es.setCourseName(trimAndNullIfBlank(line[6]));
|
|
|
+ es.setPaperType(trimAndNullIfBlank(line[7]));
|
|
|
+ es.setSpecialtyName(trimAndNullIfBlank(line[8]));
|
|
|
+ es.setExamSite(trimAndNullIfBlank(line[9]));
|
|
|
+ es.setInfoCollector(trimAndNullIfBlank(line[10]));
|
|
|
+ es.setPhone(trimAndNullIfBlank(line[11]));
|
|
|
+ es.setGrade(trimAndNullIfBlank(line[12]));
|
|
|
+
|
|
|
+ es.setExt1(trimAndNullIfBlank(line[13]));
|
|
|
+
|
|
|
+ String d1 = trimAndNullIfBlank(line[14]);
|
|
|
+ String d2 = trimAndNullIfBlank(line[15]);
|
|
|
+
|
|
|
+ if (!new Boolean(null == d1).equals(new Boolean(null == d2))) {
|
|
|
+ failRecords.add(buildFailRecord(es.getLineNum(), "考试时间不匹配"));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ int trueNum = BooleanUtil.countTrue(null != d1, null != d2);
|
|
|
+ if (2 == trueNum) {
|
|
|
+ Date specialBeginTime = null;
|
|
|
+ Date specialEndTime = null;
|
|
|
+ try {
|
|
|
+ if (NumberUtils.isCreatable(d1)) {
|
|
|
+ specialBeginTime = DateUtil.parseExcel(d1);
|
|
|
+ } else {
|
|
|
+ specialBeginTime = DateUtil.parseRandomly(d1);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ failRecords.add(buildFailRecord(es.getLineNum(), "考试开始时间格式错误"));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ if (NumberUtils.isCreatable(d2)) {
|
|
|
+ specialEndTime = DateUtil.parseExcel(d2);
|
|
|
+ } else {
|
|
|
+ specialEndTime = DateUtil.parseRandomly(d2);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ failRecords.add(buildFailRecord(es.getLineNum(), "考试结束时间格式错误"));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (specialBeginTime.after(specialEndTime)) {
|
|
|
+ failRecords.add(buildFailRecord(es.getLineNum(), "考试开始时间不能大于考试结束时间"));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ es.setSpecialBeginTime(specialBeginTime);
|
|
|
+ es.setSpecialEndTime(specialEndTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ String strExamStageOrder = trimAndNullIfBlank(line[16]);
|
|
|
+ if (StringUtils.isNotEmpty(strExamStageOrder)) {
|
|
|
+
|
|
|
+ //只有开启场次特殊设置的才会使用场次字段值
|
|
|
+ ExamSettingsCacheBean examSettings = CacheHelper.getExamSettings(examId);
|
|
|
+ if (null != examSettings.getSpecialSettingsEnabled() && examSettings.getSpecialSettingsEnabled()
|
|
|
+ && null != examSettings.getSpecialSettingsType()
|
|
|
+ && ExamSpecialSettingsType.STAGE_BASED == examSettings.getSpecialSettingsType()) {
|
|
|
+
|
|
|
+ Integer examStageOrder = null;
|
|
|
+ try {
|
|
|
+ examStageOrder = Integer.valueOf(strExamStageOrder);
|
|
|
+ } catch (Exception e) {
|
|
|
+ failRecords.add(buildFailRecord(es.getLineNum(), String.format("场次号:%s格式不正确", examStageOrder)));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ GetExamStageReq gesReq = new GetExamStageReq();
|
|
|
+ gesReq.setExamId(examId);
|
|
|
+ gesReq.setExamStageOrder(examStageOrder);
|
|
|
+
|
|
|
+ try {
|
|
|
+ GetExamStageResp gesResp = examStageCloudService.getExamStage(gesReq);
|
|
|
+ ExamStageBean examStageBean = gesResp.getExamStageBean();
|
|
|
+
|
|
|
+ if (null == examStageBean) {
|
|
|
+ failRecords.add(buildFailRecord(es.getLineNum(), String.format("找不到场次号为:%s的数据", examStageOrder)));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ es.setExamStageId(gesResp.getId());
|
|
|
+ es.setExamStageOrder(examStageOrder);
|
|
|
+ } catch (Exception e) {
|
|
|
+ taskLog.error(e.getMessage());
|
|
|
+
|
|
|
+ failRecords.add(buildFailRecord(es.getLineNum(), String.format("获取场次信息失败:%s的数据", examStageOrder)));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (hasError(failRecords, es)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ list.add(es);
|
|
|
+
|
|
|
+ String key = es.getIdentityNumber() + "____" + es.getCourseCode();
|
|
|
+ if (fullSet.contains(key)) {
|
|
|
+ sb.append("line ").append(es.getLineNum()).append(" 重复数据,执行更新").append("\n");
|
|
|
+ } else {
|
|
|
+ fullSet.add(key);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (0 == i % 100) {
|
|
|
+ examStudentTempRepo.saveAll(list);
|
|
|
+
|
|
|
+ list = Lists.newArrayList();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ examStudentTempRepo.saveAll(list);
|
|
|
+ sb.append("====================数据规格错误数据\n");
|
|
|
+ for (Map<String, Object> cur : failRecords) {
|
|
|
+ sb.append("line ").append(cur.get("lineNum")).append(cur.get("msg")).append("\n");
|
|
|
+ }
|
|
|
+
|
|
|
+ File resultFile = new File(resultFilePath);
|
|
|
+
|
|
|
+ try {
|
|
|
+ FileUtils.writeStringToFile(resultFile, sb.toString(), "UTF-8", true);
|
|
|
+ } catch (IOException e) {
|
|
|
+ importEntity.setStatus(ExamStudentImportStatus.ERROR);
|
|
|
+ importEntity.setErrorDesc("导入报告写入失败");
|
|
|
+ examStudentImportRepo.saveAndFlush(importEntity);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ importEntity.setStatus(ExamStudentImportStatus.FILE_PARSING_COMPLETE);
|
|
|
+ examStudentImportRepo.saveAndFlush(importEntity);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @param failRecords
|
|
|
+ * @param entity
|
|
|
+ * @return
|
|
|
+ * @author WANGWEI
|
|
|
+ */
|
|
|
+ public boolean hasError(List<Map<String, Object>> failRecords, ExamStudentTempEntity entity) {
|
|
|
+ boolean hasError = false;
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+
|
|
|
+ String name = entity.getName();
|
|
|
+ if (StringUtils.isBlank(name)) {
|
|
|
+ sb.append(" 姓名不能为空");
|
|
|
+ hasError = true;
|
|
|
+ } else if (20 < name.length()) {
|
|
|
+ sb.append(" 姓名不能超过20个字符");
|
|
|
+ hasError = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ String identityNumber = entity.getIdentityNumber();
|
|
|
+ if (StringUtils.isBlank(identityNumber)) {
|
|
|
+ sb.append(" 身份证号不能为空");
|
|
|
+ hasError = true;
|
|
|
+ } else if (identityNumber.length() < 6) {
|
|
|
+ sb.append(" 身份证号至少为6个字符");
|
|
|
+ hasError = true;
|
|
|
+ } else if (identityNumber.length() > 30) {
|
|
|
+ sb.append(" 身份证号不能超过30个字符");
|
|
|
+ hasError = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ String studentCode = entity.getStudentCode();
|
|
|
+ if (StringUtils.isNotBlank(studentCode)) {
|
|
|
+ if (studentCode.length() < 6) {
|
|
|
+ sb.append(" 学号至少为6个字符");
|
|
|
+ hasError = true;
|
|
|
+ } else if (studentCode.length() > 30) {
|
|
|
+ sb.append(" 学号不能超过30个字符");
|
|
|
+ hasError = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String courseCode = entity.getCourseCode();
|
|
|
+ if (StringUtils.isBlank(courseCode)) {
|
|
|
+ sb.append(" 课程代码不能为空");
|
|
|
+ hasError = true;
|
|
|
+ } else if (courseCode.length() > 30) {
|
|
|
+ sb.append(" 课程代码不能超过30个字符");
|
|
|
+ hasError = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ String orgCode = entity.getOrgCode();
|
|
|
+ if (StringUtils.isBlank(orgCode)) {
|
|
|
+ sb.append(" 学习中心代码不能为空");
|
|
|
+ hasError = true;
|
|
|
+ } else if (orgCode.length() > 30) {
|
|
|
+ sb.append(" 学习中心代码不能超过30个字符");
|
|
|
+ hasError = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (hasError) {
|
|
|
+ failRecords.add(buildFailRecord(entity.getLineNum(), sb.toString()));
|
|
|
+ }
|
|
|
+
|
|
|
+ return hasError;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建错误信息
|
|
|
+ *
|
|
|
+ * @param lineNum
|
|
|
+ * @param msg
|
|
|
+ * @return
|
|
|
+ * @author WANGWEI
|
|
|
+ */
|
|
|
+ private Map<String, Object> buildFailRecord(Long lineNum, String msg) {
|
|
|
+ Map<String, Object> map = Maps.newHashMap();
|
|
|
+ map.put("lineNum", lineNum);
|
|
|
+ map.put("msg", msg);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @param s
|
|
|
+ * @return
|
|
|
+ * @author WANGWEI
|
|
|
+ */
|
|
|
+ private String trimAndNullIfBlank(String s) {
|
|
|
+ if (StringUtils.isBlank(s)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return s.trim();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @param header
|
|
|
+ * @author WANGWEI
|
|
|
+ */
|
|
|
+ private boolean headerError(String[] header) {
|
|
|
+ for (int i = 0; i < EXCEL_HEADER.length; i++) {
|
|
|
+ if (null == header[i] || !EXCEL_HEADER[i].equals(header[i].trim())) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TaskTracker getTaskTracker() {
|
|
|
+ return taskTracker;
|
|
|
+ }
|
|
|
}
|