|
@@ -9,10 +9,7 @@ import org.slf4j.LoggerFactory;
|
|
|
import javax.validation.ConstraintViolation;
|
|
|
import javax.validation.Validation;
|
|
|
import javax.validation.Validator;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -38,6 +35,8 @@ public class ExcelDataReader<T> extends AnalysisEventListener<T> {
|
|
|
private final AtomicInteger rows = new AtomicInteger(0);
|
|
|
//异步执行的集合
|
|
|
private final List<CompletableFuture<ExcelDataReaderProperty<T>>> futureList = new ArrayList<>();
|
|
|
+ //所有异常的集合 key excel文件
|
|
|
+ private final List<Map<Integer, String>> totalErrorList = new ArrayList<>();
|
|
|
//校验
|
|
|
private final Validator vf;
|
|
|
|
|
@@ -59,6 +58,10 @@ public class ExcelDataReader<T> extends AnalysisEventListener<T> {
|
|
|
return rows.get();
|
|
|
}
|
|
|
|
|
|
+ public List<Map<Integer, String>> getTotalErrorList() {
|
|
|
+ return totalErrorList;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void invoke(T data, AnalysisContext context) {
|
|
|
//支持多sheet数据导入,每次换sheet后要清除上一个sheet的数据
|
|
@@ -70,7 +73,7 @@ public class ExcelDataReader<T> extends AnalysisEventListener<T> {
|
|
|
if (rows.get() > maxRows) {
|
|
|
throw new RuntimeException("导入的数据超过最大行数限制!" + rows.get());
|
|
|
}
|
|
|
- CompletableFuture<ExcelDataReaderProperty<T>> future = CompletableFuture.supplyAsync(() -> executed(data));
|
|
|
+ CompletableFuture<ExcelDataReaderProperty<T>> future = CompletableFuture.supplyAsync(() -> executed(data, context));
|
|
|
futureList.add(future);
|
|
|
rows.incrementAndGet();
|
|
|
}
|
|
@@ -86,7 +89,7 @@ public class ExcelDataReader<T> extends AnalysisEventListener<T> {
|
|
|
log.info("ExcelDataReader >> fileName {} >> dataList size {}", fileName, dataList.size());
|
|
|
}
|
|
|
|
|
|
- private ExcelDataReaderProperty<T> executed(T data) {
|
|
|
+ private ExcelDataReaderProperty<T> executed(T data, AnalysisContext context) {
|
|
|
ExcelDataReaderProperty<T> property = new ExcelDataReaderProperty<>();
|
|
|
property.setClazz(data);
|
|
|
//执行注解校验
|
|
@@ -96,6 +99,10 @@ public class ExcelDataReader<T> extends AnalysisEventListener<T> {
|
|
|
.map(ConstraintViolation::getMessage)
|
|
|
.collect(Collectors.joining());
|
|
|
property.setErrorMessage(collect);
|
|
|
+ Integer rowIndex = context.readRowHolder().getRowIndex();
|
|
|
+ Map<Integer, String> errorMap = new HashMap<>();
|
|
|
+ errorMap.put(rowIndex, collect);
|
|
|
+ totalErrorList.add(errorMap);
|
|
|
}
|
|
|
return property;
|
|
|
}
|