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,40 @@
|
|
|
1
|
+
# Cosmic Review Checklist
|
|
2
|
+
|
|
3
|
+
Use for Cangqiong, Xinghan, and Xingkong Flagship Java code review.
|
|
4
|
+
|
|
5
|
+
## P0 Blocking Issues
|
|
6
|
+
|
|
7
|
+
- Listener registration or UI mutation in `initialize`.
|
|
8
|
+
- Independent `SaveServiceHelper.save` inside operation transaction hooks when the transaction data packet should be modified directly.
|
|
9
|
+
- `DataSet` not closed.
|
|
10
|
+
- `DataSet` row fields read without being selected in query fields.
|
|
11
|
+
- Validator or operation plugin reads fields that were not declared in prepare hooks.
|
|
12
|
+
- Loop contains DB calls, service calls, ORM creation, or save operations.
|
|
13
|
+
- SQL string concatenation, `Statement`, sensitive credentials, or external entity XML use.
|
|
14
|
+
- Hard-coded organization, user, department, or environment-dependent IDs.
|
|
15
|
+
- `beforeBindData` or `afterBindData` mutates model data.
|
|
16
|
+
- Native JDK threads or executors bypass platform thread management.
|
|
17
|
+
|
|
18
|
+
## P1 High-Risk Issues
|
|
19
|
+
|
|
20
|
+
- Loop contains `updateView` or repeated field-index lookup.
|
|
21
|
+
- Large entry loops use repeated `model.setValue`.
|
|
22
|
+
- Missing query filters cause full table scans.
|
|
23
|
+
- Query field paths are too deep and may create Cartesian products.
|
|
24
|
+
- Third-party calls lack timeout settings.
|
|
25
|
+
- `beginInit` and `endInit` are not paired.
|
|
26
|
+
- Collections accumulate without bounds.
|
|
27
|
+
|
|
28
|
+
## P2 Maintainability Issues
|
|
29
|
+
|
|
30
|
+
- User-visible Chinese strings are not resource-managed when the project requires i18n.
|
|
31
|
+
- Exception logs omit stack traces.
|
|
32
|
+
- Magic numbers and scattered status values are not centralized.
|
|
33
|
+
- Plugin class suffix or method naming does not match project conventions.
|
|
34
|
+
- Empty catch blocks hide failures.
|
|
35
|
+
|
|
36
|
+
## Review Output
|
|
37
|
+
|
|
38
|
+
- Prioritize behavior, data consistency, transaction boundaries, performance, and security before style.
|
|
39
|
+
- Avoid regex-only judgment; confirm context before reporting.
|
|
40
|
+
- Separate P0, P1, and P2, and provide actionable remediation.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Cosmic Unit Test Guidance
|
|
2
|
+
|
|
3
|
+
Use for Cosmic-family Java modules that follow common, business, opplugin, and formplugin project structure.
|
|
4
|
+
|
|
5
|
+
## Project Structure
|
|
6
|
+
|
|
7
|
+
- `<module>-common`: constants, enums, POJO, DTO, utility classes.
|
|
8
|
+
- `<module>-business`: static helpers and business services.
|
|
9
|
+
- `<module>-opplugin`: validators, operation plugins, conversion plugins.
|
|
10
|
+
- `<module>-formplugin`: form, list, and bill plugins.
|
|
11
|
+
|
|
12
|
+
## Test Routing
|
|
13
|
+
|
|
14
|
+
- Common POJO/DTO: instantiate directly, no static mocks.
|
|
15
|
+
- Common enum: test lookup and match methods.
|
|
16
|
+
- Business helper: mock static service helpers and verify outputs or side effects.
|
|
17
|
+
- Validator: collect validation messages and cover declared field preparation.
|
|
18
|
+
- Operation plugin: test transaction data packets, field declarations, and operation results.
|
|
19
|
+
- Form plugin: use the module's `BasePluginTest` or existing tests to obtain view/model mocks.
|
|
20
|
+
|
|
21
|
+
## Mock Rules
|
|
22
|
+
|
|
23
|
+
- Mock static helpers such as `QueryServiceHelper`, `BusinessDataServiceHelper`, `OperationServiceHelper`, `SaveServiceHelper`, `BaseDataServiceHelper`, `SystemParamServiceHelper`, and `ResManager` only when the code imports or calls them.
|
|
24
|
+
- Close every `MockedStatic` in teardown.
|
|
25
|
+
- Do not duplicate mocks already provided by the module's base test.
|
|
26
|
+
- Mock `kd.bos.db.DB` only after defrost handling if the project requires it.
|
|
27
|
+
- Some project helpers require custom test helper mocks; do not replace those with generic static mocks without checking existing tests.
|
|
28
|
+
|
|
29
|
+
## Assertion Rules
|
|
30
|
+
|
|
31
|
+
- Every test must assert a real output, side effect, exception, or mock interaction.
|
|
32
|
+
- Do not use tautological assertions such as `assertTrue(true)`.
|
|
33
|
+
- Cover switch cases as separate tests.
|
|
34
|
+
- Cover boundary values around comparisons, empty collections, one row, and multiple rows.
|
|
35
|
+
- If source code appears buggy, write the expected correct behavior and call out that the test exposes the bug.
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# 金蝶云星空企业版 C# API 参考
|
|
2
|
+
|
|
3
|
+
## 核心服务类
|
|
4
|
+
|
|
5
|
+
### BusinessDataServiceHelper
|
|
6
|
+
|
|
7
|
+
业务数据服务助手,是最常用的数据访问类。
|
|
8
|
+
|
|
9
|
+
**常用方法:**
|
|
10
|
+
|
|
11
|
+
```csharp
|
|
12
|
+
// 加载单个数据实体
|
|
13
|
+
DynamicObject LoadSingle(Context ctx, object pkValue, string entityName)
|
|
14
|
+
|
|
15
|
+
// 加载多个数据实体
|
|
16
|
+
DynamicObject[] Load(Context ctx, object[] pkValues, string entityName)
|
|
17
|
+
|
|
18
|
+
// 按条件查询
|
|
19
|
+
DynamicObject[] Load(Context ctx, string entityName, QFilter[] filters)
|
|
20
|
+
|
|
21
|
+
// 按条件查询指定字段
|
|
22
|
+
DynamicObject[] Load(Context ctx, string entityName, string selectFields, QFilter[] filters)
|
|
23
|
+
|
|
24
|
+
// 加载基础资料
|
|
25
|
+
DynamicObject LoadSingle(Context ctx, string entityName, object pkValue, QFilter[] filters)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**使用示例:**
|
|
29
|
+
|
|
30
|
+
```csharp
|
|
31
|
+
// 加载采购订单
|
|
32
|
+
QFilter filter = new QFilter("billno", "=", "PO-001");
|
|
33
|
+
DynamicObject[] orders = BusinessDataServiceHelper.Load(
|
|
34
|
+
ctx,
|
|
35
|
+
"PUR_POOrder",
|
|
36
|
+
new QFilter[]{filter}
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
if (orders.Length > 0)
|
|
40
|
+
{
|
|
41
|
+
DynamicObject order = orders[0];
|
|
42
|
+
string billNo = order["billno"] as string;
|
|
43
|
+
decimal totalAmount = Convert.ToDecimal(order["totalamount"]);
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### DBUtils
|
|
48
|
+
|
|
49
|
+
数据库工具类,用于执行 SQL 查询。
|
|
50
|
+
|
|
51
|
+
**常用方法:**
|
|
52
|
+
|
|
53
|
+
```csharp
|
|
54
|
+
// 执行查询,返回 DataSet
|
|
55
|
+
DataSet ExecuteDataSet(Context ctx, string sql)
|
|
56
|
+
|
|
57
|
+
// 执行查询带参数
|
|
58
|
+
DataSet ExecuteDataSet(Context ctx, string sql, List<SqlParam> parameters)
|
|
59
|
+
|
|
60
|
+
// 执行更新
|
|
61
|
+
int Execute(Context ctx, string sql)
|
|
62
|
+
|
|
63
|
+
// 执行更新带参数
|
|
64
|
+
int Execute(Context ctx, string sql, List<SqlParam> parameters)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**使用示例:**
|
|
68
|
+
|
|
69
|
+
```csharp
|
|
70
|
+
// 查询采购订单
|
|
71
|
+
string sql = "SELECT FBILLNO, FDATE, FAMOUNT FROM T_PUR_POORDER WHERE FDOCUMENTSTATUS = 'C'";
|
|
72
|
+
DataSet ds = DBUtils.ExecuteDataSet(ctx, sql);
|
|
73
|
+
|
|
74
|
+
foreach (DataRow row in ds.Tables[0].Rows)
|
|
75
|
+
{
|
|
76
|
+
string billNo = row["FBILLNO"] as string;
|
|
77
|
+
DateTime date = Convert.ToDateTime(row["FDATE"]);
|
|
78
|
+
decimal amount = Convert.ToDecimal(row["FAMOUNT"]);
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### IDBAccesser
|
|
83
|
+
|
|
84
|
+
数据访问接口,提供 ORM 功能。
|
|
85
|
+
|
|
86
|
+
**常用方法:**
|
|
87
|
+
|
|
88
|
+
```csharp
|
|
89
|
+
// 执行查询
|
|
90
|
+
DataSet Query(string sql)
|
|
91
|
+
|
|
92
|
+
// 执行更新
|
|
93
|
+
int Update(string sql)
|
|
94
|
+
|
|
95
|
+
// 批量插入
|
|
96
|
+
void InsertBatch(string tableName, DataSet data)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## 插件基类
|
|
102
|
+
|
|
103
|
+
### AbstractOperationServicePlugIn
|
|
104
|
+
|
|
105
|
+
操作服务插件基类,用于操作事件处理。
|
|
106
|
+
|
|
107
|
+
**常用事件:**
|
|
108
|
+
|
|
109
|
+
```csharp
|
|
110
|
+
// 准备属性
|
|
111
|
+
public override void OnPreparePropertys(PreparePropertysEventArgs e)
|
|
112
|
+
|
|
113
|
+
// 操作执行前
|
|
114
|
+
public override void BeforeExecuteOperationTransaction(BeforeExecuteOperationTransaction e)
|
|
115
|
+
|
|
116
|
+
// 操作执行后
|
|
117
|
+
public override void AfterExecuteOperationTransaction(AfterExecuteOperationTransaction e)
|
|
118
|
+
|
|
119
|
+
// 添加校验规则
|
|
120
|
+
public override void OnAddValidateRules(AddValidateRulesEventArgs e)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### AbstractOperationCheckPlugIn
|
|
124
|
+
|
|
125
|
+
操作校验插件基类,用于数据校验。
|
|
126
|
+
|
|
127
|
+
**常用方法:**
|
|
128
|
+
|
|
129
|
+
```csharp
|
|
130
|
+
// 自定义校验规则
|
|
131
|
+
public override void OnAddValidateRules(AddValidateRulesEventArgs e)
|
|
132
|
+
|
|
133
|
+
// 校验数据
|
|
134
|
+
public override void Validate(ValidateEventArgs e)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### AbstractBillPlugIn
|
|
138
|
+
|
|
139
|
+
表单插件基类,用于表单事件处理。
|
|
140
|
+
|
|
141
|
+
**常用事件:**
|
|
142
|
+
|
|
143
|
+
```csharp
|
|
144
|
+
// 表单加载后
|
|
145
|
+
public override void AfterBindData(EventArgs e)
|
|
146
|
+
|
|
147
|
+
// 字段值变更后
|
|
148
|
+
public override void AfterPropertyChanged(PropertyChangedEventArgs e)
|
|
149
|
+
|
|
150
|
+
// 保存前
|
|
151
|
+
public override void BeforeSave(BeforeSaveEventArgs e)
|
|
152
|
+
|
|
153
|
+
// 保存后
|
|
154
|
+
public override void AfterSave(EventArgs e)
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## 常用工具类
|
|
160
|
+
|
|
161
|
+
### StringUtils
|
|
162
|
+
|
|
163
|
+
字符串处理工具。
|
|
164
|
+
|
|
165
|
+
```csharp
|
|
166
|
+
// 判断是否为空
|
|
167
|
+
bool IsEmpty(string str)
|
|
168
|
+
|
|
169
|
+
// 判断是否不为空
|
|
170
|
+
bool IsNotEmpty(string str)
|
|
171
|
+
|
|
172
|
+
// 去除空格
|
|
173
|
+
string Trim(string str)
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### KDException
|
|
177
|
+
|
|
178
|
+
金蝶自定义异常。
|
|
179
|
+
|
|
180
|
+
```csharp
|
|
181
|
+
// 抛出异常
|
|
182
|
+
throw new KDException("错误编码", "错误信息");
|
|
183
|
+
|
|
184
|
+
// 带原因的异常
|
|
185
|
+
throw new KDException("错误编码", "错误信息", innerException);
|
|
186
|
+
```
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
# 金蝶云星空企业版 C# 代码模式
|
|
2
|
+
|
|
3
|
+
## 数据访问模式
|
|
4
|
+
|
|
5
|
+
### 模式一:BusinessDataServiceHelper 查询
|
|
6
|
+
|
|
7
|
+
**适用场景:** 按主键或条件查询单个/多个实体
|
|
8
|
+
|
|
9
|
+
```csharp
|
|
10
|
+
// 按主键查询
|
|
11
|
+
DynamicObject entity = BusinessDataServiceHelper.LoadSingle(
|
|
12
|
+
ctx,
|
|
13
|
+
primaryKey,
|
|
14
|
+
"PUR_POOrder"
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
// 按条件查询
|
|
18
|
+
QFilter filter = new QFilter("billno", "=", "PO-001");
|
|
19
|
+
DynamicObject[] entities = BusinessDataServiceHelper.Load(
|
|
20
|
+
ctx,
|
|
21
|
+
"PUR_POOrder",
|
|
22
|
+
new QFilter[]{filter}
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
// 查询指定字段
|
|
26
|
+
string[] selectFields = new string[] { "id", "billno", "date", "amount" };
|
|
27
|
+
DynamicObject[] entities = BusinessDataServiceHelper.Load(
|
|
28
|
+
ctx,
|
|
29
|
+
"PUR_POOrder",
|
|
30
|
+
selectFields,
|
|
31
|
+
new QFilter[]{filter}
|
|
32
|
+
);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 模式二:DBUtils SQL 查询
|
|
36
|
+
|
|
37
|
+
**适用场景:** 复杂查询、报表查询、跨表查询
|
|
38
|
+
|
|
39
|
+
```csharp
|
|
40
|
+
// 简单查询
|
|
41
|
+
string sql = "SELECT FBILLNO, FDATE, FAMOUNT FROM T_PUR_POORDER WHERE FDOCUMENTSTATUS = 'C'";
|
|
42
|
+
DataSet ds = DBUtils.ExecuteDataSet(ctx, sql);
|
|
43
|
+
|
|
44
|
+
// 带参数查询
|
|
45
|
+
string sql = "SELECT * FROM T_PUR_POORDER WHERE FDATE >= @StartDate AND FDATE <= @EndDate";
|
|
46
|
+
List<SqlParam> parameters = new List<SqlParam>
|
|
47
|
+
{
|
|
48
|
+
new SqlParam("@StartDate", startDate),
|
|
49
|
+
new SqlParam("@EndDate", endDate)
|
|
50
|
+
};
|
|
51
|
+
DataSet ds = DBUtils.ExecuteDataSet(ctx, sql, parameters);
|
|
52
|
+
|
|
53
|
+
// 聚合查询
|
|
54
|
+
string sql = "SELECT FSUPPLIERID, SUM(FAMOUNT) AS TOTAL FROM T_PUR_POORDER GROUP BY FSUPPLIERID";
|
|
55
|
+
DataSet ds = DBUtils.ExecuteDataSet(ctx, sql);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## 事务处理模式
|
|
61
|
+
|
|
62
|
+
### 事务内操作
|
|
63
|
+
|
|
64
|
+
```csharp
|
|
65
|
+
// 使用 KDTransactionScope
|
|
66
|
+
using (KDTransactionScope scope = new KDTransactionScope())
|
|
67
|
+
{
|
|
68
|
+
try
|
|
69
|
+
{
|
|
70
|
+
// 业务操作
|
|
71
|
+
DBUtils.Execute(ctx, sql1);
|
|
72
|
+
DBUtils.Execute(ctx, sql2);
|
|
73
|
+
|
|
74
|
+
scope.Complete();
|
|
75
|
+
}
|
|
76
|
+
catch (Exception)
|
|
77
|
+
{
|
|
78
|
+
// 事务会自动回滚
|
|
79
|
+
throw;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## 异常处理模式
|
|
87
|
+
|
|
88
|
+
### 业务异常处理
|
|
89
|
+
|
|
90
|
+
```csharp
|
|
91
|
+
public void ProcessOrder(DynamicObject order)
|
|
92
|
+
{
|
|
93
|
+
try
|
|
94
|
+
{
|
|
95
|
+
// 业务逻辑
|
|
96
|
+
ValidateOrder(order);
|
|
97
|
+
SaveOrder(order);
|
|
98
|
+
}
|
|
99
|
+
catch (KDException ex)
|
|
100
|
+
{
|
|
101
|
+
// 业务异常,记录日志并抛出
|
|
102
|
+
Logger.Error("处理订单失败: " + ex.Message, ex);
|
|
103
|
+
throw;
|
|
104
|
+
}
|
|
105
|
+
catch (Exception ex)
|
|
106
|
+
{
|
|
107
|
+
// 其他异常,包装为业务异常
|
|
108
|
+
Logger.Error("系统异常: " + ex.Message, ex);
|
|
109
|
+
throw new KDException("SYS001", "系统异常,请联系管理员", ex);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### 校验异常处理
|
|
115
|
+
|
|
116
|
+
```csharp
|
|
117
|
+
public void ValidateOrder(DynamicObject order)
|
|
118
|
+
{
|
|
119
|
+
List<string> errors = new List<string>();
|
|
120
|
+
|
|
121
|
+
// 校验必填字段
|
|
122
|
+
if (string.IsNullOrEmpty(order["FBillNo"] as string))
|
|
123
|
+
{
|
|
124
|
+
errors.Add("单据编号不能为空");
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// 校验业务规则
|
|
128
|
+
decimal amount = Convert.ToDecimal(order["FAmount"] ?? 0);
|
|
129
|
+
if (amount <= 0)
|
|
130
|
+
{
|
|
131
|
+
errors.Add("金额必须大于零");
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// 抛出校验异常
|
|
135
|
+
if (errors.Count > 0)
|
|
136
|
+
{
|
|
137
|
+
throw new KDException("VALIDATE001", string.Join("; ", errors));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## 日志记录模式
|
|
145
|
+
|
|
146
|
+
### 使用 Logger
|
|
147
|
+
|
|
148
|
+
```csharp
|
|
149
|
+
private static readonly ILog Logger = LogManager.GetLogger(typeof(OrderPlugin));
|
|
150
|
+
|
|
151
|
+
// 记录信息
|
|
152
|
+
Logger.Info("开始处理订单: " + billNo);
|
|
153
|
+
|
|
154
|
+
// 记录警告
|
|
155
|
+
Logger.Warn("订单金额较大: " + amount);
|
|
156
|
+
|
|
157
|
+
// 记录错误
|
|
158
|
+
Logger.Error("处理订单失败", exception);
|
|
159
|
+
|
|
160
|
+
// 调试日志
|
|
161
|
+
if (Logger.IsDebugEnabled)
|
|
162
|
+
{
|
|
163
|
+
Logger.Debug("订单详情: " + order.ToString());
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## 批量处理模式
|
|
170
|
+
|
|
171
|
+
### 批量查询
|
|
172
|
+
|
|
173
|
+
```csharp
|
|
174
|
+
// 分批查询大量数据
|
|
175
|
+
int batchSize = 1000;
|
|
176
|
+
int offset = 0;
|
|
177
|
+
List<DynamicObject> allResults = new List<DynamicObject>();
|
|
178
|
+
|
|
179
|
+
while (true)
|
|
180
|
+
{
|
|
181
|
+
string sql = string.Format(
|
|
182
|
+
"SELECT * FROM T_PUR_POORDER ORDER BY FID OFFSET {0} ROWS FETCH NEXT {1} ROWS ONLY",
|
|
183
|
+
offset, batchSize
|
|
184
|
+
);
|
|
185
|
+
DataSet ds = DBUtils.ExecuteDataSet(ctx, sql);
|
|
186
|
+
|
|
187
|
+
if (ds.Tables[0].Rows.Count == 0) break;
|
|
188
|
+
|
|
189
|
+
foreach (DataRow row in ds.Tables[0].Rows)
|
|
190
|
+
{
|
|
191
|
+
// 处理每行数据
|
|
192
|
+
allResults.Add(ConvertToEntity(row));
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
offset += batchSize;
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### 批量更新
|
|
200
|
+
|
|
201
|
+
```csharp
|
|
202
|
+
// 使用事务批量更新
|
|
203
|
+
using (KDTransactionScope scope = new KDTransactionScope())
|
|
204
|
+
{
|
|
205
|
+
foreach (var entity in entities)
|
|
206
|
+
{
|
|
207
|
+
string sql = "UPDATE T_PUR_POORDER SET FStatus = @Status WHERE FID = @ID";
|
|
208
|
+
List<SqlParam> parameters = new List<SqlParam>
|
|
209
|
+
{
|
|
210
|
+
new SqlParam("@Status", "C"),
|
|
211
|
+
new SqlParam("@ID", entity["FID"])
|
|
212
|
+
};
|
|
213
|
+
DBUtils.Execute(ctx, sql, parameters);
|
|
214
|
+
}
|
|
215
|
+
scope.Complete();
|
|
216
|
+
}
|
|
217
|
+
```
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
# 金蝶云星空企业版插件生命周期
|
|
2
|
+
|
|
3
|
+
## 操作服务插件生命周期 (AbstractOperationServicePlugIn)
|
|
4
|
+
|
|
5
|
+
### 生命周期顺序
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
操作触发
|
|
9
|
+
↓
|
|
10
|
+
OnPreparePropertys() - 准备属性
|
|
11
|
+
↓
|
|
12
|
+
OnAddValidateRules() - 添加校验规则
|
|
13
|
+
↓
|
|
14
|
+
BeforeExecuteOperationTransaction() - 操作执行前
|
|
15
|
+
↓
|
|
16
|
+
ExecuteOperationTransaction() - 执行操作(事务内)
|
|
17
|
+
↓
|
|
18
|
+
AfterExecuteOperationTransaction() - 操作执行后
|
|
19
|
+
↓
|
|
20
|
+
操作完成
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### 关键事件详解
|
|
24
|
+
|
|
25
|
+
#### OnPreparePropertys - 准备属性
|
|
26
|
+
|
|
27
|
+
**触发时机:** 操作开始前,用于指定需要加载的字段
|
|
28
|
+
|
|
29
|
+
**用途:**
|
|
30
|
+
- 指定需要访问的字段
|
|
31
|
+
- 优化数据加载性能
|
|
32
|
+
|
|
33
|
+
**示例:**
|
|
34
|
+
```csharp
|
|
35
|
+
public override void OnPreparePropertys(PreparePropertysEventArgs e)
|
|
36
|
+
{
|
|
37
|
+
// 添加需要访问的字段
|
|
38
|
+
e.FieldKeys.Add("FQty");
|
|
39
|
+
e.FieldKeys.Add("FPrice");
|
|
40
|
+
e.FieldKeys.Add("FAmount");
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
#### BeforeExecuteOperationTransaction - 操作执行前
|
|
45
|
+
|
|
46
|
+
**触发时机:** 操作事务开始前
|
|
47
|
+
|
|
48
|
+
**用途:**
|
|
49
|
+
- 业务规则校验
|
|
50
|
+
- 数据预处理
|
|
51
|
+
- 权限检查
|
|
52
|
+
|
|
53
|
+
**示例:**
|
|
54
|
+
```csharp
|
|
55
|
+
public override void BeforeExecuteOperationTransaction(BeforeExecuteOperationTransaction e)
|
|
56
|
+
{
|
|
57
|
+
string operateKey = e.OperateKey;
|
|
58
|
+
|
|
59
|
+
if (operateKey == "Submit")
|
|
60
|
+
{
|
|
61
|
+
// 提交前校验
|
|
62
|
+
foreach (var entity in e.DataEntitys)
|
|
63
|
+
{
|
|
64
|
+
decimal amount = Convert.ToDecimal(entity["FAmount"] ?? 0);
|
|
65
|
+
if (amount <= 0)
|
|
66
|
+
{
|
|
67
|
+
throw new KDException("", "金额必须大于零");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
#### AfterExecuteOperationTransaction - 操作执行后
|
|
75
|
+
|
|
76
|
+
**触发时机:** 操作事务提交后
|
|
77
|
+
|
|
78
|
+
**用途:**
|
|
79
|
+
- 触发下游业务
|
|
80
|
+
- 发送通知
|
|
81
|
+
- 记录日志
|
|
82
|
+
|
|
83
|
+
**示例:**
|
|
84
|
+
```csharp
|
|
85
|
+
public override void AfterExecuteOperationTransaction(AfterExecuteOperationTransaction e)
|
|
86
|
+
{
|
|
87
|
+
string operateKey = e.OperateKey;
|
|
88
|
+
|
|
89
|
+
if (operateKey == "Audit")
|
|
90
|
+
{
|
|
91
|
+
// 审核后触发下游业务
|
|
92
|
+
foreach (var entity in e.DataEntitys)
|
|
93
|
+
{
|
|
94
|
+
TriggerDownstreamBusiness(entity);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## 表单插件生命周期 (AbstractBillPlugIn)
|
|
103
|
+
|
|
104
|
+
### 生命周期顺序
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
表单打开
|
|
108
|
+
↓
|
|
109
|
+
AfterBindData() - 绑定数据后
|
|
110
|
+
↓
|
|
111
|
+
用户操作
|
|
112
|
+
↓
|
|
113
|
+
AfterPropertyChanged() - 字段值变更后
|
|
114
|
+
↓
|
|
115
|
+
BeforeSave() - 保存前
|
|
116
|
+
↓
|
|
117
|
+
AfterSave() - 保存后
|
|
118
|
+
↓
|
|
119
|
+
表单关闭
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### 示例
|
|
123
|
+
|
|
124
|
+
```csharp
|
|
125
|
+
public class OrderPlugin : AbstractBillPlugIn
|
|
126
|
+
{
|
|
127
|
+
public override void AfterBindData(EventArgs e)
|
|
128
|
+
{
|
|
129
|
+
// 初始化界面
|
|
130
|
+
this.View.Visible = true;
|
|
131
|
+
this.View.SetControlValue("FStatus", "A");
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
public override void AfterPropertyChanged(PropertyChangedEventArgs e)
|
|
135
|
+
{
|
|
136
|
+
if (e.Property.Name == "FQty")
|
|
137
|
+
{
|
|
138
|
+
// 数量变更后计算金额
|
|
139
|
+
decimal qty = Convert.ToDecimal(e.NewValue);
|
|
140
|
+
decimal price = Convert.ToDecimal(this.Model.GetValue("FPrice"));
|
|
141
|
+
decimal amount = qty * price;
|
|
142
|
+
this.Model.SetValue("FAmount", amount);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
public override void BeforeSave(BeforeSaveEventArgs e)
|
|
147
|
+
{
|
|
148
|
+
// 校验必填字段
|
|
149
|
+
var dataEntity = this.Model.DataEntity;
|
|
150
|
+
string billNo = dataEntity["FBillNo"] as string;
|
|
151
|
+
|
|
152
|
+
if (string.IsNullOrEmpty(billNo))
|
|
153
|
+
{
|
|
154
|
+
e.Cancel = true;
|
|
155
|
+
this.View.ShowErrorNotification("单据编号不能为空");
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## 校验插件生命周期 (AbstractOperationCheckPlugIn)
|
|
165
|
+
|
|
166
|
+
### 示例
|
|
167
|
+
|
|
168
|
+
```csharp
|
|
169
|
+
public class AmountCheckPlugin : AbstractOperationCheckPlugIn
|
|
170
|
+
{
|
|
171
|
+
public override void OnAddValidateRules(AddValidateRulesEventArgs e)
|
|
172
|
+
{
|
|
173
|
+
// 添加校验规则
|
|
174
|
+
e.AddValidateRule("FAmount", "金额必须大于零");
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
public override void Validate(ValidateEventArgs e)
|
|
178
|
+
{
|
|
179
|
+
var dataEntity = e.DataEntity;
|
|
180
|
+
decimal amount = Convert.ToDecimal(dataEntity["FAmount"] ?? 0);
|
|
181
|
+
|
|
182
|
+
if (amount <= 0)
|
|
183
|
+
{
|
|
184
|
+
e.AddError("FAmount", "金额必须大于零");
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
```
|