package cn.com.goldenwater.dcproj.utils; import cn.com.goldenwater.dcproj.dto.BisInspPblmImportDto; import lombok.extern.slf4j.Slf4j; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @Slf4j public class ExcelVerifyUtil { /* 校验方法list */ List paramList = new ArrayList<>(); /* 被校验数据上下文 */ //ExcelVerifyCollection collection; /** * 构造方法(构造后直接进行校验) * @param collection 被校验数据list * @param paramList 校验参数list * @throws Exception */ // public ExcelVerifyUtil(ExcelVerifyCollection collection, List paramList) throws Exception { // //this.collection = collection; // this.paramList = paramList; // excuteVerify(); // } // // /** // * 构造方法 // * @param collection // * @param verifyParameter // */ // public ExcelVerifyUtil(ExcelVerifyCollection collection, ExcelVerifyParameter... verifyParameter) throws Exception { // //this.collection = collection; // for(ExcelVerifyParameter e : verifyParameter){ // this.paramList.add(e); // } // excuteVerify(); // } /** * 构造方法 * @param list * @param verifyParameter */ public ExcelVerifyUtil(List list, ExcelVerifyParameter... verifyParameter) throws Exception { ExcelVerifyCollection collection = new ExcelVerifyCollection<>(list); ExcelNotNullVerify excelNotNullVerify = new ExcelNotNullVerify(); excelNotNullVerify.addExcelVerifyCollection(collection); paramList.add(excelNotNullVerify); if(verifyParameter != null && verifyParameter.length > 0) { for(ExcelVerifyParameter e : verifyParameter){ e.addExcelVerifyCollection(collection); this.paramList.add(e); } } excuteVerify(); } /** * 校验方法 */ protected void excuteVerify() throws Exception { for(int i = 0; i < paramList.size(); i++){ try{ paramList.get(i).doverify(); } catch (Exception e){ ExcelVerifyParameter excelVerifyParameter = paramList.get(i); String name = excelVerifyParameter.getClass().getName(); log.error("Excel校验报错【" + name + "】",e.getMessage()); } } } /** * 获取错误信息List * @return */ public List getErrorList(){ return paramList.get(0).getCollection().getErrorList(); } /** * 获取正确list * @return */ public List getRightList(){ return paramList.get(0).getCollection().getRightList(); } /** * 包装导入结果返回格式 * @return AjaxResult */ // public Map getResultMsg(){ // Map resultMap = new HashMap<>(); // List successList = dataList.stream().filter(o -> o.isTrueOrFalse() == true).collect(Collectors.toList()); // List errorList = dataList.stream().filter(o -> o.isTrueOrFalse() == false).collect(Collectors.toList()); // resultMap.put("allCount",dataList.size()); // resultMap.put("failCount",errorList.size()); // resultMap.put("successCount",successList.size()); // resultMap.put("errorList",getErrorList()); // return resultMap; // } }