d677b925ff8d0f114043a165a60a7be9acc09c6a.svn-base 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package cn.com.goldenwater.dcproj.utils;
  2. import cn.com.goldenwater.dcproj.dto.BisInspPblmImportDto;
  3. import lombok.extern.slf4j.Slf4j;
  4. import java.lang.reflect.InvocationTargetException;
  5. import java.util.ArrayList;
  6. import java.util.HashMap;
  7. import java.util.List;
  8. import java.util.Map;
  9. @Slf4j
  10. public class ExcelVerifyUtil<T> {
  11. /*
  12. 校验方法list
  13. */
  14. List<ExcelVerifyParameter> paramList = new ArrayList<>();
  15. /*
  16. 被校验数据上下文
  17. */
  18. //ExcelVerifyCollection<T> collection;
  19. /**
  20. * 构造方法(构造后直接进行校验)
  21. * @param collection 被校验数据list
  22. * @param paramList 校验参数list
  23. * @throws Exception
  24. */
  25. // public ExcelVerifyUtil(ExcelVerifyCollection<T> collection, List<ExcelVerifyParameter> paramList) throws Exception {
  26. // //this.collection = collection;
  27. // this.paramList = paramList;
  28. // excuteVerify();
  29. // }
  30. //
  31. // /**
  32. // * 构造方法
  33. // * @param collection
  34. // * @param verifyParameter
  35. // */
  36. // public ExcelVerifyUtil(ExcelVerifyCollection<T> collection, ExcelVerifyParameter... verifyParameter) throws Exception {
  37. // //this.collection = collection;
  38. // for(ExcelVerifyParameter e : verifyParameter){
  39. // this.paramList.add(e);
  40. // }
  41. // excuteVerify();
  42. // }
  43. /**
  44. * 构造方法
  45. * @param list
  46. * @param verifyParameter
  47. */
  48. public ExcelVerifyUtil(List<T> list, ExcelVerifyParameter... verifyParameter) throws Exception {
  49. ExcelVerifyCollection<T> collection = new ExcelVerifyCollection<>(list);
  50. ExcelNotNullVerify excelNotNullVerify = new ExcelNotNullVerify();
  51. excelNotNullVerify.addExcelVerifyCollection(collection);
  52. paramList.add(excelNotNullVerify);
  53. if(verifyParameter != null && verifyParameter.length > 0) {
  54. for(ExcelVerifyParameter e : verifyParameter){
  55. e.addExcelVerifyCollection(collection);
  56. this.paramList.add(e);
  57. }
  58. }
  59. excuteVerify();
  60. }
  61. /**
  62. * 校验方法
  63. */
  64. protected void excuteVerify() throws Exception {
  65. for(int i = 0; i < paramList.size(); i++){
  66. try{
  67. paramList.get(i).doverify();
  68. } catch (Exception e){
  69. ExcelVerifyParameter excelVerifyParameter = paramList.get(i);
  70. String name = excelVerifyParameter.getClass().getName();
  71. log.error("Excel校验报错【" + name + "】",e.getMessage());
  72. }
  73. }
  74. }
  75. /**
  76. * 获取错误信息List
  77. * @return
  78. */
  79. public List<String> getErrorList(){
  80. return paramList.get(0).getCollection().getErrorList();
  81. }
  82. /**
  83. * 获取正确list
  84. * @return
  85. */
  86. public List<T> getRightList(){
  87. return paramList.get(0).getCollection().getRightList();
  88. }
  89. /**
  90. * 包装导入结果返回格式
  91. * @return AjaxResult
  92. */
  93. // public Map getResultMsg(){
  94. // Map<String,Object> resultMap = new HashMap<>();
  95. // List<VerifyItem> successList = dataList.stream().filter(o -> o.isTrueOrFalse() == true).collect(Collectors.toList());
  96. // List<VerifyItem> errorList = dataList.stream().filter(o -> o.isTrueOrFalse() == false).collect(Collectors.toList());
  97. // resultMap.put("allCount",dataList.size());
  98. // resultMap.put("failCount",errorList.size());
  99. // resultMap.put("successCount",successList.size());
  100. // resultMap.put("errorList",getErrorList());
  101. // return resultMap;
  102. // }
  103. }