Nav apraksta
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

inventory_snapshot.go 1.6KB

123456789101112131415161718192021222324252627282930313233343536
  1. package tables
  2. import (
  3. "time"
  4. "git.x2erp.com/qdy/go-db/sqldef"
  5. )
  6. func init() {
  7. sqldef.AddRegistration(func(r *sqldef.Registry) {
  8. tb := sqldef.NewTable("inventory_snapshot", "库存快照表").
  9. ID("snapshot_id", 32).Comment("快照ID,主键").End().
  10. String("sku_id", 32).NotNull().Comment("商品SKU").End().
  11. String("channel_id", 32).NotNull().Comment("所在渠道").End().
  12. String("tenant_id", 8).NotNull().Comment("租户ID").End().
  13. Int("quantity").NotNull().Default("0").Comment("可用库存数量").End().
  14. DateTime("snapshot_time").NotNull().Comment("快照时间点").End().
  15. DateTime("extracted_at").NotNull().Default("CURRENT_TIMESTAMP").Comment("数据抽取时间").End()
  16. r.RegisterTable(tb.Build())
  17. })
  18. }
  19. // InventorySnapshot 库存快照表结构体
  20. type InventorySnapshot struct {
  21. SnapshotID string `gorm:"column:snapshot_id;type:varchar(32);primaryKey;not null;comment:快照ID,主键"`
  22. SkuID string `gorm:"column:sku_id;type:varchar(32);not null;comment:商品SKU;index:idx_sku_channel"`
  23. ChannelID string `gorm:"column:channel_id;type:varchar(32);not null;comment:所在渠道;index:idx_sku_channel"`
  24. Quantity int `gorm:"column:quantity;not null;default:0;comment:可用库存数量"`
  25. SnapshotTime time.Time `gorm:"column:snapshot_time;not null;comment:快照时间点"`
  26. ExtractedAt time.Time `gorm:"column:extracted_at;not null;default:CURRENT_TIMESTAMP;comment:数据抽取时间"`
  27. TenantId string `gorm:"column:tenant_id;type:varchar(8);comment:租户ID"`
  28. }
  29. func (InventorySnapshot) TableName() string {
  30. return "inventory_snapshot"
  31. }