leniu-dev 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/.claude/mysql-config.json +34 -0
  2. package/.claude/skills/jenkins-deploy/SKILL.md +21 -5
  3. package/.claude/skills/jenkins-deploy/assets/jk_build.py +29 -14
  4. package/.claude/skills/leniu-java-amount-handling/SKILL.md +461 -0
  5. package/.claude/skills/leniu-java-export/SKILL.md +570 -0
  6. package/.claude/skills/leniu-java-report-query-param/SKILL.md +291 -0
  7. package/.claude/skills/leniu-java-total-line/SKILL.md +196 -0
  8. package/.claude/skills/leniu-marketing-price-rule-customizer/SKILL.md +301 -0
  9. package/.claude/skills/leniu-marketing-recharge-rule-customizer/SKILL.md +285 -0
  10. package/.claude/skills/leniu-mealtime/SKILL.md +215 -0
  11. package/.claude/skills/leniu-report-customization/SKILL.md +415 -0
  12. package/.claude/skills/leniu-report-customization/references/table-fields.md +93 -0
  13. package/.claude/skills/leniu-report-standard-customization/SKILL.md +391 -0
  14. package/.claude/skills/leniu-report-standard-customization/references/analysis-module.md +64 -0
  15. package/.claude/skills/leniu-report-standard-customization/references/table-fields.md +113 -0
  16. package/.claude/skills/loki-log-query/SKILL.md +25 -55
  17. package/.claude/skills/loki-log-query/environments.json +45 -0
  18. package/.claude/skills/mysql-debug/SKILL.md +6 -12
  19. package/.codex/skills/jenkins-deploy/SKILL.md +21 -5
  20. package/.codex/skills/jenkins-deploy/assets/env_param.template.json +51 -0
  21. package/.codex/skills/jenkins-deploy/assets/jk_build.py +415 -0
  22. package/.codex/skills/leniu-java-export/SKILL.md +570 -0
  23. package/.codex/skills/leniu-java-report-query-param/SKILL.md +291 -0
  24. package/.codex/skills/leniu-java-total-line/SKILL.md +196 -0
  25. package/.codex/skills/leniu-marketing-price-rule-customizer/SKILL.md +301 -0
  26. package/.codex/skills/leniu-marketing-recharge-rule-customizer/SKILL.md +285 -0
  27. package/.codex/skills/leniu-mealtime/SKILL.md +215 -0
  28. package/.codex/skills/leniu-report-customization/SKILL.md +415 -0
  29. package/.codex/skills/leniu-report-customization/references/table-fields.md +93 -0
  30. package/.codex/skills/leniu-report-standard-customization/SKILL.md +391 -0
  31. package/.codex/skills/leniu-report-standard-customization/references/analysis-module.md +64 -0
  32. package/.codex/skills/leniu-report-standard-customization/references/table-fields.md +113 -0
  33. package/.codex/skills/loki-log-query/SKILL.md +25 -55
  34. package/.codex/skills/mysql-debug/SKILL.md +6 -12
  35. package/.cursor/skills/jenkins-deploy/SKILL.md +21 -5
  36. package/.cursor/skills/jenkins-deploy/assets/env_param.template.json +51 -0
  37. package/.cursor/skills/jenkins-deploy/assets/jk_build.py +415 -0
  38. package/.cursor/skills/leniu-java-export/SKILL.md +570 -0
  39. package/.cursor/skills/leniu-java-report-query-param/SKILL.md +291 -0
  40. package/.cursor/skills/leniu-java-total-line/SKILL.md +196 -0
  41. package/.cursor/skills/leniu-marketing-price-rule-customizer/SKILL.md +301 -0
  42. package/.cursor/skills/leniu-marketing-recharge-rule-customizer/SKILL.md +285 -0
  43. package/.cursor/skills/leniu-mealtime/SKILL.md +215 -0
  44. package/.cursor/skills/leniu-report-customization/SKILL.md +415 -0
  45. package/.cursor/skills/leniu-report-customization/references/table-fields.md +93 -0
  46. package/.cursor/skills/leniu-report-standard-customization/SKILL.md +391 -0
  47. package/.cursor/skills/leniu-report-standard-customization/references/analysis-module.md +64 -0
  48. package/.cursor/skills/leniu-report-standard-customization/references/table-fields.md +113 -0
  49. package/.cursor/skills/loki-log-query/SKILL.md +25 -55
  50. package/.cursor/skills/mysql-debug/SKILL.md +6 -12
  51. package/bin/index.js +59 -15
  52. package/package.json +1 -1
  53. package/src/skills/jenkins-deploy/SKILL.md +150 -0
  54. package/src/skills/jenkins-deploy/assets/env_param.template.json +51 -0
  55. package/src/skills/jenkins-deploy/assets/jk_build.py +415 -0
