ai-engineering-init 1.7.0 → 1.10.0

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 (139) hide show
  1. package/.claude/agents/bug-analyzer.md +103 -0
  2. package/.claude/agents/code-reviewer.md +115 -5
  3. package/.claude/agents/image-reader.md +154 -0
  4. package/.claude/agents/loki-runner.md +80 -0
  5. package/.claude/agents/mysql-runner.md +81 -0
  6. package/.claude/agents/requirements-analyzer.md +162 -0
  7. package/.claude/agents/task-fetcher.md +75 -0
  8. package/.claude/commands/dev.md +29 -0
  9. package/.claude/commands/next.md +31 -1
  10. package/.claude/commands/progress.md +23 -1
  11. package/.claude/hooks/skill-forced-eval.js +46 -62
  12. package/.claude/settings.json +10 -1
  13. package/.claude/skills/api-development/SKILL.md +179 -130
  14. package/.claude/skills/architecture-design/SKILL.md +102 -212
  15. package/.claude/skills/backend-annotations/SKILL.md +166 -220
  16. package/.claude/skills/bug-detective/SKILL.md +225 -186
  17. package/.claude/skills/code-patterns/SKILL.md +127 -244
  18. package/.claude/skills/collaborating-with-codex/SKILL.md +96 -113
  19. package/.claude/skills/crud-development/SKILL.md +226 -307
  20. package/.claude/skills/data-permission/SKILL.md +131 -202
  21. package/.claude/skills/database-ops/SKILL.md +158 -355
  22. package/.claude/skills/error-handler/SKILL.md +224 -285
  23. package/.claude/skills/file-oss-management/SKILL.md +174 -169
  24. package/.claude/skills/git-workflow/SKILL.md +123 -341
  25. package/.claude/skills/json-serialization/SKILL.md +121 -137
  26. package/.claude/skills/performance-doctor/SKILL.md +83 -89
  27. package/.claude/skills/redis-cache/SKILL.md +134 -185
  28. package/.claude/skills/scheduled-jobs/SKILL.md +187 -224
  29. package/.claude/skills/security-guard/SKILL.md +168 -276
  30. package/.claude/skills/sms-mail/SKILL.md +266 -228
  31. package/.claude/skills/social-login/SKILL.md +257 -195
  32. package/.claude/skills/tenant-management/SKILL.md +172 -188
  33. package/.claude/skills/utils-toolkit/SKILL.md +214 -222
  34. package/.claude/skills/websocket-sse/SKILL.md +251 -172
  35. package/.claude/skills/workflow-engine/SKILL.md +178 -250
  36. package/.codex/skills/api-development/SKILL.md +179 -130
  37. package/.codex/skills/architecture-design/SKILL.md +102 -212
  38. package/.codex/skills/backend-annotations/SKILL.md +166 -220
  39. package/.codex/skills/bug-detective/SKILL.md +225 -186
  40. package/.codex/skills/code-patterns/SKILL.md +127 -244
  41. package/.codex/skills/collaborating-with-codex/SKILL.md +96 -113
  42. package/.codex/skills/crud-development/SKILL.md +226 -307
  43. package/.codex/skills/data-permission/SKILL.md +131 -202
  44. package/.codex/skills/database-ops/SKILL.md +158 -355
  45. package/.codex/skills/dev/SKILL.md +476 -131
  46. package/.codex/skills/error-handler/SKILL.md +224 -285
  47. package/.codex/skills/file-oss-management/SKILL.md +174 -169
  48. package/.codex/skills/git-workflow/SKILL.md +123 -341
  49. package/.codex/skills/json-serialization/SKILL.md +121 -137
  50. package/.codex/skills/next/SKILL.md +186 -42
  51. package/.codex/skills/performance-doctor/SKILL.md +83 -89
  52. package/.codex/skills/progress/SKILL.md +147 -76
  53. package/.codex/skills/redis-cache/SKILL.md +134 -185
  54. package/.codex/skills/scheduled-jobs/SKILL.md +187 -224
  55. package/.codex/skills/security-guard/SKILL.md +168 -276
  56. package/.codex/skills/sms-mail/SKILL.md +266 -228
  57. package/.codex/skills/social-login/SKILL.md +257 -195
  58. package/.codex/skills/tenant-management/SKILL.md +172 -188
  59. package/.codex/skills/utils-toolkit/SKILL.md +214 -222
  60. package/.codex/skills/websocket-sse/SKILL.md +251 -172
  61. package/.codex/skills/workflow-engine/SKILL.md +178 -250
  62. package/.cursor/agents/bug-analyzer.md +102 -0
  63. package/.cursor/agents/code-reviewer.md +80 -97
  64. package/.cursor/agents/image-reader.md +154 -0
  65. package/.cursor/agents/loki-runner.md +80 -0
  66. package/.cursor/agents/mysql-runner.md +81 -0
  67. package/.cursor/agents/project-manager.md +1 -1
  68. package/.cursor/agents/requirements-analyzer.md +141 -0
  69. package/.cursor/agents/task-fetcher.md +75 -0
  70. package/.cursor/hooks/cursor-skill-eval.js +66 -6
  71. package/.cursor/skills/api-development/SKILL.md +179 -130
  72. package/.cursor/skills/architecture-design/SKILL.md +102 -212
  73. package/.cursor/skills/backend-annotations/SKILL.md +166 -220
  74. package/.cursor/skills/bug-detective/SKILL.md +225 -186
  75. package/.cursor/skills/code-patterns/SKILL.md +127 -244
  76. package/.cursor/skills/collaborating-with-codex/SKILL.md +96 -113
  77. package/.cursor/skills/crud-development/SKILL.md +226 -307
  78. package/.cursor/skills/data-permission/SKILL.md +131 -202
  79. package/.cursor/skills/database-ops/SKILL.md +158 -355
  80. package/.cursor/skills/error-handler/SKILL.md +224 -285
  81. package/.cursor/skills/file-oss-management/SKILL.md +174 -169
  82. package/.cursor/skills/git-workflow/SKILL.md +123 -341
  83. package/.cursor/skills/json-serialization/SKILL.md +121 -137
  84. package/.cursor/skills/performance-doctor/SKILL.md +83 -89
  85. package/.cursor/skills/redis-cache/SKILL.md +134 -185
  86. package/.cursor/skills/scheduled-jobs/SKILL.md +187 -224
  87. package/.cursor/skills/security-guard/SKILL.md +168 -276
  88. package/.cursor/skills/sms-mail/SKILL.md +266 -228
  89. package/.cursor/skills/social-login/SKILL.md +257 -195
  90. package/.cursor/skills/tenant-management/SKILL.md +172 -188
  91. package/.cursor/skills/utils-toolkit/SKILL.md +214 -222
  92. package/.cursor/skills/websocket-sse/SKILL.md +251 -172
  93. package/.cursor/skills/workflow-engine/SKILL.md +178 -250
  94. package/AGENTS.md +117 -540
  95. package/CLAUDE.md +105 -117
  96. package/README.md +37 -6
  97. package/bin/index.js +5 -1
  98. package/package.json +1 -1
  99. package/src/skills/api-development/SKILL.md +179 -130
  100. package/src/skills/architecture-design/SKILL.md +102 -212
  101. package/src/skills/backend-annotations/SKILL.md +166 -220
  102. package/src/skills/bug-detective/SKILL.md +225 -186
  103. package/src/skills/code-patterns/SKILL.md +127 -244
  104. package/src/skills/collaborating-with-codex/SKILL.md +96 -113
  105. package/src/skills/crud-development/SKILL.md +226 -307
  106. package/src/skills/data-permission/SKILL.md +131 -202
  107. package/src/skills/database-ops/SKILL.md +158 -355
  108. package/src/skills/error-handler/SKILL.md +224 -285
  109. package/src/skills/file-oss-management/SKILL.md +174 -169
  110. package/src/skills/git-workflow/SKILL.md +123 -341
  111. package/src/skills/json-serialization/SKILL.md +121 -137
  112. package/src/skills/performance-doctor/SKILL.md +83 -89
  113. package/src/skills/redis-cache/SKILL.md +134 -185
  114. package/src/skills/scheduled-jobs/SKILL.md +187 -224
  115. package/src/skills/security-guard/SKILL.md +168 -276
  116. package/src/skills/sms-mail/SKILL.md +266 -228
  117. package/src/skills/social-login/SKILL.md +257 -195
  118. package/src/skills/tenant-management/SKILL.md +172 -188
  119. package/src/skills/utils-toolkit/SKILL.md +214 -222
  120. package/src/skills/websocket-sse/SKILL.md +251 -172
  121. package/src/skills/workflow-engine/SKILL.md +178 -250
  122. package/.claude/skills/skill-creator/LICENSE.txt +0 -202
  123. package/.claude/skills/skill-creator/SKILL.md +0 -479
  124. package/.claude/skills/skill-creator/agents/analyzer.md +0 -274
  125. package/.claude/skills/skill-creator/agents/comparator.md +0 -202
  126. package/.claude/skills/skill-creator/agents/grader.md +0 -223
  127. package/.claude/skills/skill-creator/assets/eval_review.html +0 -146
  128. package/.claude/skills/skill-creator/eval-viewer/generate_review.py +0 -471
  129. package/.claude/skills/skill-creator/eval-viewer/viewer.html +0 -1325
  130. package/.claude/skills/skill-creator/references/schemas.md +0 -430
  131. package/.claude/skills/skill-creator/scripts/__init__.py +0 -0
  132. package/.claude/skills/skill-creator/scripts/aggregate_benchmark.py +0 -401
  133. package/.claude/skills/skill-creator/scripts/generate_report.py +0 -326
  134. package/.claude/skills/skill-creator/scripts/improve_description.py +0 -248
  135. package/.claude/skills/skill-creator/scripts/package_skill.py +0 -136
  136. package/.claude/skills/skill-creator/scripts/quick_validate.py +0 -103
  137. package/.claude/skills/skill-creator/scripts/run_eval.py +0 -310
  138. package/.claude/skills/skill-creator/scripts/run_loop.py +0 -332
  139. package/.claude/skills/skill-creator/scripts/utils.py +0 -47
