@dazitech/cli 3.0.7 → 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.
- 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 +73 -22
- package/dist/clis/dazi.js +266 -171
- package/dist/docs/flow/flow-project-guide.md +1 -1
- package/dist/docs/guides/quickstart.md +18 -4
- package/dist/docs/guides/troubleshooting.md +12 -1
- package/dist/docs/guides/workspace-v3.md +43 -23
- package/dist/docs/index.json +28 -3
- package/dist/docs/onto/action-guide.md +3 -3
- package/dist/docs/onto/dazi_script_sdk_reference.md +244 -174
- package/dist/docs/onto/dazi_script_seed_data_guide.md +158 -155
- package/dist/docs/onto/function-guide.md +82 -27
- package/dist/docs/onto/space-management.md +3 -1
- 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
- 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/350/204/232/346/234/254/347/274/226/345/206/231/346/214/207/345/215/227.md +200 -34
- package/dist/docs/onto//346/234/254/344/275/223/350/247/204/345/210/222/346/214/207/345/215/227.md +188 -38
- 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
- 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 +620 -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 +680 -541
- package/dist/examples/index.json +208 -22
- package/dist/examples/onto/README.md +51 -0
- 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_ontology_init.py +679 -0
- package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_seed_data.py +216 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_channel_mix.py +89 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_customer_segmentation.py +121 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_get_summary.py +78 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_mom_analysis.py +89 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_region_breakdown.py +84 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_top_products.py +98 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_yoy_analysis.py +87 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/save_test_arguments.ps1 +38 -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 +5 -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 +5 -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 +5 -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 +5 -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 +5 -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 +5 -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 +5 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_ontology_init.py +539 -0
- package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_seed_data.py +163 -0
- package/dist/prompts/index.json +2 -2
- package/dist/prompts/onto/action-design.md +4 -1
- package/dist/prompts/onto/function-design.md +46 -19
- package/dist/prompts/onto/rule-seed.md +5 -1
- package/dist/prompts/onto/script-publish-run.md +87 -25
- 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,680 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
|
11
|
-
|
|
|
12
|
-
|
|
|
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
|
-
|
|
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
|
+
**文档 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/<实现名>` |
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## 一、空间概述
|
|
20
|
+
|
|
21
|
+
| 项目 | 说明 |
|
|
22
|
+
| -------- | ---- |
|
|
23
|
+
| 空间 ID | `<space-id>`(示例:`space__acme`) |
|
|
24
|
+
| 空间名称 | `<空间名称>`(与平台数据空间显示名一致) |
|
|
25
|
+
| 空间状态 | 可与销售等其他域**共用**同一 `<space-id>`;利润域表/Cube/对象独立建设 |
|
|
26
|
+
| 规划日期 | (填写定稿日期) |
|
|
27
|
+
| 实现单元 | `<item-path>/` |
|
|
28
|
+
|
|
29
|
+
> **共存说明**:本空间可能已有销售域 `dim_product`、`fact_sales_order_line` 等表。利润域 init **仅**创建/注册本域表;若 **`dim_date`** 已存在则 **ensure** 不重复建表。
|
|
30
|
+
> **与销售域关系**:销售收入可通过科目映射与实际分录对齐;勾稽函数可 LEFT JOIN `fact_sales_order_line`,**本体对象不以订单为主锚点**。
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## 二、需求分析
|
|
35
|
+
|
|
36
|
+
### 2.1 业务背景
|
|
37
|
+
|
|
38
|
+
某制造企业(示例)财务利润分析场景,需构建**利润分析本体**,以业务语言描述「会计科目」「实际分录」「预算」及其关系,支撑:
|
|
39
|
+
|
|
40
|
+
- **损益总览**:收入、成本、费用、营业利润、利润率
|
|
41
|
+
- **科目结构**:按科目层级展开收入/成本/费用构成
|
|
42
|
+
- **实际 vs 预算**:按期间、科目、成本中心的预算执行率与差异分析
|
|
43
|
+
- **组织维度**:按成本中心/部门贡献与超支预警
|
|
44
|
+
- **趋势分析**:同比、环比利润与关键科目走势
|
|
45
|
+
- **归因分析**:利润变动由哪些科目/组织驱动
|
|
46
|
+
|
|
47
|
+
### 2.2 核心业务问题
|
|
48
|
+
|
|
49
|
+
| 问题 | 说明 |
|
|
50
|
+
| --------------- | ------------------------------ |
|
|
51
|
+
| 利润是多少 | 期间营业利润、利润率 |
|
|
52
|
+
| 钱从哪来/到哪去 | 收入、成本、费用科目结构 |
|
|
53
|
+
| 预算执行如何 | 预算额、实际额、差异额、执行率 |
|
|
54
|
+
| 哪个部门拖后腿 | 成本中心维度利润与预算偏差 |
|
|
55
|
+
| 哪些科目异常 | 科目 Top N、同比/环比异动 |
|
|
56
|
+
| 趋势如何 | 按月/季/年利润与关键科目走势 |
|
|
57
|
+
|
|
58
|
+
### 2.3 规划范围说明
|
|
59
|
+
|
|
60
|
+
**物理表清单**(命名见 [命名规范 §2](./本体命名规范_物理表Cube与对象.md#2-物理表类别与前缀)):
|
|
61
|
+
|
|
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 |
|
|
69
|
+
|
|
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)。
|
|
72
|
+
|
|
73
|
+
## 三、物理层设计
|
|
74
|
+
|
|
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)`
|
|
176
|
+
|
|
177
|
+
### 3.5 表间关系设计(物理层 · 数据空间)
|
|
178
|
+
|
|
179
|
+
> **与本体链接的区别**:本节描述 **ClickHouse 物理表 FK/JOIN**,供侧栏 **数据资源 → 表间关系** 与 AI 多表 JOIN。本体链接见第五节。
|
|
180
|
+
|
|
181
|
+
**关系模型**:
|
|
182
|
+
|
|
183
|
+
```text
|
|
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(自关联)
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
**关系清单(8 条)**:
|
|
205
|
+
|
|
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 待补**) |
|
|
216
|
+
|
|
217
|
+
**实施 API**(`setup/profit_ontology_init.py`):
|
|
218
|
+
|
|
219
|
+
```python
|
|
220
|
+
s.tables.add_relationship(
|
|
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",
|
|
224
|
+
join_keys=[{"from": "account_id", "to": "account_id"}],
|
|
225
|
+
relationship_type="many_to_one",
|
|
226
|
+
description="实际分录关联会计科目",
|
|
227
|
+
)
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
**与本体链接对照**:
|
|
231
|
+
|
|
232
|
+
| 物理表关系 | 对应本体链接(业务层) |
|
|
233
|
+
| ---------------------- | ------------------------- |
|
|
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 |
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## 四、Cube 层设计
|
|
244
|
+
|
|
245
|
+
### 4.0 Cube 清单与类别
|
|
246
|
+
|
|
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 待补**) |
|
|
255
|
+
|
|
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
|
|
263
|
+
|
|
264
|
+
**度量**:
|
|
265
|
+
|
|
266
|
+
| 度量名 | 列名 | 聚合 | 说明 |
|
|
267
|
+
| ------------ | ------------- | ----- | ---------- |
|
|
268
|
+
| debit_total | debit_amount | sum | 借方合计 |
|
|
269
|
+
| credit_total | credit_amount | sum | 贷方合计 |
|
|
270
|
+
| net_amount | amount_signed | sum | 损益符号额 |
|
|
271
|
+
| line_count | line_id | count | 分录行数 |
|
|
272
|
+
|
|
273
|
+
**派生度量**(按科目类型切片,表达式示意):
|
|
274
|
+
|
|
275
|
+
| 度量名 | 表达式(示意) | 说明 |
|
|
276
|
+
| ---------------- | ------------------------------------------ | -------- |
|
|
277
|
+
| revenue | sumIf(amount_signed, account_type='收入') | 收入 |
|
|
278
|
+
| cost | sumIf(amount_signed, account_type='成本') | 营业成本 |
|
|
279
|
+
| expense | sumIf(amount_signed, account_type='费用') | 期间费用 |
|
|
280
|
+
| operating_profit | revenue - cost - expense | 营业利润 |
|
|
281
|
+
| profit_margin | if(revenue>0, operating_profit/revenue, 0) | 利润率 |
|
|
282
|
+
|
|
283
|
+
### 4.2 AccountActualCube(Subject · 科目实际)
|
|
284
|
+
|
|
285
|
+
**目的**:Account 对象 bind_source
|
|
286
|
+
|
|
287
|
+
**维度**:account_id, account_code, account_name, account_type, pl_category, account_level, fiscal_year, fiscal_period, year, month
|
|
288
|
+
|
|
289
|
+
**度量**:net_amount, line_count
|
|
290
|
+
|
|
291
|
+
**派生度量**:revenue, cost, expense
|
|
292
|
+
|
|
293
|
+
### 4.3 CostCenterActualCube(Subject · 成本中心实际)
|
|
294
|
+
|
|
295
|
+
**维度**:cost_center_id, cost_center_name, department, profit_center, fiscal_year, fiscal_period, year, month
|
|
296
|
+
|
|
297
|
+
**度量**:net_amount, line_count
|
|
298
|
+
|
|
299
|
+
**派生度量**:revenue, cost, expense, operating_profit, profit_margin
|
|
300
|
+
|
|
301
|
+
### 4.4 BudgetCube(Process · 预算)
|
|
302
|
+
|
|
303
|
+
**事实源**:`fact_budget_entry`
|
|
304
|
+
|
|
305
|
+
**维度**:budget_version, fiscal_year, fiscal_period, date_key, account_id, account_code, account_type, pl_category, cost_center_id, department
|
|
306
|
+
|
|
307
|
+
**度量**:budget_amount(sum), budget_lines(count)
|
|
308
|
+
|
|
309
|
+
**派生度量**:budget_revenue / budget_cost / budget_expense(按 account_type 切片)
|
|
310
|
+
|
|
311
|
+
### 4.5 BudgetVsActualCube(Comparison · 预实对比)
|
|
312
|
+
|
|
313
|
+
**目的**:`profit.fn.budget_vs_actual` 读模型;JOIN budget 与 actual 同维(account + cost_center + fiscal_period)
|
|
314
|
+
|
|
315
|
+
**维度**:fiscal_year, fiscal_period, account_id, cost_center_id, budget_version
|
|
316
|
+
|
|
317
|
+
**度量**:budget_amount, actual_amount(来自 ActualCube 聚合), variance, execution_rate(派生)
|
|
318
|
+
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
## 五、本体层设计
|
|
322
|
+
|
|
323
|
+
### 5.1 对象类型(6 种)
|
|
324
|
+
|
|
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 |
|
|
333
|
+
|
|
334
|
+
> 对象 **`code` 无前缀**;分类见 [命名规范 §5.3](./本体命名规范_物理表Cube与对象.md#53-对象分类无-code-前缀)。
|
|
335
|
+
|
|
336
|
+
### 5.2 对象属性(摘要)
|
|
337
|
+
|
|
338
|
+
#### Account(会计科目)
|
|
339
|
+
|
|
340
|
+
| 属性 code | 名称 | semantic_role | qualified_name |
|
|
341
|
+
| ----------- | -------- | ------------- | ------------------------------- |
|
|
342
|
+
| id | 科目 ID | dimension | AccountActualCube.account_id |
|
|
343
|
+
| code | 科目编码 | dimension | AccountActualCube.account_code |
|
|
344
|
+
| name | 科目名称 | dimension | AccountActualCube.account_name |
|
|
345
|
+
| type | 科目类型 | dimension | AccountActualCube.account_type |
|
|
346
|
+
| pl_category | 损益大类 | dimension | AccountActualCube.pl_category |
|
|
347
|
+
| level | 科目层级 | dimension | AccountActualCube.account_level |
|
|
348
|
+
| net_amount | 实际发生 | measure | AccountActualCube.net_amount |
|
|
349
|
+
| revenue | 收入 | measure | AccountActualCube.revenue |
|
|
350
|
+
| cost | 成本 | measure | AccountActualCube.cost |
|
|
351
|
+
| expense | 费用 | measure | AccountActualCube.expense |
|
|
352
|
+
|
|
353
|
+
#### JournalEntry(实际分录)
|
|
354
|
+
|
|
355
|
+
| 属性 code | 名称 | semantic_role | qualified_name |
|
|
356
|
+
| ------------- | -------- | ------------- | ------------------------ |
|
|
357
|
+
| id | 行 ID | dimension | ActualCube.line_id |
|
|
358
|
+
| posting_date | 记账日期 | dimension | ActualCube.posting_date |
|
|
359
|
+
| fiscal_period | 会计期间 | dimension | ActualCube.fiscal_period |
|
|
360
|
+
| net_amount | 损益金额 | measure | ActualCube.net_amount |
|
|
361
|
+
| debit | 借方 | measure | ActualCube.debit_total |
|
|
362
|
+
| credit | 贷方 | measure | ActualCube.credit_total |
|
|
363
|
+
|
|
364
|
+
#### BudgetLine(预算行)
|
|
365
|
+
|
|
366
|
+
| 属性 code | 名称 | semantic_role | qualified_name |
|
|
367
|
+
| ------------- | --------- | ------------- | ------------------------- |
|
|
368
|
+
| id | 预算行 ID | dimension | BudgetCube.line_id |
|
|
369
|
+
| version | 预算版本 | dimension | BudgetCube.budget_version |
|
|
370
|
+
| fiscal_period | 预算期间 | dimension | BudgetCube.fiscal_period |
|
|
371
|
+
| budget_amount | 预算金额 | measure | BudgetCube.budget_amount |
|
|
372
|
+
|
|
373
|
+
#### CostCenter / ProfitAnalysis / BudgetAnalysis
|
|
374
|
+
|
|
375
|
+
与 Cube 维/度量映射一致(约 **42** 个属性);实施参照 `利润示例/setup/profit_ontology_init.py`(表名按本规划迁移)。
|
|
376
|
+
|
|
377
|
+
### 5.3 链接类型(10 种)
|
|
378
|
+
|
|
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 |
|
|
403
|
+
|
|
404
|
+
---
|
|
405
|
+
|
|
406
|
+
## 六、本体函数设计
|
|
407
|
+
|
|
408
|
+
### 6.1 函数清单
|
|
409
|
+
|
|
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(可选) |
|
|
419
|
+
|
|
420
|
+
> 旧示例中的 `profit.fn.top_products`、`profit.fn.customer_segmentation` 属**订单/产品域**,本方案以 GL 为主,**不纳入**默认函数集;若需产品利润,可单独增加 `profit.fn.sales_reconciliation` 勾稽销售表。
|
|
421
|
+
|
|
422
|
+
### 6.2 函数示例:profit.fn.get_summary
|
|
423
|
+
|
|
424
|
+
**功能**:期间损益总览(基于实际分录)
|
|
425
|
+
|
|
426
|
+
**返回值**:
|
|
427
|
+
|
|
428
|
+
| 字段名 | 类型 | 说明 |
|
|
429
|
+
| ---------------- | ------- | -------- |
|
|
430
|
+
| total_revenue | Float64 | 总收入 |
|
|
431
|
+
| total_cost | Float64 | 总成本 |
|
|
432
|
+
| total_expense | Float64 | 总费用 |
|
|
433
|
+
| operating_profit | Float64 | 营业利润 |
|
|
434
|
+
| profit_margin | Float64 | 利润率 |
|
|
435
|
+
| line_count | Int | 分录行数 |
|
|
436
|
+
|
|
437
|
+
### 6.3 函数示例:profit.fn.budget_vs_actual
|
|
438
|
+
|
|
439
|
+
**功能**:按科目/成本中心对比预算与实际,输出差异与执行率
|
|
440
|
+
|
|
441
|
+
**参数**:fiscal_year, fiscal_period(可选 0=全年), budget_version, cost_center_id(可选)
|
|
442
|
+
|
|
443
|
+
**返回值**:
|
|
444
|
+
|
|
445
|
+
| 字段名 | 类型 | 说明 |
|
|
446
|
+
| ---------------- | ------- | ---------------------------------------- |
|
|
447
|
+
| account_code | String | 科目编码 |
|
|
448
|
+
| account_name | String | 科目名称 |
|
|
449
|
+
| pl_category | String | 损益大类 |
|
|
450
|
+
| cost_center_name | String | 成本中心 |
|
|
451
|
+
| budget_amount | Float64 | 预算额 |
|
|
452
|
+
| actual_amount | Float64 | 实际额 |
|
|
453
|
+
| variance | Float64 | 差异(实际-预算,收入/利润类为正向有利) |
|
|
454
|
+
| execution_rate | Float64 | 执行率(实际/预算) |
|
|
455
|
+
|
|
456
|
+
### 6.4 函数示例:profit.fn.account_breakdown
|
|
457
|
+
|
|
458
|
+
**功能**:按科目层级展开损益结构(树形或扁平)
|
|
459
|
+
|
|
460
|
+
**返回值**:account_code, account_name, account_level, pl_category, revenue, cost, expense, net_impact, share_pct
|
|
461
|
+
|
|
462
|
+
### 6.5 测试参数(test_arguments)
|
|
463
|
+
|
|
464
|
+
| 函数 ID | test_arguments 文件 | 默认 arguments 要点 |
|
|
465
|
+
| ---------------------------- | ----------------------------------------------------- | --------------------------------------------- |
|
|
466
|
+
| profit.fn.get_summary | `functions/test_arguments/profit.fn.get_summary.json` | 2025-01-01 ~ 2026-06-30 |
|
|
467
|
+
| profit.fn.yoy_analysis | `.../profit.fn.yoy_analysis.json` | 同上 |
|
|
468
|
+
| profit.fn.mom_analysis | `.../profit.fn.mom_analysis.json` | 同上 |
|
|
469
|
+
| profit.fn.budget_vs_actual | `.../profit.fn.budget_vs_actual.json` | fiscal_year=2026, budget_version=2026年度预算 |
|
|
470
|
+
| profit.fn.account_breakdown | `.../profit.fn.account_breakdown.json` | account_level=2 |
|
|
471
|
+
| profit.fn.cost_center_profit | `.../profit.fn.cost_center_profit.json` | 日期范围 |
|
|
472
|
+
| profit.fn.top_accounts | `.../profit.fn.top_accounts.json` | limit=10, metric=net_impact |
|
|
473
|
+
|
|
474
|
+
> 内置示例路径:`资源/examples/onto/利润示例/functions/test_arguments/`(复制到实现单元 `functions/test_arguments/`)。
|
|
475
|
+
|
|
476
|
+
批量入库(实现单元 `functions/` 下,dazi-work 根):
|
|
477
|
+
|
|
478
|
+
```powershell
|
|
479
|
+
.\<item-path>\functions\save_test_arguments.ps1
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
> 参考实现:`资源/examples/onto/利润示例/`(init + seed + 7 个 `profit_fn_*.py` + test_arguments)。
|
|
483
|
+
|
|
484
|
+
---
|
|
485
|
+
|
|
486
|
+
## 七、实施计划
|
|
487
|
+
|
|
488
|
+
> **dazi-vscode v3** · 空间 `<space-id>` · 脚本目录 `setup/`、`functions/`
|
|
489
|
+
> 发布示例:
|
|
490
|
+
> `dazi onto script publish <item-path>/setup/profit_ontology_init.py --space <space-id> --type setup`
|
|
491
|
+
|
|
492
|
+
### 7.1 阶段一:物理层(高)
|
|
493
|
+
|
|
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 |
|
|
503
|
+
|
|
504
|
+
### 7.2 阶段二:Cube 层(高)
|
|
505
|
+
|
|
506
|
+
| 步骤 | 任务 |
|
|
507
|
+
| ---- | ---- |
|
|
508
|
+
| 8 | 注册 **5 个 Cube**(含 BudgetVsActualCube;无 Time Cube) |
|
|
509
|
+
| 9 | 派生度量 revenue/cost/expense/operating_profit |
|
|
510
|
+
|
|
511
|
+
### 7.3 阶段三:本体层(高)
|
|
512
|
+
|
|
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 对齐) |
|
|
521
|
+
|
|
522
|
+
### 7.4 阶段四:函数与数据(中)
|
|
523
|
+
|
|
524
|
+
| 步骤 | 任务 |
|
|
525
|
+
| ---- | ---- |
|
|
526
|
+
| 15 | profit_ontology_init.py、profit_seed_data.py(含 dim_date / date_key) |
|
|
527
|
+
| 16 | 7 个 profit_fn_*.py |
|
|
528
|
+
| 17 | publish + run → save-test-arguments |
|
|
529
|
+
|
|
530
|
+
### 7.5 快速实施路径
|
|
531
|
+
|
|
532
|
+
| 来源 | 可复用内容 | 需改造 |
|
|
533
|
+
| ---------------------------------------------------------- | --------------------------------- | ------------------------------ |
|
|
534
|
+
| `资源/examples/onto/利润示例/` | init/seed/函数完整示例 | 复制到 `<item-path>/` 后改 `<space-id>` |
|
|
535
|
+
| [规划示例:产品销售](./规划示例_产品销售本体规划方案.md) | 工程模式对照 | 表结构与函数逻辑不同 |
|
|
536
|
+
|
|
537
|
+
**seed 数据建议**:
|
|
538
|
+
|
|
539
|
+
- 科目:一级 4–6 个(收入/成本/费用),二级 15–20 个
|
|
540
|
+
- 成本中心:5–8 个(生产/销售/管理/财务等)
|
|
541
|
+
- 实际分录:2025-01 ~ 2026-06 按月随机凭证,2000+ 行
|
|
542
|
+
- 预算:同科目×成本中心×12 期,与 actual 同维便于预实对比
|
|
543
|
+
|
|
544
|
+
---
|
|
545
|
+
|
|
546
|
+
## 八、风险与验收
|
|
547
|
+
|
|
548
|
+
### 8.1 风险
|
|
549
|
+
|
|
550
|
+
| 等级 | 风险 | 缓解措施 |
|
|
551
|
+
| ---- | ------------------------- | ------------------------------------------- |
|
|
552
|
+
| 中 | 多域共用 `<space-id>` | init 仅创建利润域表;**dim_date** 共用 ensure |
|
|
553
|
+
| 中 | 借贷方向与符号口径不一致 | seed 统一计算 `amount_signed`;文档约定口径 |
|
|
554
|
+
| 中 | 预实 JOIN 期间粒度不一致 | budget/actual 均含 fiscal_year/period |
|
|
555
|
+
| 低 | 旧示例订单模型混淆 | 规划与函数 ID 明确以 GL 为准 |
|
|
556
|
+
|
|
557
|
+
### 8.2 验收标准
|
|
558
|
+
|
|
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 可运行 |
|
|
571
|
+
| 数据 | 种子灌入后预实差异可解释 |
|
|
572
|
+
|
|
573
|
+
---
|
|
574
|
+
|
|
575
|
+
## 九、预期成果
|
|
576
|
+
|
|
577
|
+
| 分析能力 | 说明 |
|
|
578
|
+
| ------------ | ------------------------------ |
|
|
579
|
+
| 损益总览 | 收入/成本/费用/营业利润/利润率 |
|
|
580
|
+
| 科目结构 | 按层级与 pl_category 展开 |
|
|
581
|
+
| **预实分析** | 预算、实际、差异、执行率 |
|
|
582
|
+
| 组织利润 | 成本中心/部门贡献 |
|
|
583
|
+
| 趋势分析 | 同比、环比 |
|
|
584
|
+
| 科目排行 | Top N 异动科目 |
|
|
585
|
+
| 业务语义 | 科目—分录—预算—组织链接可导航 |
|
|
586
|
+
|
|
587
|
+
---
|
|
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
|
+
|
|
665
|
+
## 十、相关文档
|
|
666
|
+
|
|
667
|
+
| 文档 | 路径 |
|
|
668
|
+
| ---- | ---- |
|
|
669
|
+
| 本体命名规范 | [本体命名规范_物理表Cube与对象.md](./本体命名规范_物理表Cube与对象.md) |
|
|
670
|
+
| 本体规划指南 | [本体规划指南.md](./本体规划指南.md) |
|
|
671
|
+
| 规划示例(产品销售) | [规划示例_产品销售本体规划方案.md](./规划示例_产品销售本体规划方案.md) |
|
|
672
|
+
| **内置脚本示例** | `资源/examples/onto/利润示例/`(`dazi examples sync`;表名迁移中) |
|
|
673
|
+
| 349 · 分类方案 | [本体分类规划与 SDK 扩展方案](./本体分类规划与SDK扩展方案.md) |
|
|
674
|
+
|
|
675
|
+
---
|
|
676
|
+
|
|
677
|
+
**方案版本**:v2.2(+347 分类列与附录 B CATEGORY_REGISTRY)
|
|
678
|
+
**创建日期**:(定稿日)
|
|
679
|
+
**适用**:复制到 `<item-path>/plans/`;`<space-id>` 以该实现单元 `README.md` 为准
|
|
680
|
+
**状态**:规划示例(公共模板)
|