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,491 @@
1
+ # 编码规范与标准检查表
2
+
3
+ ## 🔴 P0 级问题
4
+
5
+ ### 1. 空指针风险 - 链式调用未判空
6
+ **检查点**:
7
+ - `getDynamicObject("xxx").getPkValue()` 是否未判空?
8
+ - `getDynamicObject("xxx").getString()` 是否未判空?
9
+ - 任何 `getXxx()` 返回对象后直接调用方法是否未判空?
10
+
11
+ **风险**: NullPointerException 导致程序崩溃
12
+
13
+ **修正方案**:
14
+ ```java
15
+ // ❌ 错误写法 - 链式调用未判空
16
+ Long orgId = (Long)bill.getDynamicObject("org").getPkValue();
17
+ String name = data.getDynamicObject("user").getString("name");
18
+
19
+ // ✅ 正确写法 - 先判空再调用
20
+ DynamicObject orgObj = bill.getDynamicObject("org");
21
+ if (orgObj == null) {
22
+ throw new KDBizException("组织信息不能为空");
23
+ }
24
+ Long orgId = (Long)orgObj.getPkValue();
25
+
26
+ // ✅ 或者使用 Optional
27
+ Long orgId = Optional.ofNullable(bill.getDynamicObject("org"))
28
+ .map(DynamicObject::getPkValue)
29
+ .map(id -> (Long)id)
30
+ .orElseThrow(() -> new KDBizException("组织信息不能为空"));
31
+ ```
32
+
33
+ ---
34
+
35
+ ### 2. 数组访问未判空
36
+ **检查点**:
37
+ - `getDataEntities()[0]` 是否未判空?
38
+ - `this.dataEntities[0]` 是否未判空?
39
+
40
+ **风险**: ArrayIndexOutOfBoundsException 或 NullPointerException
41
+
42
+ **修正方案**:
43
+ ```java
44
+ // ❌ 错误写法
45
+ DynamicObject data = e.getDataEntities()[0];
46
+
47
+ // ✅ 正确写法
48
+ DynamicObject[] entities = e.getDataEntities();
49
+ if (entities == null || entities.length == 0) {
50
+ return;
51
+ }
52
+ DynamicObject data = entities[0];
53
+ ```
54
+
55
+ ---
56
+
57
+ ## 🟠 P1 级问题
58
+
59
+ ### 3. BigDecimal 未处理 null
60
+ **检查点**:
61
+ - `getBigDecimal("xxx")` 返回值是否可能为 null?
62
+ - 使用 `compareTo()` 前是否判空?
63
+
64
+ **⚠️ 误判排除**:
65
+ - **苍穹 `DynamicObject.getBigDecimal()` 特殊规则**: 若元数据定义该字段不允许为空(即非空字段),`getBigDecimal()` 会返回 `BigDecimal.ZERO` 而非 null,此时无需额外判空
66
+ - 仅当字段在元数据中定义为**可空**,或通过 `DataSet.Row.getBigDecimal()` 获取时,才需要判空
67
+ - **审查时应先确认字段来源**:`DynamicObject` 的非空字段获取 → 无需判空(不报问题);`DataSet.Row` 获取或可空字段 → 需要判空
68
+
69
+ **风险**: NullPointerException(仅在可空字段或 DataSet 场景下)
70
+
71
+ **修正方案**:
72
+ ```java
73
+ // ⚠️ 以下场景无需判空(DynamicObject 非空字段,框架保证返回 BigDecimal.ZERO)
74
+ BigDecimal qty = entry.getBigDecimal("qty"); // 元数据定义非空,返回 ZERO 不会 null
75
+ if (qty.compareTo(BigDecimal.ZERO) > 0) { ... } // 安全
76
+
77
+ // ❌ 错误写法 - DataSet.Row 获取的值可能为 null
78
+ BigDecimal qty = row.getBigDecimal("qty"); // DataSet.Row 可能返回 null
79
+ if (qty.compareTo(BigDecimal.ZERO) > 0) { ... }
80
+
81
+ // ✅ 正确写法 - DataSet.Row 或可空字段场景
82
+ BigDecimal qty = row.getBigDecimal("qty");
83
+ if (qty != null && qty.compareTo(BigDecimal.ZERO) > 0) { ... }
84
+
85
+ // ✅ 或者使用工具方法
86
+ BigDecimal qty = ObjectUtils.defaultIfNull(row.getBigDecimal("qty"), BigDecimal.ZERO);
87
+ ```
88
+
89
+ ---
90
+
91
+ ### 4. 集合操作不规范
92
+ **检查点**:
93
+ - 使用 `size() > 0` 而非 `!isEmpty()`?
94
+ - 集合遍历时是否检查元素是否为 null?
95
+
96
+ **修正方案**:
97
+ ```java
98
+ // ❌ 错误写法
99
+ if (list != null && list.size() > 0) { ... }
100
+
101
+ // ✅ 正确写法
102
+ if (list != null && !list.isEmpty()) { ... }
103
+
104
+ // ✅ 使用工具类(推荐)
105
+ if (CollectionUtils.isNotEmpty(list)) { ... }
106
+ ```
107
+
108
+ ---
109
+
110
+ ### 5. this.dataEntities 直接访问
111
+ **检查点**:
112
+ - Validator 中直接使用 `this.dataEntities` 是否判空?
113
+
114
+ **修正方案**:
115
+ ```java
116
+ // ❌ 错误写法
117
+ public void validate() {
118
+ for(ExtendedDataEntity data : this.dataEntities) { ... }
119
+ }
120
+
121
+ // ✅ 正确写法
122
+ public void validate() {
123
+ if (this.dataEntities == null || this.dataEntities.length == 0) {
124
+ return;
125
+ }
126
+ for(ExtendedDataEntity data : this.dataEntities) { ... }
127
+ }
128
+ ```
129
+
130
+ ---
131
+
132
+ ## 🟡 P2 级问题
133
+
134
+ ### 6. 硬编码中文字符串
135
+ **检查点**:
136
+ - 代码中是否有 `"中文"` 字符串?
137
+ - 是否直接使用中文字符串作为提示信息?
138
+
139
+ **风险**: 无法国际化,维护困难
140
+
141
+ **修正方案**:
142
+ ```java
143
+ // ❌ 错误写法
144
+ this.getView().showMessage("操作成功");
145
+
146
+ // ✅ 正确写法
147
+ String msg = ResManager.loadKDString("操作成功", "key", "module");
148
+ this.getView().showMessage(msg);
149
+ ```
150
+
151
+ ---
152
+
153
+ ### 7. 异常日志丢失堆栈
154
+ **检查点**:
155
+ - `catch` 块中是否只打印了 `e.getMessage()`?
156
+ - `logger.error()` 是否没有传入异常对象?
157
+
158
+ **风险**: 无法定位问题根因
159
+
160
+ **修正方案**:
161
+ ```java
162
+ // ❌ 错误写法
163
+ try {
164
+ // ...
165
+ } catch (Exception e) {
166
+ logger.error("操作失败: " + e.getMessage()); // 丢失堆栈!
167
+ }
168
+
169
+ // ✅ 正确写法
170
+ try {
171
+ // ...
172
+ } catch (Exception e) {
173
+ logger.error("操作失败", e); // 保留完整堆栈
174
+ }
175
+ ```
176
+
177
+ ---
178
+
179
+ ### 8. 魔法数字
180
+ **检查点**:
181
+ - 代码中是否有未解释的数字常量?
182
+
183
+ **修正方案**:
184
+ ```java
185
+ // ❌ 错误写法
186
+ if (status == 1) { ... }
187
+
188
+ // ✅ 正确写法
189
+ private static final int STATUS_ENABLED = 1;
190
+ if (status == STATUS_ENABLED) { ... }
191
+ ```
192
+
193
+ ---
194
+
195
+ ### 9. 变量命名不规范
196
+ **检查点**:
197
+ - 变量名是否符合驼峰命名规范?
198
+ - 常量是否使用全大写下划线?
199
+
200
+ **修正方案**:
201
+ ```java
202
+ // ❌ 错误写法
203
+ String UserName;
204
+ int max_count;
205
+
206
+ // ✅ 正确写法
207
+ String userName;
208
+ int MAX_COUNT;
209
+ ```
210
+
211
+ ---
212
+
213
+ ### 10. 空异常处理
214
+ **检查点**:
215
+ - 是否有空 `catch` 块?
216
+
217
+ **修正方案**:
218
+ ```java
219
+ // ❌ 错误写法
220
+ try {
221
+ // ...
222
+ } catch (Exception e) {
223
+ // 吞掉异常
224
+ }
225
+
226
+ // ✅ 正确写法
227
+ try {
228
+ // ...
229
+ } catch (Exception e) {
230
+ logger.error("处理失败", e);
231
+ throw new RuntimeException("处理失败", e);
232
+ }
233
+ ```
234
+
235
+ ---
236
+
237
+ ### 11. 常量声明不规范
238
+ **检查点**:
239
+ - 实例字段是否应该声明为 static final?
240
+
241
+ **修正方案**:
242
+ ```java
243
+ // ❌ 错误写法
244
+ public class MyValidator {
245
+ private final BigDecimal ZERO; // 每个实例都创建
246
+
247
+ public MyValidator() {
248
+ this.ZERO = BigDecimal.ZERO;
249
+ }
250
+ }
251
+
252
+ // ✅ 正确写法
253
+ public class MyValidator {
254
+ private static final BigDecimal ZERO = BigDecimal.ZERO; // 类级别常量
255
+ }
256
+ ```
257
+
258
+ ---
259
+
260
+ ### 12. 冗余代码
261
+ **检查点**:
262
+ - 是否有无用的空构造函数?
263
+ - 是否有未使用的导入?
264
+ - 是否有注释掉的代码?
265
+
266
+ **修正方案**:
267
+ ```java
268
+ // ❌ 错误写法 - 冗余空构造函数
269
+ public class MyPlugin {
270
+ public MyPlugin() {
271
+ super(); // 完全冗余
272
+ }
273
+ }
274
+
275
+ // ✅ 正确写法 - 删除冗余代码
276
+ public class MyPlugin {
277
+ // 编译器会自动生成默认构造函数
278
+ }
279
+ ```
280
+
281
+ ---
282
+
283
+ ## 命名规范检查
284
+
285
+ ### 13. Java 类命名不规范
286
+ **检查点**:
287
+ - 普通类是否使用 UpperCamelCase?
288
+ - DO/BO/DTO/VO 等缩写是否全大写保留?(`UserDO` 而非 `UserDo`)
289
+ - 抽象类是否以 `Abstract` 开头?
290
+ - 异常类是否以 `Exception` 结尾?
291
+ - 枚举类是否以 `Enum` 后缀,成员是否全大写+下划线?
292
+ - 是否存在随意缩写?(`AbstractClass` → `AbsClass`、`condition` → `condi` 均不可接受)
293
+
294
+ **插件类名后缀规则**:
295
+ | 类型 | 后缀 | 示例 |
296
+ |------|------|------|
297
+ | 表单插件 | `FormPlugin` | `PurchaseFormPlugin` |
298
+ | 单据插件 | `BillPlugin` | `PurchaseBillPlugin` |
299
+ | 列表插件 | `ListPlugin` | `PurchaseListPlugin` |
300
+ | 操作插件 | `OpPlugin` | `PurchaseOpPlugin` |
301
+ | 报表插件 | `RptPlugin` | `PurchaseRptPlugin` |
302
+
303
+ ---
304
+
305
+ ### 14. 变量/常量命名不规范
306
+ **检查点**:
307
+ - 类型名词是否放词尾?(`startTime` 而非 `startedAt`,`nameList` 而非 `listName`)
308
+ - 常量是否全大写+下划线?(`TERMINATED_THREAD_COUNT`)
309
+ - POJO 布尔字段是否加了 `is` 前缀?(`Boolean isDeleted` → RPC 反序列化误读为 `deleted`)
310
+ - 子父类成员变量是否同名?
311
+ - 同一方法不同代码块的局部变量是否同名?
312
+
313
+ **修正方案**:
314
+ ```java
315
+ // ❌ 错误写法 - POJO 布尔字段加 is 前缀
316
+ public class OrderDTO {
317
+ private Boolean isDeleted; // RPC 反序列化会误读为 deleted 字段
318
+ }
319
+
320
+ // ✅ 正确写法
321
+ public class OrderDTO {
322
+ private Boolean deleted;
323
+ }
324
+ ```
325
+
326
+ ---
327
+
328
+ ### 15. 注释规范缺失
329
+ **检查点**:
330
+ - 类/接口是否有 Javadoc 注释?
331
+ - public 方法是否有完整的 Javadoc(@param、@return、@throws)?
332
+ - public 常量/属性是否有注释?
333
+ - 是否使用 `System.out.println` 代替日志?
334
+
335
+ **修正方案**:
336
+ ```java
337
+ // ❌ 错误写法 - 无注释
338
+ public class AttachmentSaveServiceHelper {
339
+ public static DynamicObject buildAttachDetail(DynamicObject typeDy, Long targetId,
340
+ Map<String, Object> attach) throws Exception { ... }
341
+ }
342
+
343
+ // ✅ 正确写法
344
+ /**
345
+ * 附件上传帮助类
346
+ * @author xxx
347
+ * @since 2020-11-20
348
+ */
349
+ public class AttachmentSaveServiceHelper {
350
+ /**
351
+ * 构建附件明细信息
352
+ * @param typeDy 附件类型实体
353
+ * @param targetId 附件 ID
354
+ * @param attach 附件信息
355
+ * @return appendix dynamic object
356
+ * @throws Exception exception
357
+ */
358
+ public static DynamicObject buildAttachDetail(DynamicObject typeDy, Long targetId,
359
+ Map<String, Object> attach) throws Exception { ... }
360
+ }
361
+ ```
362
+
363
+ ---
364
+
365
+ ### 16. 插件继承关系错误
366
+ **检查点**:
367
+ - 表单插件类型与继承基类是否匹配?
368
+
369
+ **正确的继承关系**:
370
+ | 场景 | 继承基类 |
371
+ |------|---------|
372
+ | 单据页面 | `AbstractBillPlugIn` |
373
+ | 基础资料页面 | `AbstractBasePlugIn` |
374
+ | 动态表单页面 | `AbstractFormPlugIn` |
375
+ | 列表页面 | `AbstractListPlugIn` |
376
+ | 移动表单 | `AbstractMobFormPlugin` |
377
+ | 移动单据 | `AbstractMobBillPlugin` |
378
+ | 移动列表 | `AbstractMobListPlugIn` |
379
+ | 操作服务插件 | `AbstractOperationServicePlugIn` |
380
+ | 单据转换插件 | `AbstractConvertPlugIn` |
381
+
382
+ ---
383
+
384
+ ### 17. 日志使用不规范
385
+ **检查点**:
386
+ - 是否使用 `System.out.println` 而非平台日志?
387
+ - 是否使用了非平台日志框架?(必须使用 `kd.bos.logging.Log`)
388
+ - 是否用 JSON 序列化打印页面对象?(`SerializationUtils.toJsonString` 极耗 CPU)
389
+ - debug 日志是否用 `isDebugEnabled()` 包裹?
390
+ - error 日志是否传入了异常对象?
391
+
392
+ **修正方案**:
393
+ ```java
394
+ // ❌ 错误写法
395
+ System.out.println("Debug: " + info);
396
+ SerializationUtils.toJsonString(pageObject); // 极耗 CPU
397
+
398
+ // ✅ 正确写法
399
+ private static final Log logger = LogFactory.getLog(MyClass.class);
400
+
401
+ if (logger.isDebugEnabled()) {
402
+ logger.debug("Debug: " + info);
403
+ }
404
+ logger.error("操作失败", e); // 必须传入异常对象
405
+ ```
406
+
407
+ ---
408
+
409
+ ### 18. 异常处理不规范
410
+ **检查点**:
411
+ - 是否统一使用 `KDException`?
412
+ - 有原始异常时是否作为 cause 传入?
413
+ - 是否直接调用 `Throwable.printStackTrace()`?
414
+ - 是否有空 catch 块(隐藏异常)?
415
+ - UI 层捕获异常后是否给出了业务语义提示(让用户知道下一步怎么处理)?
416
+
417
+ **修正方案**:
418
+ ```java
419
+ // ❌ 错误写法
420
+ try {
421
+ // ...
422
+ } catch (Exception e) {
423
+ e.printStackTrace(); // 禁止
424
+ }
425
+
426
+ // ❌ 错误写法 - 原始异常未作为 cause
427
+ try {
428
+ // ...
429
+ } catch (Exception e) {
430
+ throw new KDException(new ErrorCode("xxx", "操作失败")); // 丢失原始异常
431
+ }
432
+
433
+ // ✅ 正确写法
434
+ try {
435
+ // ...
436
+ } catch (Exception e) {
437
+ throw new KDException(new ErrorCode("xxx", e.getMessage()), e); // 保留原始异常
438
+ }
439
+ ```
440
+
441
+ ---
442
+
443
+ ### 19. 分录字段与单头字段 API 混用
444
+ **检查点**:
445
+ - 操作分录字段时是否使用了单头字段的 `setEnable`/`setVisible` API?
446
+ - 单头 API 操作分录字段不会报错但不生效(静默失败)
447
+
448
+ **修正方案**:
449
+ ```java
450
+ // ❌ 错误写法 - 用单头 API 操作分录字段(静默失败,不报错但不生效)
451
+ getView().setEnable(Boolean.FALSE, new String[]{"entryFieldKey"});
452
+
453
+ // ✅ 正确写法 - 分录字段必须传 rowIndex
454
+ int rowCount = getModel().getEntryRowCount("entryEntity");
455
+ for (int i = 0; i < rowCount; i++) {
456
+ getView().setEnable(Boolean.FALSE, i, new String[]{"entryFieldKey"});
457
+ }
458
+ ```
459
+
460
+ ---
461
+
462
+ ### 20. F7 字段赋值方式错误
463
+ **检查点**:
464
+ - `setValue` 写 F7 基础资料字段时是否传了整个 DynamicObject?(应只传 Long id)
465
+
466
+ **修正方案**:
467
+ ```java
468
+ // ❌ 错误写法 - 传整个 DynamicObject
469
+ DynamicObject org = (DynamicObject) getModel().getValue("org");
470
+ getModel().setValue("owner", org); // 运行时报错
471
+
472
+ // ✅ 正确写法 - 只传 id
473
+ getModel().setValue("owner", org.getLong("id"));
474
+ ```
475
+
476
+ ---
477
+
478
+ ### 21. 引用对象赋值类型不一致
479
+ **检查点**:
480
+ - 不同实体类型的 DynamicObject 是否直接赋值?(需保证对象类型一致)
481
+
482
+ **修正方案**:
483
+ ```java
484
+ // ❌ 错误写法 - 实体类型不一致直接赋值
485
+ DynamicObject customerObj = (DynamicObject) EntityMetadataCache.getData("bd_customer", pk);
486
+ prop.setValueFast(dataEntity, customerObj); // 类型不一致!
487
+
488
+ // ✅ 正确写法 - 通过当前实体自身类型创建实例
489
+ MainEntityType et = this.getModel().getDataEntityType();
490
+ DynamicObject dataEntity = (DynamicObject) et.createInstance();
491
+ ```