@@ -1,22 +1,8 @@
1
- ---
2
- name: next
3
- description: |
4
- 当需要获取项目开发的下一步建议、规划开发方向时自动使用此 Skill。
5
-
6
- 触发场景:
7
- - 不知道下一步应该做什么
8
- - 需要获取开发优先级建议
9
- - 需要分析当前项目状态并给出建议
10
- - 需要规划开发工作方向
11
-
12
- 触发词:下一步、next、建议、做什么、开发方向、优先级、工作建议、开发建议
13
- ---
14
-
15
1
  # /next - 下一步建议
16
2
 
17
3
  作为项目开发顾问,根据当前项目状态,为您建议下一步应该做什么。
18
4
 
19
- ## 🎯 执行流程
5
+ ## 执行流程
20
6
 
21
7
  ### 第一步:快速扫描项目状态
22
8
 
@@ -25,39 +11,55 @@ description: |
25
11
  git log -5 --oneline
26
12
 
27
13
  # 扫描所有业务模块中的 TODO/FIXME
28
- Grep pattern: "TODO:|FIXME:" path: ruoyi-modules/ glob: "*.java" output_mode: content -B 2
14
+ Grep pattern: "TODO:|FIXME:" path: sys-canteen/,sys-kitchen/,sys-drp/,sys-common/ glob: "*.java" output_mode: content -B 2
15
+
16
+ # 检查代码规范问题
17
+ Grep pattern: "package org\.dromara\.|package com\.ruoyi\." path: sys-canteen/,sys-kitchen/,sys-drp/ glob: "*.java" output_mode: files_with_matches
18
+ Grep pattern: "MapstructUtils|ServiceException" path: sys-canteen/,sys-kitchen/,sys-drp/ glob: "*.java" output_mode: files_with_matches
29
19
 
