Procházet zdrojové kódy

自动建立表通过-doris

qdy před 2 měsíci
revize
a8ba855dfc

+ 1
- 0
.gitignore Zobrazit soubor

@@ -0,0 +1 @@
1
+logs/

+ 25
- 0
gct.sh Zobrazit soubor

@@ -0,0 +1,25 @@
1
+#!/bin/bash
2
+
3
+# 使用命令行参数,如果没有提供则使用默认值
4
+COMMIT_MSG="${1:-初始提交}"
5
+TAG_VERSION="${2:-v0.1.0}"
6
+
7
+echo "提交信息: $COMMIT_MSG"
8
+echo "标签版本: $TAG_VERSION"
9
+
10
+# 提交和推送
11
+git add .
12
+git commit -m "$COMMIT_MSG"
13
+git push -u origin master
14
+
15
+# 创建标签(关键修改在这里)
16
+# 方法1:使用注释标签(推荐,不会打开编辑器)
17
+git tag -a "$TAG_VERSION" -m "Release $TAG_VERSION"
18
+
19
+# 或者方法2:如果你需要GPG签名,使用这个
20
+# GIT_EDITOR=true git tag -s "$TAG_VERSION" -m "Release $TAG_VERSION"
21
+
22
+# 推送标签
23
+git push origin "$TAG_VERSION"
24
+
25
+echo "完成!"

+ 17
- 0
go.mod Zobrazit soubor

@@ -0,0 +1,17 @@
1
+module git.x2erp.com/qdy/go-svc-mercury
2
+
3
+go 1.25.4
4
+
5
+require (
6
+	git.x2erp.com/qdy/go-base v0.1.70
7
+	git.x2erp.com/qdy/go-db v0.1.70
8
+	go-micro.dev/v4 v4.11.0
9
+)
10
+
11
+require (
12
+	github.com/kr/pretty v0.3.1 // indirect
13
+	github.com/rogpeppe/go-internal v1.14.1 // indirect
14
+	gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
15
+)
16
+
17
+require gopkg.in/yaml.v2 v2.4.0 // indirect

+ 14
- 0
go.sum Zobrazit soubor

@@ -0,0 +1,14 @@
1
+git.x2erp.com/qdy/go-base v0.1.44 h1:xHpMppSNj79lqdUc+lmgGXOgEvHyNotUayoe5/hHWr4=
2
+git.x2erp.com/qdy/go-base v0.1.44/go.mod h1:Q+YLwpCoU8CVSnzATLdz2LAzVMlz/CEGzo8DePf7cug=
3
+github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
4
+github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
5
+github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
6
+github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
7
+github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
8
+github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
9
+github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
10
+go-micro.dev/v4 v4.11.0 h1:DZ2xcr0pnZJDlp6MJiCLhw4tXRxLw9xrJlPT91kubr0=
11
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
12
+gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
13
+gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
14
+gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=

+ 71
- 0
main.go Zobrazit soubor

@@ -0,0 +1,71 @@
1
+package main
2
+
3
+import (
4
+	"log"
5
+
6
+	"git.x2erp.com/qdy/go-base/bootstraps"
7
+	"git.x2erp.com/qdy/go-db/factory/database"
8
+	"git.x2erp.com/qdy/go-db/sqldef"
9
+	"go-micro.dev/v4/web"
10
+
11
+	_ "git.x2erp.com/qdy/go-svc-mercury/tables" // 导入表定义包,触发 init() 函数
12
+)
13
+
14
+var (
15
+	serviceName    = "svc-configure"
16
+	serviceVersion = "1"
17
+)
18
+
19
+func main() {
20
+
21
+	// 创建服务启动器
22
+	bootstrapper := bootstraps.NewServiceBootstrapper(serviceName, serviceVersion)
23
+
24
+	//加载配置
25
+	bootstrapper.InitConfig()
26
+
27
+	//构建数据库工厂
28
+	bootstrapper.InitDatabase()
29
+
30
+	//创建表到数据库
31
+	creteTabel(bootstrapper.DbFactory)
32
+
33
+	// 启动服务,传入路由注册函数
34
+	bootstrapper.Run(registerRoutes)
35
+
36
+}
37
+
38
+// 注册所有路由
39
+func registerRoutes(webService web.Service, dbFactory *database.DBFactory) {
40
+
41
+	// // 查询yaml配置文件
42
+	// webService.Handle("/api/query/yaml", middleware.JWTAuthMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
43
+	// 	myhandle.QueryHandlerMap(w, r, dbFactory, service.QueryYamlConfigure)
44
+	// })))
45
+
46
+	// // 初始化配置模版
47
+	// webService.Handle("/api/init/config/template", middleware.JWTAuthMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
48
+	// 	myhandle.QueryHandlerMap(w, r, dbFactory, service.InitConfigTemplates)
49
+	// })))
50
+
51
+}
52
+
53
+func creteTabel(factory *database.DBFactory) {
54
+
55
+	// 获取数据库连接和类型
56
+	db := factory.GetDB()
57
+	dbType := factory.GetDBType()
58
+
59
+	// 创建表同步器
60
+	syncer, err := sqldef.NewTableSyncer(db, dbType)
61
+	if err != nil {
62
+		log.Printf("创建 - 建立器失败: %v", err)
63
+	}
64
+
65
+	// 创建表
66
+	if err := syncer.CreateTables(); err != nil {
67
+		log.Printf("建表失败: %v", err)
68
+	}
69
+
70
+	log.Println("数据库表建立完成!")
71
+}

