重构:完善 IoT 模型架构规范和数据库设计

- 完善 GORM 模型规范:货币字段使用 int64(分为单位)、JSONB 字段规范、模型结构规范
- 修复所有 IoT 模型的架构违规问题
- 更新 CLAUDE.md 开发指南,补充完整的数据库设计规范和模型示例
- 添加数据库迁移脚本(000006)用于架构重构
- 归档 OpenSpec 变更文档(2026-01-12-fix-iot-models-violations)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-12 17:43:12 +08:00
parent 4507de577b
commit 2150fb6ab9
21 changed files with 2774 additions and 263 deletions

View File

@@ -1,25 +1,26 @@
package model
import "time"
import (
"gorm.io/gorm"
)
// NumberCard 号卡模型
// 完全独立的业务线,从上游平台下单
// 使用虚拟商品编码映射运营商订单
type NumberCard struct {
ID uint `gorm:"column:id;primaryKey;comment:号卡ID" json:"id"`
VirtualProductCode string `gorm:"column:virtual_product_code;type:varchar(100);uniqueIndex;not null;comment:虚拟商品编码(用于对应运营商订单)" json:"virtual_product_code"`
CardName string `gorm:"column:card_name;type:varchar(255);not null;comment:号卡名称" json:"card_name"`
CardType string `gorm:"column:card_type;type:varchar(50);comment:号卡类型" json:"card_type"`
Carrier string `gorm:"column:carrier;type:varchar(50);comment:运营商" json:"carrier"`
DataAmountMB int64 `gorm:"column:data_amount_mb;type:bigint;comment:流量额度(MB)" json:"data_amount_mb"`
Price float64 `gorm:"column:price;type:decimal(10,2);comment:价格(元)" json:"price"`
AgentID uint `gorm:"column:agent_id;type:bigint;comment:代理用户ID" json:"agent_id"`
Status int `gorm:"column:status;type:int;default:1;not null;comment:状态 1-在售 2-下架" json:"status"`
CreatedAt time.Time `gorm:"column:created_at;autoCreateTime;comment:创建时间" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at;autoUpdateTime;comment:更新时间" json:"updated_at"`
gorm.Model
BaseModel `gorm:"embedded"`
VirtualProductCode string `gorm:"column:virtual_product_code;type:varchar(100);uniqueIndex:idx_number_card_code,where:deleted_at IS NULL;not null;comment:虚拟商品编码(用于对应运营商订单)" json:"virtual_product_code"`
CardName string `gorm:"column:card_name;type:varchar(255);not null;comment:号卡名称" json:"card_name"`
CardType string `gorm:"column:card_type;type:varchar(50);comment:号卡类型" json:"card_type"`
Carrier string `gorm:"column:carrier;type:varchar(50);comment:运营商" json:"carrier"`
DataAmountMB int64 `gorm:"column:data_amount_mb;type:bigint;comment:流量额度(MB)" json:"data_amount_mb"`
Price int64 `gorm:"column:price;type:bigint;comment:价格(分为单位)" json:"price"`
AgentID uint `gorm:"column:agent_id;index;comment:代理用户ID" json:"agent_id"`
Status int `gorm:"column:status;type:int;default:1;not null;comment:状态 1-在售 2-下架" json:"status"`
}
// TableName 指定表名
func (NumberCard) TableName() string {
return "number_cards"
return "tb_number_card"
}