ai-engineering-init 1.7.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.
- package/.claude/hooks/skill-forced-eval.js +46 -62
- package/.claude/settings.json +10 -1
- package/.claude/skills/api-development/SKILL.md +179 -130
- package/.claude/skills/architecture-design/SKILL.md +102 -212
- package/.claude/skills/backend-annotations/SKILL.md +166 -220
- package/.claude/skills/bug-detective/SKILL.md +225 -186
- package/.claude/skills/code-patterns/SKILL.md +127 -244
- package/.claude/skills/collaborating-with-codex/SKILL.md +96 -113
- package/.claude/skills/crud-development/SKILL.md +226 -307
- package/.claude/skills/data-permission/SKILL.md +131 -202
- package/.claude/skills/database-ops/SKILL.md +158 -355
- package/.claude/skills/error-handler/SKILL.md +224 -285
- package/.claude/skills/file-oss-management/SKILL.md +174 -169
- package/.claude/skills/git-workflow/SKILL.md +123 -341
- package/.claude/skills/json-serialization/SKILL.md +121 -137
- package/.claude/skills/performance-doctor/SKILL.md +83 -89
- package/.claude/skills/redis-cache/SKILL.md +134 -185
- package/.claude/skills/scheduled-jobs/SKILL.md +187 -224
- package/.claude/skills/security-guard/SKILL.md +168 -276
- package/.claude/skills/sms-mail/SKILL.md +266 -228
- package/.claude/skills/social-login/SKILL.md +257 -195
- package/.claude/skills/tenant-management/SKILL.md +172 -188
- package/.claude/skills/utils-toolkit/SKILL.md +214 -222
- package/.claude/skills/websocket-sse/SKILL.md +251 -172
- package/.claude/skills/workflow-engine/SKILL.md +178 -250
- package/.codex/skills/api-development/SKILL.md +179 -130
- package/.codex/skills/architecture-design/SKILL.md +102 -212
- package/.codex/skills/backend-annotations/SKILL.md +166 -220
- package/.codex/skills/bug-detective/SKILL.md +225 -186
- package/.codex/skills/code-patterns/SKILL.md +127 -244
- package/.codex/skills/collaborating-with-codex/SKILL.md +96 -113
- package/.codex/skills/crud-development/SKILL.md +226 -307
- package/.codex/skills/data-permission/SKILL.md +131 -202
- package/.codex/skills/database-ops/SKILL.md +158 -355
- package/.codex/skills/error-handler/SKILL.md +224 -285
- package/.codex/skills/file-oss-management/SKILL.md +174 -169
- package/.codex/skills/git-workflow/SKILL.md +123 -341
- package/.codex/skills/json-serialization/SKILL.md +121 -137
- package/.codex/skills/performance-doctor/SKILL.md +83 -89
- package/.codex/skills/redis-cache/SKILL.md +134 -185
- package/.codex/skills/scheduled-jobs/SKILL.md +187 -224
- package/.codex/skills/security-guard/SKILL.md +168 -276
- package/.codex/skills/sms-mail/SKILL.md +266 -228
- package/.codex/skills/social-login/SKILL.md +257 -195
- package/.codex/skills/tenant-management/SKILL.md +172 -188
- package/.codex/skills/utils-toolkit/SKILL.md +214 -222
- package/.codex/skills/websocket-sse/SKILL.md +251 -172
- package/.codex/skills/workflow-engine/SKILL.md +178 -250
- package/.cursor/hooks/cursor-skill-eval.js +66 -6
- package/.cursor/skills/api-development/SKILL.md +179 -130
- package/.cursor/skills/architecture-design/SKILL.md +102 -212
- package/.cursor/skills/backend-annotations/SKILL.md +166 -220
- package/.cursor/skills/bug-detective/SKILL.md +225 -186
- package/.cursor/skills/code-patterns/SKILL.md +127 -244
- package/.cursor/skills/collaborating-with-codex/SKILL.md +96 -113
- package/.cursor/skills/crud-development/SKILL.md +226 -307
- package/.cursor/skills/data-permission/SKILL.md +131 -202
- package/.cursor/skills/database-ops/SKILL.md +158 -355
- package/.cursor/skills/error-handler/SKILL.md +224 -285
- package/.cursor/skills/file-oss-management/SKILL.md +174 -169
- package/.cursor/skills/git-workflow/SKILL.md +123 -341
- package/.cursor/skills/json-serialization/SKILL.md +121 -137
- package/.cursor/skills/performance-doctor/SKILL.md +83 -89
- package/.cursor/skills/redis-cache/SKILL.md +134 -185
- package/.cursor/skills/scheduled-jobs/SKILL.md +187 -224
- package/.cursor/skills/security-guard/SKILL.md +168 -276
- package/.cursor/skills/sms-mail/SKILL.md +266 -228
- package/.cursor/skills/social-login/SKILL.md +257 -195
- package/.cursor/skills/tenant-management/SKILL.md +172 -188
- package/.cursor/skills/utils-toolkit/SKILL.md +214 -222
- package/.cursor/skills/websocket-sse/SKILL.md +251 -172
- package/.cursor/skills/workflow-engine/SKILL.md +178 -250
- package/AGENTS.md +49 -540
- package/CLAUDE.md +73 -119
- package/README.md +37 -6
- package/bin/index.js +5 -1
- package/package.json +1 -1
- package/src/skills/api-development/SKILL.md +179 -130
- package/src/skills/architecture-design/SKILL.md +102 -212
- package/src/skills/backend-annotations/SKILL.md +166 -220
- package/src/skills/bug-detective/SKILL.md +225 -186
- package/src/skills/code-patterns/SKILL.md +127 -244
- package/src/skills/collaborating-with-codex/SKILL.md +96 -113
- package/src/skills/crud-development/SKILL.md +226 -307
- package/src/skills/data-permission/SKILL.md +131 -202
- package/src/skills/database-ops/SKILL.md +158 -355
- package/src/skills/error-handler/SKILL.md +224 -285
- package/src/skills/file-oss-management/SKILL.md +174 -169
- package/src/skills/git-workflow/SKILL.md +123 -341
- package/src/skills/json-serialization/SKILL.md +121 -137
- package/src/skills/performance-doctor/SKILL.md +83 -89
- package/src/skills/redis-cache/SKILL.md +134 -185
- package/src/skills/scheduled-jobs/SKILL.md +187 -224
- package/src/skills/security-guard/SKILL.md +168 -276
- package/src/skills/sms-mail/SKILL.md +266 -228
- package/src/skills/social-login/SKILL.md +257 -195
- package/src/skills/tenant-management/SKILL.md +172 -188
- package/src/skills/utils-toolkit/SKILL.md +214 -222
- package/src/skills/websocket-sse/SKILL.md +251 -172
- package/src/skills/workflow-engine/SKILL.md +178 -250
- package/.claude/skills/skill-creator/LICENSE.txt +0 -202
- package/.claude/skills/skill-creator/SKILL.md +0 -479
- package/.claude/skills/skill-creator/agents/analyzer.md +0 -274
- package/.claude/skills/skill-creator/agents/comparator.md +0 -202
- package/.claude/skills/skill-creator/agents/grader.md +0 -223
- package/.claude/skills/skill-creator/assets/eval_review.html +0 -146
- package/.claude/skills/skill-creator/eval-viewer/generate_review.py +0 -471
- package/.claude/skills/skill-creator/eval-viewer/viewer.html +0 -1325
- package/.claude/skills/skill-creator/references/schemas.md +0 -430
- package/.claude/skills/skill-creator/scripts/__init__.py +0 -0
- package/.claude/skills/skill-creator/scripts/aggregate_benchmark.py +0 -401
- package/.claude/skills/skill-creator/scripts/generate_report.py +0 -326
- package/.claude/skills/skill-creator/scripts/improve_description.py +0 -248
- package/.claude/skills/skill-creator/scripts/package_skill.py +0 -136
- package/.claude/skills/skill-creator/scripts/quick_validate.py +0 -103
- package/.claude/skills/skill-creator/scripts/run_eval.py +0 -310
- package/.claude/skills/skill-creator/scripts/run_loop.py +0 -332
- package/.claude/skills/skill-creator/scripts/utils.py +0 -47
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
* UserPromptSubmit Hook - 强制技能评估 (跨平台版本)
|
|
4
4
|
* 功能: 开发场景下,将 Skills 激活率从约 25% 提升到 90% 以上
|
|
5
5
|
*
|
|
6
|
-
*
|
|
6
|
+
* 适配: 通用后端项目
|
|
7
7
|
* 架构: 三层架构 (Controller → Service → Mapper)
|
|
8
|
-
* 包名: org.dromara.*
|
|
9
8
|
*/
|
|
10
9
|
|
|
11
10
|
const fs = require('fs');
|
|
@@ -62,21 +61,18 @@ const instructions = `## 强制技能激活流程(必须执行)
|
|
|
62
61
|
|
|
63
62
|
针对用户问题,列出匹配的技能:\`技能名: 理由\`,无匹配则写"无匹配技能"
|
|
64
63
|
|
|
65
|
-
|
|
64
|
+
可用技能(后端项目):
|
|
66
65
|
- crud-development: CRUD/业务模块/Entity/Service/Controller 开发
|
|
67
66
|
- api-development: API设计/RESTful/接口规范
|
|
68
67
|
- database-ops: 数据库/SQL/建表/字典/菜单
|
|
69
|
-
- backend-annotations:
|
|
70
|
-
- utils-toolkit:
|
|
71
|
-
- file-oss-management: 文件上传/OSS
|
|
72
|
-
- ai-langchain4j: AI/大模型/ChatGPT/DeepSeek
|
|
73
|
-
- media-processing: 图片处理/二维码/水印/Excel
|
|
68
|
+
- backend-annotations: 注解/限流/防重复/脱敏/加密
|
|
69
|
+
- utils-toolkit: 工具类/对象转换/字符串/集合/日期
|
|
70
|
+
- file-oss-management: 文件上传/OSS/云存储
|
|
74
71
|
- bug-detective: Bug/报错/异常/不工作
|
|
75
|
-
-
|
|
76
|
-
- error-handler: 异常处理/ServiceException
|
|
72
|
+
- error-handler: 异常处理/全局异常/业务异常
|
|
77
73
|
- performance-doctor: 性能/慢查询/优化/缓存
|
|
78
|
-
- data-permission:
|
|
79
|
-
- security-guard:
|
|
74
|
+
- data-permission: 数据权限/行级权限/数据隔离
|
|
75
|
+
- security-guard: 安全/认证授权/加密/XSS/SQL注入防护
|
|
80
76
|
- architecture-design: 架构/模块划分/重构
|
|
81
77
|
- code-patterns: 规范/禁止/命名/Git提交
|
|
82
78
|
- project-navigator: 项目结构/文件在哪/定位
|
|
@@ -86,57 +82,45 @@ const instructions = `## 强制技能激活流程(必须执行)
|
|
|
86
82
|
- brainstorm: 头脑风暴/创意/方案设计
|
|
87
83
|
- collaborating-with-codex: Codex协作/多模型/算法分析
|
|
88
84
|
- collaborating-with-gemini: Gemini协作/前端原型/UI设计
|
|
89
|
-
- codex-code-review: 代码审查/review/代码检查/code review
|
|
90
|
-
- workflow-engine:
|
|
85
|
+
- codex-code-review: 代码审查/review/代码检查/code review
|
|
86
|
+
- workflow-engine: 工作流/审批流/流程引擎
|
|
91
87
|
- test-development: 测试/单元测试/@Test/JUnit5/Mockito
|
|
92
|
-
- json-serialization: JSON
|
|
93
|
-
- redis-cache: Redis/缓存/@Cacheable
|
|
94
|
-
- scheduled-jobs:
|
|
95
|
-
- add-skill:
|
|
96
|
-
- banana-image: 生成图片/AI
|
|
97
|
-
- websocket-sse: WebSocket/SSE
|
|
98
|
-
- sms-mail: 短信/邮件/SMS
|
|
99
|
-
- social-login:
|
|
100
|
-
- tenant-management: 多租户/租户隔离/
|
|
101
|
-
-
|
|
102
|
-
-
|
|
103
|
-
-
|
|
104
|
-
-
|
|
105
|
-
-
|
|
106
|
-
-
|
|
107
|
-
-
|
|
108
|
-
-
|
|
109
|
-
-
|
|
110
|
-
-
|
|
111
|
-
-
|
|
112
|
-
-
|
|
113
|
-
-
|
|
114
|
-
-
|
|
115
|
-
-
|
|
116
|
-
-
|
|
117
|
-
-
|
|
118
|
-
-
|
|
119
|
-
-
|
|
120
|
-
-
|
|
121
|
-
-
|
|
122
|
-
-
|
|
123
|
-
-
|
|
124
|
-
-
|
|
125
|
-
-
|
|
126
|
-
-
|
|
127
|
-
-
|
|
128
|
-
- leniu-marketing-price-rule-customizer: 营销计费/计价规则/RulePriceHandler/RulePriceEnum/折扣规则/满减规则/限额规则/补贴规则
|
|
129
|
-
- leniu-marketing-recharge-rule-customizer: 营销充值/充值规则/RuleRechargeHandler/RuleRechargeEnum/满赠规则/充值赠送/管理费规则
|
|
130
|
-
- openspec-new-change: 新建变更/开始新功能/opsx:new/openspec new/创建变更
|
|
131
|
-
- openspec-ff-change: 快速推进/快速生成所有制品/opsx:ff/openspec ff/fast-forward
|
|
132
|
-
- openspec-apply-change: 实现任务/开始实现/opsx:apply/openspec apply/执行变更
|
|
133
|
-
- openspec-continue-change: 继续变更/创建下一个制品/opsx:continue/openspec continue
|
|
134
|
-
- openspec-archive-change: 归档变更/完成变更/opsx:archive/openspec archive/归档
|
|
135
|
-
- openspec-bulk-archive-change: 批量归档/批量完成/opsx:bulk-archive/批量变更
|
|
136
|
-
- openspec-explore: 探索模式/思维伙伴/opsx:explore/openspec explore/探索问题
|
|
137
|
-
- openspec-onboard: 新手引导/学习工作流/opsx:onboard/openspec onboard/入门教程
|
|
138
|
-
- openspec-sync-specs: 同步规格/同步spec/opsx:sync/openspec sync/delta同步
|
|
139
|
-
- openspec-verify-change: 验证变更/检查实现/opsx:verify/openspec verify/验证规格
|
|
88
|
+
- json-serialization: JSON/序列化/反序列化/日期格式/BigDecimal/精度
|
|
89
|
+
- redis-cache: Redis/缓存/@Cacheable/分布式锁/限流
|
|
90
|
+
- scheduled-jobs: 定时任务/@Scheduled/Quartz/XXL-Job/任务调度
|
|
91
|
+
- add-skill: 添加技能/创建技能/新技能/技能开发
|
|
92
|
+
- banana-image: 生成图片/AI图片/产品图/海报/缩略图
|
|
93
|
+
- websocket-sse: WebSocket/SSE/实时推送/消息通知/双向通信
|
|
94
|
+
- sms-mail: 短信/邮件/SMS/验证码/通知
|
|
95
|
+
- social-login: 第三方登录/OAuth/OAuth2/社交登录/授权登录
|
|
96
|
+
- tenant-management: 多租户/租户隔离/SaaS/数据隔离
|
|
97
|
+
- openspec-new-change: 新建变更/开始新功能/opsx:new/openspec new
|
|
98
|
+
- openspec-ff-change: 快速推进/opsx:ff/openspec ff/fast-forward
|
|
99
|
+
- openspec-apply-change: 实现任务/opsx:apply/openspec apply
|
|
100
|
+
- openspec-continue-change: 继续变更/opsx:continue/openspec continue
|
|
101
|
+
- openspec-archive-change: 归档变更/opsx:archive/openspec archive
|
|
102
|
+
- openspec-bulk-archive-change: 批量归档/opsx:bulk-archive
|
|
103
|
+
- openspec-explore: 探索模式/opsx:explore/openspec explore
|
|
104
|
+
- openspec-onboard: 新手引导/opsx:onboard/openspec onboard
|
|
105
|
+
- openspec-sync-specs: 同步规格/opsx:sync/openspec sync
|
|
106
|
+
- openspec-verify-change: 验证变更/opsx:verify/openspec verify
|
|
107
|
+
- ui-pc: 前端组件/Element UI/页面开发
|
|
108
|
+
- store-pc: Vuex/状态管理/store模块
|
|
109
|
+
- mysql-debug: MySQL调试/查数据库/执行SQL/数据库排查
|
|
110
|
+
- loki-log-query: Loki日志/日志查询/线上日志排查
|
|
111
|
+
- yunxiao-task-management: 云效任务/任务管理/需求管理
|
|
112
|
+
- crud: 快速CRUD生成/脚手架
|
|
113
|
+
- dev: 开发新功能/功能开发流程
|
|
114
|
+
- check: 代码检查/规范检查
|
|
115
|
+
- start: 项目启动/初始化/开始
|
|
116
|
+
- next: 下一步/继续/接下来做什么
|
|
117
|
+
- progress: 进度查看/当前状态
|
|
118
|
+
- sync: 同步/代码同步
|
|
119
|
+
- sync-back-merge: 回合并/sync back merge/主分支同步
|
|
120
|
+
- init-docs: 初始化文档/项目文档生成
|
|
121
|
+
- add-todo: 添加待办/TODO/任务添加
|
|
122
|
+
- update-status: 更新状态/状态变更
|
|
123
|
+
- skill-creator: 创建技能模板/技能脚手架/skill scaffold
|
|
140
124
|
|
|
141
125
|
### 步骤 2 - 激活(逐个调用,等待每个完成)
|
|
142
126
|
|
package/.claude/settings.json
CHANGED
|
@@ -37,5 +37,14 @@
|
|
|
37
37
|
}
|
|
38
38
|
]
|
|
39
39
|
},
|
|
40
|
-
"mcpServers": {
|
|
40
|
+
"mcpServers": {
|
|
41
|
+
"sequential-thinking": {
|
|
42
|
+
"command": "npx",
|
|
43
|
+
"args": ["-y", "@modelcontextprotocol/server-sequential-thinking"]
|
|
44
|
+
},
|
|
45
|
+
"context7": {
|
|
46
|
+
"command": "npx",
|
|
47
|
+
"args": ["-y", "@upstash/context7-mcp"]
|
|
48
|
+
}
|
|
49
|
+
}
|
|
41
50
|
}
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: api-development
|
|
3
3
|
description: |
|
|
4
|
-
后端 API
|
|
4
|
+
后端 API 接口设计规范。基于 Spring Boot 的 RESTful API 开发指南。
|
|
5
5
|
|
|
6
6
|
触发场景:
|
|
7
7
|
- 设计 RESTful API 接口
|
|
8
8
|
- 编写 Controller 层代码
|
|
9
|
-
-
|
|
9
|
+
- 配置接口权限、日志注解
|
|
10
10
|
- 接口返回值类型选择
|
|
11
11
|
- 数据验证和参数校验
|
|
12
12
|
|
|
13
13
|
触发词:API、接口、RESTful、Controller、GetMapping、PostMapping、权限注解、日志注解、分页查询、接口规范
|
|
14
14
|
|
|
15
15
|
注意:
|
|
16
|
-
-
|
|
17
|
-
- 参考 java-controller 技能获取更详细的 Controller 层规范
|
|
16
|
+
- 参考项目实际架构层次选择合适的分层模式
|
|
18
17
|
---
|
|
19
18
|
|
|
20
19
|
# API 接口设计规范
|
|
@@ -23,22 +22,22 @@ description: |
|
|
|
23
22
|
|
|
24
23
|
| 原则 | 说明 |
|
|
25
24
|
|------|------|
|
|
26
|
-
|
|
|
25
|
+
| RESTful 风格 | 使用标准 HTTP 方法表达语义 |
|
|
27
26
|
| 认证保护 | 所有业务接口必须添加认证注解 |
|
|
28
27
|
| 参数校验 | 使用分组校验区分新增/修改场景 |
|
|
29
28
|
| 统一响应 | 使用统一的响应格式包装返回数据 |
|
|
30
29
|
|
|
31
30
|
### HTTP 方法规范
|
|
32
31
|
|
|
33
|
-
| 操作 | 方法 |
|
|
34
|
-
|
|
35
|
-
| 列表查询 |
|
|
36
|
-
| 获取详情 |
|
|
37
|
-
| 新增 | POST | `/add` |
|
|
38
|
-
| 修改 |
|
|
39
|
-
| 删除 |
|
|
32
|
+
| 操作 | 方法 | 路径示例 |
|
|
33
|
+
|------|------|---------|
|
|
34
|
+
| 列表查询 | GET | `/list` 或 `/page` |
|
|
35
|
+
| 获取详情 | GET | `/{id}` |
|
|
36
|
+
| 新增 | POST | `/` 或 `/add` |
|
|
37
|
+
| 修改 | PUT | `/` 或 `/update` |
|
|
38
|
+
| 删除 | DELETE | `/{ids}` |
|
|
40
39
|
| 导出 | POST | `/export` |
|
|
41
|
-
| 导入 | POST | `/import
|
|
40
|
+
| 导入 | POST | `/import` |
|
|
42
41
|
|
|
43
42
|
---
|
|
44
43
|
|
|
@@ -47,65 +46,106 @@ description: |
|
|
|
47
46
|
```java
|
|
48
47
|
@Slf4j
|
|
49
48
|
@RestController
|
|
50
|
-
@
|
|
51
|
-
@RequestMapping("/
|
|
52
|
-
@Api(value = "模块/功能", tags = "模块/功能")
|
|
49
|
+
@RequiredArgsConstructor
|
|
50
|
+
@RequestMapping("/api/v1/[模块]/[功能]")
|
|
53
51
|
public class XxxController {
|
|
54
52
|
|
|
55
|
-
|
|
56
|
-
private XxxService xxxService;
|
|
53
|
+
private final XxxService xxxService;
|
|
57
54
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
/**
|
|
56
|
+
* 分页查询
|
|
57
|
+
*/
|
|
58
|
+
@GetMapping("/page")
|
|
59
|
+
public Result<PageResult<XxxVO>> page(XxxQueryDTO query) {
|
|
60
|
+
return Result.ok(xxxService.pageList(query));
|
|
62
61
|
}
|
|
63
62
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
/**
|
|
64
|
+
* 获取详情
|
|
65
|
+
*/
|
|
66
|
+
@GetMapping("/{id}")
|
|
67
|
+
public Result<XxxVO> getById(@PathVariable Long id) {
|
|
68
|
+
return Result.ok(xxxService.getById(id));
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
/**
|
|
72
|
+
* 新增
|
|
73
|
+
*/
|
|
74
|
+
@PostMapping
|
|
75
|
+
public Result<Long> add(@Validated(InsertGroup.class) @RequestBody XxxDTO dto) {
|
|
76
|
+
return Result.ok(xxxService.add(dto));
|
|
74
77
|
}
|
|
75
78
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
/**
|
|
80
|
+
* 修改
|
|
81
|
+
*/
|
|
82
|
+
@PutMapping
|
|
83
|
+
public Result<Void> update(@Validated(UpdateGroup.class) @RequestBody XxxDTO dto) {
|
|
84
|
+
xxxService.update(dto);
|
|
85
|
+
return Result.ok();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 删除
|
|
90
|
+
*/
|
|
91
|
+
@DeleteMapping("/{ids}")
|
|
92
|
+
public Result<Void> delete(@PathVariable List<Long> ids) {
|
|
93
|
+
xxxService.deleteByIds(ids);
|
|
94
|
+
return Result.ok();
|
|
80
95
|
}
|
|
81
96
|
}
|
|
82
97
|
```
|
|
83
98
|
|
|
84
99
|
---
|
|
85
100
|
|
|
86
|
-
##
|
|
101
|
+
## 统一响应封装
|
|
87
102
|
|
|
88
|
-
###
|
|
103
|
+
### Result 包装类(通用模式)
|
|
89
104
|
|
|
90
105
|
```java
|
|
91
|
-
@
|
|
92
|
-
public
|
|
93
|
-
|
|
106
|
+
@Data
|
|
107
|
+
public class Result<T> {
|
|
108
|
+
private int code;
|
|
109
|
+
private String message;
|
|
110
|
+
private T data;
|
|
111
|
+
|
|
112
|
+
public static <T> Result<T> ok() {
|
|
113
|
+
return ok(null);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
public static <T> Result<T> ok(T data) {
|
|
117
|
+
Result<T> result = new Result<>();
|
|
118
|
+
result.setCode(200);
|
|
119
|
+
result.setMessage("success");
|
|
120
|
+
result.setData(data);
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
public static <T> Result<T> fail(String message) {
|
|
125
|
+
Result<T> result = new Result<>();
|
|
126
|
+
result.setCode(500);
|
|
127
|
+
result.setMessage(message);
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
94
130
|
}
|
|
95
131
|
```
|
|
96
132
|
|
|
97
|
-
###
|
|
133
|
+
### 分页响应
|
|
98
134
|
|
|
99
135
|
```java
|
|
100
136
|
@Data
|
|
101
|
-
public class
|
|
102
|
-
|
|
103
|
-
private
|
|
104
|
-
private
|
|
105
|
-
private
|
|
137
|
+
public class PageResult<T> {
|
|
138
|
+
private List<T> records;
|
|
139
|
+
private long total;
|
|
140
|
+
private long current;
|
|
141
|
+
private long size;
|
|
106
142
|
}
|
|
107
143
|
```
|
|
108
144
|
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## 参数校验
|
|
148
|
+
|
|
109
149
|
### 分组校验
|
|
110
150
|
|
|
111
151
|
```java
|
|
@@ -116,142 +156,152 @@ public class XxxDTO {
|
|
|
116
156
|
private Long id;
|
|
117
157
|
|
|
118
158
|
@NotBlank(message = "名称不能为空", groups = {InsertGroup.class, UpdateGroup.class})
|
|
159
|
+
@Size(max = 100, message = "名称长度不能超过100个字符")
|
|
119
160
|
private String name;
|
|
161
|
+
|
|
162
|
+
@Min(value = 0, message = "排序不能为负数")
|
|
163
|
+
private Integer sort;
|
|
120
164
|
}
|
|
121
165
|
|
|
122
166
|
// Controller 中应用
|
|
123
|
-
@PostMapping
|
|
124
|
-
public Long add(@Validated(InsertGroup.class) @RequestBody
|
|
125
|
-
```
|
|
167
|
+
@PostMapping
|
|
168
|
+
public Result<Long> add(@Validated(InsertGroup.class) @RequestBody XxxDTO dto) { ... }
|
|
126
169
|
|
|
127
|
-
|
|
170
|
+
@PutMapping
|
|
171
|
+
public Result<Void> update(@Validated(UpdateGroup.class) @RequestBody XxxDTO dto) { ... }
|
|
172
|
+
```
|
|
128
173
|
|
|
129
|
-
|
|
174
|
+
> Jakarta Validation: JDK 17+ 必须 `import jakarta.validation.constraints.*`
|
|
130
175
|
|
|
131
|
-
|
|
176
|
+
### 查询参数
|
|
132
177
|
|
|
133
178
|
```java
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
179
|
+
@Data
|
|
180
|
+
public class XxxQueryDTO {
|
|
181
|
+
private String keyword;
|
|
182
|
+
private Integer status;
|
|
137
183
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
public XxxVO getById(@PathVariable Long id) { ... }
|
|
184
|
+
@Min(value = 1)
|
|
185
|
+
private Integer pageNum = 1;
|
|
141
186
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
187
|
+
@Min(value = 1) @Max(value = 100)
|
|
188
|
+
private Integer pageSize = 10;
|
|
189
|
+
}
|
|
145
190
|
```
|
|
146
191
|
|
|
147
192
|
---
|
|
148
193
|
|
|
149
194
|
## 常见场景
|
|
150
195
|
|
|
151
|
-
###
|
|
196
|
+
### 带分布式锁的导入
|
|
152
197
|
|
|
153
198
|
```java
|
|
154
|
-
@PostMapping("/import
|
|
155
|
-
@
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
throw new LeException("文件不能为空");
|
|
159
|
-
}
|
|
160
|
-
RLock lock = redissonClient.getLock("import:lock:" + TenantContextHolder.getTenantId());
|
|
161
|
-
if (!lock.tryLock(5, 60, TimeUnit.SECONDS)) {
|
|
162
|
-
throw new LeException("正在处理中,请稍后再试");
|
|
199
|
+
@PostMapping("/import")
|
|
200
|
+
public Result<Void> importExcel(@RequestPart("file") MultipartFile file) {
|
|
201
|
+
if (file == null || file.isEmpty()) {
|
|
202
|
+
throw new [你的异常类]("文件不能为空");
|
|
163
203
|
}
|
|
204
|
+
RLock lock = redissonClient.getLock("import:lock:" + getCurrentTenantId());
|
|
164
205
|
try {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
206
|
+
if (!lock.tryLock(5, 60, TimeUnit.SECONDS)) {
|
|
207
|
+
throw new [你的异常类]("正在处理中,请稍后再试");
|
|
208
|
+
}
|
|
209
|
+
try {
|
|
210
|
+
xxxService.importExcel(file);
|
|
211
|
+
} finally {
|
|
212
|
+
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
|
|
213
|
+
lock.unlock();
|
|
214
|
+
}
|
|
169
215
|
}
|
|
216
|
+
} catch (InterruptedException e) {
|
|
217
|
+
Thread.currentThread().interrupt();
|
|
218
|
+
throw new [你的异常类]("导入被中断");
|
|
170
219
|
}
|
|
220
|
+
return Result.ok();
|
|
171
221
|
}
|
|
172
222
|
```
|
|
173
223
|
|
|
174
224
|
### 批量删除
|
|
175
225
|
|
|
176
226
|
```java
|
|
177
|
-
@
|
|
178
|
-
@
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
throw new LeException("ID列表不能为空");
|
|
227
|
+
@DeleteMapping("/{ids}")
|
|
228
|
+
public Result<Void> delete(@PathVariable List<Long> ids) {
|
|
229
|
+
if (ids == null || ids.isEmpty()) {
|
|
230
|
+
throw new [你的异常类]("ID列表不能为空");
|
|
182
231
|
}
|
|
183
|
-
xxxService.
|
|
232
|
+
xxxService.deleteByIds(ids);
|
|
233
|
+
return Result.ok();
|
|
184
234
|
}
|
|
185
235
|
```
|
|
186
236
|
|
|
187
|
-
###
|
|
237
|
+
### 文件上传
|
|
188
238
|
|
|
189
239
|
```java
|
|
190
|
-
@PostMapping("/
|
|
191
|
-
@
|
|
192
|
-
|
|
193
|
-
ReportBaseTotalVO<XxxVO> result = new ReportBaseTotalVO<>();
|
|
194
|
-
result.setTotalLine(xxxService.getSummaryTotal(request.getContent()));
|
|
195
|
-
result.setResultPage(PageVO.of(xxxService.pageList(request.getContent())));
|
|
196
|
-
return result;
|
|
240
|
+
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
|
241
|
+
public Result<UploadResult> upload(@RequestPart("file") MultipartFile file) {
|
|
242
|
+
return Result.ok(ossService.upload(file));
|
|
197
243
|
}
|
|
198
244
|
```
|
|
199
245
|
|
|
200
246
|
---
|
|
201
247
|
|
|
202
|
-
##
|
|
248
|
+
## API 文档注解
|
|
249
|
+
|
|
250
|
+
### Swagger / SpringDoc 注解
|
|
203
251
|
|
|
204
252
|
```java
|
|
205
|
-
|
|
206
|
-
@
|
|
207
|
-
@
|
|
208
|
-
@
|
|
253
|
+
// SpringDoc (OpenAPI 3.0, 推荐)
|
|
254
|
+
@Tag(name = "用户管理") // Controller 类
|
|
255
|
+
@Operation(summary = "新增用户") // 方法
|
|
256
|
+
@Schema(description = "用户DTO") // DTO/VO 类
|
|
257
|
+
@Schema(description = "主键ID", requiredMode = REQUIRED) // 字段
|
|
258
|
+
|
|
259
|
+
// Swagger 2 (旧项目)
|
|
260
|
+
@Api(value = "用户管理", tags = "用户管理")
|
|
261
|
+
@ApiOperation(value = "新增用户")
|
|
262
|
+
@ApiModel("用户DTO")
|
|
263
|
+
@ApiModelProperty(value = "主键ID", required = true)
|
|
209
264
|
```
|
|
210
265
|
|
|
211
266
|
---
|
|
212
267
|
|
|
213
|
-
##
|
|
268
|
+
## 全局异常处理
|
|
214
269
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
- [ ] 返回值类型正确(分页用 `Page<VO>`)
|
|
219
|
-
- [ ] 使用 `LeRequest<T>` 封装请求
|
|
220
|
-
- [ ] 敏感操作加分布式锁
|
|
270
|
+
```java
|
|
271
|
+
@RestControllerAdvice
|
|
272
|
+
public class GlobalExceptionHandler {
|
|
221
273
|
|
|
222
|
-
|
|
274
|
+
@ExceptionHandler([你的异常类].class)
|
|
275
|
+
public Result<Void> handleBusinessException([你的异常类] e) {
|
|
276
|
+
return Result.fail(e.getMessage());
|
|
277
|
+
}
|
|
223
278
|
|
|
224
|
-
|
|
279
|
+
@ExceptionHandler(MethodArgumentNotValidException.class)
|
|
280
|
+
public Result<Void> handleValidException(MethodArgumentNotValidException e) {
|
|
281
|
+
String message = e.getBindingResult().getFieldErrors().stream()
|
|
282
|
+
.map(FieldError::getDefaultMessage)
|
|
283
|
+
.collect(Collectors.joining(", "));
|
|
284
|
+
return Result.fail(message);
|
|
285
|
+
}
|
|
225
286
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
| 认证 | `@SaCheckPermission` | `@RequiresAuthentication` |
|
|
234
|
-
| 异常 | `ServiceException` | `LeException` |
|
|
235
|
-
| 国际化 | `MessageUtils.message()` | `I18n.getMessage()` |
|
|
287
|
+
@ExceptionHandler(Exception.class)
|
|
288
|
+
public Result<Void> handleException(Exception e) {
|
|
289
|
+
log.error("系统异常", e);
|
|
290
|
+
return Result.fail("系统繁忙,请稍后再试");
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
```
|
|
236
294
|
|
|
237
295
|
---
|
|
238
296
|
|
|
239
|
-
##
|
|
297
|
+
## 检查清单
|
|
240
298
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
// ---- 正确 ----
|
|
249
|
-
@RestController @RequiresAuthentication
|
|
250
|
-
public Long add(@Validated(InsertGroup.class) @RequestBody LeRequest<XxxDTO> request) {
|
|
251
|
-
return xxxService.add(request.getContent());
|
|
252
|
-
}
|
|
253
|
-
import jakarta.validation.constraints.NotNull;
|
|
254
|
-
```
|
|
299
|
+
- [ ] 认证注解(`@PreAuthorize` / `[你的认证注解]`)
|
|
300
|
+
- [ ] API 文档注解(`@Operation` / `@ApiOperation`)
|
|
301
|
+
- [ ] 参数校验 `@Validated` + 分组
|
|
302
|
+
- [ ] 统一响应包装 `Result<T>`
|
|
303
|
+
- [ ] 敏感操作加分布式锁
|
|
304
|
+
- [ ] 全局异常处理器已配置
|
|
255
305
|
|
|
256
306
|
---
|
|
257
307
|
|
|
@@ -259,8 +309,7 @@ import jakarta.validation.constraints.NotNull;
|
|
|
259
309
|
|
|
260
310
|
| 需要了解 | Skill |
|
|
261
311
|
|---------|-------|
|
|
262
|
-
| Service 层 | `java-service` |
|
|
263
|
-
| Controller 详细 | `java-controller` |
|
|
264
312
|
| 异常处理 | `error-handler` |
|
|
265
|
-
| 参数校验 | `java-entity` |
|
|
266
313
|
| 数据库设计 | `database-ops` |
|
|
314
|
+
| 缓存 | `redis-cache` |
|
|
315
|
+
| 文件上传 | `file-oss-management` |
|