+ 38
- 0
tables/config_channel.go Zobrazit soubor

@@ -0,0 +1,38 @@
1
+package tables
2
+
3
+import (
4
+	"time"
5
+
6
+	"git.x2erp.com/qdy/go-db/sqldef"
7
+)
8
+
9
+func init() {
10
+	sqldef.AddRegistration(func(r *sqldef.Registry) {
11
+		tb := sqldef.NewTable("config_channel", "渠道档案表").
12
+			ID("channel_id", 32).Comment("渠道编码,主键").End().
13
+			String("channel_name", 64).NotNull().Comment("渠道名称(如:天猫旗舰店)").End().
14
+			String("channel_type", 32).NotNull().Comment("渠道类型(如:线上/线下/奥莱)").End().
15
+			String("store_id", 32).Comment("关联门店/仓库ID,对应ERP编码").End().
16
+			String("tenant_id", 8).NotNull().Comment("租户ID").End().
17
+			String("store_group_id", 32).NotNull().Comment("所属店铺组").End().
18
+			String("creator", 32).NotNull().Comment("创建人").End().
19
+			DateTime("created_at").NotNull().Default("CURRENT_TIMESTAMP").Comment("创建时间").End()
20
+		r.RegisterTable(tb.Build())
21
+	})
22
+}
23
+
24
+// ConfigChannel 渠道档案表结构体
25
+type ConfigChannel struct {
26
+	ChannelID    string    `gorm:"column:channel_id;type:varchar(32);primaryKey;not null;comment:渠道编码,主键"`
27
+	ChannelName  string    `gorm:"column:channel_name;type:varchar(64);not null;comment:渠道名称(如:天猫旗舰店)"`
28
+	ChannelType  string    `gorm:"column:channel_type;type:varchar(32);not null;comment:渠道类型(如:线上/线下/奥莱)"`
29
+	StoreID      string    `gorm:"column:store_id;type:varchar(32);comment:关联门店/仓库ID,对应ERP编码"`
30
+	TenantId     string    `gorm:"column:tenant_id;type:varchar(8);comment:租户ID"`
31
+	Creator      string    `gorm:"column:creator;type:varchar(32);not null;comment:创建人"`
32
+	CreatedAt    time.Time `gorm:"column:created_at;not null;default:CURRENT_TIMESTAMP;comment:创建时间"`
33
+	StoreGroupID string    `gorm:"column:store_group_id;type:varchar(32);comment:所属店铺组"`
34
+}
35
+
36
+func (ConfigChannel) TableName() string {
37
+	return "config_channel"
38
+}

+ 52
- 0
tables/decision_task.go Zobrazit soubor

