liufumingren
8112430c37
perf(stock.report): 库存报表导出改游标分批+ExcelJS 流式,参考订单导出架构
- 原实现:明细一条大 SQL 全量拉回(货主 1000305 单次 16.9 万行),
SheetJS aoa_to_sheet 全内存构建 490 万单元格后一次性 XLSX.write 序列化,
生产实测总耗时 81.7s(其中 Excel 生成约 30~50s、内存峰值约 2GB),
且进度只有 10/100 两档,中间 80s 零反馈被误判卡死
- 改造(对齐 order_export 流式架构):
1) 明细按主键 id 游标分批拉取(batchSize=5000,走 PRIMARY 索引,
生产实测每批约 95ms、末批不满即止无空探测),行序由 created_at,id
变更为 id 升序(自增序≈插入序)
2) ExcelJS.stream.xlsx.WorkbookWriter 流式落盘(useStyles/useSharedStrings
关闭),逐批行级 commit,内存占用从约 2GB 降到批级
3) 富化映射(商品/货主/条码/入库单/订单/运单)改为按批加载
4) onProgress 每批上报 current_count/total_count,进度 5→95→100 平滑
- excel.js 新增 uploadExistingFile:流式生成场景复用上传链路
(归一化文件名/buildUploadKey/uploadFile/uploadSuccessNotify),
供 WorkbookWriter 落盘后 createReadStream 上传
- systemMethods 层 export/exportStore 接 onProgress 并持久化
current_count/total_count 字段(向前端兼容订单导出进度组件)
- 验证:storage_report_export.test.js 2/2 PASS(12000 行游标 3 批、
进度序列 5/95/100、回读 Excel 校验 sheet/表头/行数/单元格值、
空数据仅表头);生产只读探测 EXPLAIN 走 PRIMARY range、
首尾页约 95ms;ESLint 4 文件 0 error
2026-10-08 19:33:21 +08:00
..
2026-10-08 00:59:56 +08:00
2026-03-16 14:01:22 +08:00
2026-09-10 20:59:39 +08:00
2026-09-24 03:26:15 +08:00
2026-10-08 19:33:21 +08:00
2026-09-15 16:18:39 +08:00
2026-08-31 17:17:48 +08:00
2026-08-01 03:43:47 +08:00
2026-09-17 02:41:43 +08:00
2026-09-30 03:08:27 +08:00
2026-09-15 23:49:34 +08:00
2026-07-27 03:46:51 +08:00
2026-06-23 18:48:33 +08:00
2026-04-09 01:36:49 +08:00
2026-09-24 03:26:21 +08:00
2026-09-25 23:40:56 +08:00
2026-09-18 22:38:57 +08:00
2026-09-25 03:14:15 +08:00
2026-06-14 19:03:58 +08:00
2026-09-20 16:13:59 +08:00
2026-08-12 20:47:19 +08:00
2026-09-20 16:13:59 +08:00
2026-07-29 13:57:04 +08:00
2026-08-31 17:17:48 +08:00
2026-10-06 03:24:36 +08:00
2026-10-06 03:24:36 +08:00
2026-09-15 16:14:46 +08:00
2026-10-06 03:24:36 +08:00
2026-08-15 20:12:26 +08:00
2026-08-04 08:18:43 +08:00
2026-04-09 01:36:49 +08:00
2026-07-06 22:07:10 +08:00
2026-09-23 02:46:28 +08:00
2026-07-10 18:10:11 +08:00
2026-09-24 03:26:08 +08:00
2026-09-21 02:28:04 +08:00