@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.
Files changed (75) 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 +1 -1
  5. package/dist/clis/dazi.js +1 -1
  6. package/dist/docs/flow/flow-project-guide.md +1 -1
  7. package/dist/docs/guides/troubleshooting.md +12 -1
  8. package/dist/docs/index.json +20 -1
  9. package/dist/docs/onto/dazi_script_sdk_reference.md +78 -12
  10. package/dist/docs/onto/function-guide.md +61 -33
  11. 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
  12. 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
  13. 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
  14. 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
  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
  16. 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
  17. 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
  18. package/dist/examples/index.json +23 -17
  19. package/dist/examples/onto/README.md +13 -5
  20. package/dist/examples/onto/_templates/ontology_function_template.py +50 -0
  21. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_account_breakdown.py +62 -0
  22. 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
  23. 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
  24. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_get_summary.py +61 -0
  25. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_mom_analysis.py +82 -0
  26. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_top_accounts.py +61 -0
  27. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_yoy_analysis.py +79 -0
  28. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/save_test_arguments.ps1 +38 -0
  29. 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
  30. 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
  31. 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
  32. 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
  33. 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
  34. 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
  35. 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
  36. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_ontology_init.py +232 -74
  37. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_seed_data.py +16 -13
  38. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_channel_mix.py +19 -16
  39. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_customer_segmentation.py +48 -50
  40. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_get_summary.py +3 -6
  41. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_mom_analysis.py +11 -12
  42. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_region_breakdown.py +6 -7
  43. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_top_products.py +5 -8
  44. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_yoy_analysis.py +3 -6
  45. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/save_test_arguments.ps1 +32 -19
  46. 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
  47. 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
  48. 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
  49. 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
  50. 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
  51. 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
  52. 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
  53. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_ontology_init.py +291 -155
  54. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_seed_data.py +59 -20
  55. package/dist/prompts/index.json +1 -1
  56. package/dist/prompts/onto/function-design.md +42 -22
  57. package/dist/prompts/onto/script-publish-run.md +15 -1
  58. package/package.json +1 -1
  59. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_account_breakdown.py +0 -99
  60. 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
  61. 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
  62. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_get_summary.py +0 -76
  63. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_mom_analysis.py +0 -86
  64. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_top_accounts.py +0 -103
  65. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_yoy_analysis.py +0 -86
  66. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/save_test_arguments.ps1 +0 -27
  67. 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
  68. 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
  69. 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
  70. 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
  71. 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
  72. 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
  73. 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
  74. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/README.md +0 -25
  75. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/README.md +0 -5
@@ -1,19 +1,33 @@
1
- # 利润分析本体规划方案
1
+ # 规划示例 · 利润分析本体方案
2
+
3
+ **文档 ID**: `onto/planning-example-profit`
4
+
5
+ > 表/Cube/对象命名遵循 [本体命名规范](./本体命名规范_物理表Cube与对象.md)。
6
+ > 工程模式参考:[规划示例_产品销售本体规划方案.md](./规划示例_产品销售本体规划方案.md)
7
+
8
+ **占位符**(复制到工作区 `plans/` 后替换为实际值):
9
+
10
+ | 占位符 | 含义 | 权威来源 |
11
+ | ------ | ---- | -------- |
12
+ | `<space-id>` | 数据空间 ID | `项目/<业务名>/本体/ontos/<实现名>/README.md` |
13
+ | `<业务名>` | 业务项目目录名 | 工作区 `项目/` 下文件夹 |
14
+ | `<实现名>` | 本体实现单元名 | 如 `利润分析本体方案` |
15
+ | `<item-path>` | 实现单元根路径 | `项目/<业务名>/本体/ontos/<实现名>` |
2
16
 
3
17
  ---
4
18
 
5
19
  ## 一、空间概述
6
20
 
7
- | 项目 | 说明 |
8
- | -------- | ---------------------------------------------------------------------------- |
9
- | 空间 ID | `space__zlj` |
10
- | 空间名称 | 数据空间zlj |
11
- | 空间状态 | 与「产品销售」「员工培训」等**共用同一数据空间**;利润域表/Cube/对象独立建设 |
12
- | 规划日期 | 2026-06-06 |
13
- | 实现单元 | `项目/潘达石化/本体/ontos/利润分析本体方案/` |
21
+ | 项目 | 说明 |
22
+ | -------- | ---- |
23
+ | 空间 ID | `<space-id>`(示例:`space__acme`) |
24
+ | 空间名称 | `<空间名称>`(与平台数据空间显示名一致) |
25
+ | 空间状态 | 可与销售等其他域**共用**同一 `<space-id>`;利润域表/Cube/对象独立建设 |
26
+ | 规划日期 | (填写定稿日期) |
27
+ | 实现单元 | `<item-path>/` |
14
28
 
15
- > **共存说明**:本空间可能已有 `product_master`、`sales_order_fact`、`training_record` 等表。利润分析域以 **会计科目 + 实际分录 + 预算** 为读模型根基,init 脚本**仅**创建/注册利润域表,不覆盖其他域资产。
16
- > **与销售域关系**:销售收入可通过科目映射(如「6001 主营业务收入」)与实际分录对齐;必要时函数层 LEFT JOIN `sales_order_fact` 做勾稽,但**本体对象不以订单为主锚点**。
29
+ > **共存说明**:本空间可能已有销售域 `dim_product`、`fact_sales_order_line` 等表。利润域 init **仅**创建/注册本域表;若 **`dim_date`** 已存在则 **ensure** 不重复建表。
30
+ > **与销售域关系**:销售收入可通过科目映射与实际分录对齐;勾稽函数可 LEFT JOIN `fact_sales_order_line`,**本体对象不以订单为主锚点**。
17
31
 
18
32
  ---
19
33
 
@@ -21,7 +35,7 @@
21
35
 
22
36
  ### 2.1 业务背景
23
37
 
24
- 潘达石化财务利润分析场景,需构建**利润分析本体**,以业务语言描述「会计科目」「实际分录」「预算」及其关系,支撑:
38
+ 某制造企业(示例)财务利润分析场景,需构建**利润分析本体**,以业务语言描述「会计科目」「实际分录」「预算」及其关系,支撑:
25
39
 
26
40
  - **损益总览**:收入、成本、费用、营业利润、利润率
27
41
  - **科目结构**:按科目层级展开收入/成本/费用构成
@@ -43,155 +57,122 @@
43
57
 
44
58
  ### 2.3 规划范围说明
45
59
 
