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,138 +1,145 @@
1
1
  ---
2
2
  name: data-permission
3
3
  description: |
4
- 数据权限开发指南。实现行级数据隔离,支持部门权限、本人权限、自定义权限等 6 种权限类型。
5
-
4
+ 通用行级数据权限设计指南。通过 AOP + MyBatis 拦截器模式实现数据隔离,支持部门权限、本人权限、自定义权限等多种隔离粒度。
6
5
  触发场景:
7
- - 为业务模块添加数据权限过滤
8
- - 配置部门级数据隔离
6
+ - 为业务模块添加行级数据过滤
7
+ - 设计部门级 / 本人级数据隔离
9
8
  - 扩展自定义数据权限类型
10
- - 临时忽略数据权限查询全量数据
9
+ - 临时忽略数据权限查全量数据
11
10
  - 排查数据权限不生效问题
12
-
13
- 触发词:数据权限、@DataPermission、DataScope、行级权限、数据隔离、部门权限、本人权限、自定义权限、权限过滤、数据过滤、按部门过滤、按创建人过滤
14
-
15
- 注意:如果是认证授权(登录、Token、Sa-Token)或菜单/按钮权限,请使用 security-guard。
11
+ 触发词:数据权限、行级权限、数据隔离、部门权限、本人权限、自定义权限、DataScope、DataPermission、数据过滤
12
+ 注意:如果项目有专属技能(如 `leniu-data-permission`),优先使用专属版本。
16
13
  ---
17
14
 
18
- # 数据权限开发指南
15
+ # 行级数据权限开发指南
19
16
 
20
- > 通过 MyBatis 拦截器自动注入 WHERE 条件,实现行级数据过滤。
17
+ > 通用模板。如果项目有专属技能(如 `leniu-data-permission`),优先使用。
21
18
 
22
- ## 1. 六种权限类型
19
+ ## 设计原则
23
20
 
24
- | 类型 | 字典值 | SQL 效果 |
25
- |------|--------|---------|
26
- | 全部数据 | 1 | 不拼接条件 |
27
- | 自定义权限 | 2 | `dept_id IN (角色关联的部门ID)` |
28
- | 本部门 | 3 | `dept_id = 100` |
29
- | 本部门及以下 | 4 | `dept_id IN (100,101,102)` |
30
- | 仅本人 | 5 | `create_by = 1` |
31
- | 部门及以下或本人 | 6 | `dept_id IN (...) OR create_by = 1` |
21
+ 1. **对业务透明**:数据权限通过拦截器自动注入 SQL 条件,业务代码无需感知。
22
+ 2. **声明式配置**:通过注解声明字段映射关系,框架自动拼接过滤条件。
23
+ 3. **可扩展**:权限类型(部门、本人、自定义等)可通过枚举或策略模式扩展。
24
+ 4. **安全兜底**:未配置权限范围时默认为"仅本人",避免数据泄露。
32
25
 
33
26
  ---
34
27
 
35
- ## 2. 快速上手
28
+ ## 权限类型设计
36
29
 
37
- ### 步骤 1:Service 方法加注解
30
+ | 类型 | 标识 | SQL 效果 | 适用场景 |
31
+ |------|------|---------|---------|
32
+ | 全部数据 | 1 | 不拼接条件 | 超管、全局数据查看 |
33
+ | 自定义权限 | 2 | `dept_id IN (角色关联的部门ID)` | 跨部门协作 |
34
+ | 本部门 | 3 | `dept_id = ?` | 部门经理 |
35
+ | 本部门及以下 | 4 | `dept_id IN (当前部门及子部门)` | 上级部门 |
36
+ | 仅本人 | 5 | `created_by = ?` | 普通员工 |
37
+ | 部门及以下或本人 | 6 | `dept_id IN (...) OR created_by = ?` | 混合场景 |
38
38
 
