kcode-pi 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +358 -0
- package/dist/cli/kcode.d.ts +15 -0
- package/dist/cli/kcode.js +153 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +7 -0
- package/docs/KCODE_DISTRIBUTION.md +91 -0
- package/extensions/kingdee-harness.ts +180 -0
- package/extensions/kingdee-header.ts +122 -0
- package/extensions/kingdee-tools.ts +379 -0
- package/knowledge/.backup/v1.0.0/version.json +10 -0
- package/knowledge/cangqiong/product-notes.md +15 -0
- package/knowledge/common/business-flows.md +115 -0
- package/knowledge/common/config-guides.md +110 -0
- package/knowledge/common/error-patterns.md +170 -0
- package/knowledge/common/implementation.md +144 -0
- package/knowledge/cosmic/hard-constraints.md +38 -0
- package/knowledge/cosmic/ksql-datafix.md +34 -0
- package/knowledge/cosmic/platform-baseline.md +32 -0
- package/knowledge/cosmic/plugin-decision-matrix.md +40 -0
- package/knowledge/cosmic/review-checklist.md +40 -0
- package/knowledge/cosmic/unittest.md +35 -0
- package/knowledge/enterprise/api-reference.md +186 -0
- package/knowledge/enterprise/code-patterns.md +217 -0
- package/knowledge/enterprise/plugin-lifecycle.md +188 -0
- package/knowledge/enterprise/tables.json +159 -0
- package/knowledge/flagship/api-reference.md +237 -0
- package/knowledge/flagship/code-patterns.md +246 -0
- package/knowledge/flagship/cosmic-platform-note.md +15 -0
- package/knowledge/flagship/plugin-lifecycle.md +248 -0
- package/knowledge/flagship/tables.json +159 -0
- package/knowledge/version.json +10 -0
- package/knowledge/xinghan/product-notes.md +15 -0
- package/package.json +71 -0
- package/prompts/kd-discuss.md +11 -0
- package/prompts/kd-execute.md +12 -0
- package/prompts/kd-plan.md +12 -0
- package/prompts/kd-ship.md +12 -0
- package/prompts/kd-spec.md +12 -0
- package/prompts/kd-verify.md +12 -0
- package/skills/kd-check/SKILL.md +26 -0
- package/skills/kd-cosmic-dev/SKILL.md +82 -0
- package/skills/kd-cosmic-review/SKILL.md +90 -0
- package/skills/kd-cosmic-unittest/SKILL.md +92 -0
- package/skills/kd-debug/SKILL.md +30 -0
- package/skills/kd-discuss/SKILL.md +24 -0
- package/skills/kd-execute/SKILL.md +22 -0
- package/skills/kd-gen/SKILL.md +34 -0
- package/skills/kd-ksql/SKILL.md +86 -0
- package/skills/kd-plan/SKILL.md +24 -0
- package/skills/kd-ship/SKILL.md +22 -0
- package/skills/kd-spec/SKILL.md +24 -0
- package/skills/kd-verify/SKILL.md +22 -0
- package/themes/kcode-dark.json +81 -0
- package/vendor/kingdee-skills/cosmic-unittest/SKILL.md +788 -0
- package/vendor/kingdee-skills/cosmic-unittest/author-cache.json +5 -0
- package/vendor/kingdee-skills/cosmic-unittest/cosmic-unittest-skill-overview.html +746 -0
- package/vendor/kingdee-skills/cosmic-unittest/examples/business-test.md +205 -0
- package/vendor/kingdee-skills/cosmic-unittest/examples/common-test.md +257 -0
- package/vendor/kingdee-skills/cosmic-unittest/examples/formplugin-test.md +560 -0
- package/vendor/kingdee-skills/cosmic-unittest/examples/op-plugin-test.md +231 -0
- package/vendor/kingdee-skills/cosmic-unittest/examples/validator-test.md +232 -0
- package/vendor/kingdee-skills/cosmic-unittest/patterns/business-helper.md +184 -0
- package/vendor/kingdee-skills/cosmic-unittest/patterns/common-module.md +355 -0
- package/vendor/kingdee-skills/cosmic-unittest/patterns/convert-plugin.md +130 -0
- package/vendor/kingdee-skills/cosmic-unittest/patterns/formplugin.md +235 -0
- package/vendor/kingdee-skills/cosmic-unittest/patterns/op-plugin.md +226 -0
- package/vendor/kingdee-skills/cosmic-unittest/patterns/validator.md +206 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/SKILL.md +674 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/advanced-scenario-checklist.md +307 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/algox-performance-checklist.md +129 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/coding-standard-checklist.md +491 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/cosmic-api-checklist.md +285 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/data-access-checklist.md +261 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/data-transaction-checklist.md +390 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/domain-logic-checklist.md +295 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/form-plugin-checklist.md +508 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/infra-checklist.md +254 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/ksql-checklist.md +305 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/lifecycle-checklist.md +298 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/operation-plugin-checklist.md +442 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/test-mock-checklist.md +120 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/references/ui-performance-checklist.md +320 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/scripts/pattern-matcher.py +336 -0
- package/vendor/kingdee-skills/kingdee-cosmic-reviewer/scripts/review-score-calculator.py +121 -0
- package/vendor/kingdee-skills/ok-cosmic/CHANGELOG.md +295 -0
- package/vendor/kingdee-skills/ok-cosmic/README.md +460 -0
- package/vendor/kingdee-skills/ok-cosmic/SKILL.md +287 -0
- package/vendor/kingdee-skills/ok-cosmic/agents/openai.yaml +17 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/BatchImportPluginTemplate.java +93 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/BillPlugInTemplate.java +156 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/ConvertPlugInTemplate.java +255 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/FormPluginTemplate.java +597 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/IWorkflowPluginTemplate.java +91 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/ListPluginTemplate.java +194 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/OpPluginTemplate.java +201 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/OpenApiControllerTemplate.java +103 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/PrintPluginTemplate.java +95 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/ReportFormPluginTemplate.java +257 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/ReportListDataPluginTemplate.java +70 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/StandardTreeListPluginTemplate.java +130 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/TaskTemplate.java +80 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/TreeListPluginTemplate.java +152 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/WriteBackPlugInTemplate.java +286 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/attachment/AttachmentUploadBindSample.java +93 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/botp/BotpTracePushSample.java +168 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/botp/SampleConvertPlugin.java +223 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/cache/SampleCacheUsage.java +218 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/concurrent/SampleThreadPoolBatch.java +156 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/data/DynamicObjectCrudSample.java +205 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/data/DynamicObjectOpsSample.java +100 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/BeforeOperationConfirmSample.java +217 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/ConfirmDialogSample.java +131 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/EntryRowCalculateSample.java +116 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/F7FilterSample.java +134 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/GetAndSetValueSample.java +176 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/HyperlinkJumpSample.java +124 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/OpenBillModalSample.java +253 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/ReturnParentDataSample.java +295 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/TreeControlSample.java +140 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/form/ViewControlOpsSample.java +132 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/list/ListPluginBasicSample.java +170 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/list/ListPreOpenFilterSample.java +68 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/message/MessageNotifySample.java +95 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/mq/SampleMQConsumer.java +198 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/mq/sample_mq.xml +15 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/operation/OpAddValidatorsSample.java +137 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/operation/OperationOptionBridgeSample.java +228 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/package-info.java +19 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/query/BaseDataQuerySample.java +194 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/query/BatchQuerySample.java +368 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/query/DataSetQueryStatSample.java +131 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/report/SampleReportFormPlugin.java +179 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/report/SampleReportListDataPlugin.java +616 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/snippets-guide.md +64 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/task/ScheduleTaskSample.java +160 -0
- package/vendor/kingdee-skills/ok-cosmic/assets/snippets/workflow/SampleWorkflowPlugin.java +302 -0
- package/vendor/kingdee-skills/ok-cosmic/manifest.json +78 -0
- package/vendor/kingdee-skills/ok-cosmic/ok-cosmic-intro.html +903 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/attachment-api.md +114 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/botp-convert.md +98 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/dynamic-object.md +113 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/entity-metadata.md +123 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/event-lifecycle.md +184 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/flex-prop.md +114 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/form-utils.md +133 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/operate-chain.md +159 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/plugin-base.md +218 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/query-dataset.md +149 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/request-context.md +88 -0
- package/vendor/kingdee-skills/ok-cosmic/references/adv/view-handler.md +157 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-bill.md +76 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-botp.md +70 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-form.md +165 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-import.md +69 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-list.md +227 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-openapi.md +112 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-operation.md +135 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-print.md +65 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-report-data.md +64 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-report-form.md +90 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-task.md +62 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-tree-list.md +71 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-workflow.md +82 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/plugin/plugin-writeback.md +71 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-algo.md +67 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-cache.md +63 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-dynamic-model-svc.md +82 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-dynamic-object.md +70 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-entity-model.md +61 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-exception.md +64 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-file.md +63 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-id.md +47 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-lock.md +61 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-log.md +63 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-network-control.md +70 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-orm-access.md +78 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-request-context.md +62 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-threadpool.md +63 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-tx.md +64 -0
- package/vendor/kingdee-skills/ok-cosmic/references/base/sdk/sdk-utils.md +67 -0
- package/vendor/kingdee-skills/ok-cosmic/requirements.txt +2 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/a-layer-rules.json +24 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/anti-patterns.md +48 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/cheat-sheet.md +256 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/coding-preferences.md +140 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/constraints.md +61 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/decision-matrix.md +222 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/intent-routing.md +94 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/platform-baseline.md +69 -0
- package/vendor/kingdee-skills/ok-cosmic/rules/post-check.md +109 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/config_loader.py +204 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-api-knowledge.py +910 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-basedata-query.py +359 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-config-check.py +181 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-extpoints-query.py +389 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-form-metadata.py +856 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-post-check.py +262 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/cosmic-post-lint.py +293 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/lint/__init__.py +2 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/lint/base.py +393 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/lint/resource_check.py +176 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/lint/scene_check.py +375 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/lint/style_check.py +434 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/lint/verify_check.py +36 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/route_client.py +186 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/script_utils.py +40 -0
- package/vendor/kingdee-skills/ok-cosmic/scripts/sqlite_cache.py +142 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/cuslib/kd-cd-cosmic-commons.jar +0 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/cuslib/kd-cd-cosmic-features.jar +0 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/ok-cosmic-docs.db +0 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/ok-cosmic.json +13 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/setup-mac.sh +18 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/setup-windows.bat +53 -0
- package/vendor/kingdee-skills/ok-cosmic/setup/setup.jar +0 -0
- package/vendor/kingdee-skills/ok-ksql/SKILL.md +81 -0
- package/vendor/kingdee-skills/ok-ksql/agents/openai.yaml +7 -0
- package/vendor/kingdee-skills/ok-ksql/manifest.json +14 -0
- package/vendor/kingdee-skills/ok-ksql/references/ksql-datafix.md +452 -0
- package/vendor/kingdee-skills/ok-ksql/scripts/ksql_lint.py +363 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* onPreparePropertys + onAddValidators 示例。
|
|
3
|
+
* <p>
|
|
4
|
+
* 适用插件:操作插件
|
|
5
|
+
* 优先封装:AbstractOperationServicePlugInExt、AbstractValidatorExt、DynamicObjectUtils
|
|
6
|
+
* 原生兜底:PreparePropertysEventArgs、AddValidatorsEventArgs、ExtendedDataEntity
|
|
7
|
+
* 相关 lint 规则:STYLE-003、STYLE-010
|
|
8
|
+
* <p>
|
|
9
|
+
* 使用场景:
|
|
10
|
+
* 1. preparePropertys 显式准备头/体字段
|
|
11
|
+
* 2. onAddValidators 按规则拆分校验器
|
|
12
|
+
* 3. 单据头校验、分录聚合校验、分录行级校验分开处理
|
|
13
|
+
* 4. 错误信息挂到操作结果里,而不是直接抛异常
|
|
14
|
+
*/
|
|
15
|
+
package kd.cd.common.snippets.operation;
|
|
16
|
+
|
|
17
|
+
import kd.bos.dataentity.entity.DynamicObject;
|
|
18
|
+
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
19
|
+
import kd.bos.dataentity.resource.ResManager;
|
|
20
|
+
import kd.bos.entity.ExtendedDataEntity;
|
|
21
|
+
import kd.bos.entity.plugin.AddValidatorsEventArgs;
|
|
22
|
+
import kd.bos.entity.plugin.PreparePropertysEventArgs;
|
|
23
|
+
import kd.cd.common.plugin.AbstractOperationServicePlugInExt;
|
|
24
|
+
import kd.cd.common.plugin.AbstractValidatorExt;
|
|
25
|
+
import kd.cd.common.util.DynamicObjectUtils;
|
|
26
|
+
import kd.cd.core.util.BigDecimalUtils;
|
|
27
|
+
|
|
28
|
+
import java.math.BigDecimal;
|
|
29
|
+
import java.util.ArrayList;
|
|
30
|
+
import java.util.List;
|
|
31
|
+
import java.util.stream.Collectors;
|
|
32
|
+
|
|
33
|
+
public class OpAddValidatorsSample extends AbstractOperationServicePlugInExt {
|
|
34
|
+
private static final String TARGET_BILL_TYPE = "kdcd_measuresettlebill_B_02";
|
|
35
|
+
private static final String FIELD_BILL_NO = "billno";
|
|
36
|
+
private static final String FIELD_CONTRACT = "kdcd_contract";
|
|
37
|
+
private static final String FIELD_BILL_TYPE = "kdcd_billtype";
|
|
38
|
+
private static final String FIELD_INITIALIZATION = "kdcd_initialization";
|
|
39
|
+
private static final String ENTRY_MEASURE_DETAIL = "kdcd_measuredelail";
|
|
40
|
+
private static final String FIELD_TOTAL_TAX = "kdcd_totaltax";
|
|
41
|
+
private static final String ENTRY_INVOICE_DETAIL = "kdcd_invoicedetail";
|
|
42
|
+
private static final String FIELD_PRICE_TAX_TOTAL = "kdcd_pricetaxtotal";
|
|
43
|
+
private static final String FIELD_SEQ = "seq";
|
|
44
|
+
|
|
45
|
+
@Override
|
|
46
|
+
public void onPreparePropertys(PreparePropertysEventArgs e) {
|
|
47
|
+
super.onPreparePropertys(e);
|
|
48
|
+
List<String> fieldKeys = e.getFieldKeys();
|
|
49
|
+
fieldKeys.add(FIELD_BILL_NO);
|
|
50
|
+
fieldKeys.add(FIELD_CONTRACT);
|
|
51
|
+
fieldKeys.add(FIELD_CONTRACT + ".number");
|
|
52
|
+
fieldKeys.add(FIELD_BILL_TYPE);
|
|
53
|
+
fieldKeys.add(FIELD_BILL_TYPE + ".number");
|
|
54
|
+
fieldKeys.add(FIELD_INITIALIZATION);
|
|
55
|
+
fieldKeys.addAll(entryFields(ENTRY_MEASURE_DETAIL, ENTRY_INVOICE_DETAIL));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@Override
|
|
59
|
+
public void onAddValidators(AddValidatorsEventArgs e) {
|
|
60
|
+
super.onAddValidators(e);
|
|
61
|
+
e.addValidator(new ContractRequiredValidator());
|
|
62
|
+
e.addValidator(new InvoiceAmountEqualsValidator());
|
|
63
|
+
e.addValidator(new InvoiceAmountPositiveValidator());
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private static class ContractRequiredValidator extends AbstractValidatorExt {
|
|
67
|
+
@Override
|
|
68
|
+
public void validate() {
|
|
69
|
+
for (ExtendedDataEntity ext : getDataEntities()) {
|
|
70
|
+
DynamicObject bill = ext.getDataEntity();
|
|
71
|
+
if (shouldSkip(bill)) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (bill.getDynamicObject(FIELD_CONTRACT) == null) {
|
|
75
|
+
addMessageWithErrCode(ext, "kdcd_contract_required", "合同不能为空");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private static class InvoiceAmountEqualsValidator extends AbstractValidatorExt {
|
|
82
|
+
@Override
|
|
83
|
+
public void validate() {
|
|
84
|
+
for (ExtendedDataEntity ext : getDataEntities()) {
|
|
85
|
+
DynamicObject bill = ext.getDataEntity();
|
|
86
|
+
if (shouldSkip(bill)) {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
DynamicObjectCollection measureRows = bill.getDynamicObjectCollection(ENTRY_MEASURE_DETAIL);
|
|
91
|
+
DynamicObjectCollection invoiceRows = bill.getDynamicObjectCollection(ENTRY_INVOICE_DETAIL);
|
|
92
|
+
BigDecimal measureTotal = DynamicObjectUtils.sumOf(measureRows, FIELD_TOTAL_TAX);
|
|
93
|
+
BigDecimal invoiceTotal = DynamicObjectUtils.sumOf(invoiceRows, FIELD_PRICE_TAX_TOTAL);
|
|
94
|
+
if (!BigDecimalUtils.equals(measureTotal, invoiceTotal)) {
|
|
95
|
+
addMessageWithErrCode(ext, "kdcd_invoice_amount_not_match", "发票明细价税合计必须等于计量明细本期价税合计");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
private static class InvoiceAmountPositiveValidator extends AbstractValidatorExt {
|
|
102
|
+
@Override
|
|
103
|
+
public void validate() {
|
|
104
|
+
for (ExtendedDataEntity ext : getDataEntities()) {
|
|
105
|
+
DynamicObject bill = ext.getDataEntity();
|
|
106
|
+
if (shouldSkip(bill)) {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
DynamicObjectCollection invoiceRows = bill.getDynamicObjectCollection(ENTRY_INVOICE_DETAIL);
|
|
111
|
+
List<String> invalidSeqs = invoiceRows.stream()
|
|
112
|
+
.filter(row -> !BigDecimalUtils.largeThanZero(
|
|
113
|
+
BigDecimalUtils.nullToZero(row.getBigDecimal(FIELD_PRICE_TAX_TOTAL))))
|
|
114
|
+
.map(row -> String.valueOf(row.get(FIELD_SEQ)))
|
|
115
|
+
.collect(Collectors.toList());
|
|
116
|
+
if (!invalidSeqs.isEmpty()) {
|
|
117
|
+
addMessageWithErrCode(
|
|
118
|
+
ext,
|
|
119
|
+
"kdcd_invoice_row_amount_not_positive",
|
|
120
|
+
String.format(
|
|
121
|
+
ResManager.loadKDString("发票明细第%s行价税合计必须大于 0", "OpAddValidatorsSample_0", "kd-cd-common-snippets"),
|
|
122
|
+
String.join("、", invalidSeqs)
|
|
123
|
+
)
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
private static boolean isTargetBill(DynamicObject bill) {
|
|
131
|
+
return TARGET_BILL_TYPE.equals(DynamicObjectUtils.nullSafeGet(bill, FIELD_BILL_TYPE + ".number"));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
private static boolean shouldSkip(DynamicObject bill) {
|
|
135
|
+
return !isTargetBill(bill) || Boolean.TRUE.equals(DynamicObjectUtils.nullSafeGet(bill, FIELD_INITIALIZATION));
|
|
136
|
+
}
|
|
137
|
+
}
|
package/vendor/kingdee-skills/ok-cosmic/assets/snippets/operation/OperationOptionBridgeSample.java
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 界面插件与操作插件之间通过 OperateOption 传值示例。
|
|
3
|
+
* <p>
|
|
4
|
+
* 适用插件:表单插件、操作插件
|
|
5
|
+
* 优先封装:AbstractFormPluginExt、AbstractOperationServicePlugInExt
|
|
6
|
+
* 原生兜底:OperateOption、BeforeDoOperationEventArgs、AfterOperationArgs
|
|
7
|
+
* 相关 lint 规则:SCENE-001、STYLE-013
|
|
8
|
+
* <p>
|
|
9
|
+
* 使用场景:
|
|
10
|
+
* 1. 提交前先打开复核页,用户确认后带 continue 标记重新执行提交;
|
|
11
|
+
* 2. 界面插件把临时参数传给操作插件;
|
|
12
|
+
* 3. 操作插件把处理结果回写到 option,供界面插件展示提示。
|
|
13
|
+
*/
|
|
14
|
+
package kd.cd.common.snippets.operation;
|
|
15
|
+
|
|
16
|
+
import kd.bos.bill.OperationStatus;
|
|
17
|
+
import kd.bos.dataentity.OperateOption;
|
|
18
|
+
import kd.bos.dataentity.entity.DynamicObject;
|
|
19
|
+
import kd.bos.dataentity.resource.ResManager;
|
|
20
|
+
import kd.bos.entity.plugin.args.AfterOperationArgs;
|
|
21
|
+
import kd.bos.entity.plugin.args.BeginOperationTransactionArgs;
|
|
22
|
+
import kd.bos.form.CloseCallBack;
|
|
23
|
+
import kd.bos.form.FormShowParameter;
|
|
24
|
+
import kd.bos.form.ShowType;
|
|
25
|
+
import kd.bos.form.events.AfterDoOperationEventArgs;
|
|
26
|
+
import kd.bos.form.events.BeforeDoOperationEventArgs;
|
|
27
|
+
import kd.bos.form.events.ClosedCallBackEvent;
|
|
28
|
+
import kd.bos.form.operate.FormOperate;
|
|
29
|
+
import kd.cd.common.form.ShowParameterUtils;
|
|
30
|
+
import kd.cd.common.plugin.AbstractFormPluginExt;
|
|
31
|
+
import kd.cd.common.plugin.AbstractOperationServicePlugInExt;
|
|
32
|
+
import kd.cd.core.util.CharSequenceUtils;
|
|
33
|
+
|
|
34
|
+
import java.util.ArrayList;
|
|
35
|
+
import java.util.Arrays;
|
|
36
|
+
import java.util.List;
|
|
37
|
+
|
|
38
|
+
import java.util.Map;
|
|
39
|
+
|
|
40
|
+
public class OperationOptionBridgeSample {
|
|
41
|
+
public static final String OP_SUBMIT = "submit";
|
|
42
|
+
public static final String REVIEW_FORM_ID = "xxxx_submitreview";
|
|
43
|
+
public static final String REVIEW_CALLBACK_ID = "submit_review";
|
|
44
|
+
public static final String OPTION_CUSTOM_ITEM = "customItem";
|
|
45
|
+
public static final String OPTION_SKIP_SUBMIT_REVIEW = "skipSubmitReview";
|
|
46
|
+
public static final String OPTION_REVIEW_COMMENT = "reviewComment";
|
|
47
|
+
public static final String OPTION_ALL_BILL_NO = "allBillNo";
|
|
48
|
+
public static final String OPTION_WARNING_SUMMARY = "warningSummary";
|
|
49
|
+
public static final String FIELD_RISK_FLAG = "xxxx_riskflag";
|
|
50
|
+
public static final String FIELD_REVIEW_COMMENT = "xxxx_reviewcomment";
|
|
51
|
+
public static final String FIELD_CUSTOM_TAG = "xxxx_customtag";
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 界面插件侧:提交前拦截、弹复核页、读取操作插件回传值。
|
|
55
|
+
* 同文件中同时放了操作插件示例,lint 可能把本类里的 getView() 误判到操作插件上下文。
|
|
56
|
+
*/
|
|
57
|
+
public static class BillViewSide extends AbstractFormPluginExt {
|
|
58
|
+
@Override
|
|
59
|
+
public void beforeDoOperation(BeforeDoOperationEventArgs e) {
|
|
60
|
+
super.beforeDoOperation(e);
|
|
61
|
+
FormOperate operate = (FormOperate) e.getSource();
|
|
62
|
+
if (!OP_SUBMIT.equals(operate.getOperateKey())) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
bindSharedOption(operate.getOption());
|
|
67
|
+
if (shouldSkipSubmitReview(operate.getOption()) || !needOpenSubmitReview()) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
e.setCancel(true);
|
|
72
|
+
openSubmitReviewDialog();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@Override
|
|
76
|
+
public void afterDoOperation(AfterDoOperationEventArgs e) {
|
|
77
|
+
super.afterDoOperation(e);
|
|
78
|
+
FormOperate operate = (FormOperate) e.getSource();
|
|
79
|
+
if (!OP_SUBMIT.equals(operate.getOperateKey()) || !e.getOperationResult().isSuccess()) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
String allBillNo = operate.getOption().getVariableValue(OPTION_ALL_BILL_NO, "");
|
|
84
|
+
String warningSummary = operate.getOption().getVariableValue(OPTION_WARNING_SUMMARY, "");
|
|
85
|
+
if (CharSequenceUtils.isBlank(allBillNo) && CharSequenceUtils.isBlank(warningSummary)) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
StringBuilder msg = new StringBuilder("提交成功");
|
|
90
|
+
if (CharSequenceUtils.isNotBlank(allBillNo)) {
|
|
91
|
+
msg.append(":").append(allBillNo);
|
|
92
|
+
}
|
|
93
|
+
if (CharSequenceUtils.isNotBlank(warningSummary)) {
|
|
94
|
+
msg.append(";").append(warningSummary);
|
|
95
|
+
}
|
|
96
|
+
e.getOperationResult().setMessage(msg.toString());
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@Override
|
|
100
|
+
public void closedCallBack(ClosedCallBackEvent e) {
|
|
101
|
+
super.closedCallBack(e);
|
|
102
|
+
// 回调数据类型和复核页的回传类型保持一致即可。
|
|
103
|
+
if (!REVIEW_CALLBACK_ID.equals(e.getActionId())) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
@SuppressWarnings("unchecked")
|
|
107
|
+
Map<String, Object> reviewData = (Map<String, Object>) e.getReturnData();
|
|
108
|
+
if (reviewData == null || !isConfirmed(reviewData)) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
OperateOption option = OperateOption.create();
|
|
113
|
+
bindSharedOption(option);
|
|
114
|
+
option.setVariableValue(OPTION_SKIP_SUBMIT_REVIEW, "true");
|
|
115
|
+
|
|
116
|
+
String reviewComment = extractReviewComment(reviewData);
|
|
117
|
+
if (CharSequenceUtils.isNotBlank(reviewComment)) {
|
|
118
|
+
option.setVariableValue(OPTION_REVIEW_COMMENT, reviewComment);
|
|
119
|
+
}
|
|
120
|
+
getView().invokeOperation(OP_SUBMIT, option);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private void bindSharedOption(OperateOption option) {
|
|
124
|
+
String customItem = resolveCustomItem();
|
|
125
|
+
if (CharSequenceUtils.isNotBlank(customItem)) {
|
|
126
|
+
option.setVariableValue(OPTION_CUSTOM_ITEM, customItem);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
private boolean needOpenSubmitReview() {
|
|
131
|
+
return Boolean.TRUE.equals(getModel().getValue(FIELD_RISK_FLAG));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
private boolean shouldSkipSubmitReview(OperateOption option) {
|
|
135
|
+
return "true".equalsIgnoreCase(option.getVariableValue(OPTION_SKIP_SUBMIT_REVIEW, "false"));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
private void openSubmitReviewDialog() {
|
|
139
|
+
FormShowParameter fsp = ShowParameterUtils.getForm(
|
|
140
|
+
REVIEW_FORM_ID,
|
|
141
|
+
OperationStatus.ADDNEW,
|
|
142
|
+
ShowType.Modal,
|
|
143
|
+
"720px",
|
|
144
|
+
"420px"
|
|
145
|
+
);
|
|
146
|
+
fsp.setCustomParam("billNo", getModel().getValue("billno"));
|
|
147
|
+
fsp.setCustomParam("customItem", resolveCustomItem());
|
|
148
|
+
fsp.setCloseCallBack(new CloseCallBack(this, REVIEW_CALLBACK_ID));
|
|
149
|
+
getView().showForm(fsp);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
private String resolveCustomItem() {
|
|
153
|
+
Object customTag = getModel().getValue(FIELD_CUSTOM_TAG);
|
|
154
|
+
String text = customTag == null ? "" : String.valueOf(customTag).trim();
|
|
155
|
+
return CharSequenceUtils.isBlank(text) ? "default-tag" : text;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
private boolean isConfirmed(Map<String, Object> returnData) {
|
|
159
|
+
return Boolean.TRUE.equals(returnData.get("confirmed"));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
private String extractReviewComment(Map<String, Object> returnData) {
|
|
163
|
+
Object comment = returnData.get("reviewComment");
|
|
164
|
+
return comment == null ? "" : String.valueOf(comment).trim();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* 操作插件侧:读取界面参数并回写结果摘要。
|
|
170
|
+
*/
|
|
171
|
+
public static class SaveSubmitOpSide extends AbstractOperationServicePlugInExt {
|
|
172
|
+
@Override
|
|
173
|
+
public void beginOperationTransaction(BeginOperationTransactionArgs e) {
|
|
174
|
+
super.beginOperationTransaction(e);
|
|
175
|
+
if (!OP_SUBMIT.equals(e.getOperationKey())) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
String customItem = getOption().getVariableValue(OPTION_CUSTOM_ITEM, "");
|
|
180
|
+
String reviewComment = getOption().getVariableValue(OPTION_REVIEW_COMMENT, "");
|
|
181
|
+
for (DynamicObject bill : e.getDataEntities()) {
|
|
182
|
+
if (CharSequenceUtils.isNotBlank(customItem)) {
|
|
183
|
+
bill.set("remark", appendRemark(bill.getString("remark"), customItem));
|
|
184
|
+
}
|
|
185
|
+
if (CharSequenceUtils.isNotBlank(reviewComment)) {
|
|
186
|
+
bill.set(FIELD_REVIEW_COMMENT, reviewComment);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
@Override
|
|
192
|
+
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
|
|
193
|
+
super.afterExecuteOperationTransaction(e);
|
|
194
|
+
if (!OP_SUBMIT.equals(e.getOperationKey()) || !getOperationResult().isSuccess()) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
List<String> billNoList = new ArrayList<>();
|
|
199
|
+
boolean hasRiskBill = false;
|
|
200
|
+
for (DynamicObject bill : e.getDataEntities()) {
|
|
201
|
+
String billNo = bill.getString("billno");
|
|
202
|
+
if (CharSequenceUtils.isNotBlank(billNo)) {
|
|
203
|
+
billNoList.add(billNo);
|
|
204
|
+
}
|
|
205
|
+
hasRiskBill = hasRiskBill || isRiskBill(bill);
|
|
206
|
+
}
|
|
207
|
+
getOption().setVariableValue(OPTION_ALL_BILL_NO, String.join("、", billNoList));
|
|
208
|
+
if (hasRiskBill) {
|
|
209
|
+
getOption().setVariableValue(OPTION_WARNING_SUMMARY, "命中风险复核,已按复核意见继续提交");
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
private String appendRemark(String remark, String customItem) {
|
|
214
|
+
String line = String.format(
|
|
215
|
+
ResManager.loadKDString("界面参数:%s", "OperationOptionBridgeSample_0", "kd-cd-common-snippets"),
|
|
216
|
+
customItem
|
|
217
|
+
);
|
|
218
|
+
if (CharSequenceUtils.isBlank(remark)) {
|
|
219
|
+
return line;
|
|
220
|
+
}
|
|
221
|
+
return remark + System.lineSeparator() + line;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
private boolean isRiskBill(DynamicObject bill) {
|
|
225
|
+
return Boolean.TRUE.equals(bill.get(FIELD_RISK_FLAG));
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 苍穹 Commons 示例样本总览。
|
|
3
|
+
* <p>
|
|
4
|
+
* 建议按“先选场景、再看 API”的顺序阅读:
|
|
5
|
+
* <ul>
|
|
6
|
+
* <li>{@code attachment}: 附件上传、绑定、覆盖策略</li>
|
|
7
|
+
* <li>{@code botp}: 上下游追踪、直接/全链路查询、下推生成</li>
|
|
8
|
+
* <li>{@code data}: DynamicObject 安全操作、后端建单/保存/复制</li>
|
|
9
|
+
* <li>{@code form}: 表单/单据插件常见交互、页面状态控制、弹窗、回调、树控件、F7 过滤</li>
|
|
10
|
+
* <li>{@code list}: 列表插件过滤、列格式化、操作列控制</li>
|
|
11
|
+
* <li>{@code message}: 系统消息与通知用户收集</li>
|
|
12
|
+
* <li>{@code operation}: 操作插件、校验器注册、界面/操作参数桥接</li>
|
|
13
|
+
* <li>{@code query}: 基础资料缓存查询、DataSet 聚合、批量取数</li>
|
|
14
|
+
* <li>{@code task}: 后台任务与巡检型逻辑</li>
|
|
15
|
+
* </ul>
|
|
16
|
+
* <p>
|
|
17
|
+
* 每个样本尽量围绕一个明确场景展开,避免同一 API 在多个文件中重复铺陈。
|
|
18
|
+
*/
|
|
19
|
+
package kd.cd.common.snippets;
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 基础资料查询示例。
|
|
3
|
+
* <p>
|
|
4
|
+
* 适用插件:表单插件、操作插件、服务层
|
|
5
|
+
* 优先封装:BusinessDataServiceHelper.loadFromCache(...)
|
|
6
|
+
* 原生兜底:BaseDataServiceHelper、QFilter、QueryServiceHelper
|
|
7
|
+
* 相关 lint 规则:STYLE-008、STYLE-015
|
|
8
|
+
* <p>
|
|
9
|
+
* 使用场景:根据编码、ID 或批量条件加载基础资料并回写界面。
|
|
10
|
+
* 关键点:
|
|
11
|
+
* 1. 基础资料优先走 BusinessDataServiceHelper.loadFromCache(...)。
|
|
12
|
+
* 2. 需要先按编码查主键时,优先用 QueryServiceHelper.query(...)。
|
|
13
|
+
* 3. 批量场景先查主键集合,再一次性 loadFromCache,避免循环查库。
|
|
14
|
+
* 4. 带组织权限过滤时使用 BaseDataServiceHelper.queryBaseData(...)。
|
|
15
|
+
*/
|
|
16
|
+
package kd.cd.common.snippets.query;
|
|
17
|
+
|
|
18
|
+
import kd.bos.dataentity.entity.DynamicObject;
|
|
19
|
+
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
20
|
+
import kd.bos.orm.query.QCP;
|
|
21
|
+
import kd.bos.orm.query.QFilter;
|
|
22
|
+
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
23
|
+
import kd.bos.servicehelper.QueryServiceHelper;
|
|
24
|
+
import kd.bos.servicehelper.basedata.BaseDataServiceHelper;
|
|
25
|
+
import kd.cd.common.plugin.AbstractFormPluginExt;
|
|
26
|
+
import kd.cd.common.util.DynamicObjectUtils;
|
|
27
|
+
import kd.cd.core.util.CollectionUtils;
|
|
28
|
+
|
|
29
|
+
import java.util.Collection;
|
|
30
|
+
import java.util.Collections;
|
|
31
|
+
import java.util.Date;
|
|
32
|
+
import java.util.HashMap;
|
|
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 BaseDataQuerySample extends AbstractFormPluginExt {
|
|
39
|
+
private static final String BD_SUPPLIER = "bd_supplier";
|
|
40
|
+
private static final String BD_CUSTOMER = "bd_customer";
|
|
41
|
+
private static final String BOS_USER = "bos_user";
|
|
42
|
+
private static final String BD_TAXRATE = "bd_taxrate";
|
|
43
|
+
private static final String FIELD_ID = "id";
|
|
44
|
+
private static final String FIELD_NUMBER = "number";
|
|
45
|
+
private static final String FIELD_NAME = "name";
|
|
46
|
+
private static final String FIELD_ENABLE = "enable";
|
|
47
|
+
private static final String FIELD_STATUS = "status";
|
|
48
|
+
|
|
49
|
+
// ==================== 场景1:按主键批量走缓存查询 ====================
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 根据主键集合批量走缓存,返回 id -> DynamicObject 映射
|
|
53
|
+
* 适用场景:已知主键集合,需要批量获取完整对象
|
|
54
|
+
*/
|
|
55
|
+
public Map<Object, DynamicObject> loadEnabledAuditedSuppliers(Collection<?> supplierIds) {
|
|
56
|
+
if (CollectionUtils.isEmpty(supplierIds)) {
|
|
57
|
+
return Collections.emptyMap();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
QFilter filter = new QFilter(FIELD_ID, QCP.in, supplierIds)
|
|
61
|
+
.and(new QFilter(FIELD_ENABLE, QCP.equals, true))
|
|
62
|
+
.and(new QFilter(FIELD_STATUS, QCP.equals, "C"));
|
|
63
|
+
return BusinessDataServiceHelper.loadFromCache(BD_SUPPLIER,
|
|
64
|
+
String.join(",", FIELD_ID, FIELD_NUMBER, FIELD_NAME), filter.toArray());
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 批量加载用户信息(项目中常见场景:获取审批人姓名等)
|
|
69
|
+
*
|
|
70
|
+
* @param userIds 用户主键集合
|
|
71
|
+
* @return 用户名称拼接字符串
|
|
72
|
+
*/
|
|
73
|
+
public String batchLoadUserNames(Collection<Object> userIds) {
|
|
74
|
+
if (CollectionUtils.isEmpty(userIds)) {
|
|
75
|
+
return "";
|
|
76
|
+
}
|
|
77
|
+
Map<Object, DynamicObject> map = BusinessDataServiceHelper.loadFromCache(BOS_USER,
|
|
78
|
+
new QFilter[]{new QFilter(FIELD_ID, QCP.in, userIds)});
|
|
79
|
+
return map.values().stream()
|
|
80
|
+
.map(o -> String.valueOf(o.get(FIELD_NAME)))
|
|
81
|
+
.collect(Collectors.joining("、"));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 批量加载并构建 Map(按编码或名称分组)
|
|
86
|
+
*
|
|
87
|
+
* @param supplierIds 供应商主键集合
|
|
88
|
+
* @return 编码 -> DynamicObject 映射
|
|
89
|
+
*/
|
|
90
|
+
public Map<String, DynamicObject> loadSuppliersMapByNumber(Collection<?> supplierIds) {
|
|
91
|
+
Map<Object, DynamicObject> idMap = loadEnabledAuditedSuppliers(supplierIds);
|
|
92
|
+
return idMap.values().stream()
|
|
93
|
+
.collect(Collectors.toMap(o -> o.getString(FIELD_NUMBER), o -> o, (a, b) -> a));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// ==================== 场景2:按编码批量查询 ====================
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 先按业务条件查主键集合,再批量加载缓存对象
|
|
100
|
+
*/
|
|
101
|
+
public Map<Object, DynamicObject> queryAndLoadSuppliersByNumbers(Collection<String> supplierNumbers) {
|
|
102
|
+
if (CollectionUtils.isEmpty(supplierNumbers)) {
|
|
103
|
+
return Collections.emptyMap();
|
|
104
|
+
}
|
|
105
|
+
QFilter filter = new QFilter(FIELD_NUMBER, QCP.in, supplierNumbers);
|
|
106
|
+
DynamicObjectCollection rows = QueryServiceHelper.query(BD_SUPPLIER, "id", filter.toArray());
|
|
107
|
+
Set<Object> supplierIds = DynamicObjectUtils.setOf(rows, "id");
|
|
108
|
+
return loadEnabledAuditedSuppliers(supplierIds);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* 根据税率值批量查询税率档案
|
|
113
|
+
*
|
|
114
|
+
* @param taxRates 税率值集合(如 6, 9, 13)
|
|
115
|
+
* @return 税率值 -> 税率档案对象
|
|
116
|
+
*/
|
|
117
|
+
public Map<java.math.BigDecimal, DynamicObject> loadTaxRateByValues(Collection<java.math.BigDecimal> taxRates) {
|
|
118
|
+
if (CollectionUtils.isEmpty(taxRates)) {
|
|
119
|
+
return Collections.emptyMap();
|
|
120
|
+
}
|
|
121
|
+
QFilter filter = new QFilter("taxrate", QCP.in, taxRates)
|
|
122
|
+
.and(FIELD_ENABLE, QCP.equals, true)
|
|
123
|
+
.and(FIELD_STATUS, QCP.equals, "C");
|
|
124
|
+
Map<Object, DynamicObject> map = BusinessDataServiceHelper.loadFromCache(BD_TAXRATE,
|
|
125
|
+
String.join(",", FIELD_ID, FIELD_NUMBER, FIELD_NAME, "taxrate"), filter.toArray());
|
|
126
|
+
return map.values().stream()
|
|
127
|
+
.collect(Collectors.toMap(o -> o.getBigDecimal("taxrate"), o -> o, (a, b) -> a));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// ==================== 场景3:带组织权限过滤的批量查询 ====================
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* 根据税务登记号查询供应商/客户(带组织权限过滤)
|
|
134
|
+
* 适用场景:发票导入时根据税号匹配往来户
|
|
135
|
+
*
|
|
136
|
+
* @param orgId 组织ID
|
|
137
|
+
* @param taxNo 税务登记号
|
|
138
|
+
* @param isPurBiz 是否采购业务(true:供应商, false:客户)
|
|
139
|
+
* @return 供应商/客户对象
|
|
140
|
+
*/
|
|
141
|
+
public DynamicObject querySupplierOrCustomerByTaxNo(long orgId, String taxNo, boolean isPurBiz) {
|
|
142
|
+
QFilter qfilter = new QFilter(FIELD_ENABLE, QCP.equals, Boolean.TRUE)
|
|
143
|
+
.and(FIELD_STATUS, QCP.equals, "C")
|
|
144
|
+
.and("tx_register_no", QCP.equals, taxNo);
|
|
145
|
+
|
|
146
|
+
String entity = isPurBiz ? BD_SUPPLIER : BD_CUSTOMER;
|
|
147
|
+
DynamicObjectCollection results = BaseDataServiceHelper.queryBaseData(
|
|
148
|
+
entity, orgId, qfilter, String.join(",", FIELD_ID, FIELD_NUMBER, FIELD_NAME, "entry_bank.bankaccount"));
|
|
149
|
+
|
|
150
|
+
if (!CollectionUtils.isEmpty(results)) {
|
|
151
|
+
return results.get(0);
|
|
152
|
+
}
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// ==================== 场景4:批量查询用于数据转换/回填 ====================
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* 批量查询基础资料名称并做展示转换。
|
|
160
|
+
* <p>
|
|
161
|
+
* 为了避免“不同基础资料的名称字段不一致”这一类误导,
|
|
162
|
+
* 示例里把 nameField 显式作为参数传入。
|
|
163
|
+
*
|
|
164
|
+
* @param entityId 基础资料标识
|
|
165
|
+
* @param nameField 名称字段,如 name / fullname / shortname
|
|
166
|
+
* @param ids 主键集合
|
|
167
|
+
* @return 名称拼接字符串
|
|
168
|
+
*/
|
|
169
|
+
public String batchLoadDimensionNames(String entityId, String nameField, Set<Long> ids) {
|
|
170
|
+
if (CollectionUtils.isEmpty(ids)) {
|
|
171
|
+
return "";
|
|
172
|
+
}
|
|
173
|
+
Map<Object, DynamicObject> valsFromDb = BusinessDataServiceHelper.loadFromCache(
|
|
174
|
+
entityId, nameField, new QFilter(FIELD_ID, QCP.in, ids).toArray());
|
|
175
|
+
List<String> names = valsFromDb.values().stream()
|
|
176
|
+
.map(x -> x.getString(nameField))
|
|
177
|
+
.collect(Collectors.toList());
|
|
178
|
+
return String.join(",", names);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// ==================== 场景5:查询主键集合用于后续处理 ====================
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* 查询满足条件的主键集合(用于后续批量操作)
|
|
185
|
+
*
|
|
186
|
+
* @param formId 表单标识
|
|
187
|
+
* @param filter 过滤条件
|
|
188
|
+
* @return 主键集合
|
|
189
|
+
*/
|
|
190
|
+
public Set<Object> queryPkSetForBatchProcess(String formId, QFilter filter) {
|
|
191
|
+
DynamicObjectCollection rows = QueryServiceHelper.query(formId, "id", filter.toArray());
|
|
192
|
+
return DynamicObjectUtils.setOf(rows, "id");
|
|
193
|
+
}
|
|
194
|
+
}
|