46
- **核心物理表(本方案重点)**:
47
-
48
- | 表名 | 中文名 | 角色 |
49
- | ---------------------- | -------------- | ------------------------------- |
50
- | `account_master` | **科目表** | 会计科目主数据(维表) |
51
- | `actual_journal_entry` | **实际分录表** | 总账/财务实际记账流水(事实表) |
52
- | `budget_entry` | **预算表** | 预算编制明细(事实表) |
60
+ **物理表清单**(命名见 [命名规范 §2](./本体命名规范_物理表Cube与对象.md#2-物理表类别与前缀)):
53
61
 
54
- **辅助维表**:
62
+ | 表名 | 前缀类别 | **347 分类** | 显示名 | 说明 | 角色 |
63
+ | ---- | -------- | ------------ | ------ | ---- | ---- |
64
+ | **`dim_date`** | 时间维(**强制**) | **时间维** | 日期维表 | 与 sales 域共用;PK **`date_key`** | 时间维 |
65
+ | `dim_account` | dim | **维度表** | 科目维表 | 会计科目主数据 | dim |
66
+ | `dim_cost_center` | dim | **维度表** | 成本中心维表 | 组织/利润中心主数据 | dim |
67
+ | **`fact_gl_journal_entry`** | fact | **事实表** | 总账实际分录 | 凭证行粒度损益流水;含 **date_key** | fact |
68
+ | **`fact_budget_entry`** | fact | **事实表** | 预算明细 | 预算行粒度编制数据;含 **date_key** | fact |
55
69
 
56
- | 表名 | 中文名 | 角色 |
57
- | ----------------------- | ------------ | ------------------------ |
58
- | `cost_center_dimension` | 成本中心维表 | 组织/部门/利润中心主数据 |
59
-
60
- > 规划原则:先定义**业务对象**(Account、JournalEntry、BudgetLine 等)与**链接**,再反推物理表。
61
- > **实际分录**承载「实际发生」;**预算表**承载「计划数」;**科目表**统一语义与损益口径(收入/成本/费用)。
62
- > 旧版示例中的 `profit_analysis_fact`(订单粒度收入/成本)**不作为本方案主模型**;若需订单维度利润,可另建与销售域的映射函数,不替代 GL 分录。
63
-
64
- ---
70
+ > 规划原则:先定义 **Account、JournalEntry、BudgetLine** 等业务对象与链接,再反推 Cube 与物理表。旧版 `profit_analysis_fact`(订单粒度)**不作为主模型**。
71
+ > init 脚本 `资源/examples/onto/利润示例/setup/profit_ontology_init.py` 顶部 **`TABLE_REGISTRY`** 与上表及 §3.x 字段 **显示名/说明** 一一对应,经 `s.tables.register_with_meta` 注册;**`CATEGORY_REGISTRY`** 见 [附录 B](#附录-b347-分类挂载对照表category_registry)。
65
72
 
66
73
  ## 三、物理层设计
67
74
 
68
- ### 3.1 科目表:account_master
69
-
70
- **用途**:存储会计科目主数据,定义损益口径与层级,供实际分录、预算关联及科目树分析。
71
-
72
- **表结构**:
73
-
74
- | 字段名 | 类型 | 说明 | 主键/索引 |
75
- | ----------------- | -------- | ------------------------------------------- | --------- |
76
- | account_id | String | 科目 ID | PK |
77
- | account_code | String | 科目编码(如 6001、6401) | |
78
- | account_name | String | 科目名称 | |
79
- | account_type | String | 科目类型(资产/负债/权益/收入/成本/费用) | |
80
- | pl_category | String | 损益大类(营业收入/营业成本/期间费用/其他) | |
81
- | parent_account_id | String | 上级科目 ID(根节点为空) | FK 语义 |
82
- | account_level | Int32 | 科目层级(1=一级,2=二级…) | |
83
- | is_leaf | Boolean | 是否末级科目 | |
84
- | normal_balance | String | 余额方向(借/贷) | |
85
- | status | String | 状态(启用/停用) | |
86
- | created_at | DateTime | 创建时间 | |
87
-
88
- **排序键**:`ORDER BY (account_code)`
89
- **引擎**:`MergeTree()`
90
-
91
- **业务规则**:
92
-
93
- - 损益分析默认过滤 `account_type IN ('收入','成本','费用')`
94
- - `pl_category` 用于利润表行项目归集;函数层可按一级科目 + `pl_category` 双轨展示
95
- - 收入类科目:`amount_signed` 为正表示增加利润;成本/费用类为负向影响(见 §3.3 符号约定)
96
-
97
- ### 3.2 成本中心维表:cost_center_dimension
98
-
99
- **用途**:组织/部门/利润中心主数据,支撑分录与预算的多维切片。
100
-
101
- | 字段名 | 类型 | 说明 |
102
- | ---------------- | -------- | ----------------- |
103
- | cost_center_id | String | 成本中心 ID(PK) |
104
- | cost_center_code | String | 编码 |
105
- | cost_center_name | String | 名称 |
106
- | department | String | 所属部门 |
107
- | company_code | String | 公司代码 |
108
- | profit_center | String | 利润中心 |
109
- | status | String | 状态 |
110
- | created_at | DateTime | 创建时间 |
111
-
112
- **排序键**:`ORDER BY (cost_center_id)`
113
-
114
- ### 3.3 实际分录表:actual_journal_entry
115
-
116
- **用途**:存储总账凭证行粒度实际发生额,是 ActualCube / JournalEntry 对象的主要事实来源。
117
-
118
- **表结构**:
119
-
120
- | 字段名 | 类型 | 说明 | 主键/索引 |
121
- | ---------------- | -------- | ----------------------------------- | --------- |
122
- | entry_id | String | 凭证 ID | |
123
- | line_id | String | 凭证行 ID | PK 组合 |
124
- | posting_date | Date | 记账日期 | |
125
- | fiscal_year | Int32 | 会计年度 | |
126
- | fiscal_period | Int32 | 会计期间(1–12) | |
127
- | account_id | String | 科目 ID account_master | FK 语义 |
128
- | account_code | String | 科目编码(冗余) | |
129
- | account_name | String | 科目名称(冗余) | |
130
- | account_type | String | 科目类型(冗余) | |
131
- | pl_category | String | 损益大类(冗余) | |
132
- | cost_center_id | String | 成本中心 ID → cost_center_dimension | FK 语义 |
133
- | cost_center_name | String | 成本中心名称(冗余) | |
134
- | department | String | 部门(冗余) | |
135
- | debit_amount | Float64 | 借方金额 | |
136
- | credit_amount | Float64 | 贷方金额 | |
137
- | amount_signed | Float64 | **损益符号金额**(见下) | |
138
- | currency | String | 币种 | |
139
- | voucher_no | String | 凭证号 | |
140
- | source_system | String | 来源系统(GL/ERP) | |
141
- | description | String | 摘要 | |
142
- | created_at | DateTime | 创建时间 | |
143
-
144
- **排序键**:`ORDER BY (posting_date, entry_id, line_id)`
145
- **引擎**:`MergeTree()`
146
-
147
- **损益符号约定 `amount_signed`**(写入 ETL/seed 时统一计算,便于 Cube 聚合):
148
-
149
- | account_type | 计算规则(示例) | 含义 |
150
- | ------------ | ------------------------------ | ----------- |
151
- | 收入 | `credit_amount - debit_amount` | 正=收入增加 |
152
- | 成本 | `debit_amount - credit_amount` | 正=成本发生 |
153
- | 费用 | `debit_amount - credit_amount` | 正=费用发生 |
154
-
155
- **分析口径**:
156
-
157
- - `revenue` = Σ `amount_signed` where `account_type='收入'`
158
- - `cost` = Σ `amount_signed` where `account_type='成本'`
159
- - `expense` = Σ `amount_signed` where `account_type='费用'`
160
- - `operating_profit` = `revenue - cost - expense`
161
-
162
- ### 3.4 预算表:budget_entry
163
-
164
- **用途**:存储预算编制明细(年度/月度预算版本),支撑预算 vs 实际分析。
165
-
166
- **表结构**:
167
-
168
- | 字段名 | 类型 | 说明 | 主键/索引 |
169
- | ---------------- | -------- | --------------------------------------- | --------- |
170
- | budget_id | String | 预算批次 ID | |
171
- | line_id | String | 预算行 ID | PK 组合 |
172
- | budget_version | String | 预算版本(如 2026年度预算) | |
173
- | fiscal_year | Int32 | 预算年度 | |
174
- | fiscal_period | Int32 | 预算期间(1–12,0=全年) | |
175
- | account_id | String | 科目 ID → account_master | FK 语义 |
176
- | account_code | String | 科目编码(冗余) | |
177
- | account_name | String | 科目名称(冗余) | |
178
- | account_type | String | 科目类型(冗余) | |
179
- | pl_category | String | 损益大类(冗余) | |
180
- | cost_center_id | String | 成本中心 ID | FK 语义 |
181
- | cost_center_name | String | 成本中心名称(冗余) | |
182
- | department | String | 部门(冗余) | |
183
- | budget_amount | Float64 | 预算金额(与 `amount_signed` 同向符号) | |
184
- | currency | String | 币种 | |
185
- | status | String | 状态(草稿/已发布) | |
186
- | created_at | DateTime | 创建时间 | |
187
-
188
- **排序键**:`ORDER BY (fiscal_year, fiscal_period, account_id, line_id)`
189
- **引擎**:`MergeTree()`
190
-
191
- **业务规则**:
192
-
193
- - 分析默认 `status = '已发布'`
194
- - 月度预算:`fiscal_period BETWEEN 1 AND 12`;年度汇总:`fiscal_period = 0` 或由函数按月 SUM
75
+ ### 3.0 时间维:dim_date(强制)
76
+
77
+ 与销售域共用;字段定义见 [销售规划示例 §3.0](./规划示例_产品销售本体规划方案.md#30-时间维dim_date强制)。分录 **`date_key = toYYYYMMDD(posting_date)`**;预算行可用 **`toYYYYMMDD(toDate(concat(toString(fiscal_year), '-', lpad(toString(fiscal_period), 2, '0'), '-01')))`** 或 period 末代表日,规划须写清口径。
78
+
79
+ ### 3.1 维度表:dim_account
80
+
81
+ **用途**:会计科目主数据;科目树与损益口径。
82
+
83
+ | 字段名 | 类型 | 显示名 | 说明 |
84
+ | ------ | ---- | ------ | ---- |
85
+ | account_id | String | 科目 ID | 主键 |
86
+ | account_code | String | 科目编码 | |
87
+ | account_name | String | 科目名称 | |
88
+ | account_type | String | 科目类型 | 资产/负债/权益/收入/成本/费用 |
89
+ | pl_category | String | 损益大类 | |
90
+ | parent_account_id | String | 上级科目 | 关联 dim_account |
91
+ | account_level | Int32 | 层级 | |
92
+ | is_leaf | Boolean | 末级 | |
93
+ | normal_balance | String | 余额方向 | 借/贷 |
94
+ | status | String | 状态 | 启用/停用 |
95
+ | created_at | DateTime | 创建时间 | |
96
+
97
+ **排序键**:`ORDER BY (account_code)`
98
+
99
+ ### 3.2 维度表:dim_cost_center
100
+
101
+ | 字段名 | 类型 | 显示名 | 说明 |
102
+ | ------ | ---- | ------ | ---- |
103
+ | cost_center_id | String | 成本中心 ID | 主键 |
104
+ | cost_center_code | String | 编码 | |
105
+ | cost_center_name | String | 名称 | |
106
+ | department | String | 部门 | |
107
+ | company_code | String | 公司代码 | |
108
+ | profit_center | String | 利润中心 | |
109
+ | status | String | 状态 | |
110
+ | created_at | DateTime | 创建时间 | |
111
+
112
+ ### 3.3 事实表:fact_gl_journal_entry
113
+
114
+ **用途**:总账凭证行实际发生额;ActualCube / JournalEntry 主源。
115
+
116
+ | 字段名 | 类型 | 显示名 | 说明 |
117
+ | ------ | ---- | ------ | ---- |
118
+ | entry_id | String | 凭证 ID | |
119
+ | line_id | String | 凭证行 ID | 主键组合 |
120
+ | **date_key** | Int32 | 日期键 | 关联 dim_date,YYYYMMDD |
121
+ | posting_date | Date | 记账日期 | |
122
+ | fiscal_year | Int32 | 会计年度 | |
123
+ | fiscal_period | Int32 | 会计期间 | 1–12 |
124
+ | account_id | String | 科目 ID | 关联 dim_account |
125
+ | account_code | String | 科目编码 | 冗余 |
126
+ | account_name | String | 科目名称 | 冗余 |
127
+ | account_type | String | 科目类型 | 冗余 |
128
+ | pl_category | String | 损益大类 | 冗余 |
129
+ | account_level | Int32 | 科目层级 | 冗余 |
130
+ | cost_center_id | String | 成本中心 ID | 关联 dim_cost_center |
131
+ | cost_center_name | String | 成本中心 | 冗余 |
132
+ | department | String | 部门 | 冗余 |
133
+ | profit_center | String | 利润中心 | 冗余 |
134
+ | debit_amount | Float64 | 借方 | |
135
+ | credit_amount | Float64 | 贷方 | |
136
+ | amount_signed | Float64 | 损益金额 | 收入为正、成本费用为负 |
137
+ | currency | String | 币种 | |
138
+ | voucher_no | String | 凭证号 | |
139
+ | source_system | String | 来源系统 | |
140
+ | description | String | 摘要 | 凭证行摘要文本 |
141
+ | created_at | DateTime | 创建时间 | |
142
+
143
+ **排序键**:`ORDER BY (date_key, entry_id, line_id)`
144
+
145
+ **损益符号 `amount_signed`**(seed 统一计算):
146
+
147
+ | account_type | 规则 | 含义 |
148
+ | ------------ | ---- | ---- |
149
+ | 收入 | credit - debit | 正=收入增加 |
150
+ | 成本/费用 | debit - credit | 正=成本/费用发生 |
151
+
152
+ ### 3.4 事实表:fact_budget_entry
153
+
154
+ | 字段名 | 类型 | 显示名 | 说明 |
155
+ | ------ | ---- | ------ | ---- |
156
+ | budget_id | String | 预算批次 | |
157
+ | line_id | String | 预算行 ID | 主键组合 |
158
+ | **date_key** | Int32 | 日期键 | 关联 dim_date(期间代表日) |
159
+ | budget_version | String | 预算版本 | |
160
+ | fiscal_year | Int32 | 预算年度 | |
161
+ | fiscal_period | Int32 | 预算期间 | 1–12;0=全年 |
162
+ | account_id | String | 科目 ID | 关联 dim_account |
163
+ | account_code | String | 科目编码 | 冗余 |
164
+ | account_name | String | 科目名称 | 冗余 |
165
+ | account_type | String | 科目类型 | 冗余 |
166
+ | pl_category | String | 损益大类 | 冗余 |
167
+ | cost_center_id | String | 成本中心 ID | 关联 dim_cost_center |
168
+ | cost_center_name | String | 成本中心 | 冗余 |
169
+ | department | String | 部门 | 冗余 |
170
+ | budget_amount | Float64 | 预算金额 | |
171
+ | currency | String | 币种 | |
172
+ | status | String | 状态 | 草稿/已发布 |
173
+ | created_at | DateTime | 创建时间 | |
174
+
175
+ **排序键**:`ORDER BY (fiscal_year, fiscal_period, account_id, line_id)`
195
176
 
196
177
  ### 3.5 表间关系设计(物理层 · 数据空间)
197
178
 
@@ -200,45 +181,46 @@
200
181
  **关系模型**:
201
182
 
202
183
  ```text
203
- account_master
204
- (account_id PK)
205
-
206
-
207
- many_to_one many_to_one
208
-
209
- actual_journal_entry budget_entry
210
- (分录行) (预算行)
211
-
212
- many_to_one
213
-
214
- cost_center_dimension
215
- (cost_center_id PK)
216
-
217
- account_master.parent_account_id ──► account_master(自关联,科目树)
184
+ dim_date
185
+ (date_key PK)
186
+
187
+
188
+ date_key date_key
189
+
190
+ dim_account ◄────┼────┼────► dim_cost_center
191
+ (account_id PK) │ │ (cost_center_id PK)
192
+ │ ▲
193
+ │ │ │
194
+ │ fact_gl_journal_entry │
195
+ │ (分录行) │
196
+ │ │ │ │
197
+ │ │ fact_budget_entry
198
+ │ │ (预算行)
199
+ │ └─────────┘
200
+
201
+ dim_account.parent_account_id ──► dim_account(自关联)
218
202
  ```
219
203
 
220
- **关系清单(6 条)**:
221
-
222
- | 关系 ID(建议) | 类型 | 从表 | 到表 | join_keys | 说明 |
223
- | ---------------------- | ----------- | -------------------- | --------------------- | --------------------------------------- | ------------------------------------------------- |
224
- | rel_actual_account | many_to_one | actual_journal_entry | account_master | account_id → account_id | 分录关联科目 |
225
- | rel_actual_cost_center | many_to_one | actual_journal_entry | cost_center_dimension | cost_center_id → cost_center_id | 分录关联成本中心 |
226
- | rel_budget_account | many_to_one | budget_entry | account_master | account_id → account_id | 预算关联科目 |
227
- | rel_budget_cost_center | many_to_one | budget_entry | cost_center_dimension | cost_center_id → cost_center_id | 预算关联成本中心 |
228
- | rel_account_parent | many_to_one | account_master | account_master | parent_account_id → account_id | 科目上级(树形) |
229
- | rel_budget_actual | many_to_one | budget_entry | actual_journal_entry | account_id+cost_center_id+fiscal_period | 预算与实际同维对齐(语义关联,JOIN 时加期间条件) |
204
+ **关系清单(8 条)**:
230
205
 
231
- > **说明**:`rel_budget_actual` **同维关联**(非严格 FK),`join_sql` 示例:
232
- > `budget_entry.account_id = actual_journal_entry.account_id AND budget_entry.cost_center_id = actual_journal_entry.cost_center_id AND budget_entry.fiscal_year = actual_journal_entry.fiscal_year AND budget_entry.fiscal_period = actual_journal_entry.fiscal_period`
233
- > 函数 `profit.fn.budget_vs_actual` 主要基于此 JOIN。
206
+ | 关系 ID | **347 分类** | 类型 | 从表 | 到表 | join_keys | 说明 |
207
+ | ------- | ------------ | ---- | ---- | ---- | --------- | ---- |
208
+ | rel_journal_date | **时间关联** | many_to_one | fact_gl_journal_entry | dim_date | date_key → date_key | 分录关联日历 |
209
+ | rel_budget_date | **时间关联** | many_to_one | fact_budget_entry | dim_date | date_key → date_key | 预算关联日历 |
210
+ | rel_journal_account | **主数据关联** | many_to_one | fact_gl_journal_entry | dim_account | account_id → account_id | 分录→科目 |
211
+ | rel_journal_cost_center | **主数据关联** | many_to_one | fact_gl_journal_entry | dim_cost_center | cost_center_id → cost_center_id | 分录→成本中心 |
212
+ | rel_budget_account | **主数据关联** | many_to_one | fact_budget_entry | dim_account | account_id → account_id | 预算→科目 |
213
+ | rel_budget_cost_center | **主数据关联** | many_to_one | fact_budget_entry | dim_cost_center | cost_center_id → cost_center_id | 预算→成本中心 |
214
+ | rel_account_parent | **层级自关联** | many_to_one | dim_account | dim_account | parent_account_id → account_id | 科目树 |
215
+ | rel_budget_actual | **预实关联** | many_to_one | fact_budget_entry | fact_gl_journal_entry | account_id+cost_center_id+fiscal_period | 预实同维(语义 JOIN;**init 待补**) |
234
216
 
235
217
  **实施 API**(`setup/profit_ontology_init.py`):
236
218
 
237
219
  ```python
238
220
  s.tables.add_relationship(
239
- from_table="actual_journal_entry",
240
- to_table="account_master",
241
- join_sql="actual_journal_entry.account_id = account_master.account_id",
221
+ from_table="fact_gl_journal_entry",
222
+ to_table="dim_account",
223
+ join_sql="fact_gl_journal_entry.account_id = dim_account.account_id",
242
224
  join_keys=[{"from": "account_id", "to": "account_id"}],
243
225
  relationship_type="many_to_one",
244
226
  description="实际分录关联会计科目",
@@ -249,22 +231,35 @@ s.tables.add_relationship(
249
231
 
250
232
  | 物理表关系 | 对应本体链接(业务层) |
251
233
  | ---------------------- | ------------------------- |
252
- | rel_actual_account | entry_belongs_account |
253
- | rel_actual_cost_center | entry_belongs_cost_center |
254
- | rel_budget_account | budget_for_account |
255
- | rel_budget_cost_center | budget_for_cost_center |
256
- | rel_account_parent | account_has_parent |
257
- | rel_budget_actual | budget_compared_to_actual |
234
+ | rel_journal_account | entry_belongs_account |
235
+ | rel_journal_cost_center | entry_belongs_cost_center |
236
+ | rel_budget_account | budget_for_account |
237
+ | rel_budget_cost_center | budget_for_cost_center |
238
+ | rel_account_parent | account_has_parent |
239
+ | rel_budget_actual | budget_compared_to_actual |
258
240
 
259
241
  ---
260
242
 
261
243
  ## 四、Cube 层设计
262
244
 
263
- ### 4.1 ActualCube(实际发生主 Cube)
245
+ ### 4.0 Cube 清单与类别
264
246
 
265
- **事实源**:`actual_journal_entry`
247
+ | Cube | 类别 | **347 分类** | 事实源 | 时间维 | 支撑对象 |
248
+ | ---- | ---- | ------------ | ------ | ------ | -------- |
249
+ | **ActualCube** | Process | **流程型** | fact_gl_journal_entry | dim_date + fiscal_* | JournalEntry, ProfitAnalysis |
250
+ | **AccountActualCube** | Subject | **主体型** | fact_gl_journal_entry | 同上 | Account |
251
+ | **CostCenterActualCube** | Subject | **主体型** | fact_gl_journal_entry | 同上 | CostCenter |
252
+ | **BudgetCube** | Process | **流程型** | fact_budget_entry | 同上 | BudgetLine, BudgetAnalysis |
253
+ | **TimeActualCube** | Subject | **主体型** | fact_gl_journal_entry | 同上 | (时间切片;**init 已注册**,347 建议后续并入 Process) |
254
+ | **BudgetVsActualCube** | Comparison | **对比型** | fact_budget_entry + fact_gl_journal_entry | fiscal_year/period | BudgetAnalysis(预实;**规划目标,init 待补**) |
266
255
 
267
- **维度**:entry_id, line_id, posting_date, fiscal_year, fiscal_period, account_id, account_code, account_name, account_type, pl_category, cost_center_id, cost_center_name, department, voucher_no, source_system
256
+ > 347 §4.2 建议时间增强不单独建 Cube;当前示例 init 仍含 **TimeActualCube** 并归 **主体型**,后续可合并进 ActualCube 后从注册表移除。
257
+
258
+ ### 4.1 ActualCube(Process · 实际发生主 Cube)
259
+
260
+ **事实源**:`fact_gl_journal_entry`
261
+
262
+ **维度**:entry_id, line_id, date_key, posting_date, fiscal_year, fiscal_period, year, month, account_id, account_code, account_name, account_type, pl_category, cost_center_id, cost_center_name, department, voucher_no, source_system
268
263
 
269
264
  **度量**:
270
265
 
@@ -285,44 +280,41 @@ s.tables.add_relationship(
285
280
  | operating_profit | revenue - cost - expense | 营业利润 |
286
281
  | profit_margin | if(revenue>0, operating_profit/revenue, 0) | 利润率 |
287
282
 
288
- ### 4.2 AccountActualCube(科目实际 Cube)
283
+ ### 4.2 AccountActualCube(Subject · 科目实际)
289
284
 
290
285
  **目的**:Account 对象 bind_source
291
286
 
292
- **维度**:account_id, account_code, account_name, account_type, pl_category, account_level, fiscal_year, fiscal_period
287
+ **维度**:account_id, account_code, account_name, account_type, pl_category, account_level, fiscal_year, fiscal_period, year, month
293
288
 
294
289
  **度量**:net_amount, line_count
295
290
 
296
- **派生度量**:revenue, cost, expense(同上,按 account_type 聚合)
291
+ **派生度量**:revenue, cost, expense
297
292
 
298
- ### 4.3 CostCenterActualCube(成本中心实际 Cube)
293
+ ### 4.3 CostCenterActualCube(Subject · 成本中心实际)
299
294
 
300
- **维度**:cost_center_id, cost_center_name, department, profit_center, fiscal_year, fiscal_period
295
+ **维度**:cost_center_id, cost_center_name, department, profit_center, fiscal_year, fiscal_period, year, month
301
296
 
302
297
  **度量**:net_amount, line_count
303
298
 
304
299
  **派生度量**:revenue, cost, expense, operating_profit, profit_margin
305
300
 
306
- ### 4.4 BudgetCube(预算 Cube)
301
+ ### 4.4 BudgetCube(Process · 预算)
307
302
 
308
- **事实源**:`budget_entry`
303
+ **事实源**:`fact_budget_entry`
309
304
 
310
- **维度**:budget_version, fiscal_year, fiscal_period, account_id, account_code, account_type, pl_category, cost_center_id, department
305
+ **维度**:budget_version, fiscal_year, fiscal_period, date_key, account_id, account_code, account_type, pl_category, cost_center_id, department
311
306
 
312
- **度量**:
307
+ **度量**:budget_amount(sum), budget_lines(count)
313
308
 
314
- | 度量名 | 列名 | 聚合 | 说明 |
315
- | ------------- | ------------- | ----- | -------- |
316
- | budget_amount | budget_amount | sum | 预算金额 |
317
- | budget_lines | line_id | count | 预算行数 |
309
+ **派生度量**:budget_revenue / budget_cost / budget_expense(按 account_type 切片)
318
310
 
319
- **派生度量**:budget_revenue / budget_cost / budget_expense(按 account_type 切片,同 ActualCube 逻辑)
311
+ ### 4.5 BudgetVsActualCube(Comparison · 预实对比)
320
312
 
321
- ### 4.5 TimeActualCube(时间维度 Cube
313
+ **目的**:`profit.fn.budget_vs_actual` 读模型;JOIN budget 与 actual 同维(account + cost_center + fiscal_period
322
314
 
323
- **维度**:posting_date, fiscal_year, fiscal_period, year_month, quarter
315
+ **维度**:fiscal_year, fiscal_period, account_id, cost_center_id, budget_version
324
316
 
325
- **度量**:net_amount, revenue, cost, expense, operating_profit(派生)
317
+ **度量**:budget_amount, actual_amount(来自 ActualCube 聚合), variance, execution_rate(派生)
326
318
 
327
319
  ---
328
320
 
@@ -330,16 +322,16 @@ s.tables.add_relationship(
330
322
 
331
323
  ### 5.1 对象类型(6 种)
332
324
 
333
- | 对象类型 code | 名称 | 说明 | bind_source |
334
- | -------------- | -------- | ----------------------- | -------------------- |
335
- | Account | 会计科目 | 科目业务对象 | AccountActualCube |
336
- | CostCenter | 成本中心 | 组织/利润中心业务对象 | CostCenterActualCube |
337
- | JournalEntry | 实际分录 | 凭证行/实际发生业务对象 | ActualCube |
338
- | BudgetLine | 预算行 | 预算编制明细业务对象 | BudgetCube |
339
- | ProfitAnalysis | 利润分析 | 多维度损益指标聚合对象 | ActualCube |
340
- | BudgetAnalysis | 预算分析 | 预算执行与差异分析对象 | BudgetCube |
325
+ | code | 分类 | **347 分类** | 名称 | bind_source | 主物理支撑 |
326
+ | ---- | ---- | ------------ | ---- | ------------- | ---------- |
327
+ | Account | Master | **主数据** | 会计科目 | AccountActualCube | dim_account |
328
+ | CostCenter | Master | **主数据** | 成本中心 | CostCenterActualCube | dim_cost_center |
329
+ | JournalEntry | Transaction | **事务** | 实际分录 | ActualCube | fact_gl_journal_entry |
330
+ | BudgetLine | Transaction | **事务** | 预算行 | BudgetCube | fact_budget_entry |
331
+ | ProfitAnalysis | Analytical | **分析** | 利润分析 | ActualCube | fact_gl_journal_entry |
332
+ | BudgetAnalysis | Analytical | **分析** | 预算分析 | BudgetCube / BudgetVsActualCube | fact_budget_entry |
341
333
 
342
- > 对象类型 `code` 使用稳定英文标识;与表名、Cube 名刻意区分。
334
+ > 对象 **`code` 无前缀**;分类见 [命名规范 §5.3](./本体命名规范_物理表Cube与对象.md#53-对象分类无-code-前缀)。
343
335
 
344
336
  ### 5.2 对象属性(摘要)
345
337
 
@@ -380,22 +372,34 @@ s.tables.add_relationship(
380
372
 
381
373
  #### CostCenter / ProfitAnalysis / BudgetAnalysis
382
374
 
383
- 与 Cube 维/度量映射一致(约 **42** 个属性,实施时参照 init 脚本)。
375
+ 与 Cube 维/度量映射一致(约 **42** 个属性);实施参照 `利润示例/setup/profit_ontology_init.py`(表名按本规划迁移)。
384
376
 
385
377
  ### 5.3 链接类型(10 种)
386
378
 
387
- | 链接 code | 名称 | from | to | 说明 |
388
- | ------------------------------ | ---------------- | -------------- | -------------- | ---------------- |
389
- | entry_belongs_account | 分录归属科目 | JournalEntry | Account | 分录行对应科目 |
390
- | entry_belongs_cost_center | 分录归属成本中心 | JournalEntry | CostCenter | 分录行对应组织 |
391
- | budget_for_account | 预算对应科目 | BudgetLine | Account | 预算行对应科目 |
392
- | budget_for_cost_center | 预算对应成本中心 | BudgetLine | CostCenter | 预算行对应组织 |
393
- | account_has_parent | 科目上级 | Account | Account | 科目树父级 |
394
- | budget_compared_to_actual | 预算对比实际 | BudgetAnalysis | ProfitAnalysis | 预实差异分析 |
395
- | analysis_by_account | 分析归因科目 | ProfitAnalysis | Account | 指标按科目切片 |
396
- | analysis_by_cost_center | 分析归因成本中心 | ProfitAnalysis | CostCenter | 指标按组织切片 |
397
- | account_contributes_profit | 科目贡献利润 | Account | ProfitAnalysis | 科目损益贡献 |
398
- | cost_center_contributes_profit | 组织贡献利润 | CostCenter | ProfitAnalysis | 成本中心利润贡献 |
379
+ | 链接 code | **347 分类** | 名称 | from | to | 说明 |
380
+ | ------------------------------ | ------------ | ---------------- | -------------- | -------------- | ---------------- |
381
+ | entry_belongs_account | **归属关系** | 分录归属科目 | JournalEntry | Account | 分录行对应科目 |
382
+ | entry_belongs_cost_center | **归属关系** | 分录归属成本中心 | JournalEntry | CostCenter | 分录行对应组织 |
383
+ | budget_for_account | **归属关系** | 预算对应科目 | BudgetLine | Account | 预算行对应科目 |
384
+ | budget_for_cost_center | **归属关系** | 预算对应成本中心 | BudgetLine | CostCenter | 预算行对应组织 |
385
+ | account_has_parent | **层级关系** | 科目上级 | Account | Account | 科目树父级 |
386
+ | budget_compared_to_actual | **对比关系** | 预算对比实际 | BudgetAnalysis | ProfitAnalysis | 预实差异分析 |
387
+ | analysis_by_account | **分析归因** | 分析归因科目 | ProfitAnalysis | Account | 指标按科目切片 |
388
+ | analysis_by_cost_center | **分析归因** | 分析归因成本中心 | ProfitAnalysis | CostCenter | 指标按组织切片 |
389
+ | account_contributes_profit | **分析归因** | 科目贡献利润 | Account | ProfitAnalysis | 科目损益贡献 |
390
+ | cost_center_contributes_profit | **分析归因** | 组织贡献利润 | CostCenter | ProfitAnalysis | 成本中心利润贡献 |
391
+
392
+ ### 5.4 三层对照总表
393
+
394
+ | 对象 code | 分类 | Cube | 主 fact / dim |
395
+ | --------- | ---- | ---- | ------------- |
396
+ | Account | Master | AccountActualCube | dim_account |
397
+ | CostCenter | Master | CostCenterActualCube | dim_cost_center |
398
+ | JournalEntry | Transaction | ActualCube | fact_gl_journal_entry |
399
+ | BudgetLine | Transaction | BudgetCube | fact_budget_entry |
400
+ | ProfitAnalysis | Analytical | ActualCube | fact_gl_journal_entry |
401
+ | BudgetAnalysis | Analytical | BudgetVsActualCube | fact_budget_entry + fact_gl_journal_entry |
402
+ | (时间) | — | ActualCube / BudgetCube | dim_date |
399
403
 
400
404
  ---
401
405
 
@@ -403,15 +407,15 @@ s.tables.add_relationship(
403
407
 
404
408
  ### 6.1 函数清单
405
409
 
406
- | 函数 ID | 功能 | 参数 |
407
- | ---------------------------- | ------------ | ------------------------------------------------------------------ |
408
- | profit.fn.get_summary | 利润总览 | start_date, end_date, cost_center_id(可选) |
409
- | profit.fn.yoy_analysis | 同比分析 | start_date, end_date, pl_category(可选) |
410
- | profit.fn.mom_analysis | 环比分析 | start_date, end_date, pl_category(可选) |
411
- | profit.fn.budget_vs_actual | **预实对比** | fiscal_year, fiscal_period, budget_version, cost_center_id(可选) |
412
- | profit.fn.account_breakdown | **科目结构** | start_date, end_date, account_level, pl_category(可选) |
413
- | profit.fn.cost_center_profit | **组织利润** | start_date, end_date, department(可选) |
414
- | profit.fn.top_accounts | 科目 Top N | limit, metric, start_date, end_date, account_type(可选) |
410
+ | 函数 ID | **347 分类** | 功能 | 参数 |
411
+ | ---------------------------- | ------------ | ------------ | ------------------------------------------------------------------ |
412
+ | profit.fn.get_summary | **总览分析** | 利润总览 | start_date, end_date, cost_center_id(可选) |
413
+ | profit.fn.yoy_analysis | **趋势分析** | 同比分析 | start_date, end_date, pl_category(可选) |
414
+ | profit.fn.mom_analysis | **趋势分析** | 环比分析 | start_date, end_date, pl_category(可选) |
415
+ | profit.fn.budget_vs_actual | **预实分析** | **预实对比** | fiscal_year, fiscal_period, budget_version, cost_center_id(可选) |
416
+ | profit.fn.account_breakdown | **结构分析** | **科目结构** | start_date, end_date, account_level, pl_category(可选) |
417
+ | profit.fn.cost_center_profit | **组织分析** | **组织利润** | start_date, end_date, department(可选) |
418
+ | profit.fn.top_accounts | **结构分析** | 科目 Top N | limit, metric, start_date, end_date, account_type(可选) |
415
419
 
416
420
  > 旧示例中的 `profit.fn.top_products`、`profit.fn.customer_segmentation` 属**订单/产品域**,本方案以 GL 为主,**不纳入**默认函数集;若需产品利润,可单独增加 `profit.fn.sales_reconciliation` 勾稽销售表。
417
421
 
@@ -467,12 +471,12 @@ s.tables.add_relationship(
467
471
  | profit.fn.cost_center_profit | `.../profit.fn.cost_center_profit.json` | 日期范围 |
468
472
  | profit.fn.top_accounts | `.../profit.fn.top_accounts.json` | limit=10, metric=net_impact |
469
473
 
470
- > 内置示例路径:`资源/examples/onto/利润示例/function/test_arguments/`(复制到实现单元 `functions/test_arguments/`)。
474
+ > 内置示例路径:`资源/examples/onto/利润示例/functions/test_arguments/`(复制到实现单元 `functions/test_arguments/`)。
471
475
 
472
476
  批量入库(实现单元 `functions/` 下,dazi-work 根):
473
477
 
474
478
  ```powershell
475
- .\项目\潘达石化\本体\ontos\利润分析本体方案\functions\save_test_arguments.ps1
479
+ .\<item-path>\functions\save_test_arguments.ps1
476
480
  ```
477
481
 
478
482
  > 参考实现:`资源/examples/onto/利润示例/`(init + seed + 7 个 `profit_fn_*.py` + test_arguments)。
@@ -481,54 +485,54 @@ s.tables.add_relationship(
481
485
 
482
486
  ## 七、实施计划
483
487
 
484
- > **dazi-vscode v3** · 空间 `space__zlj` · 脚本目录 `setup/`、`functions/`
488
+ > **dazi-vscode v3** · 空间 `<space-id>` · 脚本目录 `setup/`、`functions/`
485
489
  > 发布示例:
486
- > `dazi onto script publish 项目/潘达石化/本体/ontos/利润分析本体方案/setup/profit_ontology_init.py --space space__zlj --type setup`
490
+ > `dazi onto script publish <item-path>/setup/profit_ontology_init.py --space <space-id> --type setup`
487
491
 
488
492
  ### 7.1 阶段一:物理层(高)
489
493
 
490
- | 步骤 | 任务 | 说明 |
491
- | ---- | -------------------------- | ----------------------- |
492
- | 1 | 创建 account_master | **科目表** |
493
- | 2 | 创建 cost_center_dimension | 成本中心维表 |
494
- | 3 | 创建 actual_journal_entry | **实际分录表** |
495
- | 4 | 创建 budget_entry | **预算表** |
496
- | 5 | 注册表到空间 | register + sync_columns |
497
- | 6 | **注册表间关系(6 条)** | add_relationship |
494
+ | 步骤 | 任务 | 说明 |
495
+ | ---- | ---- | ---- |
496
+ | 1 | **dim_date** | 共用或 ensure |
497
+ | 2 | dim_account | 科目维 |
498
+ | 3 | dim_cost_center | 成本中心维 |
499
+ | 4 | fact_gl_journal_entry | 含 **date_key** |
500
+ | 5 | fact_budget_entry | **date_key** |
501
+ | 6 | **TABLE_REGISTRY** + `register_with_meta` | 表/列 display_name、description |
502
+ | 7 | **表间关系(8 条)** | 含两条 fact→dim_date |
498
503
 
499
504
  ### 7.2 阶段二:Cube 层(高)
500
505
 
501
- | 步骤 | 任务 |
502
- | ---- | -------------------------------------------------- |
503
- | 7 | 注册 ActualCube / AccountActualCube 5 Cube |
504
- | 8 | 配置派生度量 revenue/cost/expense/operating_profit |
506
+ | 步骤 | 任务 |
507
+ | ---- | ---- |
508
+ | 8 | 注册 **5 Cube**(含 BudgetVsActualCube;无 Time Cube) |
509
+ | 9 | 派生度量 revenue/cost/expense/operating_profit |
505
510
 
506
511
  ### 7.3 阶段三:本体层(高)
507
512
 
508
- | 步骤 | 任务 |
509
- | ---- | --------------------------- |
510
- | 9 | define_object_type(6 种) |
511
- | 10 | bind_source |
512
- | 11 | define_property(约 42 个) |
513
- | 12 | define_link_type(10 种) |
514
- | 13 | sync_metric_refs |
513
+ | 步骤 | 任务 |
514
+ | ---- | ---- |
515
+ | 10 | define_object_type(6 种) |
516
+ | 11 | bind_source |
517
+ | 12 | define_property(约 42 个) |
518
+ | 13 | define_link_type(10 种) |
519
+ | 14 | sync_metric_refs |
520
+ | 15 | **CATEGORY_REGISTRY** + `s.categories.apply_registry`(347 对齐) |
515
521
 
516
522
  ### 7.4 阶段四:函数与数据(中)
517
523
 
518
- | 步骤 | 任务 |
519
- | ---- | --------------------------------------------------------------------------------- |
520
- | 14 | 新建 `profit_ontology_init.py`、`profit_seed_data.py`(科目树+分录+预算演示数据) |
521
- | 15 | 适配/新建 7 个 `profit_fn_*.py` |
522
- | 16 | publish + run 验证 → save-test-arguments |
524
+ | 步骤 | 任务 |
525
+ | ---- | ---- |
526
+ | 15 | profit_ontology_init.pyprofit_seed_data.py(含 dim_date / date_key) |
527
+ | 16 | 7 个 profit_fn_*.py |
528
+ | 17 | publish + run → save-test-arguments |
523
529
 
524
530
  ### 7.5 快速实施路径
525
531
 
526
532
  | 来源 | 可复用内容 | 需改造 |
527
533
  | ---------------------------------------------------------- | --------------------------------- | ------------------------------ |
528
- | `资源/examples/onto/利润示例/setup/profit_ontology_init.py` | GL 表/Cube/对象/链接完整 init | 按业务改 `space_id` 与科目口径 |
529
- | `资源/examples/onto/利润示例/setup/profit_seed_data.py` | 科目树+分录+预算演示数据 | 同上 |
530
- | `资源/examples/onto/利润示例/function/profit_fn_*.py` | 7 个 GL 分析函数 + test_arguments | 复制到 `functions/` 后发布 |
531
- | `项目/潘达石化/本体/ontos/产品销售本体方案/` | init/seed/test_arguments 工程模式 | 表结构与函数逻辑不同 |
534
+ | `资源/examples/onto/利润示例/` | init/seed/函数完整示例 | 复制到 `<item-path>/` 后改 `<space-id>` |
535
+ | [规划示例:产品销售](./规划示例_产品销售本体规划方案.md) | 工程模式对照 | 表结构与函数逻辑不同 |
532
536
 
533
537
  **seed 数据建议**:
534
538
 
@@ -545,22 +549,25 @@ s.tables.add_relationship(
545
549
 
546
550
  | 等级 | 风险 | 缓解措施 |
547
551
  | ---- | ------------------------- | ------------------------------------------- |
548
- | 中 | 与销售域共用 space\_\_zlj | init 仅创建利润域 4 |
552
+ | 中 | 多域共用 `<space-id>` | init 仅创建利润域表;**dim_date** 共用 ensure |
549
553
  | 中 | 借贷方向与符号口径不一致 | seed 统一计算 `amount_signed`;文档约定口径 |
550
554
  | 中 | 预实 JOIN 期间粒度不一致 | budget/actual 均含 fiscal_year/period |
551
555
  | 低 | 旧示例订单模型混淆 | 规划与函数 ID 明确以 GL 为准 |
552
556
 
553
557
  ### 8.2 验收标准
554
558
 
555
- | 验收项 | 标准 |
556
- | ------------ | ------------------------------------------------------- |
557
- | 科目表 | account_master 可查询,树形 parent 可解析 |
558
- | 实际分录表 | actual_journal_entry 可查询,损益汇总与手工 SQL 一致 |
559
- | 预算表 | budget_entry 可查询,与 actual 同维可 JOIN |
560
- | **表间关系** | **6 条**注册成功 |
561
- | Cube | 5 Cube + 派生度量可算 |
562
- | 对象类型 | 6 种对象 + 10 种链接 |
563
- | 函数 | get_summary、budget_vs_actual、account_breakdown 可运行 |
559
+ | 验收项 | 标准 |
560
+ | ------ | ---- |
561
+ | dim_date | 可查询;fact date_key 可 JOIN |
562
+ | dim_account | 树形 parent 可解析 |
563
+ | fact_gl_journal_entry | 损益汇总与手工 SQL 一致 |
564
+ | fact_budget_entry | actual 同维可 JOIN |
565
+ | 表/列元数据 | 侧栏与表预览显示名、说明与 §3.x 一致 |
566
+ | **表间关系** | **8 条** |
567
+ | Cube | **5 个** + 派生度量 |
568
+ | 对象 | 6 种 + 分类;10 种链接 |
569
+ | **347 平台分类** | 侧栏分类名与附录 B 一致;`category_mounts` 非空 |
570
+ | 函数 | get_summary、budget_vs_actual、account_breakdown 可运行 |
564
571
  | 数据 | 种子灌入后预实差异可解释 |
565
572
 
566
573
  ---
@@ -579,19 +586,95 @@ s.tables.add_relationship(
579
586
 
580
587
  ---
581
588
 
589
+ ## 附录 B:347 分类挂载对照表(CATEGORY_REGISTRY)
590
+
591
+ 与 `利润示例/setup/profit_ontology_init.py` 顶部 **`CATEGORY_REGISTRY`** 一一对应(见 [349 方案](./本体分类规划与SDK扩展方案.md))。
592
+
593
+ ### B.1 物理表(table)
594
+
595
+ | 347 分类 | 表名 |
596
+ | -------- | ---- |
597
+ | 维度表 | dim_account, dim_cost_center |
598
+ | 事实表 | fact_gl_journal_entry, fact_budget_entry |
599
+
600
+ > `dim_date` 为 **时间维**,多域共用;由销售域 init 创建时,利润域 `CATEGORY_REGISTRY` 可不重复挂载。
601
+
602
+ ### B.2 Cube(cube)
603
+
604
+ | 347 分类 | Cube |
605
+ | -------- | ---- |
606
+ | 流程型 | ActualCube, BudgetCube |
607
+ | 主体型 | AccountActualCube, CostCenterActualCube, TimeActualCube |
608
+
609
+ ### B.3 对象类型(object)
610
+
611
+ | 347 分类 | code |
612
+ | -------- | ---- |
613
+ | 主数据 | Account, CostCenter |
614
+ | 事务 | JournalEntry, BudgetLine |
615
+ | 分析 | ProfitAnalysis, BudgetAnalysis |
616
+
617
+ ### B.4 表间关系(relation)
618
+
619
+ | 347 分类 | 从表 → 到表 |
620
+ | -------- | ----------- |
621
+ | 时间关联 | fact_gl_journal_entry → dim_date;fact_budget_entry → dim_date |
622
+ | 主数据关联 | fact_gl_journal_entry → dim_account / dim_cost_center;fact_budget_entry → dim_account / dim_cost_center |
623
+ | 层级自关联 | dim_account → dim_account |
624
+
625
+ ### B.5 链接类型(link)
626
+
627
+ | 347 分类 | link code |
628
+ | -------- | --------- |
629
+ | 归属关系 | entry_belongs_account, entry_belongs_cost_center, budget_for_account, budget_for_cost_center |
630
+ | 分析归因 | analysis_by_account, analysis_by_cost_center, account_contributes_profit, cost_center_contributes_profit |
631
+ | 层级关系 | account_has_parent |
632
+ | 对比关系 | budget_compared_to_actual |
633
+
634
+ ### B.6 本体函数(function)
635
+
636
+ init **不**注册函数;`apply_registry(..., skip_missing=True)` 跳过未发布函数。建议分类:
637
+
638
+ | 347 分类 | function_id |
639
+ | -------- | ----------- |
640
+ | 总览分析 | profit.fn.get_summary |
641
+ | 趋势分析 | profit.fn.yoy_analysis, profit.fn.mom_analysis |
642
+ | 结构分析 | profit.fn.account_breakdown, profit.fn.top_accounts |
643
+ | 预实分析 | profit.fn.budget_vs_actual |
644
+ | 组织分析 | profit.fn.cost_center_profit |
645
+
646
+ ---
647
+
648
+ ## 附录:规划完整性自检清单
649
+
650
+ 定稿前逐项勾选(完整说明见 [本体规划指南 · 规划文档完整性自检清单](./本体规划指南.md#规划文档完整性自检清单))。
651
+
652
+ | # | 检查项 | 本方案 |
653
+ | - | ------ | ------ |
654
+ | 1 | 业务场景 | ☑ |
655
+ | 2 | 物理表 | ☑(dim_date + 2 dim + 2 fact) |
656
+ | 2a–2c | 命名规范 | ☑ |
657
+ | 3 | 表间关系 | ☑(**8 条**) |
658
+ | 4 | Cube 层 | ☑(**5 个**,§4.0) |
659
+ | 5 | 对象 + 分类 | ☑(§5.1、§5.4) |
660
+ | 6–10 | 同指南 | ☑ |
661
+ | 6a–6e | 347 平台分类 | ☑(附录 B + init 步骤 10) |
662
+
663
+ ---
664
+
582
665
  ## 十、相关文档
583
666
 
584
- | 文档 | 路径 |
585
- | ---------------------------------- | ----------------------------------------------------------------------------- |
586
- | 快速启动 | [../快速启动\_利润分析本体方案.md](../快速启动_利润分析本体方案.md) |
587
- | 本体规划指南 | `资源/docs/onto/本体规划指南.md` |
588
- | 规划示例(产品销售,推荐工程模式) | `资源/docs/onto/规划示例_产品销售本体规划方案.md` |
589
- | 规划示例(利润·GL 域) | `资源/docs/onto/规划示例_利润分析本体方案.md` |
590
- | **内置脚本示例** | `资源/examples/onto/利润示例/`(`dazi examples sync`) |
667
+ | 文档 | 路径 |
668
+ | ---- | ---- |
669
+ | 本体命名规范 | [本体命名规范_物理表Cube与对象.md](./本体命名规范_物理表Cube与对象.md) |
670
+ | 本体规划指南 | [本体规划指南.md](./本体规划指南.md) |
671
+ | 规划示例(产品销售) | [规划示例_产品销售本体规划方案.md](./规划示例_产品销售本体规划方案.md) |
672
+ | **内置脚本示例** | `资源/examples/onto/利润示例/`(`dazi examples sync`;表名迁移中) |
673
+ | 349 · 分类方案 | [本体分类规划与 SDK 扩展方案](./本体分类规划与SDK扩展方案.md) |
591
674
 
592
675
  ---
593
676
 
594
- **方案版本**:v2.0
595
- **创建日期**:2026-06-06
596
- **适用空间**:`space__zlj`
597
- **状态**:已落地
677
+ **方案版本**:v2.2(+347 分类列与附录 B CATEGORY_REGISTRY)
678
+ **创建日期**:(定稿日)
679
+ **适用**:复制到 `<item-path>/plans/`;`<space-id>` 以该实现单元 `README.md` 为准
680
+ **状态**:规划示例(公共模板)