diff --git a/CLAUDE.md b/CLAUDE.md index d14e7d7..acabfcc 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -113,6 +113,24 @@ Handler → Service → Store → Model - 禁止硬编码字符串和 magic numbers - **必须为所有常量添加中文注释** +### 枚举与状态字段(必须遵守) + +**两个强制规则**: + +1. **int vs string**:状态类(生命周期)用 `int`,类型/方式类用 `string` +2. **DTO description 必须从 constants 原文抄写**,禁止凭记忆填写枚举值(历史上已有 description 与 constants 不一致导致前端显示错误的案例) + +```go +// ✅ description 从 constants 原文抄,格式统一用冒号+逗号 +Status int `json:"status" description:"状态 (1:待支付, 2:已支付, 3:已完成, 4:已关闭, 5:已退款)"` +StatusName string `json:"status_name" description:"状态名称(中文)"` // Response DTO 必须加 + +// ❌ 禁止:启用/禁用用 1=启用 2=禁用(全局约定是 0=禁用, 1=启用) +// ❌ 禁止:description 枚举值与 constants 不一致 +``` + +**完整规范**: 参见 [`docs/enum-status-standards.md`](docs/enum-status-standards.md) + ### 注释规范 - **所有注释使用中文**,导出符号必须有文档注释(包、函数、类型、接口、常量) @@ -220,6 +238,13 @@ Handler → Service → Store → Model - [ ] 常量定义在 `pkg/constants/` - [ ] 使用 Go 惯用法(非 Java 风格) +### 枚举与状态 + +- [ ] 状态类字段用 `int`,类型/方式类字段用 `string` +- [ ] 禁用/启用使用 `0=禁用, 1=启用`(禁止 `1=启用, 2=禁用`) +- [ ] DTO description 枚举列表已从 `pkg/constants/` 原文抄写,无遗漏、无错误 +- [ ] Response DTO 的 int 状态字段有对应的 `_name` 文字字段 + ### 文档和注释 - [ ] 所有注释使用中文