package tables import ( "time" "git.x2erp.com/qdy/go-db/sqldef" ) func init() { sqldef.AddRegistration(func(r *sqldef.Registry) { tb := sqldef.NewTable("dws_discount_analysis", "折扣深度分析表"). ID("analysis_id", 32).Comment("分析ID,主键").End(). Int("product_year").NotNull().Comment("年份").End(). String("product_season", 10).NotNull().Comment("产品季节(春/夏/秋/冬)").End(). Int("week_of_year").NotNull().Comment("年第几周(1-52)").End(). String("store_id", 32).NotNull().Comment("店铺ID").End(). String("category_id", 32).NotNull().Comment("品类ID").End(). String("inventory_age_range", 20).NotNull().Comment("库龄段(<30天,30-60天,60-90天,>90天)").End(). String("discount_range", 10).NotNull().Comment("折扣档位(全价,9折,8折,7折,6折,5折)").End(). // 生命周期相关字段 String("lifecycle_stage", 10).NotNull().Comment("生命周期阶段(导入期,成长期,成熟期,衰退期)").End(). String("season_status", 10).NotNull().Comment("季节状态(当季,临季,过季)").End(). Int("days_on_market").NotNull().Comment("上市天数").End(). String("is_cross_season", 1).Default("'0'").Comment("是否跨季款(0:否,1:是)").End(). // 核心指标 Int("sale_quantity").NotNull().Default("0").Comment("总销量").End(). Int("begin_inventory").NotNull().Default("0").Comment("期初库存").End(). Int("end_inventory").NotNull().Default("0").Comment("期末库存").End(). Int("production_quantity").NotNull().Default("0").Comment("在产量").End(). Int("consumption_rate").NotNull().Default("0").Comment("消耗率(单位:%)").End(). Int("production_sales_ratio").NotNull().Default("0").Comment("产销率(单位:%)").End(). // 时间字段 Date("stat_date").NotNull().Comment("统计日期").End(). DateTime("created_at").NotNull().Default("CURRENT_TIMESTAMP").Comment("创建时间").End() // 索引 - 支持多种分析维度 //tb.Index("idx_season_week", "product_season", "week_of_year", "category_id").End(). // Index("idx_age_discount", "inventory_age_range", "discount_range").End(). // Index("idx_lifecycle", "lifecycle_stage", "season_status").End(). // Index("idx_date_store_cat", "stat_date", "store_id", "category_id").End() r.RegisterTable(tb.Build()) }) } type DwsDiscountAnalysis struct { AnalysisID string `gorm:"column:analysis_id;type:varchar(32);primaryKey;not null;comment:分析ID,主键"` ProductYear int `gorm:"column:product_year;type:int(4);not null;comment:年份"` ProductSeason string `gorm:"column:product_season;type:varchar(10);not null;comment:产品季节"` WeekOfYear int `gorm:"column:week_of_year;type:int(2);not null;comment:年第几周"` StoreID string `gorm:"column:store_id;type:varchar(32);not null;comment:店铺ID"` CategoryID string `gorm:"column:category_id;type:varchar(32);not null;comment:品类ID"` InventoryAgeRange string `gorm:"column:inventory_age_range;type:varchar(20);not null;comment:库龄段"` DiscountRange string `gorm:"column:discount_range;type:varchar(10);not null;comment:折扣档位"` // 生命周期相关字段 LifecycleStage string `gorm:"column:lifecycle_stage;type:varchar(10);not null;comment:生命周期阶段"` SeasonStatus string `gorm:"column:season_status;type:varchar(10);not null;comment:季节状态"` DaysOnMarket int `gorm:"column:days_on_market;type:int(4);not null;comment:上市天数"` IsCrossSeason string `gorm:"column:is_cross_season;type:varchar(1);default:0;comment:是否跨季款"` // 核心指标 SaleQuantity int `gorm:"column:sale_quantity;type:int(11);not null;default:0;comment:总销量"` BeginInventory int `gorm:"column:begin_inventory;type:int(11);not null;default:0;comment:期初库存"` EndInventory int `gorm:"column:end_inventory;type:int(11);not null;default:0;comment:期末库存"` ProductionQuantity int `gorm:"column:production_quantity;type:int(11);not null;default:0;comment:在产量"` ConsumptionRate int `gorm:"column:consumption_rate;type:int(3);not null;default:0;comment:消耗率"` ProductionSalesRatio int `gorm:"column:production_sales_ratio;type:int(3);not null;default:0;comment:产销率"` // 时间字段 StatDate time.Time `gorm:"column:stat_date;type:date;not null;comment:统计日期"` CreatedAt time.Time `gorm:"column:created_at;not null;default:CURRENT_TIMESTAMP;comment:创建时间"` TenantId string `gorm:"column:tenant_id;type:varchar(8);comment:租户ID"` } func (DwsDiscountAnalysis) TableName() string { return "dws_discount_analysis" }