@@ -0,0 +1,52 @@
1
+package tables
2
+
3
+import (
4
+	"time"
5
+
6
+	"git.x2erp.com/qdy/go-db/sqldef"
7
+)
8
+
9
+func init() {
10
+	sqldef.AddRegistration(func(r *sqldef.Registry) {
11
+		tb := sqldef.NewTable("decision_task", "决策任务表").
12
+			ID("task_id", 32).Comment("任务ID,主键").End().
13
+			String("sku_id", 32).NotNull().Comment("关联商品").End().
14
+			String("task_type", 32).NotNull().Comment("任务类型(调拨/促销/反单/保持)").End().
15
+			String("task_status", 32).NotNull().Default("'pending'").Comment("任务状态(pending/approved/rejected/executed)").End().
16
+			Text("task_content").NotNull().Comment("任务详细内容与参数(JSON格式)").End().
17
+			Text("diagnosis_basis").NotNull().Comment("诊断依据与数据快照(JSON格式)").End().
18
+			String("creator", 32).Comment("任务创建人(系统或用户)").End().
19
+			String("approver", 32).Comment("审批人").End().
20
+			DateTime("approved_at").Comment("审批时间").End().
21
+			String("executor", 32).Comment("执行人").End().
22
+			String("tenant_id", 8).NotNull().Comment("租户ID").End().
23
+			DateTime("executed_at").Comment("执行时间").End().
24
+			Text("execution_feedback").Comment("执行反馈(JSON格式)").End().
25
+			DateTime("created_at").NotNull().Default("CURRENT_TIMESTAMP").Comment("创建时间").End().
26
+			DateTime("updated_at").NotNull().Default("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP").Comment("更新时间").End()
27
+		r.RegisterTable(tb.Build())
28
+	})
29
+}
30
+
31
+// DecisionTask 决策任务表结构体
32
+type DecisionTask struct {
33
+	TaskID            string    `gorm:"column:task_id;type:varchar(32);primaryKey;not null;comment:任务ID,主键"`
34
+	SkuID             string    `gorm:"column:sku_id;type:varchar(32);not null;comment:关联商品;index"`
35
+	TaskType          string    `gorm:"column:task_type;type:varchar(32);not null;comment:任务类型(调拨/促销/反单/保持)"`
36
+	TaskStatus        string    `gorm:"column:task_status;type:varchar(32);not null;default:'pending';comment:任务状态(pending/approved/rejected/executed)"`
37
+	TaskContent       string    `gorm:"column:task_content;type:text;not null;comment:任务详细内容与参数(JSON格式)"`
38
+	DiagnosisBasis    string    `gorm:"column:diagnosis_basis;type:text;not null;comment:诊断依据与数据快照(JSON格式)"`
39
+	Creator           string    `gorm:"column:creator;type:varchar(32);comment:任务创建人(系统或用户)"`
40
+	Approver          string    `gorm:"column:approver;type:varchar(32);comment:审批人"`
41
+	ApprovedAt        time.Time `gorm:"column:approved_at;comment:审批时间"`
42
+	Executor          string    `gorm:"column:executor;type:varchar(32);comment:执行人"`
43
+	ExecutedAt        time.Time `gorm:"column:executed_at;comment:执行时间"`
44
+	ExecutionFeedback string    `gorm:"column:execution_feedback;type:text;comment:执行反馈(JSON格式)"`
45
+	CreatedAt         time.Time `gorm:"column:created_at;not null;default:CURRENT_TIMESTAMP;comment:创建时间"`
46
+	UpdatedAt         time.Time `gorm:"column:updated_at;not null;default:CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;comment:更新时间"`
47
+	TenantId          string    `gorm:"column:tenant_id;type:varchar(8);comment:租户ID"`
48
+}
49
+
50
+func (DecisionTask) TableName() string {
51
+	return "decision_task"
52
+}

+ 39
- 0
tables/dim_season.go Zobrazit soubor

