@dazitech/cli 3.0.8 → 3.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/clis/dazi-app.js +1 -1
- package/dist/clis/dazi-flow.js +1 -1
- package/dist/clis/dazi-onto.js +1 -1
- package/dist/clis/dazi.js +1 -1
- package/dist/docs/flow/flow-project-guide.md +1 -1
- package/dist/docs/guides/troubleshooting.md +12 -1
- package/dist/docs/index.json +20 -1
- package/dist/docs/onto/dazi_script_sdk_reference.md +78 -12
- package/dist/docs/onto/function-guide.md +61 -33
- package/dist/docs/onto//346/234/254/344/275/223/345/210/206/347/261/273/350/247/204/345/210/222/344/270/216SDK/346/211/251/345/261/225/346/226/271/346/241/210.md +168 -0
- package/dist/docs/onto//346/234/254/344/275/223/345/221/275/345/220/215/350/247/204/350/214/203_/347/211/251/347/220/206/350/241/250Cube/344/270/216/345/257/271/350/261/241.md +402 -0
- package/dist/docs/onto//346/234/254/344/275/223/350/204/232/346/234/254/347/274/226/345/206/231/346/214/207/345/215/227.md +63 -1
- package/dist/docs/onto//346/234/254/344/275/223/350/247/204/345/210/222/346/214/207/345/215/227.md +123 -15
- package/dist/docs/onto//350/204/232/346/234/254/350/277/220/350/241/214/347/272/240/351/224/231_/345/225/206/345/212/241/346/210/220/346/234/254/346/226/271/346/241/210/345/274/200/345/217/221/350/277/207/347/250/213.md +213 -0
- package/dist/docs/onto//350/247/204/345/210/222/347/244/272/344/276/213_/344/272/247/345/223/201/351/224/200/345/224/256/346/234/254/344/275/223/350/247/204/345/210/222/346/226/271/346/241/210.md +356 -233
- package/dist/docs/onto//350/247/204/345/210/222/347/244/272/344/276/213_/345/210/251/346/266/246/345/210/206/346/236/220/346/234/254/344/275/223/346/226/271/346/241/210.md +379 -296
- package/dist/examples/index.json +23 -17
- package/dist/examples/onto/README.md +13 -5
- package/dist/examples/onto/_templates/ontology_function_template.py +50 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_account_breakdown.py +62 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_budget_vs_actual.py +69 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_cost_center_profit.py +64 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_get_summary.py +61 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_mom_analysis.py +82 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_top_accounts.py +61 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_yoy_analysis.py +79 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/save_test_arguments.ps1 +38 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/test_arguments/profit.fn.account_breakdown.json +1 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/test_arguments/profit.fn.budget_vs_actual.json +1 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/test_arguments/profit.fn.cost_center_profit.json +1 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/test_arguments/profit.fn.get_summary.json +1 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/test_arguments/profit.fn.mom_analysis.json +1 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/test_arguments/profit.fn.top_accounts.json +1 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/test_arguments/profit.fn.yoy_analysis.json +1 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_ontology_init.py +232 -74
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_seed_data.py +16 -13
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_channel_mix.py +19 -16
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_customer_segmentation.py +48 -50
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_get_summary.py +3 -6
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_mom_analysis.py +11 -12
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_region_breakdown.py +6 -7
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_top_products.py +5 -8
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_yoy_analysis.py +3 -6
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/save_test_arguments.ps1 +32 -19
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.channel_mix.json +3 -6
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.customer_segmentation.json +2 -7
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.get_summary.json +2 -5
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.mom_analysis.json +2 -5
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.region_breakdown.json +2 -5
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.top_products.json +2 -7
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.yoy_analysis.json +2 -5
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_ontology_init.py +291 -155
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_seed_data.py +59 -20
- package/dist/prompts/index.json +1 -1
- package/dist/prompts/onto/function-design.md +42 -22
- package/dist/prompts/onto/script-publish-run.md +15 -1
- package/package.json +1 -1
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_account_breakdown.py +0 -99
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_budget_vs_actual.py +0 -116
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_cost_center_profit.py +0 -85
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_get_summary.py +0 -76
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_mom_analysis.py +0 -86
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_top_accounts.py +0 -103
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_yoy_analysis.py +0 -86
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/save_test_arguments.ps1 +0 -27
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.account_breakdown.json +0 -10
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.budget_vs_actual.json +0 -10
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.cost_center_profit.json +0 -9
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.get_summary.json +0 -9
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.mom_analysis.json +0 -9
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.top_accounts.json +0 -11
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.yoy_analysis.json +0 -9
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/README.md +0 -25
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/README.md +0 -5
|
@@ -2,20 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
**文档 ID**: `onto/planning-example-product-sales`
|
|
4
4
|
|
|
5
|
-
> **推荐**:本体规划阶段**首选参考示例**。覆盖物理表、**表间关系**、Cube、本体链接、函数与 **test_arguments**
|
|
5
|
+
> **推荐**:本体规划阶段**首选参考示例**。覆盖物理表、**表间关系**、Cube、本体链接、函数与 **test_arguments** 完整落地;表/Cube/对象命名遵循 [本体命名规范](./本体命名规范_物理表Cube与对象.md)。
|
|
6
6
|
> 补充示例(利润分析域):[规划示例_利润分析本体方案.md](./规划示例_利润分析本体方案.md)
|
|
7
7
|
|
|
8
|
+
**占位符**(复制到工作区 `plans/` 后替换为实际值):
|
|
9
|
+
|
|
10
|
+
| 占位符 | 含义 | 权威来源 |
|
|
11
|
+
| ------ | ---- | -------- |
|
|
12
|
+
| `<space-id>` | 数据空间 ID | `项目/<业务名>/本体/ontos/<实现名>/README.md` |
|
|
13
|
+
| `<业务名>` | 业务项目目录名 | 工作区 `项目/` 下文件夹 |
|
|
14
|
+
| `<实现名>` | 本体实现单元名 | 如 `产品销售本体方案` |
|
|
15
|
+
| `<item-path>` | 实现单元根路径 | `项目/<业务名>/本体/ontos/<实现名>` |
|
|
16
|
+
|
|
8
17
|
---
|
|
9
18
|
|
|
10
19
|
## 一、空间概述
|
|
11
20
|
|
|
12
|
-
| 项目 | 说明
|
|
13
|
-
| -------- |
|
|
14
|
-
| 空间 ID |
|
|
15
|
-
| 空间名称 |
|
|
16
|
-
| 空间状态 | 空白空间(无表、无 Cube
|
|
17
|
-
| 规划日期 |
|
|
18
|
-
| 实现单元 |
|
|
21
|
+
| 项目 | 说明 |
|
|
22
|
+
| -------- | ---- |
|
|
23
|
+
| 空间 ID | `<space-id>`(示例:`space__acme`) |
|
|
24
|
+
| 空间名称 | `<空间名称>`(与平台数据空间显示名一致) |
|
|
25
|
+
| 空间状态 | 空白空间(无表、无 Cube、无本体)或已有他域表共存 |
|
|
26
|
+
| 规划日期 | (填写定稿日期) |
|
|
27
|
+
| 实现单元 | `<item-path>/` |
|
|
19
28
|
|
|
20
29
|
---
|
|
21
30
|
|
|
@@ -23,7 +32,7 @@
|
|
|
23
32
|
|
|
24
33
|
### 2.1 业务背景
|
|
25
34
|
|
|
26
|
-
|
|
35
|
+
某制造企业(示例)产品销售场景,需构建**产品销售本体**,以业务语言描述「产品」「销售订单」及其关系,支撑:
|
|
27
36
|
|
|
28
37
|
- 按产品大类、SKU 的销售量与销售额分析
|
|
29
38
|
- 按区域、客户类型、渠道的销售分布
|
|
@@ -42,183 +51,206 @@
|
|
|
42
51
|
|
|
43
52
|
### 2.3 规划范围说明
|
|
44
53
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
| 表名 | 中文名 | 角色 |
|
|
48
|
-
| ------------------ | ------------ | ---------------------------- |
|
|
49
|
-
| `product_master` | **产品表** | 产品主数据(维表) |
|
|
50
|
-
| `sales_order_fact` | **销售表** | 销售订单/订单行事实(事实表)|
|
|
51
|
-
|
|
52
|
-
**辅助维表(支撑销售表外键语义,建议同期建设)**:
|
|
54
|
+
**物理表清单**(命名见 [命名规范 §2](./本体命名规范_物理表Cube与对象.md#2-物理表类别与前缀)):
|
|
53
55
|
|
|
54
|
-
| 表名
|
|
55
|
-
|
|
|
56
|
-
|
|
|
57
|
-
| `
|
|
56
|
+
| 表名 | 前缀类别 | **347 分类** | 显示名 | 说明 | 角色 |
|
|
57
|
+
| ---- | -------- | ------------ | ------ | ---- | ---- |
|
|
58
|
+
| **`dim_date`** | 时间维(**强制**) | **时间维** | 日期维表 | 全空间共享;PK **`date_key`** | 时间维 |
|
|
59
|
+
| `dim_product` | dim | **维度表** | 产品维表 | 可售产品主数据 | dim |
|
|
60
|
+
| `dim_customer` | dim | **维度表** | 客户维表 | 购买方主数据 | dim |
|
|
61
|
+
| `dim_channel` | dim | **维度表** | 渠道维表 | 销售渠道主数据 | dim |
|
|
62
|
+
| **`fact_sales_order_line`** | fact | **事实表** | 销售订单行事实表 | 订单行粒度销售流水;含 **`date_key`** | fact |
|
|
58
63
|
|
|
59
|
-
>
|
|
64
|
+
> 规划原则:**先**定义业务对象(Product、SalesOrder 等)与链接,**再**反推 Cube 与物理表。事实表通过 `date_key` 关联 `dim_date`,支撑同比/环比与时间层次分析。
|
|
65
|
+
> init 脚本 `资源/examples/onto/销售示例/setup/sales_ontology_init.py` 顶部 **`TABLE_REGISTRY`** 与上表及 §3.x 字段 **显示名/说明** 一一对应,经 `s.tables.register_with_meta` 注册;**`CATEGORY_REGISTRY`** 与 [附录 B](#附录-b347-分类挂载对照表category_registry) 及 `apply_registry` 步骤对齐。
|
|
60
66
|
|
|
61
67
|
---
|
|
62
68
|
|
|
63
69
|
## 三、物理层设计
|
|
64
70
|
|
|
65
|
-
### 3.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
|
72
|
-
|
|
|
73
|
-
|
|
|
74
|
-
|
|
|
75
|
-
|
|
|
76
|
-
|
|
|
77
|
-
|
|
|
78
|
-
|
|
|
79
|
-
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
|
96
|
-
|
|
|
97
|
-
|
|
|
98
|
-
|
|
|
99
|
-
|
|
|
100
|
-
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
|
109
|
-
|
|
|
110
|
-
|
|
|
111
|
-
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
71
|
+
### 3.0 时间维:dim_date(强制)
|
|
72
|
+
|
|
73
|
+
**用途**:全空间共享日历;事实表通过 **`date_key`** 关联;Cube 时间维与 YoY/MoM 函数优先基于本表。
|
|
74
|
+
|
|
75
|
+
| 字段名 | 类型 | 显示名 | 说明 |
|
|
76
|
+
| ------ | ---- | ------ | ---- |
|
|
77
|
+
| **date_key** | Int32 | 日期键 | YYYYMMDD,主键 |
|
|
78
|
+
| calendar_date | Date | 自然日 | |
|
|
79
|
+
| year | Int16 | 公历年 | |
|
|
80
|
+
| quarter | Int8 | 季度 | 1–4 |
|
|
81
|
+
| month | Int8 | 月 | 1–12 |
|
|
82
|
+
| week_of_year | Int8 | 周 | |
|
|
83
|
+
| day_of_week | Int8 | 星期 | |
|
|
84
|
+
| is_weekend | UInt8 | 是否周末 | 0/1 |
|
|
85
|
+
| year_month | String | 年月 | 如 2025-06 |
|
|
86
|
+
|
|
87
|
+
**排序键**:`ORDER BY (date_key)` · **引擎**:`MergeTree()`
|
|
88
|
+
|
|
89
|
+
### 3.1 维度表:dim_product
|
|
90
|
+
|
|
91
|
+
**用途**:可售产品(油品、化工品等)主数据。
|
|
92
|
+
|
|
93
|
+
| 字段名 | 类型 | 显示名 | 说明 |
|
|
94
|
+
| ------ | ---- | ------ | ---- |
|
|
95
|
+
| product_id | String | 产品 ID | 主键 |
|
|
96
|
+
| product_code | String | 产品编码 | |
|
|
97
|
+
| product_name | String | 产品名称 | |
|
|
98
|
+
| product_category | String | 产品大类 | |
|
|
99
|
+
| product_subcategory | String | 产品小类 | |
|
|
100
|
+
| brand | String | 品牌 | |
|
|
101
|
+
| unit | String | 计量单位 | |
|
|
102
|
+
| list_price | Float64 | 挂牌价 | |
|
|
103
|
+
| cost_price | Float64 | 成本单价 | |
|
|
104
|
+
| status | String | 状态 | 在售/停售 |
|
|
105
|
+
| created_at | DateTime | 创建时间 | |
|
|
106
|
+
| updated_at | DateTime | 更新时间 | |
|
|
107
|
+
|
|
108
|
+
**排序键**:`ORDER BY (product_id)`
|
|
109
|
+
|
|
110
|
+
### 3.2 事实表:fact_sales_order_line
|
|
111
|
+
|
|
112
|
+
**用途**:订单行粒度销售流水;Cube 与 SalesOrder 对象的主事实源。
|
|
113
|
+
|
|
114
|
+
| 字段名 | 类型 | 显示名 | 说明 |
|
|
115
|
+
| ------ | ---- | ------ | ---- |
|
|
116
|
+
| order_id | String | 订单 ID | |
|
|
117
|
+
| order_line_id | String | 订单行 ID | 主键组合 |
|
|
118
|
+
| **date_key** | Int32 | 日期键 | 关联 dim_date |
|
|
119
|
+
| order_date | Date | 订单日期 | |
|
|
120
|
+
| product_id | String | 产品 ID | 关联 dim_product |
|
|
121
|
+
| product_category | String | 产品大类 | 冗余 |
|
|
122
|
+
| customer_id | String | 客户 ID | 关联 dim_customer |
|
|
123
|
+
| customer_region | String | 销售区域 | 冗余 |
|
|
124
|
+
| customer_type | String | 客户类型 | 冗余 |
|
|
125
|
+
| channel_id | String | 渠道 ID | 关联 dim_channel |
|
|
126
|
+
| quantity | Int32 | 销售数量 | |
|
|
127
|
+
| unit_price | Float64 | 成交单价 | |
|
|
128
|
+
| discount_amount | Float64 | 折扣金额 | |
|
|
129
|
+
| sales_amount | Float64 | 销售金额 | |
|
|
130
|
+
| currency | String | 币种 | |
|
|
131
|
+
| order_status | String | 订单状态 | |
|
|
132
|
+
|
|
133
|
+
**排序键**:`ORDER BY (date_key, order_id, order_line_id)`
|
|
115
134
|
|
|
116
135
|
**业务规则**:
|
|
117
136
|
|
|
118
|
-
-
|
|
119
|
-
-
|
|
137
|
+
- 灌数:`date_key = toYYYYMMDD(order_date)`
|
|
138
|
+
- 分析默认过滤 `order_status IN ('已完成', '已发货')`
|
|
139
|
+
- `sales_amount` 与 `quantity * unit_price - discount_amount` 口径一致
|
|
120
140
|
|
|
121
|
-
### 3.3
|
|
141
|
+
### 3.3 维度表:dim_customer、dim_channel
|
|
122
142
|
|
|
123
|
-
####
|
|
143
|
+
#### dim_customer
|
|
124
144
|
|
|
125
|
-
| 字段名
|
|
126
|
-
|
|
|
127
|
-
| customer_id
|
|
128
|
-
| customer_code
|
|
129
|
-
| customer_name
|
|
130
|
-
| customer_region | String
|
|
131
|
-
| customer_type
|
|
132
|
-
| industry
|
|
133
|
-
| created_at
|
|
145
|
+
| 字段名 | 类型 | 显示名 | 说明 |
|
|
146
|
+
| ------ | ---- | ------ | ---- |
|
|
147
|
+
| customer_id | String | 客户 ID | 主键 |
|
|
148
|
+
| customer_code | String | 客户编码 | |
|
|
149
|
+
| customer_name | String | 客户名称 | |
|
|
150
|
+
| customer_region | String | 销售区域 | |
|
|
151
|
+
| customer_type | String | 客户类型 | |
|
|
152
|
+
| industry | String | 所属行业 | |
|
|
153
|
+
| created_at | DateTime | 创建时间 | |
|
|
134
154
|
|
|
135
|
-
####
|
|
155
|
+
#### dim_channel
|
|
136
156
|
|
|
137
|
-
| 字段名
|
|
138
|
-
|
|
|
139
|
-
| channel_id
|
|
140
|
-
| channel_code | String | 渠道编码 |
|
|
141
|
-
| channel_name | String | 渠道名称 |
|
|
142
|
-
| channel_type | String | 渠道类型 |
|
|
157
|
+
| 字段名 | 类型 | 显示名 | 说明 |
|
|
158
|
+
| ------ | ---- | ------ | ---- |
|
|
159
|
+
| channel_id | String | 渠道 ID | 主键 |
|
|
160
|
+
| channel_code | String | 渠道编码 | |
|
|
161
|
+
| channel_name | String | 渠道名称 | |
|
|
162
|
+
| channel_type | String | 渠道类型 | |
|
|
143
163
|
|
|
144
164
|
### 3.4 表间关系设计(物理层 · 数据空间)
|
|
145
165
|
|
|
146
166
|
> **与本体链接的区别**:本节描述 **ClickHouse 物理表之间的 FK/JOIN 关系**,写入数据空间 `ads_dataspace_relationships`,供侧栏 **数据资源 → 表间关系** 展示,并支撑流程节点多表 JOIN、AI 读空间上下文。
|
|
147
167
|
> **本体层链接**(第五节 `define_link_type`)描述业务对象语义,二者应 **一一对应、分层不混用**。
|
|
148
168
|
|
|
149
|
-
**关系模型(星型)**:以
|
|
169
|
+
**关系模型(星型)**:以 **`fact_sales_order_line`** 为事实表,关联 **`dim_date`** 与三张业务维表。
|
|
150
170
|
|
|
151
171
|
```text
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
(
|
|
159
|
-
▲
|
|
160
|
-
│
|
|
161
|
-
│
|
|
162
|
-
|
|
163
|
-
|
|
172
|
+
dim_date
|
|
173
|
+
(date_key PK)
|
|
174
|
+
▲
|
|
175
|
+
│ many_to_one
|
|
176
|
+
│
|
|
177
|
+
dim_product ◄─────────────┼─────────────► dim_customer
|
|
178
|
+
(product_id PK) │ (customer_id PK)
|
|
179
|
+
▲ │ ▲
|
|
180
|
+
│ │ │
|
|
181
|
+
│ fact_sales_order_line │
|
|
182
|
+
│ (order_line) │
|
|
183
|
+
└──────────────────┼────────────────────┘
|
|
184
|
+
│
|
|
185
|
+
▼
|
|
186
|
+
dim_channel
|
|
187
|
+
(channel_id PK)
|
|
164
188
|
```
|
|
165
189
|
|
|
166
|
-
**关系清单(
|
|
190
|
+
**关系清单(5 条)**:
|
|
167
191
|
|
|
168
|
-
| 关系 ID
|
|
169
|
-
|
|
|
170
|
-
|
|
|
171
|
-
|
|
|
172
|
-
|
|
|
192
|
+
| 关系 ID | **347 分类** | 类型 | 从表 | 到表 | join_keys | 说明 |
|
|
193
|
+
| ------- | ------------ | ---- | ---- | ---- | --------- | ---- |
|
|
194
|
+
| rel_sales_date | **时间关联** | many_to_one | fact_sales_order_line | dim_date | date_key → date_key | 订单行关联日历 |
|
|
195
|
+
| rel_sales_product | **主数据关联** | many_to_one | fact_sales_order_line | dim_product | product_id → product_id | 订单行关联产品 |
|
|
196
|
+
| rel_sales_customer | **主数据关联** | many_to_one | fact_sales_order_line | dim_customer | customer_id → customer_id | 订单行关联客户 |
|
|
197
|
+
| rel_sales_channel | **主数据关联** | many_to_one | fact_sales_order_line | dim_channel | channel_id → channel_id | 订单行关联渠道 |
|
|
173
198
|
|
|
174
|
-
**join_sql
|
|
199
|
+
**join_sql 示例**:
|
|
175
200
|
|
|
176
|
-
| 关系
|
|
177
|
-
|
|
|
178
|
-
|
|
|
179
|
-
|
|
|
180
|
-
|
|
|
201
|
+
| 关系 | join_sql |
|
|
202
|
+
| ---- | -------- |
|
|
203
|
+
| rel_sales_date | `fact_sales_order_line.date_key = dim_date.date_key` |
|
|
204
|
+
| rel_sales_product | `fact_sales_order_line.product_id = dim_product.product_id` |
|
|
205
|
+
| rel_sales_customer | `fact_sales_order_line.customer_id = dim_customer.customer_id` |
|
|
206
|
+
| rel_sales_channel | `fact_sales_order_line.channel_id = dim_channel.channel_id` |
|
|
181
207
|
|
|
182
|
-
**实施 API**(`setup/sales_ontology_init.py
|
|
208
|
+
**实施 API**(`setup/sales_ontology_init.py`,表 register 之后、Cube 之前):
|
|
183
209
|
|
|
184
210
|
```python
|
|
185
211
|
s.tables.add_relationship(
|
|
186
|
-
from_table="
|
|
187
|
-
to_table="
|
|
188
|
-
join_sql="
|
|
212
|
+
from_table="fact_sales_order_line",
|
|
213
|
+
to_table="dim_product",
|
|
214
|
+
join_sql="fact_sales_order_line.product_id = dim_product.product_id",
|
|
189
215
|
join_keys=[{"from": "product_id", "to": "product_id"}],
|
|
190
216
|
relationship_type="many_to_one",
|
|
191
|
-
description="
|
|
217
|
+
description="销售订单行关联产品",
|
|
192
218
|
)
|
|
193
219
|
```
|
|
194
220
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
| 字段 | 原因 |
|
|
198
|
-
| ------------------ | ------------------------------------------ |
|
|
199
|
-
| product_category | 事实表冗余列,非独立维表 FK |
|
|
200
|
-
| customer_region | 事实表冗余列,与 customer_dimension 重复 |
|
|
201
|
-
| customer_type | 事实表冗余列,与 customer_dimension 重复 |
|
|
221
|
+
**冗余列说明**(不单独建关系):`product_category`、`customer_region`、`customer_type` 为事实表冗余,与维表字段重复便于聚合。
|
|
202
222
|
|
|
203
223
|
**与本体链接对照**:
|
|
204
224
|
|
|
205
|
-
| 物理表关系
|
|
206
|
-
|
|
|
207
|
-
| rel_sales_product
|
|
208
|
-
| rel_sales_customer
|
|
209
|
-
| rel_sales_channel
|
|
225
|
+
| 物理表关系 | 对应本体链接 |
|
|
226
|
+
| ---------- | ------------ |
|
|
227
|
+
| rel_sales_product | order_contains_product |
|
|
228
|
+
| rel_sales_customer | order_belongs_customer |
|
|
229
|
+
| rel_sales_channel | order_via_channel |
|
|
230
|
+
| rel_sales_date | (时间维,函数/Cube 层 JOIN,可无独立链接类型) |
|
|
210
231
|
|
|
211
232
|
---
|
|
212
233
|
|
|
213
234
|
## 四、Cube 层设计
|
|
214
235
|
|
|
215
|
-
|
|
236
|
+
### 4.0 Cube 清单与类别
|
|
237
|
+
|
|
238
|
+
| Cube | 类别 | **347 分类** | 事实源 | 时间维 | 支撑对象 |
|
|
239
|
+
| ---- | ---- | ------------ | ------ | ------ | -------- |
|
|
240
|
+
| **SalesCube** | Process | **流程型** | fact_sales_order_line | dim_date(year/month/quarter) | SalesOrder, SalesAnalysis |
|
|
241
|
+
| **ProductSalesCube** | Subject | **主体型** | fact_sales_order_line | 同上 | Product |
|
|
242
|
+
| **CustomerSalesCube** | Subject | **主体型** | fact_sales_order_line | 同上 | Customer |
|
|
243
|
+
| **ChannelSalesCube** | Subject | **主体型** | fact_sales_order_line | 同上 | SalesChannel |
|
|
244
|
+
|
|
245
|
+
> 时间智能 **不单独建 Cube**;`SalesCube` 维度含 `date_key` 及自 `dim_date` JOIN 的 `year`、`month`、`year_month`、`quarter`(见 [命名规范 §4.2](./本体命名规范_物理表Cube与对象.md#42-cube-类别))。
|
|
246
|
+
|
|
247
|
+
所有 Cube 均以 **`fact_sales_order_line`** 为事实源;产品名称等可在函数 SQL 中 LEFT JOIN **`dim_product`**。
|
|
216
248
|
|
|
217
|
-
### 4.1 SalesCube
|
|
249
|
+
### 4.1 SalesCube(Process · 销售分析主 Cube)
|
|
218
250
|
|
|
219
251
|
**目的**:全局销售分析、SalesOrder / SalesAnalysis 读模型
|
|
220
252
|
|
|
221
|
-
**维度**:order_id, order_line_id, order_date, product_id, product_category, customer_id, customer_region, customer_type, channel_id
|
|
253
|
+
**维度**:order_id, order_line_id, date_key, order_date, year, month, year_month, quarter, product_id, product_category, customer_id, customer_region, customer_type, channel_id
|
|
222
254
|
|
|
223
255
|
**度量**:
|
|
224
256
|
|
|
@@ -237,92 +269,97 @@ s.tables.add_relationship(
|
|
|
237
269
|
| avg_unit_price | if(quantity>0, sales_amount/quantity, 0) | 平均单价 |
|
|
238
270
|
| avg_order_value | if(order_count>0, sales_amount/order_count, 0) | 客单价 |
|
|
239
271
|
|
|
240
|
-
### 4.2 ProductSalesCube
|
|
272
|
+
### 4.2 ProductSalesCube(Subject · 产品销售)
|
|
241
273
|
|
|
242
274
|
**目的**:Product 对象 bind_source;按产品聚合
|
|
243
275
|
|
|
244
|
-
**维度**:product_id, product_category
|
|
276
|
+
**维度**:product_id, product_category, year, month(来自 dim_date)
|
|
245
277
|
|
|
246
278
|
**度量**:quantity, sales_amount, order_count
|
|
247
279
|
|
|
248
280
|
**派生度量**:avg_unit_price
|
|
249
281
|
|
|
250
|
-
### 4.3 CustomerSalesCube
|
|
282
|
+
### 4.3 CustomerSalesCube(Subject · 客户销售)
|
|
251
283
|
|
|
252
|
-
**维度**:customer_id, customer_region, customer_type
|
|
284
|
+
**维度**:customer_id, customer_region, customer_type, year, month
|
|
253
285
|
|
|
254
286
|
**度量**:quantity, sales_amount, order_count
|
|
255
287
|
|
|
256
288
|
**派生度量**:avg_order_value
|
|
257
289
|
|
|
258
|
-
### 4.4 ChannelSalesCube
|
|
290
|
+
### 4.4 ChannelSalesCube(Subject · 渠道销售)
|
|
259
291
|
|
|
260
|
-
**维度**:channel_id
|
|
292
|
+
**维度**:channel_id, year, month
|
|
261
293
|
|
|
262
294
|
**度量**:quantity, sales_amount, order_count
|
|
263
295
|
|
|
264
|
-
### 4.5 TimeSalesCube(时间维度 Cube)
|
|
265
|
-
|
|
266
|
-
**维度**:order_date, year_month, quarter, year
|
|
267
|
-
|
|
268
|
-
**度量**:sales_amount, quantity, order_count
|
|
269
|
-
|
|
270
296
|
---
|
|
271
297
|
|
|
272
298
|
## 五、本体层设计
|
|
273
299
|
|
|
274
300
|
### 5.1 对象类型(5 种)
|
|
275
301
|
|
|
276
|
-
|
|
|
277
|
-
|
|
|
278
|
-
| Product
|
|
279
|
-
| Customer
|
|
280
|
-
| SalesChannel
|
|
281
|
-
| SalesOrder
|
|
282
|
-
| SalesAnalysis
|
|
302
|
+
| code | 分类 | **347 分类** | 名称 | bind_source | 主物理支撑 |
|
|
303
|
+
| ---- | ---- | ------------ | ---- | ------------- | ---------- |
|
|
304
|
+
| Product | Master | **主数据** | 产品 | ProductSalesCube | dim_product |
|
|
305
|
+
| Customer | Master | **主数据** | 客户 | CustomerSalesCube | dim_customer |
|
|
306
|
+
| SalesChannel | Reference | **参考** | 销售渠道 | ChannelSalesCube | dim_channel |
|
|
307
|
+
| SalesOrder | Transaction | **事务** | 销售订单 | SalesCube | fact_sales_order_line |
|
|
308
|
+
| SalesAnalysis | Analytical | **分析** | 销售分析 | SalesCube | fact_sales_order_line |
|
|
283
309
|
|
|
284
|
-
>
|
|
310
|
+
> 对象 **`code` 无前缀**(Palantir 式业务名);分类写入规划表,不写入 `code`。详见 [命名规范 §5](./本体命名规范_物理表Cube与对象.md#5-本体对象palantir-思想与分类)。
|
|
285
311
|
|
|
286
312
|
### 5.2 对象属性(摘要)
|
|
287
313
|
|
|
288
|
-
#### Product
|
|
314
|
+
#### Product(Master)
|
|
289
315
|
|
|
290
|
-
| 属性 code
|
|
291
|
-
|
|
|
292
|
-
| id
|
|
293
|
-
| category
|
|
294
|
-
| quantity
|
|
295
|
-
| sales_amount
|
|
296
|
-
| order_count
|
|
297
|
-
| avg_unit_price | 平均单价
|
|
316
|
+
| 属性 code | 名称 | semantic_role | qualified_name |
|
|
317
|
+
| --------- | ---- | ------------- | -------------- |
|
|
318
|
+
| id | 产品 ID | dimension | ProductSalesCube.product_id |
|
|
319
|
+
| category | 产品大类 | dimension | ProductSalesCube.product_category |
|
|
320
|
+
| quantity | 累计销量 | measure | ProductSalesCube.quantity |
|
|
321
|
+
| sales_amount | 累计销售额 | measure | ProductSalesCube.sales_amount |
|
|
322
|
+
| order_count | 订单数 | measure | ProductSalesCube.order_count |
|
|
323
|
+
| avg_unit_price | 平均单价 | measure | ProductSalesCube.avg_unit_price |
|
|
298
324
|
|
|
299
|
-
#### SalesOrder
|
|
325
|
+
#### SalesOrder(Transaction)
|
|
300
326
|
|
|
301
|
-
| 属性 code
|
|
302
|
-
|
|
|
303
|
-
| id
|
|
304
|
-
| line_id
|
|
305
|
-
| date
|
|
306
|
-
| quantity
|
|
307
|
-
| sales_amount | 销售金额 | measure
|
|
308
|
-
| unit_price
|
|
327
|
+
| 属性 code | 名称 | semantic_role | qualified_name |
|
|
328
|
+
| --------- | ---- | ------------- | -------------- |
|
|
329
|
+
| id | 订单 ID | dimension | SalesCube.order_id |
|
|
330
|
+
| line_id | 订单行 | dimension | SalesCube.order_line_id |
|
|
331
|
+
| date | 订单日期 | dimension | SalesCube.order_date |
|
|
332
|
+
| quantity | 数量 | measure | SalesCube.quantity |
|
|
333
|
+
| sales_amount | 销售金额 | measure | SalesCube.sales_amount |
|
|
334
|
+
| unit_price | 成交单价 | measure | SalesCube.avg_unit_price |
|
|
309
335
|
|
|
310
336
|
#### Customer / SalesChannel / SalesAnalysis
|
|
311
337
|
|
|
312
|
-
与
|
|
338
|
+
与 `销售示例/setup/sales_ontology_init.py` 中属性映射一致(约 29 个属性);实施时改 `space_id`,**表名按本规划**(脚本示例可能仍为旧表名,迁移中)。
|
|
313
339
|
|
|
314
340
|
### 5.3 链接类型(8 种)
|
|
315
341
|
|
|
316
|
-
| 链接 code | 名称 | from | to | 说明 |
|
|
317
|
-
| ---------------------- | -------------- | ------------- | ------------- | -------------------- |
|
|
318
|
-
| order_contains_product | 订单包含产品 | SalesOrder | Product | 订单行对应产品 |
|
|
319
|
-
| order_belongs_customer | 订单归属客户 | SalesOrder | Customer | 订单归属客户 |
|
|
320
|
-
| order_via_channel | 订单经渠道成交 | SalesOrder | SalesChannel | 订单销售渠道 |
|
|
321
|
-
| product_has_orders | 产品有订单 | Product | SalesOrder | 产品被哪些订单购买 |
|
|
322
|
-
| customer_places_orders | 客户下单 | Customer | SalesOrder | 客户历史订单 |
|
|
323
|
-
| analysis_by_product | 分析归因产品 | SalesAnalysis | Product | 指标按产品切片 |
|
|
324
|
-
| analysis_by_customer | 分析归因客户 | SalesAnalysis | Customer | 指标按客户切片 |
|
|
325
|
-
| analysis_by_channel | 分析归因渠道 | SalesAnalysis | SalesChannel | 指标按渠道切片 |
|
|
342
|
+
| 链接 code | **347 分类** | 名称 | from | to | 说明 |
|
|
343
|
+
| ---------------------- | ------------ | -------------- | ------------- | ------------- | -------------------- |
|
|
344
|
+
| order_contains_product | **归属关系** | 订单包含产品 | SalesOrder | Product | 订单行对应产品 |
|
|
345
|
+
| order_belongs_customer | **归属关系** | 订单归属客户 | SalesOrder | Customer | 订单归属客户 |
|
|
346
|
+
| order_via_channel | **归属关系** | 订单经渠道成交 | SalesOrder | SalesChannel | 订单销售渠道 |
|
|
347
|
+
| product_has_orders | **归属关系** | 产品有订单 | Product | SalesOrder | 产品被哪些订单购买 |
|
|
348
|
+
| customer_places_orders | **归属关系** | 客户下单 | Customer | SalesOrder | 客户历史订单 |
|
|
349
|
+
| analysis_by_product | **分析归因** | 分析归因产品 | SalesAnalysis | Product | 指标按产品切片 |
|
|
350
|
+
| analysis_by_customer | **分析归因** | 分析归因客户 | SalesAnalysis | Customer | 指标按客户切片 |
|
|
351
|
+
| analysis_by_channel | **分析归因** | 分析归因渠道 | SalesAnalysis | SalesChannel | 指标按渠道切片 |
|
|
352
|
+
|
|
353
|
+
### 5.4 三层对照总表
|
|
354
|
+
|
|
355
|
+
| 对象 code | 分类 | Cube | 主 fact / dim |
|
|
356
|
+
| --------- | ---- | ---- | ------------- |
|
|
357
|
+
| Product | Master | ProductSalesCube | dim_product |
|
|
358
|
+
| Customer | Master | CustomerSalesCube | dim_customer |
|
|
359
|
+
| SalesChannel | Reference | ChannelSalesCube | dim_channel |
|
|
360
|
+
| SalesOrder | Transaction | SalesCube | fact_sales_order_line |
|
|
361
|
+
| SalesAnalysis | Analytical | SalesCube | fact_sales_order_line |
|
|
362
|
+
| (时间) | — | SalesCube 时间维 | dim_date |
|
|
326
363
|
|
|
327
364
|
---
|
|
328
365
|
|
|
@@ -330,15 +367,15 @@ s.tables.add_relationship(
|
|
|
330
367
|
|
|
331
368
|
### 6.1 函数清单
|
|
332
369
|
|
|
333
|
-
| 函数 ID | 功能 | 参数 |
|
|
334
|
-
| --------------------------------- | ------------ | ------------------------------------------------- |
|
|
335
|
-
| sales.fn.get_summary | 销售总览 | start_date, end_date(可选) |
|
|
336
|
-
| sales.fn.yoy_analysis | 同比分析 | start_date, end_date |
|
|
337
|
-
| sales.fn.mom_analysis | 环比分析 | start_date, end_date |
|
|
338
|
-
| sales.fn.top_products | 产品排行 | limit, metric, start_date, end_date |
|
|
339
|
-
| sales.fn.customer_segmentation | 客户分层 | metric, method, start_date, end_date |
|
|
340
|
-
| sales.fn.region_breakdown | 区域销售分布 | start_date, end_date |
|
|
341
|
-
| sales.fn.channel_mix | 渠道结构 | start_date, end_date |
|
|
370
|
+
| 函数 ID | **347 分类** | 功能 | 参数 |
|
|
371
|
+
| --------------------------------- | ------------ | ------------ | ------------------------------------------------- |
|
|
372
|
+
| sales.fn.get_summary | **总览分析** | 销售总览 | start_date, end_date(可选) |
|
|
373
|
+
| sales.fn.yoy_analysis | **趋势分析** | 同比分析 | start_date, end_date |
|
|
374
|
+
| sales.fn.mom_analysis | **趋势分析** | 环比分析 | start_date, end_date |
|
|
375
|
+
| sales.fn.top_products | **结构分析** | 产品排行 | limit, metric, start_date, end_date |
|
|
376
|
+
| sales.fn.customer_segmentation | **结构分析** | 客户分层 | metric, method, start_date, end_date |
|
|
377
|
+
| sales.fn.region_breakdown | **组织分析** | 区域销售分布 | start_date, end_date |
|
|
378
|
+
| sales.fn.channel_mix | **结构分析** | 渠道结构 | start_date, end_date |
|
|
342
379
|
|
|
343
380
|
### 6.2 函数示例:sales.fn.get_summary
|
|
344
381
|
|
|
@@ -356,13 +393,13 @@ s.tables.add_relationship(
|
|
|
356
393
|
|
|
357
394
|
### 6.3 函数示例:sales.fn.top_products
|
|
358
395
|
|
|
359
|
-
**功能**:按销售额或销量 Top N;JOIN
|
|
396
|
+
**功能**:按销售额或销量 Top N;JOIN **`dim_product`** 补全 product_name
|
|
360
397
|
|
|
361
398
|
**参数**:limit(默认 10), metric(sales_amount / quantity), start_date, end_date
|
|
362
399
|
|
|
363
400
|
**返回值**:rank, product_id, product_name, product_category, sales_amount, quantity, share_pct
|
|
364
401
|
|
|
365
|
-
>
|
|
402
|
+
> 参考实现:`资源/examples/onto/销售示例/functions/sales_fn_*.py`(复制到 `<item-path>/functions/`)。
|
|
366
403
|
|
|
367
404
|
### 6.4 测试参数(test_arguments)
|
|
368
405
|
|
|
@@ -381,7 +418,7 @@ s.tables.add_relationship(
|
|
|
381
418
|
批量入库(dazi-work 根):
|
|
382
419
|
|
|
383
420
|
```powershell
|
|
384
|
-
|
|
421
|
+
.\<item-path>\functions\save_test_arguments.ps1
|
|
385
422
|
```
|
|
386
423
|
|
|
387
424
|
JSON 格式须含 `v`、`arguments`、`object_type_code`(与平台函数定义一致);各 `.py` 内 `TEST_ARGUMENTS` 常量与 JSON **保持同步**。
|
|
@@ -390,27 +427,27 @@ JSON 格式须含 `v`、`arguments`、`object_type_code`(与平台函数定义
|
|
|
390
427
|
|
|
391
428
|
## 七、实施计划
|
|
392
429
|
|
|
393
|
-
> **dazi-vscode v3** · 空间
|
|
430
|
+
> **dazi-vscode v3** · 空间 `<space-id>` · 脚本目录 `setup/`、`functions/`
|
|
394
431
|
> 发布示例:
|
|
395
|
-
> `dazi onto script publish
|
|
432
|
+
> `dazi onto script publish <item-path>/setup/sales_ontology_init.py --space <space-id> --type setup`
|
|
396
433
|
|
|
397
434
|
### 7.1 阶段一:物理层(高)
|
|
398
435
|
|
|
399
|
-
| 步骤 | 任务
|
|
400
|
-
| ---- |
|
|
401
|
-
| 1
|
|
402
|
-
| 2
|
|
403
|
-
| 3
|
|
404
|
-
| 4
|
|
405
|
-
| 5
|
|
406
|
-
| 6
|
|
436
|
+
| 步骤 | 任务 | 说明 |
|
|
437
|
+
| ---- | ---- | ---- |
|
|
438
|
+
| 1 | 创建 **dim_date** | 时间维(强制) |
|
|
439
|
+
| 2 | 创建 dim_product | 产品维表 |
|
|
440
|
+
| 3 | 创建 **fact_sales_order_line** | 含 **date_key** |
|
|
441
|
+
| 4 | 创建 dim_customer、dim_channel | 业务维表 |
|
|
442
|
+
| 5 | 注册表到空间 | **TABLE_REGISTRY** + `register_with_meta` |
|
|
443
|
+
| 6 | **注册表间关系(4 条)** | 含 fact → dim_date |
|
|
407
444
|
|
|
408
445
|
### 7.2 阶段二:Cube 层(高)
|
|
409
446
|
|
|
410
|
-
| 步骤 | 任务
|
|
411
|
-
| ---- |
|
|
412
|
-
| 7
|
|
413
|
-
| 8
|
|
447
|
+
| 步骤 | 任务 |
|
|
448
|
+
| ---- | ---- |
|
|
449
|
+
| 7 | 注册 SalesCube / ProductSalesCube 等 **4 个 Cube**(无独立 Time Cube) |
|
|
450
|
+
| 8 | 配置派生度量;SalesCube 含 dim_date 时间维 |
|
|
414
451
|
|
|
415
452
|
### 7.3 阶段三:本体层(高)
|
|
416
453
|
|
|
@@ -421,23 +458,24 @@ JSON 格式须含 `v`、`arguments`、`object_type_code`(与平台函数定义
|
|
|
421
458
|
| 11 | define_property(约 29 个) |
|
|
422
459
|
| 12 | define_link_type(8 种) |
|
|
423
460
|
| 13 | sync_metric_refs |
|
|
461
|
+
| 14 | **CATEGORY_REGISTRY** + `s.categories.apply_registry`(347 对齐) |
|
|
424
462
|
|
|
425
463
|
### 7.4 阶段四:函数与数据(中)
|
|
426
464
|
|
|
427
465
|
| 步骤 | 任务 |
|
|
428
466
|
| ---- | -------------------------------------------------------------------- |
|
|
429
|
-
| 14 | 从
|
|
430
|
-
| 15 |
|
|
467
|
+
| 14 | 从 `销售示例/functions/sales_fn_*.py` 复制并适配(SQL 表名按本规划) |
|
|
468
|
+
| 15 | seed 灌数:**dim_date** + 维表 + fact(写入 date_key) |
|
|
431
469
|
| 16 | publish + run 验证 |
|
|
432
470
|
| 17 | **`save-test-arguments`** 写入各函数 `test_arguments`(侧栏预填;见 §6.4) |
|
|
433
471
|
|
|
434
472
|
### 7.5 快速实施路径
|
|
435
473
|
|
|
436
|
-
本仓库
|
|
474
|
+
本仓库 **`资源/examples/onto/销售示例/setup/sales_ontology_init.py`** 含完整 init 逻辑(含 **`TABLE_REGISTRY`** 与 `register_with_meta`),与本文 §2.3、§3.x 对齐:
|
|
437
475
|
|
|
438
|
-
1. 复制 `sales_ontology_init.py`、`sales_seed_data.py` →
|
|
439
|
-
2. 将
|
|
440
|
-
3. 按 [快速启动
|
|
476
|
+
1. 复制 `sales_ontology_init.py`、`sales_seed_data.py` → 实现单元 `setup/`(`dazi examples sync` 或侧栏 **帮助 → 示例**)
|
|
477
|
+
2. 将 init/seed 内 `space_id` 改为 README 中的 `<space-id>`
|
|
478
|
+
3. 按 [快速启动](./本体规划指南.md) 发布执行
|
|
441
479
|
|
|
442
480
|
---
|
|
443
481
|
|
|
@@ -453,16 +491,19 @@ JSON 格式须含 `v`、`arguments`、`object_type_code`(与平台函数定义
|
|
|
453
491
|
|
|
454
492
|
### 8.2 验收标准
|
|
455
493
|
|
|
456
|
-
| 验收项
|
|
457
|
-
|
|
|
458
|
-
|
|
|
459
|
-
|
|
|
460
|
-
|
|
|
461
|
-
|
|
|
462
|
-
|
|
|
463
|
-
|
|
|
464
|
-
|
|
|
465
|
-
|
|
|
494
|
+
| 验收项 | 标准 |
|
|
495
|
+
| ------ | ---- |
|
|
496
|
+
| dim_date | 可查询,**date_key** 连续覆盖 seed 日期范围 |
|
|
497
|
+
| fact_sales_order_line | 可查询,**date_key** 与 dim_date 可 JOIN |
|
|
498
|
+
| 维表 | dim_product / dim_customer / dim_channel 完整 |
|
|
499
|
+
| 表/列元数据 | 侧栏与表预览显示名、说明与 §3.x 一致 |
|
|
500
|
+
| **表间关系** | **4 条**(含 fact → dim_date) |
|
|
501
|
+
| Cube | **4 个** Cube;SalesCube 含时间维 |
|
|
502
|
+
| 对象类型 | 5 种 + 分类列;8 种链接 |
|
|
503
|
+
| **347 平台分类** | 侧栏分类名与附录 B 一致;init 重跑幂等 |
|
|
504
|
+
| 函数 | get_summary、top_products 可运行 |
|
|
505
|
+
| test_arguments | 各 function_id 已 save-test-arguments |
|
|
506
|
+
| 数据 | 种子灌入后指标与手工 SQL 一致 |
|
|
466
507
|
|
|
467
508
|
---
|
|
468
509
|
|
|
@@ -478,20 +519,102 @@ JSON 格式须含 `v`、`arguments`、`object_type_code`(与平台函数定义
|
|
|
478
519
|
|
|
479
520
|
---
|
|
480
521
|
|
|
522
|
+
## 附录 B:347 分类挂载对照表(CATEGORY_REGISTRY)
|
|
523
|
+
|
|
524
|
+
与 `销售示例/setup/sales_ontology_init.py` 顶部 **`CATEGORY_REGISTRY`** 一一对应;平台 `category_name` **=** 347 标准中文名(见 [349 方案](./本体分类规划与SDK扩展方案.md))。
|
|
525
|
+
|
|
526
|
+
### B.1 物理表(table)
|
|
527
|
+
|
|
528
|
+
| 347 分类 | 表名 |
|
|
529
|
+
| -------- | ---- |
|
|
530
|
+
| 时间维 | dim_date |
|
|
531
|
+
| 维度表 | dim_product, dim_customer, dim_channel |
|
|
532
|
+
| 事实表 | fact_sales_order_line |
|
|
533
|
+
|
|
534
|
+
### B.2 Cube(cube)
|
|
535
|
+
|
|
536
|
+
| 347 分类 | Cube |
|
|
537
|
+
| -------- | ---- |
|
|
538
|
+
| 流程型 | SalesCube |
|
|
539
|
+
| 主体型 | ProductSalesCube, CustomerSalesCube, ChannelSalesCube |
|
|
540
|
+
|
|
541
|
+
### B.3 对象类型(object)
|
|
542
|
+
|
|
543
|
+
| 347 分类 | code |
|
|
544
|
+
| -------- | ---- |
|
|
545
|
+
| 主数据 | Product, Customer |
|
|
546
|
+
| 参考 | SalesChannel |
|
|
547
|
+
| 事务 | SalesOrder |
|
|
548
|
+
| 分析 | SalesAnalysis |
|
|
549
|
+
|
|
550
|
+
### B.4 表间关系(relation)
|
|
551
|
+
|
|
552
|
+
| 347 分类 | 从表 → 到表 |
|
|
553
|
+
| -------- | ----------- |
|
|
554
|
+
| 时间关联 | fact_sales_order_line → dim_date |
|
|
555
|
+
| 主数据关联 | fact_sales_order_line → dim_product / dim_customer / dim_channel |
|
|
556
|
+
|
|
557
|
+
### B.5 链接类型(link)
|
|
558
|
+
|
|
559
|
+
| 347 分类 | link code |
|
|
560
|
+
| -------- | --------- |
|
|
561
|
+
| 归属关系 | order_contains_product, order_belongs_customer, order_via_channel, product_has_orders, customer_places_orders |
|
|
562
|
+
| 分析归因 | analysis_by_product, analysis_by_customer, analysis_by_channel |
|
|
563
|
+
|
|
564
|
+
### B.6 本体函数(function)
|
|
565
|
+
|
|
566
|
+
init 脚本**不**注册函数;函数发布后单独执行 `apply_registry` 的 `function` 段,或 `skip_missing=True` 跳过。建议分类:
|
|
567
|
+
|
|
568
|
+
| 347 分类 | function_id |
|
|
569
|
+
| -------- | ----------- |
|
|
570
|
+
| 总览分析 | sales.fn.get_summary |
|
|
571
|
+
| 趋势分析 | sales.fn.yoy_analysis, sales.fn.mom_analysis |
|
|
572
|
+
| 结构分析 | sales.fn.top_products, sales.fn.customer_segmentation, sales.fn.channel_mix |
|
|
573
|
+
| 组织分析 | sales.fn.region_breakdown |
|
|
574
|
+
|
|
575
|
+
---
|
|
576
|
+
|
|
577
|
+
## 附录:规划完整性自检清单
|
|
578
|
+
|
|
579
|
+
定稿前逐项勾选(完整说明见 [本体规划指南 · 规划文档完整性自检清单](./本体规划指南.md#规划文档完整性自检清单))。
|
|
580
|
+
|
|
581
|
+
| # | 检查项 | 本方案 |
|
|
582
|
+
| - | ------ | ------ |
|
|
583
|
+
| 1 | 业务场景 | ☑ |
|
|
584
|
+
| 2 | 物理表 | ☑(dim_date + fact + 3 dim) |
|
|
585
|
+
| 2a | dim_date / date_key | ☑(§3.0、§3.2) |
|
|
586
|
+
| 2b | fact 含 date_key | ☑ |
|
|
587
|
+
| 2c | 表前缀规范 | ☑(fact_/dim_) |
|
|
588
|
+
| 3 | 表间关系 | ☑(**4 条**) |
|
|
589
|
+
| 4 | Cube 层 | ☑(**4 个**,§4.0 含类别) |
|
|
590
|
+
| 4a–4b | Cube 类别/命名 | ☑ |
|
|
591
|
+
| 5 | 对象类型 | ☑(5 种 + 分类) |
|
|
592
|
+
| 5a–5c | 对象分类/三层对照 | ☑(§5.1、§5.4) |
|
|
593
|
+
| 6 | bind_source | ☑ |
|
|
594
|
+
| 7 | 链接类型 | ☑(8 种) |
|
|
595
|
+
| 8 | 函数清单 | ☑ |
|
|
596
|
+
| 9 | test_arguments | ☑ |
|
|
597
|
+
| 10 | 实施与验收 | ☑ |
|
|
598
|
+
| 6a–6e | 347 平台分类 | ☑(附录 B + init 步骤 10) |
|
|
599
|
+
|
|
600
|
+
---
|
|
601
|
+
|
|
481
602
|
## 十、相关文档
|
|
482
603
|
|
|
483
604
|
| 文档 | 路径 |
|
|
484
605
|
| ---- | ---- |
|
|
606
|
+
| 本体命名规范 | [本体命名规范_物理表Cube与对象.md](./本体命名规范_物理表Cube与对象.md) |
|
|
485
607
|
| 本体规划指南 | [本体规划指南.md](./本体规划指南.md) |
|
|
486
608
|
| 本体脚本编写指南 | [本体脚本编写指南.md](./本体脚本编写指南.md) |
|
|
487
609
|
| 函数开发 | [function-guide.md](./function-guide.md) |
|
|
488
|
-
| 参考实现(init/seed/函数) |
|
|
610
|
+
| 参考实现(init/seed/函数) | `资源/examples/onto/销售示例/` → 复制到 `<item-path>/` |
|
|
489
611
|
| **内置脚本示例** | `资源/examples/onto/销售示例/`(`dazi examples sync` 后复制到实现单元) |
|
|
490
612
|
| 补充示例(利润) | [规划示例_利润分析本体方案.md](./规划示例_利润分析本体方案.md) · `资源/examples/onto/利润示例/` |
|
|
613
|
+
| 349 · 分类方案 | [本体分类规划与 SDK 扩展方案](./本体分类规划与SDK扩展方案.md) |
|
|
491
614
|
|
|
492
615
|
---
|
|
493
616
|
|
|
494
|
-
**方案版本**:v1.
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
617
|
+
**方案版本**:v1.3(表/Cube/对象命名对齐 [命名规范](./本体命名规范_物理表Cube与对象.md))
|
|
618
|
+
**创建日期**:(定稿日)
|
|
619
|
+
**适用**:复制到 `<item-path>/plans/`;`<space-id>` 以该实现单元 `README.md` 为准
|
|
620
|
+
**状态**:规划示例(公共模板)
|