ai-engineering-init 1.4.3 → 1.6.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/.cursor/skills/bug-detective/SKILL.md +19 -19
- package/.cursor/skills/project-navigator/SKILL.md +164 -258
- package/README.md +20 -236
- package/bin/index.js +437 -7
- package/package.json +7 -1
- package/scripts/build-skills.js +180 -0
- package/src/platform-map.json +56 -0
- package/src/skills/add-skill/SKILL.md +488 -0
- package/src/skills/add-todo/SKILL.md +269 -0
- package/src/skills/api-development/SKILL.md +266 -0
- package/src/skills/architecture-design/SKILL.md +262 -0
- package/src/skills/backend-annotations/SKILL.md +302 -0
- package/src/skills/banana-image/CHANGELOG.md +37 -0
- package/src/skills/banana-image/README.md +146 -0
- package/src/skills/banana-image/SKILL.md +171 -0
- package/src/skills/banana-image/assets/logo.png +0 -0
- package/src/skills/banana-image/references/advanced-usage.md +189 -0
- package/src/skills/banana-image/scripts/apply_template.py +125 -0
- package/src/skills/banana-image/scripts/banana_image_exec.ts +412 -0
- package/src/skills/banana-image/scripts/batch_prep.py +82 -0
- package/src/skills/banana-image/scripts/package-lock.json +1437 -0
- package/src/skills/banana-image/scripts/package.json +18 -0
- package/src/skills/banana-image/scripts/requirements.txt +10 -0
- package/src/skills/banana-image/templates/poster.json +22 -0
- package/src/skills/banana-image/templates/product.json +17 -0
- package/src/skills/banana-image/templates/social.json +22 -0
- package/src/skills/banana-image/templates/thumbnail.json +17 -0
- package/src/skills/brainstorm/SKILL.md +216 -0
- package/src/skills/bug-detective/SKILL.md +256 -0
- package/src/skills/bug-detective/references/error-patterns.md +242 -0
- package/src/skills/check/SKILL.md +367 -0
- package/src/skills/code-patterns/SKILL.md +280 -0
- package/src/skills/code-patterns/references/leniu-code-patterns.md +87 -0
- package/src/skills/codex-code-review/SKILL.md +135 -0
- package/src/skills/collaborating-with-codex/SKILL.md +174 -0
- package/src/skills/collaborating-with-codex/scripts/codex_bridge.py +275 -0
- package/src/skills/collaborating-with-gemini/SKILL.md +194 -0
- package/src/skills/collaborating-with-gemini/scripts/gemini_bridge.py +275 -0
- package/src/skills/crud/SKILL.md +265 -0
- package/src/skills/crud-development/SKILL.md +409 -0
- package/src/skills/data-permission/SKILL.md +292 -0
- package/src/skills/data-permission/references/custom-data-scope.md +90 -0
- package/src/skills/database-ops/SKILL.md +407 -0
- package/src/skills/dev/SKILL.md +187 -0
- package/src/skills/error-handler/SKILL.md +371 -0
- package/src/skills/file-oss-management/SKILL.md +255 -0
- package/src/skills/file-oss-management/references/entities.md +105 -0
- package/src/skills/file-oss-management/references/service-impl.md +104 -0
- package/src/skills/git-workflow/SKILL.md +397 -0
- package/src/skills/init-docs/SKILL.md +194 -0
- package/src/skills/json-serialization/SKILL.md +357 -0
- package/src/skills/leniu-api-development/SKILL.md +319 -0
- package/src/skills/leniu-api-development/references/real-examples.md +273 -0
- package/src/skills/leniu-architecture-design/SKILL.md +383 -0
- package/src/skills/leniu-backend-annotations/SKILL.md +277 -0
- package/src/skills/leniu-brainstorm/SKILL.md +242 -0
- package/src/skills/leniu-brainstorm/references/business-scenarios.md +162 -0
- package/src/skills/leniu-code-patterns/SKILL.md +411 -0
- package/src/skills/leniu-crud-development/SKILL.md +404 -0
- package/src/skills/leniu-crud-development/references/templates.md +597 -0
- package/src/skills/leniu-customization-location/SKILL.md +410 -0
- package/src/skills/leniu-data-permission/SKILL.md +341 -0
- package/src/skills/leniu-database-ops/SKILL.md +426 -0
- package/src/skills/leniu-error-handler/SKILL.md +462 -0
- package/src/skills/leniu-java-amount-handling/SKILL.md +461 -0
- package/src/skills/leniu-java-code-style/SKILL.md +510 -0
- package/src/skills/leniu-java-concurrent/SKILL.md +400 -0
- package/src/skills/leniu-java-entity/SKILL.md +237 -0
- package/src/skills/leniu-java-entity/references/templates.md +237 -0
- package/src/skills/leniu-java-export/SKILL.md +570 -0
- package/src/skills/leniu-java-logging/SKILL.md +229 -0
- package/src/skills/leniu-java-logging/references/data-mask.md +46 -0
- package/src/skills/leniu-java-logging/references/logging-scenarios.md +113 -0
- package/src/skills/leniu-java-mq/SKILL.md +338 -0
- package/src/skills/leniu-java-mybatis/SKILL.md +267 -0
- package/src/skills/leniu-java-mybatis/references/report-mapper.md +88 -0
- package/src/skills/leniu-java-report-query-param/SKILL.md +291 -0
- package/src/skills/leniu-java-task/SKILL.md +367 -0
- package/src/skills/leniu-java-total-line/SKILL.md +196 -0
- package/src/skills/leniu-marketing-price-rule-customizer/SKILL.md +301 -0
- package/src/skills/leniu-marketing-recharge-rule-customizer/SKILL.md +285 -0
- package/src/skills/leniu-mealtime/SKILL.md +215 -0
- package/src/skills/leniu-redis-cache/SKILL.md +331 -0
- package/src/skills/leniu-report-customization/SKILL.md +335 -0
- package/src/skills/leniu-report-customization/references/table-fields.md +93 -0
- package/src/skills/leniu-report-standard-customization/SKILL.md +328 -0
- package/src/skills/leniu-report-standard-customization/references/analysis-module.md +64 -0
- package/src/skills/leniu-report-standard-customization/references/table-fields.md +113 -0
- package/src/skills/leniu-security-guard/SKILL.md +306 -0
- package/src/skills/leniu-utils-toolkit/SKILL.md +380 -0
- package/src/skills/mysql-debug/SKILL.md +364 -0
- package/src/skills/next/SKILL.md +137 -0
- package/src/skills/openspec-apply-change/SKILL.md +165 -0
- package/src/skills/openspec-archive-change/SKILL.md +122 -0
- package/src/skills/openspec-bulk-archive-change/SKILL.md +254 -0
- package/src/skills/openspec-continue-change/SKILL.md +126 -0
- package/src/skills/openspec-explore/SKILL.md +299 -0
- package/src/skills/openspec-ff-change/SKILL.md +109 -0
- package/src/skills/openspec-new-change/SKILL.md +82 -0
- package/src/skills/openspec-onboard/SKILL.md +414 -0
- package/src/skills/openspec-sync-specs/SKILL.md +146 -0
- package/src/skills/openspec-verify-change/SKILL.md +176 -0
- package/src/skills/performance-doctor/SKILL.md +303 -0
- package/src/skills/progress/SKILL.md +193 -0
- package/src/skills/project-navigator/SKILL.md +211 -0
- package/src/skills/redis-cache/SKILL.md +333 -0
- package/src/skills/redis-cache/references/listeners.md +23 -0
- package/src/skills/scheduled-jobs/SKILL.md +314 -0
- package/src/skills/security-guard/SKILL.md +353 -0
- package/src/skills/security-guard/references/encrypt-config.md +103 -0
- package/src/skills/security-guard/references/sensitive-strategies.md +42 -0
- package/src/skills/sms-mail/SKILL.md +308 -0
- package/src/skills/sms-mail/references/mail-config.md +88 -0
- package/src/skills/sms-mail/references/sms-config.md +74 -0
- package/src/skills/social-login/SKILL.md +266 -0
- package/src/skills/social-login/references/provider-configs.md +118 -0
- package/src/skills/start/SKILL.md +154 -0
- package/src/skills/store-pc/SKILL.md +366 -0
- package/src/skills/sync/SKILL.md +149 -0
- package/src/skills/task-tracker/SKILL.md +307 -0
- package/src/skills/tech-decision/SKILL.md +393 -0
- package/src/skills/tenant-management/SKILL.md +288 -0
- package/src/skills/tenant-management/references/tenant-scenarios.md +91 -0
- package/src/skills/test-development/SKILL.md +301 -0
- package/src/skills/test-development/references/parameterized-examples.md +119 -0
- package/src/skills/ui-pc/SKILL.md +438 -0
- package/src/skills/update-status/SKILL.md +159 -0
- package/src/skills/utils-toolkit/SKILL.md +362 -0
- package/src/skills/utils-toolkit/references/redis-utils-api.md +56 -0
- package/src/skills/websocket-sse/SKILL.md +271 -0
- package/src/skills/workflow-engine/SKILL.md +321 -0
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: leniu-code-patterns
|
|
3
|
+
description: |
|
|
4
|
+
leniu-tengyun-core 项目代码规范速查。基于 pigx-framework 框架的后端代码禁令和编码规范。
|
|
5
|
+
|
|
6
|
+
触发场景:
|
|
7
|
+
- 查看项目禁止事项(leniu 后端代码)
|
|
8
|
+
- 命名规范速查
|
|
9
|
+
- Git 提交规范
|
|
10
|
+
- 避免过度工程
|
|
11
|
+
- 代码风格检查
|
|
12
|
+
|
|
13
|
+
触发词:代码禁令、代码规范、命名规范、代码风格、Git提交规范、包结构、禁止写法、审计字段规范、delFlag、crby/crtime
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
# leniu-tengyun-core 代码规范速查
|
|
17
|
+
|
|
18
|
+
## leniu 项目特征
|
|
19
|
+
|
|
20
|
+
| 项目特征 | 说明 |
|
|
21
|
+
|----------|------|
|
|
22
|
+
| **包名前缀** | `net.xnzn.core.*` |
|
|
23
|
+
| **JDK 版本** | 21 |
|
|
24
|
+
| **Validation** | `jakarta.validation.*` |
|
|
25
|
+
| **工具库** | Hutool (CollUtil, ObjectUtil, BeanUtil) |
|
|
26
|
+
| **分页组件** | PageHelper (PageMethod) |
|
|
27
|
+
| **对象转换** | `BeanUtil.copyProperties()` |
|
|
28
|
+
| **异常类** | `LeException` |
|
|
29
|
+
| **国际化** | `I18n` |
|
|
30
|
+
| **租户上下文** | `TenantContextHolder` |
|
|
31
|
+
|
|
32
|
+
## 与 RuoYi-Vue-Plus 对比
|
|
33
|
+
|
|
34
|
+
| 特征 | RuoYi-Vue-Plus | leniu-tengyun-core |
|
|
35
|
+
|---------|----------------|-------------------|
|
|
36
|
+
| **包名前缀** | `org.dromara.*` | `net.xnzn.core.*` |
|
|
37
|
+
| **JDK 版本** | 17 | 21 |
|
|
38
|
+
| **Validation** | `jakarta.validation.*` | `jakarta.validation.*` |
|
|
39
|
+
| **工具库** | 自定义工具类 | Hutool |
|
|
40
|
+
| **分页** | `TableDataInfo<T>` | `Page<T>` |
|
|
41
|
+
| **对象转换** | `MapstructUtils.convert()` | `BeanUtil.copyProperties()` |
|
|
42
|
+
| **异常类** | `ServiceException` | `LeException` |
|
|
43
|
+
| **国际化** | `MessageUtils.message()` | `I18n.getMessage()` |
|
|
44
|
+
| **审计字段** | create_by/create_time/update_by/update_time | crby/crtime/upby/uptime |
|
|
45
|
+
| **逻辑删除** | 0=正常, 2=删除 | 1=删除, 2=正常 |
|
|
46
|
+
|
|
47
|
+
## 后端禁令速查表
|
|
48
|
+
|
|
49
|
+
> **快速查表**:一眼定位所有后端代码禁止写法
|
|
50
|
+
|
|
51
|
+
| 禁止项 | ❌ 禁止写法 | ✅ 正确写法 | 原因 |
|
|
52
|
+
|--------|-----------|-----------|------|
|
|
53
|
+
| 包名规范 | `org.dromara.*` | `net.xnzn.core.*` | 包名统一标准 |
|
|
54
|
+
| 完整引用 | `org.dromara.xxx.Xxx` | `import` + 短类名 | 代码整洁 |
|
|
55
|
+
| Map 封装业务数据 | `Map<String, Object>` | 创建 VO 类 | 类型安全 |
|
|
56
|
+
| Service 继承基类 | `extends ServiceImpl<>` | `implements XxxService` | 三层架构 |
|
|
57
|
+
| 查询构建位置 | Controller 层 | **Service 层** | 职责分离 |
|
|
58
|
+
| 对象转换工具 | `MapstructUtils` | `BeanUtil.copyProperties()` | 项目统一规范 |
|
|
59
|
+
| 审计字段命名 | create_by/create_time | crby/crtime | 项目规范 |
|
|
60
|
+
| 逻辑删除值 | 0=正常, 2=删除 | 2=正常, 1=删除 | 项目规范 |
|
|
61
|
+
| 异常类 | `ServiceException` | `LeException` | 项目规范 |
|
|
62
|
+
| 国际化工具 | `MessageUtils` | `I18n` | 项目规范 |
|
|
63
|
+
|
|
64
|
+
## 后端禁令详解
|
|
65
|
+
|
|
66
|
+
### 1. 包名必须是 `net.xnzn.core.*`
|
|
67
|
+
|
|
68
|
+
```java
|
|
69
|
+
// ✅ 正确
|
|
70
|
+
package net.xnzn.core.order.service;
|
|
71
|
+
package net.xnzn.core.marketing.handler;
|
|
72
|
+
|
|
73
|
+
// ❌ 错误
|
|
74
|
+
package org.dromara.system.service;
|
|
75
|
+
package plus.ruoyi.business.service;
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 2. 禁止使用完整类型引用
|
|
79
|
+
|
|
80
|
+
```java
|
|
81
|
+
// ✅ 正确:先 import 再使用
|
|
82
|
+
import net.xnzn.core.common.response.LeResponse;
|
|
83
|
+
public LeResponse<XxxVo> getXxx(Long id) { ... }
|
|
84
|
+
|
|
85
|
+
// ❌ 错误:直接使用完整包名
|
|
86
|
+
public net.xnzn.core.common.response.LeResponse<XxxVo> getXxx(Long id) { ... }
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 3. 禁止使用 Map 封装业务数据
|
|
90
|
+
|
|
91
|
+
```java
|
|
92
|
+
// ✅ 正确:创建 VO 类
|
|
93
|
+
public XxxVo getXxx(Long id) {
|
|
94
|
+
XxxEntity entity = mapper.selectById(id);
|
|
95
|
+
return BeanUtil.copyProperties(entity, XxxVo.class);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// ❌ 错误:使用 Map
|
|
99
|
+
public Map<String, Object> getXxx(Long id) {
|
|
100
|
+
XxxEntity entity = mapper.selectById(id);
|
|
101
|
+
Map<String, Object> result = new HashMap<>();
|
|
102
|
+
result.put("id", entity.getId());
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### 4. Service 禁止继承 ServiceImpl 基类
|
|
108
|
+
|
|
109
|
+
```java
|
|
110
|
+
// ✅ 正确:不继承任何基类,直接注入 Mapper
|
|
111
|
+
@Service
|
|
112
|
+
public class XxxServiceImpl implements XxxService {
|
|
113
|
+
@Autowired
|
|
114
|
+
private XxxMapper mapper;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// ❌ 错误:继承 ServiceImpl
|
|
118
|
+
public class XxxServiceImpl extends ServiceImpl<XxxMapper, Xxx> {
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### 5. 查询条件必须在 Service 层构建
|
|
123
|
+
|
|
124
|
+
```java
|
|
125
|
+
// ✅ 正确:在 Service 层构建查询条件
|
|
126
|
+
@Service
|
|
127
|
+
public class XxxServiceImpl implements XxxService {
|
|
128
|
+
|
|
129
|
+
@Autowired
|
|
130
|
+
private XxxMapper mapper;
|
|
131
|
+
|
|
132
|
+
private LambdaQueryWrapper<Xxx> buildWrapper(XxxParam param) {
|
|
133
|
+
return Wrappers.lambdaQuery()
|
|
134
|
+
.eq(param.getStatus() != null, Xxx::getStatus, param.getStatus());
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
public List<XxxVo> list(XxxParam param) {
|
|
138
|
+
return mapper.selectList(buildWrapper(param));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// ❌ 错误:在 Controller 层构建查询条件
|
|
143
|
+
@RestController
|
|
144
|
+
public class XxxController {
|
|
145
|
+
@GetMapping("/list")
|
|
146
|
+
public LeResponse<List<XxxVo>> list(XxxParam param) {
|
|
147
|
+
LambdaQueryWrapper<Xxx> wrapper = new LambdaQueryWrapper<>(); // 禁止!
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### 6. 使用正确的对象转换工具
|
|
153
|
+
|
|
154
|
+
```java
|
|
155
|
+
// ✅ 正确:使用 BeanUtil
|
|
156
|
+
import cn.hutool.core.bean.BeanUtil;
|
|
157
|
+
|
|
158
|
+
XxxVo vo = BeanUtil.copyProperties(entity, XxxVo.class);
|
|
159
|
+
List<XxxVo> voList = BeanUtil.copyToList(entities, XxxVo.class);
|
|
160
|
+
|
|
161
|
+
// ❌ 错误:使用 MapstructUtils(RuoYi 的工具类)
|
|
162
|
+
import org.dromara.common.core.utils.MapstructUtils;
|
|
163
|
+
|
|
164
|
+
XxxVo vo = MapstructUtils.convert(entity, XxxVo.class);
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### 7. 使用正确的审计字段命名
|
|
168
|
+
|
|
169
|
+
```java
|
|
170
|
+
// ✅ 正确:leniu 审计字段
|
|
171
|
+
@Data
|
|
172
|
+
public class XxxEntity {
|
|
173
|
+
private String crby; // 创建人
|
|
174
|
+
private LocalDateTime crtime; // 创建时间
|
|
175
|
+
private String upby; // 更新人
|
|
176
|
+
private LocalDateTime uptime; // 更新时间
|
|
177
|
+
private Integer delFlag; // 删除标识(1=删除,2=正常)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// ❌ 错误:RuoYi 审计字段
|
|
181
|
+
@Data
|
|
182
|
+
public class XxxEntity {
|
|
183
|
+
private String createBy; // ❌
|
|
184
|
+
private LocalDateTime createTime; // ❌
|
|
185
|
+
private String updateBy; // ❌
|
|
186
|
+
private LocalDateTime updateTime; // ❌
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### 8. 使用正确的逻辑删除值
|
|
191
|
+
|
|
192
|
+
```java
|
|
193
|
+
// ✅ 正确:leniu 使用 2 表示正常
|
|
194
|
+
wrapper.eq(XxxEntity::getDelFlag, 2);
|
|
195
|
+
|
|
196
|
+
// ❌ 错误:RuoYi 使用 0 表示正常
|
|
197
|
+
wrapper.eq(XxxEntity::getDelFlag, 0);
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### 9. 使用正确的异常类
|
|
201
|
+
|
|
202
|
+
```java
|
|
203
|
+
// ✅ 正确:使用 leniu 的异常
|
|
204
|
+
import net.xnzn.core.common.exception.LeException;
|
|
205
|
+
|
|
206
|
+
throw new LeException("订单不存在");
|
|
207
|
+
throw new LeException(I18n.getMessage("order.not.exists"));
|
|
208
|
+
|
|
209
|
+
// ❌ 错误:使用 RuoYi 的异常
|
|
210
|
+
import org.dromara.common.core.exception.ServiceException;
|
|
211
|
+
|
|
212
|
+
throw new ServiceException("订单不存在");
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### 10. 使用正确的国际化工具
|
|
216
|
+
|
|
217
|
+
```java
|
|
218
|
+
// ✅ 正确:使用 leniu 的国际化
|
|
219
|
+
import net.xnzn.core.common.i18n.I18n;
|
|
220
|
+
|
|
221
|
+
throw new LeException(I18n.getMessage("order.not.exists"));
|
|
222
|
+
throw new LeException(I18n.getMessage("user.password.retry.limit.exceed", maxRetryCount));
|
|
223
|
+
|
|
224
|
+
// ❌ 错误:使用 RuoYi 的国际化
|
|
225
|
+
import org.dromara.common.core.utils.MessageUtils;
|
|
226
|
+
|
|
227
|
+
throw new ServiceException(MessageUtils.message("order.not.exists"));
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## 命名规范速查
|
|
231
|
+
|
|
232
|
+
### 后端命名
|
|
233
|
+
|
|
234
|
+
| 类型 | 规范 | 示例 |
|
|
235
|
+
|------|------|------|
|
|
236
|
+
| 包名 | 小写,点分隔 | `net.xnzn.core.order` |
|
|
237
|
+
| 类名 | 大驼峰 | `OrderServiceImpl` |
|
|
238
|
+
| 方法名 | 小驼峰 | `pageList`, `getById` |
|
|
239
|
+
| 变量名 | 小驼峰 | `userName`, `crtime` |
|
|
240
|
+
| 常量 | 全大写下划线 | `MAX_PAGE_SIZE` |
|
|
241
|
+
| 表名 | 小写下划线 | `order_table` |
|
|
242
|
+
| 字段名 | 小写下划线 | `order_amount`, `crby` |
|
|
243
|
+
|
|
244
|
+
### 类命名后缀
|
|
245
|
+
|
|
246
|
+
| 类型 | 后缀 | 示例 |
|
|
247
|
+
|------|------|------|
|
|
248
|
+
| 实体类 | 无/Entity | `Order`, `OrderEntity` |
|
|
249
|
+
| VO | XxxVO | `OrderVO` |
|
|
250
|
+
| DTO | XxxDTO | `OrderDTO` |
|
|
251
|
+
| Param | XxxParam/XxxQueryParam | `OrderQueryParam` |
|
|
252
|
+
| Service 接口 | XxxService | `OrderService` |
|
|
253
|
+
| Service 实现 | XxxServiceImpl | `OrderServiceImpl` |
|
|
254
|
+
| Controller | XxxController | `OrderController` |
|
|
255
|
+
| Mapper | XxxMapper | `OrderMapper` |
|
|
256
|
+
| Enum | XxxEnum | `OrderStatusEnum` |
|
|
257
|
+
| Handler | XxxHandler | `OrderHandler` |
|
|
258
|
+
|
|
259
|
+
### 方法命名
|
|
260
|
+
|
|
261
|
+
| 操作 | Service 方法 | Mapper 方法 |
|
|
262
|
+
|------|-------------|-------------|
|
|
263
|
+
| 分页查询 | `pageXxx` | `pageXxx` |
|
|
264
|
+
| 查询列表 | `listXxx` | `listXxx` |
|
|
265
|
+
| 查询单个 | `getXxx` | `selectById` |
|
|
266
|
+
| 新增 | `save` / `add` / `create` | `insert` |
|
|
267
|
+
| 更新 | `update` / `modify` | `updateById` |
|
|
268
|
+
| 删除 | `delete` / `remove` | `deleteById` |
|
|
269
|
+
|
|
270
|
+
## 避免过度工程
|
|
271
|
+
|
|
272
|
+
### 不要做的事
|
|
273
|
+
|
|
274
|
+
1. **不要创建不必要的抽象**
|
|
275
|
+
- 只有一处使用的代码不需要抽取
|
|
276
|
+
- 三处以上相同代码才考虑抽取
|
|
277
|
+
|
|
278
|
+
2. **不要添加不需要的功能**
|
|
279
|
+
- 只实现当前需求
|
|
280
|
+
- 不要"以防万一"添加功能
|
|
281
|
+
|
|
282
|
+
3. **不要过早优化**
|
|
283
|
+
- 优先使用简单直接的方案
|
|
284
|
+
- 复杂方案需要有明确理由
|
|
285
|
+
|
|
286
|
+
4. **不要添加无用注释**
|
|
287
|
+
- 不要给显而易见的代码加注释
|
|
288
|
+
- 只在逻辑复杂处添加注释
|
|
289
|
+
|
|
290
|
+
5. **不要保留废弃代码**
|
|
291
|
+
- 删除不用的代码,不要注释保留
|
|
292
|
+
- Git 有历史记录
|
|
293
|
+
|
|
294
|
+
## Git 提交规范
|
|
295
|
+
|
|
296
|
+
### 格式
|
|
297
|
+
|
|
298
|
+
```
|
|
299
|
+
<type>(<scope>): <description>
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
### 类型
|
|
303
|
+
|
|
304
|
+
| type | 说明 |
|
|
305
|
+
|------|------|
|
|
306
|
+
| `feat` | 新功能 |
|
|
307
|
+
| `fix` | 修复 Bug |
|
|
308
|
+
| `docs` | 文档更新 |
|
|
309
|
+
| `style` | 代码格式(不影响逻辑) |
|
|
310
|
+
| `refactor` | 重构(不是新功能或修复) |
|
|
311
|
+
| `perf` | 性能优化 |
|
|
312
|
+
| `test` | 测试 |
|
|
313
|
+
| `chore` | 构建/工具 |
|
|
314
|
+
|
|
315
|
+
### 示例
|
|
316
|
+
|
|
317
|
+
```bash
|
|
318
|
+
feat(order): 新增订单创建功能
|
|
319
|
+
fix(order): 修复订单状态显示错误
|
|
320
|
+
docs(readme): 更新安装说明
|
|
321
|
+
refactor(common): 重构分页查询工具类
|
|
322
|
+
perf(order): 优化订单列表查询性能
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
## Hutool 工具类速查
|
|
326
|
+
|
|
327
|
+
```java
|
|
328
|
+
import cn.hutool.core.collection.CollUtil;
|
|
329
|
+
import cn.hutool.core.util.ObjectUtil;
|
|
330
|
+
import cn.hutool.core.util.StrUtil;
|
|
331
|
+
import cn.hutool.core.bean.BeanUtil;
|
|
332
|
+
|
|
333
|
+
// 集合判空
|
|
334
|
+
if (CollUtil.isEmpty(list)) { }
|
|
335
|
+
if (CollUtil.isNotEmpty(list)) { }
|
|
336
|
+
|
|
337
|
+
// 对象判空
|
|
338
|
+
if (ObjectUtil.isNull(obj)) { }
|
|
339
|
+
if (ObjectUtil.isNotNull(obj)) { }
|
|
340
|
+
|
|
341
|
+
// 字符串判空
|
|
342
|
+
if (StrUtil.isBlank(str)) { }
|
|
343
|
+
if (StrUtil.isNotBlank(str)) { }
|
|
344
|
+
|
|
345
|
+
// 对象拷贝
|
|
346
|
+
Target target = BeanUtil.copyProperties(source, Target.class);
|
|
347
|
+
List<Target> targets = BeanUtil.copyToList(sources, Target.class);
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
## 包结构规范
|
|
351
|
+
|
|
352
|
+
```
|
|
353
|
+
net.xnzn.core
|
|
354
|
+
├── [module]/
|
|
355
|
+
│ ├── controller/ # 控制器层(按端分:web/mobile/android)
|
|
356
|
+
│ ├── business/impl/ # 业务编排层
|
|
357
|
+
│ ├── service/impl/ # 服务层
|
|
358
|
+
│ ├── mapper/ # 数据访问层(含 XML 同目录)
|
|
359
|
+
│ ├── model/ # 数据模型(Entity)
|
|
360
|
+
│ ├── vo/ # 视图对象(返回前端)
|
|
361
|
+
│ ├── dto/ # 数据传输对象(服务间/MQ)
|
|
362
|
+
│ ├── param/ # 请求参数对象
|
|
363
|
+
│ ├── constants/ # 常量和枚举
|
|
364
|
+
│ ├── config/ # 配置类
|
|
365
|
+
│ ├── mq/ # 消息队列监听器
|
|
366
|
+
│ ├── task/ # 定时任务
|
|
367
|
+
│ ├── handle/ # 业务处理器(策略模式)
|
|
368
|
+
│ └── util/ # 工具类
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
## 依赖注入规范
|
|
372
|
+
|
|
373
|
+
```java
|
|
374
|
+
// 推荐:字段注入
|
|
375
|
+
@Autowired
|
|
376
|
+
private OrderService orderService;
|
|
377
|
+
|
|
378
|
+
// 解决循环依赖
|
|
379
|
+
@Resource
|
|
380
|
+
@Lazy
|
|
381
|
+
private ProductService productService;
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
## 类注释规范
|
|
385
|
+
|
|
386
|
+
```java
|
|
387
|
+
/**
|
|
388
|
+
* 类功能描述
|
|
389
|
+
*
|
|
390
|
+
* @author xujiajun
|
|
391
|
+
* @date 2026-02-20
|
|
392
|
+
*/
|
|
393
|
+
public class OrderService {
|
|
394
|
+
}
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
## 通用代码规范
|
|
398
|
+
|
|
399
|
+
无论使用哪种项目架构,以下规范都是通用的:
|
|
400
|
+
|
|
401
|
+
1. **禁止使用 `SELECT *`**:明确指定字段
|
|
402
|
+
2. **使用参数化查询**:`#{}` 而非 `${}`
|
|
403
|
+
3. **异常必须处理**:不能吞掉异常
|
|
404
|
+
4. **日志使用占位符**:`log.info("msg: {}", value)`
|
|
405
|
+
5. **敏感信息脱敏**:不记录密码、身份证等
|
|
406
|
+
6. **集合判空**:使用 `CollUtil.isEmpty()` 或类似方法
|
|
407
|
+
7. **空指针防护**:使用 `ObjectUtil.isNull()`
|
|
408
|
+
|
|
409
|
+
## 参考文档
|
|
410
|
+
|
|
411
|
+
详见:[leniu-tengyun-core 源码](/Users/xujiajun/Developer/gongsi_proj/core/leniu-tengyun-core)
|