前言

Github:https://github.com/HealerJean

博客:http://blog.healerjean.com

一、本文的简单描述

经常会有需求需要上传excel 导入数据,或者需要下载一些数据明细,那么同步的时候最明显的存在以下2个问题。因此我写了一个简单的异步任务中心

功能 缺点
同步导入: 上传的数据量过大,接口可能导致超时无法同步获取不到上传的结构
同步导出 导出的数据量过大,同样也可能超时导致无法下载明细信息

实现效果

image-20231215132644152

二、任务中心架子

1、任务中心主表

create table `file_task`
(
    `id`             bigint(20)    not null auto_increment comment '主键标识列',
    `user_id`        varchar(64)  not null comment '用户Id',
    `task_id`        varchar(255)  not null comment '任务唯一id',
    `task_type`      varchar(32)   not null comment 'export 导出,import导入',
    `business_type`  varchar(32)   not null comment '业务类型',
    `business_data`  varchar(1024) not null comment '业务请求数据',
    `task_status`    varchar(32)   not null comment 'processing 处理中,completed 完成,fail 失败',
    `result_url`     varchar(1024) not null default '' comment '返回的url地址',
    `result_message` varchar(1024) not null default '' comment '处理结果',
    `url`            varchar(255)  not null default '' comment '上传文件地址',
    `ext`            varchar(1024) not null default '' comment '',
    `created_time`   datetime     not null default current_timestamp comment '记录创建时间',
    `modified_time`  datetime     not null default current_timestamp on update current_timestamp comment '记录最后更新时间',
    primary key (`id`),
    unique key uk_task_id(`task_id`),
    key `idx_user_modified_time` (`user_id`, `modified_time`),
    key `idx_task` (`task_id`),
    key `idx_created_time` (`created_time`),
    key `idx_modified_time` (`modified_time`)
) engine = innodb comment ='文件任务'

2、任务中心工作流程

1)生成一个任务

image-20231215130427658

2)消息监听执行任务

image-20231215130512468

3)任务分发-导入

image-20231215131107760

4)任务分发-导出

image-20231215131200248

三、具体实现

1、任务创建

POST http://localhost:8888/hlj/fileTask/save
{
  "userId": "healerjean",
  "taskType": "export",
  "businessType": "exportDemo",
  "businessData": "{\"phone\": \"1234567\"}",
  "taskStatus": "processing"
}

1)实体对象

a、任务执行结果

package com.healerjean.proj.data.bo;

import com.healerjean.proj.enums.FileTaskEnum;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * FileTaskResultBO
 *
 * @author zhangyujin
 * @date 2023/12/13
 */
@Accessors(chain = true)
@Data
public class FileTaskResultBO implements Serializable {

    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = -7865290338813842668L;

    /**
     * 任务状态
     */
    private FileTaskEnum.TaskStatusEnum taskStatusEnum;

    /**
     * 结果描述
     */
    private String resultDesc;

    /**
     * 任务执行结束待更新数据
     */
    private FileTaskBO updateFileTaskBO;



    /**
     * 执行成功
     */
    public static FileTaskResultBO success(FileTaskBO updateFileTaskBO) {
        return new FileTaskResultBO()
                .setTaskStatusEnum(FileTaskEnum.TaskStatusEnum.COMPLETED)
                .setResultDesc(FileTaskEnum.TaskErrorEnum.SUCCESS.getDesc())
                .setUpdateFileTaskBO(updateFileTaskBO);
    }

    /**
     * 执行失败
     */
    public static FileTaskResultBO fail(FileTaskBO updateFileTaskBO, String errorMsg) {
        return new FileTaskResultBO()
                .setTaskStatusEnum(FileTaskEnum.TaskStatusEnum.FAIL)
                .setResultDesc(errorMsg)
                .setUpdateFileTaskBO(updateFileTaskBO);
    }
}

b、导入检查类

package com.healerjean.proj.data.bo;

import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.List;

/**
 * FileTaskImportCheckResultBO
 *
 * @author zhangyujin
 * @date 2023/12/13
 */
@Accessors(chain = true)
@Data
public class FileTaskImportCheckResultBO<Excel> implements Serializable {
    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = -5763906879585498801L;


    /**
     * 校验结果
     */
    private Boolean checkFlag;

