Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

stock_store_snapshot.go 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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("stock_store_snapshot", "店铺库存快照表").
  9. ID("id", 50).NotNull().Comment("主键ID").End().
  10. String("inventory_sn", 100).NotNull().Comment("库存流水号 (日期+店铺+商品,用于唯一标识)").End().
  11. String("shop_id", 50).NotNull().Comment("店铺ID").End().
  12. String("shop_code", 50).NotNull().Comment("店铺编码").End().
  13. String("shop_name", 200).NotNull().Comment("店铺名称").End().
  14. String("product_id", 50).NotNull().Comment("商品ID").End().
  15. String("product_code", 50).NotNull().Comment("商品编码").End().
  16. String("product_name", 200).NotNull().Comment("商品名称").End().
  17. Int("on_hand_qty").NotNull().Default("0").Comment("现货数量 (店铺实际库存)").End().
  18. Int("in_transit_qty").NotNull().Default("0").Comment("在途数量 (已发货未到店)").End().
  19. Int("committed_qty").NotNull().Default("0").Comment("已承诺数量 (已销售未出库)").End().
  20. Int("available_qty").NotNull().Default("0").Comment("可用库存 (on_hand_qty - committed_qty)").End().
  21. Int("reserved_qty").NotNull().Default("0").Comment("预留数量 (用于调拨、补货预留)").End().
  22. Decimal("unit_cost", 10, 2).Comment("单位成本 (最近采购成本)").End().
  23. Decimal("inventory_value", 12, 2).Comment("库存金额 (on_hand_qty * unit_cost)").End().
  24. Date("last_receipt_date").Comment("最近收货日期").End().
  25. Date("last_sales_date").Comment("最近销售日期").End().
  26. Decimal("days_supply", 10, 2).Comment("可销天数 (available_qty / 日均销量)").End().
  27. Decimal("stock_cover", 10, 2).Comment("库存覆盖率 (现有库存能满足未来多少天的销售)").End().
  28. Decimal("inventory_turnover", 10, 4).Comment("库存周转率").End().
  29. Decimal("sell_through_rate", 5, 4).Comment("售罄率 (已售数量/总进货数量)").End().
  30. Int("safety_stock").Comment("安全库存 (该店铺该商品的安全库存水平)").End().
  31. Int("reorder_point").Comment("补货点 (触发补货的库存水平)").End().
  32. Int("reorder_qty").Comment("建议补货量").End().
  33. Date("last_replenish_date").Comment("最近补货日期").End().
  34. String("season_code", 10).Comment("季节代码 (SS/FW)").End().
  35. Int("year").Comment("年份").End().
  36. Int("inventory_age").Comment("库龄 (天)").End().
  37. Bool("is_new_arrival").Comment("是否新品 (上市30天内)").End().
  38. String("inventory_status", 20).Comment("库存状态 (NORMAL正常/OVERSTOCK积压/SHORTAGE缺货/SLOW_MOVING滞销)").End().
  39. Date("data_date").NotNull().Comment("数据日期 (库存快照日期)").End().
  40. DateTime("snapshot_time").NotNull().Comment("快照时间 (具体时间点)").End().
  41. DateTime("created_at").NotNull().Default("CURRENT_TIMESTAMP").Comment("创建时间").End()
  42. tb.AddUniqueIndex("idx_inventory_sn", "inventory_sn")
  43. tb.AddIndex("idx_shop_id", "shop_id")
  44. tb.AddIndex("idx_product_id", "product_id")
  45. tb.AddIndex("idx_data_date", "data_date")
  46. tb.AddIndex("idx_inventory_status", "inventory_status")
  47. tb.AddIndex("idx_shop_product_date", "shop_id", "product_id", "data_date")
  48. tb.AddIndex("idx_product_status_date", "product_id", "inventory_status", "data_date")
  49. tb.AddIndex("idx_shop_season_status", "shop_id", "season_code", "inventory_status")
  50. r.RegisterTable(tb.Build())
  51. })
  52. }
  53. type StockStoreSnapshot struct {
  54. ID string `gorm:"column:id;type:varchar(50);not null;primaryKey;comment:主键ID"`
  55. InventorySN string `gorm:"column:inventory_sn;type:varchar(100);not null;comment:库存流水号 (日期+店铺+商品,用于唯一标识)"`
  56. ShopID string `gorm:"column:shop_id;type:varchar(50);not null;comment:店铺ID"`
  57. ShopCode string `gorm:"column:shop_code;type:varchar(50);not null;comment:店铺编码"`
  58. ShopName string `gorm:"column:shop_name;type:varchar(200);not null;comment:店铺名称"`
  59. ProductID string `gorm:"column:product_id;type:varchar(50);not null;comment:商品ID"`
  60. ProductCode string `gorm:"column:product_code;type:varchar(50);not null;comment:商品编码"`
  61. ProductName string `gorm:"column:product_name;type:varchar(200);not null;comment:商品名称"`
  62. OnHandQty int32 `gorm:"column:on_hand_qty;type:int;not null;default:0;comment:现货数量 (店铺实际库存)"`
  63. InTransitQty int32 `gorm:"column:in_transit_qty;type:int;not null;default:0;comment:在途数量 (已发货未到店)"`
  64. CommittedQty int32 `gorm:"column:committed_qty;type:int;not null;default:0;comment:已承诺数量 (已销售未出库)"`
  65. AvailableQty int32 `gorm:"column:available_qty;type:int;not null;default:0;comment:可用库存 (on_hand_qty - committed_qty)"`
  66. ReservedQty int32 `gorm:"column:reserved_qty;type:int;not null;default:0;comment:预留数量 (用于调拨、补货预留)"`
  67. UnitCost float64 `gorm:"column:unit_cost;type:decimal(10,2);comment:单位成本 (最近采购成本)"`
  68. InventoryValue float64 `gorm:"column:inventory_value;type:decimal(12,2);comment:库存金额 (on_hand_qty * unit_cost)"`
  69. LastReceiptDate *time.Time `gorm:"column:last_receipt_date;type:date;comment:最近收货日期"`
  70. LastSalesDate *time.Time `gorm:"column:last_sales_date;type:date;comment:最近销售日期"`
  71. DaysSupply float64 `gorm:"column:days_supply;type:decimal(10,2);comment:可销天数 (available_qty / 日均销量)"`
  72. StockCover float64 `gorm:"column:stock_cover;type:decimal(10,2);comment:库存覆盖率 (现有库存能满足未来多少天的销售)"`
  73. InventoryTurnover float64 `gorm:"column:inventory_turnover;type:decimal(10,4);comment:库存周转率"`
  74. SellThroughRate float64 `gorm:"column:sell_through_rate;type:decimal(5,4);comment:售罄率 (已售数量/总进货数量)"`
  75. SafetyStock int32 `gorm:"column:safety_stock;type:int;comment:安全库存 (该店铺该商品的安全库存水平)"`
  76. ReorderPoint int32 `gorm:"column:reorder_point;type:int;comment:补货点 (触发补货的库存水平)"`
  77. ReorderQty int32 `gorm:"column:reorder_qty;type:int;comment:建议补货量"`
  78. LastReplenishDate *time.Time `gorm:"column:last_replenish_date;type:date;comment:最近补货日期"`
  79. SeasonCode string `gorm:"column:season_code;type:varchar(10);comment:季节代码 (SS/FW)"`
  80. Year int32 `gorm:"column:year;type:int;comment:年份"`
  81. InventoryAge int32 `gorm:"column:inventory_age;type:int;comment:库龄 (天)"`
  82. IsNewArrival bool `gorm:"column:is_new_arrival;type:bool;comment:是否新品 (上市30天内)"`
  83. InventoryStatus string `gorm:"column:inventory_status;type:varchar(20);comment:库存状态 (NORMAL正常/OVERSTOCK积压/SHORTAGE缺货/SLOW_MOVING滞销)"`
  84. DataDate time.Time `gorm:"column:data_date;type:date;not null;comment:数据日期 (库存快照日期)"`
  85. SnapshotTime time.Time `gorm:"column:snapshot_time;type:datetime;not null;comment:快照时间 (具体时间点)"`
  86. CreatedAt time.Time `gorm:"column:created_at;not null;default:CURRENT_TIMESTAMP;comment:创建时间"`
  87. }
  88. type StockStoreSnapshotDB struct {
  89. ID string `db:"id" json:"id"`
  90. InventorySN string `db:"inventory_sn" json:"inventorySN"`
  91. ShopID string `db:"shop_id" json:"shopID"`
  92. ShopCode string `db:"shop_code" json:"shopCode"`
  93. ShopName string `db:"shop_name" json:"shopName"`
  94. ProductID string `db:"product_id" json:"productID"`
  95. ProductCode string `db:"product_code" json:"productCode"`
  96. ProductName string `db:"product_name" json:"productName"`
  97. OnHandQty int32 `db:"on_hand_qty" json:"onHandQty"`
  98. InTransitQty int32 `db:"in_transit_qty" json:"inTransitQty"`
  99. CommittedQty int32 `db:"committed_qty" json:"committedQty"`
  100. AvailableQty int32 `db:"available_qty" json:"availableQty"`
  101. ReservedQty int32 `db:"reserved_qty" json:"reservedQty"`
  102. UnitCost float64 `db:"unit_cost" json:"unitCost"`
  103. InventoryValue float64 `db:"inventory_value" json:"inventoryValue"`
  104. LastReceiptDate *time.Time `db:"last_receipt_date" json:"lastReceiptDate"`
  105. LastSalesDate *time.Time `db:"last_sales_date" json:"lastSalesDate"`
  106. DaysSupply float64 `db:"days_supply" json:"daysSupply"`
  107. StockCover float64 `db:"stock_cover" json:"stockCover"`
  108. InventoryTurnover float64 `db:"inventory_turnover" json:"inventoryTurnover"`
  109. SellThroughRate float64 `db:"sell_through_rate" json:"sellThroughRate"`
  110. SafetyStock int32 `db:"safety_stock" json:"safetyStock"`
  111. ReorderPoint int32 `db:"reorder_point" json:"reorderPoint"`
  112. ReorderQty int32 `db:"reorder_qty" json:"reorderQty"`
  113. LastReplenishDate *time.Time `db:"last_replenish_date" json:"lastReplenishDate"`
  114. SeasonCode string `db:"season_code" json:"seasonCode"`
  115. Year int32 `db:"year" json:"year"`
  116. InventoryAge int32 `db:"inventory_age" json:"inventoryAge"`
  117. IsNewArrival bool `db:"is_new_arrival" json:"isNewArrival"`
  118. InventoryStatus string `db:"inventory_status" json:"inventoryStatus"`
  119. DataDate time.Time `db:"data_date" json:"dataDate"`
  120. SnapshotTime time.Time `db:"snapshot_time" json:"snapshotTime"`
  121. CreatedAt time.Time `db:"created_at" json:"createdAt"`
  122. }
  123. func (StockStoreSnapshot) TableName() string {
  124. return "stock_store_snapshot"
  125. }