|
@@ -96,8 +96,8 @@ public class BatchImportExamStudentTask implements TaskService {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (total > 100000) {
|
|
|
- throw new StatusException("Excel的数据条数限制最大10万条!");
|
|
|
+ if (total > 200000) {
|
|
|
+ throw new StatusException("Excel的数据限制最大20万条!");
|
|
|
}
|
|
|
|
|
|
// 检验数据
|
|
@@ -169,17 +169,21 @@ public class BatchImportExamStudentTask implements TaskService {
|
|
|
long startTime = System.currentTimeMillis();
|
|
|
AtomicInteger successCount = new AtomicInteger(), failCount = new AtomicInteger();
|
|
|
if (total <= 1000) {
|
|
|
- this.singleRun(loginUser, dataList, successCount, failCount, task.getId(), failRecords);
|
|
|
+ // 数量少,正常执行
|
|
|
+ this.normalRun(loginUser, dataList, successCount, failCount, task.getId(), failRecords);
|
|
|
} else {
|
|
|
- final int batchSize = 20;// 分批数量
|
|
|
-
|
|
|
- // 目前重复数据在多线程并发下会执行失败,拆成多个不重复集合分开执行。
|
|
|
+ // 目前多线程并发下会少量执行失败(后端接口目前容易产生事务、数据库约束等错误),针对重复记录也需要拆成多个不重复集合分开分散执行,减少报错情况。
|
|
|
List<List<ExamStudentInfo>> newList = this.redoList(dataList);
|
|
|
+
|
|
|
+ // 数量多,多线程分批执行
|
|
|
+ final int concurrentSize = 10;
|
|
|
for (List<ExamStudentInfo> list : newList) {
|
|
|
int cutTotal = list.size();
|
|
|
- for (int start = 0; start < cutTotal; start += batchSize) {
|
|
|
- int end = Math.min(start + batchSize, cutTotal);
|
|
|
+
|
|
|
+ for (int start = 0; start < cutTotal; start += concurrentSize) {
|
|
|
+ int end = Math.min(start + concurrentSize, cutTotal);
|
|
|
List<ExamStudentInfo> batchList = list.subList(start, end);
|
|
|
+
|
|
|
this.concurrentRun(loginUser, batchList, successCount, failCount, task.getId(), failRecords);
|
|
|
|
|
|
long cost = Math.max((System.currentTimeMillis() - startTime) / 1000L, 1);
|
|
@@ -201,11 +205,12 @@ public class BatchImportExamStudentTask implements TaskService {
|
|
|
dataList.clear();
|
|
|
}
|
|
|
|
|
|
- private void singleRun(User loginUser, List<ExamStudentInfo> batchList, AtomicInteger successCount,
|
|
|
+ private void normalRun(User loginUser, List<ExamStudentInfo> batchList, AtomicInteger successCount,
|
|
|
AtomicInteger failCount, Long taskId, List<String> failRecords) {
|
|
|
long startTime = System.currentTimeMillis();
|
|
|
for (int n = 0; n < batchList.size(); n++) {
|
|
|
ExamStudentInfo examStudent = batchList.get(n);
|
|
|
+
|
|
|
try {
|
|
|
this.saveExamStudent(loginUser, examStudent);
|
|
|
successCount.incrementAndGet();
|