--- name: "add-database-field" description: "Standardized field addition tool for ERPTurbo project. Automatically adds fields to DO, VO, Cmd, and Domain Entity classes with proper type mapping, annotations, and generates DDL migration script. Supports snake_case to camelCase conversion, BigDecimal for decimal types, and proper Java imports." --- # Add Database Field Add fields to ERPTurbo project entities following the standard DDD layered architecture. ## ⚠️ 重要规则 **仅操作 `erp-turbo-business` 模块,禁止修改 `erp-turbo-svc` 模块!** 详见:`.claude/PROJECT_RULES.md` ## Workflow ## Input Format Provide field information in this format: ```markdown Field: field_name | java_type | default_value | comment ``` **Example:** ``` Field: receivable_amount | BigDecimal | 0.00 | 应收金额(元) Field: adjusted_amount | BigDecimal | 0.00 | 调整总额(元) ``` ## Supported Java Types | Database Type | Java Type | Import | |---------------|-----------|--------| | DECIMAL(p,s) | BigDecimal | `java.math.BigDecimal` | | INT / BIGINT | Long | (primitive) | | VARCHAR | String | (primitive) | | DATETIME | LocalDateTime | `java.time.LocalDateTime` | | DATE | LocalDate | `java.time.LocalDate` | | BOOLEAN / TINYINT | Boolean | (primitive) | | DOUBLE / FLOAT | Double | (primitive) | ## Workflow 1. **Locate Entity File**: Find `*DO.java` in `erp-turbo-business/erp-turbo-biz/.../infrastructure/entity/` (**跳过 erp-turbo-svc**) 2. **Find Related Files**: Locate corresponding VO, Cmd, common DTO, and domain Entity files(**仅在 erp-turbo-business 模块**) 3. **Add Import**: Add `java.math.BigDecimal` if needed 4. **Add Field**: Insert after `remark` field with proper annotations: - DO: `@TableField(value = "snake_case_name")` - VO: `@Schema(title = "comment")` - Cmd: `@Schema(title = "comment")` - Domain Entity: No annotations 5. **Generate DDL**: Output migration script ## Output Example ``` ✅ 已完成字段添加 ======================================== 文件变更: ✅ biz/.../entity/OrderShipDO.java ✅ api/.../vo/OrderShipVO.java ✅ api/.../cmd/OrderShipCreateCmd.java ✅ api/.../cmd/OrderShipUpdateCmd.java ✅ api/.../common/OrderShip.java ✅ biz/.../domain/entity/OrderShip.java ⚠️ 请执行数据库迁移: ALTER TABLE order_ship ADD COLUMN receivable_amount DECIMAL(16, 2) DEFAULT 0.00 NULL COMMENT '应收金额(元)', ADD COLUMN adjusted_amount DECIMAL(16, 2) DEFAULT 0.00 NULL COMMENT '调整总额(元)'; ``` ## Naming Convention - **Database**: snake_case (e.g., `receivable_amount`) - **Java**: camelCase (e.g., `receivableAmount`) - **Comment**: Chinese description with unit if applicable