kcode-pi 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +358 -0
- package/dist/cli/kcode.d.ts +15 -0
- package/dist/cli/kcode.js +153 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +7 -0
- package/docs/KCODE_DISTRIBUTION.md +91 -0
- package/extensions/kingdee-harness.ts +180 -0
- package/extensions/kingdee-header.ts +122 -0
- package/extensions/kingdee-tools.ts +379 -0
- package/knowledge/.backup/v1.0.0/version.json +10 -0
- package/knowledge/cangqiong/product-notes.md +15 -0
- package/knowledge/common/business-flows.md +115 -0
- package/knowledge/common/config-guides.md +110 -0
- package/knowledge/common/error-patterns.md +170 -0
- package/knowledge/common/implementation.md +144 -0
- package/knowledge/cosmic/hard-constraints.md +38 -0
- package/knowledge/cosmic/ksql-datafix.md +34 -0
- package/knowledge/cosmic/platform-baseline.md +32 -0
- package/knowledge/cosmic/plugin-decision-matrix.md +40 -0
- package/knowledge/cosmic/review-checklist.md +40 -0
- package/knowledge/cosmic/unittest.md +35 -0
- package/knowledge/enterprise/api-reference.md +186 -0
- package/knowledge/enterprise/code-patterns.md +217 -0
- package/knowledge/enterprise/plugin-lifecycle.md +188 -0
- package/knowledge/enterprise/tables.json +159 -0
- package/knowledge/flagship/api-reference.md +237 -0
- package/knowledge/flagship/code-patterns.md +246 -0
- package/knowledge/flagship/cosmic-platform-note.md +15 -0
- package/knowledge/flagship/plugin-lifecycle.md +248 -0
- package/knowledge/flagship/tables.json +159 -0
- package/knowledge/version.json +10 -0
- package/knowledge/xinghan/product-notes.md +15 -0
- package/package.json +71 -0
- package/prompts/kd-discuss.md +11 -0
- package/prompts/kd-execute.md +12 -0
- package/prompts/kd-plan.md +12 -0
- package/prompts/kd-ship.md +12 -0
- package/prompts/kd-spec.md +12 -0
- package/prompts/kd-verify.md +12 -0
- package/skills/kd-check/SKILL.md +26 -0
- package/skills/kd-cosmic-dev/SKILL.md +82 -0
- package/skills/kd-cosmic-review/SKILL.md +90 -0
- package/skills/kd-cosmic-unittest/SKILL.md +92 -0
- package/skills/kd-debug/SKILL.md +30 -0
- package/skills/kd-discuss/SKILL.md +24 -0
- package/skills/kd-execute/SKILL.md +22 -0
- package/skills/kd-gen/SKILL.md +34 -0
- package/skills/kd-ksql/SKILL.md +86 -0
- package/skills/kd-plan/SKILL.md +24 -0
- package/skills/kd-ship/SKILL.md +22 -0
- package/skills/kd-spec/SKILL.md +24 -0
- package/skills/kd-verify/SKILL.md +22 -0
- package/themes/kcode-dark.json +81 -0
- package/vendor/kingdee-skills/cosmic-unittest/SKILL.md +788 -0
- package/vendor/kingdee-skills/cosmic-unittest/author-cache.json +5 -0
- package/vendor/kingdee-skills/cosmic-unittest/cosmic-unittest-skill-overview.html +746 -0
- package/vendor/kingdee-skills/cosmic-unittest/examples/business-test.md +205 -0
- package/vendor/kingdee-skills/cosmic-unittest/examples/common-test.md +257 -0
- package/vendor/kingdee-skills/cosmic-unittest/examples/formplugin-test.md +560 -0
- package/vendor/kingdee-skills/cosmic-unittest/examples/op-plugin-test.md +231 -0
- package/vendor/kingdee-skills/cosmic-unittest/examples/validator-test.md +232 -0
- package/vendor/kingdee-skills/cosmic-unittest/patterns/business-helper.md +184 -0
- package/vendor/kingdee-skills/cosmic-unittest/patterns/common-module.md +355 -0
- package/vendor/kingdee-skills/cosmic-unittest/patterns/convert-plugin.md +130 -0
- package/vendor/kingdee-skills/cosmic-unittest/patterns/formplugin.md +235 -0
- package/vendor/kingdee-skills/cosmic-unittest/patterns/op-plugin.md +226 -0
- package/vendor/kingdee-skills/cosmic-unittest/patterns/validator.md +206 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/SKILL.md +674 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/advanced-scenario-checklist.md +307 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/algox-performance-checklist.md +129 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/coding-standard-checklist.md +491 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/cosmic-api-checklist.md +285 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/data-access-checklist.md +261 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/data-transaction-checklist.md +390 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/domain-logic-checklist.md +295 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/form-plugin-checklist.md +508 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/infra-checklist.md +254 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/ksql-checklist.md +305 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/lifecycle-checklist.md +298 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/operation-plugin-checklist.md +442 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/test-mock-checklist.md +120 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/ui-performance-checklist.md +320 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/scripts/pattern-matcher.py +336 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/scripts/review-score-calculator.py +121 -0
- package/vendor/kingdee-skills/ok-cosmic/CHANGELOG.md +295 -0
- package/vendor/kingdee-skills/ok-cosmic/README.md +460 -0
- package/vendor/kingdee-skills/ok-cosmic/SKILL.md +287 -0
- package/vendor/kingdee-skills/ok-cosmic/agents/openai.yaml +17 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/BatchImportPluginTemplate.java +93 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/BillPlugInTemplate.java +156 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/ConvertPlugInTemplate.java +255 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/FormPluginTemplate.java +597 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/IWorkflowPluginTemplate.java +91 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/ListPluginTemplate.java +194 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/OpPluginTemplate.java +201 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/OpenApiControllerTemplate.java +103 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/PrintPluginTemplate.java +95 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/ReportFormPluginTemplate.java +257 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/ReportListDataPluginTemplate.java +70 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/StandardTreeListPluginTemplate.java +130 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/TaskTemplate.java +80 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/TreeListPluginTemplate.java +152 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/WriteBackPlugInTemplate.java +286 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/attachment/AttachmentUploadBindSample.java +93 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/botp/BotpTracePushSample.java +168 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/botp/SampleConvertPlugin.java +223 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/cache/SampleCacheUsage.java +218 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/concurrent/SampleThreadPoolBatch.java +156 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/data/DynamicObjectCrudSample.java +205 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/data/DynamicObjectOpsSample.java +100 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/BeforeOperationConfirmSample.java +217 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/ConfirmDialogSample.java +131 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/EntryRowCalculateSample.java +116 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/F7FilterSample.java +134 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/GetAndSetValueSample.java +176 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/HyperlinkJumpSample.java +124 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/OpenBillModalSample.java +253 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/ReturnParentDataSample.java +295 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/TreeControlSample.java +140 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/ViewControlOpsSample.java +132 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/list/ListPluginBasicSample.java +170 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/list/ListPreOpenFilterSample.java +68 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/message/MessageNotifySample.java +95 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/mq/SampleMQConsumer.java +198 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/mq/sample_mq.xml +15 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/operation/OpAddValidatorsSample.java +137 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/operation/OperationOptionBridgeSample.java +228 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/package-info.java +19 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/query/BaseDataQuerySample.java +194 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/query/BatchQuerySample.java +368 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/query/DataSetQueryStatSample.java +131 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/report/SampleReportFormPlugin.java +179 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/report/SampleReportListDataPlugin.java +616 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/snippets-guide.md +64 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/task/ScheduleTaskSample.java +160 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/workflow/SampleWorkflowPlugin.java +302 -0
- package/vendor/kingdee-skills/ok-cosmic/manifest.json +78 -0
- package/vendor/kingdee-skills/ok-cosmic/ok-cosmic-intro.html +903 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/attachment-api.md +114 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/botp-convert.md +98 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/dynamic-object.md +113 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/entity-metadata.md +123 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/event-lifecycle.md +184 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/flex-prop.md +114 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/form-utils.md +133 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/operate-chain.md +159 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/plugin-base.md +218 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/query-dataset.md +149 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/request-context.md +88 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/view-handler.md +157 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-bill.md +76 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-botp.md +70 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-form.md +165 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-import.md +69 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-list.md +227 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-openapi.md +112 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-operation.md +135 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-print.md +65 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-report-data.md +64 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-report-form.md +90 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-task.md +62 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-tree-list.md +71 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-workflow.md +82 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-writeback.md +71 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-algo.md +67 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-cache.md +63 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-dynamic-model-svc.md +82 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-dynamic-object.md +70 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-entity-model.md +61 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-exception.md +64 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-file.md +63 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-id.md +47 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-lock.md +61 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-log.md +63 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-network-control.md +70 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-orm-access.md +78 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-request-context.md +62 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-threadpool.md +63 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-tx.md +64 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-utils.md +67 -0
- package/vendor/kingdee-skills/ok-cosmic/requirements.txt +2 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/a-layer-rules.json +24 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/anti-patterns.md +48 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/cheat-sheet.md +256 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/coding-preferences.md +140 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/constraints.md +61 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/decision-matrix.md +222 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/intent-routing.md +94 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/platform-baseline.md +69 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/post-check.md +109 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/config_loader.py +204 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-api-knowledge.py +910 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-basedata-query.py +359 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-config-check.py +181 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-extpoints-query.py +389 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-form-metadata.py +856 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-post-check.py +262 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-post-lint.py +293 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/lint/__init__.py +2 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/lint/base.py +393 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/lint/resource_check.py +176 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/lint/scene_check.py +375 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/lint/style_check.py +434 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/lint/verify_check.py +36 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/route_client.py +186 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/script_utils.py +40 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/sqlite_cache.py +142 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/cuslib/kd-cd-cosmic-commons.jar +0 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/cuslib/kd-cd-cosmic-features.jar +0 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/ok-cosmic-docs.db +0 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/ok-cosmic.json +13 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/setup-mac.sh +18 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/setup-windows.bat +53 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/setup.jar +0 -0
- package/vendor/kingdee-skills/ok-ksql/SKILL.md +81 -0
- package/vendor/kingdee-skills/ok-ksql/agents/openai.yaml +7 -0
- package/vendor/kingdee-skills/ok-ksql/manifest.json +14 -0
- package/vendor/kingdee-skills/ok-ksql/references/ksql-datafix.md +452 -0
- package/vendor/kingdee-skills/ok-ksql/scripts/ksql_lint.py +363 -0
package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/advanced-scenario-checklist.md
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
# 高级场景检查表(分表分片/高并发/批量处理/微服务)
|
|
2
|
+
|
|
3
|
+
## 🔴 P0 级问题
|
|
4
|
+
|
|
5
|
+
### 1. 水平分表分片定位错误
|
|
6
|
+
**检查点**:
|
|
7
|
+
- 分表查询是否正确指定了分片键?
|
|
8
|
+
- 是否存在跨分片查询但未带分片键的情况?
|
|
9
|
+
- 分片键的值是否与实际数据分布一致?
|
|
10
|
+
- `DB.execute()` 或原生 SQL 是否正确路由到目标分片?
|
|
11
|
+
|
|
12
|
+
**风险**: 查询到错误分片的数据,或全分片扫描导致性能骤降
|
|
13
|
+
|
|
14
|
+
**修正方案**:
|
|
15
|
+
```java
|
|
16
|
+
// ❌ 错误写法 - 未指定分片键,全分片扫描
|
|
17
|
+
DataSet ds = QueryServiceHelper.queryDataSet("q", "sharded_entity",
|
|
18
|
+
"id,name", null); // 无分片键条件!
|
|
19
|
+
|
|
20
|
+
// ❌ 错误写法 - 分片键值不正确
|
|
21
|
+
QFilter filter = new QFilter("org", QCP.equals, wrongOrgId); // 查错分片
|
|
22
|
+
|
|
23
|
+
// ✅ 正确写法 - 必须带分片键
|
|
24
|
+
QFilter shardFilter = new QFilter("org", QCP.equals, currentOrgId);
|
|
25
|
+
QFilter bizFilter = new QFilter("billstatus", QCP.equals, "C");
|
|
26
|
+
try (DataSet ds = QueryServiceHelper.queryDataSet("q", "sharded_entity",
|
|
27
|
+
"id,name", new QFilter[]{shardFilter, bizFilter})) {
|
|
28
|
+
// 处理数据
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
### 2. 跨分片写操作
|
|
35
|
+
**检查点**:
|
|
36
|
+
- 同一事务内是否写了不同分片的数据?
|
|
37
|
+
- 批量操作是否涉及多个分片?
|
|
38
|
+
|
|
39
|
+
**风险**: 跨分片事务不被支持,可能导致数据不一致
|
|
40
|
+
|
|
41
|
+
**修正方案**:
|
|
42
|
+
```java
|
|
43
|
+
// ❌ 错误写法 - 一个事务内写多个分片
|
|
44
|
+
try (TXHandle h = TX.required("crossShard")) {
|
|
45
|
+
try {
|
|
46
|
+
SaveServiceHelper.save(orgAData); // 分片A
|
|
47
|
+
SaveServiceHelper.save(orgBData); // 分片B - 跨分片!
|
|
48
|
+
} catch (Throwable e) {
|
|
49
|
+
h.markRollback();
|
|
50
|
+
throw e;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// ✅ 正确写法 - 按分片分组,每组独立事务
|
|
55
|
+
Map<Long, List<DynamicObject>> grouped = groupByOrg(allData);
|
|
56
|
+
for (Map.Entry<Long, List<DynamicObject>> entry : grouped.entrySet()) {
|
|
57
|
+
try (TXHandle h = TX.required("saveShard_" + entry.getKey())) {
|
|
58
|
+
try {
|
|
59
|
+
SaveServiceHelper.save(entry.getValue().toArray(new DynamicObject[0]));
|
|
60
|
+
} catch (Throwable e) {
|
|
61
|
+
h.markRollback();
|
|
62
|
+
throw e;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
### 3. 分布式锁粒度不当
|
|
71
|
+
**检查点**:
|
|
72
|
+
- 分布式锁的 key 粒度是否过粗(如只用模块名),导致不必要的锁竞争?
|
|
73
|
+
- 分布式锁的 key 粒度是否过细(如用行级ID),导致锁数量爆炸?
|
|
74
|
+
- 锁的超时时间是否合理?
|
|
75
|
+
|
|
76
|
+
**风险**: 粒度过粗导致并发性能差;粒度过细导致锁管理开销大
|
|
77
|
+
|
|
78
|
+
**修正方案**:
|
|
79
|
+
```java
|
|
80
|
+
// ❌ 错误写法 - 锁粒度过粗
|
|
81
|
+
DLock lock = DLock.create("pm_purchase", "采购模块锁"); // 整个模块串行!
|
|
82
|
+
|
|
83
|
+
// ❌ 错误写法 - 锁粒度过细
|
|
84
|
+
for (DynamicObject entry : entries) {
|
|
85
|
+
DLock lock = DLock.create("entry_" + entry.getPkValue(), "分录行锁"); // 锁太多!
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ✅ 正确写法 - 以单据为粒度
|
|
89
|
+
DLock lock = DLock.create("pm/purorder/" + billId, "采购订单" + billNo);
|
|
90
|
+
lock.lock(30, TimeUnit.SECONDS); // 设置合理超时
|
|
91
|
+
try {
|
|
92
|
+
doSomething();
|
|
93
|
+
} finally {
|
|
94
|
+
lock.unlock();
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## 🟠 P1 级问题
|
|
101
|
+
|
|
102
|
+
### 4. 大批量操作未分批处理
|
|
103
|
+
**检查点**:
|
|
104
|
+
- 批量操作(save/delete/update)是否一次性处理所有数据?
|
|
105
|
+
- 单次操作数据量是否超过 1000 条?
|
|
106
|
+
- 是否有分批提交和进度反馈?
|
|
107
|
+
|
|
108
|
+
**风险**: 大事务超时、OOM、数据库锁等待
|
|
109
|
+
|
|
110
|
+
**修正方案**:
|
|
111
|
+
```java
|
|
112
|
+
// ❌ 错误写法 - 一次性处理所有数据
|
|
113
|
+
DynamicObject[] allData = BusinessDataServiceHelper.load(entityName, "id", filter);
|
|
114
|
+
SaveServiceHelper.save(allData); // 可能数万条数据!
|
|
115
|
+
|
|
116
|
+
// ✅ 正确写法 - 分批处理
|
|
117
|
+
int batchSize = 500;
|
|
118
|
+
DynamicObject[] allData = BusinessDataServiceHelper.load(entityName, "id", filter);
|
|
119
|
+
for (int i = 0; i < allData.length; i += batchSize) {
|
|
120
|
+
int end = Math.min(i + batchSize, allData.length);
|
|
121
|
+
DynamicObject[] batch = Arrays.copyOfRange(allData, i, end);
|
|
122
|
+
try (TXHandle h = TX.required("batch_" + i)) {
|
|
123
|
+
try {
|
|
124
|
+
SaveServiceHelper.save(batch);
|
|
125
|
+
} catch (Throwable e) {
|
|
126
|
+
h.markRollback();
|
|
127
|
+
throw e;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
### 5. 高并发场景缓存穿透/击穿
|
|
136
|
+
**检查点**:
|
|
137
|
+
- 缓存查询未命中时是否直接查库?(缓存穿透)
|
|
138
|
+
- 热点数据缓存过期瞬间是否有大量请求直接到数据库?(缓存击穿)
|
|
139
|
+
- 恶意查询不存在的数据是否会绕过缓存?(缓存穿透)
|
|
140
|
+
|
|
141
|
+
**风险**: 数据库被打爆,服务不可用
|
|
142
|
+
|
|
143
|
+
**修正方案**:
|
|
144
|
+
```java
|
|
145
|
+
// ❌ 错误写法 - 缓存未命中直接查库
|
|
146
|
+
Object data = cache.get(key);
|
|
147
|
+
if (data == null) {
|
|
148
|
+
data = loadFromDB(key); // 高并发下大量请求打到数据库
|
|
149
|
+
cache.put(key, data);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// ✅ 正确写法 - 使用分布式锁防止击穿
|
|
153
|
+
Object data = cache.get(key);
|
|
154
|
+
if (data == null) {
|
|
155
|
+
DLock lock = DLock.create("cache_lock_" + key, "缓存加载锁");
|
|
156
|
+
if (lock.tryLock(5, TimeUnit.SECONDS)) {
|
|
157
|
+
try {
|
|
158
|
+
data = cache.get(key); // 双重检查
|
|
159
|
+
if (data == null) {
|
|
160
|
+
data = loadFromDB(key);
|
|
161
|
+
cache.put(key, data, 300); // 设置过期时间
|
|
162
|
+
}
|
|
163
|
+
} finally {
|
|
164
|
+
lock.unlock();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
### 6. 微服务调用链超时传播
|
|
173
|
+
**检查点**:
|
|
174
|
+
- 微服务调用是否设置了超时时间?
|
|
175
|
+
- 调用链中是否存在超时时间层层累加导致总超时过长?
|
|
176
|
+
- 是否有降级/熔断策略?
|
|
177
|
+
|
|
178
|
+
**风险**: 下游服务超时导致上游线程阻塞,服务级联故障
|
|
179
|
+
|
|
180
|
+
**修正方案**:
|
|
181
|
+
```java
|
|
182
|
+
// ❌ 错误写法 - 无超时、无降级
|
|
183
|
+
Object result = DispatchServiceHelper.invokeService(
|
|
184
|
+
"isv.ti.bo", "appId", "service", "method", args);
|
|
185
|
+
|
|
186
|
+
// ✅ 正确写法 - 设置超时并处理异常
|
|
187
|
+
try {
|
|
188
|
+
Object result = DispatchServiceHelper.invokeService(
|
|
189
|
+
"isv.ti.bo", "appId", "service", "method", args);
|
|
190
|
+
// 处理结果
|
|
191
|
+
} catch (Exception e) {
|
|
192
|
+
logger.error("微服务调用失败,执行降级逻辑", e);
|
|
193
|
+
return getDefaultValue(); // 降级处理
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
### 7. 异步操作结果一致性
|
|
200
|
+
**检查点**:
|
|
201
|
+
- 异步操作完成后是否正确更新了主流程状态?
|
|
202
|
+
- 异步失败时是否有补偿机制?
|
|
203
|
+
- 是否使用了正确的线程池保证上下文传递?
|
|
204
|
+
|
|
205
|
+
**风险**: 异步操作静默失败,主流程数据状态不一致
|
|
206
|
+
|
|
207
|
+
**修正方案**:
|
|
208
|
+
```java
|
|
209
|
+
// ❌ 错误写法 - 异步操作无异常处理
|
|
210
|
+
ThreadPools.executeOnce("asyncTask", () -> {
|
|
211
|
+
updateRelatedData(billId); // 失败了谁都不知道
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
// ✅ 正确写法 - 异步操作带上下文和异常处理
|
|
215
|
+
ThreadPools.executeOnceIncludeRequestContext("asyncTask", () -> {
|
|
216
|
+
try {
|
|
217
|
+
updateRelatedData(billId);
|
|
218
|
+
} catch (Exception e) {
|
|
219
|
+
logger.error("异步更新关联数据失败: billId={}", billId, e);
|
|
220
|
+
// 记录失败日志或发送重试消息
|
|
221
|
+
retryQueue.put(billId);
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## 🟡 P2 级问题
|
|
229
|
+
|
|
230
|
+
### 8. 分页查询性能
|
|
231
|
+
**检查点**:
|
|
232
|
+
- 深分页(offset > 10000)是否使用了游标分页或 ID 范围分页?
|
|
233
|
+
- 分页查询是否有合理的排序字段?
|
|
234
|
+
|
|
235
|
+
**修正方案**:
|
|
236
|
+
```java
|
|
237
|
+
// ❌ 错误写法 - 深分页性能差
|
|
238
|
+
// 第 10000 页,每页 20 条
|
|
239
|
+
List<DynamicObject> data = BusinessDataServiceHelper.load(
|
|
240
|
+
filter, 200000, 20); // offset 太大!
|
|
241
|
+
|
|
242
|
+
// ✅ 正确写法 - 基于 ID 范围分页
|
|
243
|
+
QFilter pageFilter = new QFilter("id", QCP.large_than, lastMaxId);
|
|
244
|
+
List<DynamicObject> data = BusinessDataServiceHelper.load(
|
|
245
|
+
entityName, "id,name",
|
|
246
|
+
new QFilter[]{pageFilter}, "id ASC", 20);
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
### 9. 定时任务并发执行
|
|
252
|
+
**检查点**:
|
|
253
|
+
- 定时任务是否考虑了多节点同时触发的情况?
|
|
254
|
+
- 是否使用了分布式锁防止重复执行?
|
|
255
|
+
|
|
256
|
+
**修正方案**:
|
|
257
|
+
```java
|
|
258
|
+
// ✅ 正确写法 - 定时任务加分布式锁
|
|
259
|
+
@Override
|
|
260
|
+
public void execute(RequestContext ctx, Map<String, Object> map) throws KDException {
|
|
261
|
+
DLock lock = DLock.create("task_" + taskName, "定时任务");
|
|
262
|
+
if (!lock.tryLock(0, TimeUnit.SECONDS)) {
|
|
263
|
+
logger.info("任务正在其他节点执行,跳过");
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
try {
|
|
267
|
+
doTaskLogic();
|
|
268
|
+
} finally {
|
|
269
|
+
lock.unlock();
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
### 10. 数据导入/导出性能
|
|
277
|
+
**检查点**:
|
|
278
|
+
- 大数据量导入是否使用了流式处理?
|
|
279
|
+
- 导出是否一次性加载所有数据到内存?
|
|
280
|
+
- 是否有进度反馈机制?
|
|
281
|
+
|
|
282
|
+
**修正方案**:
|
|
283
|
+
```java
|
|
284
|
+
// ❌ 错误写法 - 一次性加载所有数据导出
|
|
285
|
+
List<DynamicObject> all = BusinessDataServiceHelper.load(filter); // OOM!
|
|
286
|
+
|
|
287
|
+
// ✅ 正确写法 - 流式查询分批导出
|
|
288
|
+
try (DataSet ds = QueryServiceHelper.queryDataSet("export", entity, fields, filter)) {
|
|
289
|
+
int count = 0;
|
|
290
|
+
List<Object[]> batch = new ArrayList<>(1000);
|
|
291
|
+
while (ds.hasNext()) {
|
|
292
|
+
Row row = ds.next();
|
|
293
|
+
batch.add(new Object[]{row.getString("name"), row.getBigDecimal("amount")});
|
|
294
|
+
if (batch.size() >= 1000) {
|
|
295
|
+
writeBatchToExcel(batch);
|
|
296
|
+
batch.clear();
|
|
297
|
+
}
|
|
298
|
+
count++;
|
|
299
|
+
if (count % 5000 == 0) {
|
|
300
|
+
feedbackProgress(count, "已导出 " + count + " 条");
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
if (!batch.isEmpty()) {
|
|
304
|
+
writeBatchToExcel(batch);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
```
|
package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/algox-performance-checklist.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# AlgoX 大数据计算性能检查表
|
|
2
|
+
|
|
3
|
+
## 🟠 P1 级问题
|
|
4
|
+
|
|
5
|
+
### 1. 循环内获取 FieldIndex
|
|
6
|
+
**检查点**:
|
|
7
|
+
- `map()`/`filter()` 内是否调用 `getFieldIndex()`?
|
|
8
|
+
- 是否在 lambda 表达式中重复计算?
|
|
9
|
+
|
|
10
|
+
**风险**: 性能损耗,不必要的重复计算
|
|
11
|
+
|
|
12
|
+
**修正方案**:
|
|
13
|
+
```java
|
|
14
|
+
// ❌ 错误写法
|
|
15
|
+
ds.map(row -> {
|
|
16
|
+
int idx = row.getMeta().getFieldIndex("amount"); // 每行都查!
|
|
17
|
+
return row.getBigDecimal(idx);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// ✅ 正确写法 - 缓存为成员变量
|
|
21
|
+
private int amountIndex = -1;
|
|
22
|
+
|
|
23
|
+
public void process(DataSet ds) {
|
|
24
|
+
amountIndex = ds.getRowMeta().getFieldIndex("amount");
|
|
25
|
+
ds.map(row -> row.getBigDecimal(amountIndex));
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
### 2. 集合无限累积
|
|
32
|
+
**检查点**:
|
|
33
|
+
- 是否在 `map` 中无限制 `add` 到 List?
|
|
34
|
+
- 是否在循环中持续累积数据?
|
|
35
|
+
|
|
36
|
+
**风险**: OOM 内存溢出
|
|
37
|
+
|
|
38
|
+
**修正方案**:
|
|
39
|
+
```java
|
|
40
|
+
// ❌ 错误写法
|
|
41
|
+
List<Object> result = new ArrayList<>();
|
|
42
|
+
ds.forEach(row -> {
|
|
43
|
+
result.add(transform(row)); // 无限累积!
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// ✅ 正确写法 - 分批处理
|
|
47
|
+
int batchSize = 10000;
|
|
48
|
+
List<Object> batch = new ArrayList<>(batchSize);
|
|
49
|
+
ds.forEach(row -> {
|
|
50
|
+
batch.add(transform(row));
|
|
51
|
+
if (batch.size() >= batchSize) {
|
|
52
|
+
saveBatch(batch);
|
|
53
|
+
batch.clear();
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
if (!batch.isEmpty()) {
|
|
57
|
+
saveBatch(batch);
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
### 3. DataSet 未关闭
|
|
64
|
+
**检查点**:
|
|
65
|
+
- `DataSet` 是否使用 try-with-resources?
|
|
66
|
+
|
|
67
|
+
**修正方案**:
|
|
68
|
+
```java
|
|
69
|
+
// ❌ 错误写法
|
|
70
|
+
DataSet ds = Algo.create().query(...);
|
|
71
|
+
process(ds);
|
|
72
|
+
// ds 未关闭!
|
|
73
|
+
|
|
74
|
+
// ✅ 正确写法
|
|
75
|
+
try (DataSet ds = Algo.create().query(...)) {
|
|
76
|
+
process(ds);
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
### 4. AlgoContext 未关闭
|
|
83
|
+
**检查点**:
|
|
84
|
+
- `AlgoContext` 是否正确关闭?
|
|
85
|
+
|
|
86
|
+
**修正方案**:
|
|
87
|
+
```java
|
|
88
|
+
// ✅ 正确写法
|
|
89
|
+
try (AlgoContext ctx = Algo.newContext()) {
|
|
90
|
+
DataSet ds = ...;
|
|
91
|
+
// 处理数据
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## 🟡 P2 级问题
|
|
98
|
+
|
|
99
|
+
### 5. 不必要的 collect
|
|
100
|
+
**检查点**:
|
|
101
|
+
- 是否将 DataSet 收集到 List 后又遍历?
|
|
102
|
+
|
|
103
|
+
**修正方案**:
|
|
104
|
+
```java
|
|
105
|
+
// ❌ 错误写法
|
|
106
|
+
List<Row> rows = ds.collect(Collectors.toList());
|
|
107
|
+
rows.forEach(this::process);
|
|
108
|
+
|
|
109
|
+
// ✅ 正确写法 - 直接遍历
|
|
110
|
+
ds.forEach(this::process);
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
### 6. 重复计算
|
|
116
|
+
**检查点**:
|
|
117
|
+
- 是否多次调用相同的 `filter()`/`groupBy()`?
|
|
118
|
+
|
|
119
|
+
**修正方案**:
|
|
120
|
+
```java
|
|
121
|
+
// ❌ 错误写法
|
|
122
|
+
long count = ds.filter("status = 1").count();
|
|
123
|
+
DataSet filtered = ds.filter("status = 1"); // 重复过滤!
|
|
124
|
+
|
|
125
|
+
// ✅ 正确写法 - 缓存中间结果
|
|
126
|
+
DataSet filtered = ds.filter("status = 1");
|
|
127
|
+
long count = filtered.count();
|
|
128
|
+
process(filtered);
|
|
129
|
+
```
|