123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- package com.ruoyi.common.excel;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.util.StrUtil;
- import lombok.Setter;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * 默认excel返回对象
- *
- * @author Yjoioooo
- * @author Lion Li
- */
- public class DefautExcelResult<T> implements ExcelResult<T> {
- /**
- * 数据对象list
- */
- @Setter
- private List<T> list;
- /**
- * 错误信息列表
- */
- @Setter
- private List<String> errorList;
- public DefautExcelResult() {
- this.list = new ArrayList<>();
- this.errorList = new ArrayList<>();
- }
- public DefautExcelResult(List<T> list, List<String> errorList) {
- this.list = list;
- this.errorList = errorList;
- }
- public DefautExcelResult(ExcelResult<T> excelResult) {
- this.list = excelResult.getList();
- this.errorList = excelResult.getErrorList();
- }
- @Override
- public List<T> getList() {
- return list;
- }
- @Override
- public List<String> getErrorList() {
- return errorList;
- }
- /**
- * 获取导入回执
- *
- * @return 导入回执
- */
- @Override
- public String getAnalysis() {
- int successCount = list.size();
- int errorCount = errorList.size();
- if (successCount == 0) {
- return "读取失败,未解析到数据";
- } else {
- if (errorList.size() == 0) {
- return StrUtil.format("恭喜您,全部读取成功!共{}条", successCount);
- } else {
- return StrUtil.format("部分读取成功,其中成功{}条,失败{}条,错误信息如下:<br/>{}",
- successCount,
- errorCount,
- CollUtil.join(errorList, "<br/>"));
- }
- }
- }
- }
|