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