package tables import ( "time" "git.x2erp.com/qdy/go-db/sqldef" ) func init() { sqldef.AddRegistration(func(r *sqldef.Registry) { tb := sqldef.NewTable("stock_store_snapshot", "日店铺库存快照表 - 用于保存每天晚上所有店铺的商品库存"). ChineseName("日店铺库存快照表").Aliases("日店铺库存快照"). ID("id", 50).NotNull().Comment("主键ID").ChineseName("主键ID").End(). String("store_id", 50).NotNull().Comment("店铺ID").ChineseName("店铺ID").End(). String("product_id", 50).NotNull().Comment("商品ID").ChineseName("商品ID").End(). String("style_code", 30).NotNull().Comment("款式编码").ChineseName("款式编码").Aliases("编码").End(). String("color_code", 20).NotNull().Comment("颜色代码").ChineseName("颜色代码").End(). String("color_name", 50).NotNull().Comment("颜色名称").ChineseName("颜色名称").Aliases("名称").End(). String("size_code", 10).NotNull().Comment("尺码代码").ChineseName("尺码代码").End(). String("size_name", 20).NotNull().Comment("尺码名称").ChineseName("尺码名称").Aliases("名称").End(). Decimal("stock_actual", 12, 4).NotNull().Default("0").Comment("目前库存").ChineseName("目前库存").End(). Date("data_date").NotNull().Comment("快照日期").ChineseName("快照日期").End(). DateTime("created_at").NotNull().Default("CURRENT_TIMESTAMP").Comment("创建时间").ChineseName("创建时间").Aliases("时间").End() tb.AddUniqueIndex("idx_store_product", "store_id", "product_id") tb.AddIndex("idx_style_code", "style_code") tb.AddIndex("idx_store_id", "store_id") tb.AddIndex("idx_product_id", "product_id") tb.AddIndex("idx_data_date", "data_date") tb.AddIndex("idx_store_product_date", "store_id", "product_id", "data_date") r.RegisterTable(tb.Build()) }) } type StockStoreSnapshot struct { ID string `gorm:"column:id;type:varchar(50);not null;primaryKey;comment:主键ID"` StoreID string `gorm:"column:store_id;type:varchar(50);not null;comment:店铺ID"` ProductID string `gorm:"column:product_id;type:varchar(50);not null;comment:商品ID"` StyleCode string `gorm:"column:style_code;type:varchar(30);not null;comment:款式编码"` ColorCode string `gorm:"column:color_code;type:varchar(20);not null;comment:颜色代码"` ColorName string `gorm:"column:color_name;type:varchar(50);not null;comment:颜色名称"` SizeCode string `gorm:"column:size_code;type:varchar(10);not null;comment:尺码代码"` SizeName string `gorm:"column:size_name;type:varchar(20);not null;comment:尺码名称"` StockActual float64 `gorm:"column:stock_actual;type:decimal(12,4);not null;default:0;comment:目前库存"` DataDate time.Time `gorm:"column:data_date;type:date;not null;comment:快照日期"` CreatedAt time.Time `gorm:"column:created_at;not null;default:CURRENT_TIMESTAMP;comment:创建时间"` } type StockStoreSnapshotDB struct { ID string `db:"id" json:"id"` StoreID string `db:"store_id" json:"storeID"` ProductID string `db:"product_id" json:"productID"` StyleCode string `db:"style_code" json:"styleCode"` ColorCode string `db:"color_code" json:"colorCode"` ColorName string `db:"color_name" json:"colorName"` SizeCode string `db:"size_code" json:"sizeCode"` SizeName string `db:"size_name" json:"sizeName"` StockActual float64 `db:"stock_actual" json:"stockActual"` DataDate time.Time `db:"data_date" json:"dataDate"` CreatedAt time.Time `db:"created_at" json:"createdAt"` } func (StockStoreSnapshot) TableName() string { return "stock_store_snapshot" }