@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.
Files changed (70) hide show
  1. package/README.md +1 -1
  2. package/dist/clis/dazi-app.js +1 -1
  3. package/dist/clis/dazi-flow.js +1 -1
  4. package/dist/clis/dazi-onto.js +73 -22
  5. package/dist/clis/dazi.js +266 -171
  6. package/dist/docs/flow/flow-project-guide.md +1 -1
  7. package/dist/docs/guides/quickstart.md +18 -4
  8. package/dist/docs/guides/troubleshooting.md +12 -1
  9. package/dist/docs/guides/workspace-v3.md +43 -23
  10. package/dist/docs/index.json +28 -3
  11. package/dist/docs/onto/action-guide.md +3 -3
  12. package/dist/docs/onto/dazi_script_sdk_reference.md +244 -174
  13. package/dist/docs/onto/dazi_script_seed_data_guide.md +158 -155
  14. package/dist/docs/onto/function-guide.md +82 -27
  15. package/dist/docs/onto/space-management.md +3 -1
  16. 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
  17. 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
  18. 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
  19. 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
  20. 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
  21. 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
  22. 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
  23. package/dist/examples/index.json +208 -22
  24. package/dist/examples/onto/README.md +51 -0
  25. package/dist/examples/onto/_templates/ontology_function_template.py +50 -0
  26. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_account_breakdown.py +62 -0
  27. 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
  28. 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
  29. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_get_summary.py +61 -0
  30. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_mom_analysis.py +82 -0
  31. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_top_accounts.py +61 -0
  32. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/profit_fn_yoy_analysis.py +79 -0
  33. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/functions/save_test_arguments.ps1 +38 -0
  34. 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
  35. 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
  36. 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
  37. 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
  38. 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
  39. 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
  40. 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
  41. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_ontology_init.py +679 -0
  42. package/dist/examples/onto//345/210/251/346/266/246/347/244/272/344/276/213/setup/profit_seed_data.py +216 -0
  43. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_channel_mix.py +89 -0
  44. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_customer_segmentation.py +121 -0
  45. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_get_summary.py +78 -0
  46. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_mom_analysis.py +89 -0
  47. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_region_breakdown.py +84 -0
  48. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_top_products.py +98 -0
  49. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/sales_fn_yoy_analysis.py +87 -0
  50. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/functions/save_test_arguments.ps1 +38 -0
  51. 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
  52. 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
  53. 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
  54. 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
  55. 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
  56. 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
  57. 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
  58. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_ontology_init.py +539 -0
  59. package/dist/examples/onto//351/224/200/345/224/256/347/244/272/344/276/213/setup/sales_seed_data.py +163 -0
  60. package/dist/prompts/index.json +2 -2
  61. package/dist/prompts/onto/action-design.md +4 -1
  62. package/dist/prompts/onto/function-design.md +46 -19
  63. package/dist/prompts/onto/rule-seed.md +5 -1
  64. package/dist/prompts/onto/script-publish-run.md +87 -25
  65. package/package.json +1 -1
  66. package/dist/examples/onto/function/profit_fn_customer_segmentation.py +0 -117
  67. package/dist/examples/onto/function/profit_fn_mom_analysis.py +0 -89
  68. package/dist/examples/onto/function/profit_fn_top_products.py +0 -89
  69. package/dist/examples/onto/function/profit_fn_yoy_analysis.py +0 -89
  70. package/dist/examples/onto/setup/profit_ontology_init.py +0 -388
