| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- 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<T> {
- /*
- 校验方法list
- */
- List<ExcelVerifyParameter> paramList = new ArrayList<>();
- /*
- 被校验数据上下文
- */
- //ExcelVerifyCollection<T> collection;
- /**
- * 构造方法(构造后直接进行校验)
- * @param collection 被校验数据list
- * @param paramList 校验参数list
- * @throws Exception
- */
- // public ExcelVerifyUtil(ExcelVerifyCollection<T> collection, List<ExcelVerifyParameter> paramList) throws Exception {
- // //this.collection = collection;
- // this.paramList = paramList;
- // excuteVerify();
- // }
- //
- // /**
- // * 构造方法
- // * @param collection
- // * @param verifyParameter
- // */
- // public ExcelVerifyUtil(ExcelVerifyCollection<T> collection, ExcelVerifyParameter... verifyParameter) throws Exception {
- // //this.collection = collection;
- // for(ExcelVerifyParameter e : verifyParameter){
- // this.paramList.add(e);
- // }
- // excuteVerify();
- // }
- /**
- * 构造方法
- * @param list
- * @param verifyParameter
- */
- public ExcelVerifyUtil(List<T> list, ExcelVerifyParameter... verifyParameter) throws Exception {
- ExcelVerifyCollection<T> 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<String> getErrorList(){
- return paramList.get(0).getCollection().getErrorList();
- }
- /**
- * 获取正确list
- * @return
- */
- public List<T> getRightList(){
- return paramList.get(0).getCollection().getRightList();
- }
- /**
- * 包装导入结果返回格式
- * @return AjaxResult
- */
- // public Map getResultMsg(){
- // Map<String,Object> resultMap = new HashMap<>();
- // List<VerifyItem> successList = dataList.stream().filter(o -> o.isTrueOrFalse() == true).collect(Collectors.toList());
- // List<VerifyItem> 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;
- // }
- }
|