[alibaba/easyexcel]第一次导出时,超时

2024-05-24 50 views
3

异常代码

  //根据条件查询项目度量数据列表
        log.error("【度量数据】-开始查询数据库,{}", DateProcessorUtilExtend.formatDateObjectChn(new Date()));
        PageResult<QcProjectMetric> pageResult = this.queryMetricByExample(qcProjectMetricExample, null);
        log.error("【度量数据】-数据库查询结束,{}", DateProcessorUtilExtend.formatDateObjectChn(new Date()));
        List<QcProjectMetric> metricList = pageResult.getData().isEmpty() ? new ArrayList<>() : pageResult.getData();

        log.error("【度量数据】-数据整理,{}", DateProcessorUtilExtend.formatDateObjectChn(new Date()));

        List<QcProjectMetricExport> data = new ArrayList<>();
        for (QcProjectMetric metric : metricList) {
            QcProjectMetricExport export = new QcProjectMetricExport();
            BeanUtils.copyProperties(metric, export);
            data.add(export);
        }
        log.error("【度量数据】-数据转换,{}", DateProcessorUtilExtend.formatDateObjectChn(new Date()));

        //导出至excel
        try (ServletOutputStream out = response.getOutputStream()) {
            log.error("【度量数据】-开启导出流,{}", DateProcessorUtilExtend.formatDateObjectChn(new Date()));

            String fileName = "项目度量数据-" + qcProjectMetricExample.getMetricPeriod().getEquals()
                    + "_" + new SimpleDateFormat("yyyy-MM-dd").format(new Date()) + ".xlsx";
            fileName = URLEncoder.encode(fileName, "UTF-8");
            response.setContentType("multipart/form-data");
            response.setCharacterEncoding("utf-8");
            response.setHeader("Content-disposition", "attachment;filename=" + fileName);
            response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");

            log.error("【度量数据】-开启excel writer 对象,{}", DateProcessorUtilExtend.formatDateObjectChn(new Date()));

            ExcelWriter excelWriter = EasyExcel
                    .write(out, QcProjectMetricExport.class)
                    .build();
            log.error("【度量数据】-开启excel sheet 对象,{}", DateProcessorUtilExtend.formatDateObjectChn(new Date()));

            WriteSheet writeSheet = new WriteSheet();
            writeSheet.setSheetNo(0);
            writeSheet.setSheetName("项目度量数据");
            excelWriter.write(data, writeSheet);

            log.error("【度量数据】-写入sheet,{}", DateProcessorUtilExtend.formatDateObjectChn(new Date()));

            excelWriter.finish();
            out.flush();
            log.error("【度量数据】-关闭流,{}", DateProcessorUtilExtend.formatDateObjectChn(new Date()));

        } catch (Exception e) {
            log.error("【导出失败】", e);
            throw new QcApplyBusinessException("导出失败!");
        }
    }

异常提示 图片

 org.apache.catalina.connector.ClientAbortException: java.io.IOException: Broken pipe
    at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:299)
    at org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:262)
    at org.apache.catalina.connector.CoyoteOutputStream.flush(CoyoteOutputStream.java:118)
    at org.springframework.security.web.util.OnCommittedResponseWrapper$SaveContextServletOutputStream.flush(OnCommittedResponseWrapper.java:514)
    at com.ctsi.ssdc.admin.service.impl.QcProjectMetricServiceImpl.exportMetricByExample(QcProjectMetricServiceImpl.java:825)
    at com.ctsi.ssdc.admin.service.impl.QcProjectMetricServiceImpl$$FastClassBySpringCGLIB$$3f601f1f.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
    at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:88)
    at com.ctsi.ssdc.config.LoggingAspect.logAround(LoggingAspect.java:104)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)

建议描述 只有在第一次导出的时候会出现在这个问题,web端请求超时。数据很少,只有30多条。 这是什么问题。

回答

7

这个不是异常,是因为数据导出太慢了,浏览器关闭了的原因。请确认是否数据量是否很大导致?

2

数据量很少,总共也就30多条。 现在的问题就是第一次导出的时候超时,之后再导出基本上是秒出。

8

你把导出文件名改为英文,试一下

7

数据量很少,总共也就30多条。 现在的问题就是第一次导出的时候超时,之后再导出基本上是秒出。

这个需要多测试下,看下是否关闭那一块有问题。没报错我也不确定