30
- # 检查代码规范和问题
31
- Grep pattern: "package com\.ruoyi\.|BeanUtil\.copy" path: ruoyi-modules/ glob: "*.java" output_mode: files_with_matches
20
+ # 扫描 OpenSpec 活跃变更(如果存在 openspec 目录)
21
+ Glob pattern: "openspec/changes/*/tasks.md"
22
+ # 对每个找到的 tasks.md,读取内容检查任务完成状态([ ] 未完成 / [x] 已完成)
32
23
  ```
33
24
 
34
25
  ### 第二步:分析开发阶段
35
26
 
27
+ 根据代码完整性和功能数量判断:
28
+
36
29
  | 阶段 | 特征 | 功能完成率 |
37
30
  |------|------|----------|
38
31
  | 🟢 初期 | 基础框架搭建,功能模块较少 | < 30% |
39
32
  | 🟡 中期 | 核心功能开发中,模块逐步完善 | 30-70% |
40
33
  | 🔴 后期 | 功能基本完成,处于优化阶段 | > 70% |
41
34
 
42
- ### 第三步:分类问题和建议
35
+ ### 第三步:分析 OpenSpec 变更状态(如有)
36
+
37
+ 如果发现 `openspec/changes/` 下有活跃变更:
38
+
39
+ 1. 读取每个变更的 `tasks.md`,统计未完成任务
40
+ 2. 读取 `proposal.md` 获取变更概述
41
+ 3. 将未完成的 OpenSpec 任务纳入建议优先级
42
+
43
+ ### 第四步:分类问题和建议
43
44
 
44
45
  - **紧急问题**:安全漏洞、严重 Bug、编译错误
46
+ - **OpenSpec 待实现**:已拆解但未完成的变更任务
45
47
  - **重要问题**:功能缺陷、设计问题、规范问题
46
48
  - **优化建议**:性能优化、代码重构、文档完善
47
49
 
48
50
  ---
49
51
 
50
- ## 📊 输出格式
52
+ ## 输出格式
51
53
 
52
54
  ```markdown
53
- # 🎯 下一步建议
55
+ # 下一步建议
54
56
 
55
57
  **分析时间**:YYYY-MM-DD HH:mm
56
58
  **分析范围**:全量后端代码
57
59
 
58
60
  ---
59
61
 
60
- ## 📌 当前状态
62
+ ## 当前状态
61
63
 
62
64
  ### Git 提交分析
63
65
  - **最近一次提交**:[commit message] ([commit hash])
@@ -66,64 +68,197 @@ Grep pattern: "package com\.ruoyi\.|BeanUtil\.copy" path: ruoyi-modules/ glob: "
66
68
 
67
69
  ### 代码状态
68
70
  - **开发阶段**:🟡 中期(核心功能开发中)
69
- - **代码质量**:良好(无 com.ruoyi 包名问题)
70
- - **规范问题**:3 个接口缺少 @SaCheckPermission 注解
71
+ - **代码质量**:良好(包名符合 net.xnzn.core.*)
72
+ - **规范问题**:3 个接口缺少 @RequiresAuthentication 注解
71
73
 
72
74
  ### 代码待办统计
73
75
  - **TODO 项**:X 个
74
76
  - **FIXME 项**:X 个
75
77
  - **编译/运行错误**:无
76
78
 
79
+ ### OpenSpec 变更状态(如有活跃变更)
80
+ - **活跃变更**:X 个
81
+ - **待实现任务**:X 个
82
+ - **变更列表**:
83
+ - `[变更名]`:X/Y 任务完成([proposal 概述])
84
+
77
85
  ---
78
86
 
79
- ## 🚀 建议优先级
87
+ ## 建议优先级
80
88
 
81
89
  ### 🔴 高优先级(必须立即处理)
82
90
 
83
91
  1. **修复 FIXME 问题**
84
- - 位置:ruoyi-demo/PaymentService.java:156
85
- - 问题:退款金额计算错误
92
+ - 位置:sys-canteen/.../service/impl/XxxService.java:156
93
+ - 问题:业务逻辑存在已知错误
94
+ - 原因:影响核心业务正确性
95
+ - 影响:可能导致数据异常
86
96
  - **快速修复**:`/check` 找出所有 FIXME 并逐一解决
