use of com.github.lybgeek.excel.entity.ErrorExcelRow in project springboot-learning by lyb-geek.
the class BaseAnalysisEventListener method onException.
/**
* 在转换异常 获取其他异常下会调用本接口。抛出异常则停止读取。如果这里不抛出异常则 继续读取下一行。
*
* @param exception
* @param analysisContext
* @throws Exception
*/
@Override
public void onException(Exception exception, AnalysisContext analysisContext) {
log.error("解析失败,但是继续解析下一行:{}", exception.getMessage());
ErrorExcelRow errorExcelRow = this.setAndReturnErrorExcelRow(analysisContext, exception.getMessage());
errorExcelRows.add(errorExcelRow);
// 如果要获取头的信息 配合invokeHeadMap使用
if (exception instanceof ExcelDataConvertException) {
ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) exception;
log.error("第{}行,第{}列解析异常,数据为:{}", excelDataConvertException.getRowIndex(), excelDataConvertException.getColumnIndex(), excelDataConvertException.getCellData());
}
}
use of com.github.lybgeek.excel.entity.ErrorExcelRow in project springboot-learning by lyb-geek.
the class BaseAnalysisEventListener method setAndReturnErrorExcelRow.
private ErrorExcelRow setAndReturnErrorExcelRow(AnalysisContext analysisContext, String errorMsg) {
int rowIndex = analysisContext.readRowHolder().getRowIndex();
int sheetNo = analysisContext.readSheetHolder().getSheetNo();
String sheetName = analysisContext.readSheetHolder().getSheetName();
ErrorExcelRow errorExcelRow = ErrorExcelRow.builder().rowNum(rowIndex).sheetName(sheetName).sheetNo(sheetNo).errorMessage(errorMsg).build();
return errorExcelRow;
}
use of com.github.lybgeek.excel.entity.ErrorExcelRow in project springboot-learning by lyb-geek.
the class BaseAnalysisEventListener method validatePass.
private boolean validatePass(T entity, AnalysisContext analysisContext) {
ValidResult validResult = ValidatorUtils.allCheckValidate(entity, false, ExcelGroup.class);
if (!validResult.isSuccess()) {
String errorMsg = StringUtils.join(validResult.getErrorMessages(), ",");
ErrorExcelRow errorExcelRow = this.setAndReturnErrorExcelRow(analysisContext, errorMsg);
errorExcelRows.add(errorExcelRow);
}
return validResult.isSuccess();
}
use of com.github.lybgeek.excel.entity.ErrorExcelRow in project springboot-learning by lyb-geek.
the class ExcelController method getErrorMsg.
private String getErrorMsg(List<ErrorExcelRow> errorExcelRows) {
Map<Integer, List<String>> sheetErrorMap = new HashMap<>();
for (ErrorExcelRow errorRow : errorExcelRows) {
Integer sheetNo = errorRow.getSheetNo();
List<String> errorMsgs = sheetErrorMap.get(sheetNo);
String errorMsg = "第" + errorRow.getRowNum() + "行," + errorRow.getErrorMessage();
if (CollectionUtils.isEmpty(errorMsgs)) {
errorMsgs = new ArrayList<>();
sheetErrorMap.put(sheetNo, errorMsgs);
}
errorMsgs.add(errorMsg);
}
List<String> errorMsgList = new ArrayList<>();
sheetErrorMap.forEach((sheetNo, errorMsgs) -> {
String errorMsg = "在第" + (sheetNo + 1) + "个sheet中存在错误-->" + StringUtils.join(errorMsgs, "|");
errorMsgList.add(errorMsg);
});
return StringUtils.join(errorMsgList, ";");
}
Aggregations