@@ -0,0 +1,39 @@
1
+package tables
2
+
3
+import (
4
+	"time"
5
+
6
+	"git.x2erp.com/qdy/go-db/sqldef"
7
+)
8
+
9
+func init() {
10
+	sqldef.AddRegistration(func(r *sqldef.Registry) {
11
+		tb := sqldef.NewTable("dim_season", "季节波段档案表").
12
+			ID("season_id", 32).Comment("季节波段ID,主键").End().
13
+			String("season_code", 32).NotNull().Unique().Comment("季节编码(如:2024FA)").End().
14
+			String("season_name", 64).NotNull().Comment("季节名称(如:2024秋冬)").End().
15
+			Int("year").NotNull().Comment("年份").End().
16
+			String("phase", 32).NotNull().Comment("季节(春/夏/秋/冬)").End().
17
+			DateTime("plan_start").NotNull().Comment("季节计划开始日期").End().
18
+			DateTime("plan_end").NotNull().Comment("季节计划结束日期").End().
19
+			String("creator", 32).NotNull().Comment("创建人").End().
20
+			String("tenant_id", 8).NotNull().Comment("租户ID").End().
21
+			DateTime("created_at").NotNull().Default("CURRENT_TIMESTAMP").Comment("创建时间").End()
22
+		r.RegisterTable(tb.Build())
23
+	})
24
+}
25
+
26
+type DimSeason struct {
27
+	SeasonID   string    `gorm:"column:season_id;type:varchar(32);primaryKey;not null;comment:季节波段ID,主键"`
28
+	SeasonCode string    `gorm:"column:season_code;type:varchar(32);not null;unique;comment:季节编码(如:2024FA)"`
29
+	SeasonName string    `gorm:"column:season_name;type:varchar(64);not null;comment:季节名称(如:2024秋冬)"`
30
+	Year       int       `gorm:"column:year;not null;comment:年份"`
31
+	Phase      string    `gorm:"column:phase;type:varchar(32);not null;comment:季节(春/夏/秋/冬)"`
32
+	PlanStart  time.Time `gorm:"column:plan_start;not null;comment:季节计划开始日期"`
33
+	PlanEnd    time.Time `gorm:"column:plan_end;not null;comment:季节计划结束日期"`
34
+	Creator    string    `gorm:"column:creator;type:varchar(32);not null;comment:创建人"`
35
+	CreatedAt  time.Time `gorm:"column:created_at;not null;default:CURRENT_TIMESTAMP;comment:创建时间"`
36
+	TenantId   string    `gorm:"column:tenant_id;type:varchar(8);comment:租户ID"`
37
+}
38
+
39
+func (DimSeason) TableName() string { return "dim_season" }

+ 34
- 0
tables/dim_store_group.go Zobrazit soubor

@@ -0,0 +1,34 @@
1
+package tables
2
+
3
+import (
4
+	"time"
5
+
6
+	"git.x2erp.com/qdy/go-db/sqldef"
7
+)
8
+
9
+func init() {
10
+	sqldef.AddRegistration(func(r *sqldef.Registry) {
11
+		tb := sqldef.NewTable("dim_store_group", "店铺组档案表").
12
+			ID("group_id", 32).Comment("店铺组ID,主键").End().
13
+			String("group_code", 32).NotNull().Unique().Comment("店铺组编码").End().
14
+			String("group_name", 64).NotNull().Comment("店铺组名称(如:华东A类店)").End().
15
+			String("group_type", 32).NotNull().Comment("分组类型(区域/城市等级/渠道/店铺等级)").End().
16
+			String("description", 255).Comment("分组描述").End().
17
+			String("creator", 32).NotNull().Comment("创建人").End().
18
+			DateTime("created_at").NotNull().Default("CURRENT_TIMESTAMP").Comment("创建时间").End()
19
+		r.RegisterTable(tb.Build())
20
+	})
21
+}
22
+
23
+type DimStoreGroup struct {
24
+	GroupID     string    `gorm:"column:group_id;type:varchar(32);primaryKey;not null;comment:店铺组ID,主键"`
25
+	GroupCode   string    `gorm:"column:group_code;type:varchar(32);not null;unique;comment:店铺组编码"`
26
+	GroupName   string    `gorm:"column:group_name;type:varchar(64);not null;comment:店铺组名称(如:华东A类店)"`
27
+	GroupType   string    `gorm:"column:group_type;type:varchar(32);not null;comment:分组类型(区域/城市等级/渠道/店铺等级)"`
28
+	Description string    `gorm:"column:description;type:varchar(255);comment:分组描述"`
29
+	Creator     string    `gorm:"column:creator;type:varchar(32);not null;comment:创建人"`
30
+	CreatedAt   time.Time `gorm:"column:created_at;not null;default:CURRENT_TIMESTAMP;comment:创建时间"`
31
+	TenantId    string    `gorm:"column:tenant_id;type:varchar(8);comment:租户ID"`
32
+}
33
+
34
+func (DimStoreGroup) TableName() string { return "dim_store_group" }

+ 47
- 0
tables/fact_campaign_plan.go Zobrazit soubor