@@ -0,0 +1,82 @@
1
+ """环比分析函数
2
+
3
+ 功能:对比当期与上一期的利润指标变化
4
+ 参数:start_date, end_date
5
+
6
+ 放置:项目/DAZI_TEST/本体/ontos/利润分析示例/functions/profit_fn_mom_analysis.py
7
+ 发布:dazi onto script publish 项目/DAZI_TEST/本体/ontos/利润分析示例/functions/profit_fn_mom_analysis.py --space space__misc_01 --register-function-id profit.fn.mom_analysis
8
+ """
9
+
10
+ from datetime import datetime, timedelta
11
+ import calendar
12
+ import json
13
+
14
+
15
+ def _ontology_fn_body(p):
16
+ start_date = p.get("start_date", "2025-01-01")
17
+ end_date = p.get("end_date", datetime.now().strftime("%Y-%m-%d"))
18
+
19
+ start_dt = datetime.strptime(start_date, "%Y-%m-%d")
20
+ end_dt = datetime.strptime(end_date, "%Y-%m-%d")
21
+
22
+ days_diff = (end_dt - start_dt).days
23
+
24
+ prev_start = (start_dt - timedelta(days=days_diff)).strftime("%Y-%m-%d")
25
+ prev_end = (end_dt - timedelta(days=days_diff)).strftime("%Y-%m-%d")
26
+
27
+ output.print(f"当期: {start_date} ~ {end_date}")
28
+ output.print(f"上期: {prev_start} ~ {prev_end}")
29
+
30
+ def get_period_data(sd, ed):
31
+ sql = """
32
+ SELECT
33
+ sumIf(amount_signed, account_type='收入') as revenue,
34
+ sumIf(amount_signed, account_type='成本') as cost,
35
+ sumIf(amount_signed, account_type='费用') as expense
36
+ FROM fact_gl_journal_entry
37
+ WHERE posting_date >= '{sd}' AND posting_date <= '{ed}'
38
+ """.format(sd=sd, ed=ed)
39
+ result = p.space.sql.query_one(sql)
40
+ return {
41
+ "revenue": result.get("revenue", 0) or 0,
42
+ "cost": result.get("cost", 0) or 0,
43
+ "expense": result.get("expense", 0) or 0,
44
+ }
45
+
46
+ current = get_period_data(start_date, end_date)
47
+ previous = get_period_data(prev_start, prev_end)
48
+
49
+ current_profit = current["revenue"] - current["cost"] - current["expense"]
50
+ previous_profit = previous["revenue"] - previous["cost"] - previous["expense"]
51
+
52
+ def calc_mom(current, prev):
53
+ if prev == 0:
54
+ return 0 if current == 0 else None
55
+ return (current - prev) / prev
56
+
57
+ result = {
58
+ "period": f"{start_date} ~ {end_date}",
59
+ "previous_period": f"{prev_start} ~ {prev_end}",
60
+ "current": {
61
+ "revenue": round(current["revenue"], 2),
62
+ "cost": round(current["cost"], 2),
63
+ "expense": round(current["expense"], 2),
64
+ "operating_profit": round(current_profit, 2),
65
+ },
66
+ "previous": {
67
+ "revenue": round(previous["revenue"], 2),
68
+ "cost": round(previous["cost"], 2),
69
+ "expense": round(previous["expense"], 2),
70
+ "operating_profit": round(previous_profit, 2),
71
+ },
72
+ "mom": {
73
+ "revenue": round(calc_mom(current["revenue"], previous["revenue"]), 4) if calc_mom(current["revenue"], previous["revenue"]) is not None else None,
74
+ "cost": round(calc_mom(current["cost"], previous["cost"]), 4) if calc_mom(current["cost"], previous["cost"]) is not None else None,
75
+ "expense": round(calc_mom(current["expense"], previous["expense"]), 4) if calc_mom(current["expense"], previous["expense"]) is not None else None,
76
+ "operating_profit": round(calc_mom(current_profit, previous_profit), 4) if calc_mom(current_profit, previous_profit) is not None else None,
77
+ },
78
+ }
79
+
80
+ p.function_result(result)
81
+
82
+
@@ -0,0 +1,61 @@
1
+ """科目Top N分析函数
2
+
3
+ 功能:获取损益影响最大的前N个科目
4
+ 参数:limit(默认10), metric(net_impact/revenue/cost/expense), start_date, end_date, account_type(可选)
5
+
6
+ 放置:项目/DAZI_TEST/本体/ontos/利润分析示例/functions/profit_fn_top_accounts.py
7
+ 发布:dazi onto script publish 项目/DAZI_TEST/本体/ontos/利润分析示例/functions/profit_fn_top_accounts.py --space space__misc_01 --register-function-id profit.fn.top_accounts
8
+ """
9
+
10
+ from datetime import datetime
11
+ import json
12
+
13
+
14
+ def _ontology_fn_body(p):
15
+ limit = int(p.get("limit", 10))
16
+ metric = p.get("metric", "net_impact")
17
+ start_date = p.get("start_date", "2025-01-01")
18
+ end_date = p.get("end_date", datetime.now().strftime("%Y-%m-%d"))
19
+ account_type = p.get("account_type", None)
20
+
21
+ output.print(f"期间: {start_date} ~ {end_date}, 取前{limit}个, 指标: {metric}")
22
+
23
+ type_cond = "" if not account_type else f"AND account_type = '{account_type}'"
24
+
25
+ metric_expr = {
26
+ "net_impact": "SUM(amount_signed)",
27
+ "revenue": "SUM(if(account_type='收入', amount_signed, 0))",
28
+ "cost": "SUM(if(account_type='成本', amount_signed, 0))",
29
+ "expense": "SUM(if(account_type='费用', amount_signed, 0))",
30
+ }.get(metric, "SUM(amount_signed)")
31
+
32
+ sql = f"""
33
+ SELECT
34
+ account_code,
35
+ account_name,
36
+ account_type,
37
+ pl_category,
38
+ {metric_expr} as metric_value
39
+ FROM fact_gl_journal_entry
40
+ WHERE posting_date >= '{start_date}' AND posting_date <= '{end_date}'
41
+ {type_cond}
42
+ GROUP BY account_code, account_name, account_type, pl_category
43
+ ORDER BY metric_value DESC
44
+ LIMIT {limit}
45
+ """
46
+
47
+ rows = p.space.sql.query(sql)
48
+
49
+ result = []
50
+ for row in rows:
51
+ result.append({
52
+ "account_code": row.get("account_code"),
53
+ "account_name": row.get("account_name"),
54
+ "account_type": row.get("account_type"),
55
+ "pl_category": row.get("pl_category"),
56
+ "metric_value": round(row.get("metric_value", 0) or 0, 2),
57
+ })
58
+
59
+ p.function_result(result)
60
+
61
+
@@ -0,0 +1,79 @@
1
+ """同比分析函数
2
+
3
+ 功能:对比当期与去年同期的利润指标变化
4
+ 参数:start_date, end_date
5
+
6
+ 放置:项目/DAZI_TEST/本体/ontos/利润分析示例/functions/profit_fn_yoy_analysis.py
7
+ 发布:dazi onto script publish 项目/DAZI_TEST/本体/ontos/利润分析示例/functions/profit_fn_yoy_analysis.py --space space__misc_01 --register-function-id profit.fn.yoy_analysis
8
+ """
9
+
10
+ from datetime import datetime, timedelta
11
+ import json
12
+
13
+
14
+ def _ontology_fn_body(p):
15
+ start_date = p.get("start_date", "2025-01-01")
16
+ end_date = p.get("end_date", datetime.now().strftime("%Y-%m-%d"))
17
+
18
+ start_dt = datetime.strptime(start_date, "%Y-%m-%d")
19
+ end_dt = datetime.strptime(end_date, "%Y-%m-%d")
20
+
21
+ last_year_start = (start_dt - timedelta(days=365)).strftime("%Y-%m-%d")
22
+ last_year_end = (end_dt - timedelta(days=365)).strftime("%Y-%m-%d")
23
+
24
+ output.print(f"当期: {start_date} ~ {end_date}")
25
+ output.print(f"去年同期: {last_year_start} ~ {last_year_end}")
26
+
27
+ def get_period_data(sd, ed):
28
+ sql = """
29
+ SELECT
30
+ sumIf(amount_signed, account_type='收入') as revenue,
31
+ sumIf(amount_signed, account_type='成本') as cost,
32
+ sumIf(amount_signed, account_type='费用') as expense
33
+ FROM fact_gl_journal_entry
34
+ WHERE posting_date >= '{sd}' AND posting_date <= '{ed}'
35
+ """.format(sd=sd, ed=ed)
36
+ result = p.space.sql.query_one(sql)
37
+ return {
38
+ "revenue": result.get("revenue", 0) or 0,
39
+ "cost": result.get("cost", 0) or 0,
40
+ "expense": result.get("expense", 0) or 0,
41
+ }
42
+
43
+ current = get_period_data(start_date, end_date)
44
+ last_year = get_period_data(last_year_start, last_year_end)
45
+
46
+ current_profit = current["revenue"] - current["cost"] - current["expense"]
47
+ last_year_profit = last_year["revenue"] - last_year["cost"] - last_year["expense"]
48
+
49
+ def calc_yoy(current, last):
50
+ if last == 0:
51
+ return 0 if current == 0 else None
52
+ return (current - last) / last
53
+
54
+ result = {
55
+ "period": f"{start_date} ~ {end_date}",
56
+ "last_year_period": f"{last_year_start} ~ {last_year_end}",
57
+ "current": {
58
+ "revenue": round(current["revenue"], 2),
59
+ "cost": round(current["cost"], 2),
60
+ "expense": round(current["expense"], 2),
61
+ "operating_profit": round(current_profit, 2),
62
+ },
63
+ "last_year": {
64
+ "revenue": round(last_year["revenue"], 2),
65
+ "cost": round(last_year["cost"], 2),
66
+ "expense": round(last_year["expense"], 2),
67
+ "operating_profit": round(last_year_profit, 2),
68
+ },
69
+ "yoy": {
70
+ "revenue": round(calc_yoy(current["revenue"], last_year["revenue"]), 4) if calc_yoy(current["revenue"], last_year["revenue"]) is not None else None,
71
+ "cost": round(calc_yoy(current["cost"], last_year["cost"]), 4) if calc_yoy(current["cost"], last_year["cost"]) is not None else None,
72
+ "expense": round(calc_yoy(current["expense"], last_year["expense"]), 4) if calc_yoy(current["expense"], last_year["expense"]) is not None else None,
73
+ "operating_profit": round(calc_yoy(current_profit, last_year_profit), 4) if calc_yoy(current_profit, last_year_profit) is not None else None,
74
+ },
75
+ }
76
+
77
+ p.function_result(result)
78
+
79
+
@@ -0,0 +1,38 @@
1
+ # save_test_arguments.ps1
2
+ # 批量保存各函数的 test_arguments
3
+ # 用法:在 dazi-work 根目录执行 .\项目\DAZI_TEST\本体\ontos\利润分析示例\functions\save_test_arguments.ps1
4
+
5
+ $spaceId = "space__misc_01"
6
+ $itemPath = "项目/DAZI_TEST/本体/ontos/利润分析示例/functions"
7
+
8
+ $functions = @(
9
+ @{fn_id="profit.fn.get_summary"; file="profit.fn.get_summary.json"},
10
+ @{fn_id="profit.fn.yoy_analysis"; file="profit.fn.yoy_analysis.json"},
11
+ @{fn_id="profit.fn.mom_analysis"; file="profit.fn.mom_analysis.json"},
12
+ @{fn_id="profit.fn.budget_vs_actual"; file="profit.fn.budget_vs_actual.json"},
13
+ @{fn_id="profit.fn.account_breakdown"; file="profit.fn.account_breakdown.json"},
14
+ @{fn_id="profit.fn.cost_center_profit"; file="profit.fn.cost_center_profit.json"},
15
+ @{fn_id="profit.fn.top_accounts"; file="profit.fn.top_accounts.json"}
16
+ )
17
+
18
+ Write-Host "获取函数列表..."
19
+ $fnList = & dazi onto function list --space $spaceId 2>$null
20
+
21
+ foreach ($fn in $functions) {
22
+ $fnId = $fn.fn_id
23
+ $fileName = $fn.file
24
+ $jsonPath = "$PSScriptRoot/test_arguments/$fileName"
25
+
26
+ $ofnId = $fnList | Where-Object { $_ -match $fnId } | ForEach-Object {
27
+ if ($_ -match 'id:\s*(\S+)') { $matches[1] }
28
+ }
29
+
30
+ if ($ofnId) {
31
+ Write-Host "保存 $fnId (ofnId=$ofnId)..."
32
+ & dazi onto function save-test-arguments $ofnId --space $spaceId --arguments-json-file $jsonPath
33
+ } else {
34
+ Write-Host "函数 $fnId 未找到,请先发布函数"
35
+ }
36
+ }
37
+
38
+ Write-Host "完成"
@@ -0,0 +1 @@
1
+ {"v":1,"meta":{"last_source":"admin_panel","last_saved_at":"2026-06-06T01:00:00.000000+00:00","last_input_shape":"json"},"arguments":{"start_date":"2025-01-01","end_date":"2026-06-30","account_type":"收入"},"object_type_code":"Account"}
@@ -0,0 +1 @@
1
+ {"v":1,"meta":{"last_source":"admin_panel","last_saved_at":"2026-06-06T01:00:00.000000+00:00","last_input_shape":"json"},"arguments":{"start_date":"2025-01-01","end_date":"2026-06-30"},"object_type_code":"BudgetAnalysis"}
@@ -0,0 +1 @@
1
+ {"v":1,"meta":{"last_source":"admin_panel","last_saved_at":"2026-06-06T01:00:00.000000+00:00","last_input_shape":"json"},"arguments":{"start_date":"2025-01-01","end_date":"2026-06-30"},"object_type_code":"CostCenter"}
@@ -0,0 +1 @@
1
+ {"v":1,"meta":{"last_source":"admin_panel","last_saved_at":"2026-06-06T01:00:00.000000+00:00","last_input_shape":"json"},"arguments":{"start_date":"2025-01-01","end_date":"2026-06-30"},"object_type_code":"ProfitAnalysis"}
@@ -0,0 +1 @@
1
+ {"v":1,"meta":{"last_source":"admin_panel","last_saved_at":"2026-06-06T01:00:00.000000+00:00","last_input_shape":"json"},"arguments":{"start_date":"2025-01-01","end_date":"2026-06-30"},"object_type_code":"ProfitAnalysis"}
@@ -0,0 +1 @@
1
+ {"v":1,"meta":{"last_source":"admin_panel","last_saved_at":"2026-06-06T01:00:00.000000+00:00","last_input_shape":"json"},"arguments":{"start_date":"2025-01-01","end_date":"2026-06-30","limit":10},"object_type_code":"Account"}
@@ -0,0 +1 @@
1
+ {"v":1,"meta":{"last_source":"admin_panel","last_saved_at":"2026-06-06T01:00:00.000000+00:00","last_input_shape":"json"},"arguments":{"start_date":"2025-01-01","end_date":"2026-06-30"},"object_type_code":"ProfitAnalysis"}