From 7c04ca65bafe01b654a3bb28b304a7eb6e5fe33f Mon Sep 17 00:00:00 2001 From: "han\\hanst" Date: Fri, 15 May 2026 15:17:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=B6=E9=97=B4=E8=BD=AC=E6=8D=A2BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/Impl/MesTidEpcLogServiceImpl.java | 114 ++++++++++-------- .../mapper/pms/MesTidEpcLogMapper.xml | 4 +- 2 files changed, 69 insertions(+), 49 deletions(-) diff --git a/src/main/java/com/xujie/sys/modules/pms/service/Impl/MesTidEpcLogServiceImpl.java b/src/main/java/com/xujie/sys/modules/pms/service/Impl/MesTidEpcLogServiceImpl.java index 96e04b03..e220e6d6 100644 --- a/src/main/java/com/xujie/sys/modules/pms/service/Impl/MesTidEpcLogServiceImpl.java +++ b/src/main/java/com/xujie/sys/modules/pms/service/Impl/MesTidEpcLogServiceImpl.java @@ -32,7 +32,11 @@ import java.net.URLEncoder; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZoneId; import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.format.DateTimeParseException; import java.util.*; import java.util.concurrent.atomic.AtomicLong; import java.util.zip.ZipEntry; @@ -198,41 +202,37 @@ public class MesTidEpcLogServiceImpl extends ServiceImpl【V5版本:真正的流式导出】

* - * + * *

【导出策略】

* - * + * * @param data 查询条件 * @param response HttpServletResponse * @author rqrq @@ -364,14 +384,14 @@ public class MesTidEpcLogServiceImpl extends ServiceImpl【核心原理】

*
    *
  • MyBatis ResultHandler 逐行回调
  • *
  • 每收到一行数据立即写入CSV
  • *
  • 内存中始终只有1行数据
  • *
- * + * * @param data 查询条件 * @param dataTotal 数据总数 * @param response HttpServletResponse @@ -448,7 +468,7 @@ public class MesTidEpcLogServiceImpl extends ServiceImpl【核心原理】

*
    *
  • MyBatis ResultHandler 逐行回调
  • @@ -456,7 +476,7 @@ public class MesTidEpcLogServiceImpl extends ServiceImpl当前CSV达到100万行自动切换到新CSV *
  • 内存中始终只有1行数据
  • *
- * + * * @param data 查询条件 * @param dataTotal 数据总数 * @param response HttpServletResponse @@ -536,10 +556,10 @@ public class MesTidEpcLogServiceImpl extends ServiceImpl【已被V5取代】保留此方法用于对比或回退

*

【调用方式】如需使用,在exportCsv方法中替换exportToZipRealStreaming为此方法

- * + * * @param data 查询条件 * @param dataTotal 数据总数 * @param response HttpServletResponse @@ -549,7 +569,7 @@ public class MesTidEpcLogServiceImpl extends ServiceImpl特点:使用EasyExcel默认配置,支持注解样式

*

预计耗时:50万条约35-40秒

- * + * * @param dataList 数据列表 * @param response HttpServletResponse * @author rqrq @@ -708,10 +728,10 @@ public class MesTidEpcLogServiceImpl extends ServiceImpl特点:关闭自动列宽计算,使用inMemory模式

*

预计耗时:50万条约25-30秒

- * + * * @param dataList 数据列表 * @param response HttpServletResponse * @author rqrq @@ -764,11 +784,11 @@ public class MesTidEpcLogServiceImpl extends ServiceImpl特点:直接写入CSV文本,无Excel格式处理开销

*

预计耗时:50万条约3-5秒

*

注意:CSV无多Sheet支持,大文件用Excel打开可能卡

- * + * * @param dataList 数据列表 * @param response HttpServletResponse * @author rqrq @@ -787,7 +807,7 @@ public class MesTidEpcLogServiceImpl extends ServiceImpl特点:

*
    *
  • 分批查询,每批查完立即写入CSV
  • @@ -882,7 +902,7 @@ public class MesTidEpcLogServiceImpl extends ServiceImpl边查边写,总耗时最短 *
*

预计耗时:50万条约25-30秒(查询+写入并行)

- * + * * @param data 查询条件 * @param dataTotal 数据总数(由调用方传入,避免重复COUNT查询) * @param response HttpServletResponse @@ -976,17 +996,17 @@ public class MesTidEpcLogServiceImpl extends ServiceImpl【V1版本特点】

*
    *
  • 每批查询10万条,查完立即写入Excel
  • *
  • 优点:内存占用小,适合超大数据量
  • *
  • 缺点:IO操作频繁,可能较慢
  • *
- * + * *

【执行流程】

*
    *
  1. 先查询总数,计算需要查询的批次数
  2. @@ -995,13 +1015,13 @@ public class MesTidEpcLogServiceImpl extends ServiceImpl检查当前Sheet是否已满,满了则创建新Sheet *
  3. 循环直到所有批次处理完成
  4. *
- * + * *

【切换方法】

*
    *
  1. 将Controller中调用的 exportCsv 改为 exportCsvOld
  2. *
  3. 或者将本方法内容与 exportCsv 方法内容互换
  4. *
- * + * * @param data 查询条件 * @param response HttpServletResponse * @author rqrq @@ -1056,7 +1076,7 @@ public class MesTidEpcLogServiceImpl extends ServiceImpl records = mesTidEpcLogMapper.searchExportListManual(data, offset, pageSize); @@ -1102,7 +1122,7 @@ public class MesTidEpcLogServiceImpl extends ServiceImpl