    /**
     * 上传结果描述
     */
    private String resultDesc;

    /**
     * 上传需要导入的数据
     */
    private List<Excel> importExcelList;

    /**
     * 上传结果Excel
     */
    private List<Excel> excelResultList;

}

c、导出检查类

package com.healerjean.proj.data.bo;

import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * FileTaskCheckResultBO
 *
 * @author zhangyujin
 * @date 2023/12/13
 */
@Accessors(chain = true)
@Data
public class FileTaskExportCheckResultBO implements Serializable {

    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = -1852568103843446332L;

    /**
     * 校验结果
     */
    private Boolean checkFlag;

    /**
     * 错误原因
     */
    private String errorMsg;

    /**
     * success
     *
     * @return {@link FileTaskExportCheckResultBO}
     */
    public static FileTaskExportCheckResultBO success() {
        return new FileTaskExportCheckResultBO().setCheckFlag(true);
    }


    /**
     * fail
     *
     * @param errorMsg errorMsg
     * @return {@link FileTaskExportCheckResultBO}
     */
    public static FileTaskExportCheckResultBO fail(String errorMsg) {
        return new FileTaskExportCheckResultBO().setCheckFlag(false).setErrorMsg(errorMsg);
    }
}

2)写excel工具

package com.healerjean.proj.utils.file;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.healerjean.proj.data.excel.UserDemoExportExcel;
import com.healerjean.proj.enums.ExcelEnum;
import com.healerjean.proj.utils.date.DateUtils;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;

/**
 * ExcelWriteResult
 *
 * @author zhangyujin
 * @date 2023/12/13
 */
@Accessors(chain = true)
@Data
public class ExcelWriteUtils implements Serializable {

    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = -7324987042050706041L;


    /**
     * 写入总数量
     */
    private AtomicLong count;

    /**
     * 写入单元格
     */
    private WriteSheet writeSheet;

    /**
     * 写
     */
    private ExcelWriter excelWriter;

    /**
     * 写文件路径
     */
    private String filePath;


    /**
     * ExcelWriteHolderInstance
     *
     * @param excelObjEnum excelObjEnum
     * @return {@link ExcelWriteUtils}
     */
    public static ExcelWriteUtils instance(ExcelEnum.ExcelObjEnum excelObjEnum) {
        String filePath = ExcelUtils.DEFAULT_LOCAL_PATH + DateUtils.toDateString(LocalDateTime.now(), DateUtils.YYYYMMDD) + "/" + excelObjEnum.name().toLowerCase() + "/" + System.currentTimeMillis() + ".xlsx";
        return new ExcelWriteUtils()
                .setCount(new AtomicLong(0))
                .setExcelWriter(EasyExcel.write(filePath, UserDemoExportExcel.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).autoCloseStream(false).build())
                .setWriteSheet(EasyExcel.writerSheet(1, "Sheet1").build())
                .setFilePath(filePath);
    }

    /**
     * close
     */
    public void close() {
        if (excelWriter != null) {
            excelWriter.finish();
        }

        // todo 
        //清除文件
        // FileUtils.cleanFile(new File(filePath));
    }

    /**
     * 写数据
     *
     * @param list list
     */
    public ExcelWriteUtils write(List list) {
        writeSheet.setSheetNo((int) (count.addAndGet(list.size()) / ExcelUtils.EXCEL_SHEET_ROW_MAX_SIZE + 1));
        writeSheet.setSheetName("Sheet" + writeSheet.getSheetNo());
        excelWriter.write(list, writeSheet);
        return this;
    }


}

2、任务执行

1)消息监听 FileTaskListener

package com.healerjean.proj.service.filetask;

import com.alibaba.fastjson.JSON;
import com.healerjean.proj.data.mq.FileTaskMq;
import com.healerjean.proj.enums.FileTaskEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
* FileTaskListener
*
* @author zhangyujin
* @date 2023/12/13
*/
@Slf4j
@Component
public class FileTaskListener {

  /**
   * fileTaskHandlers
   */
  @Resource
  private List<FileTaskHandler> fileTaskHandlers;

  /**
   * execute
   *
   * @param fileTaskMq 对象
   */
  public void execute(FileTaskMq fileTaskMq) {
      FileTaskEnum.BusinessTypeEnum businessTypeEnum = FileTaskEnum.BusinessTypeEnum.toBusinessTypeEnum(fileTaskMq.getBusinessType());
      if (Objects.isNull(businessTypeEnum)) {
          log.error("[FileTaskListener#execute] 非法 businessTypeEnumfileTaskMq:{}", JSON.toJSONString(fileTaskMq));
          return;
      }

      for (FileTaskHandler fileTaskHandler : fileTaskHandlers) {
          boolean match = fileTaskHandler.match(fileTaskMq.getBusinessType());
          if (Boolean.TRUE.equals(match)) {
              try {
                  fileTaskHandler.handler(fileTaskMq.getTaskId());
              } catch (Exception e) {
                  log.error("任务执行异常, fileTaskMq:{}", JSON.toJSONString(fileTaskMq), e);
                  throw new RuntimeException("任务执行异常");
              }
          }
      }
  }
}

3)任务总线 FileTaskHandler

package com.healerjean.proj.service.filetask;

/**
 * FileTaskHandler
 *
 * @author zhangyujin
 * @date 2023/6/26$  19:59$
 */
public interface FileTaskHandler {


    /**
     * handler是否匹配
     *
     * @param businessType businessType
     * @return boolean
     */
    boolean match(String businessType);

    /**
     * 执行任务
     *
     * @param taskId 任务id
     */
    void handler(String taskId) throws Exception;
}

3)抽象任务总线 AbstractFileTaskHandler

package com.healerjean.proj.service.filetask;

import com.healerjean.proj.data.bo.FileTaskBO;
import com.healerjean.proj.data.bo.FileTaskQueryBO;
import com.healerjean.proj.data.bo.FileTaskResultBO;
import com.healerjean.proj.enums.FileTaskEnum;
import com.healerjean.proj.service.FileTaskService;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;
import java.util.Objects;


/**
 * 抽象任务处理
 *
 * @author zhangyujin
 * @date 2023-12-13 02:12:26
 */
@Slf4j
public abstract class AbstractFileTaskHandler implements FileTaskHandler {

    /**
     * fileTaskService
     */
    @Resource
    private FileTaskService fileTaskService;

    /**
     * businessTypeEnum
     */
    private final FileTaskEnum.BusinessTypeEnum businessTypeEnum;

    /**
     * taskTypeEnum
     */
    private final FileTaskEnum.TaskTypeEnum taskTypeEnum;

    /**
     * 抽象类
     *
     * @param businessTypeEnum businessTypeEnum
     */
    public AbstractFileTaskHandler(FileTaskEnum.TaskTypeEnum taskTypeEnum, FileTaskEnum.BusinessTypeEnum businessTypeEnum) {
        this.businessTypeEnum = businessTypeEnum;
        this.taskTypeEnum = taskTypeEnum;

    }

    /**
     * 是否匹配 FileTaskHandler
     *
     * @param businessType businessType
     * @return boolean
     */
    @Override
    public boolean match(String businessType) {
        return businessTypeEnum.getCode().equals(businessType);
    }

    /**
     * handler
     *
     * @param taskId 任务id
     */
    @Override
    public void handler(String taskId) throws Exception {
        FileTaskQueryBO queryBO = new FileTaskQueryBO();
        queryBO.setTaskId(taskId);
        FileTaskBO fileTaskBO = fileTaskService.queryFileTaskSingle(queryBO);
        if (fileTaskBO == null) {
            throw new RuntimeException("任务不存在!" + taskId);
        }
        FileTaskResultBO taskResult = executeTask(fileTaskBO);
        if (Objects.isNull(taskResult)) {
            throw new RuntimeException("任务异常!" + taskId);
        }
        FileTaskEnum.TaskStatusEnum taskStatusEnum = taskResult.getTaskStatusEnum();
        if (Objects.isNull(taskStatusEnum)) {
            throw new RuntimeException("任务Bug异常!" + taskId);
        }
        switch (taskStatusEnum) {
            case COMPLETED:
                log.info("taskTypeEnum:{}, businessTypeEnum:{}, taskId:{}, success", taskTypeEnum, businessTypeEnum, taskId);
                fileTaskService.updateFileTask(taskResult.getUpdateFileTaskBO().setTaskStatus(FileTaskEnum.TaskStatusEnum.COMPLETED.getCode()).setTaskId(fileTaskBO.getTaskId()));
                break;
            case FAIL:
                log.info("taskTypeEnum:{}, businessTypeEnum:{}, taskId:{}, fail, errorMsg:{}", taskTypeEnum, businessTypeEnum, taskId, taskResult.getResultDesc());
                fileTaskService.updateFileTask(taskResult.getUpdateFileTaskBO().setTaskStatus(FileTaskEnum.TaskStatusEnum.FAIL.getCode()).setTaskId(fileTaskBO.getTaskId()).setResultMessage(taskResult.getResultDesc()));
                break;
            default:
                throw new RuntimeException("任务异常!" + taskId);
        }
    }


    /**
     * 执行任务,等待子类实现
     *
     * @param fileTaskBO fileTaskBO
     * @return FileTaskResultBO
     */
    abstract FileTaskResultBO executeTask(FileTaskBO fileTaskBO) throws Exception;

}

3、导出任务

1)导出总线 ExportFileTaskHandler

package com.healerjean.proj.service.filetask;

import com.healerjean.proj.data.bo.FileTaskBO;
import com.healerjean.proj.data.bo.FileTaskExportCheckResultBO;
import com.healerjean.proj.data.bo.FileTaskResultBO;

/**
 * ReadFileTaskHandler
 *
 * @author zhangyujin
 * @date 2023/12/13
 */
public interface ExportFileTaskHandler extends FileTaskHandler {

    /**
     * 校验导出的请求
     *
     * @return FileTaskResultBO
     */
    FileTaskExportCheckResultBO checkExportReq(FileTaskBO fileTask);

    /**
     * 执行导出任务
     *
     * @return FileTaskResultBO
     */
    FileTaskResultBO executeExportTask(FileTaskBO fileTask) throws Exception;
}

2)抽象导出总线

package com.healerjean.proj.service.filetask;

import com.healerjean.proj.data.bo.FileTaskBO;
import com.healerjean.proj.data.bo.FileTaskExportCheckResultBO;
import com.healerjean.proj.data.bo.FileTaskResultBO;
import com.healerjean.proj.enums.FileTaskEnum;

/**
 * 导出抽象控制器
 *
 * @author zhangyujin
 * @date 2023/12/13
 */
public abstract class AbstractExportFileTaskHandler extends AbstractFileTaskHandler implements ExportFileTaskHandler {


    /**
     * 抽象类
     *
     * @param taskTypeEnum     taskTypeEnum
     * @param businessTypeEnum businessTypeEnum
     */
    public AbstractExportFileTaskHandler(FileTaskEnum.TaskTypeEnum taskTypeEnum, FileTaskEnum.BusinessTypeEnum businessTypeEnum) {
        super(taskTypeEnum, businessTypeEnum);
    }

    /**
     * 执行任务,等待子类实现
     *
     * @param fileTaskBo fileTaskBO
     * @return FileTaskResultBO
     */
    public FileTaskResultBO executeTask(FileTaskBO fileTaskBo) throws Exception {
        FileTaskExportCheckResultBO checkResult = checkExportReq(fileTaskBo);
        if (Boolean.FALSE.equals(checkResult.getCheckFlag())) {
            return FileTaskResultBO.fail(new FileTaskBO().setTaskId(fileTaskBo.getTaskId()), checkResult.getErrorMsg());
        }
        return executeExportTask(fileTaskBo);
    }

}

3)具体业务导出实现 ExportDemoFileTaskHandler

package com.healerjean.proj.service.filetask;

import com.healerjean.proj.data.bo.*;
import com.healerjean.proj.data.converter.UserDemoConverter;
import com.healerjean.proj.data.excel.UserDemoExportExcel;
import com.healerjean.proj.data.req.UserDemoQueryReq;
import com.healerjean.proj.enums.ExcelEnum;
import com.healerjean.proj.enums.FileTaskEnum;
import com.healerjean.proj.service.BigDataService;
import com.healerjean.proj.utils.JsonUtils;
import com.healerjean.proj.utils.ThreadPoolUtils;
import com.healerjean.proj.utils.file.ExcelWriteHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.Future;

/**
 * 导出Demo 控制器
 *
 * @author zhangyujin
 * @date 2023/12/13
 */
@Slf4j
@Service
public class ExportDemoFileTaskHandler extends AbstractExportFileTaskHandler {


    /**
     * bigDataService
     */
    @Resource
    private BigDataService bigDataService;


    /**
     * 抽象类
     */
    public ExportDemoFileTaskHandler() {
        super(FileTaskEnum.TaskTypeEnum.EXPORT, FileTaskEnum.BusinessTypeEnum.EXPORT_DEMO);
    }

    /**
     * 校验请求结果
     *
     * @param fileTask fileTask
     * @return FileTaskResultBO
     */
    @Override
    public FileTaskExportCheckResultBO checkExportReq(FileTaskBO fileTask) {
        // todo  不验证,直接通过
        // UserDemoQueryReq fileDemoExportReq = JsonUtils.toObject(fileTask.getBusinessData(), UserDemoQueryReq.class);
        // if (StringUtils.isBlank(fileDemoExportReq.getName())) {
        //     return FileTaskCheckResultBO.fail("name不能为空");
        // }
        return FileTaskExportCheckResultBO.success();
    }

    /**
     * 执行任务
     *
     * @param fileTask fileTask
     * @return {@link FileTaskResultBO}
     */
    @Override
    public FileTaskResultBO executeExportTask(FileTaskBO fileTask) throws Exception {
        UserDemoQueryReq req = JsonUtils.toObject(fileTask.getBusinessData(), UserDemoQueryReq.class);
        UserDemoQueryBO queryBO = UserDemoConverter.INSTANCE.covertUserDemoQueryReqToBo(req);

        // 大数据量-线程池limit查询
        CompletionService<List<UserDemoBO>> completionService = new ExecutorCompletionService<>(ThreadPoolUtils.DEFAULT_THREAD_POOL_TASK_EXECUTOR);
        List<Future<List<UserDemoBO>>> futures = bigDataService.queryAllUserDemoByPoolLimit(completionService, queryBO);
        ExcelWriteHolder excelWriteHolder = ExcelWriteHolder.instance(ExcelEnum.ExcelObjEnum.EXPORT_EXCEL_USER_DEMO);
        for (int i = 0; i < futures.size(); i++) {
            Future<List<UserDemoBO>> future = completionService.take();
            List<UserDemoBO> userDemos = future.get();
            if (CollectionUtils.isEmpty(userDemos)) {
                continue;
            }
            List<UserDemoExportExcel> excels = UserDemoConverter.INSTANCE.covertUserDemoPoToExcelList(userDemos);
            excelWriteHolder.write(excels);
        }
        excelWriteHolder.close();

        // 大数据量-IdSize查询全部
        // List<UserDemoBO> queryAllUserDemoByIdSize = bigDataService.queryAllUserDemoByIdSize(queryBO);
        // ExcelWriteHolder.instance(ExcelEnum.ExcelObjEnum.EXPORT_EXCEL_USER_DEMO).write(UserDemoConverter.INSTANCE.covertUserDemoPoToExcelList(queryAllUserDemoByIdSize)).close();

        // 大数据量-分页查询全部
        // List<UserDemoBO> queryAllUserDemoByLimit = bigDataService.queryAllUserDemoByLimit(queryBO);
        // ExcelWriteHolder.instance(ExcelEnum.ExcelObjEnum.EXPORT_EXCEL_USER_DEMO).write(UserDemoConverter.INSTANCE.covertUserDemoPoToExcelList(queryAllUserDemoByLimit)).close();
        return FileTaskResultBO.success(new FileTaskBO().setTaskId(fileTask.getTaskId()));
    }
}

4、导入任务

1)导入总线

package com.healerjean.proj.service.filetask;

import com.healerjean.proj.data.bo.FileTaskBO;
import com.healerjean.proj.data.bo.FileTaskImportCheckResultBO;
import com.healerjean.proj.data.bo.FileTaskResultBO;
import com.healerjean.proj.data.excel.Excel;

/**
 * 导入任务
 *
 * @author zhangyujin
 * @date 2023/12/13
 */
public interface ImportFileTaskHandler extends FileTaskHandler {

    /**
     * 校验导入的Excel数据
     *
     * @return FileTaskResultBO
     */
    FileTaskImportCheckResultBO checkImportExcel(FileTaskBO fileTask);

    /**
     * 执行导入任务
     *
     * @param fileTaskBO fileTaskBO
     */
    FileTaskResultBO executeImportTask(FileTaskBO fileTaskBO, FileTaskImportCheckResultBO importCheckResult);

}

2)抽象导入总线

package com.healerjean.proj.service.filetask;

import com.healerjean.proj.data.bo.FileTaskBO;
import com.healerjean.proj.data.bo.FileTaskImportCheckResultBO;
import com.healerjean.proj.data.bo.FileTaskResultBO;
import com.healerjean.proj.enums.FileTaskEnum;

/**
 * 导入抽象控制器
 *
 * @author zhangyujin
 * @date 2023/12/13
 */
public abstract class AbstractImportFileTaskHandler extends AbstractFileTaskHandler implements ImportFileTaskHandler {

    /**
     * 抽象类
     *
     * @param taskTypeEnum     taskTypeEnum
     * @param businessTypeEnum businessTypeEnum
     */
    public AbstractImportFileTaskHandler(FileTaskEnum.TaskTypeEnum taskTypeEnum, FileTaskEnum.BusinessTypeEnum businessTypeEnum) {
        super(taskTypeEnum, businessTypeEnum);
    }

    /**
     * executeTask
     * 1、校验上传的excel
     * 2、导入校验通过的数据
     * 3、上传校验完成excel
     *
     * @param fileTaskBo fileTaskBO
     * @return {@link FileTaskResultBO}
     */
    @Override
    public FileTaskResultBO executeTask(FileTaskBO fileTaskBo) throws Exception {
        // 1、校验上传的excel
        FileTaskImportCheckResultBO<?> checkResult = checkImportExcel(fileTaskBo);
        if (Boolean.FALSE.equals(checkResult.getCheckFlag())) {
            return FileTaskResultBO.fail(new FileTaskBO().setTaskId(fileTaskBo.getTaskId()), checkResult.getResultDesc());
        }
        // 2、导入校验通过的数据
        FileTaskResultBO fileTaskResult = executeImportTask(fileTaskBo, checkResult);

        // 3、上传校验完成excel
        fileTaskResult.setResultDesc(checkResult.getResultDesc());
        return fileTaskResult;
    }


}

3)具体业务导出实现 ExportDemoFileTaskHandler

package com.healerjean.proj.service.filetask;

import com.healerjean.proj.data.bo.FileTaskBO;
import com.healerjean.proj.data.bo.FileTaskImportCheckResultBO;
import com.healerjean.proj.data.bo.FileTaskResultBO;
import com.healerjean.proj.data.excel.UserDemoImportExcel;
import com.healerjean.proj.enums.FileTaskEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 导出Demo 控制器
 *
 * @author zhangyujin
 * @date 2023/12/13
 */
@Slf4j
@Service
public class ImportDemoFileTaskHandler extends AbstractImportFileTaskHandler {


    /**
     * AbstractImportFileTaskHandler
     */
    public ImportDemoFileTaskHandler() {
        super(FileTaskEnum.TaskTypeEnum.IMPORT, FileTaskEnum.BusinessTypeEnum.IMPORt_DEMO);
    }

    /**
     * 校验上传的excel表格
     *
     * @param fileTask fileTask
     * @return FileTaskImportCheckResultBO
     */
    @Override
    public FileTaskImportCheckResultBO checkImportExcel(FileTaskBO fileTask) {
        // todo 校验表格
        return new FileTaskImportCheckResultBO<UserDemoImportExcel>();
    }

    /**
     * executeImportTask
     *
     * @param fileTaskBo        fileTaskBO
     * @param importCheckResult importCheckResult
     * @return FileTaskResultBO
     */
    @Override
    public FileTaskResultBO executeImportTask(FileTaskBO fileTaskBo, FileTaskImportCheckResultBO importCheckResult) {
        // todo 导入数据
        List<UserDemoImportExcel> importExcelList = importCheckResult.getImportExcelList();
        return FileTaskResultBO.success(new FileTaskBO().setTaskId(fileTaskBo.getTaskId()));
    }


}

ContactAuthor