@@ -0,0 +1,570 @@
1
+ ---
2
+ name: leniu-java-export
3
+ description: |
4
+ leniu-tengyun-core / leniu-yunshitang 项目数据导出规范。当实现数据导出功能时使用此skill,包括Excel异步导出和分页导出方案。
5
+
6
+ 触发场景:
7
+ - 实现Excel数据导出(exportApi.startExcelExportTaskByPage)
8
+ - 实现异步导出(数据量大时)
9
+ - 实现分页导出(防内存溢出)
10
+ - 导出API接口设计(@PostMapping("/export"))
11
+
12
+ 适用项目:
13
+ - leniu-tengyun-core:/Users/xujiajun/Developer/gongsi_proj/leniu-api/leniu-tengyun-core
14
+ - leniu-yunshitang:/Users/xujiajun/Developer/gongsi_proj/leniu-api/leniu-tengyun/leniu-yunshitang
15
+
16
+ 触发词:导出、Excel导出、异步导出、分页导出、@ExcelProperty、exportApi、数据导出
17
+ ---
18
+
19
+ # leniu-tengyun-core 数据导出规范
20
+
21
+ ## 项目特征
22
+
23
+ | 特征 | 说明 |
24
+ |------|------|
25
+ | 包名 | `net.xnzn.*` |
26
+ | 异常类 | `LeException` |
27
+ | 导出工具 | `ExportApi.startExcelExportTaskByPage()` |
28
+ | 国际化 | `I18n.getMessage()` |
29
+ | 工具类 | Hutool(CollUtil、BeanUtil 等) |
30
+ | 请求包装 | `LeRequest<T>` |
31
+
32
+ ## 核心组件
33
+
34
+ - **ExportApi**: 导出API接口
35
+ - **EasyExcelUtil**: 同步导出工具(报表 Controller 直接使用)
36
+ - **I18n**: 国际化工具
37
+ - **PageDTO**: 分页参数
38
+ - **ReportConstant**: 报表常量(工作表名称等)
39
+
40
+ ## 两种导出模式
41
+
42
+ | 模式 | 工具 | 适用场景 |
43
+ |------|------|---------|
44
+ | **同步导出** | `EasyExcelUtil.writeExcelByDownLoadIncludeWrite()` | 报表 Controller 直接返回文件流,数据量不大 |
45
+ | **异步分页导出** | `exportApi.startExcelExportTaskByPage()` | 大数据量,任务队列方式 |
46
+ | **异步分页导出(Feign)** | `orderClients.export().startExcelExportTaskByPage()` | 跨模块导出,通过 Feign 客户端 |
47
+
48
+ ## 同步导出(EasyExcelUtil)
49
+
50
+ ```java
51
+ @ApiOperation(value = "流水汇总-同步导出")
52
+ @PostMapping("/export")
53
+ @SneakyThrows
54
+ public void export(@RequestBody LeRequest<ReportAnalysisTurnoverParam> request,
55
+ HttpServletResponse response) {
56
+ ReportAnalysisTurnoverParam param = request.getContent();
57
+
58
+ // 1. 查询数据
59
+ ReportBaseTotalVO<TurnoverVO> result = reportService.pageSummary(param);
60
+
61
+ // 2. 将列表 + 合计行合并(合计行追加到列表末尾)
62
+ List<TurnoverVO> records = result.getResultPage().getRecords();
63
+ CollUtil.addAll(records, result.getTotalLine()); // 合计行是单个 VO 或 List
64
+
65
+ // 3. 直接写出文件流
66
+ EasyExcelUtil.writeExcelByDownLoadIncludeWrite(
67
+ response,
68
+ I18n.getMessage("report.turnover.title"), // 文件名(国际化)
69
+ TurnoverVO.class, // VO 类型
70
+ I18n.getMessage(ReportConstant.REPORT_TITLE_DETAILS), // 工作表名
71
+ records, // 数据列表(含合计行)
72
+ param.getExportCols() // 导出列
73
+ );
74
+ }
75
+ ```
76
+
77
+ **注意事项**:
78
+ - 方法签名必须加 `@SneakyThrows`(`EasyExcelUtil` 抛出受检异常)
79
+ - `HttpServletResponse response` 作为方法参数接收
80
+ - 合计行用 `CollUtil.addAll(records, totalLine)` 追加到列表末尾
81
+ - 若合计行是单个 VO:`records.add(totalLine)` 即可
82
+
83
+ ## 异步分页导出
84
+
85
+ ### 基础导出模板
86
+
87
+ ```java
88
+ @ApiOperation(value = "xxx导出")
89
+ @PostMapping("/export")
90
+ public void export(@RequestBody LeRequest<XxxPageParam> request) {
91
+ XxxPageParam param = request.getContent();
92
+
93
+ // 获取合计行(可选)
94
+ XxxVO totalLine = xxxService.getSummaryTotal(param);
95
+
96
+ // 启动异步导出任务
97
+ exportApi.startExcelExportTaskByPage(
98
+ I18n.getMessage("report.xxx.title"), // 文件名(国际化)
99
+ I18n.getMessage(ReportConstant.REPORT_TITLE_DETAILS), // 工作表名
100
+ XxxVO.class, // 数据类型
101
+ param.getExportCols(), // 导出列
102
+ param.getPage(), // 分页参数
103
+ totalLine, // 合计行(可为null)
104
+ () -> xxxService.pageList(param).getResultPage() // 数据提供者
105
+ );
106
+ }
107
+ ```
108
+
109
+ ### 实际项目示例
110
+
111
+ ```java
112
+ @PostMapping("/purchase/order/export")
113
+ @ApiOperation(value = "采购-采购订单汇总-导出")
114
+ public void exportPurchaseOrder(@RequestBody LeRequest<MonitorPageParam> param) {
115
+ MonitorPageParam content = param.getContent();
116
+
117
+ // 1. 获取合计行
118
+ PurchaseOrderSummaryVO totalLine = monitorSafetyPurchaseService.getPurchaseOrderSummaryTotal(content);
119
+
120
+ // 2. 启动导出任务
121
+ exportApi.startExcelExportTaskByPage(
122
+ I18n.getMessage("school.purchase-order-summary"), // 文件名(国际化)
123
+ I18n.getMessage(ReportConstant.REPORT_TITLE_DETAILS), // 工作表名
124
+ PurchaseOrderSummaryVO.class, // VO类型
125
+ content.getExportCols(), // 导出列
126
+ content.getPage(), // 分页参数
127
+ totalLine, // 合计行
128
+ () -> monitorSafetyPurchaseService.getPurchaseOrderSummary(content).getResultPage()
129
+ );
130
+ }
131
+ ```
132
+
133
+ ## 异步分页导出(Feign 客户端模式)
134
+
135
+ 跨模块导出时,通过 Feign 客户端调用目标模块的导出接口。订单模块导出是典型示例:
136
+
137
+ ```java
138
+ /**
139
+ * 订单导出 Controller(独立拆分,避免与主 Controller 耦合)
140
+ */
141
+ @Slf4j
142
+ @Api(tags = "订单导出")
143
+ @RestController
144
+ @RequestMapping("/web/order/export")
145
+ public class OrderInfoExportWebController {
146
+
147
+ // ✅ 跨模块依赖:通过 Feign 客户端调用,@Lazy 避免循环依赖
148
+ @Autowired
149
+ @Lazy
150
+ private OrderClients orderClients;
151
+
152
+ @ApiOperation(value = "订单导出")
153
+ @PostMapping("/start")
154
+ public void export(@RequestBody LeRequest<OrderDetailWebDTO> request) {
155
+ OrderDetailWebDTO dto = request.getContent();
156
+
157
+ // 转换为内部查询参数
158
+ OrderSearchParam searchParam = dto.convertToOrderSearchParam();
159
+
160
+ // 通过 Feign 客户端启动异步导出任务
161
+ orderClients.export().startExcelExportTaskByPage(
162
+ I18n.getMessage("order.export.title"), // 文件名
163
+ I18n.getMessage(ReportConstant.REPORT_TITLE_DETAILS), // 工作表名
164
+ OrderDetailVO.class, // VO 类型
165
+ dto.getExportCols(), // 导出列
166
+ dto.getPage(), // 分页参数
167
+ null, // 无合计行
168
+ () -> orderClients.order().pageOrder(searchParam) // Lambda 提供数据
169
+ );
170
+ }
171
+ }
172
+ ```
173
+
174
+ **独立 Export Controller 的优点**:
175
+ - 将导出逻辑与查询逻辑解耦
176
+ - 避免单个 Controller 过于庞大
177
+ - `@Autowired @Lazy` 防止 Spring 循环依赖
178
+
179
+ ## VO类导出注解
180
+
181
+ ### 使用@ExcelProperty
182
+
183
+ > ⚠️ **金额字段必须使用 `converter = CustomNumberConverter.class`,禁止用 `@NumberFormat`!**
184
+
185
+ ```java
186
+ import net.xnzn.core.common.export.converter.CustomNumberConverter;
187
+
188
+ @Data
189
+ @ApiModel("xxx导出VO")
190
+ public class XxxVO {
191
+
192
+ @ExcelProperty(value = "ID", index = 0)
193
+ @ApiModelProperty("ID")
194
+ private Long id;
195
+
196
+ @ExcelProperty(value = "名称", index = 1)
197
+ @ApiModelProperty("名称")
198
+ private String name;
199
+
200
+ @ExcelProperty(value = "状态", index = 2)
201
+ @ApiModelProperty("状态")
202
+ private String statusDesc;
203
+
204
+ // ✅ 金额字段:必须用 CustomNumberConverter,框架自动完成分→元转换
205
+ @ExcelProperty(value = "金额(元)", index = 3, converter = CustomNumberConverter.class)
206
+ @ApiModelProperty("金额(分)")
207
+ private BigDecimal amount;
208
+
209
+ @ExcelProperty(value = "创建时间", index = 4)
210
+ @ApiModelProperty("创建时间")
211
+ @DateTimeFormat("yyyy-MM-dd HH:mm:ss")
212
+ private LocalDateTime createTime;
213
+ }
214
+ ```
215
+
216
+ ## 导出参数类
217
+
218
+ ### PageParam包含导出列
219
+
220
+ ```java
221
+ @Data
222
+ @ApiModel("xxx分页查询参数")
223
+ public class XxxPageParam extends ReportBaseParam {
224
+
225
+ @ApiModelProperty(value = "查询条件")
226
+ private String keyword;
227
+
228
+ // 其他查询条件...
229
+ // 导出列 exportCols 和分页 page 已在 ReportBaseParam 基类中定义
230
+ }
231
+ ```
232
+
233
+ ## Service层导出逻辑
234
+
235
+ ### 导出时不分页
236
+
237
+ ```java
238
+ public PageVO<XxxVO> pageList(XxxPageParam param) {
239
+ // 导出时不分页,查询全部数据
240
+ if (CollUtil.isNotEmpty(param.getExportCols())) {
241
+ // 不调用 PageMethod.startPage()
242
+ List<XxxEntity> records = mapper.selectList(param);
243
+ List<XxxVO> voList = BeanUtil.copyToList(records, XxxVO.class);
244
+ return PageVO.of(voList);
245
+ }
246
+
247
+ // 正常分页查询
248
+ PageMethod.startPage(param);
249
+ List<XxxEntity> records = mapper.pageList(param);
250
+ List<XxxVO> voList = BeanUtil.copyToList(records, XxxVO.class);
251
+ return PageVO.of(voList);
252
+ }
253
+ ```
254
+
255
+ ### 带合计行的导出
256
+
257
+ ```java
258
+ // ⚠️ 系统默认在商户库执行,业务查询无需 Executors.readInSystem()
259
+ // Executors.readInSystem() 仅用于需要访问系统库的场景(如全局配置、商户管理)
260
+
261
+ public ReportBaseTotalVO<XxxVO> pageWithTotal(XxxPageParam param) {
262
+ ReportBaseTotalVO<XxxVO> result = new ReportBaseTotalVO<>();
263
+
264
+ // 1. 导出时不查询合计行(避免不必要的性能开销)
265
+ if (CollUtil.isEmpty(param.getExportCols())) {
266
+ XxxVO totalLine = mapper.getSummaryTotal(param);
267
+ result.setTotalLine(totalLine);
268
+ }
269
+
270
+ // 2. 导出时不分页
271
+ if (CollUtil.isNotEmpty(param.getExportCols())) {
272
+ List<XxxVO> list = mapper.getSummaryList(param);
273
+ result.setResultPage(PageVO.of(list));
274
+ } else {
275
+ // 正常分页查询
276
+ PageMethod.startPage(param);
277
+ List<XxxVO> list = mapper.getSummaryList(param);
278
+ result.setResultPage(PageVO.of(list));
279
+ }
280
+
281
+ return result;
282
+ }
283
+ ```
284
+
285
+ ## 导出文件名国际化
286
+
287
+ ### 使用I18n
288
+
289
+ ```java
290
+ // 在 resources/message_zh.properties 中定义
291
+ report.order.title=订单报表
292
+ report.order.sheet=订单明细
293
+
294
+ // 在 resources/message_en.properties 中定义
295
+ report.order.title=Order Report
296
+ report.order.sheet=Order Details
297
+
298
+ // 在代码中使用
299
+ exportApi.startExcelExportTaskByPage(
300
+ I18n.getMessage("report.order.title"), // 订单报表
301
+ I18n.getMessage("report.order.sheet"), // 订单明细
302
+ OrderVO.class,
303
+ param.getExportCols(),
304
+ param.getPage(),
305
+ totalLine,
306
+ () -> orderService.pageList(param).getResultPage()
307
+ );
308
+ ```
309
+
310
+ ## 导出列控制
311
+
312
+ ### 前端传递导出列
313
+
314
+ ```json
315
+ {
316
+ "page": {
317
+ "current": 1,
318
+ "size": 10
319
+ },
320
+ "exportCols": ["id", "name", "status", "amount", "createTime"],
321
+ "keyword": "test"
322
+ }
323
+ ```
324
+
325
+ ### 后端处理导出列
326
+
327
+ ```java
328
+ @PostMapping("/export")
329
+ public void export(@RequestBody LeRequest<XxxPageParam> request) {
330
+ XxxPageParam param = request.getContent();
331
+
332
+ // 校验导出列
333
+ if (CollUtil.isEmpty(param.getExportCols())) {
334
+ throw new LeException("导出列不能为空");
335
+ }
336
+
337
+ // 启动导出任务
338
+ exportApi.startExcelExportTaskByPage(
339
+ I18n.getMessage("report.xxx.title"),
340
+ I18n.getMessage("report.xxx.sheet"),
341
+ XxxVO.class,
342
+ param.getExportCols(), // 传递导出列
343
+ param.getPage(),
344
+ null,
345
+ () -> xxxService.pageList(param).getResultPage()
346
+ );
347
+ }
348
+ ```
349
+
350
+ ## 导出数据转换
351
+
352
+ ### 状态码转换为描述(使用BeanUtil)
353
+
354
+ ```java
355
+ public PageVO<XxxVO> pageList(XxxPageParam param) {
356
+ PageMethod.startPage(param);
357
+ List<XxxEntity> records = mapper.pageList(param);
358
+
359
+ // 转换为VO并处理状态描述(leniu 使用 BeanUtil,不用 MapstructUtils)
360
+ List<XxxVO> voList = records.stream()
361
+ .map(entity -> {
362
+ XxxVO vo = new XxxVO();
363
+ BeanUtil.copyProperties(entity, vo);
364
+
365
+ // 状态码转换为描述
366
+ vo.setStatusDesc(StatusEnum.getByCode(entity.getStatus()).getDesc());
367
+
368
+ return vo;
369
+ })
370
+ .collect(Collectors.toList());
371
+
372
+ return PageVO.of(voList);
373
+ }
374
+ ```
375
+
376
+ ## 常见场景
377
+
378
+ ### 场景1:订单导出
379
+
380
+ ```java
381
+ @ApiOperation(value = "订单导出")
382
+ @PostMapping("/export")
383
+ public void export(@RequestBody LeRequest<OrderPageParam> request) {
384
+ OrderPageParam param = request.getContent();
385
+
386
+ log.info("【导出】订单导出,条件:{}", param);
387
+
388
+ // 获取合计行
389
+ OrderVO totalLine = orderService.getSummaryTotal(param);
390
+
391
+ // 启动导出任务
392
+ exportApi.startExcelExportTaskByPage(
393
+ I18n.getMessage("report.order.title"),
394
+ I18n.getMessage("report.order.sheet"),
395
+ OrderVO.class,
396
+ param.getExportCols(),
397
+ param.getPage(),
398
+ totalLine,
399
+ () -> orderService.pageList(param).getResultPage()
400
+ );
401
+ }
402
+ ```
403
+
404
+ ### 场景2:报表导出
405
+
406
+ ```java
407
+ @ApiOperation(value = "销售报表导出")
408
+ @PostMapping("/export")
409
+ public void export(@RequestBody LeRequest<SalesReportParam> request) {
410
+ SalesReportParam param = request.getContent();
411
+
412
+ log.info("【导出】销售报表导出,日期范围:{} - {}",
413
+ param.getStartDate(), param.getEndDate());
414
+
415
+ // 获取合计行
416
+ SalesReportVO totalLine = reportService.getSummaryTotal(param);
417
+
418
+ // 启动导出任务
419
+ exportApi.startExcelExportTaskByPage(
420
+ I18n.getMessage("report.sales.title"),
421
+ I18n.getMessage("report.sales.sheet"),
422
+ SalesReportVO.class,
423
+ param.getExportCols(),
424
+ param.getPage(),
425
+ totalLine,
426
+ () -> reportService.getSummary(param).getResultPage()
427
+ );
428
+ }
429
+ ```
430
+
431
+ ### 场景3:带权限过滤的导出
432
+
433
+ ```java
434
+ @ApiOperation(value = "数据导出")
435
+ @PostMapping("/export")
436
+ public void export(@RequestBody LeRequest<DataPageParam> request) {
437
+ DataPageParam param = request.getContent();
438
+
439
+ // 获取用户权限
440
+ MgrUserAuthPO authPO = mgrAuthApi.getUserAuthPO();
441
+ ReportDataPermissionParam dataPermission =
442
+ reportDataPermissionService.getDataPermission(authPO);
443
+
444
+ log.info("【导出】数据导出,用户:{}, 权限范围:{}",
445
+ authPO.getUserId(), dataPermission.getCanteenIds());
446
+
447
+ // 启动导出任务(权限过滤在Service层处理)
448
+ exportApi.startExcelExportTaskByPage(
449
+ I18n.getMessage("report.data.title"),
450
+ I18n.getMessage("report.data.sheet"),
451
+ DataVO.class,
452
+ param.getExportCols(),
453
+ param.getPage(),
454
+ null,
455
+ () -> dataService.pageList(param).getResultPage()
456
+ );
457
+ }
458
+ ```
459
+
460
+ ## 导出性能优化
461
+
462
+ ### 1. 限制导出数量
463
+
464
+ ```java
465
+ @PostMapping("/export")
466
+ public void export(@RequestBody LeRequest<XxxPageParam> request) {
467
+ XxxPageParam param = request.getContent();
468
+
469
+ // 查询总数
470
+ long total = xxxService.count(param);
471
+
472
+ // 限制导出数量
473
+ if (total > 100000) {
474
+ throw new LeException("导出数据量过大,请缩小查询范围");
475
+ }
476
+
477
+ // 启动导出任务
478
+ exportApi.startExcelExportTaskByPage(
479
+ I18n.getMessage("report.xxx.title"),
480
+ I18n.getMessage("report.xxx.sheet"),
481
+ XxxVO.class,
482
+ param.getExportCols(),
483
+ param.getPage(),
484
+ null,
485
+ () -> xxxService.pageList(param).getResultPage()
486
+ );
487
+ }
488
+ ```
489
+
490
+ ### 2. 导出数据脱敏
491
+
492
+ ```java
493
+ public PageVO<UserVO> pageList(UserPageParam param) {
494
+ PageMethod.startPage(param);
495
+ List<User> records = mapper.pageList(param);
496
+
497
+ List<UserVO> voList = records.stream()
498
+ .map(user -> {
499
+ UserVO vo = new UserVO();
500
+ BeanUtil.copyProperties(user, vo);
501
+
502
+ // 导出时脱敏
503
+ if (CollUtil.isNotEmpty(param.getExportCols())) {
504
+ vo.setMobile(maskMobile(user.getMobile()));
505
+ vo.setIdCard(maskIdCard(user.getIdCard()));
506
+ }
507
+
508
+ return vo;
509
+ })
510
+ .collect(Collectors.toList());
511
+
512
+ return PageVO.of(voList);
513
+ }
514
+ ```
515
+
516
+ ## 最佳实践
517
+
518
+ ### 1. 导出日志
519
+
520
+ ```java
521
+ @PostMapping("/export")
522
+ public void export(@RequestBody LeRequest<XxxPageParam> request) {
523
+ XxxPageParam param = request.getContent();
524
+
525
+ log.info("【导出】开始导出,文件名:{}, 条件:{}",
526
+ I18n.getMessage("report.xxx.title"), param);
527
+
528
+ exportApi.startExcelExportTaskByPage(
529
+ I18n.getMessage("report.xxx.title"),
530
+ I18n.getMessage("report.xxx.sheet"),
531
+ XxxVO.class,
532
+ param.getExportCols(),
533
+ param.getPage(),
534
+ null,
535
+ () -> xxxService.pageList(param).getResultPage()
536
+ );
537
+
538
+ log.info("【导出】导出任务已启动");
539
+ }
540
+ ```
541
+
542
+ ### 2. 导出权限校验
543
+
544
+ ```java
545
+ @PostMapping("/export")
546
+ public void export(@RequestBody LeRequest<XxxPageParam> request) {
547
+ // 校验导出权限
548
+ if (!hasExportPermission()) {
549
+ throw new LeException("无导出权限");
550
+ }
551
+
552
+ // 启动导出任务
553
+ exportApi.startExcelExportTaskByPage(...);
554
+ }
555
+ ```
556
+
557
+ ## 常见错误
558
+
559
+ | 错误写法 | 正确写法 | 说明 |
560
+ |---------|---------|------|
561
+ | `throw new ServiceException("msg")` | `throw new LeException("msg")` | leniu 项目异常类 |
562
+ | `MapstructUtils.convert(a, B.class)` | `BeanUtil.copyProperties(a, b)` | leniu 使用 Hutool |
563
+ | `@RequestParam` 接收请求 | `@RequestBody LeRequest<T>` | leniu 接口使用 LeRequest 包装 |
564
+ | `import javax.validation.*` | `import jakarta.validation.*` | JDK 21 + Spring Boot 3.x |
565
+ | 不写导出日志 | 写 log.info 记录导出参数 | 便于排查导出问题 |
566
+ | ⛔ `@NumberFormat("#,##0.00")` 用于金额字段 | ✅ `@ExcelProperty(converter = CustomNumberConverter.class)` | `@NumberFormat` 无法完成分→元转换,框架的 `CustomNumberConverter` 才能自动处理 |
567
+ | ⛔ `mapFunc` 参数手动做分→元转换 | ✅ VO 字段加 `converter = CustomNumberConverter.class` | 金额转换在 VO 注解层处理,不在 `startExcelExportTaskByPage` 的 mapFunc 里做 |
568
+ | ⛔ 手写 `EasyExcel.write()` + `List<List<Object>>` | ✅ 使用 `exportApi.startExcelExportTaskByPage()` | 禁止手动拼接行列数据 |
569
+ | ⛔ Service 里手动创建临时 File + `exportApi.createRecord()` | ✅ 使用 `exportApi.startExcelExportTaskByPage()` | 统一使用标准异步分页导出接口 |
570
+ | ⛔ VO 无 `@ExcelProperty` 注解 | ✅ 每个导出字段必须加 `@ExcelProperty("列头")` | 无注解字段不会被导出 |