DefautExcelResult.java 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package com.ruoyi.common.excel;
  2. import cn.hutool.core.util.StrUtil;
  3. import lombok.Setter;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6. /**
  7. * 默认excel返回对象
  8. *
  9. * @author Yjoioooo
  10. * @author Lion Li
  11. */
  12. public class DefautExcelResult<T> implements ExcelResult<T> {
  13. /**
  14. * 数据对象list
  15. */
  16. @Setter
  17. private List<T> list;
  18. /**
  19. * 错误信息列表
  20. */
  21. @Setter
  22. private List<String> errorList;
  23. public DefautExcelResult() {
  24. this.list = new ArrayList<>();
  25. this.errorList = new ArrayList<>();
  26. }
  27. public DefautExcelResult(List<T> list, List<String> errorList) {
  28. this.list = list;
  29. this.errorList = errorList;
  30. }
  31. public DefautExcelResult(ExcelResult<T> excelResult) {
  32. this.list = excelResult.getList();
  33. this.errorList = excelResult.getErrorList();
  34. }
  35. @Override
  36. public List<T> getList() {
  37. return list;
  38. }
  39. @Override
  40. public List<String> getErrorList() {
  41. return errorList;
  42. }
  43. /**
  44. * 获取导入回执
  45. *
  46. * @return 导入回执
  47. */
  48. @Override
  49. public String getAnalysis() {
  50. int successCount = list.size();
  51. int errorCount = errorList.size();
  52. if (successCount == 0) {
  53. return "读取失败,未解析到数据";
  54. } else {
  55. if (errorCount == 0) {
  56. return StrUtil.format("恭喜您,全部读取成功!共{}条", successCount);
  57. } else {
  58. return "";
  59. }
  60. }
  61. }
  62. }