87
97
 
88
98
  2. **补充缺失的权限注解**
89
- - 位置:ruoyi-demo 模块 3 个接口
90
- - **快速修复**:`/check demo` 查出所有问题接口
99
+ - 位置:sys-canteen 模块 3 个接口
100
+ - 问题:缺少 @RequiresAuthentication 或 @RequiresGuest 注解
101
+ - 原因:权限控制不完整
102
+ - 影响:系统存在未授权访问风险
103
+ - **快速修复**:`/check canteen` 查出所有问题接口
104
+
105
+ 3. **完善代码规范**
106
+ - 问题:部分接口 POST 请求未使用 LeRequest<T> 封装
107
+ - 原因:请求封装规范不一致
108
+ - 影响:后续维护成本高
109
+ - **快速修复**:`/check` 全量检查
91
110
 
92
111
  ### 🟡 中优先级(近期应该做)
93
112
 
94
113
  1. **补充缺失功能模块**
95
- - **快速开发**:`/crud Payment` 快速生成 CRUD 代码
114
+ - 建议模块:[根据扫描结果列出未完成的业务模块]
115
+ - 完成率:目前 X%,建议提升到 80%
116
+ - **快速开发**:`/crud [表名]` 快速生成 CRUD 代码
96
117
 
97
118
  2. **优化 Service 查询层**
98
- - **参考代码**:ruoyi-system/SysNoticeServiceImpl.java
119
+ - 建议模块:[根据扫描结果列出查询不完善的模块]
120
+ - 问题:buildWrapper 查询条件需要完善
121
+ - 价值:提升查询效率,支持更复杂的搜索
122
+ - **参考代码**:`sys-canteen/.../order/common/service/impl/OrderInfoService.java`
123
+
124
+ 3. **补充接口文档注释**
125
+ - 建议范围:所有 Controller 接口
126
+ - 目标:添加 @Api、@ApiOperation Swagger 文档注解、JavaDoc 方法注释
127
+ - 价值:便于接口文档自动生成
99
128
 
100
129
  ### 🟢 低优先级(可以考虑)
101
130
 
102
131
  1. **性能优化**
132
+ - 建议项:添加查询缓存、分页优化
133
+ - 触发条件:数据量大时
134
+
103
135
  2. **代码重构**
136
+ - 建议项:提取通用工具类、统一错误处理
137
+
104
138
  3. **单元测试**
139
+ - 建议项:为核心 Service 添加单元测试
140
+ - 触发条件:功能稳定后
105
141
 
106
142
  ---
107
143
 
108
- ## 💡 具体行动建议
144
+ ## 具体行动建议
145
+
146
+ ### 如果有未完成的 OpenSpec 变更:
147
+
148
+ **推荐:继续实现已拆解的任务**
149
+ - 变更名称:`[change-name]`
150
+ - 未完成任务:[列出 tasks.md 中 [ ] 的任务]
151
+ - **快速开始**:
152
+ ```bash
153
+ /opsx:apply [change-name] # 自动实现下一个任务
154
+ /dev [任务描述] # 手动实现特定任务
155
+ ```
109
156
 
110
157
  ### 如果您想继续开发新功能:
111
158
 
112
- ```bash
113
- /crud Payment # 快速生成 Payment 模块
114
- /check business # 检查并修复规范问题
115
- ```
159
+ **推荐 1:完善业务模块**
160
+ - 建议实现:[根据扫描结果列出未完成的功能]
161
+ - 所属模块:[sys-canteen / sys-kitchen / sys-drp / sys-common]
162
+ - **快速开始**:
163
+ ```bash
164
+ /crud [表名] # 快速生成 CRUD 代码
165
+ /check [模块名] # 检查并修复规范问题
166
+ ```
167
+
168
+ **推荐 2:开发新的业务功能**
169
+ - 建议实现:[根据项目进展推荐下一个业务功能]
170
+ - **快速开始**:
171
+ ```bash
172
+ /dev 功能名称 # 使用向导开发新功能(含表设计)
173
+ ```
116
174
 
117
175
  ### 如果您想优化代码质量:
118
176
 
