DefautExcelResult.java 1.8 KB

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