|
@@ -1,8 +1,10 @@
|
|
|
package cn.com.qmth.scancentral.service.impl;
|
|
|
|
|
|
+import cn.com.qmth.scancentral.bean.ImportStudentDomain;
|
|
|
import cn.com.qmth.scancentral.entity.ExamEntity;
|
|
|
import cn.com.qmth.scancentral.service.ExamService;
|
|
|
import cn.com.qmth.scancentral.service.StudentImportService;
|
|
|
+import cn.com.qmth.scancentral.service.StudentService;
|
|
|
import cn.com.qmth.scancentral.service.SubjectService;
|
|
|
import cn.com.qmth.scancentral.util.FileUtil;
|
|
|
import cn.com.qmth.scancentral.vo.studentimport.ImportTaskVo;
|
|
@@ -35,6 +37,9 @@ public class StudentImportServiceImpl implements StudentImportService {
|
|
|
@Autowired
|
|
|
private SubjectService subjectService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private StudentService studentService;
|
|
|
+
|
|
|
@Override
|
|
|
public Map<String, Object> studentImportProgress(String taskId) {
|
|
|
ImportTaskVo task = IMPORT_TASKS.get(taskId);
|
|
@@ -69,6 +74,16 @@ public class StudentImportServiceImpl implements StudentImportService {
|
|
|
return logFile;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public boolean existRunningStudentImportTask() {
|
|
|
+ for (ImportTaskVo task : IMPORT_TASKS.values()) {
|
|
|
+ if (task.getProgress() < 100d) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
@Async
|
|
|
@Override
|
|
|
public void studentImport(String taskId, Long examId, String fileName, byte[] fileBytes) {
|
|
@@ -117,29 +132,78 @@ public class StudentImportServiceImpl implements StudentImportService {
|
|
|
|
|
|
List<StudentImportInfo> list = new ArrayList<>();
|
|
|
List<String> errs = this.parseValues(lines, list, examId, exam.getYear(), exam.getYearHalf());
|
|
|
- log.warn("解析考生数据共{}条! errCount:{} taskId:{}", list.size(), errs.size(), taskId);
|
|
|
+ log.warn("本次解析考生数据共{}条! errCount:{} taskId:{}", list.size(), errs.size(), taskId);
|
|
|
if (!errs.isEmpty()) {
|
|
|
- errs.add("本次执行导入0条,请先处理内容错误!");
|
|
|
+ errs.add(String.format("本次解析考生数据共%s条,执行导入0条,请先处理文件内容错误!", list.size()));
|
|
|
this.writeLogFile(logFile, StringUtils.join(errs, "\n"));
|
|
|
task.setProgress(100d);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ if (list.isEmpty()) {
|
|
|
+ this.writeLogFile(logFile, "本次解析考生数据共0条,请填写有效的数据内容!");
|
|
|
+ task.setProgress(100d);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
log.info("执行导入数据库开始... {}", taskId);
|
|
|
this.writeLogFile(logFile, "执行导入数据库开始...");
|
|
|
|
|
|
- //to do
|
|
|
+ int finishCount = 0;
|
|
|
+ int total = list.size();
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
+
|
|
|
try {
|
|
|
- for (int i = 1; i <= list.size(); i++) {
|
|
|
- Thread.sleep(5000);
|
|
|
- task.setProgress(i * 100d / list.size());
|
|
|
+ int batchNum = 1000;
|
|
|
+ List<ImportStudentDomain> batchList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (int n = 0; n < total; n++) {
|
|
|
+ batchList.add(ofData(list.get(n)));
|
|
|
+
|
|
|
+ if ((n + 1) % batchNum == 0) {
|
|
|
+ studentService.importStudent(batchList);
|
|
|
+ finishCount = finishCount + batchList.size();
|
|
|
+ batchList.clear();
|
|
|
+
|
|
|
+ double progress = finishCount * 100f / total;
|
|
|
+ long cost = (System.currentTimeMillis() - startTime) / 1000L;
|
|
|
+ log.info("已导入:{}条 已耗时:{}秒 进度:{}%", finishCount, cost, progress);
|
|
|
+ task.setProgress(progress);
|
|
|
+ }
|
|
|
}
|
|
|
- } catch (InterruptedException e) {
|
|
|
- log.error(e.getMessage());
|
|
|
+
|
|
|
+ if (!batchList.isEmpty()) {
|
|
|
+ studentService.importStudent(batchList);
|
|
|
+ finishCount = finishCount + batchList.size();
|
|
|
+ }
|
|
|
+
|
|
|
+ long cost = (System.currentTimeMillis() - startTime) / 1000L;
|
|
|
+ log.info("已导入:{}条 已耗时:{}秒 进度:100%", finishCount, cost);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ this.writeLogFile(logFile, "【错误】导入过程异常终止!");
|
|
|
+ } finally {
|
|
|
+ task.setProgress(100d);
|
|
|
}
|
|
|
|
|
|
log.info("执行导入数据库结束... {}", taskId);
|
|
|
- this.writeLogFile(logFile, "本次成功导入0条,失败0条");
|
|
|
+ this.writeLogFile(logFile, String.format("本次解析考生数据共%s条,成功导入%s条,失败导入%s条!", total, finishCount, total - finishCount));
|
|
|
+ }
|
|
|
+
|
|
|
+ private ImportStudentDomain ofData(StudentImportInfo info) {
|
|
|
+ ImportStudentDomain data = new ImportStudentDomain();
|
|
|
+ data.setExamId(info.getExamId());
|
|
|
+ data.setSubjectCode(info.getSubjectCode());
|
|
|
+ data.setExamNumber(info.getExamNumber());
|
|
|
+ data.setName(info.getName());
|
|
|
+ data.setCampusCode(info.getCampusCode());
|
|
|
+ data.setCampusName(info.getCampusName());
|
|
|
+ data.setExamSite(info.getExamSite());
|
|
|
+ data.setExamSiteName(info.getExamSiteName());
|
|
|
+ data.setExamRoom(info.getExamRoom());
|
|
|
+ data.setPackageCode(info.getPackageCode());
|
|
|
+ data.setSeatNumber(info.getSeatNumber());
|
|
|
+ return data;
|
|
|
}
|
|
|
|
|
|
private List<String> parseValues(List<String> lines, List<StudentImportInfo> list, Long examId, Integer yearConfig, Integer yearHalfConfig) {
|
|
@@ -217,8 +281,8 @@ public class StudentImportServiceImpl implements StudentImportService {
|
|
|
data.setExamId(examId);
|
|
|
data.setSubjectCode(subjectCode);
|
|
|
data.setExamNumber(examNumber);
|
|
|
- data.setName(name);
|
|
|
data.setStudentCode(examNumber);
|
|
|
+ data.setName(name);
|
|
|
data.setExamSite(examSite);
|
|
|
data.setExamSiteName(examSiteName);
|
|
|
data.setCampusCode(campusCode);
|