119
- ```bash
120
- /check # 全量检查
121
- /check business # 按模块检查
122
- ```
177
+ **推荐 1:规范检查和修复**
178
+ - 建议优化:修复所有代码规范问题
179
+ - **快速检查**:
180
+ ```bash
181
+ /check # 全量检查
182
+ /check canteen # 按模块检查
183
+ ```
184
+
185
+ **推荐 2:Service 层优化**
186
+ - 建议优化:完善 buildWrapper 实现,支持更复杂的查询
187
+ - **参考代码**:`sys-canteen/.../order/common/service/impl/OrderInfoService.java`
188
+
189
+ **推荐 3:注释和文档**
190
+ - 建议优化:添加 JavaDoc 注释
191
+ - 位置:所有 Controller 接口和关键 Service 方法
192
+
193
+ ### 如果您想修复现存问题:
194
+
195
+ **按严重程度排序的问题列表**:
196
+
197
+ #### 🔴 严重问题(立即修复)
198
+ - **FIXME 问题**:[根据扫描结果列出 FIXME 位置和内容]
199
+ - **权限注解缺失**:[根据扫描结果列出缺少 @RequiresAuthentication 的接口]
200
+ - **命令**:`/check [模块名]`
201
+
202
+ #### 🟡 重要问题(本周修复)
203
+ - **LeRequest 封装缺失**:[根据扫描结果列出未使用 LeRequest<T> 的 POST 接口]
204
+ - **del_flag 值错误**:[扫描是否有 delFlag=0 的设置]
205
+ - **命令**:`/check [模块名]`
206
+
207
+ #### 🟢 建议问题(择机修复)
208
+ - **缺少接口文档**:所有 Controller
209
+ - **缺少业务注释**:部分 Service 方法
210
+ - **命令**:逐一完善
211
+
212
+ ---
213
+
214
+ ## 开发建议
215
+
216
+ ### 开发流程建议
217
+
218
+ 1. **明确需求**:使用 `/start` 快速了解项目结构
219
+ 2. **检查规范**:使用 `/check` 检查代码质量
220
+ 3. **分析进度**:使用 `/progress` 了解完成情况
221
+ 4. **开始开发**:使用 `/dev` 或 `/crud` 快速生成代码
222
+ 5. **添加待办**:使用 `/add-todo` 跟踪任务
223
+ 6. **获取建议**:使用 `/next` 确定下一步方向
224
+
225
+ ### 最佳实践
226
+
227
+ | 实践 | 说明 |
228
+ |------|------|
229
+ | 四层职责清晰 | Controller 路由 → Business 编排 → Service 单表 → Mapper ORM |
230
+ | 查询构建 | 在 Service 层用 LambdaQueryWrapper 构建,禁止在 Controller 层 |
231
+ | 对象转换 | 使用 BeanUtil.copyProperties(),禁止 MapstructUtils |
232
+ | 权限管理 | 所有接口必须有 @RequiresAuthentication 或 @RequiresGuest |
233
+ | 请求封装 | POST 请求体统一使用 LeRequest<T>,通过 request.getContent() 获取参数 |
234
+ | 注释完整 | 关键方法必须有 JavaDoc 注释 |
235
+ | 定期检查 | 每周至少一次运行 `/check` 和 `/progress` |
236
+
237
+ ### 技术选型建议
238
+
239
+ | 场景 | 推荐方案 | 理由 |
240
+ |------|--------|------|
241
+ | 快速生成 CRUD | `/crud` 命令 | 已有表结构时最快 |
242
+ | 从零开发功能 | `/dev` 命令 | 包含数据库设计和代码生成 |
243
+ | 代码规范检查 | `/check` 命令 | 及时发现问题 |
244
+ | 项目进度追踪 | `/progress` 命令 | 定期了解完成情况 |
123
245
 
124
246
  ---
125
247
 
126
- ## 🔗 相关命令
248
+ ## 需要确认的问题
249
+
250
+ ### 如果不确定下一步方向,请回答:
251
+
252
+ - [ ] **您更希望继续开发功能,还是优化现有代码?**
253
+ - 选项 A:继续开发新功能(推荐 `/crud` 或 `/dev` 命令)
254
+ - 选项 B:优化现有代码(推荐 `/check` 和 `/progress` 命令)
255
+
256
+ - [ ] **是否需要为新开发的功能添加到待办列表中?**
257
+ - 可使用 `/add-todo` 快速添加
258
+
259
+ ---
260
+
261
+ ## 相关命令
127
262
 
128
263
  | 命令 | 用途 | 何时使用 |
129
264
  |------|------|---------|
@@ -134,4 +269,13 @@ Grep pattern: "package com\.ruoyi\.|BeanUtil\.copy" path: ruoyi-modules/ glob: "
134
269
  | `/dev` | 开发新功能 | 从零开始开发 |
135
270
  | `/crud` | 快速生成代码 | 表已存在时 |
136
271
  | `/add-todo` | 添加待办任务 | 跟踪任务 |
137
- ```
272
+
273
+ ---
274
+
275
+ ## 说明
276
+
277
+ - 本建议基于对当前项目代码的分析生成
278
+ - 建议具体且可执行,不空泛
279
+ - 会考虑开发的连贯性和代码质量
280
+ - 如发现紧急问题会明确标注
281
+ - 如不确定用户意图会主动询问
@@ -10,9 +10,8 @@ description: |
10
10
  - 分页查询优化
11
11
  - N+1 查询问题
12
12
  - 批量操作超时
13
- - 多租户查询优化
14
13
 
15
- 触发词:性能优化、慢查询、SQL优化、索引优化、缓存、Redis缓存、N+1、分页优化、EXPLAIN、响应慢、批量操作、多租户优化
14
+ 触发词:性能优化、慢查询、SQL优化、索引优化、缓存、Redis缓存、N+1、分页优化、EXPLAIN、响应慢、批量操作
16
15
 
17
16
  注意:如果是排查功能性 Bug(代码报错、逻辑错误),请使用 bug-detective。
18
17
  ---
@@ -23,7 +22,7 @@ description: |
23
22
 
24
23
  ```
25
24
  1. 定位 -> 接口层面(响应时间) / SQL层面(慢查询) / 缓存层面(命中率)
26
- 2. 分析 -> p6spy SQL 日志 / Arthas JVM 诊断 / 日志分析
25
+ 2. 分析 -> SQL 日志 / Arthas JVM 诊断 / 日志分析
27
26
  3. 优化 -> 索引 / 缓存 / 批量处理
