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
@@ -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 的逻辑隔离方式不同