@@ -0,0 +1,47 @@
1
+package tables
2
+
3
+import (
4
+	"time"
5
+
6
+	"git.x2erp.com/qdy/go-db/sqldef"
7
+)
8
+
9
+func init() {
10
+	sqldef.AddRegistration(func(r *sqldef.Registry) {
11
+		tb := sqldef.NewTable("fact_campaign_plan", "波段作战计划表").
12
+			ID("plan_id", 32).Comment("计划ID,主键").End().
13
+			String("season_id", 32).NotNull().Comment("季节波段").End().
14
+			String("group_id", 32).NotNull().Comment("店铺组").End().
15
+			String("campaign_tag", 64).NotNull().Comment("波段标签(如:秋一波)").End().
16
+			Int("campaign_seq").NotNull().Comment("波段序号").End().
17
+			DateTime("plan_start_date").NotNull().Comment("该组计划上市日期").End().
18
+			DateTime("plan_end_date").NotNull().Comment("该组计划下市日期").End().
19
+			Decimal("sales_target", 12, 2).Comment("销售目标金额").End().
20
+			Int("sales_target_qty").Comment("销售目标件数").End().
21
+			String("tenant_id", 8).NotNull().Comment("租户ID").End().
22
+			Text("planned_skus").Comment("计划主推SKU列表(JSON)").End().
23
+			String("creator", 32).NotNull().Comment("创建人").End().
24
+			DateTime("created_at").NotNull().Default("CURRENT_TIMESTAMP").Comment("创建时间").End().
25
+			DateTime("updated_at").NotNull().Default("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP").Comment("更新时间").End()
26
+		r.RegisterTable(tb.Build())
27
+	})
28
+}
29
+
30
+type FactCampaignPlan struct {
31
+	PlanID         string    `gorm:"column:plan_id;type:varchar(32);primaryKey;not null;comment:计划ID,主键"`
32
+	SeasonID       string    `gorm:"column:season_id;type:varchar(32);not null;comment:季节波段;index:idx_season_group"`
33
+	GroupID        string    `gorm:"column:group_id;type:varchar(32);not null;comment:店铺组;index:idx_season_group"`
34
+	CampaignTag    string    `gorm:"column:campaign_tag;type:varchar(64);not null;comment:波段标签(如:秋一波)"`
35
+	CampaignSeq    int       `gorm:"column:campaign_seq;not null;comment:波段序号"`
36
+	PlanStartDate  time.Time `gorm:"column:plan_start_date;not null;comment:该组计划上市日期"`
37
+	PlanEndDate    time.Time `gorm:"column:plan_end_date;not null;comment:该组计划下市日期"`
38
+	SalesTarget    float64   `gorm:"column:sales_target;type:decimal(12,2);comment:销售目标金额"`
39
+	SalesTargetQty int       `gorm:"column:sales_target_qty;comment:销售目标件数"`
40
+	PlannedSkus    string    `gorm:"column:planned_skus;type:text;comment:计划主推SKU列表(JSON)"`
41
+	Creator        string    `gorm:"column:creator;type:varchar(32);not null;comment:创建人"`
42
+	CreatedAt      time.Time `gorm:"column:created_at;not null;default:CURRENT_TIMESTAMP;comment:创建时间"`
43
+	UpdatedAt      time.Time `gorm:"column:updated_at;not null;default:CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;comment:更新时间"`
44
+	TenantId       string    `gorm:"column:tenant_id;type:varchar(8);comment:租户ID"`
45
+}
46
+
47
+func (FactCampaignPlan) TableName() string { return "fact_campaign_plan" }

+ 36
- 0
tables/inventory_snapshot.go Zobrazit soubor

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

+ 48
- 0
tables/product_sku.go Zobrazit soubor

@@ -0,0 +1,48 @@
1
+package tables
2
+
3
+import (
4
+	"time"
5
+
6
+	"git.x2erp.com/qdy/go-db/sqldef"
7
+)
8
+
9
+func init() {
10
+	sqldef.AddRegistration(func(r *sqldef.Registry) {
11
+		tb := sqldef.NewTable("product_sku", "商品档案表").
12
+			ID("sku_id", 32).Comment("款色码唯一标识,主键").End().
13
+			String("sku_code", 64).NotNull().Comment("商品款号").End().
14
+			String("sku_name", 128).NotNull().Comment("商品名称").End().
15
+			String("category_code", 32).NotNull().Comment("品类编码").End().
16
+			String("category_name", 64).NotNull().Comment("品类名称").End().
17
+			String("season_code", 32).NotNull().Comment("季节波段编码").End().
18
+			String("season_name", 64).NotNull().Comment("季节波段名称").End().
19
+			String("tenant_id", 8).NotNull().Comment("租户ID").End().
20
+			DateTime("first_list_date").NotNull().Comment("首次上市日期").End().
21
+			Decimal("tag_price", 10, 2).NotNull().Comment("吊牌价").End().
22
+			String("creator", 32).NotNull().Comment("创建人").End().
23
+			DateTime("created_at").NotNull().Default("CURRENT_TIMESTAMP").Comment("创建时间").End().
24
+			DateTime("updated_at").NotNull().Default("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP").Comment("更新时间").End()
25
+		r.RegisterTable(tb.Build())
26
+	})
27
+}
28
+
29
+// ProductSku 商品档案表结构体
30
+type ProductSku struct {
31
+	SkuID         string    `gorm:"column:sku_id;type:varchar(32);primaryKey;not null;comment:款色码唯一标识,主键"`
32
+	SkuCode       string    `gorm:"column:sku_code;type:varchar(64);not null;comment:商品款号"`
33
+	SkuName       string    `gorm:"column:sku_name;type:varchar(128);not null;comment:商品名称"`
34
+	CategoryCode  string    `gorm:"column:category_code;type:varchar(32);not null;comment:品类编码"`
35
+	CategoryName  string    `gorm:"column:category_name;type:varchar(64);not null;comment:品类名称"`
36
+	SeasonCode    string    `gorm:"column:season_code;type:varchar(32);not null;comment:季节波段编码"`
37
+	SeasonName    string    `gorm:"column:season_name;type:varchar(64);not null;comment:季节波段名称"`
38
+	FirstListDate time.Time `gorm:"column:first_list_date;not null;comment:首次上市日期"`
39
+	TagPrice      float64   `gorm:"column:tag_price;type:decimal(10,2);not null;comment:吊牌价"`
40
+	Creator       string    `gorm:"column:creator;type:varchar(32);not null;comment:创建人"`
41
+	CreatedAt     time.Time `gorm:"column:created_at;not null;default:CURRENT_TIMESTAMP;comment:创建时间"`
42
+	UpdatedAt     time.Time `gorm:"column:updated_at;not null;default:CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;comment:更新时间"`
43
+	TenantId      string    `gorm:"column:tenant_id;type:varchar(8);comment:租户ID"`
44
+}
45
+
46
+func (ProductSku) TableName() string {
47
+	return "product_sku"
48
+}

+ 40
- 0
tables/purchase_receipt.go Zobrazit soubor

@@ -0,0 +1,40 @@
1
+package tables
2
+
3
+import (
4
+	"time"
5
+
6
+	"git.x2erp.com/qdy/go-db/sqldef"
7
+)
8
+
9
+func init() {
10
+	sqldef.AddRegistration(func(r *sqldef.Registry) {
11
+		tb := sqldef.NewTable("purchase_receipt", "采购入库表").
12
+			ID("receipt_id", 32).Comment("入库单ID,主键").End().
13
+			String("erp_receipt_id", 64).NotNull().Comment("ERP原始入库单号").End().
14
+			String("sku_id", 32).NotNull().Comment("商品SKU").End().
15
+			String("channel_id", 32).NotNull().Comment("入库渠道/仓库").End().
16
+			Int("quantity").NotNull().Default("0").Comment("入库数量").End().
17
+			String("tenant_id", 8).NotNull().Comment("租户ID").End().
18
+			DateTime("receipt_time").NotNull().Comment("实际入库时间").End().
19
+			DateTime("expected_arrival_date").Comment("预计到货日期").End().
20
+			DateTime("extracted_at").NotNull().Default("CURRENT_TIMESTAMP").Comment("数据抽取时间").End()
21
+		r.RegisterTable(tb.Build())
22
+	})
23
+}
24
+
25
+// PurchaseReceipt 采购入库表结构体
26
+type PurchaseReceipt struct {
27
+	ReceiptID           string    `gorm:"column:receipt_id;type:varchar(32);primaryKey;not null;comment:入库单ID,主键"`
28
+	ErpReceiptID        string    `gorm:"column:erp_receipt_id;type:varchar(64);not null;comment:ERP原始入库单号;index"`
29
+	SkuID               string    `gorm:"column:sku_id;type:varchar(32);not null;comment:商品SKU;index"`
30
+	ChannelID           string    `gorm:"column:channel_id;type:varchar(32);not null;comment:入库渠道/仓库"`
31
+	Quantity            int       `gorm:"column:quantity;not null;default:0;comment:入库数量"`
32
+	ReceiptTime         time.Time `gorm:"column:receipt_time;not null;comment:实际入库时间"`
33
+	ExpectedArrivalDate time.Time `gorm:"column:expected_arrival_date;comment:预计到货日期"`
34
+	ExtractedAt         time.Time `gorm:"column:extracted_at;not null;default:CURRENT_TIMESTAMP;comment:数据抽取时间"`
35
+	TenantId            string    `gorm:"column:tenant_id;type:varchar(8);comment:租户ID"`
36
+}
37
+
38
+func (PurchaseReceipt) TableName() string {
39
+	return "purchase_receipt"
40
+}

