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