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,298 @@
1
+ # 插件生命周期合规性检查表
2
+
3
+ ## 🔴 P0 级问题
4
+
5
+ ### 1. Initialize 方法滥用
6
+ **检查点**:
7
+ - `initialize()` 内是否调用了 `addItemClickListener()`?
8
+ - `initialize()` 内是否操作了 UI 控件?
9
+
10
+ **风险**: 导致内存泄漏,监听器无法正确释放
11
+
12
+ **修正方案**:
13
+ ```java
14
+ // ❌ 错误写法
15
+ @Override
16
+ public void initialize() {
17
+ this.getView().addItemClickListener(this);
18
+ }
19
+
20
+ // ✅ 正确写法
21
+ @Override
22
+ public void registerListener(EventObject e) {
23
+ this.getView().addItemClickListener(this);
24
+ }
25
+ ```
26
+
27
+ ---
28
+
29
+ ### 2. 数据绑定事件修改模型
30
+ **检查点**:
31
+ - `beforeBindData()` 内是否调用了 `setValue()`?
32
+ - `afterBindData()` 内是否调用了 `setValue()`?
33
+
34
+ **风险**: 破坏数据绑定流程,可能导致数据不一致
35
+
36
+ **修正方案**:
37
+ ```java
38
+ // ❌ 错误写法
39
+ @Override
40
+ public void afterBindData(EventObject e) {
41
+ this.getModel().setValue("field", value);
42
+ }
43
+
44
+ // ✅ 正确写法
45
+ @Override
46
+ public void afterCreateNewData(EventObject e) {
47
+ this.getModel().setValue("field", value);
48
+ }
49
+ ```
50
+
51
+ ---
52
+
53
+ ### 3. 校验器字段未声明
54
+ **检查点**:
55
+ - `validate()` 方法使用了字段 X
56
+ - `preparePropertys()` 是否返回了字段 X?
57
+ - 若校验器继承 `AbstractValidator`,`validate()` 中通过 `dataEntities` 访问的字段,是否在校验器自身的 `preparePropertys()` 中声明,或在引用该校验器的操作插件(`AbstractOperationServicePlugIn`)的 `onPreparePropertys()` 中通过 `e.getFieldKeys().add()` 预加载?(两处满足其一即合规)
58
+ - 操作插件的 `onAddValidators()` 引用了哪些校验器?这些校验器所需字段是否已在操作插件的 `onPreparePropertys()` 中覆盖?
59
+
60
+ **风险**: 校验器无法正确获取字段值,导致校验逻辑基于默认值(null/0/false)运行,校验完全失效且不抛错,极难排查
61
+
62
+ **修正方案**:
63
+ ```java
64
+ // ❌ 错误写法 - 校验器使用了字段,但两处均未预加载
65
+ public class MyValidator extends AbstractValidator {
66
+ @Override
67
+ public void validate() {
68
+ for (ExtendedDataEntity extend : dataEntities) {
69
+ DynamicObject bill = extend.getDataEntity();
70
+ // 使用了 entryentity 子表,但操作插件和校验器均未在 preparePropertys 中声明
71
+ DynamicObjectCollection entries = bill.getDynamicObjectCollection("entryentity");
72
+ }
73
+ }
74
+ }
75
+
76
+ // ✅ 正确写法A - 在校验器自身的 preparePropertys 中声明
77
+ public class MyValidator extends AbstractValidator {
78
+ @Override
79
+ public Collection<String> preparePropertys() {
80
+ List<String> fields = new ArrayList<>();
81
+ fields.add("entryentity");
82
+ fields.add("entryentity.xsbillentryid");
83
+ return fields;
84
+ }
85
+ }
86
+
87
+ // ✅ 正确写法B - 在引用该校验器的操作插件 onPreparePropertys 中预加载
88
+ public class MyOperationPlugin extends AbstractOperationServicePlugIn {
89
+ @Override
90
+ public void onPreparePropertys(PreparePropertysEventArgs e) {
91
+ super.onPreparePropertys(e);
92
+ // 覆盖 MyValidator 所需的字段
93
+ e.getFieldKeys().add("entryentity");
94
+ e.getFieldKeys().add("entryentity.xsbillentryid");
95
+ }
96
+
97
+ @Override
98
+ public void onAddValidators(AddValidatorsEventArgs e) {
99
+ super.onAddValidators(e);
100
+ e.addValidator(new MyValidator());
101
+ }
102
+ }
103
+ ```
104
+
105
+ ---
106
+
107
+ ### 4. 闭包捕获 this 导致内存泄漏
108
+ **检查点**:
109
+ - Lambda 表达式或匿名类是否捕获了 `this`?
110
+ - 是否在静态上下文中持有插件引用?
111
+
112
+ **修正方案**:
113
+ ```java
114
+ // ❌ 错误写法 - 捕获 this
115
+ button.addActionListener(e -> this.doSomething());
116
+
117
+ // ✅ 正确写法 - 使用弱引用或解耦
118
+ button.addActionListener(e -> {
119
+ // 使用局部变量或弱引用
120
+ });
121
+ ```
122
+
123
+ ---
124
+
125
+ ### 5. 操作插件字段未声明(onPreparePropertys)
126
+ **检查点**:
127
+ - 操作插件 `beforeExecuteOperationTransaction` / `afterExecuteOperationTransaction` 中使用了字段 X
128
+ - `onPreparePropertys()` 是否通过 `e.getFieldKeys().add()` 声明了字段 X?
129
+ - 分录字段是否使用 `entryEntity.fieldKey` 格式声明?
130
+
131
+ **风险**: 未声明的字段在操作执行时不会被加载,读取到 null/默认值,导致业务逻辑静默失败
132
+
133
+ **修正方案**:
134
+ ```java
135
+ // ❌ 错误写法 - 使用了字段但未声明
136
+ @Override
137
+ public void beforeExecuteOperationTransaction(BeforeOperationArgs args) {
138
+ for (DynamicObject entity : args.getDataEntities()) {
139
+ String billno = entity.getString("billno"); // billno 未声明,可能为 null
140
+ }
141
+ }
142
+
143
+ // ✅ 正确写法 - 先声明再使用
144
+ @Override
145
+ public void onPreparePropertys(PreparePropertysEventArgs e) {
146
+ super.onPreparePropertys(e);
147
+ e.getFieldKeys().add("billno");
148
+ e.getFieldKeys().add("status");
149
+ e.getFieldKeys().add("entryEntity.field1"); // 分录字段
150
+ }
151
+ ```
152
+
153
+ ---
154
+
155
+ ### 6. afterExecuteOperationTransaction 误用 getOperationResult
156
+ **检查点**:
157
+ - `afterExecuteOperationTransaction()` 中是否调用了 `args.getOperationResult()`?
158
+ - `AfterOperationArgs` 没有 `getOperationResult()` 方法,不要与 `BeforeOperationArgs` 混淆
159
+
160
+ **风险**: 编译失败或运行时异常
161
+
162
+ **修正方案**:
163
+ ```java
164
+ // ❌ 错误写法 - AfterOperationArgs 没有 getOperationResult()
165
+ @Override
166
+ public void afterExecuteOperationTransaction(AfterOperationArgs args) {
167
+ if (args.getOperationResult().isSuccess()) { // 方法不存在!
168
+ // ...
169
+ }
170
+ }
171
+
172
+ // ✅ 正确写法 - afterExecuteOperationTransaction 仅在操作成功后回调,无需判断结果
173
+ @Override
174
+ public void afterExecuteOperationTransaction(AfterOperationArgs args) {
175
+ // 此方法仅在操作成功后回调,直接处理业务逻辑
176
+ for (DynamicObject entity : args.getDataEntities()) {
177
+ updateRelatedData(entity);
178
+ }
179
+ }
180
+ ```
181
+
182
+ ---
183
+
184
+ ### 7. 表单插件生命周期方法顺序错误
185
+ **检查点**:
186
+ - 是否在 `initialize()` 中设置控件可见性?(应在 `afterBindData()` 中)
187
+ - 是否在 `initialize()` 中注册控件事件?(应在 `registerListener()` 中)
188
+ - 是否在 `afterBindData()` 中修改数据对象?(会覆盖用户修改的值)
189
+ - 是否在 `afterCreateNewData()` 中做了仅编辑模式才需要的逻辑?
190
+
191
+ **风险**: 控件状态不生效、事件监听失效、数据被意外覆盖
192
+
193
+ **正确的生命周期顺序**:
194
+ ```
195
+ preOpenForm → initialize → registerListener →
196
+ afterCreateNewData(仅新增)/ afterLoadData(仅编辑)→
197
+ afterCopyData(仅复制)→ beforeBindData → afterBindData
198
+ →(运行中)propertyChanged / itemClick / beforeDoOperation / afterDoOperation
199
+ → beforeClosed → destroy
200
+ ```
201
+
202
+ **各方法职责**:
203
+ | 方法 | 正确用途 | 禁止操作 |
204
+ |------|---------|---------|
205
+ | `initialize` | 初始化插件成员变量 | 注册事件、操作UI控件 |
206
+ | `registerListener` | 注册按钮/F7/Tab监听 | 设置字段值 |
207
+ | `afterCreateNewData` | 设置默认字段值(仅新增) | 操作UI控件 |
208
+ | `afterLoadData` | 编辑模式额外初始化 | 操作UI控件 |
209
+ | `afterBindData` | 控制控件显隐/启用 | 修改数据对象(setValue) |
210
+
211
+ ---
212
+
213
+ ### 8. 工作流插件 super 调用规则混淆
214
+ **检查点**:
215
+ - 实现 `IWorkflowPlugin` 接口的插件是否错误调用了 `super.xxx()`?(接口无需调用 super)
216
+ - 继承 `AbstractWorkflowPlugin` 的插件是否遗漏了 `super.xxx()` 调用?(继承类必须调用 super)
217
+
218
+ **风险**: 接口实现调用 super 编译失败;继承类遗漏 super 导致框架行为异常
219
+
220
+ **修正方案**:
221
+ ```java
222
+ // ❌ 错误写法 - IWorkflowPlugin 接口不需要 super
223
+ public class MyPlugin implements IWorkflowPlugin {
224
+ @Override
225
+ public void notify(AgentExecution execution) {
226
+ super.notify(execution); // 编译错误!接口没有 super
227
+ }
228
+ }
229
+
230
+ // ✅ 正确写法 - 接口直接实现
231
+ public class MyPlugin implements IWorkflowPlugin {
232
+ @Override
233
+ public void notify(AgentExecution execution) {
234
+ // 直接编写业务逻辑
235
+ }
236
+ }
237
+
238
+ // ✅ 继承 AbstractWorkflowPlugin 必须调用 super
239
+ public class MyApprovalPlugin extends AbstractWorkflowPlugin {
240
+ @Override
241
+ public void afterBindData(EventObject e) {
242
+ super.afterBindData(e); // 必须调用
243
+ // 审批页面定制逻辑
244
+ }
245
+ }
246
+ ```
247
+
248
+ ---
249
+
250
+ ### 9. 调度任务插件规范
251
+ **检查点**:
252
+ - 调度任务是否继承 `AbstractTask` 并实现 `Plugin` 接口?
253
+ - `execute` 方法签名是否正确:`execute(RequestContext, Map<String, Object>) throws KDException`?
254
+ - 批量处理时是否每条数据单独 try-catch?
255
+ - 大循环是否反馈进度(`feedbackProgress`)?
256
+ - 长任务是否实现 `StopTask` 接口并在循环中检查 `isStop()`?
257
+
258
+ **风险**: 单条失败影响全局、用户无法感知任务状态、长任务无法停止
259
+
260
+ **修正方案**:
261
+ ```java
262
+ // ❌ 错误写法 - 无进度反馈、无异常隔离
263
+ public class MyTask extends AbstractTask implements Plugin {
264
+ @Override
265
+ public void execute(RequestContext ctx, Map<String, Object> map) throws KDException {
266
+ DynamicObject[] data = BusinessDataServiceHelper.load(...);
267
+ for (DynamicObject obj : data) {
268
+ processData(obj); // 单条失败全部中断
269
+ }
270
+ }
271
+ }
272
+
273
+ // ✅ 正确写法 - 逐条隔离 + 进度反馈 + 可停止
274
+ public class MyTask extends AbstractTask implements Plugin, StopTask {
275
+ @Override
276
+ public void execute(RequestContext ctx, Map<String, Object> map) throws KDException {
277
+ DynamicObject[] data = BusinessDataServiceHelper.load(...);
278
+ int total = data.length;
279
+ int success = 0, fail = 0;
280
+ for (int i = 0; i < total; i++) {
281
+ try {
282
+ processData(data[i]);
283
+ success++;
284
+ } catch (Exception e) {
285
+ fail++;
286
+ log.error("处理失败: id={}", data[i].getPkValue(), e);
287
+ }
288
+ feedbackProgress(100 * (i + 1) / total,
289
+ String.format("已处理 %d/%d", i + 1, total), null);
290
+ if (isStop()) {
291
+ log.info("任务被停止");
292
+ stop();
293
+ break;
294
+ }
295
+ }
296
+ }
297
+ }
298
+ ```