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.
Files changed (219) hide show
  1. package/README.md +358 -0
  2. package/dist/cli/kcode.d.ts +15 -0
  3. package/dist/cli/kcode.js +153 -0
  4. package/dist/cli/main.d.ts +2 -0
  5. package/dist/cli/main.js +7 -0
  6. package/docs/KCODE_DISTRIBUTION.md +91 -0
  7. package/extensions/kingdee-harness.ts +180 -0
  8. package/extensions/kingdee-header.ts +122 -0
  9. package/extensions/kingdee-tools.ts +379 -0
  10. package/knowledge/.backup/v1.0.0/version.json +10 -0
  11. package/knowledge/cangqiong/product-notes.md +15 -0
  12. package/knowledge/common/business-flows.md +115 -0
  13. package/knowledge/common/config-guides.md +110 -0
  14. package/knowledge/common/error-patterns.md +170 -0
  15. package/knowledge/common/implementation.md +144 -0
  16. package/knowledge/cosmic/hard-constraints.md +38 -0
  17. package/knowledge/cosmic/ksql-datafix.md +34 -0
  18. package/knowledge/cosmic/platform-baseline.md +32 -0
  19. package/knowledge/cosmic/plugin-decision-matrix.md +40 -0
  20. package/knowledge/cosmic/review-checklist.md +40 -0
  21. package/knowledge/cosmic/unittest.md +35 -0
  22. package/knowledge/enterprise/api-reference.md +186 -0
  23. package/knowledge/enterprise/code-patterns.md +217 -0
  24. package/knowledge/enterprise/plugin-lifecycle.md +188 -0
  25. package/knowledge/enterprise/tables.json +159 -0
  26. package/knowledge/flagship/api-reference.md +237 -0
  27. package/knowledge/flagship/code-patterns.md +246 -0
  28. package/knowledge/flagship/cosmic-platform-note.md +15 -0
  29. package/knowledge/flagship/plugin-lifecycle.md +248 -0
  30. package/knowledge/flagship/tables.json +159 -0
  31. package/knowledge/version.json +10 -0
  32. package/knowledge/xinghan/product-notes.md +15 -0
  33. package/package.json +71 -0
  34. package/prompts/kd-discuss.md +11 -0
  35. package/prompts/kd-execute.md +12 -0
  36. package/prompts/kd-plan.md +12 -0
  37. package/prompts/kd-ship.md +12 -0
  38. package/prompts/kd-spec.md +12 -0
  39. package/prompts/kd-verify.md +12 -0
  40. package/skills/kd-check/SKILL.md +26 -0
  41. package/skills/kd-cosmic-dev/SKILL.md +82 -0
  42. package/skills/kd-cosmic-review/SKILL.md +90 -0
  43. package/skills/kd-cosmic-unittest/SKILL.md +92 -0
  44. package/skills/kd-debug/SKILL.md +30 -0
  45. package/skills/kd-discuss/SKILL.md +24 -0
  46. package/skills/kd-execute/SKILL.md +22 -0
  47. package/skills/kd-gen/SKILL.md +34 -0
  48. package/skills/kd-ksql/SKILL.md +86 -0
  49. package/skills/kd-plan/SKILL.md +24 -0
  50. package/skills/kd-ship/SKILL.md +22 -0
  51. package/skills/kd-spec/SKILL.md +24 -0
  52. package/skills/kd-verify/SKILL.md +22 -0
  53. package/themes/kcode-dark.json +81 -0
  54. package/vendor/kingdee-skills/cosmic-unittest/SKILL.md +788 -0
  55. package/vendor/kingdee-skills/cosmic-unittest/author-cache.json +5 -0
  56. package/vendor/kingdee-skills/cosmic-unittest/cosmic-unittest-skill-overview.html +746 -0
  57. package/vendor/kingdee-skills/cosmic-unittest/examples/business-test.md +205 -0
  58. package/vendor/kingdee-skills/cosmic-unittest/examples/common-test.md +257 -0
  59. package/vendor/kingdee-skills/cosmic-unittest/examples/formplugin-test.md +560 -0
  60. package/vendor/kingdee-skills/cosmic-unittest/examples/op-plugin-test.md +231 -0
  61. package/vendor/kingdee-skills/cosmic-unittest/examples/validator-test.md +232 -0
  62. package/vendor/kingdee-skills/cosmic-unittest/patterns/business-helper.md +184 -0
  63. package/vendor/kingdee-skills/cosmic-unittest/patterns/common-module.md +355 -0
  64. package/vendor/kingdee-skills/cosmic-unittest/patterns/convert-plugin.md +130 -0
  65. package/vendor/kingdee-skills/cosmic-unittest/patterns/formplugin.md +235 -0
  66. package/vendor/kingdee-skills/cosmic-unittest/patterns/op-plugin.md +226 -0
  67. package/vendor/kingdee-skills/cosmic-unittest/patterns/validator.md +206 -0
  68. package/vendor/kingdee-skills/kingdee-cosmic-reviewer/SKILL.md +674 -0
  69. package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/advanced-scenario-checklist.md +307 -0
  70. package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/algox-performance-checklist.md +129 -0
  71. package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/coding-standard-checklist.md +491 -0
  72. package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/cosmic-api-checklist.md +285 -0
  73. package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/data-access-checklist.md +261 -0
  74. package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/data-transaction-checklist.md +390 -0
  75. package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/domain-logic-checklist.md +295 -0
  76. package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/form-plugin-checklist.md +508 -0
  77. package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/infra-checklist.md +254 -0
  78. package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/ksql-checklist.md +305 -0
  79. package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/lifecycle-checklist.md +298 -0
  80. package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/operation-plugin-checklist.md +442 -0
  81. package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/test-mock-checklist.md +120 -0
  82. package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/ui-performance-checklist.md +320 -0
  83. package/vendor/kingdee-skills/kingdee-cosmic-reviewer/scripts/pattern-matcher.py +336 -0
  84. package/vendor/kingdee-skills/kingdee-cosmic-reviewer/scripts/review-score-calculator.py +121 -0
  85. package/vendor/kingdee-skills/ok-cosmic/CHANGELOG.md +295 -0
  86. package/vendor/kingdee-skills/ok-cosmic/README.md +460 -0
  87. package/vendor/kingdee-skills/ok-cosmic/SKILL.md +287 -0
  88. package/vendor/kingdee-skills/ok-cosmic/agents/openai.yaml +17 -0
  89. package/vendor/kingdee-skills/ok-cosmic/assets/BatchImportPluginTemplate.java +93 -0
  90. package/vendor/kingdee-skills/ok-cosmic/assets/BillPlugInTemplate.java +156 -0
  91. package/vendor/kingdee-skills/ok-cosmic/assets/ConvertPlugInTemplate.java +255 -0
  92. package/vendor/kingdee-skills/ok-cosmic/assets/FormPluginTemplate.java +597 -0
  93. package/vendor/kingdee-skills/ok-cosmic/assets/IWorkflowPluginTemplate.java +91 -0
  94. package/vendor/kingdee-skills/ok-cosmic/assets/ListPluginTemplate.java +194 -0
  95. package/vendor/kingdee-skills/ok-cosmic/assets/OpPluginTemplate.java +201 -0
  96. package/vendor/kingdee-skills/ok-cosmic/assets/OpenApiControllerTemplate.java +103 -0
  97. package/vendor/kingdee-skills/ok-cosmic/assets/PrintPluginTemplate.java +95 -0
  98. package/vendor/kingdee-skills/ok-cosmic/assets/ReportFormPluginTemplate.java +257 -0
  99. package/vendor/kingdee-skills/ok-cosmic/assets/ReportListDataPluginTemplate.java +70 -0
  100. package/vendor/kingdee-skills/ok-cosmic/assets/StandardTreeListPluginTemplate.java +130 -0
  101. package/vendor/kingdee-skills/ok-cosmic/assets/TaskTemplate.java +80 -0
  102. package/vendor/kingdee-skills/ok-cosmic/assets/TreeListPluginTemplate.java +152 -0
  103. package/vendor/kingdee-skills/ok-cosmic/assets/WriteBackPlugInTemplate.java +286 -0
  104. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/attachment/AttachmentUploadBindSample.java +93 -0
  105. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/botp/BotpTracePushSample.java +168 -0
  106. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/botp/SampleConvertPlugin.java +223 -0
  107. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/cache/SampleCacheUsage.java +218 -0
  108. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/concurrent/SampleThreadPoolBatch.java +156 -0
  109. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/data/DynamicObjectCrudSample.java +205 -0
  110. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/data/DynamicObjectOpsSample.java +100 -0
  111. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/BeforeOperationConfirmSample.java +217 -0
  112. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/ConfirmDialogSample.java +131 -0
  113. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/EntryRowCalculateSample.java +116 -0
  114. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/F7FilterSample.java +134 -0
  115. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/GetAndSetValueSample.java +176 -0
  116. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/HyperlinkJumpSample.java +124 -0
  117. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/OpenBillModalSample.java +253 -0
  118. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/ReturnParentDataSample.java +295 -0
  119. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/TreeControlSample.java +140 -0
  120. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/ViewControlOpsSample.java +132 -0
  121. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/list/ListPluginBasicSample.java +170 -0
  122. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/list/ListPreOpenFilterSample.java +68 -0
  123. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/message/MessageNotifySample.java +95 -0
  124. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/mq/SampleMQConsumer.java +198 -0
  125. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/mq/sample_mq.xml +15 -0
  126. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/operation/OpAddValidatorsSample.java +137 -0
  127. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/operation/OperationOptionBridgeSample.java +228 -0
  128. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/package-info.java +19 -0
  129. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/query/BaseDataQuerySample.java +194 -0
  130. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/query/BatchQuerySample.java +368 -0
  131. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/query/DataSetQueryStatSample.java +131 -0
  132. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/report/SampleReportFormPlugin.java +179 -0
  133. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/report/SampleReportListDataPlugin.java +616 -0
  134. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/snippets-guide.md +64 -0
  135. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/task/ScheduleTaskSample.java +160 -0
  136. package/vendor/kingdee-skills/ok-cosmic/assets/snippets/workflow/SampleWorkflowPlugin.java +302 -0
  137. package/vendor/kingdee-skills/ok-cosmic/manifest.json +78 -0
  138. package/vendor/kingdee-skills/ok-cosmic/ok-cosmic-intro.html +903 -0
  139. package/vendor/kingdee-skills/ok-cosmic/references/adv/attachment-api.md +114 -0
  140. package/vendor/kingdee-skills/ok-cosmic/references/adv/botp-convert.md +98 -0
  141. package/vendor/kingdee-skills/ok-cosmic/references/adv/dynamic-object.md +113 -0
  142. package/vendor/kingdee-skills/ok-cosmic/references/adv/entity-metadata.md +123 -0
  143. package/vendor/kingdee-skills/ok-cosmic/references/adv/event-lifecycle.md +184 -0
  144. package/vendor/kingdee-skills/ok-cosmic/references/adv/flex-prop.md +114 -0
  145. package/vendor/kingdee-skills/ok-cosmic/references/adv/form-utils.md +133 -0
  146. package/vendor/kingdee-skills/ok-cosmic/references/adv/operate-chain.md +159 -0
  147. package/vendor/kingdee-skills/ok-cosmic/references/adv/plugin-base.md +218 -0
  148. package/vendor/kingdee-skills/ok-cosmic/references/adv/query-dataset.md +149 -0
  149. package/vendor/kingdee-skills/ok-cosmic/references/adv/request-context.md +88 -0
  150. package/vendor/kingdee-skills/ok-cosmic/references/adv/view-handler.md +157 -0
  151. package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-bill.md +76 -0
  152. package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-botp.md +70 -0
  153. package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-form.md +165 -0
  154. package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-import.md +69 -0
  155. package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-list.md +227 -0
  156. package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-openapi.md +112 -0
  157. package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-operation.md +135 -0
  158. package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-print.md +65 -0
  159. package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-report-data.md +64 -0
  160. package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-report-form.md +90 -0
  161. package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-task.md +62 -0
  162. package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-tree-list.md +71 -0
  163. package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-workflow.md +82 -0
  164. package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-writeback.md +71 -0
  165. package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-algo.md +67 -0
  166. package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-cache.md +63 -0
  167. package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-dynamic-model-svc.md +82 -0
  168. package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-dynamic-object.md +70 -0
  169. package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-entity-model.md +61 -0
  170. package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-exception.md +64 -0
  171. package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-file.md +63 -0
  172. package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-id.md +47 -0
  173. package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-lock.md +61 -0
  174. package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-log.md +63 -0
  175. package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-network-control.md +70 -0
  176. package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-orm-access.md +78 -0
  177. package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-request-context.md +62 -0
  178. package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-threadpool.md +63 -0
  179. package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-tx.md +64 -0
  180. package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-utils.md +67 -0
  181. package/vendor/kingdee-skills/ok-cosmic/requirements.txt +2 -0
  182. package/vendor/kingdee-skills/ok-cosmic/rules/a-layer-rules.json +24 -0
  183. package/vendor/kingdee-skills/ok-cosmic/rules/anti-patterns.md +48 -0
  184. package/vendor/kingdee-skills/ok-cosmic/rules/cheat-sheet.md +256 -0
  185. package/vendor/kingdee-skills/ok-cosmic/rules/coding-preferences.md +140 -0
  186. package/vendor/kingdee-skills/ok-cosmic/rules/constraints.md +61 -0
  187. package/vendor/kingdee-skills/ok-cosmic/rules/decision-matrix.md +222 -0
  188. package/vendor/kingdee-skills/ok-cosmic/rules/intent-routing.md +94 -0
  189. package/vendor/kingdee-skills/ok-cosmic/rules/platform-baseline.md +69 -0
  190. package/vendor/kingdee-skills/ok-cosmic/rules/post-check.md +109 -0
  191. package/vendor/kingdee-skills/ok-cosmic/scripts/config_loader.py +204 -0
  192. package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-api-knowledge.py +910 -0
  193. package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-basedata-query.py +359 -0
  194. package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-config-check.py +181 -0
  195. package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-extpoints-query.py +389 -0
  196. package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-form-metadata.py +856 -0
  197. package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-post-check.py +262 -0
  198. package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-post-lint.py +293 -0
  199. package/vendor/kingdee-skills/ok-cosmic/scripts/lint/__init__.py +2 -0
  200. package/vendor/kingdee-skills/ok-cosmic/scripts/lint/base.py +393 -0
  201. package/vendor/kingdee-skills/ok-cosmic/scripts/lint/resource_check.py +176 -0
  202. package/vendor/kingdee-skills/ok-cosmic/scripts/lint/scene_check.py +375 -0
  203. package/vendor/kingdee-skills/ok-cosmic/scripts/lint/style_check.py +434 -0
  204. package/vendor/kingdee-skills/ok-cosmic/scripts/lint/verify_check.py +36 -0
  205. package/vendor/kingdee-skills/ok-cosmic/scripts/route_client.py +186 -0
  206. package/vendor/kingdee-skills/ok-cosmic/scripts/script_utils.py +40 -0
  207. package/vendor/kingdee-skills/ok-cosmic/scripts/sqlite_cache.py +142 -0
  208. package/vendor/kingdee-skills/ok-cosmic/setup/cuslib/kd-cd-cosmic-commons.jar +0 -0
  209. package/vendor/kingdee-skills/ok-cosmic/setup/cuslib/kd-cd-cosmic-features.jar +0 -0
  210. package/vendor/kingdee-skills/ok-cosmic/setup/ok-cosmic-docs.db +0 -0
  211. package/vendor/kingdee-skills/ok-cosmic/setup/ok-cosmic.json +13 -0
  212. package/vendor/kingdee-skills/ok-cosmic/setup/setup-mac.sh +18 -0
  213. package/vendor/kingdee-skills/ok-cosmic/setup/setup-windows.bat +53 -0
  214. package/vendor/kingdee-skills/ok-cosmic/setup/setup.jar +0 -0
  215. package/vendor/kingdee-skills/ok-ksql/SKILL.md +81 -0
  216. package/vendor/kingdee-skills/ok-ksql/agents/openai.yaml +7 -0
  217. package/vendor/kingdee-skills/ok-ksql/manifest.json +14 -0
  218. package/vendor/kingdee-skills/ok-ksql/references/ksql-datafix.md +452 -0
  219. package/vendor/kingdee-skills/ok-ksql/scripts/ksql_lint.py +363 -0
@@ -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
+ ```
@@ -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
+ ```