Commit b7bab0b7 authored by liaozan's avatar liaozan 🏀

Polish

parent 98858bca
......@@ -32,9 +32,9 @@ public class ValidationMessageBuilder {
return joiner.toString();
}
public static <T> String buildConstraintViolationErrorMsg(Set<ConstraintViolation<T>> constraintViolations) {
public static String buildConstraintViolationErrorMsg(Set<ConstraintViolation<?>> violations) {
StringJoiner joiner = new StringJoiner(", ");
for (ConstraintViolation<?> violation : constraintViolations) {
for (ConstraintViolation<?> violation : violations) {
String propertyPath = violation.getPropertyPath().toString();
joiner.add(getActualProperty(propertyPath) + " " + violation.getMessage());
}
......
package com.schbrain.common.util.support.excel.listener;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.metadata.holder.ReadSheetHolder;
import com.schbrain.common.util.StreamUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
......@@ -28,10 +28,13 @@ public class ExcelBeanReadListener<T> extends ExcelReadListenerBase<T> {
}
protected void collectErrorMsg(AnalysisContext context, Set<ConstraintViolation<T>> violations) {
ReadSheetHolder currentSheet = context.readSheetHolder();
String sheetName = currentSheet.getSheetName();
Integer rowIndex = currentSheet.getRowIndex();
getErrors().put(sheetName, rowIndex + 1, buildConstraintViolationErrorMsg(violations));
String sheetName = context.readSheetHolder().getSheetName();
Integer rowIndex = context.readRowHolder().getRowIndex();
getErrors().put(sheetName, rowIndex + 1, buildErrorMsg(violations));
}
protected String buildErrorMsg(Set<ConstraintViolation<T>> violations) {
return buildConstraintViolationErrorMsg(StreamUtils.toSet(violations, self -> self));
}
}
......@@ -26,18 +26,16 @@ import java.util.Map;
public class ExcelReadListenerBase<T> extends AnalysisEventListener<T> {
protected final Validator validator = SpringUtil.getBean(Validator.class);
protected final Map<Integer, String> headers = new HashMap<>();
protected List<T> dataList = new LinkedList<>();
protected Map<Integer, String> headers = new HashMap<>();
protected Table<String, Integer, String> errors = HashBasedTable.create();
protected boolean terminateOnValidateFail = false;
@Override
public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
this.headers = headMap;
this.headers.putAll(headMap);
}
@Override
......@@ -47,13 +45,13 @@ public class ExcelReadListenerBase<T> extends AnalysisEventListener<T> {
@Override
public void invoke(T data, AnalysisContext context) {
boolean validated = validate(data, context);
if (!validated) {
if (validate(data, context)) {
this.dataList.add(data);
} else {
if (isTerminateOnValidateFail()) {
throw new ExcelException(getErrorMsg());
}
}
this.dataList.add(data);
}
@Override
......@@ -86,4 +84,4 @@ public class ExcelReadListenerBase<T> extends AnalysisEventListener<T> {
return true;
}
}
\ No newline at end of file
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment