小工具知识网

当前位置: 首页 > 行业知识 > 微服务超大Excel文件导出方案优化

行业知识

微服务超大Excel文件导出方案优化

2026-11-12 03:28:09 来源:互联网转载

1、在导���Excel时经常会碰到文件过大,导出特别慢

2、微服务限制了请求超时时间,文件过大情况必然超时

优化思路:

1、文件过大时通过文件拆分、打包压缩zip,然后上传到oss,并设置有效期(30天过期)

2、把同步下载改成异步

3、文件生成完成,更新任务状态

4、通过oss的下载链接下载文件

5、多模块复用,只需要实现各自查询Excel业务数据的接口即可

以下是部分参考代码:

public class TxnETExecutor extends AbstractExportTaskExecutor {    private final MposScene mposScene;    private final OssService ossService;    @Override    public boolean support(int taskType) {        return ExportTaskType.MPOS_TXN_BILL_EXPORT.ordinal() == taskType;    }    @Override    public int getFileSize(String reqBody, String audClientId, Long groupId) {        TxnMposBillItemFindReq req = JSON.parseObject(reqBody, TxnMposBillItemFindReq.class);        req.setAudClientId(audClientId);        req.setLoginGroupId(groupId);        req.setPage(1);        req.setPageSize(1);        req.setDiffStatus(true);        Pageable pageable = mposScene.findByChannelBillItem(req);        return pageable.getTotalPages().intValue();    }    public void execute(Long taskId, int fileSize, String reqBody, String audClientId, Long groupId) {        TxnMposBillItemFindReq req = JSON.parseObject(reqBody, TxnMposBillItemFindReq.class);        req.setAudClientId(audClientId);        req.setLoginGroupId(groupId);        req.setPage(1);        req.setDiffStatus(true);        int pageSize = Math.min(fileSize, DEFAULT_PAGE_SIZE);        req.setPageSize(pageSize);        Pageable pageable = mposScene.findByChannelBillItem(req);        Long totalPages = pageable.getTotalPages();        List first = parse(pageable.getItems());        ByteArrayOutputStream outputStream = WebFluxUtils.buildExcelOutputStream(first, null);        if (totalPages 

上一篇:dnf服务器怎么做?

下一篇:NPM缓存清除秘籍,一键操作,轻松解决缓存问题!