39
- ```java
40
- import org.dromara.common.mybatis.annotation.DataPermission;
41
- import org.dromara.common.mybatis.annotation.DataColumn;
39
+ ---
42
40
 
43
- @Service
44
- @RequiredArgsConstructor
45
- public class OrderServiceImpl implements IOrderService {
41
+ ## 实现模式
46
42
 
47
- private final OrderMapper baseMapper;
43
+ ### 架构概览
48
44
 
49
- @DataPermission({
50
- @DataColumn(key = "deptName", value = "create_dept"),
51
- @DataColumn(key = "userName", value = "create_by")
52
- })
53
- @Override
54
- public TableDataInfo<OrderVo> pageWithPermission(OrderBo bo, PageQuery pageQuery) {
55
- LambdaQueryWrapper<Order> lqw = buildQueryWrapper(bo);
56
- Page<OrderVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
57
- return TableDataInfo.build(result);
58
- }
59
- }
60
45
  ```
61
-
62
- ### 步骤 2:确保表有权限字段
63
-
64
- ```sql
65
- CREATE TABLE m_order (
66
- id BIGINT(20) NOT NULL COMMENT '主键ID',
67
- -- 业务字段 ...
68
- create_dept BIGINT(20) DEFAULT NULL COMMENT '创建部门', -- 必须
69
- create_by BIGINT(20) DEFAULT NULL COMMENT '创建人', -- 必须
70
- create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
71
- PRIMARY KEY (id)
72
- );
46
+ Controller -> Service (加注解) -> Mapper -> MyBatis 拦截器
47
+ |
48
+ 自动注入 WHERE 条件
49
+ |
50
+ [你的权限处理器] (查询当前用户权限范围)
73
51
  ```
74
52
 
75
- ### 步骤 3:角色管理中配置数据权限范围
53
+ ### 步骤 1:定义注解
76
54
 
77
- ---
55
+ ```java
56
+ @Target({ElementType.METHOD, ElementType.TYPE})
57
+ @Retention(RetentionPolicy.RUNTIME)
58
+ public @interface DataPermission {
59
+ DataColumn[] value();
60
+ String joinStr() default "AND"; // 多角色权限连接方式
61
+ }
78
62
 
79
- ## 3. 使用场景
63
+ @Target(ElementType.ANNOTATION_TYPE)
64
+ @Retention(RetentionPolicy.RUNTIME)
65
+ public @interface DataColumn {
66
+ String key() default "deptName"; // 占位符关键字
67
+ String value() default "dept_id"; // 对应的表字段名
68
+ String permission() default ""; // 拥有此权限则不过滤
69
+ }
70
+ ```
80
71
 
81
- ### 按部门过滤(最常见)
72
+ ### 步骤 2:实现 MyBatis 拦截器
82
73
 
83
74
  ```java
84
- @DataPermission({
85
- @DataColumn(key = "deptName", value = "create_dept")
86
- })
87
- public List<Order> listWithPermission(OrderBo bo) {
88
- return list(buildQueryWrapper(bo));
75
+ @Intercepts({@Signature(type = Executor.class, method = "query", args = {...})})
76
+ public class DataPermissionInterceptor implements Interceptor {
77
+
78
+ @Override
79
+ public Object intercept(Invocation invocation) throws Throwable {
80
+ // 1. 从线程上下文获取 @DataPermission 注解
81
+ // 2. 获取当前用户的角色及数据权限范围
82
+ // 3. 根据权限类型拼接 WHERE 条件
83
+ // 4. 修改原始 SQL,追加过滤条件
84
+ return invocation.proceed();
85
+ }
89
86
  }
90
87
  ```
91
88
 
92
- ### 按创建人过滤
89
+ ### 步骤 3:在 Service / Mapper 上使用
93
90
 
94
91
  ```java
95
- @DataPermission({
96
- @DataColumn(key = "userName", value = "create_by")
97
- })
98
- public List<Task> listMyTasks(TaskBo bo) {
99
- return list(buildQueryWrapper(bo));
92
+ @Service
93
+ public class OrderServiceImpl implements OrderService {
94
+
95
+ @Autowired
96
+ private OrderMapper orderMapper;
97
+
98
+ // 按部门 + 创建人过滤
99
+ @DataPermission({
100
+ @DataColumn(key = "deptName", value = "dept_id"),
101
+ @DataColumn(key = "userName", value = "created_by")
102
+ })
103
+ @Override
104
+ public List<OrderVo> listWithPermission(OrderQuery query) {
105
+ return orderMapper.selectList(buildWrapper(query));
106
+ }
100
107
  }
101
108
  ```
