@dazitech/cli 3.0.7 → 3.0.8

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.
Files changed (68) hide show
  1. package/README.md +1 -1
  2. package/dist/clis/dazi-app.js +1 -1
  3. package/dist/clis/dazi-flow.js +1 -1
  4. package/dist/clis/dazi-onto.js +73 -22
  5. package/dist/clis/dazi.js +266 -171
  6. package/dist/docs/flow/flow-project-guide.md +1 -1
  7. package/dist/docs/guides/quickstart.md +18 -4
  8. package/dist/docs/guides/troubleshooting.md +1 -1
  9. package/dist/docs/guides/workspace-v3.md +43 -23
  10. package/dist/docs/index.json +9 -3
  11. package/dist/docs/onto/action-guide.md +3 -3
  12. package/dist/docs/onto/dazi_script_sdk_reference.md +178 -174
  13. package/dist/docs/onto/dazi_script_seed_data_guide.md +158 -155
  14. package/dist/docs/onto/function-guide.md +37 -10
  15. package/dist/docs/onto/space-management.md +3 -1
  16. 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 +138 -34
  17. package/dist/docs/onto//346/234/254/344/275/223/350/247/204/345/210/222/346/214/207/345/215/227.md +73 -31
  18. 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 +497 -0
  19. 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 +597 -541
  20. package/dist/examples/index.json +202 -22
  21. package/dist/examples/onto/README.md +43 -0
  22. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_account_breakdown.py +99 -0
  23. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_budget_vs_actual.py +116 -0
  24. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_cost_center_profit.py +85 -0
  25. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_get_summary.py +76 -0
  26. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_mom_analysis.py +86 -0
  27. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_top_accounts.py +103 -0
  28. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_yoy_analysis.py +86 -0
  29. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/save_test_arguments.ps1 +27 -0
  30. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.account_breakdown.json +10 -0
  31. 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 +10 -0
  32. 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 +9 -0
  33. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.get_summary.json +9 -0
  34. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.mom_analysis.json +9 -0
  35. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.top_accounts.json +11 -0
  36. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/test_arguments/profit.fn.yoy_analysis.json +9 -0
  37. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_ontology_init.py +521 -0
  38. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_seed_data.py +213 -0
  39. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/README.md +25 -0
  40. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_channel_mix.py +86 -0
  41. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_customer_segmentation.py +123 -0
  42. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_get_summary.py +81 -0
  43. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_mom_analysis.py +90 -0
  44. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_region_breakdown.py +85 -0
  45. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_top_products.py +101 -0
  46. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_yoy_analysis.py +90 -0
  47. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/save_test_arguments.ps1 +25 -0
  48. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.channel_mix.json +8 -0
  49. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.customer_segmentation.json +10 -0
  50. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.get_summary.json +8 -0
  51. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.mom_analysis.json +8 -0
  52. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.region_breakdown.json +8 -0
  53. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.top_products.json +10 -0
  54. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/test_arguments/sales.fn.yoy_analysis.json +8 -0
  55. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/README.md +5 -0
  56. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_ontology_init.py +403 -0
  57. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_seed_data.py +124 -0
  58. package/dist/prompts/index.json +2 -2
  59. package/dist/prompts/onto/action-design.md +4 -1
  60. package/dist/prompts/onto/function-design.md +9 -2
  61. package/dist/prompts/onto/rule-seed.md +5 -1
  62. package/dist/prompts/onto/script-publish-run.md +72 -24
  63. package/package.json +1 -1
  64. package/dist/examples/onto/function/profit_fn_customer_segmentation.py +0 -117
  65. package/dist/examples/onto/function/profit_fn_mom_analysis.py +0 -89
  66. package/dist/examples/onto/function/profit_fn_top_products.py +0 -89
  67. package/dist/examples/onto/function/profit_fn_yoy_analysis.py +0 -89
  68. package/dist/examples/onto/setup/profit_ontology_init.py +0 -388
