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,286 @@
1
+ package kd.cd.common;
2
+
3
+ import kd.bos.entity.BillEntityType;
4
+ import kd.bos.entity.LinkSetItemElement;
5
+ import kd.bos.entity.botp.plugin.AbstractWriteBackPlugIn;
6
+ import kd.bos.entity.botp.plugin.args.AfterBuildSourceBillIdsEventArgs;
7
+ import kd.bos.entity.botp.plugin.args.AfterCalcWriteValueEventArgs;
8
+ import kd.bos.entity.botp.plugin.args.AfterCloseRowEventArgs;
9
+ import kd.bos.entity.botp.plugin.args.AfterCommitAmountEventArgs;
10
+ import kd.bos.entity.botp.plugin.args.AfterExcessCheckEventArgs;
11
+ import kd.bos.entity.botp.plugin.args.AfterReadSourceBillEventArgs;
12
+ import kd.bos.entity.botp.plugin.args.AfterSaveSourceBillEventArgs;
13
+ import kd.bos.entity.botp.plugin.args.BeforeCloseRowEventArgs;
14
+ import kd.bos.entity.botp.plugin.args.BeforeCreateArticulationRowEventArgs;
15
+ import kd.bos.entity.botp.plugin.args.BeforeExcessCheckEventArgs;
16
+ import kd.bos.entity.botp.plugin.args.BeforeExecWriteBackRuleEventArgs;
17
+ import kd.bos.entity.botp.plugin.args.BeforeReadSourceBillEventArgs;
18
+ import kd.bos.entity.botp.plugin.args.BeforeSaveSourceBillEventArgs;
19
+ import kd.bos.entity.botp.plugin.args.BeforeSaveTransEventArgs;
20
+ import kd.bos.entity.botp.plugin.args.BeforeTrackEventArgs;
21
+ import kd.bos.entity.botp.plugin.args.FinishWriteBackEventArgs;
22
+ import kd.bos.entity.botp.plugin.args.PreparePropertysEventArgs;
23
+ import kd.bos.entity.botp.plugin.args.RollbackSaveEventArgs;
24
+
25
+ /**
26
+ * 单据反写插件骨架模板(原生 AbstractWriteBackPlugIn)。
27
+ * 该类仅用于示例写法,生成后请按实际业务删除无用事件并替换占位常量。
28
+ */
29
+ public class WriteBackPlugInTemplate extends AbstractWriteBackPlugIn {
30
+
31
+ /**
32
+ * 触发时机: 在需要了解当前插件可访问上下文能力时调用。
33
+ * 参数要点: 无入参;仅展示当前插件可通过 this. 访问的方法能力。
34
+ * 典型用途: 作为模板提示,指导在各事件内选择正确的上下文 API。
35
+ */
36
+ private void getContextSample() {
37
+ // this.getCurrLinkSetItem();
38
+ // this.getTargetSubMainType();
39
+ // this.getOpType();
40
+ // this.setContext(null, null, null);
41
+ }
42
+
43
+ // 占位常量:复制模板后请统一替换为业务真实 key。
44
+ private static final String FIELD_TGT_AMOUNT = "writeback_amount";
45
+ private static final String FIELD_SRC_TOTAL = "totalamount";
46
+
47
+ // ===== 反写预处理阶段 =====
48
+
49
+ /**
50
+ * 触发时机: 反写执行前,框架准备目标单字段阶段。
51
+ * 参数要点: e.getFieldKeys() 为后续反写读取字段集合。
52
+ *
53
+ */
54
+
55
+ @Override
56
+ public void preparePropertys(PreparePropertysEventArgs e) {
57
+ super.preparePropertys(e);
58
+ e.getFieldKeys().add(FIELD_TGT_AMOUNT);
59
+ }
60
+
61
+ /**
62
+ * 触发时机: 系统构建来源单据 ID 集合后。
63
+ * 参数要点: e 可读取来源单范围,用于诊断或二次过滤。
64
+ */
65
+ @Override
66
+ public void afterBuildSourceBillIds(AfterBuildSourceBillIdsEventArgs e) {
67
+ super.afterBuildSourceBillIds(e);
68
+ this.getCurrLinkSetItem();
69
+ }
70
+
71
+ /**
72
+ * 触发时机: 读取来源单前。
73
+ * 参数要点: e.getFieldKeys() 控制来源单需加载字段。
74
+ *
75
+ */
76
+
77
+ @Override
78
+ public void beforeReadSourceBill(BeforeReadSourceBillEventArgs e) {
79
+ super.beforeReadSourceBill(e);
80
+ e.getFieldKeys().add(FIELD_SRC_TOTAL);
81
+ }
82
+
83
+ /**
84
+ * 触发时机: 来源单读取完成后。
85
+ * 参数要点: 可访问来源单数据并做缓存,供后续规则使用。
86
+ */
87
+ @Override
88
+ public void afterReadSourceBill(AfterReadSourceBillEventArgs e) {
89
+ super.afterReadSourceBill(e);
90
+ this.getTargetSubMainType();
91
+ }
92
+
93
+ // ===== 超额与规则执行阶段 =====
94
+
95
+ /**
96
+ * 触发时机: 超额校验前。
97
+ * 参数要点: 可按业务改写超额校验上下文。
98
+ */
99
+
100
+ @Override
101
+ public void beforeExcessCheck(BeforeExcessCheckEventArgs e) {
102
+ super.beforeExcessCheck(e);
103
+ this.getCurrLinkSetItem();
104
+ }
105
+
106
+ /**
107
+ * 触发时机: 超额校验后。
108
+ * 参数要点: 可读取超额结果并决定后续行为。
109
+ */
110
+ @Override
111
+ public void afterExcessCheck(AfterExcessCheckEventArgs e) {
112
+ super.afterExcessCheck(e);
113
+ this.getTargetSubMainType();
114
+ }
115
+
116
+ /**
117
+ * 触发时机: 执行反写规则前。
118
+ * 参数要点: 可做最终拦截和环境准备。
119
+ */
120
+
121
+ @Override
122
+ public void beforeExecWriteBackRule(BeforeExecWriteBackRuleEventArgs e) {
123
+ super.beforeExecWriteBackRule(e);
124
+ this.getOpType();
125
+ }
126
+
127
+ /**
128
+ * 触发时机: 反写值计算完成后。
129
+ * 参数要点: 可读取计算结果并做二次修正。
130
+ */
131
+ @Override
132
+ public void afterCalcWriteValue(AfterCalcWriteValueEventArgs e) {
133
+ super.afterCalcWriteValue(e);
134
+ this.getOpType();
135
+ }
136
+
137
+ // ===== 关联行与关行处理 =====
138
+
139
+ /**
140
+ * 触发时机: 创建关联行前。
141
+ * 参数要点: 可按条件跳过关联行生成。
142
+ */
143
+
144
+ @Override
145
+ public void beforeCreateArticulationRow(BeforeCreateArticulationRowEventArgs e) {
146
+ super.beforeCreateArticulationRow(e);
147
+ this.getCurrLinkSetItem();
148
+ }
149
+
150
+ /**
151
+ * 触发时机: 关行前。
152
+ * 参数要点: 可校验关行条件并拦截。
153
+ */
154
+ @Override
155
+ public void beforeCloseRow(BeforeCloseRowEventArgs e) {
156
+ super.beforeCloseRow(e);
157
+ this.getCurrLinkSetItem();
158
+ }
159
+
160
+ /**
161
+ * 触发时机: 关行后。
162
+ * 参数要点: 可记录关行结果并同步状态。
163
+ */
164
+
165
+ @Override
166
+ public void afterCloseRow(AfterCloseRowEventArgs e) {
167
+ super.afterCloseRow(e);
168
+ this.getTargetSubMainType();
169
+ }
170
+
171
+ // ===== 提交与保存阶段 =====
172
+
173
+ /**
174
+ * 触发时机: 反查来源/去向链路前。
175
+ * 参数要点: 可覆盖链路追踪策略。
176
+ */
177
+ @Override
178
+ public void beforeTrack(BeforeTrackEventArgs e) {
179
+ super.beforeTrack(e);
180
+ this.getCurrLinkSetItem();
181
+ }
182
+
183
+ /**
184
+ * 触发时机: 反写数量/金额提交后。
185
+ * 参数要点: 可读取提交汇总结果。
186
+ */
187
+
188
+ @Override
189
+ public void afterCommitAmount(AfterCommitAmountEventArgs e) {
190
+ super.afterCommitAmount(e);
191
+ this.getOpType();
192
+ }
193
+
194
+ /**
195
+ * 触发时机: 保存事务提交前。
196
+ * 参数要点: 适合同事务内最后修正。
197
+ */
198
+ @Override
199
+ public void beforeSaveTrans(BeforeSaveTransEventArgs e) {
200
+ super.beforeSaveTrans(e);
201
+ this.getTargetSubMainType();
202
+ }
203
+
204
+ /**
205
+ * 触发时机: 保存来源单前。
206
+ * 参数要点: 可校验来源单最终写入数据。
207
+ */
208
+
209
+ @Override
210
+ public void beforeSaveSourceBill(BeforeSaveSourceBillEventArgs e) {
211
+ super.beforeSaveSourceBill(e);
212
+ this.getTargetSubMainType();
213
+ }
214
+
215
+ /**
216
+ * 触发时机: 保存来源单后。
217
+ * 参数要点: 可进行后置日志、状态同步。
218
+ */
219
+ @Override
220
+ public void afterSaveSourceBill(AfterSaveSourceBillEventArgs e) {
221
+ super.afterSaveSourceBill(e);
222
+ this.getTargetSubMainType();
223
+ }
224
+
225
+ /**
226
+ * 触发时机: 保存失败并回滚时。
227
+ * 参数要点: e 包含回滚上下文,可做补偿记录。
228
+ */
229
+
230
+ @Override
231
+ public void rollbackSave(RollbackSaveEventArgs e) {
232
+ super.rollbackSave(e);
233
+ this.getOpType();
234
+ }
235
+
236
+ /**
237
+ * 触发时机: 反写流程结束(成功或失败后收尾阶段)。
238
+ * 参数要点: 可统一释放资源、输出日志。
239
+ */
240
+ @Override
241
+ public void finishWriteBack(FinishWriteBackEventArgs e) {
242
+ super.finishWriteBack(e);
243
+ this.getCurrLinkSetItem();
244
+ }
245
+
246
+ // ===== 上下文与元信息 =====
247
+
248
+ /**
249
+ * 获取当前关联关系项。
250
+ * 注意: 模板示例返回 null,实际使用时需根据业务逻辑实现。
251
+ */
252
+ @Override
253
+ public LinkSetItemElement getCurrLinkSetItem() {
254
+ super.getCurrLinkSetItem();
255
+ return null;
256
+ }
257
+
258
+ /**
259
+ * 获取目标单据类型。
260
+ * 注意: 模板示例返回 null,实际使用时需根据业务逻辑实现。
261
+ */
262
+ @Override
263
+ public BillEntityType getTargetSubMainType() {
264
+ super.getTargetSubMainType();
265
+ return null;
266
+ }
267
+
268
+ /**
269
+ * 获取操作类型。
270
+ * 注意: 模板示例返回 null,实际使用时需根据业务逻辑实现。
271
+ */
272
+ @Override
273
+ public String getOpType() {
274
+ super.getOpType();
275
+ return null;
276
+ }
277
+
278
+ /**
279
+ * 设置上下文信息。
280
+ * 注意: 模板示例为空实现,实际使用时需根据业务逻辑实现。
281
+ */
282
+ @Override
283
+ public void setContext(BillEntityType targetSubMainType, String opType, LinkSetItemElement linkSetItem) {
284
+ super.setContext(targetSubMainType, opType, linkSetItem);
285
+ }
286
+ }
@@ -0,0 +1,93 @@
1
+ /**
2
+ * 上传并绑定附件到附件面板示例。
3
+ * <p>
4
+ * 适用插件:表单插件、操作插件、服务层
5
+ * 优先封装:AttachmentUtils、AttPanelUploader
6
+ * 原生兜底:AttachmentServiceHelper、附件面板原生控件 API
7
+ * 相关 lint 规则:STYLE-007、RESOURCE-001、RESOURCE-004
8
+ * <p>
9
+ * 使用场景:
10
+ * 1. 已拿到第三方文件 URL、byte[] 或 InputStream,需要挂到当前单据附件面板;
11
+ * 2. 后台接口建单成功后,继续补传电子回单、影像件、证照等附件;
12
+ * 3. 希望走仓库推荐链路:AttPanelUploader 上传,再 bindTo(...) 绑定。
13
+ * 4. 需要控制同名覆盖或大小校验策略。
14
+ */
15
+ package kd.cd.common.snippets.attachment;
16
+
17
+ import kd.bos.dataentity.resource.ResManager;
18
+ import kd.bos.exception.ErrorCode;
19
+ import kd.bos.exception.KDBizException;
20
+ import kd.bos.logging.Log;
21
+ import kd.bos.logging.LogFactory;
22
+ import kd.cd.common.attachment.AttachmentUtils;
23
+ import kd.cd.common.attachment.upload.AttPanelUploader;
24
+ import kd.cd.common.attachment.upload.PanelUploadResult;
25
+ import kd.cd.core.tuple.State;
26
+
27
+ import java.io.IOException;
28
+ import java.io.InputStream;
29
+
30
+ public class AttachmentUploadBindSample {
31
+ private static final Log log = LogFactory.getLog(AttachmentUploadBindSample.class);
32
+ private static final String TARGET_FORM_ID = "kdcd_basicapplication";
33
+ private static final String ATTACHMENT_PANEL_KEY = "attachmentpanel";
34
+ private static final String RES_APP_ID = "kd-cd-common-snippets";
35
+ private static final String ERR_CODE_ATTACHMENT = "AttachmentUploadBindSample_001";
36
+
37
+ // --- 已有文件 URL:先下载,再上传并绑定 ---
38
+ public static State uploadUrlToPanel(Object pkValue, String fileUrl, String fileName) {
39
+ try (InputStream in = AttachmentUtils.download(fileUrl)) {
40
+ if (in == null) {
41
+ return State.of(false, ResManager.loadKDString("附件下载失败或文件为空", "AttachmentUploadBindSample_0", RES_APP_ID));
42
+ }
43
+ return AttPanelUploader.of(TARGET_FORM_ID, pkValue)
44
+ .upload(in, fileName)
45
+ .bindTo(ATTACHMENT_PANEL_KEY);
46
+ } catch (IOException e) {
47
+ log.error(ResManager.loadKDString("附件下载异常", "AttachmentUploadBindSample_1", RES_APP_ID), e);
48
+ return State.of(false, String.format(
49
+ ResManager.loadKDString("附件下载异常:%s", "AttachmentUploadBindSample_2", RES_APP_ID),
50
+ e.getMessage()
51
+ ));
52
+ }
53
+ }
54
+
55
+ // --- 已有 byte[]:适合接口返回文件流、SFTP 下载结果、报表导出结果 ---
56
+ public static void uploadBytesToPanelOrThrow(Object pkValue, byte[] bytes, String fileName) {
57
+ if (bytes == null || bytes.length == 0) {
58
+ throw new KDBizException(new ErrorCode(
59
+ ERR_CODE_ATTACHMENT,
60
+ ResManager.loadKDString("上传附件不能为空", "AttachmentUploadBindSample_3", RES_APP_ID)
61
+ ));
62
+ }
63
+ State state = AttPanelUploader.of(TARGET_FORM_ID, pkValue)
64
+ .upload(bytes, fileName)
65
+ .bindTo(ATTACHMENT_PANEL_KEY);
66
+ if (!state.isTrue()) {
67
+ throw new KDBizException(new ErrorCode(
68
+ ERR_CODE_ATTACHMENT,
69
+ String.format(
70
+ ResManager.loadKDString("附件上传绑定失败:%s", "AttachmentUploadBindSample_4", RES_APP_ID),
71
+ state.text()
72
+ )
73
+ ));
74
+ }
75
+ }
76
+
77
+ // --- 已有 InputStream:适合页面临时区文件、网关下载流、OSS/SFTP 输入流 ---
78
+ public static State uploadStreamToPanel(Object pkValue, InputStream inputStream, String fileName) {
79
+ return AttPanelUploader.of(TARGET_FORM_ID, pkValue)
80
+ .upload(inputStream, fileName)
81
+ .bindTo(ATTACHMENT_PANEL_KEY);
82
+ }
83
+
84
+ // --- 需要控制上传参数:覆盖同名文件、跳过大小校验 ---
85
+ public static State uploadWithOptions(Object pkValue, byte[] bytes, String fileName, boolean overrideExistFile, boolean skipUploadSizeCheck) {
86
+ AttPanelUploader uploader = AttPanelUploader.of(TARGET_FORM_ID, pkValue);
87
+ uploader.setOverrideExistFile(overrideExistFile);
88
+ uploader.setSkipUploadSizeCheck(skipUploadSizeCheck);
89
+
90
+ PanelUploadResult result = uploader.upload(bytes, fileName);
91
+ return result.bindTo(ATTACHMENT_PANEL_KEY);
92
+ }
93
+ }
@@ -0,0 +1,168 @@
1
+ /**
2
+ * BOTP 链路查询与下推示例。
3
+ * <p>
4
+ * 适用插件:操作插件、转换插件、服务层
5
+ * 优先封装:BotpUtils、OpUtils
6
+ * 原生兜底:PushArgs、DrawArgs、ConvertServiceHelper、OperationServiceHelper
7
+ * 相关 lint 规则:STYLE-003、STYLE-004、STYLE-005
8
+ * <p>
9
+ * 使用场景:
10
+ * 1. 查全部上下游:{@code findAllSourceBills / findAllTargetBills}
11
+ * 2. 只查某一种上下游单据:传 {@code 目标单类型 + 当前单类型 + 主键集}
12
+ * 3. 只看直接关系:{@code findDirectSourceBills / findDirectTargetBills}
13
+ * 4. 下推但不保存:{@code pushNoSave}
14
+ * 5. 下推后补字段再保存:{@code OpUtils.executeOperateOrThrow("save", ...)}
15
+ */
16
+ package kd.cd.common.snippets.botp;
17
+
18
+ import kd.bos.dataentity.entity.DynamicObject;
19
+ import kd.bos.dataentity.entity.DynamicObjectCollection;
20
+ import kd.bos.dataentity.resource.ResManager;
21
+ import kd.bos.orm.query.QCP;
22
+ import kd.bos.orm.query.QFilter;
23
+ import kd.cd.common.operate.OpUtils;
24
+ import kd.cd.common.util.BotpUtils;
25
+ import kd.cd.common.util.DynamicObjectUtils;
26
+ import kd.cd.common.util.PushResult;
27
+ import kd.cd.core.util.CollectionUtils;
28
+ import kd.bos.servicehelper.QueryServiceHelper;
29
+
30
+ import java.util.ArrayList;
31
+ import java.util.Collection;
32
+ import java.util.Collections;
33
+ import java.util.List;
34
+ import java.util.Map;
35
+ import java.util.Set;
36
+ import java.util.stream.Collectors;
37
+
38
+ public class BotpTracePushSample {
39
+ private static final String MEASURE_SETTLE = "kdcd_measuresettlebill";
40
+ private static final String AP_PAYAPPLY = "ap_payapply";
41
+ private static final String CAS_PAYBILL = "cas_paybill";
42
+ private static final String CEXP_DEDUCTION = "kdcd_cexp_deduction";
43
+ private static final String RES_APP_ID = "kd-cd-common-snippets";
44
+
45
+ // ==================== 场景1:全链路下查 ====================
46
+
47
+ /**
48
+ * 以“源单主键 -> 目标单类型 -> 目标单主键集”结构返回全部下游。
49
+ * 适合做整条链路预览或按单据类型分组校验。
50
+ */
51
+ public static Map<Long, Map<String, Set<Long>>> findAllTargetBills(Collection<Long> measureIds) {
52
+ if (CollectionUtils.isEmpty(measureIds)) {
53
+ return Collections.emptyMap();
54
+ }
55
+ return BotpUtils.findAllTargetBills(MEASURE_SETTLE, measureIds);
56
+ }
57
+
58
+ /**
59
+ * 只关心一种目标单据类型时,直接使用扁平化 API。
60
+ */
61
+ public static Set<Long> findAllPayApplyIds(Collection<Long> measureIds) {
62
+ if (CollectionUtils.isEmpty(measureIds)) {
63
+ return Collections.emptySet();
64
+ }
65
+ return BotpUtils.findAllTargetBillsFlat(AP_PAYAPPLY, MEASURE_SETTLE, measureIds);
66
+ }
67
+
68
+ // ==================== 场景2:直接下查 ====================
69
+
70
+ /**
71
+ * 付款申请单只往下看一层付款处理单,不追完整链路。
72
+ */
73
+ public static Set<Long> findDirectPayBillIds(Collection<Long> payApplyIds) {
74
+ if (CollectionUtils.isEmpty(payApplyIds)) {
75
+ return Collections.emptySet();
76
+ }
77
+ return BotpUtils.findDirectTargetBills(CAS_PAYBILL, AP_PAYAPPLY, payApplyIds).values().stream()
78
+ .flatMap(Set::stream)
79
+ .collect(Collectors.toSet());
80
+ }
81
+
82
+ // ==================== 场景3:反查上游 ====================
83
+
84
+ /**
85
+ * 从扣款清单反查全部来源计量结算单。
86
+ */
87
+ public static Set<Long> findAllMeasureIdsByDeduction(Collection<Long> deductionIds) {
88
+ if (CollectionUtils.isEmpty(deductionIds)) {
89
+ return Collections.emptySet();
90
+ }
91
+ return BotpUtils.findAllSourceBillsFlat(MEASURE_SETTLE, CEXP_DEDUCTION, deductionIds);
92
+ }
93
+
94
+ /**
95
+ * 只看直接来源时,仍然建议保留“目标单主键 -> 源单主键集”的映射,后续更好回填。
96
+ */
97
+ public static Map<Long, Set<Long>> findDirectMeasureIdsByDeduction(Collection<Long> deductionIds) {
98
+ if (CollectionUtils.isEmpty(deductionIds)) {
99
+ return Collections.emptyMap();
100
+ }
101
+ return BotpUtils.findDirectSourceBills(MEASURE_SETTLE, CEXP_DEDUCTION, deductionIds);
102
+ }
103
+
104
+ // ==================== 场景4:链路结果回填/提示 ====================
105
+
106
+ /**
107
+ * 构建“源单 -> 指定目标单”的映射,适合附件复制、状态回写、批量关联处理。
108
+ */
109
+ public static Map<Long, Set<Long>> findMeasureToDeductionMap(QFilter filter) {
110
+ DynamicObjectCollection rows = QueryServiceHelper.query(MEASURE_SETTLE, "id", filter.toArray());
111
+ Set<Long> measureIds = DynamicObjectUtils.setOf(rows, "id");
112
+ if (CollectionUtils.isEmpty(measureIds)) {
113
+ return Collections.emptyMap();
114
+ }
115
+ return BotpUtils.findAllTargetBills(CEXP_DEDUCTION, MEASURE_SETTLE, measureIds);
116
+ }
117
+
118
+ /**
119
+ * 只提示某一类下游单据时,先查目标主键,再回查单号,避免把整条链路拼到消息里。
120
+ */
121
+ public static String buildPayApplyExistsMessage(Long measureId, String measureBillNo) {
122
+ Set<Long> payApplyIds = BotpUtils.findAllTargetBillsFlat(
123
+ AP_PAYAPPLY,
124
+ MEASURE_SETTLE,
125
+ Collections.singleton(measureId)
126
+ );
127
+ if (CollectionUtils.isEmpty(payApplyIds)) {
128
+ return null;
129
+ }
130
+ QFilter filter = new QFilter("id", QCP.in, payApplyIds);
131
+ DynamicObjectCollection rows = QueryServiceHelper.query(AP_PAYAPPLY, "id,billno", filter.toArray());
132
+ Map<Long, String> billNoMap = rows.stream().collect(Collectors.toMap(
133
+ row -> row.getLong("id"),
134
+ row -> row.getString("billno"),
135
+ (left, right) -> left
136
+ ));
137
+ String payApplyNos = billNoMap.values().stream().sorted().collect(Collectors.joining("、"));
138
+ return String.format(
139
+ ResManager.loadKDString("计量结算单[%s]已生成付款申请单:%s", "BotpTracePushSample_0", RES_APP_ID),
140
+ measureBillNo,
141
+ payApplyNos
142
+ );
143
+ }
144
+
145
+ // ==================== 场景5:下推生成 ====================
146
+
147
+ /**
148
+ * 下推但先不保存,适合需要补字段、补分录、做二次校验的场景。
149
+ */
150
+ public static DynamicObject pushNoSave(Long measureId, String ruleId) {
151
+ PushResult pushResult = BotpUtils.pushNoSave(MEASURE_SETTLE, AP_PAYAPPLY, measureId, ruleId)
152
+ .failThenThrow();
153
+ return pushResult.getSingleDataPack();
154
+ }
155
+
156
+ /**
157
+ * 下推后补充头字段,再调用统一保存操作。
158
+ */
159
+ public static DynamicObject pushAndSave(Long measureId, String sourceBillNo, String ruleId) {
160
+ DynamicObject targetBill = pushNoSave(measureId, ruleId);
161
+ if (targetBill == null) {
162
+ return null;
163
+ }
164
+ targetBill.set("kdcd_sourcebillno", sourceBillNo);
165
+ OpUtils.executeOperateOrThrow("save", AP_PAYAPPLY, new DynamicObject[]{targetBill});
166
+ return targetBill;
167
+ }
168
+ }