@macrowing/inbiz-codegen 0.0.0-stage → 1.0.1
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 +592 -2
- package/bin/inbiz-codegen.mjs +7 -0
- package/package.json +32 -4
- package/scripts/prepare-templates.mjs +35 -0
- package/src/backend/init.mjs +170 -0
- package/src/config.mjs +150 -0
- package/src/favicon.mjs +100 -0
- package/src/generate.mjs +935 -0
- package/src/generated-output.mjs +107 -0
- package/src/index.mjs +346 -0
- package/src/menu/build.mjs +252 -0
- package/src/menu/check.mjs +163 -0
- package/src/menu/command.mjs +179 -0
- package/src/migrate-runtime.mjs +106 -0
- package/src/platform/client.mjs +167 -0
- package/src/platform/command.mjs +386 -0
- package/src/platform/pack.mjs +591 -0
- package/src/platform/recover.mjs +236 -0
- package/src/platform/startup.mjs +343 -0
- package/src/platform/state.mjs +116 -0
- package/src/platform/update.mjs +157 -0
- package/src/platform/zip.mjs +134 -0
- package/src/pull.mjs +284 -0
- package/src/scaffold/commands.mjs +349 -0
- package/src/scaffold/init.mjs +392 -0
- package/src/scaffold/template-files.mjs +40 -0
- package/src/scaffold/template-source.mjs +235 -0
- package/src/scaffold/template-sync.mjs +335 -0
- package/src/transform/heaviness.mjs +380 -0
- package/src/transform/preview-props.mjs +108 -0
- package/src/transform/published-page-links.mjs +61 -0
- package/src/transform/published-script.mjs +110 -0
- package/src/transform/registry.mjs +781 -0
- package/src/transform/schema-to-jsx.mjs +1708 -0
- package/src/util/des.mjs +10 -0
- package/templates/README.md +34 -0
- package/templates/backend/Directory.Build.props +19 -0
- package/templates/backend/Directory.Packages.props +49 -0
- package/templates/backend/Macrowing.Scaffold.slnx +13 -0
- package/templates/backend/host/Macrowing.Start/Init/app.json +8 -0
- package/templates/backend/host/Macrowing.Start/Init/menus.json +4 -0
- package/templates/backend/host/Macrowing.Start/Initialization/InitializationDefinition.cs +245 -0
- package/templates/backend/host/Macrowing.Start/Initialization/InitializationEndpoints.cs +57 -0
- package/templates/backend/host/Macrowing.Start/Initialization/InitializationHostedService.cs +63 -0
- package/templates/backend/host/Macrowing.Start/Initialization/InitializationOptions.cs +44 -0
- package/templates/backend/host/Macrowing.Start/Initialization/InitializationRunner.cs +294 -0
- package/templates/backend/host/Macrowing.Start/Initialization/InitializationState.cs +72 -0
- package/templates/backend/host/Macrowing.Start/Initialization/MenuFactory.cs +118 -0
- package/templates/backend/host/Macrowing.Start/Initialization/PackageBuilder.cs +317 -0
- package/templates/backend/host/Macrowing.Start/Initialization/PlatformAppImporter.cs +371 -0
- package/templates/backend/host/Macrowing.Start/Macrowing.Start.csproj +26 -0
- package/templates/backend/host/Macrowing.Start/Program.cs +33 -0
- package/templates/backend/host/Macrowing.Start/StartModule.cs +67 -0
- package/templates/backend/host/Macrowing.Start/appsettings.json +38 -0
- package/templates/backend/modules/Macrowing.Generated/Application/GeneratedApplicationAutoMapperProfile.cs +42 -0
- package/templates/backend/modules/Macrowing.Generated/Domain/Entities/GeneratedEntityBase.cs +72 -0
- package/templates/backend/modules/Macrowing.Generated/Domain/GeneratedConsts.cs +50 -0
- package/templates/backend/modules/Macrowing.Generated/EntityFrameworkCore/GeneratedDbContext.cs +55 -0
- package/templates/backend/modules/Macrowing.Generated/EntityFrameworkCore/GeneratedDbContextModelBuilderExtensions.cs +61 -0
- package/templates/backend/modules/Macrowing.Generated/EntityFrameworkCore/IGeneratedDbContext.cs +32 -0
- package/templates/backend/modules/Macrowing.Generated/GeneratedModule.cs +89 -0
- package/templates/backend/modules/Macrowing.Generated/Macrowing.Generated.csproj +22 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Cms/CmsClient.cs +95 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Cms/CmsModels.cs +81 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Dictionary/DictionaryClient.cs +44 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/InBizSdkModule.cs +16 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/InterfaceEngine/InterfaceEngineClient.cs +50 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Localization/LocalizationClient.cs +28 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Macrowing.InBiz.SDK.csproj +16 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Message/MessageClient.cs +99 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Message/MessageModels.cs +63 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Model/ModelClient.cs +131 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Model/ModelQuery.cs +108 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Model/ModelWrite.cs +44 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Permission/PermissionClient.cs +86 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Platform/InBizPlatformException.cs +42 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Platform/InBizPlatformRegistration.cs +60 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Platform/InBizPlatformTransport.cs +96 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/Platform/InBizRequestContext.cs +27 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/README.md +117 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Details/WorkFlowDetailsClient.cs +35 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Details/WorkFlowDetailsQuery.cs +20 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Operations/WorkFlowOperationRequests.cs +105 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Operations/WorkFlowOperationsClient.cs +53 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/README.md +132 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Tracking/WorkFlowTrackingClient.cs +50 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Upgrade/WorkFlowUpgradeClient.cs +78 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Upgrade/WorkFlowUpgradeModels.cs +34 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/WorkFlowContracts.cs +88 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/WorkFlowRegistration.cs +59 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/WorkFlowTransport.cs +163 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Workbench/WorkFlowWorkbenchClient.cs +59 -0
- package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Workbench/WorkFlowWorkbenchModels.cs +76 -0
- package/templates/backend/modules/Macrowing.OC.SDK/Macrowing.OC.SDK.csproj +20 -0
- package/templates/backend/modules/Macrowing.OC.SDK/OcSdkModule.cs +18 -0
- package/templates/backend/modules/Macrowing.OC.SDK/Protos/README.md +22 -0
- package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/Macrowing.InBiz.SDK.Tests.csproj +14 -0
- package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/PlatformContractTests.cs +288 -0
- package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/PlatformLiveTests.cs +173 -0
- package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/WorkFlowHttpServer.cs +113 -0
- package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/WorkFlowLiveTests.cs +269 -0
- package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/WorkFlowOperationsTests.cs +80 -0
- package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/WorkFlowQueryTests.cs +163 -0
- package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/WorkFlowTransportTests.cs +111 -0
- package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/WorkFlowUpgradeTests.cs +87 -0
- package/templates/frontend/components/README.md +39 -0
- package/templates/frontend/components/app-components/README.md +33 -0
- package/templates/frontend/components/app-components/common/.gitkeep +0 -0
- package/templates/frontend/components/app-components/components/.gitkeep +0 -0
- package/templates/frontend/components/app-components/package.json +20 -0
- package/templates/frontend/mgt/.umirc.ts +574 -0
- package/templates/frontend/mgt/package.json +96 -0
- package/templates/frontend/mgt/src/app-extends.ts +9 -0
- package/templates/frontend/mgt/src/app.tsx +20 -0
- package/templates/frontend/mgt/src/config/app.ts +31 -0
- package/templates/frontend/mgt/src/layout/header.tsx +14 -0
- package/templates/frontend/mgt/src/layout/index.tsx +11 -0
- package/templates/frontend/mgt/src/layout/sidebar.tsx +14 -0
- package/templates/frontend/mgt/src/locales.ts +8 -0
- package/templates/frontend/mgt/src/pages/.gitkeep +0 -0
- package/templates/frontend/mgt/src/root.tsx +12 -0
- package/templates/frontend/mgt/src/route-view.tsx +3 -0
- package/templates/frontend/mgt/src/runtime.ts +21 -0
- package/templates/frontend/mgt/src/styles/app.css +1 -0
- package/templates/frontend/mgt/src/styles/layout.less +79 -0
- package/templates/frontend/mgt/tsconfig.json +65 -0
- package/templates/frontend/mgt/typings.d.ts +57 -0
- package/templates/frontend/wap/.umirc.ts +574 -0
- package/templates/frontend/wap/package.json +73 -0
- package/templates/frontend/wap/src/app-extends.ts +9 -0
- package/templates/frontend/wap/src/app.tsx +28 -0
- package/templates/frontend/wap/src/config/app.ts +31 -0
- package/templates/frontend/wap/src/layout/header.tsx +14 -0
- package/templates/frontend/wap/src/layout/index.tsx +18 -0
- package/templates/frontend/wap/src/layout/sidebar.tsx +14 -0
- package/templates/frontend/wap/src/locales.ts +8 -0
- package/templates/frontend/wap/src/pages/.gitkeep +0 -0
- package/templates/frontend/wap/src/root.tsx +12 -0
- package/templates/frontend/wap/src/route-view.tsx +3 -0
- package/templates/frontend/wap/src/runtime.ts +21 -0
- package/templates/frontend/wap/src/styles/adaptation.less +190 -0
- package/templates/frontend/wap/src/styles/app.css +7 -0
- package/templates/frontend/wap/src/styles/global.less +81 -0
- package/templates/frontend/wap/src/styles/layout.less +92 -0
- package/templates/frontend/wap/tsconfig.json +66 -0
- package/templates/frontend/wap/typings.d.ts +24 -0
- package/templates/frontend/web/.umirc.ts +574 -0
- package/templates/frontend/web/package.json +26 -0
- package/templates/frontend/web/src/app-extends.ts +9 -0
- package/templates/frontend/web/src/app.tsx +25 -0
- package/templates/frontend/web/src/config/app.ts +31 -0
- package/templates/frontend/web/src/layout/header.tsx +14 -0
- package/templates/frontend/web/src/layout/index.tsx +11 -0
- package/templates/frontend/web/src/layout/sidebar.tsx +14 -0
- package/templates/frontend/web/src/locales.ts +8 -0
- package/templates/frontend/web/src/root.tsx +12 -0
- package/templates/frontend/web/src/route-view.tsx +3 -0
- package/templates/frontend/web/src/runtime.ts +21 -0
- package/templates/frontend/web/src/styles/app.css +104 -0
- package/templates/frontend/web/src/styles/layout.less +124 -0
- package/templates/frontend/web/tsconfig.json +91 -0
- package/templates/frontend/web/typings.d.ts +46 -0
- package/templates/package.json +14 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
namespace Macrowing.Generated.Domain;
|
|
2
|
+
|
|
3
|
+
/// <summary>
|
|
4
|
+
/// 出码产物的全局约定常量。
|
|
5
|
+
///
|
|
6
|
+
/// 【出码器会往这里写什么】
|
|
7
|
+
/// 出码器在每次生成时,把 <c>inbiz.config.json</c> 里的数据库相关配置翻译成这里的常量:
|
|
8
|
+
/// - <c>database.connectionStringName</c> → <see cref="ConnectionStringName"/>
|
|
9
|
+
/// - <c>database.tablePrefix</c> → <see cref="TablePrefix"/>
|
|
10
|
+
/// - 平台侧字段长度约束 → 下面各个 MaxLength
|
|
11
|
+
///
|
|
12
|
+
/// 为什么集中成常量,而不是散落在每个实体配置里:
|
|
13
|
+
/// 1. 表名前缀在 InBiz 里是「动态表名」的一部分(见 02-codegen-framework.md §7.1 第 2 条),
|
|
14
|
+
/// 同名模型在不同部署下可能带不同前缀。集中一处,出码器只改本文件一行即可整体切换;
|
|
15
|
+
/// 2. 字段长度一旦和平台 schema 不一致,写入时会被数据库截断或直接报错,
|
|
16
|
+
/// 集中管理便于出码器在生成前做一致性校验;
|
|
17
|
+
/// 3. 这些值会被 EF 迁移快照记录,改动必须是「显式的一次 diff」,不能隐式漂移。
|
|
18
|
+
///
|
|
19
|
+
/// 本文件是**出码覆盖文件**:出码器直接重写它,不保留人工修改。
|
|
20
|
+
/// 需要人工定制的常量请放到 GeneratedModule.cs 或单独的 *.Custom.cs 里。
|
|
21
|
+
/// </summary>
|
|
22
|
+
public static class GeneratedConsts
|
|
23
|
+
{
|
|
24
|
+
/// <summary>连接串名。对应 appsettings.json 中 ConnectionStrings 的键。</summary>
|
|
25
|
+
public const string ConnectionStringName = "Default";
|
|
26
|
+
|
|
27
|
+
/// <summary>
|
|
28
|
+
/// 生成表名的统一前缀,最终表名为 <c>TablePrefix + 实体名</c>(如 <c>Gen_Order</c>)。
|
|
29
|
+
/// 出码器按部署配置覆写此值;本地开发默认 Gen_。
|
|
30
|
+
/// </summary>
|
|
31
|
+
public const string TablePrefix = "Gen_";
|
|
32
|
+
|
|
33
|
+
/// <summary>未显式指定 DataVersion 时写入的默认版本号,代表「基线数据」。</summary>
|
|
34
|
+
public const string DefaultDataVersion = "1";
|
|
35
|
+
|
|
36
|
+
/// <summary>InBiz outId 的长度。平台侧是 32 位无横线 GUID,这里留一倍冗余。</summary>
|
|
37
|
+
public const int OutIdMaxLength = 64;
|
|
38
|
+
|
|
39
|
+
/// <summary>数据版本号长度(对应平台的 dataVersionId)。</summary>
|
|
40
|
+
public const int DataVersionMaxLength = 64;
|
|
41
|
+
|
|
42
|
+
/// <summary>业务编码类字段(单号、编号)长度 —— 对应 schema 里 type=string 且作主键展示的字段。</summary>
|
|
43
|
+
public const int CodeMaxLength = 64;
|
|
44
|
+
|
|
45
|
+
/// <summary>标题/名称类字段长度。</summary>
|
|
46
|
+
public const int TitleMaxLength = 256;
|
|
47
|
+
|
|
48
|
+
/// <summary>备注/多行文本字段长度。</summary>
|
|
49
|
+
public const int RemarkMaxLength = 2000;
|
|
50
|
+
}
|
package/templates/backend/modules/Macrowing.Generated/EntityFrameworkCore/GeneratedDbContext.cs
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
using Macrowing.Generated.Domain;
|
|
2
|
+
using Microsoft.EntityFrameworkCore;
|
|
3
|
+
using Volo.Abp.Data;
|
|
4
|
+
using Volo.Abp.EntityFrameworkCore;
|
|
5
|
+
|
|
6
|
+
namespace Macrowing.Generated.EntityFrameworkCore;
|
|
7
|
+
|
|
8
|
+
/// <summary>
|
|
9
|
+
/// 出码模块的 EF Core 上下文。
|
|
10
|
+
///
|
|
11
|
+
/// 【出码器会往这里写什么】
|
|
12
|
+
/// <list type="bullet">
|
|
13
|
+
/// <item>按实体追加 <c>DbSet</c> 属性(与 <see cref="IGeneratedDbContext"/> 一一对应);</item>
|
|
14
|
+
/// <item>**不**在 <c>OnModelCreating</c> 里写任何实体配置 —— 全部委托给
|
|
15
|
+
/// <c>ConfigureGenerated</c> 扩展方法。原因是实体配置随实体数量增长,
|
|
16
|
+
/// 若直接写在这里,每次生成都要在这个被继承的类里做中段插入,diff 噪音大且容易冲突。</item>
|
|
17
|
+
/// </list>
|
|
18
|
+
///
|
|
19
|
+
/// 为什么继承 <c>AbpDbContext<T></c> 而不是裸 <c>DbContext</c>:
|
|
20
|
+
/// ABP 在基类里做了三件出码产物必须依赖的事:
|
|
21
|
+
/// 1. 自动填充审计字段(CreationTime / CreatorId / LastModificationTime),
|
|
22
|
+
/// 否则出码实体继承了审计基类却永远拿到默认时间;
|
|
23
|
+
/// 2. 软删除全局过滤(IsDeleted),与 InBiz 的回收站语义对齐;
|
|
24
|
+
/// 3. 工作单元与事务管理 —— 仓储的 Insert/Update 不需要手动 SaveChanges。
|
|
25
|
+
///
|
|
26
|
+
/// 数据库提供程序(SqlServer / MySQL)**不在本模块配置**:
|
|
27
|
+
/// 提供程序属于部署形态,由 Host 或未来的 KernelModule 通过
|
|
28
|
+
/// <c>Configure<AbpDbContextOptions>(opt => opt.UseSqlServer())</c> 决定。
|
|
29
|
+
/// 本模块只负责「有哪些表、长什么样」,不负责「连哪个库」。
|
|
30
|
+
/// 这样同一份出码产物可以部署到客户自己的 MySQL 或 SQL Server 上,不需要重新出码。
|
|
31
|
+
///
|
|
32
|
+
/// 注意:单独运行本模块(无 Host、无提供程序配置)时,解析 DbContext 会抛出
|
|
33
|
+
/// "No database provider has been configured" —— 这是**预期行为**,
|
|
34
|
+
/// 说明该由上层补提供程序配置,而不是本模块偷偷兜底成内存库。
|
|
35
|
+
/// </summary>
|
|
36
|
+
[ConnectionStringName(GeneratedConsts.ConnectionStringName)]
|
|
37
|
+
public class GeneratedDbContext : AbpDbContext<GeneratedDbContext>, IGeneratedDbContext
|
|
38
|
+
{
|
|
39
|
+
// 初始工程没有实体。出码器每生成一个实体,就在这里追加一行:
|
|
40
|
+
// public DbSet<{实体名}> {实体名复数} => Set<{实体名}>();
|
|
41
|
+
|
|
42
|
+
public GeneratedDbContext(DbContextOptions<GeneratedDbContext> options)
|
|
43
|
+
: base(options)
|
|
44
|
+
{
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
protected override void OnModelCreating(ModelBuilder builder)
|
|
48
|
+
{
|
|
49
|
+
// 必须调用基类:ABP 的 ExtraProperties、ConcurrencyStamp 等约定在这里生效。
|
|
50
|
+
base.OnModelCreating(builder);
|
|
51
|
+
|
|
52
|
+
// 出码器只改 ConfigureGenerated 的内容,不改本文件。
|
|
53
|
+
builder.ConfigureGenerated();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
using Macrowing.Generated.Domain;
|
|
2
|
+
using Microsoft.EntityFrameworkCore;
|
|
3
|
+
using Volo.Abp.EntityFrameworkCore.Modeling;
|
|
4
|
+
|
|
5
|
+
namespace Macrowing.Generated.EntityFrameworkCore;
|
|
6
|
+
|
|
7
|
+
/// <summary>
|
|
8
|
+
/// 实体 ↔ 表的映射配置,集中在这个扩展方法里。
|
|
9
|
+
///
|
|
10
|
+
/// 【出码器会往这里写什么】
|
|
11
|
+
/// 每生成一个实体,就往本方法末尾追加一个 <c>builder.Entity<{实体名}>(b => { ... })</c> 块,
|
|
12
|
+
/// 块内固定按「表名 → 约定 → 列约束 → 索引」四段生成。
|
|
13
|
+
///
|
|
14
|
+
/// 为什么从 DbContext 里抽出来:
|
|
15
|
+
/// <list type="bullet">
|
|
16
|
+
/// <item>
|
|
17
|
+
/// 实体配置是**纯追加**的,每加一个模型就多一段。放在独立文件里,
|
|
18
|
+
/// 出码器的插入点固定(方法末尾),不会和手写的 DbContext 构造/OnModelCreating 混在一次 diff 里。
|
|
19
|
+
/// </item>
|
|
20
|
+
/// <item>
|
|
21
|
+
/// EF 迁移只看最终 ModelBuilder,拆分不影响迁移结果。
|
|
22
|
+
/// </item>
|
|
23
|
+
/// </list>
|
|
24
|
+
///
|
|
25
|
+
/// 四段生成规则:
|
|
26
|
+
/// <list type="number">
|
|
27
|
+
/// <item><b>表名</b>:<c>GeneratedConsts.TablePrefix + 实体名</c>。
|
|
28
|
+
/// 对应 InBiz 的 TableNamePrefix 机制 —— 平台允许同名模型在不同应用/租户下用不同表名前缀,
|
|
29
|
+
/// 出码产物把它落到常量,而不是把前缀硬编码在每个实体配置里。</item>
|
|
30
|
+
/// <item><b>约定</b>:<c>ConfigureByConvention()</c> 必须在最前调用。
|
|
31
|
+
/// 它负责 ExtraProperties 的 JSON 列、ConcurrencyStamp 乐观锁列、
|
|
32
|
+
/// 以及审计字段的类型与索引约定。漏调会导致 ExtraProperties 建不出来。</item>
|
|
33
|
+
/// <item><b>列约束</b>:从 schema 的 required / maxLength 翻译。
|
|
34
|
+
/// decimal 统一 <c>HasPrecision(18, 4)</c>,不用 provider 专有的 <c>HasColumnType</c>,
|
|
35
|
+
/// 否则同一份出码产物换数据库就要改代码。</item>
|
|
36
|
+
/// <item><b>索引</b>:<c>(OutId, DataVersion)</c> 唯一 —— 见下方注释。</item>
|
|
37
|
+
/// </list>
|
|
38
|
+
/// </summary>
|
|
39
|
+
public static class GeneratedDbContextModelBuilderExtensions
|
|
40
|
+
{
|
|
41
|
+
/// <summary>
|
|
42
|
+
/// 配置出码模块的全部实体。出码器只向这里追加实体块,不要改动已有块。
|
|
43
|
+
/// </summary>
|
|
44
|
+
public static void ConfigureGenerated(this ModelBuilder builder)
|
|
45
|
+
{
|
|
46
|
+
// 初始工程没有实体。出码器每生成一个实体,就在本方法末尾追加一个块,
|
|
47
|
+
// 固定按「表名 → 约定 → 列约束 → 索引」四段生成,形如:
|
|
48
|
+
//
|
|
49
|
+
// builder.Entity<{实体名}>(b =>
|
|
50
|
+
// {
|
|
51
|
+
// b.ToTable(GeneratedConsts.TablePrefix + nameof({实体名}));
|
|
52
|
+
// b.ConfigureByConvention();
|
|
53
|
+
// b.Property(x => x.OutId).IsRequired().HasMaxLength(GeneratedConsts.OutIdMaxLength);
|
|
54
|
+
// b.Property(x => x.DataVersion).IsRequired().HasMaxLength(GeneratedConsts.DataVersionMaxLength);
|
|
55
|
+
// b.HasIndex(x => new { x.OutId, x.DataVersion }).IsUnique();
|
|
56
|
+
// });
|
|
57
|
+
//
|
|
58
|
+
// 唯一性必须是 (OutId, DataVersion):平台的 copy-on-write 定制机制会让同一条业务记录
|
|
59
|
+
// 在基线与定制版本下各存一份、outId 相同;只对 OutId 建唯一索引会在定制数据落库时冲突。
|
|
60
|
+
}
|
|
61
|
+
}
|
package/templates/backend/modules/Macrowing.Generated/EntityFrameworkCore/IGeneratedDbContext.cs
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
using Macrowing.Generated.Domain;
|
|
2
|
+
using Microsoft.EntityFrameworkCore;
|
|
3
|
+
using Volo.Abp.Data;
|
|
4
|
+
using Volo.Abp.EntityFrameworkCore;
|
|
5
|
+
|
|
6
|
+
namespace Macrowing.Generated.EntityFrameworkCore;
|
|
7
|
+
|
|
8
|
+
/// <summary>
|
|
9
|
+
/// 出码模块的 DbContext 契约。
|
|
10
|
+
///
|
|
11
|
+
/// 【出码器会往这里写什么】
|
|
12
|
+
/// 每生成一个实体,就往这里加一行 <c>DbSet<{实体名}> {实体名复数} { get; }</c>。
|
|
13
|
+
/// 这是全模块**唯一**需要按实体数量增行的文件,因此它必须是纯追加结构:
|
|
14
|
+
/// 出码器只插入,不重排已有行,否则每次生成都会在文件中部产生大段 diff。
|
|
15
|
+
///
|
|
16
|
+
/// 为什么单独定义接口而不是让应用服务直接依赖 <c>GeneratedDbContext</c>:
|
|
17
|
+
/// 1. ABP 的 <c>AddDefaultRepositories</c> 需要知道「仓储挂哪个 DbContext」,接口是它的锚点;
|
|
18
|
+
/// 2. 自定义仓储(如 EfCore{实体名}Repository)依赖 <c>IDbContextProvider<IGeneratedDbContext></c>,
|
|
19
|
+
/// 而不是具体类 —— 将来按连接串拆分多个 DbContext 时,仓储代码不用改;
|
|
20
|
+
/// 3. 集成测试可以用实现同一接口的内存/替换上下文。
|
|
21
|
+
///
|
|
22
|
+
/// 连接串名取自 <see cref="GeneratedConsts.ConnectionStringName"/>:
|
|
23
|
+
/// 出码产物默认用 <c>Default</c>,若客户要求业务库与平台库分离,改常量即可整体切走。
|
|
24
|
+
/// </summary>
|
|
25
|
+
[ConnectionStringName(GeneratedConsts.ConnectionStringName)]
|
|
26
|
+
public interface IGeneratedDbContext : IEfCoreDbContext
|
|
27
|
+
{
|
|
28
|
+
// 初始工程没有实体。出码器每生成一个实体,就在这里追加一行:
|
|
29
|
+
// DbSet<{实体名}> {实体名复数} { get; }
|
|
30
|
+
// 命名规则:实体名的复数(ABP 约定用 DbSet 名决定默认表名,
|
|
31
|
+
// 但本项目统一在 ModelBuilder 里显式 ToTable,因此 DbSet 名只影响代码可读性)。
|
|
32
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
using Macrowing.Generated.EntityFrameworkCore;
|
|
2
|
+
using Microsoft.Extensions.DependencyInjection;
|
|
3
|
+
using Volo.Abp.Application;
|
|
4
|
+
using Volo.Abp.AutoMapper;
|
|
5
|
+
using Volo.Abp.Domain;
|
|
6
|
+
using Volo.Abp.EntityFrameworkCore;
|
|
7
|
+
using Volo.Abp.Modularity;
|
|
8
|
+
|
|
9
|
+
namespace Macrowing.Generated;
|
|
10
|
+
|
|
11
|
+
/// <summary>
|
|
12
|
+
/// 出码业务模块。此文件是**手写文件,出码器不覆盖**。
|
|
13
|
+
///
|
|
14
|
+
/// 出码器只会向下列子目录写入产物:
|
|
15
|
+
/// <code>
|
|
16
|
+
/// Domain/
|
|
17
|
+
/// GeneratedConsts.cs 常量(表前缀、长度)—— 可覆盖
|
|
18
|
+
/// Entities/GeneratedEntityBase.cs 实体基类 —— 不覆盖
|
|
19
|
+
/// Entities/{模型名}.generated.cs 实体 —— 覆盖
|
|
20
|
+
/// I{模型名}Repository.cs 仓储接口 —— 覆盖
|
|
21
|
+
/// Application/
|
|
22
|
+
/// {模型名}s/{模型名}Dto.cs 输出 DTO —— 覆盖
|
|
23
|
+
/// {模型名}s/CreateUpdate{模型名}Dto.cs 输入 DTO —— 覆盖
|
|
24
|
+
/// {模型名}s/{模型名}GetListInput.cs 列表入参 —— 覆盖
|
|
25
|
+
/// {模型名}s/I{模型名}AppService.cs 应用服务契约 —— 覆盖
|
|
26
|
+
/// {模型名}s/{模型名}AppService.cs 应用服务实现 —— 覆盖
|
|
27
|
+
/// GeneratedApplicationAutoMapperProfile.cs 映射 —— 纯追加
|
|
28
|
+
/// EntityFrameworkCore/
|
|
29
|
+
/// IGeneratedDbContext.cs DbSet 声明 —— 纯追加
|
|
30
|
+
/// GeneratedDbContext.cs 上下文本体 —— 不覆盖
|
|
31
|
+
/// GeneratedDbContextModelBuilderExtensions.cs 表映射 —— 纯追加
|
|
32
|
+
/// EfCore{模型名}Repository.cs 自定义仓储 —— 覆盖(仅当有额外查询时)
|
|
33
|
+
/// </code>
|
|
34
|
+
///
|
|
35
|
+
/// 本文件(GeneratedModule)是**装配点**,出码器只读不写:
|
|
36
|
+
/// 它注册的是「框架级」的东西(模块依赖、仓储、映射扫描),子目录增减不影响它。
|
|
37
|
+
/// 若出码器确实需要改本文件,会产出 GeneratedModule.suggested.cs 交给人工合并,
|
|
38
|
+
/// 而不是直接覆盖 —— 这是三段式规则在后端的落地。
|
|
39
|
+
///
|
|
40
|
+
/// 模块依赖说明(为什么必须是这四个 ABP 模块):
|
|
41
|
+
/// <list type="bullet">
|
|
42
|
+
/// <item><c>AbpDddDomainModule</c> —— 提供 IRepository / 聚合根基类 / 工作单元。</item>
|
|
43
|
+
/// <item><c>AbpDddApplicationModule</c> —— 提供 CrudAppService / ApplicationService 基类。</item>
|
|
44
|
+
/// <item><c>AbpEntityFrameworkCoreModule</c> —— 提供 AbpDbContext / AddAbpDbContext 注册扩展。</item>
|
|
45
|
+
/// <item><c>AbpAutoMapperModule</c> —— 提供 AbpAutoMapperOptions 与 ObjectMapper,缺了它 DTO 映射不会生效(运行时空引用)。</item>
|
|
46
|
+
/// </list>
|
|
47
|
+
///
|
|
48
|
+
/// 数据库提供程序不在这里配置,见 GeneratedDbContext 的注释。
|
|
49
|
+
/// </summary>
|
|
50
|
+
[DependsOn(
|
|
51
|
+
typeof(AbpDddDomainModule),
|
|
52
|
+
typeof(AbpDddApplicationModule),
|
|
53
|
+
typeof(AbpEntityFrameworkCoreModule),
|
|
54
|
+
typeof(AbpAutoMapperModule),
|
|
55
|
+
typeof(InBiz.SDK.InBizSdkModule),
|
|
56
|
+
typeof(OC.SDK.OcSdkModule)
|
|
57
|
+
)]
|
|
58
|
+
public class GeneratedModule : AbpModule
|
|
59
|
+
{
|
|
60
|
+
public override void ConfigureServices(ServiceConfigurationContext context)
|
|
61
|
+
{
|
|
62
|
+
// 给本模块注册独立的 ObjectMapper 实例:
|
|
63
|
+
// 不调用这一行时,AddMaps 扫描到的 Profile 会被挂到根映射器上,
|
|
64
|
+
// 与宿主的映射配置混在一起,一旦有同名 DTO 就会出现「映射到了别的模块的类」。
|
|
65
|
+
context.Services.AddAutoMapperObjectMapper<GeneratedModule>();
|
|
66
|
+
|
|
67
|
+
Configure<AbpAutoMapperOptions>(options =>
|
|
68
|
+
{
|
|
69
|
+
// Generated/ 下的 Profile 由此注册
|
|
70
|
+
// validate: false —— 保持脚手架既有行为。若希望出码器漏映射时在启动阶段就失败,
|
|
71
|
+
// 可改为 true;代价是实体新增字段而 DTO 未同步时会直接起不来。
|
|
72
|
+
options.AddMaps<GeneratedModule>(validate: false);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
context.Services.AddAbpDbContext<GeneratedDbContext>(options =>
|
|
76
|
+
{
|
|
77
|
+
// 默认仓储:为所有实体注册 IRepository<T, TKey>(含软删除过滤、分页)。
|
|
78
|
+
// includeAllEntities: true 让出码实体不必逐个注册 —— 实体是生成出来的,
|
|
79
|
+
// 逐个注册意味着出码器还得改本文件。
|
|
80
|
+
options.AddDefaultRepositories(includeAllEntities: true);
|
|
81
|
+
|
|
82
|
+
// 显式仓储:领域层声明了额外查询方法的实体,必须在这里绑定具体实现,
|
|
83
|
+
// 否则解析 I{模型名}Repository 时会落回默认实现而缺少自定义方法。
|
|
84
|
+
// 出码器为本行生成规则:仅当 I{模型名}Repository 有额外方法时追加,
|
|
85
|
+
// 形如 options.AddRepository<{实体名}, EfCore{实体名}Repository>();
|
|
86
|
+
// 初始工程没有任何实体,这里保持为空。
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
|
2
|
+
|
|
3
|
+
<PropertyGroup>
|
|
4
|
+
<RootNamespace>Macrowing.Generated</RootNamespace>
|
|
5
|
+
<AssemblyName>Macrowing.Generated</AssemblyName>
|
|
6
|
+
<!-- 出码器识别标记:本工程下 *.generated.cs 可被安全覆盖 -->
|
|
7
|
+
<IsGenerated>true</IsGenerated>
|
|
8
|
+
</PropertyGroup>
|
|
9
|
+
|
|
10
|
+
<ItemGroup>
|
|
11
|
+
<PackageReference Include="Volo.Abp.Ddd.Domain" />
|
|
12
|
+
<PackageReference Include="Volo.Abp.Ddd.Application" />
|
|
13
|
+
<PackageReference Include="Volo.Abp.EntityFrameworkCore" />
|
|
14
|
+
<PackageReference Include="Volo.Abp.AutoMapper" />
|
|
15
|
+
</ItemGroup>
|
|
16
|
+
|
|
17
|
+
<ItemGroup>
|
|
18
|
+
<ProjectReference Include="..\Macrowing.InBiz.SDK\Macrowing.InBiz.SDK.csproj" />
|
|
19
|
+
<ProjectReference Include="..\Macrowing.OC.SDK\Macrowing.OC.SDK.csproj" />
|
|
20
|
+
</ItemGroup>
|
|
21
|
+
|
|
22
|
+
</Project>
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
using System.Globalization;
|
|
2
|
+
using Macrowing.InBiz.SDK.Platform;
|
|
3
|
+
|
|
4
|
+
namespace Macrowing.InBiz.SDK.Cms;
|
|
5
|
+
|
|
6
|
+
/// <summary>Reads news and images from the platform CMS. Does not manage files or edit published content.</summary>
|
|
7
|
+
public interface ICmsClient
|
|
8
|
+
{
|
|
9
|
+
/// <summary>Reads category choices under the given parent.</summary>
|
|
10
|
+
/// <param name="context">Authorized application and caller.</param>
|
|
11
|
+
/// <param name="kind">Image or news categories.</param>
|
|
12
|
+
/// <param name="parentId">Parent category key. Omit for the platform's root category.</param>
|
|
13
|
+
/// <param name="cancellationToken">Cancels the HTTP call.</param>
|
|
14
|
+
/// <returns>Category keys and titles in the server's order.</returns>
|
|
15
|
+
Task<IReadOnlyList<CmsCategory>> GetCategoriesAsync(InBizRequestContext context, CmsContentKind kind,
|
|
16
|
+
string parentId = "0000-0000-0000", CancellationToken cancellationToken = default);
|
|
17
|
+
|
|
18
|
+
/// <summary>Reads one page of CMS content, with pinned records returned separately by the server.</summary>
|
|
19
|
+
/// <param name="context">Authorized application and caller.</param>
|
|
20
|
+
/// <param name="query">Category, content type and paging options.</param>
|
|
21
|
+
/// <param name="cancellationToken">Cancels the HTTP call.</param>
|
|
22
|
+
/// <returns>The CMS page, including any pinned content.</returns>
|
|
23
|
+
Task<CmsContentPage> ListAsync(InBizRequestContext context, CmsContentQuery query, CancellationToken cancellationToken = default);
|
|
24
|
+
|
|
25
|
+
/// <summary>Reads full CMS content, including the original body or configured external link.</summary>
|
|
26
|
+
/// <param name="context">Authorized application and caller.</param>
|
|
27
|
+
/// <param name="id">The content ID, not its category key.</param>
|
|
28
|
+
/// <param name="cancellationToken">Cancels the HTTP call.</param>
|
|
29
|
+
/// <returns>The CMS entry, or null when the service returns no content.</returns>
|
|
30
|
+
Task<CmsContent?> GetAsync(InBizRequestContext context, string id, CancellationToken cancellationToken = default);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
internal sealed class CmsClient(InBizPlatformTransport transport) : ICmsClient
|
|
34
|
+
{
|
|
35
|
+
private const string Prefix = "api/services/cms/v3/cms/";
|
|
36
|
+
|
|
37
|
+
public async Task<IReadOnlyList<CmsCategory>> GetCategoriesAsync(InBizRequestContext context, CmsContentKind kind,
|
|
38
|
+
string parentId, CancellationToken cancellationToken)
|
|
39
|
+
{
|
|
40
|
+
var route = Prefix + "categoryTree/" + InBizPlatformTransport.PathSegment(parentId) + "?categoryType=" + EncodeKind(kind);
|
|
41
|
+
var reply = await transport.SendAsync(context, HttpMethod.Get, route, cancellationToken).ConfigureAwait(false);
|
|
42
|
+
return reply.Require<IReadOnlyList<CmsCategory>>();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public async Task<CmsContentPage> ListAsync(InBizRequestContext context, CmsContentQuery query, CancellationToken cancellationToken)
|
|
46
|
+
{
|
|
47
|
+
ArgumentNullException.ThrowIfNull(query);
|
|
48
|
+
if (query.PageIndex < 1 || query.PageSize < 1 || query.TopNum < 0 || query.NumNew < 0)
|
|
49
|
+
throw new ArgumentOutOfRangeException(nameof(query), "Paging values must be positive and top/new counts cannot be negative.");
|
|
50
|
+
var parameters = new Dictionary<string, string>
|
|
51
|
+
{
|
|
52
|
+
["categoryId"] = InBizPlatformTransport.QueryValue(query.CategoryId),
|
|
53
|
+
["contentType"] = EncodeKind(query.Kind),
|
|
54
|
+
["pageIndex"] = query.PageIndex.ToString(CultureInfo.InvariantCulture),
|
|
55
|
+
["pageSize"] = query.PageSize.ToString(CultureInfo.InvariantCulture),
|
|
56
|
+
["topNum"] = query.TopNum.ToString(CultureInfo.InvariantCulture),
|
|
57
|
+
["numNew"] = query.NumNew.ToString(CultureInfo.InvariantCulture),
|
|
58
|
+
["getDetail"] = query.GetDetail ? "true" : "false",
|
|
59
|
+
["showNew"] = query.ShowNew ? "true" : "false"
|
|
60
|
+
};
|
|
61
|
+
if (!string.IsNullOrWhiteSpace(query.Tag))
|
|
62
|
+
parameters["tag"] = InBizPlatformTransport.QueryValue(query.Tag);
|
|
63
|
+
if (!string.IsNullOrWhiteSpace(query.CustomCategoryIds))
|
|
64
|
+
parameters["customCategoryIds"] = InBizPlatformTransport.QueryValue(query.CustomCategoryIds);
|
|
65
|
+
var reply = await transport.SendAsync(context, HttpMethod.Get, Prefix + "contentList?" +
|
|
66
|
+
string.Join("&", parameters.Select(pair => pair.Key + "=" + pair.Value)), cancellationToken).ConfigureAwait(false);
|
|
67
|
+
var page = reply.Require<PageReply>();
|
|
68
|
+
if (page.Total is not int total || page.PageIndex is not int index ||
|
|
69
|
+
page.PageSize is not int size || page.PageCount is not int pageCount)
|
|
70
|
+
throw reply.ProtocolFailure();
|
|
71
|
+
return new(page.ContentList ?? [], page.TopList ?? [], index, size, pageCount, total);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public async Task<CmsContent?> GetAsync(InBizRequestContext context, string id, CancellationToken cancellationToken)
|
|
75
|
+
{
|
|
76
|
+
var route = Prefix + InBizPlatformTransport.PathSegment(id) + "/detailContentInfo";
|
|
77
|
+
var reply = await transport.SendAsync(context, HttpMethod.Get, route, cancellationToken).ConfigureAwait(false);
|
|
78
|
+
if (reply.Status == System.Net.HttpStatusCode.NoContent)
|
|
79
|
+
return null;
|
|
80
|
+
var content = reply.Read<CmsContent>();
|
|
81
|
+
if (content is not null && string.IsNullOrWhiteSpace(content.Id))
|
|
82
|
+
throw reply.ProtocolFailure();
|
|
83
|
+
return content;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private static string EncodeKind(CmsContentKind kind) => kind switch
|
|
87
|
+
{
|
|
88
|
+
CmsContentKind.Image => "0",
|
|
89
|
+
CmsContentKind.News => "1",
|
|
90
|
+
_ => throw new ArgumentOutOfRangeException(nameof(kind))
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
private sealed record PageReply(IReadOnlyList<CmsContent>? ContentList, IReadOnlyList<CmsContent>? TopList,
|
|
94
|
+
int? PageIndex, int? PageSize, int? PageCount, int? Total);
|
|
95
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
namespace Macrowing.InBiz.SDK.Cms;
|
|
2
|
+
|
|
3
|
+
/// <summary>Published CMS content and category types.</summary>
|
|
4
|
+
public enum CmsContentKind
|
|
5
|
+
{
|
|
6
|
+
/// <summary>Image content and image categories.</summary>
|
|
7
|
+
Image = 0,
|
|
8
|
+
/// <summary>News content and news categories.</summary>
|
|
9
|
+
News = 1
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/// <summary>A category that can be used for a CMS content query.</summary>
|
|
13
|
+
/// <param name="Key">Category ID.</param>
|
|
14
|
+
/// <param name="Title">Category display name.</param>
|
|
15
|
+
public sealed record CmsCategory(string Key, string Title);
|
|
16
|
+
|
|
17
|
+
/// <summary>Filters for a page of published content.</summary>
|
|
18
|
+
/// <param name="Kind">Image or news content.</param>
|
|
19
|
+
/// <param name="CategoryId">The configured CMS category ID; the server does not list content without a category.</param>
|
|
20
|
+
public sealed record CmsContentQuery(CmsContentKind Kind, string CategoryId)
|
|
21
|
+
{
|
|
22
|
+
/// <summary>One-based page index.</summary>
|
|
23
|
+
public int PageIndex { get; init; } = 1;
|
|
24
|
+
/// <summary>Maximum number of regular rows per page.</summary>
|
|
25
|
+
public int PageSize { get; init; } = 20;
|
|
26
|
+
/// <summary>Maximum number of pinned entries requested separately.</summary>
|
|
27
|
+
public int TopNum { get; init; }
|
|
28
|
+
/// <summary>Whether to request the full content body in list results.</summary>
|
|
29
|
+
public bool GetDetail { get; init; }
|
|
30
|
+
/// <summary>Whether to ask the service to mark recent entries.</summary>
|
|
31
|
+
public bool ShowNew { get; init; }
|
|
32
|
+
/// <summary>Number of recent entries to mark when <see cref="ShowNew"/> is enabled.</summary>
|
|
33
|
+
public int NumNew { get; init; }
|
|
34
|
+
/// <summary>Optional configured tag, such as the tag used by a portal news component.</summary>
|
|
35
|
+
public string? Tag { get; init; }
|
|
36
|
+
/// <summary>Optional custom category filter in the format configured in CMS.</summary>
|
|
37
|
+
public string? CustomCategoryIds { get; init; }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/// <summary>A page as returned by CMS. Pinned entries are not merged with regular entries.</summary>
|
|
41
|
+
/// <param name="ContentList">Regular entries.</param>
|
|
42
|
+
/// <param name="TopList">Pinned entries.</param>
|
|
43
|
+
/// <param name="PageIndex">Page index reported by the service.</param>
|
|
44
|
+
/// <param name="PageSize">Page size reported by the service.</param>
|
|
45
|
+
/// <param name="PageCount">Page count reported by the service.</param>
|
|
46
|
+
/// <param name="Total">Total reported by the service.</param>
|
|
47
|
+
public sealed record CmsContentPage(IReadOnlyList<CmsContent> ContentList, IReadOnlyList<CmsContent> TopList,
|
|
48
|
+
int PageIndex, int PageSize, int PageCount, int Total);
|
|
49
|
+
|
|
50
|
+
/// <summary>A published CMS entry. Treat body markup and URLs as untrusted when rendering them.</summary>
|
|
51
|
+
/// <param name="Id">Content ID.</param>
|
|
52
|
+
/// <param name="Title">Display title.</param>
|
|
53
|
+
/// <param name="Summary">Short summary.</param>
|
|
54
|
+
/// <param name="Content">Body, which may contain original markup.</param>
|
|
55
|
+
/// <param name="ContentUrl">Configured content link.</param>
|
|
56
|
+
/// <param name="ImgUrl">Configured image URL.</param>
|
|
57
|
+
/// <param name="ImgLinkUrl">Configured destination of the image link.</param>
|
|
58
|
+
/// <param name="ContentType">Image or news content type.</param>
|
|
59
|
+
/// <param name="ContentCategory">Parent category ID.</param>
|
|
60
|
+
/// <param name="ContentCategoryName">Parent category display name.</param>
|
|
61
|
+
/// <param name="CustomCategories">Custom category value from CMS.</param>
|
|
62
|
+
/// <param name="Tag">Configured content tag.</param>
|
|
63
|
+
/// <param name="IsTop">Whether CMS marked the entry as pinned.</param>
|
|
64
|
+
/// <param name="IsNew">Whether the list request marked the entry as recent.</param>
|
|
65
|
+
/// <param name="IsOutsiteUrl">Whether CMS marked the content link as external.</param>
|
|
66
|
+
/// <param name="CreateTime">Creation date text as returned by CMS.</param>
|
|
67
|
+
/// <param name="CreateTimeStr">Creation date text with time as returned by CMS.</param>
|
|
68
|
+
/// <param name="LastModifiedTime">Last modification date text as returned by CMS.</param>
|
|
69
|
+
/// <param name="Creator">Creator display name.</param>
|
|
70
|
+
/// <param name="CreatorId">Creator user ID.</param>
|
|
71
|
+
/// <param name="LastModifier">Last modifier display name.</param>
|
|
72
|
+
/// <param name="LastModifierId">Last modifier user ID.</param>
|
|
73
|
+
/// <param name="CreatorIdentityId">Creator identity number reported by CMS.</param>
|
|
74
|
+
/// <param name="Timestamp">CMS synchronization timestamp.</param>
|
|
75
|
+
public sealed record CmsContent(string Id, string? Title, string? Summary, string? Content, string? ContentUrl,
|
|
76
|
+
string? ImgUrl, string? ImgLinkUrl, CmsContentKind ContentType, string? ContentCategory, string? ContentCategoryName,
|
|
77
|
+
string? CustomCategories, string? Tag, bool IsTop, bool IsNew, bool IsOutsiteUrl, string? CreateTime,
|
|
78
|
+
string? CreateTimeStr, string? LastModifiedTime, string? Creator, string? CreatorId, string? LastModifier,
|
|
79
|
+
string? LastModifierId, int CreatorIdentityId,
|
|
80
|
+
[property: System.Text.Json.Serialization.JsonNumberHandling(System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString)]
|
|
81
|
+
long Timestamp);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
using Macrowing.InBiz.SDK.Platform;
|
|
2
|
+
|
|
3
|
+
namespace Macrowing.InBiz.SDK.Dictionary;
|
|
4
|
+
|
|
5
|
+
/// <summary>A dictionary entry as returned by the model engine, without changing its value or display order.</summary>
|
|
6
|
+
/// <param name="Id">Dictionary entry ID.</param>
|
|
7
|
+
/// <param name="Value">Stored value used by applications.</param>
|
|
8
|
+
/// <param name="Text">Display text, translated by the server when available.</param>
|
|
9
|
+
/// <param name="GroupId">Dictionary group key.</param>
|
|
10
|
+
/// <param name="AppId">Owning application ID.</param>
|
|
11
|
+
/// <param name="ColumnSort">Configured display order.</param>
|
|
12
|
+
/// <param name="IsCustomized">Whether the entry is a customized platform record.</param>
|
|
13
|
+
public sealed record DictionaryEntry(string? Id, string? Value, string? Text, string? GroupId, string? AppId,
|
|
14
|
+
int ColumnSort, bool IsCustomized);
|
|
15
|
+
|
|
16
|
+
/// <summary>Reads application dictionary options without changing the dictionary configuration.</summary>
|
|
17
|
+
public interface IDictionaryClient
|
|
18
|
+
{
|
|
19
|
+
/// <summary>Reads options for several dictionary groups in one request.</summary>
|
|
20
|
+
/// <param name="context">Authorized application and caller.</param>
|
|
21
|
+
/// <param name="groupKeys">Individual keys of the configured dictionary groups, not display names.</param>
|
|
22
|
+
/// <param name="kindCode">Optional language code. The server applies its normal translation fallback.</param>
|
|
23
|
+
/// <param name="cancellationToken">Cancels the HTTP call.</param>
|
|
24
|
+
/// <returns>Options keyed by group ID; groups with no entries can be absent.</returns>
|
|
25
|
+
Task<IReadOnlyDictionary<string, IReadOnlyList<DictionaryEntry>>> GetGroupsAsync(InBizRequestContext context,
|
|
26
|
+
IReadOnlyCollection<string> groupKeys, string? kindCode = null, CancellationToken cancellationToken = default);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
internal sealed class DictionaryClient(InBizPlatformTransport transport) : IDictionaryClient
|
|
30
|
+
{
|
|
31
|
+
public async Task<IReadOnlyDictionary<string, IReadOnlyList<DictionaryEntry>>> GetGroupsAsync(InBizRequestContext context,
|
|
32
|
+
IReadOnlyCollection<string> groupKeys, string? kindCode, CancellationToken cancellationToken)
|
|
33
|
+
{
|
|
34
|
+
ArgumentNullException.ThrowIfNull(groupKeys);
|
|
35
|
+
if (groupKeys.Count == 0 || groupKeys.Any(key => string.IsNullOrWhiteSpace(key) || key.Contains(',')))
|
|
36
|
+
throw new ArgumentException("Provide at least one group key, with no commas in individual keys.", nameof(groupKeys));
|
|
37
|
+
var route = "api/services/front/modelengine/v3/dictData/groupIds/" + InBizPlatformTransport.AppPath(context) +
|
|
38
|
+
"?groupKeys=" + InBizPlatformTransport.QueryValue(string.Join(",", groupKeys));
|
|
39
|
+
if (kindCode is not null)
|
|
40
|
+
route += "&kindCode=" + InBizPlatformTransport.QueryValue(kindCode);
|
|
41
|
+
var reply = await transport.SendAsync(context, HttpMethod.Get, route, cancellationToken).ConfigureAwait(false);
|
|
42
|
+
return reply.Require<Dictionary<string, IReadOnlyList<DictionaryEntry>>>();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
using Macrowing.InBiz.SDK.Platform;
|
|
2
|
+
using Macrowing.InBiz.SDK.WorkFlow;
|
|
3
|
+
using Volo.Abp.Modularity;
|
|
4
|
+
|
|
5
|
+
namespace Macrowing.InBiz.SDK;
|
|
6
|
+
|
|
7
|
+
/// <summary>Registers the InBiz platform and workflow clients in an ABP host.</summary>
|
|
8
|
+
public class InBizSdkModule : AbpModule
|
|
9
|
+
{
|
|
10
|
+
/// <inheritdoc />
|
|
11
|
+
public override void ConfigureServices(ServiceConfigurationContext context)
|
|
12
|
+
{
|
|
13
|
+
context.Services.AddInBizPlatform();
|
|
14
|
+
context.Services.AddInBizWorkFlow();
|
|
15
|
+
}
|
|
16
|
+
}
|
package/templates/backend/modules/Macrowing.InBiz.SDK/InterfaceEngine/InterfaceEngineClient.cs
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
using System.Text.Json;
|
|
2
|
+
using Macrowing.InBiz.SDK.Platform;
|
|
3
|
+
|
|
4
|
+
namespace Macrowing.InBiz.SDK.InterfaceEngine;
|
|
5
|
+
|
|
6
|
+
/// <summary>Parameters for invoking an interface already configured in the application.</summary>
|
|
7
|
+
/// <param name="Key">Configured interface key, not a URL.</param>
|
|
8
|
+
/// <param name="Header">Configured header parameter values, not the InBiz authentication headers.</param>
|
|
9
|
+
/// <param name="Body">JSON object parameters for the configured upstream body.</param>
|
|
10
|
+
/// <param name="Query">Configured query parameter values.</param>
|
|
11
|
+
/// <param name="Path">Configured path parameter values.</param>
|
|
12
|
+
public sealed record InterfaceInvocation(string Key, IReadOnlyDictionary<string, object?>? Header = null,
|
|
13
|
+
IReadOnlyDictionary<string, object?>? Body = null, IReadOnlyDictionary<string, object?>? Query = null,
|
|
14
|
+
IReadOnlyDictionary<string, object?>? Path = null);
|
|
15
|
+
|
|
16
|
+
/// <summary>Calls interfaces configured in InBiz. Does not create interfaces or accept arbitrary upstream URLs.</summary>
|
|
17
|
+
public interface IInterfaceEngineClient
|
|
18
|
+
{
|
|
19
|
+
/// <summary>Invokes a configured interface. The configured operation can have side effects; the SDK does not retry it.</summary>
|
|
20
|
+
/// <param name="context">Authorized application and caller.</param>
|
|
21
|
+
/// <param name="invocation">Configured key and parameter values. The SDK performs the platform's nested JSON encoding.</param>
|
|
22
|
+
/// <param name="cancellationToken">Cancels waiting, not the upstream operation.</param>
|
|
23
|
+
/// <returns>Returned text. The application's configured upstream contract determines its structure and success semantics.</returns>
|
|
24
|
+
Task<string> InvokeAsync(InBizRequestContext context, InterfaceInvocation invocation, CancellationToken cancellationToken = default);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
internal sealed class InterfaceEngineClient(InBizPlatformTransport transport) : IInterfaceEngineClient
|
|
28
|
+
{
|
|
29
|
+
public async Task<string> InvokeAsync(InBizRequestContext context, InterfaceInvocation invocation, CancellationToken cancellationToken)
|
|
30
|
+
{
|
|
31
|
+
ArgumentNullException.ThrowIfNull(context);
|
|
32
|
+
ArgumentNullException.ThrowIfNull(invocation);
|
|
33
|
+
ArgumentException.ThrowIfNullOrWhiteSpace(invocation.Key);
|
|
34
|
+
var reply = await transport.SendAsync(context, HttpMethod.Post, InBizPlatformTransport.PublicApi + "apiEngineApp/invoke",
|
|
35
|
+
cancellationToken, new
|
|
36
|
+
{
|
|
37
|
+
invocation.Key, context.AppId, Header = Encode(invocation.Header), Body = Encode(invocation.Body),
|
|
38
|
+
Query = Encode(invocation.Query), Path = Encode(invocation.Path)
|
|
39
|
+
}).ConfigureAwait(false);
|
|
40
|
+
if (reply.MediaType?.Equals("text/html", StringComparison.OrdinalIgnoreCase) == true ||
|
|
41
|
+
(reply.IsJson && reply.Body.AsSpan().Trim().SequenceEqual("null")))
|
|
42
|
+
throw reply.ProtocolFailure();
|
|
43
|
+
return reply.IsJson && reply.Body.AsSpan().TrimStart().StartsWith("\"", StringComparison.Ordinal)
|
|
44
|
+
? reply.Require<string>()
|
|
45
|
+
: reply.Body;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private static string? Encode(IReadOnlyDictionary<string, object?>? value) =>
|
|
49
|
+
value is null ? null : JsonSerializer.Serialize(value, InBizPlatformTransport.Json);
|
|
50
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
using System.Text.Json;
|
|
2
|
+
using Macrowing.InBiz.SDK.Platform;
|
|
3
|
+
|
|
4
|
+
namespace Macrowing.InBiz.SDK.Localization;
|
|
5
|
+
|
|
6
|
+
/// <summary>Reads published InBiz translations for an application.</summary>
|
|
7
|
+
public interface ILocalizationClient
|
|
8
|
+
{
|
|
9
|
+
/// <summary>Reads published business translations for one language without merging design-time or component dictionaries.</summary>
|
|
10
|
+
/// <param name="context">Authorized application and caller.</param>
|
|
11
|
+
/// <param name="kindCode">Platform language code, for example <c>zh-cn</c>.</param>
|
|
12
|
+
/// <param name="cancellationToken">Cancels the HTTP call.</param>
|
|
13
|
+
/// <returns>Translation entries as published. JSON values preserve any nested namespaces.</returns>
|
|
14
|
+
Task<IReadOnlyDictionary<string, JsonElement>> GetTextsAsync(InBizRequestContext context, string kindCode,
|
|
15
|
+
CancellationToken cancellationToken = default);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
internal sealed class LocalizationClient(InBizPlatformTransport transport) : ILocalizationClient
|
|
19
|
+
{
|
|
20
|
+
public async Task<IReadOnlyDictionary<string, JsonElement>> GetTextsAsync(InBizRequestContext context,
|
|
21
|
+
string kindCode, CancellationToken cancellationToken)
|
|
22
|
+
{
|
|
23
|
+
var route = "api/services/languagengine/v3/language/json/" + InBizPlatformTransport.AppPath(context) +
|
|
24
|
+
"?kindCode=" + InBizPlatformTransport.QueryValue(kindCode) + "&type=0";
|
|
25
|
+
var reply = await transport.SendAsync(context, HttpMethod.Get, route, cancellationToken).ConfigureAwait(false);
|
|
26
|
+
return reply.Require<Dictionary<string, JsonElement>>();
|
|
27
|
+
}
|
|
28
|
+
}
|