@@ -0,0 +1,497 @@
1
+ # 规划示例 · 产品销售本体方案
2
+
3
+ **文档 ID**: `onto/planning-example-product-sales`
4
+
5
+ > **推荐**:本体规划阶段**首选参考示例**。覆盖物理表、**表间关系**、Cube、本体链接、函数与 **test_arguments** 完整落地;对应可运行脚本见 `项目/潘达石化/本体/ontos/产品销售本体方案/`。
6
+ > 补充示例(利润分析域):[规划示例_利润分析本体方案.md](./规划示例_利润分析本体方案.md)
7
+
8
+ ---
9
+
10
+ ## 一、空间概述
11
+
12
+ | 项目 | 说明 |
13
+ | -------- | ------------------------------------------ |
14
+ | 空间 ID | `space__zlj` |
15
+ | 空间名称 | 数据空间zlj |
16
+ | 空间状态 | 空白空间(无表、无 Cube、无本体) |
17
+ | 规划日期 | 2026-06-05 |
18
+ | 实现单元 | `项目/潘达石化/本体/ontos/产品销售本体方案/` |
19
+
20
+ ---
21
+
22
+ ## 二、需求分析
23
+
24
+ ### 2.1 业务背景
25
+
26
+ 潘达石化产品销售场景,需构建**产品销售本体**,以业务语言描述「产品」「销售订单」及其关系,支撑:
27
+
28
+ - 按产品大类、SKU 的销售量与销售额分析
29
+ - 按区域、客户类型、渠道的销售分布
30
+ - 同比、环比趋势与 Top N 产品排行
31
+ - 客户分层与渠道结构分析
32
+
33
+ ### 2.2 核心业务问题
34
+
35
+ | 问题 | 说明 |
36
+ | -------------- | ---------------------------- |
37
+ | 卖了多少 | 销量、销售额、订单数 |
38
+ | 哪些产品卖得好 | 产品排行、品类结构、动销 SKU |
39
+ | 谁在买 | 客户/区域贡献、客户分层 |
40
+ | 通过什么渠道卖 | 直销/经销/电商等渠道占比 |
41
+ | 趋势如何 | 同比、环比、季节性 |
42
+
43
+ ### 2.3 规划范围说明
44
+
45
+ **核心物理表(本方案重点)**:
46
+
47
+ | 表名 | 中文名 | 角色 |
48
+ | ------------------ | ------------ | ---------------------------- |
49
+ | `product_master` | **产品表** | 产品主数据(维表) |
50
+ | `sales_order_fact` | **销售表** | 销售订单/订单行事实(事实表)|
51
+
52
+ **辅助维表(支撑销售表外键语义,建议同期建设)**:
53
+
54
+ | 表名 | 中文名 | 角色 |
55
+ | -------------------- | ---------- | ------------------ |
56
+ | `customer_dimension` | 客户维表 | 购买方主数据 |
57
+ | `channel_dimension` | 渠道维表 | 销售渠道主数据 |
58
+
59
+ > 规划原则:先定义**业务对象**(Product、SalesOrder 等)与**链接**,再反推物理表;产品表与销售表是读模型的根基,维表避免销售表中出现无法解释的裸 ID。
60
+
61
+ ---
62
+
63
+ ## 三、物理层设计
64
+
65
+ ### 3.1 产品表:product_master
66
+
67
+ **用途**:存储可售产品(油品、化工品等)主数据,供销售表关联与产品分析。
68
+
69
+ **表结构**:
70
+
71
+ | 字段名 | 类型 | 说明 | 主键/索引 |
72
+ | -------------------- | -------- | -------------- | --------- |
73
+ | product_id | String | 产品 ID | PK |
74
+ | product_code | String | 产品编码 | |
75
+ | product_name | String | 产品名称 | |
76
+ | product_category | String | 产品大类 | |
77
+ | product_subcategory | String | 产品小类 | |
78
+ | brand | String | 品牌/牌号 | |
79
+ | unit | String | 计量单位(吨等)| |
80
+ | list_price | Float64 | 挂牌价 | |
81
+ | cost_price | Float64 | 成本单价 | |
82
+ | status | String | 状态(在售/停售)| |
83
+ | created_at | DateTime | 创建时间 | |
84
+ | updated_at | DateTime | 更新时间 | |
85
+
86
+ **排序键**:`ORDER BY (product_id)`
87
+ **引擎**:`MergeTree()`
88
+
89
+ ### 3.2 销售表:sales_order_fact
90
+
91
+ **用途**:存储订单行粒度销售流水,是 Cube 与 SalesOrder 对象的主要事实来源。
92
+
93
+ **表结构**:
94
+
95
+ | 字段名 | 类型 | 说明 | 主键/索引 |
96
+ | ---------------- | ------- | ---------------------------- | --------- |
97
+ | order_id | String | 订单 ID | |
98
+ | order_line_id | String | 订单行 ID | PK 组合 |
99
+ | order_date | Date | 订单日期 | |
100
+ | product_id | String | 产品 ID → product_master | FK 语义 |
101
+ | product_category | String | 产品大类(冗余,便于聚合) | |
102
+ | customer_id | String | 客户 ID | |
103
+ | customer_region | String | 销售区域 | |
104
+ | customer_type | String | 客户类型(战略/VIP/普通) | |
105
+ | channel_id | String | 渠道 ID | |
106
+ | quantity | Int32 | 销售数量 | |
107
+ | unit_price | Float64 | 成交单价 | |
108
+ | discount_amount | Float64 | 折扣金额 | |
109
+ | sales_amount | Float64 | 销售金额(扣折后) | |
110
+ | currency | String | 币种 | |
111
+ | order_status | String | 订单状态(已完成/已发货等) | |
112
+
113
+ **排序键**:`ORDER BY (order_date, order_id, order_line_id)`
114
+ **引擎**:`MergeTree()`
115
+
116
+ **业务规则**:
117
+
118
+ - 分析类函数默认过滤 `order_status IN ('已完成', '已发货')`
119
+ - `sales_amount` 为行级实收,与 `quantity * unit_price - discount_amount` 口径一致
120
+
121
+ ### 3.3 辅助维表(建议同期创建)
122
+
123
+ #### customer_dimension(客户维表)
124
+
125
+ | 字段名 | 类型 | 说明 |
126
+ | --------------- | -------- | -------- |
127
+ | customer_id | String | 客户 ID |
128
+ | customer_code | String | 客户编码 |
129
+ | customer_name | String | 客户名称 |
130
+ | customer_region | String | 销售区域 |
131
+ | customer_type | String | 客户类型 |
132
+ | industry | String | 所属行业 |
133
+ | created_at | DateTime | 创建时间 |
134
+
135
+ #### channel_dimension(渠道维表)
136
+
137
+ | 字段名 | 类型 | 说明 |
138
+ | ------------ | ------ | -------- |
139
+ | channel_id | String | 渠道 ID |
140
+ | channel_code | String | 渠道编码 |
141
+ | channel_name | String | 渠道名称 |
142
+ | channel_type | String | 渠道类型 |
143
+
144
+ ### 3.4 表间关系设计(物理层 · 数据空间)
145
+
146
+ > **与本体链接的区别**:本节描述 **ClickHouse 物理表之间的 FK/JOIN 关系**,写入数据空间 `ads_dataspace_relationships`,供侧栏 **数据资源 → 表间关系** 展示,并支撑流程节点多表 JOIN、AI 读空间上下文。
147
+ > **本体层链接**(第五节 `define_link_type`)描述业务对象语义,二者应 **一一对应、分层不混用**。
148
+
149
+ **关系模型(星型)**:以 **销售表** `sales_order_fact` 为事实表,关联三张维表。
150
+
151
+ ```text
152
+ product_master
153
+ (product_id PK)
154
+
155
+ │ many_to_one
156
+
157
+ customer_dimension ◄──────┼──────► channel_dimension
158
+ (customer_id PK) │ (channel_id PK)
159
+ ▲ │
160
+ │ many_to_one │
161
+ │ │
162
+ └──── sales_order_fact ────┘
163
+ (order_line 粒度)
164
+ ```
165
+
166
+ **关系清单(3 条)**:
167
+
168
+ | 关系 ID(建议) | 类型 | 从表(事实) | 到表(维表) | join_keys | 说明 |
169
+ | ------------------- | ----------- | ------------------ | -------------------- | -------------------------------------- | -------------------- |
170
+ | rel_sales_product | many_to_one | sales_order_fact | product_master | product_id → product_id | 订单行关联产品 |
171
+ | rel_sales_customer | many_to_one | sales_order_fact | customer_dimension | customer_id → customer_id | 订单行关联客户 |
172
+ | rel_sales_channel | many_to_one | sales_order_fact | channel_dimension | channel_id → channel_id | 订单行关联销售渠道 |
173
+
174
+ **join_sql 示例**(init 脚本中 `s.tables.add_relationship` 使用):
175
+
176
+ | 关系 | join_sql |
177
+ | ------------------ | --------------------------------------------------------------------- |
178
+ | rel_sales_product | `sales_order_fact.product_id = product_master.product_id` |
179
+ | rel_sales_customer | `sales_order_fact.customer_id = customer_dimension.customer_id` |
180
+ | rel_sales_channel | `sales_order_fact.channel_id = channel_dimension.channel_id` |
181
+
182
+ **实施 API**(`setup/sales_ontology_init.py`,表注册之后、Cube 注册之前):
183
+
184
+ ```python
185
+ s.tables.add_relationship(
186
+ from_table="sales_order_fact",
187
+ to_table="product_master",
188
+ join_sql="sales_order_fact.product_id = product_master.product_id",
189
+ join_keys=[{"from": "product_id", "to": "product_id"}],
190
+ relationship_type="many_to_one",
191
+ description="销售订单行关联产品主数据",
192
+ )
193
+ ```
194
+
195
+ **不建关系的字段说明**:
196
+
197
+ | 字段 | 原因 |
198
+ | ------------------ | ------------------------------------------ |
199
+ | product_category | 事实表冗余列,非独立维表 FK |
200
+ | customer_region | 事实表冗余列,与 customer_dimension 重复 |
201
+ | customer_type | 事实表冗余列,与 customer_dimension 重复 |
202
+
203
+ **与本体链接对照**:
204
+
205
+ | 物理表关系 | 对应本体链接(业务层) |
206
+ | -------------------- | ------------------------ |
207
+ | rel_sales_product | order_contains_product |
208
+ | rel_sales_customer | order_belongs_customer |
209
+ | rel_sales_channel | order_via_channel |
210
+
211
+ ---
212
+
213
+ ## 四、Cube 层设计
214
+
215
+ 所有 Cube 均以 **销售表** `sales_order_fact` 为事实源;产品表通过 JOIN 或维度冗余参与产品名称等展示(函数层 SQL 可 LEFT JOIN `product_master`)。
216
+
217
+ ### 4.1 SalesCube(销售分析主 Cube)
218
+
219
+ **目的**:全局销售分析、SalesOrder / SalesAnalysis 读模型
220
+
221
+ **维度**:order_id, order_line_id, order_date, product_id, product_category, customer_id, customer_region, customer_type, channel_id
222
+
223
+ **度量**:
224
+
225
+ | 度量名 | 列名 | 聚合 | 说明 |
226
+ | ----------- | ---------------- | ----- | -------- |
227
+ | quantity | quantity | sum | 销售数量 |
228
+ | sales_amount| sales_amount | sum | 销售金额 |
229
+ | discount | discount_amount | sum | 折扣金额 |
230
+ | order_count | order_id | uniq | 订单数 |
231
+ | line_count | order_line_id | uniq | 订单行数 |
232
+
233
+ **派生度量**:
234
+
235
+ | 度量名 | 表达式 | 说明 |
236
+ | --------------- | --------------------------------------------------- | -------- |
237
+ | avg_unit_price | if(quantity>0, sales_amount/quantity, 0) | 平均单价 |
238
+ | avg_order_value | if(order_count>0, sales_amount/order_count, 0) | 客单价 |
239
+
240
+ ### 4.2 ProductSalesCube(产品销售 Cube)
241
+
242
+ **目的**:Product 对象 bind_source;按产品聚合
243
+
244
+ **维度**:product_id, product_category
245
+
246
+ **度量**:quantity, sales_amount, order_count
247
+
248
+ **派生度量**:avg_unit_price
249
+
250
+ ### 4.3 CustomerSalesCube(客户销售 Cube)
251
+
252
+ **维度**:customer_id, customer_region, customer_type
253
+
254
+ **度量**:quantity, sales_amount, order_count
255
+
256
+ **派生度量**:avg_order_value
257
+
258
+ ### 4.4 ChannelSalesCube(渠道销售 Cube)
259
+
260
+ **维度**:channel_id
261
+
262
+ **度量**:quantity, sales_amount, order_count
263
+
264
+ ### 4.5 TimeSalesCube(时间维度 Cube)
265
+
266
+ **维度**:order_date, year_month, quarter, year
267
+
268
+ **度量**:sales_amount, quantity, order_count
269
+
270
+ ---
271
+
272
+ ## 五、本体层设计
273
+
274
+ ### 5.1 对象类型(5 种)
275
+
276
+ | 对象类型 code | 名称 | 说明 | bind_source |
277
+ | -------------- | -------- | ------------------------ | ----------------- |
278
+ | Product | 产品 | 可售产品业务对象 | ProductSalesCube |
279
+ | Customer | 客户 | 购买方业务对象 | CustomerSalesCube |
280
+ | SalesChannel | 销售渠道 | 渠道业务对象 | ChannelSalesCube |
281
+ | SalesOrder | 销售订单 | 订单/订单行业务对象 | SalesCube |
282
+ | SalesAnalysis | 销售分析 | 多维度销售指标聚合对象 | SalesCube |
283
+
284
+ > 对象类型 `code` 使用稳定英文标识,与表名、Cube 名刻意区分。
285
+
286
+ ### 5.2 对象属性(摘要)
287
+
288
+ #### Product(产品)— 读模型来自 ProductSalesCube + 产品表补全名称(函数层)
289
+
290
+ | 属性 code | 名称 | semantic_role | qualified_name |
291
+ | -------------- | ---------- | ------------- | --------------------------------- |
292
+ | id | 产品 ID | dimension | ProductSalesCube.product_id |
293
+ | category | 产品大类 | dimension | ProductSalesCube.product_category |
294
+ | quantity | 累计销量 | measure | ProductSalesCube.quantity |
295
+ | sales_amount | 累计销售额 | measure | ProductSalesCube.sales_amount |
296
+ | order_count | 订单数 | measure | ProductSalesCube.order_count |
297
+ | avg_unit_price | 平均单价 | measure | ProductSalesCube.avg_unit_price |
298
+
299
+ #### SalesOrder(销售订单)
300
+
301
+ | 属性 code | 名称 | semantic_role | qualified_name |
302
+ | ------------ | -------- | ------------- | ------------------------ |
303
+ | id | 订单 ID | dimension | SalesCube.order_id |
304
+ | line_id | 订单行 | dimension | SalesCube.order_line_id |
305
+ | date | 订单日期 | dimension | SalesCube.order_date |
306
+ | quantity | 数量 | measure | SalesCube.quantity |
307
+ | sales_amount | 销售金额 | measure | SalesCube.sales_amount |
308
+ | unit_price | 成交单价 | measure | SalesCube.avg_unit_price |
309
+
310
+ #### Customer / SalesChannel / SalesAnalysis
311
+
312
+ 与 `本体01/setup/sales_ontology_init.py` 中属性映射一致(共约 29 个属性),实施时可复用该脚本结构,仅将 `space_id` 改为 `space__zlj`。
313
+
314
+ ### 5.3 链接类型(8 种)
315
+
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 | 指标按渠道切片 |
326
+
327
+ ---
328
+
329
+ ## 六、本体函数设计
330
+
331
+ ### 6.1 函数清单
332
+
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 |
342
+
343
+ ### 6.2 函数示例:sales.fn.get_summary
344
+
345
+ **功能**:指定时间范围内销售总览
346
+
347
+ **返回值**:
348
+
349
+ | 字段名 | 类型 | 说明 |
350
+ | --------------- | ------- | ------------ |
351
+ | total_sales | Float64 | 总销售额 |
352
+ | total_quantity | Int | 总销量 |
353
+ | order_count | Int | 订单数 |
354
+ | avg_order_value | Float64 | 客单价 |
355
+ | product_count | Int | 动销 SKU 数 |
356
+
357
+ ### 6.3 函数示例:sales.fn.top_products
358
+
359
+ **功能**:按销售额或销量 Top N;JOIN **产品表** 补全 product_name
360
+
361
+ **参数**:limit(默认 10), metric(sales_amount / quantity), start_date, end_date
362
+
363
+ **返回值**:rank, product_id, product_name, product_category, sales_amount, quantity, share_pct
364
+
365
+ > 参考实现:`项目/潘达石化/本体/ontos/产品销售本体方案/functions/sales_fn_*.py`。
366
+
367
+ ### 6.4 测试参数(test_arguments)
368
+
369
+ 发布并验证函数后,**必须**将默认测试入参写入函数定义,供侧栏 **Onto → 运行函数** 预填。
370
+
371
+ | 函数 ID | test_arguments 文件 | 默认 arguments |
372
+ | ------- | --------------------- | -------------- |
373
+ | sales.fn.get_summary | `functions/test_arguments/sales.fn.get_summary.json` | start_date, end_date |
374
+ | sales.fn.yoy_analysis | `.../sales.fn.yoy_analysis.json` | 同上 |
375
+ | sales.fn.mom_analysis | `.../sales.fn.mom_analysis.json` | 同上 |
376
+ | sales.fn.top_products | `.../sales.fn.top_products.json` | limit=5, metric=sales_amount, 日期 |
377
+ | sales.fn.customer_segmentation | `.../sales.fn.customer_segmentation.json` | metric, method=quartile, 日期 |
378
+ | sales.fn.region_breakdown | `.../sales.fn.region_breakdown.json` | 日期 |
379
+ | sales.fn.channel_mix | `.../sales.fn.channel_mix.json` | 日期 |
380
+
381
+ 批量入库(dazi-work 根):
382
+
383
+ ```powershell
384
+ .\项目\潘达石化\本体\ontos\产品销售本体方案\functions\save_test_arguments.ps1
385
+ ```
386
+
387
+ JSON 格式须含 `v`、`arguments`、`object_type_code`(与平台函数定义一致);各 `.py` 内 `TEST_ARGUMENTS` 常量与 JSON **保持同步**。
388
+
389
+ ---
390
+
391
+ ## 七、实施计划
392
+
393
+ > **dazi-vscode v3** · 空间 `space__zlj` · 脚本目录 `setup/`、`functions/`
394
+ > 发布示例:
395
+ > `dazi onto script publish 项目/潘达石化/本体/ontos/产品销售本体方案/setup/sales_ontology_init.py --space space__zlj --type setup`
396
+
397
+ ### 7.1 阶段一:物理层(高)
398
+
399
+ | 步骤 | 任务 | 说明 |
400
+ | ---- | ----------------------- | ----------------------------- |
401
+ | 1 | 创建 product_master | **产品表** |
402
+ | 2 | 创建 sales_order_fact | **销售表** |
403
+ | 3 | 创建 customer_dimension | 客户维表 |
404
+ | 4 | 创建 channel_dimension | 渠道维表 |
405
+ | 5 | 注册表到空间 | `s.tables.register` + sync |
406
+ | 6 | **注册表间关系(3 条)**| `s.tables.add_relationship` |
407
+
408
+ ### 7.2 阶段二:Cube 层(高)
409
+
410
+ | 步骤 | 任务 |
411
+ | ---- | ------------------------------------------------- |
412
+ | 7 | 注册 SalesCube / ProductSalesCube 等 5 个 Cube |
413
+ | 8 | 配置派生度量 avg_unit_price、avg_order_value |
414
+
415
+ ### 7.3 阶段三:本体层(高)
416
+
417
+ | 步骤 | 任务 |
418
+ | ---- | ------------------------------------------------------------ |
419
+ | 9 | define_object_type(5 种) |
420
+ | 10 | bind_source |
421
+ | 11 | define_property(约 29 个) |
422
+ | 12 | define_link_type(8 种) |
423
+ | 13 | sync_metric_refs |
424
+
425
+ ### 7.4 阶段四:函数与数据(中)
426
+
427
+ | 步骤 | 任务 |
428
+ | ---- | -------------------------------------------------------------------- |
429
+ | 14 | 从 `本体01/functions/sales_fn_*.py` 复制并适配到本实现 `functions/` |
430
+ | 15 | `sales_seed_data.py` 灌入演示数据(产品表 + 销售表 + 维表) |
431
+ | 16 | publish + run 验证 |
432
+ | 17 | **`save-test-arguments`** 写入各函数 `test_arguments`(侧栏预填;见 §6.4) |
433
+
434
+ ### 7.5 快速实施路径
435
+
436
+ 本仓库 **`本体01/setup/sales_ontology_init.py`** 已包含完整 init 逻辑,建议:
437
+
438
+ 1. 复制 `sales_ontology_init.py`、`sales_seed_data.py` → `产品销售本体方案/setup/`
439
+ 2. 将 `space_id = "space__0519"` 改为 `"space__zlj"`
440
+ 3. 按 [快速启动_产品销售本体方案.md](../快速启动_产品销售本体方案.md) 发布执行
441
+
442
+ ---
443
+
444
+ ## 八、风险与验收
445
+
446
+ ### 8.1 风险
447
+
448
+ | 等级 | 风险 | 缓解措施 |
449
+ | ---- | ------------------ | ---------------------------- |
450
+ | 中 | 空间为空,无现网表 | 按本方案建表或对接 ERP 导数 |
451
+ | 低 | 产品表与销售表口径 | 种子数据脚本统一生成 |
452
+ | 低 | 函数与 Cube 不同步 | init 末尾 `sync_metric_refs` |
453
+
454
+ ### 8.2 验收标准
455
+
456
+ | 验收项 | 标准 |
457
+ | -------- | ----------------------------------------- |
458
+ | 产品表 | product_master 可查询,字段完整 |
459
+ | 销售表 | sales_order_fact 可查询,与产品 ID 可关联 |
460
+ | **表间关系** | **3 条**(事实表 → 产品/客户/渠道维表) |
461
+ | Cube | 5 个 Cube 注册成功,派生度量可算 |
462
+ | 对象类型 | 5 种对象 + 8 种链接定义正确 |
463
+ | 函数 | 至少 get_summary、top_products 可运行 |
464
+ | **test_arguments** | 各 function_id 已 `save-test-arguments`,`function get` 中 **非 null** |
465
+ | 数据 | 种子数据灌入后指标与手工 SQL 一致 |
466
+
467
+ ---
468
+
469
+ ## 九、预期成果
470
+
471
+ | 分析能力 | 说明 |
472
+ | ---------- | ------------------------------ |
473
+ | 产品销售 | SKU/品类销量、销售额、排行 |
474
+ | 客户价值 | 区域分布、客户分层 |
475
+ | 渠道结构 | 各渠道销售占比 |
476
+ | 趋势分析 | 同比、环比 |
477
+ | 业务语义 | 产品—订单—客户—渠道链接可导航 |
478
+
479
+ ---
480
+
481
+ ## 十、相关文档
482
+
483
+ | 文档 | 路径 |
484
+ | ---- | ---- |
485
+ | 本体规划指南 | [本体规划指南.md](./本体规划指南.md) |
486
+ | 本体脚本编写指南 | [本体脚本编写指南.md](./本体脚本编写指南.md) |
487
+ | 函数开发 | [function-guide.md](./function-guide.md) |
488
+ | 参考实现(init/seed/函数) | `项目/潘达石化/本体/ontos/产品销售本体方案/setup/`、`functions/` |
489
+ | **内置脚本示例** | `资源/examples/onto/销售示例/`(`dazi examples sync` 后复制到实现单元) |
490
+ | 补充示例(利润) | [规划示例_利润分析本体方案.md](./规划示例_利润分析本体方案.md) · `资源/examples/onto/利润示例/` |
491
+
492
+ ---
493
+
494
+ **方案版本**:v1.1
495
+ **创建日期**:2026-06-05
496
+ **适用空间**:`space__zlj`
497
+ **状态**:已落地(规划 + 脚本 + test_arguments)