+ 42
- 0
tables/sales_transaction.go Zobrazit soubor

@@ -0,0 +1,42 @@
1
+package tables
2
+
3
+import (
4
+	"time"
5
+
6
+	"git.x2erp.com/qdy/go-db/sqldef"
7
+)
8
+
9
+func init() {
10
+	sqldef.AddRegistration(func(r *sqldef.Registry) {
11
+		tb := sqldef.NewTable("sales_transaction", "销售流水表").
12
+			ID("transaction_id", 32).Comment("交易流水ID,主键").End().
13
+			String("erp_order_id", 64).NotNull().Comment("ERP原始订单号").End().
14
+			String("sku_id", 32).NotNull().Comment("商品SKU").End().
15
+			String("channel_id", 32).NotNull().Comment("销售渠道").End().
16
+			String("tenant_id", 8).NotNull().Comment("租户ID").End().
17
+			Int("quantity").NotNull().Default("0").Comment("销售数量").End().
18
+			Decimal("original_amount", 12, 2).NotNull().Comment("吊牌价金额").End().
19
+			Decimal("actual_amount", 12, 2).NotNull().Comment("实收金额").End().
20
+			DateTime("sale_time").NotNull().Comment("销售时间").End().
21
+			DateTime("extracted_at").NotNull().Default("CURRENT_TIMESTAMP").Comment("数据抽取时间").End()
22
+		r.RegisterTable(tb.Build())
23
+	})
24
+}
25
+
26
+// SalesTransaction 销售流水表结构体
27
+type SalesTransaction struct {
28
+	TransactionID  string    `gorm:"column:transaction_id;type:varchar(32);primaryKey;not null;comment:交易流水ID,主键"`
29
+	ErpOrderID     string    `gorm:"column:erp_order_id;type:varchar(64);not null;comment:ERP原始订单号;index"`
30
+	SkuID          string    `gorm:"column:sku_id;type:varchar(32);not null;comment:商品SKU;index:idx_sku_channel_time"`
31
+	ChannelID      string    `gorm:"column:channel_id;type:varchar(32);not null;comment:销售渠道;index:idx_sku_channel_time"`
32
+	Quantity       int       `gorm:"column:quantity;not null;default:0;comment:销售数量"`
33
+	OriginalAmount float64   `gorm:"column:original_amount;type:decimal(12,2);not null;comment:吊牌价金额"`
34
+	ActualAmount   float64   `gorm:"column:actual_amount;type:decimal(12,2);not null;comment:实收金额"`
35
+	SaleTime       time.Time `gorm:"column:sale_time;not null;comment:销售时间;index:idx_sku_channel_time"`
36
+	ExtractedAt    time.Time `gorm:"column:extracted_at;not null;default:CURRENT_TIMESTAMP;comment:数据抽取时间"`
37
+	TenantId       string    `gorm:"column:tenant_id;type:varchar(8);comment:租户ID"`
38
+}
39
+
40
+func (SalesTransaction) TableName() string {
41
+	return "sales_transaction"
42
+}

Loading…
Zrušit
Uložit