102
109
 
103
- ### 部门 + 创建人混合
110
+ ### 步骤 4:确保数据库表有权限字段
104
111
 
105
- ```java
106
- @DataPermission({
107
- @DataColumn(key = "deptName", value = "create_dept"),
108
- @DataColumn(key = "userName", value = "create_by")
109
- })
110
- public TableDataInfo<ProjectVo> pageWithPermission(ProjectBo bo, PageQuery pageQuery) {
111
- // ...
112
- }
112
+ ```sql
113
+ CREATE TABLE biz_order (
114
+ id BIGINT NOT NULL COMMENT '主键',
115
+ -- 业务字段 ...
116
+ dept_id BIGINT DEFAULT NULL COMMENT '所属部门', -- 必须
117
+ created_by BIGINT DEFAULT NULL COMMENT '创建人', -- 必须
118
+ created_time DATETIME DEFAULT CURRENT_TIMESTAMP,
119
+ PRIMARY KEY (id)
120
+ );
113
121
  ```
114
122
 
115
123
  ### 多表关联(使用表别名)
116
124
 
117
125
  ```java
118
- // SQL: SELECT u.*, d.dept_name FROM sys_user u LEFT JOIN sys_dept d ON ...
126
+ // SQL: SELECT o.*, u.user_name FROM biz_order o LEFT JOIN sys_user u ON ...
119
127
  @DataPermission({
120
- @DataColumn(key = "deptName", value = "u.dept_id"),
121
- @DataColumn(key = "userName", value = "u.user_id")
128
+ @DataColumn(key = "deptName", value = "o.dept_id"),
129
+ @DataColumn(key = "userName", value = "o.created_by")
122
130
  })
131
+ List<OrderVo> selectWithJoin(@Param("query") OrderQuery query);
123
132
  ```
124
133
 
125
134
  ### 临时忽略数据权限
126
135
 
127
136
  ```java
128
- import org.dromara.common.mybatis.helper.DataPermissionHelper;
129
-
130
- // 忽略数据权限,查全量
131
- Long total = DataPermissionHelper.ignore(() -> orderService.count());
137
+ // 使用工具类忽略权限过滤,查全量数据
138
+ Long total = [你的权限工具类].ignore(() -> orderService.count());
132
139
 
133
140
  // 无返回值
