| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- 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", "店铺库存快照表").
- ID("id", 50).NotNull().Comment("主键ID").End().
- String("inventory_sn", 100).NotNull().Comment("库存流水号 (日期+店铺+商品,用于唯一标识)").End().
- String("shop_id", 50).NotNull().Comment("店铺ID").End().
- String("shop_code", 50).NotNull().Comment("店铺编码").End().
- String("shop_name", 200).NotNull().Comment("店铺名称").End().
- String("product_id", 50).NotNull().Comment("商品ID").End().
- String("product_code", 50).NotNull().Comment("商品编码").End().
- String("product_name", 200).NotNull().Comment("商品名称").End().
- Int("on_hand_qty").NotNull().Default("0").Comment("现货数量 (店铺实际库存)").End().
- Int("in_transit_qty").NotNull().Default("0").Comment("在途数量 (已发货未到店)").End().
- Int("committed_qty").NotNull().Default("0").Comment("已承诺数量 (已销售未出库)").End().
- Int("available_qty").NotNull().Default("0").Comment("可用库存 (on_hand_qty - committed_qty)").End().
- Int("reserved_qty").NotNull().Default("0").Comment("预留数量 (用于调拨、补货预留)").End().
- Decimal("unit_cost", 10, 2).Comment("单位成本 (最近采购成本)").End().
- Decimal("inventory_value", 12, 2).Comment("库存金额 (on_hand_qty * unit_cost)").End().
- Date("last_receipt_date").Comment("最近收货日期").End().
- Date("last_sales_date").Comment("最近销售日期").End().
- Decimal("days_supply", 10, 2).Comment("可销天数 (available_qty / 日均销量)").End().
- Decimal("stock_cover", 10, 2).Comment("库存覆盖率 (现有库存能满足未来多少天的销售)").End().
- Decimal("inventory_turnover", 10, 4).Comment("库存周转率").End().
- Decimal("sell_through_rate", 5, 4).Comment("售罄率 (已售数量/总进货数量)").End().
- Int("safety_stock").Comment("安全库存 (该店铺该商品的安全库存水平)").End().
- Int("reorder_point").Comment("补货点 (触发补货的库存水平)").End().
- Int("reorder_qty").Comment("建议补货量").End().
- Date("last_replenish_date").Comment("最近补货日期").End().
- String("season_code", 10).Comment("季节代码 (SS/FW)").End().
- Int("year").Comment("年份").End().
- Int("inventory_age").Comment("库龄 (天)").End().
- Bool("is_new_arrival").Comment("是否新品 (上市30天内)").End().
- String("inventory_status", 20).Comment("库存状态 (NORMAL正常/OVERSTOCK积压/SHORTAGE缺货/SLOW_MOVING滞销)").End().
- Date("data_date").NotNull().Comment("数据日期 (库存快照日期)").End().
- DateTime("snapshot_time").NotNull().Comment("快照时间 (具体时间点)").End().
- DateTime("created_at").NotNull().Default("CURRENT_TIMESTAMP").Comment("创建时间").End()
-
- tb.AddUniqueIndex("idx_inventory_sn", "inventory_sn")
- tb.AddIndex("idx_shop_id", "shop_id")
- tb.AddIndex("idx_product_id", "product_id")
- tb.AddIndex("idx_data_date", "data_date")
- tb.AddIndex("idx_inventory_status", "inventory_status")
- tb.AddIndex("idx_shop_product_date", "shop_id", "product_id", "data_date")
- tb.AddIndex("idx_product_status_date", "product_id", "inventory_status", "data_date")
- tb.AddIndex("idx_shop_season_status", "shop_id", "season_code", "inventory_status")
-
- r.RegisterTable(tb.Build())
- })
- }
-
- type StockStoreSnapshot struct {
- ID string `gorm:"column:id;type:varchar(50);not null;primaryKey;comment:主键ID"`
- InventorySN string `gorm:"column:inventory_sn;type:varchar(100);not null;comment:库存流水号 (日期+店铺+商品,用于唯一标识)"`
- ShopID string `gorm:"column:shop_id;type:varchar(50);not null;comment:店铺ID"`
- ShopCode string `gorm:"column:shop_code;type:varchar(50);not null;comment:店铺编码"`
- ShopName string `gorm:"column:shop_name;type:varchar(200);not null;comment:店铺名称"`
- ProductID string `gorm:"column:product_id;type:varchar(50);not null;comment:商品ID"`
- ProductCode string `gorm:"column:product_code;type:varchar(50);not null;comment:商品编码"`
- ProductName string `gorm:"column:product_name;type:varchar(200);not null;comment:商品名称"`
- OnHandQty int32 `gorm:"column:on_hand_qty;type:int;not null;default:0;comment:现货数量 (店铺实际库存)"`
- InTransitQty int32 `gorm:"column:in_transit_qty;type:int;not null;default:0;comment:在途数量 (已发货未到店)"`
- CommittedQty int32 `gorm:"column:committed_qty;type:int;not null;default:0;comment:已承诺数量 (已销售未出库)"`
- AvailableQty int32 `gorm:"column:available_qty;type:int;not null;default:0;comment:可用库存 (on_hand_qty - committed_qty)"`
- ReservedQty int32 `gorm:"column:reserved_qty;type:int;not null;default:0;comment:预留数量 (用于调拨、补货预留)"`
- UnitCost float64 `gorm:"column:unit_cost;type:decimal(10,2);comment:单位成本 (最近采购成本)"`
- InventoryValue float64 `gorm:"column:inventory_value;type:decimal(12,2);comment:库存金额 (on_hand_qty * unit_cost)"`
- LastReceiptDate *time.Time `gorm:"column:last_receipt_date;type:date;comment:最近收货日期"`
- LastSalesDate *time.Time `gorm:"column:last_sales_date;type:date;comment:最近销售日期"`
- DaysSupply float64 `gorm:"column:days_supply;type:decimal(10,2);comment:可销天数 (available_qty / 日均销量)"`
- StockCover float64 `gorm:"column:stock_cover;type:decimal(10,2);comment:库存覆盖率 (现有库存能满足未来多少天的销售)"`
- InventoryTurnover float64 `gorm:"column:inventory_turnover;type:decimal(10,4);comment:库存周转率"`
- SellThroughRate float64 `gorm:"column:sell_through_rate;type:decimal(5,4);comment:售罄率 (已售数量/总进货数量)"`
- SafetyStock int32 `gorm:"column:safety_stock;type:int;comment:安全库存 (该店铺该商品的安全库存水平)"`
- ReorderPoint int32 `gorm:"column:reorder_point;type:int;comment:补货点 (触发补货的库存水平)"`
- ReorderQty int32 `gorm:"column:reorder_qty;type:int;comment:建议补货量"`
- LastReplenishDate *time.Time `gorm:"column:last_replenish_date;type:date;comment:最近补货日期"`
- SeasonCode string `gorm:"column:season_code;type:varchar(10);comment:季节代码 (SS/FW)"`
- Year int32 `gorm:"column:year;type:int;comment:年份"`
- InventoryAge int32 `gorm:"column:inventory_age;type:int;comment:库龄 (天)"`
- IsNewArrival bool `gorm:"column:is_new_arrival;type:bool;comment:是否新品 (上市30天内)"`
- InventoryStatus string `gorm:"column:inventory_status;type:varchar(20);comment:库存状态 (NORMAL正常/OVERSTOCK积压/SHORTAGE缺货/SLOW_MOVING滞销)"`
- DataDate time.Time `gorm:"column:data_date;type:date;not null;comment:数据日期 (库存快照日期)"`
- SnapshotTime time.Time `gorm:"column:snapshot_time;type:datetime;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"`
- InventorySN string `db:"inventory_sn" json:"inventorySN"`
- ShopID string `db:"shop_id" json:"shopID"`
- ShopCode string `db:"shop_code" json:"shopCode"`
- ShopName string `db:"shop_name" json:"shopName"`
- ProductID string `db:"product_id" json:"productID"`
- ProductCode string `db:"product_code" json:"productCode"`
- ProductName string `db:"product_name" json:"productName"`
- OnHandQty int32 `db:"on_hand_qty" json:"onHandQty"`
- InTransitQty int32 `db:"in_transit_qty" json:"inTransitQty"`
- CommittedQty int32 `db:"committed_qty" json:"committedQty"`
- AvailableQty int32 `db:"available_qty" json:"availableQty"`
- ReservedQty int32 `db:"reserved_qty" json:"reservedQty"`
- UnitCost float64 `db:"unit_cost" json:"unitCost"`
- InventoryValue float64 `db:"inventory_value" json:"inventoryValue"`
- LastReceiptDate *time.Time `db:"last_receipt_date" json:"lastReceiptDate"`
- LastSalesDate *time.Time `db:"last_sales_date" json:"lastSalesDate"`
- DaysSupply float64 `db:"days_supply" json:"daysSupply"`
- StockCover float64 `db:"stock_cover" json:"stockCover"`
- InventoryTurnover float64 `db:"inventory_turnover" json:"inventoryTurnover"`
- SellThroughRate float64 `db:"sell_through_rate" json:"sellThroughRate"`
- SafetyStock int32 `db:"safety_stock" json:"safetyStock"`
- ReorderPoint int32 `db:"reorder_point" json:"reorderPoint"`
- ReorderQty int32 `db:"reorder_qty" json:"reorderQty"`
- LastReplenishDate *time.Time `db:"last_replenish_date" json:"lastReplenishDate"`
- SeasonCode string `db:"season_code" json:"seasonCode"`
- Year int32 `db:"year" json:"year"`
- InventoryAge int32 `db:"inventory_age" json:"inventoryAge"`
- IsNewArrival bool `db:"is_new_arrival" json:"isNewArrival"`
- InventoryStatus string `db:"inventory_status" json:"inventoryStatus"`
- DataDate time.Time `db:"data_date" json:"dataDate"`
- SnapshotTime time.Time `db:"snapshot_time" json:"snapshotTime"`
- CreatedAt time.Time `db:"created_at" json:"createdAt"`
- }
-
- func (StockStoreSnapshot) TableName() string {
- return "stock_store_snapshot"
- }
|