@dazitech/cli 3.0.6 → 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.
- package/README.md +1 -1
- package/dist/clis/dazi-app.js +1 -1
- package/dist/clis/dazi-flow.js +43 -24
- package/dist/clis/dazi-onto.js +73 -22
- package/dist/clis/dazi.js +266 -171
- package/dist/docs/flow/ai-workflow-playbook.md +4 -2
- package/dist/docs/flow/flow-project-guide.md +9 -5
- package/dist/docs/flow/flows-guide.md +2 -2
- package/dist/docs/flow/node-code-guide.md +408 -401
- package/dist/docs/flow/run-guide.md +13 -6
- package/dist/docs/flow/variables-guide.md +407 -406
- package/dist/docs/guides/quickstart.md +18 -4
- package/dist/docs/guides/troubleshooting.md +1 -1
- package/dist/docs/guides/workspace-v3.md +43 -23
- package/dist/docs/index.json +9 -3
- package/dist/docs/onto/action-guide.md +3 -3
- package/dist/docs/onto/dazi_script_sdk_reference.md +178 -174
- package/dist/docs/onto/dazi_script_seed_data_guide.md +158 -155
- package/dist/docs/onto/function-guide.md +37 -10
- package/dist/docs/onto/space-management.md +3 -1
- 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
- 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
- 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
- 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
- package/dist/examples/index.json +202 -22
- package/dist/examples/onto/README.md +43 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_account_breakdown.py +99 -0
- 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
- 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
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_get_summary.py +76 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_mom_analysis.py +86 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_top_accounts.py +103 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/profit_fn_yoy_analysis.py +86 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/function/save_test_arguments.ps1 +27 -0
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_ontology_init.py +521 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_seed_data.py +213 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/README.md +25 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_channel_mix.py +86 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_customer_segmentation.py +123 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_get_summary.py +81 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_mom_analysis.py +90 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_region_breakdown.py +85 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_top_products.py +101 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_yoy_analysis.py +90 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/save_test_arguments.ps1 +25 -0
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/README.md +5 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_ontology_init.py +403 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_seed_data.py +124 -0
- package/dist/prompts/flow/ai-workflow-playbook.md +4 -2
- package/dist/prompts/flow/flow-design.md +12 -9
- package/dist/prompts/flow/run-fix-loop.md +37 -22
- package/dist/prompts/index.json +2 -2
- package/dist/prompts/onto/action-design.md +4 -1
- package/dist/prompts/onto/function-design.md +9 -2
- package/dist/prompts/onto/rule-seed.md +5 -1
- package/dist/prompts/onto/script-publish-run.md +72 -24
- package/package.json +1 -1
- package/dist/examples/onto/function/profit_fn_customer_segmentation.py +0 -117
- package/dist/examples/onto/function/profit_fn_mom_analysis.py +0 -89
- package/dist/examples/onto/function/profit_fn_top_products.py +0 -89
- package/dist/examples/onto/function/profit_fn_yoy_analysis.py +0 -89
- package/dist/examples/onto/setup/profit_ontology_init.py +0 -388
|
@@ -1,541 +1,597 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
## 一、空间概述
|
|
6
|
-
|
|
7
|
-
| 项目 | 说明
|
|
8
|
-
| -------- |
|
|
9
|
-
| 空间ID
|
|
10
|
-
| 空间名称 |
|
|
11
|
-
| 空间状态 |
|
|
12
|
-
| 规划日期 | 2026-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
|
49
|
-
|
|
|
50
|
-
|
|
|
51
|
-
|
|
|
52
|
-
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
|
57
|
-
|
|
|
58
|
-
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
|
75
|
-
|
|
|
76
|
-
|
|
|
77
|
-
|
|
|
78
|
-
|
|
|
79
|
-
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
-
### 4
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
|
169
|
-
|
|
|
170
|
-
|
|
|
171
|
-
|
|
|
172
|
-
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
|
177
|
-
|
|
|
178
|
-
|
|
|
179
|
-
|
|
|
180
|
-
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
|
185
|
-
|
|
|
186
|
-
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
|
223
|
-
|
|
|
224
|
-
|
|
|
225
|
-
|
|
|
226
|
-
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
|
251
|
-
|
|
|
252
|
-
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
|
257
|
-
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
|
272
|
-
|
|
|
273
|
-
|
|
|
274
|
-
|
|
|
275
|
-
|
|
|
276
|
-
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
|
283
|
-
|
|
|
284
|
-
|
|
|
285
|
-
|
|
|
286
|
-
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
|
316
|
-
|
|
|
317
|
-
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
|
337
|
-
|
|
|
338
|
-
|
|
|
339
|
-
|
|
|
340
|
-
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
|
352
|
-
|
|
|
353
|
-
|
|
|
354
|
-
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
|
359
|
-
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
|
364
|
-
|
|
|
365
|
-
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
|
375
|
-
|
|
|
376
|
-
|
|
|
377
|
-
|
|
|
378
|
-
|
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
|
388
|
-
|
|
|
389
|
-
|
|
|
390
|
-
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
|
408
|
-
|
|
|
409
|
-
|
|
|
410
|
-
|
|
|
411
|
-
|
|
|
412
|
-
| profit
|
|
413
|
-
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
|
428
|
-
|
|
|
429
|
-
|
|
|
430
|
-
|
|
|
431
|
-
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
|
442
|
-
|
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
|
447
|
-
|
|
|
448
|
-
|
|
|
449
|
-
|
|
|
450
|
-
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
|
461
|
-
|
|
|
462
|
-
|
|
|
463
|
-
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
|
468
|
-
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
---
|
|
481
|
-
|
|
482
|
-
##
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
|
495
|
-
|
|
|
496
|
-
|
|
|
497
|
-
|
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
|
502
|
-
|
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
|
511
|
-
|
|
|
512
|
-
|
|
|
513
|
-
|
|
|
514
|
-
|
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
|
530
|
-
|
|
|
531
|
-
|
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
1
|
+
# 利润分析本体规划方案
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
## 一、空间概述
|
|
6
|
+
|
|
7
|
+
| 项目 | 说明 |
|
|
8
|
+
| -------- | ---------------------------------------------------------------------------- |
|
|
9
|
+
| 空间 ID | `space__zlj` |
|
|
10
|
+
| 空间名称 | 数据空间zlj |
|
|
11
|
+
| 空间状态 | 与「产品销售」「员工培训」等**共用同一数据空间**;利润域表/Cube/对象独立建设 |
|
|
12
|
+
| 规划日期 | 2026-06-06 |
|
|
13
|
+
| 实现单元 | `项目/潘达石化/本体/ontos/利润分析本体方案/` |
|
|
14
|
+
|
|
15
|
+
> **共存说明**:本空间可能已有 `product_master`、`sales_order_fact`、`training_record` 等表。利润分析域以 **会计科目 + 实际分录 + 预算** 为读模型根基,init 脚本**仅**创建/注册利润域表,不覆盖其他域资产。
|
|
16
|
+
> **与销售域关系**:销售收入可通过科目映射(如「6001 主营业务收入」)与实际分录对齐;必要时函数层 LEFT JOIN `sales_order_fact` 做勾稽,但**本体对象不以订单为主锚点**。
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## 二、需求分析
|
|
21
|
+
|
|
22
|
+
### 2.1 业务背景
|
|
23
|
+
|
|
24
|
+
潘达石化财务利润分析场景,需构建**利润分析本体**,以业务语言描述「会计科目」「实际分录」「预算」及其关系,支撑:
|
|
25
|
+
|
|
26
|
+
- **损益总览**:收入、成本、费用、营业利润、利润率
|
|
27
|
+
- **科目结构**:按科目层级展开收入/成本/费用构成
|
|
28
|
+
- **实际 vs 预算**:按期间、科目、成本中心的预算执行率与差异分析
|
|
29
|
+
- **组织维度**:按成本中心/部门贡献与超支预警
|
|
30
|
+
- **趋势分析**:同比、环比利润与关键科目走势
|
|
31
|
+
- **归因分析**:利润变动由哪些科目/组织驱动
|
|
32
|
+
|
|
33
|
+
### 2.2 核心业务问题
|
|
34
|
+
|
|
35
|
+
| 问题 | 说明 |
|
|
36
|
+
| --------------- | ------------------------------ |
|
|
37
|
+
| 利润是多少 | 期间营业利润、利润率 |
|
|
38
|
+
| 钱从哪来/到哪去 | 收入、成本、费用科目结构 |
|
|
39
|
+
| 预算执行如何 | 预算额、实际额、差异额、执行率 |
|
|
40
|
+
| 哪个部门拖后腿 | 成本中心维度利润与预算偏差 |
|
|
41
|
+
| 哪些科目异常 | 科目 Top N、同比/环比异动 |
|
|
42
|
+
| 趋势如何 | 按月/季/年利润与关键科目走势 |
|
|
43
|
+
|
|
44
|
+
### 2.3 规划范围说明
|
|
45
|
+
|
|
46
|
+
**核心物理表(本方案重点)**:
|
|
47
|
+
|
|
48
|
+
| 表名 | 中文名 | 角色 |
|
|
49
|
+
| ---------------------- | -------------- | ------------------------------- |
|
|
50
|
+
| `account_master` | **科目表** | 会计科目主数据(维表) |
|
|
51
|
+
| `actual_journal_entry` | **实际分录表** | 总账/财务实际记账流水(事实表) |
|
|
52
|
+
| `budget_entry` | **预算表** | 预算编制明细(事实表) |
|
|
53
|
+
|
|
54
|
+
**辅助维表**:
|
|
55
|
+
|
|
56
|
+
| 表名 | 中文名 | 角色 |
|
|
57
|
+
| ----------------------- | ------------ | ------------------------ |
|
|
58
|
+
| `cost_center_dimension` | 成本中心维表 | 组织/部门/利润中心主数据 |
|
|
59
|
+
|
|
60
|
+
> 规划原则:先定义**业务对象**(Account、JournalEntry、BudgetLine 等)与**链接**,再反推物理表。
|
|
61
|
+
> **实际分录**承载「实际发生」;**预算表**承载「计划数」;**科目表**统一语义与损益口径(收入/成本/费用)。
|
|
62
|
+
> 旧版示例中的 `profit_analysis_fact`(订单粒度收入/成本)**不作为本方案主模型**;若需订单维度利润,可另建与销售域的映射函数,不替代 GL 分录。
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## 三、物理层设计
|
|
67
|
+
|
|
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
|
|
195
|
+
|
|
196
|
+
### 3.5 表间关系设计(物理层 · 数据空间)
|
|
197
|
+
|
|
198
|
+
> **与本体链接的区别**:本节描述 **ClickHouse 物理表 FK/JOIN**,供侧栏 **数据资源 → 表间关系** 与 AI 多表 JOIN。本体链接见第五节。
|
|
199
|
+
|
|
200
|
+
**关系模型**:
|
|
201
|
+
|
|
202
|
+
```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(自关联,科目树)
|
|
218
|
+
```
|
|
219
|
+
|
|
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 时加期间条件) |
|
|
230
|
+
|
|
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。
|
|
234
|
+
|
|
235
|
+
**实施 API**(`setup/profit_ontology_init.py`):
|
|
236
|
+
|
|
237
|
+
```python
|
|
238
|
+
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",
|
|
242
|
+
join_keys=[{"from": "account_id", "to": "account_id"}],
|
|
243
|
+
relationship_type="many_to_one",
|
|
244
|
+
description="实际分录关联会计科目",
|
|
245
|
+
)
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
**与本体链接对照**:
|
|
249
|
+
|
|
250
|
+
| 物理表关系 | 对应本体链接(业务层) |
|
|
251
|
+
| ---------------------- | ------------------------- |
|
|
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 |
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
## 四、Cube 层设计
|
|
262
|
+
|
|
263
|
+
### 4.1 ActualCube(实际发生主 Cube)
|
|
264
|
+
|
|
265
|
+
**事实源**:`actual_journal_entry`
|
|
266
|
+
|
|
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
|
|
268
|
+
|
|
269
|
+
**度量**:
|
|
270
|
+
|
|
271
|
+
| 度量名 | 列名 | 聚合 | 说明 |
|
|
272
|
+
| ------------ | ------------- | ----- | ---------- |
|
|
273
|
+
| debit_total | debit_amount | sum | 借方合计 |
|
|
274
|
+
| credit_total | credit_amount | sum | 贷方合计 |
|
|
275
|
+
| net_amount | amount_signed | sum | 损益符号额 |
|
|
276
|
+
| line_count | line_id | count | 分录行数 |
|
|
277
|
+
|
|
278
|
+
**派生度量**(按科目类型切片,表达式示意):
|
|
279
|
+
|
|
280
|
+
| 度量名 | 表达式(示意) | 说明 |
|
|
281
|
+
| ---------------- | ------------------------------------------ | -------- |
|
|
282
|
+
| revenue | sumIf(amount_signed, account_type='收入') | 收入 |
|
|
283
|
+
| cost | sumIf(amount_signed, account_type='成本') | 营业成本 |
|
|
284
|
+
| expense | sumIf(amount_signed, account_type='费用') | 期间费用 |
|
|
285
|
+
| operating_profit | revenue - cost - expense | 营业利润 |
|
|
286
|
+
| profit_margin | if(revenue>0, operating_profit/revenue, 0) | 利润率 |
|
|
287
|
+
|
|
288
|
+
### 4.2 AccountActualCube(科目实际 Cube)
|
|
289
|
+
|
|
290
|
+
**目的**:Account 对象 bind_source
|
|
291
|
+
|
|
292
|
+
**维度**:account_id, account_code, account_name, account_type, pl_category, account_level, fiscal_year, fiscal_period
|
|
293
|
+
|
|
294
|
+
**度量**:net_amount, line_count
|
|
295
|
+
|
|
296
|
+
**派生度量**:revenue, cost, expense(同上,按 account_type 聚合)
|
|
297
|
+
|
|
298
|
+
### 4.3 CostCenterActualCube(成本中心实际 Cube)
|
|
299
|
+
|
|
300
|
+
**维度**:cost_center_id, cost_center_name, department, profit_center, fiscal_year, fiscal_period
|
|
301
|
+
|
|
302
|
+
**度量**:net_amount, line_count
|
|
303
|
+
|
|
304
|
+
**派生度量**:revenue, cost, expense, operating_profit, profit_margin
|
|
305
|
+
|
|
306
|
+
### 4.4 BudgetCube(预算 Cube)
|
|
307
|
+
|
|
308
|
+
**事实源**:`budget_entry`
|
|
309
|
+
|
|
310
|
+
**维度**:budget_version, fiscal_year, fiscal_period, account_id, account_code, account_type, pl_category, cost_center_id, department
|
|
311
|
+
|
|
312
|
+
**度量**:
|
|
313
|
+
|
|
314
|
+
| 度量名 | 列名 | 聚合 | 说明 |
|
|
315
|
+
| ------------- | ------------- | ----- | -------- |
|
|
316
|
+
| budget_amount | budget_amount | sum | 预算金额 |
|
|
317
|
+
| budget_lines | line_id | count | 预算行数 |
|
|
318
|
+
|
|
319
|
+
**派生度量**:budget_revenue / budget_cost / budget_expense(按 account_type 切片,同 ActualCube 逻辑)
|
|
320
|
+
|
|
321
|
+
### 4.5 TimeActualCube(时间维度 Cube)
|
|
322
|
+
|
|
323
|
+
**维度**:posting_date, fiscal_year, fiscal_period, year_month, quarter
|
|
324
|
+
|
|
325
|
+
**度量**:net_amount, revenue, cost, expense, operating_profit(派生)
|
|
326
|
+
|
|
327
|
+
---
|
|
328
|
+
|
|
329
|
+
## 五、本体层设计
|
|
330
|
+
|
|
331
|
+
### 5.1 对象类型(6 种)
|
|
332
|
+
|
|
333
|
+
| 对象类型 code | 名称 | 说明 | bind_source |
|
|
334
|
+
| -------------- | -------- | ----------------------- | -------------------- |
|
|
335
|
+
| Account | 会计科目 | 科目业务对象 | AccountActualCube |
|
|
336
|
+
| CostCenter | 成本中心 | 组织/利润中心业务对象 | CostCenterActualCube |
|
|
337
|
+
| JournalEntry | 实际分录 | 凭证行/实际发生业务对象 | ActualCube |
|
|
338
|
+
| BudgetLine | 预算行 | 预算编制明细业务对象 | BudgetCube |
|
|
339
|
+
| ProfitAnalysis | 利润分析 | 多维度损益指标聚合对象 | ActualCube |
|
|
340
|
+
| BudgetAnalysis | 预算分析 | 预算执行与差异分析对象 | BudgetCube |
|
|
341
|
+
|
|
342
|
+
> 对象类型 `code` 使用稳定英文标识;与表名、Cube 名刻意区分。
|
|
343
|
+
|
|
344
|
+
### 5.2 对象属性(摘要)
|
|
345
|
+
|
|
346
|
+
#### Account(会计科目)
|
|
347
|
+
|
|
348
|
+
| 属性 code | 名称 | semantic_role | qualified_name |
|
|
349
|
+
| ----------- | -------- | ------------- | ------------------------------- |
|
|
350
|
+
| id | 科目 ID | dimension | AccountActualCube.account_id |
|
|
351
|
+
| code | 科目编码 | dimension | AccountActualCube.account_code |
|
|
352
|
+
| name | 科目名称 | dimension | AccountActualCube.account_name |
|
|
353
|
+
| type | 科目类型 | dimension | AccountActualCube.account_type |
|
|
354
|
+
| pl_category | 损益大类 | dimension | AccountActualCube.pl_category |
|
|
355
|
+
| level | 科目层级 | dimension | AccountActualCube.account_level |
|
|
356
|
+
| net_amount | 实际发生 | measure | AccountActualCube.net_amount |
|
|
357
|
+
| revenue | 收入 | measure | AccountActualCube.revenue |
|
|
358
|
+
| cost | 成本 | measure | AccountActualCube.cost |
|
|
359
|
+
| expense | 费用 | measure | AccountActualCube.expense |
|
|
360
|
+
|
|
361
|
+
#### JournalEntry(实际分录)
|
|
362
|
+
|
|
363
|
+
| 属性 code | 名称 | semantic_role | qualified_name |
|
|
364
|
+
| ------------- | -------- | ------------- | ------------------------ |
|
|
365
|
+
| id | 行 ID | dimension | ActualCube.line_id |
|
|
366
|
+
| posting_date | 记账日期 | dimension | ActualCube.posting_date |
|
|
367
|
+
| fiscal_period | 会计期间 | dimension | ActualCube.fiscal_period |
|
|
368
|
+
| net_amount | 损益金额 | measure | ActualCube.net_amount |
|
|
369
|
+
| debit | 借方 | measure | ActualCube.debit_total |
|
|
370
|
+
| credit | 贷方 | measure | ActualCube.credit_total |
|
|
371
|
+
|
|
372
|
+
#### BudgetLine(预算行)
|
|
373
|
+
|
|
374
|
+
| 属性 code | 名称 | semantic_role | qualified_name |
|
|
375
|
+
| ------------- | --------- | ------------- | ------------------------- |
|
|
376
|
+
| id | 预算行 ID | dimension | BudgetCube.line_id |
|
|
377
|
+
| version | 预算版本 | dimension | BudgetCube.budget_version |
|
|
378
|
+
| fiscal_period | 预算期间 | dimension | BudgetCube.fiscal_period |
|
|
379
|
+
| budget_amount | 预算金额 | measure | BudgetCube.budget_amount |
|
|
380
|
+
|
|
381
|
+
#### CostCenter / ProfitAnalysis / BudgetAnalysis
|
|
382
|
+
|
|
383
|
+
与 Cube 维/度量映射一致(约 **42** 个属性,实施时参照 init 脚本)。
|
|
384
|
+
|
|
385
|
+
### 5.3 链接类型(10 种)
|
|
386
|
+
|
|
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 | 成本中心利润贡献 |
|
|
399
|
+
|
|
400
|
+
---
|
|
401
|
+
|
|
402
|
+
## 六、本体函数设计
|
|
403
|
+
|
|
404
|
+
### 6.1 函数清单
|
|
405
|
+
|
|
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(可选) |
|
|
415
|
+
|
|
416
|
+
> 旧示例中的 `profit.fn.top_products`、`profit.fn.customer_segmentation` 属**订单/产品域**,本方案以 GL 为主,**不纳入**默认函数集;若需产品利润,可单独增加 `profit.fn.sales_reconciliation` 勾稽销售表。
|
|
417
|
+
|
|
418
|
+
### 6.2 函数示例:profit.fn.get_summary
|
|
419
|
+
|
|
420
|
+
**功能**:期间损益总览(基于实际分录)
|
|
421
|
+
|
|
422
|
+
**返回值**:
|
|
423
|
+
|
|
424
|
+
| 字段名 | 类型 | 说明 |
|
|
425
|
+
| ---------------- | ------- | -------- |
|
|
426
|
+
| total_revenue | Float64 | 总收入 |
|
|
427
|
+
| total_cost | Float64 | 总成本 |
|
|
428
|
+
| total_expense | Float64 | 总费用 |
|
|
429
|
+
| operating_profit | Float64 | 营业利润 |
|
|
430
|
+
| profit_margin | Float64 | 利润率 |
|
|
431
|
+
| line_count | Int | 分录行数 |
|
|
432
|
+
|
|
433
|
+
### 6.3 函数示例:profit.fn.budget_vs_actual
|
|
434
|
+
|
|
435
|
+
**功能**:按科目/成本中心对比预算与实际,输出差异与执行率
|
|
436
|
+
|
|
437
|
+
**参数**:fiscal_year, fiscal_period(可选 0=全年), budget_version, cost_center_id(可选)
|
|
438
|
+
|
|
439
|
+
**返回值**:
|
|
440
|
+
|
|
441
|
+
| 字段名 | 类型 | 说明 |
|
|
442
|
+
| ---------------- | ------- | ---------------------------------------- |
|
|
443
|
+
| account_code | String | 科目编码 |
|
|
444
|
+
| account_name | String | 科目名称 |
|
|
445
|
+
| pl_category | String | 损益大类 |
|
|
446
|
+
| cost_center_name | String | 成本中心 |
|
|
447
|
+
| budget_amount | Float64 | 预算额 |
|
|
448
|
+
| actual_amount | Float64 | 实际额 |
|
|
449
|
+
| variance | Float64 | 差异(实际-预算,收入/利润类为正向有利) |
|
|
450
|
+
| execution_rate | Float64 | 执行率(实际/预算) |
|
|
451
|
+
|
|
452
|
+
### 6.4 函数示例:profit.fn.account_breakdown
|
|
453
|
+
|
|
454
|
+
**功能**:按科目层级展开损益结构(树形或扁平)
|
|
455
|
+
|
|
456
|
+
**返回值**:account_code, account_name, account_level, pl_category, revenue, cost, expense, net_impact, share_pct
|
|
457
|
+
|
|
458
|
+
### 6.5 测试参数(test_arguments)
|
|
459
|
+
|
|
460
|
+
| 函数 ID | test_arguments 文件 | 默认 arguments 要点 |
|
|
461
|
+
| ---------------------------- | ----------------------------------------------------- | --------------------------------------------- |
|
|
462
|
+
| profit.fn.get_summary | `functions/test_arguments/profit.fn.get_summary.json` | 2025-01-01 ~ 2026-06-30 |
|
|
463
|
+
| profit.fn.yoy_analysis | `.../profit.fn.yoy_analysis.json` | 同上 |
|
|
464
|
+
| profit.fn.mom_analysis | `.../profit.fn.mom_analysis.json` | 同上 |
|
|
465
|
+
| profit.fn.budget_vs_actual | `.../profit.fn.budget_vs_actual.json` | fiscal_year=2026, budget_version=2026年度预算 |
|
|
466
|
+
| profit.fn.account_breakdown | `.../profit.fn.account_breakdown.json` | account_level=2 |
|
|
467
|
+
| profit.fn.cost_center_profit | `.../profit.fn.cost_center_profit.json` | 日期范围 |
|
|
468
|
+
| profit.fn.top_accounts | `.../profit.fn.top_accounts.json` | limit=10, metric=net_impact |
|
|
469
|
+
|
|
470
|
+
> 内置示例路径:`资源/examples/onto/利润示例/function/test_arguments/`(复制到实现单元 `functions/test_arguments/`)。
|
|
471
|
+
|
|
472
|
+
批量入库(实现单元 `functions/` 下,dazi-work 根):
|
|
473
|
+
|
|
474
|
+
```powershell
|
|
475
|
+
.\项目\潘达石化\本体\ontos\利润分析本体方案\functions\save_test_arguments.ps1
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
> 参考实现:`资源/examples/onto/利润示例/`(init + seed + 7 个 `profit_fn_*.py` + test_arguments)。
|
|
479
|
+
|
|
480
|
+
---
|
|
481
|
+
|
|
482
|
+
## 七、实施计划
|
|
483
|
+
|
|
484
|
+
> **dazi-vscode v3** · 空间 `space__zlj` · 脚本目录 `setup/`、`functions/`
|
|
485
|
+
> 发布示例:
|
|
486
|
+
> `dazi onto script publish 项目/潘达石化/本体/ontos/利润分析本体方案/setup/profit_ontology_init.py --space space__zlj --type setup`
|
|
487
|
+
|
|
488
|
+
### 7.1 阶段一:物理层(高)
|
|
489
|
+
|
|
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 |
|
|
498
|
+
|
|
499
|
+
### 7.2 阶段二:Cube 层(高)
|
|
500
|
+
|
|
501
|
+
| 步骤 | 任务 |
|
|
502
|
+
| ---- | -------------------------------------------------- |
|
|
503
|
+
| 7 | 注册 ActualCube / AccountActualCube 等 5 个 Cube |
|
|
504
|
+
| 8 | 配置派生度量 revenue/cost/expense/operating_profit |
|
|
505
|
+
|
|
506
|
+
### 7.3 阶段三:本体层(高)
|
|
507
|
+
|
|
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 |
|
|
515
|
+
|
|
516
|
+
### 7.4 阶段四:函数与数据(中)
|
|
517
|
+
|
|
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 |
|
|
523
|
+
|
|
524
|
+
### 7.5 快速实施路径
|
|
525
|
+
|
|
526
|
+
| 来源 | 可复用内容 | 需改造 |
|
|
527
|
+
| ---------------------------------------------------------- | --------------------------------- | ------------------------------ |
|
|
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 工程模式 | 表结构与函数逻辑不同 |
|
|
532
|
+
|
|
533
|
+
**seed 数据建议**:
|
|
534
|
+
|
|
535
|
+
- 科目:一级 4–6 个(收入/成本/费用),二级 15–20 个
|
|
536
|
+
- 成本中心:5–8 个(生产/销售/管理/财务等)
|
|
537
|
+
- 实际分录:2025-01 ~ 2026-06 按月随机凭证,2000+ 行
|
|
538
|
+
- 预算:同科目×成本中心×12 期,与 actual 同维便于预实对比
|
|
539
|
+
|
|
540
|
+
---
|
|
541
|
+
|
|
542
|
+
## 八、风险与验收
|
|
543
|
+
|
|
544
|
+
### 8.1 风险
|
|
545
|
+
|
|
546
|
+
| 等级 | 风险 | 缓解措施 |
|
|
547
|
+
| ---- | ------------------------- | ------------------------------------------- |
|
|
548
|
+
| 中 | 与销售域共用 space\_\_zlj | init 仅创建利润域 4 表 |
|
|
549
|
+
| 中 | 借贷方向与符号口径不一致 | seed 统一计算 `amount_signed`;文档约定口径 |
|
|
550
|
+
| 中 | 预实 JOIN 期间粒度不一致 | budget/actual 均含 fiscal_year/period |
|
|
551
|
+
| 低 | 旧示例订单模型混淆 | 规划与函数 ID 明确以 GL 为准 |
|
|
552
|
+
|
|
553
|
+
### 8.2 验收标准
|
|
554
|
+
|
|
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 可运行 |
|
|
564
|
+
| 数据 | 种子灌入后预实差异可解释 |
|
|
565
|
+
|
|
566
|
+
---
|
|
567
|
+
|
|
568
|
+
## 九、预期成果
|
|
569
|
+
|
|
570
|
+
| 分析能力 | 说明 |
|
|
571
|
+
| ------------ | ------------------------------ |
|
|
572
|
+
| 损益总览 | 收入/成本/费用/营业利润/利润率 |
|
|
573
|
+
| 科目结构 | 按层级与 pl_category 展开 |
|
|
574
|
+
| **预实分析** | 预算、实际、差异、执行率 |
|
|
575
|
+
| 组织利润 | 成本中心/部门贡献 |
|
|
576
|
+
| 趋势分析 | 同比、环比 |
|
|
577
|
+
| 科目排行 | Top N 异动科目 |
|
|
578
|
+
| 业务语义 | 科目—分录—预算—组织链接可导航 |
|
|
579
|
+
|
|
580
|
+
---
|
|
581
|
+
|
|
582
|
+
## 十、相关文档
|
|
583
|
+
|
|
584
|
+
| 文档 | 路径 |
|
|
585
|
+
| ---------------------------------- | ----------------------------------------------------------------------------- |
|
|
586
|
+
| 快速启动 | [../快速启动\_利润分析本体方案.md](../快速启动_利润分析本体方案.md) |
|
|
587
|
+
| 本体规划指南 | `资源/docs/onto/本体规划指南.md` |
|
|
588
|
+
| 规划示例(产品销售,推荐工程模式) | `资源/docs/onto/规划示例_产品销售本体规划方案.md` |
|
|
589
|
+
| 规划示例(利润·GL 域) | `资源/docs/onto/规划示例_利润分析本体方案.md` |
|
|
590
|
+
| **内置脚本示例** | `资源/examples/onto/利润示例/`(`dazi examples sync`) |
|
|
591
|
+
|
|
592
|
+
---
|
|
593
|
+
|
|
594
|
+
**方案版本**:v2.0
|
|
595
|
+
**创建日期**:2026-06-06
|
|
596
|
+
**适用空间**:`space__zlj`
|
|
597
|
+
**状态**:已落地
|