|
@@ -1,7 +1,6 @@
|
|
|
package cn.com.qmth.scancloud.tools.service.impl;
|
|
|
|
|
|
import java.io.File;
|
|
|
-import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashSet;
|
|
|
import java.util.List;
|
|
@@ -9,7 +8,6 @@ import java.util.Set;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
-import org.apache.commons.io.LineIterator;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -30,7 +28,9 @@ import cn.com.qmth.scancloud.tools.utils.StatusException;
|
|
|
public class ExamStudentImportTask extends AbstractTask {
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(ExamStudentImportTask.class);
|
|
|
+
|
|
|
private static Pattern examNumberRex = Pattern.compile("^[0-9]{15}$");
|
|
|
+
|
|
|
@Override
|
|
|
protected String getTaskName() {
|
|
|
return TaskType.EXAM_STUDENT_IMPORT.getTitle();
|
|
@@ -56,26 +56,22 @@ public class ExamStudentImportTask extends AbstractTask {
|
|
|
Set<String> subjectCodes = new HashSet<>();
|
|
|
Set<String> examNumbers = new HashSet<>();
|
|
|
|
|
|
- File file = new File(SysProperty.DATA_DIR+"/"+SysProperty.DATA_FILE);
|
|
|
- try (LineIterator lines = FileHelper.readLines(file);) {
|
|
|
- while (lines.hasNext()) {
|
|
|
- String line = lines.nextLine();
|
|
|
-
|
|
|
- ExamStudent data = this.parseValues(total, line, examNumbers);
|
|
|
- if (data != null) {
|
|
|
- data.setExamId(examId);
|
|
|
- list.add(data);
|
|
|
+ File file = new File(SysProperty.DATA_DIR + "/" + SysProperty.DATA_FILE);
|
|
|
+ List<String> lines = FileHelper.readAllLines(file);
|
|
|
+ for (int n = 1; n < lines.size(); n++) {
|
|
|
|
|
|
- subjectCodes.add(data.getSubjectCode());
|
|
|
+ ExamStudent data = this.parseValues(total, lines.get(n), examNumbers);
|
|
|
+ if (data != null) {
|
|
|
+ data.setExamId(examId);
|
|
|
+ list.add(data);
|
|
|
|
|
|
-
|
|
|
- examNumbers.add(data.getExamNumber());
|
|
|
- }
|
|
|
+ subjectCodes.add(data.getSubjectCode());
|
|
|
|
|
|
- total++;
|
|
|
+
|
|
|
+ examNumbers.add(data.getExamNumber());
|
|
|
}
|
|
|
- } catch (IOException e) {
|
|
|
- log.error(e.getMessage(), e);
|
|
|
+
|
|
|
+ total++;
|
|
|
}
|
|
|
|
|
|
log.info("导入文件全部行数共 {} 行,实际有效数据共 {} 条!", total, list.size());
|
|
@@ -149,7 +145,7 @@ public class ExamStudentImportTask extends AbstractTask {
|
|
|
try {
|
|
|
checkExamNumber(examNumber);
|
|
|
} catch (StatusException e) {
|
|
|
- throw new StatusException(String.format("【第%s行】%s! %s", index + 1,e.getMessage(), line));
|
|
|
+ throw new StatusException(String.format("【第%s行】%s! %s", index + 1, e.getMessage(), line));
|
|
|
}
|
|
|
|
|
|
ExamStudent data = new ExamStudent();
|
|
@@ -158,8 +154,8 @@ public class ExamStudentImportTask extends AbstractTask {
|
|
|
data.setExamSite(examNumber.substring(0, 5));
|
|
|
data.setExamSiteName(examSiteName);
|
|
|
data.setCampusCode(examNumber.substring(0, 6));
|
|
|
- data.setCampusName(examSiteName+examNumber.substring(5, 6));
|
|
|
- data.setExamRoom(examNumber.substring(0, 6)+examNumber.substring(10, 13));
|
|
|
+ data.setCampusName(examSiteName + examNumber.substring(5, 6));
|
|
|
+ data.setExamRoom(examNumber.substring(0, 6) + examNumber.substring(10, 13));
|
|
|
data.setSeatNumber(examNumber.substring(13, 15));
|
|
|
data.setPackageCode(data.getExamRoom());
|
|
|
data.setSubjectCode(examNumber.substring(9, 10));
|
|
@@ -171,21 +167,21 @@ public class ExamStudentImportTask extends AbstractTask {
|
|
|
throw new StatusException("数据内容有误!");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private void checkExamNumber(String examNumber) {
|
|
|
- if(!examNumberRex.matcher(examNumber).find()) {
|
|
|
+ if (!examNumberRex.matcher(examNumber).find()) {
|
|
|
throw new StatusException("准考证号不是15位数字");
|
|
|
}
|
|
|
- String year=examNumber.substring(6, 8);
|
|
|
- if(!year.equals(SysProperty.YEAR)) {
|
|
|
+ String year = examNumber.substring(6, 8);
|
|
|
+ if (!year.equals(SysProperty.YEAR)) {
|
|
|
throw new StatusException("年度不正确");
|
|
|
}
|
|
|
- String yearHalf=examNumber.substring(8, 9);
|
|
|
- if(!yearHalf.equals(SysProperty.YEAR_HALF)) {
|
|
|
+ String yearHalf = examNumber.substring(8, 9);
|
|
|
+ if (!yearHalf.equals(SysProperty.YEAR_HALF)) {
|
|
|
throw new StatusException("考次不正确");
|
|
|
}
|
|
|
- int subjectCode=Integer.valueOf(examNumber.substring(9, 10));
|
|
|
- if(subjectCode<1||subjectCode>9) {
|
|
|
+ int subjectCode = Integer.valueOf(examNumber.substring(9, 10));
|
|
|
+ if (subjectCode < 1 || subjectCode > 9) {
|
|
|
throw new StatusException("语种不正确");
|
|
|
}
|
|
|
}
|