Commit 97f873a3 authored by fangxinjiang's avatar fangxinjiang

代码优化-fxj

parent a787f0c5
......@@ -234,9 +234,12 @@ public class TDispatchInfoServiceImpl extends ServiceImpl<TDispatchInfoMapper, T
if (redisLabelMap != null) {
redisLabelMap.putAll(userMap);
}
// 使用 try-with-resources 确保输出流正确关闭
try (ServletOutputStream out = response.getOutputStream()) {
ExcelWriter excelWriter = EasyExcel.write(out, TDispatchInfoExportVo.class)
// 获取输出流
OutputStream out = null;
ExcelWriter excelWriter = null;
try {
out = response.getOutputStream();
excelWriter = EasyExcel.write(out, TDispatchInfoExportVo.class)
.registerConverter(new DictConverter(nameAndDicTypeMap, redisLabelMap))
.includeColumnFieldNames(searchVo.getExportFields())
.build();
......@@ -263,13 +266,19 @@ public class TDispatchInfoServiceImpl extends ServiceImpl<TDispatchInfoMapper, T
excelWriter.write(list, writeSheet);
}
excelWriter.finish();
out.flush();
}
} catch (IOException e) {
log.error("导出文件时发生IO异常", e);
throw new RuntimeException("导出文件失败", e); // 可以根据需要转换为业务异常
} finally {
if (excelWriter != null) {
try {
excelWriter.finish();
} catch (Exception e) {
log.error("关闭ExcelWriter时发生异常", e);
}
}
}
}catch (Exception e) {
log.error("执行导出时发生未知异常", e);
throw new RuntimeException("导出过程中发生错误", e);
} finally {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment