ai-engineering-init 1.6.0 → 1.8.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 (187) hide show
  1. package/.claude/agents/code-reviewer.md +3 -130
  2. package/.claude/hooks/skill-forced-eval.js +46 -60
  3. package/.claude/hooks/stop.js +24 -1
  4. package/.claude/settings.json +10 -1
  5. package/.claude/skills/api-development/SKILL.md +179 -130
  6. package/.claude/skills/architecture-design/SKILL.md +102 -212
  7. package/.claude/skills/backend-annotations/SKILL.md +166 -220
  8. package/.claude/skills/bug-detective/SKILL.md +225 -186
  9. package/.claude/skills/code-patterns/SKILL.md +127 -244
  10. package/.claude/skills/codex-code-review/SKILL.md +327 -0
  11. package/.claude/skills/collaborating-with-codex/SKILL.md +96 -113
  12. package/.claude/skills/crud-development/SKILL.md +226 -307
  13. package/.claude/skills/data-permission/SKILL.md +131 -202
  14. package/.claude/skills/database-ops/SKILL.md +158 -355
  15. package/.claude/skills/error-handler/SKILL.md +224 -285
  16. package/.claude/skills/file-oss-management/SKILL.md +174 -169
  17. package/.claude/skills/git-workflow/SKILL.md +123 -341
  18. package/.claude/skills/json-serialization/SKILL.md +121 -137
  19. package/.claude/skills/leniu-report-customization/SKILL.md +82 -2
  20. package/.claude/skills/leniu-report-standard-customization/SKILL.md +65 -2
  21. package/.claude/skills/loki-log-query/SKILL.md +400 -0
  22. package/.claude/skills/mysql-debug/SKILL.md +58 -22
  23. package/.claude/skills/performance-doctor/SKILL.md +83 -89
  24. package/.claude/skills/redis-cache/SKILL.md +134 -185
  25. package/.claude/skills/scheduled-jobs/SKILL.md +187 -224
  26. package/.claude/skills/security-guard/SKILL.md +168 -276
  27. package/.claude/skills/sms-mail/SKILL.md +266 -228
  28. package/.claude/skills/social-login/SKILL.md +257 -195
  29. package/.claude/skills/sync-back-merge/SKILL.md +66 -0
  30. package/.claude/skills/tenant-management/SKILL.md +172 -188
  31. package/.claude/skills/utils-toolkit/SKILL.md +214 -222
  32. package/.claude/skills/websocket-sse/SKILL.md +251 -172
  33. package/.claude/skills/workflow-engine/SKILL.md +178 -250
  34. package/.claude/skills/yunxiao-task-management/SKILL.md +489 -0
  35. package/.codex/skills/api-development/SKILL.md +179 -130
  36. package/.codex/skills/architecture-design/SKILL.md +102 -212
  37. package/.codex/skills/backend-annotations/SKILL.md +166 -220
  38. package/.codex/skills/bug-detective/SKILL.md +225 -186
  39. package/.codex/skills/code-patterns/SKILL.md +127 -244
  40. package/.codex/skills/collaborating-with-codex/SKILL.md +96 -113
  41. package/.codex/skills/crud-development/SKILL.md +226 -307
  42. package/.codex/skills/data-permission/SKILL.md +131 -202
  43. package/.codex/skills/database-ops/SKILL.md +158 -355
  44. package/.codex/skills/error-handler/SKILL.md +224 -285
  45. package/.codex/skills/file-oss-management/SKILL.md +174 -169
  46. package/.codex/skills/git-workflow/SKILL.md +123 -341
  47. package/.codex/skills/json-serialization/SKILL.md +121 -137
  48. package/.codex/skills/leniu-report-customization/SKILL.md +82 -2
  49. package/.codex/skills/leniu-report-standard-customization/SKILL.md +65 -2
  50. package/.codex/skills/loki-log-query/SKILL.md +400 -0
  51. package/.codex/skills/loki-log-query/environments.json +45 -0
  52. package/.codex/skills/mysql-debug/SKILL.md +58 -22
  53. package/.codex/skills/performance-doctor/SKILL.md +83 -89
  54. package/.codex/skills/redis-cache/SKILL.md +134 -185
  55. package/.codex/skills/scheduled-jobs/SKILL.md +187 -224
  56. package/.codex/skills/security-guard/SKILL.md +168 -276
  57. package/.codex/skills/skill-creator/LICENSE.txt +202 -0
  58. package/.codex/skills/skill-creator/SKILL.md +479 -0
  59. package/.codex/skills/skill-creator/agents/analyzer.md +274 -0
  60. package/.codex/skills/skill-creator/agents/comparator.md +202 -0
  61. package/.codex/skills/skill-creator/agents/grader.md +223 -0
  62. package/.codex/skills/skill-creator/assets/eval_review.html +146 -0
  63. package/.codex/skills/skill-creator/eval-viewer/generate_review.py +471 -0
  64. package/.codex/skills/skill-creator/eval-viewer/viewer.html +1325 -0
  65. package/.codex/skills/skill-creator/references/schemas.md +430 -0
  66. package/.codex/skills/skill-creator/scripts/__init__.py +0 -0
  67. package/.codex/skills/skill-creator/scripts/aggregate_benchmark.py +401 -0
  68. package/.codex/skills/skill-creator/scripts/generate_report.py +326 -0
  69. package/.codex/skills/skill-creator/scripts/improve_description.py +248 -0
  70. package/.codex/skills/skill-creator/scripts/package_skill.py +136 -0
  71. package/.codex/skills/skill-creator/scripts/quick_validate.py +103 -0
  72. package/.codex/skills/skill-creator/scripts/run_eval.py +310 -0
  73. package/.codex/skills/skill-creator/scripts/run_loop.py +332 -0
  74. package/.codex/skills/skill-creator/scripts/utils.py +47 -0
  75. package/.codex/skills/sms-mail/SKILL.md +266 -228
  76. package/.codex/skills/social-login/SKILL.md +257 -195
  77. package/.codex/skills/sync-back-merge/SKILL.md +66 -0
  78. package/.codex/skills/tenant-management/SKILL.md +172 -188
  79. package/.codex/skills/utils-toolkit/SKILL.md +214 -222
  80. package/.codex/skills/websocket-sse/SKILL.md +251 -172
  81. package/.codex/skills/workflow-engine/SKILL.md +178 -250
  82. package/.codex/skills/yunxiao-task-management/SKILL.md +489 -0
  83. package/.cursor/hooks/cursor-skill-eval.js +66 -6
  84. package/.cursor/hooks/stop.js +23 -1
  85. package/.cursor/skills/api-development/SKILL.md +179 -130
  86. package/.cursor/skills/architecture-design/SKILL.md +102 -212
  87. package/.cursor/skills/backend-annotations/SKILL.md +166 -220
  88. package/.cursor/skills/bug-detective/SKILL.md +225 -186
  89. package/.cursor/skills/code-patterns/SKILL.md +127 -244
  90. package/.cursor/skills/collaborating-with-codex/SKILL.md +96 -113
  91. package/.cursor/skills/crud-development/SKILL.md +226 -307
  92. package/.cursor/skills/data-permission/SKILL.md +131 -202
  93. package/.cursor/skills/database-ops/SKILL.md +158 -355
  94. package/.cursor/skills/error-handler/SKILL.md +224 -285
  95. package/.cursor/skills/file-oss-management/SKILL.md +174 -169
  96. package/.cursor/skills/git-workflow/SKILL.md +123 -341
  97. package/.cursor/skills/json-serialization/SKILL.md +121 -137
  98. package/.cursor/skills/leniu-report-customization/SKILL.md +82 -2
  99. package/.cursor/skills/leniu-report-standard-customization/SKILL.md +65 -2
  100. package/.cursor/skills/loki-log-query/SKILL.md +400 -0
  101. package/.cursor/skills/loki-log-query/environments.json +45 -0
  102. package/.cursor/skills/mysql-debug/SKILL.md +58 -22
  103. package/.cursor/skills/performance-doctor/SKILL.md +83 -89
  104. package/.cursor/skills/redis-cache/SKILL.md +134 -185
  105. package/.cursor/skills/scheduled-jobs/SKILL.md +187 -224
  106. package/.cursor/skills/security-guard/SKILL.md +168 -276
  107. package/.cursor/skills/skill-creator/LICENSE.txt +202 -0
  108. package/.cursor/skills/skill-creator/SKILL.md +479 -0
  109. package/.cursor/skills/skill-creator/agents/analyzer.md +274 -0
  110. package/.cursor/skills/skill-creator/agents/comparator.md +202 -0
  111. package/.cursor/skills/skill-creator/agents/grader.md +223 -0
  112. package/.cursor/skills/skill-creator/assets/eval_review.html +146 -0
  113. package/.cursor/skills/skill-creator/eval-viewer/generate_review.py +471 -0
  114. package/.cursor/skills/skill-creator/eval-viewer/viewer.html +1325 -0
  115. package/.cursor/skills/skill-creator/references/schemas.md +430 -0
  116. package/.cursor/skills/skill-creator/scripts/__init__.py +0 -0
  117. package/.cursor/skills/skill-creator/scripts/aggregate_benchmark.py +401 -0
  118. package/.cursor/skills/skill-creator/scripts/generate_report.py +326 -0
  119. package/.cursor/skills/skill-creator/scripts/improve_description.py +248 -0
  120. package/.cursor/skills/skill-creator/scripts/package_skill.py +136 -0
  121. package/.cursor/skills/skill-creator/scripts/quick_validate.py +103 -0
  122. package/.cursor/skills/skill-creator/scripts/run_eval.py +310 -0
  123. package/.cursor/skills/skill-creator/scripts/run_loop.py +332 -0
  124. package/.cursor/skills/skill-creator/scripts/utils.py +47 -0
  125. package/.cursor/skills/sms-mail/SKILL.md +266 -228
  126. package/.cursor/skills/social-login/SKILL.md +257 -195
  127. package/.cursor/skills/sync-back-merge/SKILL.md +66 -0
  128. package/.cursor/skills/tenant-management/SKILL.md +172 -188
  129. package/.cursor/skills/utils-toolkit/SKILL.md +214 -222
  130. package/.cursor/skills/websocket-sse/SKILL.md +251 -172
  131. package/.cursor/skills/workflow-engine/SKILL.md +178 -250
  132. package/.cursor/skills/yunxiao-task-management/SKILL.md +489 -0
  133. package/AGENTS.md +49 -540
  134. package/CLAUDE.md +73 -119
  135. package/README.md +37 -6
  136. package/bin/index.js +611 -25
  137. package/package.json +1 -1
  138. package/src/platform-map.json +4 -0
  139. package/src/skills/api-development/SKILL.md +179 -130
  140. package/src/skills/architecture-design/SKILL.md +102 -212
  141. package/src/skills/backend-annotations/SKILL.md +166 -220
  142. package/src/skills/bug-detective/SKILL.md +225 -186
  143. package/src/skills/code-patterns/SKILL.md +127 -244
  144. package/src/skills/codex-code-review/SKILL.md +261 -69
  145. package/src/skills/collaborating-with-codex/SKILL.md +96 -113
  146. package/src/skills/crud-development/SKILL.md +226 -307
  147. package/src/skills/data-permission/SKILL.md +131 -202
  148. package/src/skills/database-ops/SKILL.md +158 -355
  149. package/src/skills/error-handler/SKILL.md +224 -285
  150. package/src/skills/file-oss-management/SKILL.md +174 -169
  151. package/src/skills/git-workflow/SKILL.md +123 -341
  152. package/src/skills/json-serialization/SKILL.md +121 -137
  153. package/src/skills/leniu-report-customization/SKILL.md +82 -2
  154. package/src/skills/leniu-report-standard-customization/SKILL.md +65 -2
  155. package/src/skills/loki-log-query/SKILL.md +400 -0
  156. package/src/skills/loki-log-query/environments.json +45 -0
  157. package/src/skills/mysql-debug/SKILL.md +58 -22
  158. package/src/skills/performance-doctor/SKILL.md +83 -89
  159. package/src/skills/redis-cache/SKILL.md +134 -185
  160. package/src/skills/scheduled-jobs/SKILL.md +187 -224
  161. package/src/skills/security-guard/SKILL.md +168 -276
  162. package/src/skills/skill-creator/LICENSE.txt +202 -0
  163. package/src/skills/skill-creator/SKILL.md +479 -0
  164. package/src/skills/skill-creator/agents/analyzer.md +274 -0
  165. package/src/skills/skill-creator/agents/comparator.md +202 -0
  166. package/src/skills/skill-creator/agents/grader.md +223 -0
  167. package/src/skills/skill-creator/assets/eval_review.html +146 -0
  168. package/src/skills/skill-creator/eval-viewer/generate_review.py +471 -0
  169. package/src/skills/skill-creator/eval-viewer/viewer.html +1325 -0
  170. package/src/skills/skill-creator/references/schemas.md +430 -0
  171. package/src/skills/skill-creator/scripts/__init__.py +0 -0
  172. package/src/skills/skill-creator/scripts/aggregate_benchmark.py +401 -0
  173. package/src/skills/skill-creator/scripts/generate_report.py +326 -0
  174. package/src/skills/skill-creator/scripts/improve_description.py +248 -0
  175. package/src/skills/skill-creator/scripts/package_skill.py +136 -0
  176. package/src/skills/skill-creator/scripts/quick_validate.py +103 -0
  177. package/src/skills/skill-creator/scripts/run_eval.py +310 -0
  178. package/src/skills/skill-creator/scripts/run_loop.py +332 -0
  179. package/src/skills/skill-creator/scripts/utils.py +47 -0
  180. package/src/skills/sms-mail/SKILL.md +266 -228
  181. package/src/skills/social-login/SKILL.md +257 -195
  182. package/src/skills/sync-back-merge/SKILL.md +66 -0
  183. package/src/skills/tenant-management/SKILL.md +172 -188
  184. package/src/skills/utils-toolkit/SKILL.md +214 -222
  185. package/src/skills/websocket-sse/SKILL.md +251 -172
  186. package/src/skills/workflow-engine/SKILL.md +178 -250
  187. package/src/skills/yunxiao-task-management/SKILL.md +489 -0
@@ -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
  ---