28
27
  4. 验证 -> 对比优化前后指标
29
28
  ```
@@ -33,51 +32,46 @@ description: |
33
32
  | 指标 | 良好 | 需优化 | 工具 |
34
33
  |------|------|--------|------|
35
34
  | 接口响应 | < 200ms | > 500ms | p6spy/SkyWalking |
36
- | 数据库查询 | < 50ms | > 200ms | p6spy SQL 日志 |
35
+ | 数据库查询 | < 50ms | > 200ms | SQL 日志 |
37
36
  | 内存使用 | < 70% | > 85% | Arthas/JVM 监控 |
38
37
 
39
38
  ---
40
39
 
41
40
  ## 1. MyBatis-Plus 查询优化
42
41
 
43
- > 源码:`ruoyi-modules/ruoyi-demo/.../TestDemoServiceImpl.java:62-73`
44
-
45
42
  ### 查询构建规范
46
43
 
47
44
  ```java
48
45
  import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
49
46
  import com.baomidou.mybatisplus.core.toolkit.Wrappers;
50
47
 
51
- private LambdaQueryWrapper<TestDemo> buildQueryWrapper(TestDemoBo bo) {
52
- Map<String, Object> params = bo.getParams();
53
- LambdaQueryWrapper<TestDemo> lqw = Wrappers.lambdaQuery();
54
- lqw.eq(bo.getDeptId() != null, TestDemo::getDeptId, bo.getDeptId());
55
- lqw.like(StringUtils.isNotBlank(bo.getTestKey()), TestDemo::getTestKey, bo.getTestKey());
56
- lqw.between(params.get("beginCreateTime") != null && params.get("endCreateTime") != null,
57
- TestDemo::getCreateTime, params.get("beginCreateTime"), params.get("endCreateTime"));
48
+ private LambdaQueryWrapper<XxxEntity> buildQueryWrapper(XxxQueryDTO query) {
49
+ LambdaQueryWrapper<XxxEntity> lqw = Wrappers.lambdaQuery();
50
+ lqw.eq(query.getDeptId() != null, XxxEntity::getDeptId, query.getDeptId());
51
+ lqw.like(StrUtil.isNotBlank(query.getKeyword()), XxxEntity::getName, query.getKeyword());
52
+ lqw.between(query.getStartTime() != null && query.getEndTime() != null,
53
+ XxxEntity::getCreateTime, query.getStartTime(), query.getEndTime());
58
54
  return lqw;
59
55
  }
60
56
  ```
61
57
 
62
58
  ### 更新构建规范
63
59
 
64
- > 源码:`ruoyi-modules/ruoyi-system/.../SysUserServiceImpl.java:383-404`
65
-
66
60
  ```java
67
61
  import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
68
62
 
69
63
  // 精确更新
70
64
  baseMapper.update(null,
71
- new LambdaUpdateWrapper<SysUser>()
72
- .set(SysUser::getStatus, status)
73
- .eq(SysUser::getUserId, userId));
65
+ new LambdaUpdateWrapper<XxxEntity>()
66
+ .set(XxxEntity::getStatus, status)
67
+ .eq(XxxEntity::getId, id));
74
68
 
75
69
  // 条件更新(非null才设置)
76
70
  baseMapper.update(null,
77
- new LambdaUpdateWrapper<SysUser>()
78
- .set(ObjectUtil.isNotNull(user.getNickName()), SysUser::getNickName, user.getNickName())
79
- .set(SysUser::getPhonenumber, user.getPhonenumber())
80
- .eq(SysUser::getUserId, user.getUserId()));
71
+ new LambdaUpdateWrapper<XxxEntity>()
72
+ .set(ObjectUtil.isNotNull(entity.getName()), XxxEntity::getName, entity.getName())
73
+ .set(XxxEntity::getPhone, entity.getPhone())
74
+ .eq(XxxEntity::getId, entity.getId()));
81
75
  ```
82
76
 
83
77
  ### 批量更新
@@ -94,15 +88,15 @@ Db.updateBatchById(entityList);
94
88
  ### N+1 查询修复
95
89
 
96
90
  ```java
97
- // 错误:循环查询
91
+ // 错误:循环查询
98
92
  for (Order order : orders) {
99
93
  User user = userMapper.selectById(order.getUserId());
100
94
  }
101
95
 
102
- // 正确:批量查询 + Map 映射
96
+ // 正确:批量查询 + Map 映射
103
97
  List<Long> userIds = orders.stream().map(Order::getUserId).distinct().toList();
104
98
  Map<Long, User> userMap = userMapper.selectBatchIds(userIds).stream()
105
- .collect(Collectors.toMap(User::getUserId, Function.identity()));
99
+ .collect(Collectors.toMap(User::getId, Function.identity()));
106
100
  for (Order order : orders) {
107
101
  User user = userMap.get(order.getUserId());
108
102
  }