134
- DataPermissionHelper.ignore(() -> {
135
- List<Config> configs = configService.list();
141
+ [你的权限工具类].ignore(() -> {
142
+ configService.refreshAll();
136
143
  return null;
137
144
  });
138
145
  ```
@@ -142,151 +149,73 @@ DataPermissionHelper.ignore(() -> {
142
149
  ```java
143
150
  // 拥有 order:all 权限的角色不过滤
144
151
  @DataPermission({
145
- @DataColumn(key = "deptName", value = "create_dept", permission = "order:all")
152
+ @DataColumn(key = "deptName", value = "dept_id", permission = "order:all")
146
153
  })
147
154
  ```
148
155
 
149
156
  ---
150
157
 
151
- ## 4. Mapper XML 中使用
158
+ ## 选型建议
152
159
 
153
- ```java
154
- // Mapper 接口
155
- @DataPermission({
156
- @DataColumn(key = "deptName", value = "o.create_dept")
157
- })
158
- List<OrderVo> selectOrderReport(@Param("bo") OrderBo bo);
159
- ```
160
-
161
- ```xml
162
- <select id="selectOrderReport" resultType="OrderVo">
163
- SELECT o.*, u.user_name
164
- FROM m_order o
165
- LEFT JOIN sys_user u ON o.create_by = u.user_id
166
- WHERE o.status = #{bo.status}
167
- <!-- 数据权限自动追加到这里 -->
168
- </select>
169
- ```
170
-
171
- ---
172
-
173
- ## 5. 扩展自定义权限类型
174
-
175
- > 详细步骤见 `references/custom-data-scope.md`
176
-
177
- **步骤 1**:修改 `DataScopeType` 枚举
178
-
179
- ```java
180
- REGION("7", "按区域", "#{#regionName} IN ( #{@sdss.getUserRegions( #user.userId )} )"),
181
- ```
182
-
183
- **步骤 2**:在 `ISysDataScopeService` 添加方法
184
-
185
- ```java
186
- @Service("sdss")
187
- public class SysDataScopeServiceImpl implements ISysDataScopeService {
188
- @Override
189
- @Cacheable(cacheNames = CacheNames.SYS_USER_REGIONS, key = "#userId")
190
- public String getUserRegions(Long userId) {
191
- List<Long> regionIds = userRegionMapper.selectRegionIdsByUserId(userId);
192
- return CollUtil.isEmpty(regionIds) ? "-1" : StringUtils.join(regionIds, ",");
193
- }
194
- }
195
- ```
196
-
197
- **步骤 3**:使用
198
-
199
- ```java
200
- @DataPermission({
201
- @DataColumn(key = "regionName", value = "region_id")
202
- })
203
- ```
204
-
205
- ### 自定义变量
160
+ | 方案 | 优点 | 缺点 | 适用场景 |
161
+ |------|------|------|---------|
162
+ | MyBatis 拦截器 | 对业务透明、自动注入 | 依赖 MyBatis | 绝大多数 Java Web 项目 |
163
+ | AOP + SQL 改写 | 框架无关 | 需自行解析 SQL | 非 MyBatis 项目 |
164
+ | 数据库视图 | 完全透明 | 难以动态切换 | 权限固定的场景 |
165
+ | 应用层过滤 | 实现简单 | 性能差(全量查出再过滤) | 数据量小 |
206
166
 
207
- ```java
208
- // 设置自定义变量(请求结束后自动清理)
209
- DataPermissionHelper.setVariable("shopId", shopId);
167
+ ### 多角色权限计算
210
168
 
211
- @DataPermission({
212
- @DataColumn(key = "shopId", value = "shop_id")
213
- })
214
- ```
169
+ - **SELECT 查询**:多角色权限用 `OR` 连接(并集,看到更多数据)
170
+ - **UPDATE / DELETE**:多角色权限用 `AND` 连接(交集,更安全)
215
171
 
216
172
  ---
217
173
 
218
- ## 6. 多角色权限计算
219
-
220
- - **SELECT 查询**:多角色权限用 `OR` 连接(并集)
221
- - **UPDATE/DELETE**:多角色权限用 `AND` 连接(交集)
222
- - 可通过 `joinStr` 参数自定义:
174
+ ## 常见错误
223
175
 
224
176
  ```java
225
- @DataPermission(value = {
226
- @DataColumn(key = "deptName", value = "create_dept")
227
- }, joinStr = "AND")
228
- ```
229
-
230
- ---
177
+ // 1. 注解放在 Controller 层(无效,拦截器在 Mapper 执行前生效)
178
+ @Controller
179
+ public class OrderController {
180
+ @DataPermission({...}) // 无效!应在 Service 或 Mapper 上
181
+ public Result<?> list() { }
182
+ }
231
183
 
232
- ## 7. 禁止项
184
+ // 2. 表别名不匹配
185
+ @DataColumn(key = "deptName", value = "user.dept_id") // SQL 中别名是 u
186
+ // 应为 value = "u.dept_id"
233
187
 
234
- ```java
235
- // ❌ 在 ISysDataScopeService 内调用带权限的方法(死循环)
188
+ // 3. 在权限服务内部调用带权限的方法(死循环)
236
189
  public String getDeptAndChild(Long deptId) {
237
- deptService.list(wrapper); // 如果带 @DataPermission 会死循环
238
- // 直接用 Mapper 或 DataPermissionHelper.ignore()
239
- deptMapper.selectList(wrapper);
190
+ deptService.list(wrapper); // 如果 list 也带 @DataPermission -> 死循环
191
+ // 应直接用 Mapper 或 ignore() 包装
240
192
  }
241
193
 
242
- // 表别名不匹配
243
- @DataColumn(key = "deptName", value = "user.dept_id") // SQL 别名是 u
244
- // ✅ @DataColumn(key = "deptName", value = "u.dept_id")
194
+ // 4. 忘记在表中添加部门/创建人字段
195
+ // 没有 dept_id / created_by 字段,权限 SQL 会报错
245
196
 
246
- // 在 Controller 层使用 @DataPermission(无效!)
247
- // ✅ 必须在 Service 实现类或 Mapper 接口上
197
+ // 5. 超级管理员测试数据权限
198
+ // 超管通常跳过权限过滤,应使用普通用户账号测试
248
199
 
249
- // Entity 必须继承 TenantEntity(包含 create_dept、create_by)
250
- // 多表查询时使用正确的表别名
200
+ // 6. @DataPermission 注解为空
201
+ @DataPermission // 空注解,无 @DataColumn 映射,不会生效
251
202
  ```
252
203
 
253
- ---
254
-
255
- ## 8. 问题排查
204
+ ### 问题排查
256
205
 
257
206
  | 检查项 | 可能原因 | 解决方案 |
258
207
  |--------|---------|---------|
259
208
  | 超级管理员? | 超管自动跳过权限 | 用普通用户测试 |
260
- | 角色数据范围? | 范围为"全部数据" | 修改角色数据权限 |
261
- | 注解位置? | 不在 Service/Mapper 层 | 移动到 Service 实现类 |
262
- | 表别名? | value 别名与 SQL 不一致 | 检查修正别名 |
263
- | Unknown column? | 表别名不存在 | 检查 value 中的别名 |
264
- | dept_id IN ()? | 权限服务返回空 | 检查 ISysDataScopeService |
209
+ | 角色数据范围? | 范围为"全部数据" | 修改角色数据权限配置 |
210
+ | 注解位置? | 不在 Service / Mapper 层 | 移动注解到正确位置 |
211
+ | 表别名? | value 别名与 SQL 不一致 | 检查并修正别名 |
212
+ | Unknown column? | 表中没有该字段 | 检查数据库表结构 |
265
213
 
266
214
  **调试**:开启 SQL 日志查看拼接结果
267
215
 
268
216
  ```yaml
269
- mybatis-plus:
270
- configuration:
271
- log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
217
+ # MyBatis SQL 日志
218
+ logging:
219
+ level:
220
+ [你的Mapper包路径]: debug
272
221
  ```
273
-
274
- ---
275
-
276
- ## 9. 核心类位置
277
-
278
- | 类 | 路径 |
279
- |---|------|
280
- | `@DataPermission` | `ruoyi-common/ruoyi-common-mybatis/.../annotation/DataPermission.java` |
281
- | `@DataColumn` | `ruoyi-common/ruoyi-common-mybatis/.../annotation/DataColumn.java` |
282
- | `DataScopeType` | `ruoyi-common/ruoyi-common-mybatis/.../enums/DataScopeType.java` |
283
- | `DataPermissionHelper` | `ruoyi-common/ruoyi-common-mybatis/.../helper/DataPermissionHelper.java` |
284
- | `PlusDataPermissionHandler` | `ruoyi-common/ruoyi-common-mybatis/.../handler/PlusDataPermissionHandler.java` |
285
- | 使用示例 | `ruoyi-modules/ruoyi-system/.../impl/SysUserServiceImpl.java` |
286
-
287
- ---
288
-
289
- ## 多项目适配说明
290
-
291
- - 如果需要 leniu-tengyun-core 项目的数据权限开发规范,请使用 `leniu-data-permission` skill
292
- - leniu-tengyun-core 使用物理库隔离架构,与 RuoYi-Vue-Plus 的逻辑隔离方式不同