|
@@ -28,6 +28,7 @@ import java.util.*;
|
|
|
import java.util.concurrent.CountDownLatch;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -91,7 +92,7 @@ public class BatchImportExamStudentTask implements TaskService {
|
|
|
List<ExamStudentInfo> dataList = dataListener.getList();
|
|
|
|
|
|
int total = dataList.size();
|
|
|
- log.info("共{}条数据!examId:{} dataFile:{}", total, examId, dataFilePath);
|
|
|
+ log.info("Excel共{}条数据!examId:{} dataFile:{}", total, examId, dataFilePath);
|
|
|
if (total == 0) {
|
|
|
return;
|
|
|
}
|
|
@@ -101,6 +102,9 @@ public class BatchImportExamStudentTask implements TaskService {
|
|
|
}
|
|
|
|
|
|
// 检验数据
|
|
|
+ Set<String> courseStudentCodes = new HashSet<>();
|
|
|
+ Set<String> courseIdentityNumbers = new HashSet<>();
|
|
|
+ Set<String> courseStudentCodeIdentityNumbers = new HashSet<>();
|
|
|
Map<String, Long> orgMaps = new HashMap<>();
|
|
|
Map<String, Long> courseMaps = new HashMap<>();
|
|
|
List<String> errMessages = new ArrayList<>();
|
|
@@ -158,6 +162,12 @@ public class BatchImportExamStudentTask implements TaskService {
|
|
|
examStudent.setCourseId(courseId);
|
|
|
}
|
|
|
|
|
|
+ String courseStudentCode = examStudent.getCourseCode() + "@" + examStudent.getStudentCode();
|
|
|
+ String courseIdentityNumber = examStudent.getCourseCode() + "@" + examStudent.getIdentityNumber();
|
|
|
+ String courseStudentCodeIdentityNumber = courseStudentCode + "@" + examStudent.getIdentityNumber();
|
|
|
+ courseStudentCodes.add(courseStudentCode);
|
|
|
+ courseIdentityNumbers.add(courseIdentityNumber);
|
|
|
+ courseStudentCodeIdentityNumbers.add(courseStudentCodeIdentityNumber);
|
|
|
// log.info(examStudent.toString());
|
|
|
}
|
|
|
|
|
@@ -166,7 +176,9 @@ public class BatchImportExamStudentTask implements TaskService {
|
|
|
throw new StatusException("检验数据有误!");
|
|
|
}
|
|
|
|
|
|
- log.info("检验数据完成! taskId:{}", task.getId());
|
|
|
+ log.info("检验数据完成!Excel共{}条【课程_学号:{}条】【课程_证件号:{}条】【课程_学号_证件号:{}条】examId:{} taskId:{}",
|
|
|
+ total, courseStudentCodes.size(), courseIdentityNumbers.size(), courseStudentCodeIdentityNumbers.size(),
|
|
|
+ examId, task.getId());
|
|
|
// if (true) return;
|
|
|
|
|
|
// 开始执行导入
|
|
@@ -177,12 +189,13 @@ public class BatchImportExamStudentTask implements TaskService {
|
|
|
// 数量少,正常执行
|
|
|
this.normalRun(loginUser, dataList, successCount, failCount, task.getId(), failRecords);
|
|
|
} else {
|
|
|
- // 目前多线程并发下会少量执行失败(后端接口目前容易产生事务、数据库约束等错误),针对重复记录也需要拆成多个不重复集合分开分散执行,减少报错情况。
|
|
|
+ // 目前多线程并发下会少量执行失败(后端接口目前容易产生事务、数据库约束等错误),针对重复记录也需要拆成多个不重复集合分开分散执行,减少报错情况!!
|
|
|
List<List<ExamStudentInfo>> newList = this.redoList(dataList);
|
|
|
|
|
|
// 数量多,多线程分批执行
|
|
|
final int concurrentSize = 20;
|
|
|
- for (List<ExamStudentInfo> list : newList) {
|
|
|
+ for (int n = 0; n < newList.size(); n++) {
|
|
|
+ List<ExamStudentInfo> list = newList.get(n);
|
|
|
int cutTotal = list.size();
|
|
|
|
|
|
for (int start = 0; start < cutTotal; start += concurrentSize) {
|
|
@@ -197,12 +210,21 @@ public class BatchImportExamStudentTask implements TaskService {
|
|
|
, total, successCount.get(), failCount.get(), runCount, cost, runCount / cost,
|
|
|
runCount * 100f / total, predictTime(total, runCount, cost));
|
|
|
}
|
|
|
+
|
|
|
+ log.info("----------> 分批集合{} size:{}", n + 1, cutTotal);
|
|
|
+ try {
|
|
|
+ // 等待几秒后再处理下一步,减少报错情况!!
|
|
|
+ TimeUnit.SECONDS.sleep(5);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ // ignore
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
long cost = Math.max((System.currentTimeMillis() - startTime) / 1000L, 1);
|
|
|
- String msg = String.format("总数:%s 成功数:%s 失败数:%s 平均每秒%s条 总耗时:%s秒"
|
|
|
- , total, successCount.get(), failCount.get(), total / cost, cost);
|
|
|
+ String msg = String.format("Excel共%s条 【课程_学号:%s条】【课程_证件号:%s条】【课程_学号_证件号:%s条】 成功数:%s 失败数:%s 平均每秒%s条 总耗时:%s秒",
|
|
|
+ total, courseStudentCodes.size(), courseIdentityNumbers.size(), courseStudentCodeIdentityNumbers.size(),
|
|
|
+ successCount.get(), failCount.get(), total / cost, cost);
|
|
|
log.info(msg);
|
|
|
task.setDescription(msg);
|
|
|
FileHelper.writeLines(logFile, failRecords, true);
|