@@ -112,17 +106,21 @@ for (Order order : orders) {
112
106
 
113
107
  ## 2. 缓存优化
114
108
 
115
- > 源码:`ruoyi-common/ruoyi-common-redis/.../RedisUtils.java`
116
-
117
- ### RedisUtils 操作
109
+ ### Redisson 缓存操作
118
110
 
119
111
  ```java
120
- import org.dromara.common.redis.utils.RedisUtils;
112
+ import org.redisson.api.RedissonClient;
113
+ import org.redisson.api.RBucket;
114
+
115
+ // 设置缓存
116
+ RBucket<UserVo> bucket = redissonClient.getBucket("user:" + id);
117
+ bucket.set(userVo, Duration.ofMinutes(30));
121
118
 
122
- RedisUtils.setCacheObject("user:" + id, userVo, Duration.ofMinutes(30));
123
- UserVo cached = RedisUtils.getCacheObject("user:" + id);
124
- RedisUtils.deleteObject("user:" + id);
125
- boolean exists = RedisUtils.isExistsObject("user:" + id);
119
+ // 获取缓存
120
+ UserVo cached = redissonClient.<UserVo>getBucket("user:" + id).get();
121
+
122
+ // 删除缓存
123
+ redissonClient.getBucket("user:" + id).delete();
126
124
  ```
127
125
 
128
126
  ### Spring Cache 注解
@@ -137,40 +135,42 @@ public int update(UserBo bo) { ... }
137
135
 
138
136
  > **@Cacheable 禁止返回不可变集合**(`List.of()`、`Set.of()`),Redis 反序列化会失败。必须用 `new ArrayList<>(List.of(...))`。
139
137
 
140
- ### 分布式锁(Lock4j)
141
-
142
- > 源码:`ruoyi-modules/ruoyi-demo/.../RedisLockController.java:47-67`
138
+ ### 分布式锁
143
139
 
144
140
  ```java
145
- import com.baomidou.lock.annotation.Lock4j;
146
- import com.baomidou.lock.LockTemplate;
147
- import com.baomidou.lock.LockInfo;
148
- import com.baomidou.lock.executor.RedissonLockExecutor;
149
-
150
- // 注解方式(推荐)
151
- @Lock4j(keys = {"#key"}, expire = 60000, acquireTimeout = 3000)
152
- public void doSomething(String key) { ... }
153
-
154
- // 编程方式
155
- LockInfo lockInfo = lockTemplate.lock(key, 30000L, 5000L, RedissonLockExecutor.class);
156
- if (null == lockInfo) {
157
- throw new ServiceException("业务处理中,请稍后再试");
158
- }
141
+ import org.redisson.api.RLock;
142
+
143
+ // 注入 RedissonClient
144
+ RLock lock = redissonClient.getLock("lock:order:" + orderId);
159
145
  try {
160
- // 业务逻辑
161
- } finally {
162
- lockTemplate.releaseLock(lockInfo);
146
+ if (lock.tryLock(3, 10, TimeUnit.SECONDS)) {
147
+ try {
148
+ // 业务逻辑
149
+ } finally {
150
+ if (lock.isLocked() && lock.isHeldByCurrentThread()) {
151
+ lock.unlock();
152
+ }
153
+ }
154
+ } else {
155
+ throw new [你的异常类]("业务处理中,请稍后再试");
156
+ }
157
+ } catch (InterruptedException e) {
158
+ Thread.currentThread().interrupt();
159
+ throw new [你的异常类]("操作被中断");
163
160
  }
164
161
  ```
165
162
 
166
163
  ### 限流
167
164
 
168
165
  ```java
166
+ import org.redisson.api.RRateLimiter;
169
167
  import org.redisson.api.RateType;
168
+ import org.redisson.api.RateIntervalUnit;
170
169
 
171
- long remaining = RedisUtils.rateLimiter("api:rate:" + userId, RateType.OVERALL, 100, 60);
172
- if (remaining < 0) {
173
- throw new ServiceException("请求过于频繁");
170
+ RRateLimiter limiter = redissonClient.getRateLimiter("api:rate:" + userId);
171
+ limiter.trySetRate(RateType.OVERALL, 100, 60, RateIntervalUnit.SECONDS);
172
+ if (!limiter.tryAcquire()) {
173
+ throw new [你的异常类]("请求过于频繁");
174
174
  }
175
175
  ```
176
176
 
@@ -187,23 +187,26 @@ private final Cache<Long, UserVo> localCache = Caffeine.newBuilder()
187
187
 
188
188
  public UserVo getUser(Long id) {
189
189
  return localCache.get(id, key -> {
190
- UserVo cached = RedisUtils.getCacheObject("user:" + id);
191
- return cached != null ? cached : baseMapper.selectVoById(id);
190
+ RBucket<UserVo> bucket = redissonClient.getBucket("user:" + id);
191
+ UserVo cached = bucket.get();
192
+ return cached != null ? cached : baseMapper.selectById(id);
192
193
  });
193
194
  }
194
195
  ```
195
196
 
196
197
  ---
197
198
 
198
- ## 3. 多租户优化
199
+ ## 3. 索引优化
199
200
 
200
201
  ```sql
201
- -- tenant_id 必须建索引
202
- CREATE INDEX idx_tenant_id ON xxx_table(tenant_id);
202
+ -- 为高频查询字段添加索引
203
+ CREATE INDEX idx_status ON xxx_table(status);
204
+
205
+ -- 复合索引:遵循最左前缀原则
206
+ CREATE INDEX idx_status_create_time ON xxx_table(status, create_time);
203
207
 
204
- -- 复合索引第一列放 tenant_id(多租户自动添加 tenant_id 条件)
205
- CREATE INDEX idx_tenant_status ON xxx_table(tenant_id, status);
206
- CREATE INDEX idx_tenant_create_time ON xxx_table(tenant_id, create_time);
208
+ -- 使用 EXPLAIN 分析查询
209
+ EXPLAIN SELECT * FROM xxx_table WHERE status = 1 AND create_time > '2026-01-01';
207
210
  ```
208
211
 
209
212
  ---
@@ -212,7 +215,7 @@ CREATE INDEX idx_tenant_create_time ON xxx_table(tenant_id, create_time);
212
215
 
213
216
  ```java
214
217
  // 推荐:分批处理(每批500条)
215
- public void batchInsert(List<Xxx> list) {
218
+ public void batchInsert(List<XxxEntity> list) {
216
219
  int batchSize = 500;
217
220
  for (int i = 0; i < list.size(); i += batchSize) {
218
221
  int end = Math.min(i + batchSize, list.size());
@@ -222,12 +225,13 @@ public void batchInsert(List<Xxx> list) {
222
225
 
223
226
  // 批量更新同理
224
227
  @Transactional(rollbackFor = Exception.class)
225
- public void batchUpdate(List<XxxBo> list) {
228
+ public void batchUpdate(List<XxxDTO> list) {
226
229
  int batchSize = 500;
227
230
  for (int i = 0; i < list.size(); i += batchSize) {
228
231
  int end = Math.min(i + batchSize, list.size());
229
- List<Xxx> batch = list.subList(i, end).stream()
230
- .map(bo -> MapstructUtils.convert(bo, Xxx.class)).toList();
232
+ List<XxxEntity> batch = list.subList(i, end).stream()
233
+ .map(dto -> BeanUtil.copyProperties(dto, XxxEntity.class))
234
+ .toList();
231
235
  Db.updateBatchById(batch);
232
236
  }
233
237
  }
@@ -237,15 +241,6 @@ public void batchUpdate(List<XxxBo> list) {
237
241
 
238
242
  ## 5. 性能日志分析
239
243
 
240
- > 日志配置:`ruoyi-admin/src/main/resources/logback-plus.xml:52-72`
241
-
242
- ### 日志文件
243
-
244
- | 环境 | 文件 | 说明 |
245
- |------|------|------|
246
- | **开发** | `./logs/console.log` | 每次启动清空,含 SQL 日志 |
247
- | 生产 | `./logs/sys-*.log` | 按天滚动,保留60天 |
248
-
249
244
  ### SQL 监控
250
245
 
251
246
  开发环境 p6spy 默认开启:`spring.datasource.dynamic.p6spy: true`
@@ -253,18 +248,9 @@ public void batchUpdate(List<XxxBo> list) {
253
248
  日志格式:
254
249
  ```
255
250
  2026-01-08 22:12:10 [req-123] [...] INFO p6spy - Consume Time:245 ms
256
- Execute SQL:SELECT * FROM sys_user WHERE tenant_id = '000000' AND del_flag = '0'
251
+ Execute SQL:SELECT * FROM user WHERE status = 1
257
252
  ```
258
253
 
259
- ### AI 主动读日志的触发条件
260
-
261
- | 场景 | 关键词 | 分析重点 |
262
- |------|--------|---------|
263
- | 接口慢 | "接口慢"、"超时" | SQL 执行时间、N+1 查询 |
264
- | SQL 慢 | "SQL慢"、"查询慢" | p6spy Consume Time |
265
- | 内存/CPU | "内存高"、"卡顿" | OOM、GC、线程池满 |
266
- | 频繁报错 | "一直报错" | ERROR 日志、异常频率 |
267
-
268
254
  ### 分析命令
269
255
 
270
256
  ```bash
@@ -278,6 +264,15 @@ grep "Execute SQL" ./logs/console.log | sed 's/WHERE.*/WHERE .../' | sort | uniq
278
264
  grep "ERROR" ./logs/console.log | tail -50
279
265
  ```
280
266
 
267
+ ### AI 主动读日志的触发条件
268
+
269
+ | 场景 | 关键词 | 分析重点 |
270
+ |------|--------|---------|
271
+ | 接口慢 | "接口慢"、"超时" | SQL 执行时间、N+1 查询 |
272
+ | SQL 慢 | "SQL慢"、"查询慢" | p6spy Consume Time |
273
+ | 内存/CPU | "内存高"、"卡顿" | OOM、GC、线程池满 |
274
+ | 频繁报错 | "一直报错" | ERROR 日志、异常频率 |
275
+
281
276
  ---
282
277
 
283
278
  ## 常见问题速查
@@ -286,10 +281,9 @@ grep "ERROR" ./logs/console.log | tail -50
286
281
  |------|------|------|
287
282
  | 接口响应慢 | SQL 无索引 | 添加索引,EXPLAIN 分析 |
288
283
  | 接口响应慢 | N+1 查询 | 批量查询 + Map 映射 |
289
- | 接口响应慢 | 未缓存 | RedisUtils 或 @Cacheable |
284
+ | 接口响应慢 | 未缓存 | Redisson 或 @Cacheable |
290
285
  | 分页查询慢 | 深分页 | 游标分页或限制页码 |
291
286
  | 批量操作超时 | 数据量太大 | 分批500条处理 |
292
- | 多租户查询慢 | tenant_id 无索引 | 添加 tenant_id 复合索引 |
293
287
  | 内存溢出 | 大数据量一次加载 | 分批/流式处理 |
294
288
 
295
289
  ---