|
|
@ -141,6 +141,8 @@ public class QcReportServiceImpl implements QcReportService { |
|
|
|
|
|
|
|
|
// 4. 查询总数 |
|
|
// 4. 查询总数 |
|
|
int totalRowCount = this.qcReportMapper.getIPQCReportCountOptimized(data); |
|
|
int totalRowCount = this.qcReportMapper.getIPQCReportCountOptimized(data); |
|
|
|
|
|
System.out.println("----------------------------"+totalRowCount); |
|
|
|
|
|
|
|
|
if (totalRowCount <= 0) { |
|
|
if (totalRowCount <= 0) { |
|
|
// 处理空数据:写入空Excel(避免客户端收到损坏文件) |
|
|
// 处理空数据:写入空Excel(避免客户端收到损坏文件) |
|
|
writer = EasyExcel.write(out, QcReportIPQCData.class).autoCloseStream(false).build(); |
|
|
writer = EasyExcel.write(out, QcReportIPQCData.class).autoCloseStream(false).build(); |
|
|
@ -154,6 +156,7 @@ public class QcReportServiceImpl implements QcReportService { |
|
|
// 5. 分页参数 |
|
|
// 5. 分页参数 |
|
|
int pageSize = ExcelConstant.PER_WRITE_ROW_COUNT; |
|
|
int pageSize = ExcelConstant.PER_WRITE_ROW_COUNT; |
|
|
int writeCount = (totalRowCount + pageSize - 1) / pageSize; // 优化分页计算 |
|
|
int writeCount = (totalRowCount + pageSize - 1) / pageSize; // 优化分页计算 |
|
|
|
|
|
System.out.println("-----------------"+writeCount); |
|
|
|
|
|
|
|
|
// 6. 线程池(明确配置,避免资源泄漏) |
|
|
// 6. 线程池(明确配置,避免资源泄漏) |
|
|
executor = new ThreadPoolExecutor( |
|
|
executor = new ThreadPoolExecutor( |
|
|
@ -187,7 +190,7 @@ public class QcReportServiceImpl implements QcReportService { |
|
|
// 9. 处理子线程结果(捕获异常) |
|
|
// 9. 处理子线程结果(捕获异常) |
|
|
for (Future<List<QcReportIPQCData>> future : futureList) { |
|
|
for (Future<List<QcReportIPQCData>> future : futureList) { |
|
|
try { |
|
|
try { |
|
|
List<QcReportIPQCData> dataList = future.get(30, TimeUnit.SECONDS); // 单个任务超时 |
|
|
|
|
|
|
|
|
List<QcReportIPQCData> dataList = future.get(180, TimeUnit.SECONDS); // 单个任务超时 |
|
|
if (dataList != null) { |
|
|
if (dataList != null) { |
|
|
writer.write(dataList, sheet); |
|
|
writer.write(dataList, sheet); |
|
|
} |
|
|
} |
|
|
@ -203,13 +206,12 @@ public class QcReportServiceImpl implements QcReportService { |
|
|
out.flush(); |
|
|
out.flush(); |
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
// 增强异常信息,便于排查 |
|
|
|
|
|
throw new RuntimeException("下载QC报表失败: " + e.getMessage(), e); |
|
|
throw new RuntimeException("下载QC报表失败: " + e.getMessage(), e); |
|
|
} finally { |
|
|
} finally { |
|
|
// 10. 按顺序关闭资源(先关闭writer,再关闭流) |
|
|
// 10. 按顺序关闭资源(先关闭writer,再关闭流) |
|
|
if (writer != null) { |
|
|
if (writer != null) { |
|
|
try { |
|
|
try { |
|
|
writer.finish(); // 确保最后关闭writer |
|
|
|
|
|
|
|
|
writer.finish(); |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
e.printStackTrace(); |
|
|
e.printStackTrace(); |
|
|
} |
|
|
} |
|
|
|