From 551ac09f78588d37217bdc736c3dc444ccd3b970 Mon Sep 17 00:00:00 2001 From: xiaolipro <2357729423@qq.com> Date: Tue, 13 Oct 2026 15:20:53 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E5=8D=87=E7=BA=A7=E6=A1=86?= =?UTF-8?q?=E6=9E=B6=E6=80=BB=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Directory.Build.props | 4 +- Fake.Local.EventBus.props | 13 ++ SimpleAdmin.sln | 1 + src/Oms.Application/Oms.Application.csproj | 28 +++- src/Oms.Tests/Oms.Tests.csproj | 12 +- src/SimpleAdmin.Api/Program.cs | 12 +- src/SimpleAdmin.Api/SimpleAdmin.Api.csproj | 28 +++- src/SimpleAdmin.Api/SimpleAdminApiModule.cs | 16 +- .../Storage/IntegrationEventLogSchema.cs | 48 ------ .../appsettings.Development.json | 158 ------------------ src/SimpleAdmin.Api/appsettings.json | 4 +- 11 files changed, 92 insertions(+), 232 deletions(-) create mode 100644 Fake.Local.EventBus.props delete mode 100644 src/SimpleAdmin.Api/Storage/IntegrationEventLogSchema.cs delete mode 100644 src/SimpleAdmin.Api/appsettings.Development.json diff --git a/Directory.Build.props b/Directory.Build.props index 5ebd994..9220097 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,8 @@ + + - 8.0.5.20 + 8.0.5.21 diff --git a/Fake.Local.EventBus.props b/Fake.Local.EventBus.props new file mode 100644 index 0000000..9e0099b --- /dev/null +++ b/Fake.Local.EventBus.props @@ -0,0 +1,13 @@ + + + + C:\Users\BSI\RiderProjects\fake2 + + false + + false + + diff --git a/SimpleAdmin.sln b/SimpleAdmin.sln index 8816a47..858277c 100644 --- a/SimpleAdmin.sln +++ b/SimpleAdmin.sln @@ -16,6 +16,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "items", "items", "{BE5132AD db.sql = db.sql Directory.Build.props = Directory.Build.props .gitea\workflows\deploy.yml = .gitea\workflows\deploy.yml + Fake.Local.EventBus.props = Fake.Local.EventBus.props EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleAdmin.Api", "src\SimpleAdmin.Api\SimpleAdmin.Api.csproj", "{229ED167-9ECC-4736-8DFB-522EEA8FF680}" diff --git a/src/Oms.Application/Oms.Application.csproj b/src/Oms.Application/Oms.Application.csproj index 72efa2e..515006d 100644 --- a/src/Oms.Application/Oms.Application.csproj +++ b/src/Oms.Application/Oms.Application.csproj @@ -18,13 +18,8 @@ - - - - - @@ -35,6 +30,29 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Oms.Tests/Oms.Tests.csproj b/src/Oms.Tests/Oms.Tests.csproj index 040ca5b..2638958 100644 --- a/src/Oms.Tests/Oms.Tests.csproj +++ b/src/Oms.Tests/Oms.Tests.csproj @@ -14,8 +14,18 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + + + + + + + + + + + diff --git a/src/SimpleAdmin.Api/Program.cs b/src/SimpleAdmin.Api/Program.cs index 39bf160..4c8fb29 100644 --- a/src/SimpleAdmin.Api/Program.cs +++ b/src/SimpleAdmin.Api/Program.cs @@ -1,10 +1,16 @@ +using Fake.EntityFrameworkCore; using Serilog; using SimpleAdmin.Api; var builder = WebApplication.CreateSlimBuilder(args); var configuration = builder.Configuration; -builder.Configuration.AddConsul("idwms/common", source => source.ReloadOnChange = true); -builder.Configuration.AddConsul("idwms/admin", source => source.ReloadOnChange = true); +var prefix = builder.Environment.EnvironmentName == "Development" ? "dev" : "idwms"; +builder.Configuration.AddConsul($"{prefix}/common", source => source.ReloadOnChange = true); +builder.Configuration.AddConsul($"{prefix}/admin", source => source.ReloadOnChange = true); + +// Fake 框架表前缀(默认 fk_):须在 AddApplication / Migrate 之前生效 +FakeDbProperties.Configure(configuration[FakeDbProperties.TablePrefixConfigurationKey]); + Log.Logger = new LoggerConfiguration() .ReadFrom.Configuration(configuration) .CreateLogger(); @@ -26,4 +32,4 @@ catch (Exception ex) finally { Log.CloseAndFlush(); -} \ No newline at end of file +} diff --git a/src/SimpleAdmin.Api/SimpleAdmin.Api.csproj b/src/SimpleAdmin.Api/SimpleAdmin.Api.csproj index 568c1a4..6b854bb 100644 --- a/src/SimpleAdmin.Api/SimpleAdmin.Api.csproj +++ b/src/SimpleAdmin.Api/SimpleAdmin.Api.csproj @@ -15,15 +15,35 @@ - - - - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/SimpleAdmin.Api/SimpleAdminApiModule.cs b/src/SimpleAdmin.Api/SimpleAdminApiModule.cs index 19f0d1f..19726d7 100644 --- a/src/SimpleAdmin.Api/SimpleAdminApiModule.cs +++ b/src/SimpleAdmin.Api/SimpleAdminApiModule.cs @@ -7,6 +7,7 @@ using Fake.AspNetCore.Auditing; using Fake.AspNetCore.ExceptionHandling; using Fake.AspNetCore.Newtonsoft; using Fake.AspNetCore.Swagger; +using Fake.EventBus.Dashboard; using Fake.EventBus.IntegrationEventLog; using Fake.FeiShu; using Fake.FileManagement.Application; @@ -40,6 +41,8 @@ namespace SimpleAdmin.Api; typeof(FakeObjectStorageTencentCosModule), // 在 RabbitMQ 物理总线之后 Replace IDistributedEventBus → Outbox typeof(FakeEventBusIntegrationEventLogModule), + // 独立 EventBus Dashboard(本地工程引用调试;默认 /eventbus) + typeof(FakeEventBusDashboardModule), typeof(FakeAspNetCoreModule), typeof(FakeSerilogModule) )] @@ -184,6 +187,9 @@ public class SimpleAdminApiModule : FakeModule // 路由 - 必须在认证和授权之前 app.UseRouting(); + // EventBus Dashboard(CAP 风格;也可依赖 IStartupFilter 自动挂载,这里显式保证顺序) + app.UseFakeEventBusDashboard(); + // OpenAPI 验签需读取原始 Body,允许二次读流 app.Use(async (ctx, next) => { @@ -204,16 +210,6 @@ public class SimpleAdminApiModule : FakeModule // 端点映射 app.MapControllers(); - - // FileManagement / Outbox 与业务同库并行(EF) - using (var scope = app.Services.CreateScope()) - { - var fileDb = scope.ServiceProvider.GetRequiredService(); - fileDb.Database.Migrate(); - - var outboxDb = scope.ServiceProvider.GetRequiredService(); - IntegrationEventLogSchema.EnsureTablesAsync(outboxDb).GetAwaiter().GetResult(); - } app.Services.GetRequiredService().Send("Application started"); } diff --git a/src/SimpleAdmin.Api/Storage/IntegrationEventLogSchema.cs b/src/SimpleAdmin.Api/Storage/IntegrationEventLogSchema.cs deleted file mode 100644 index f44e97c..0000000 --- a/src/SimpleAdmin.Api/Storage/IntegrationEventLogSchema.cs +++ /dev/null @@ -1,48 +0,0 @@ -using Fake.EventBus.IntegrationEventLog; -using Microsoft.EntityFrameworkCore; - -namespace SimpleAdmin.Api.Storage; - -/// -/// Outbox/Inbox 与业务同库时 EnsureCreated 无效(库已存在),用 IF NOT EXISTS 建表。 -/// -internal static class IntegrationEventLogSchema -{ - public static async Task EnsureTablesAsync( - IntegrationEventLogContext db, - CancellationToken cancellationToken = default) - { - await db.Database.ExecuteSqlRawAsync( - """ - CREATE TABLE IF NOT EXISTS `OutboxEventLog` ( - `EventId` char(36) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL, - `EventTypeName` varchar(512) NOT NULL, - `State` int NOT NULL, - `TimesSent` int NOT NULL, - `CreationTime` datetime(6) NOT NULL, - `Content` longtext NOT NULL, - `TransactionId` varchar(64) NOT NULL, - `LockExpiresAt` datetime(6) NULL, - PRIMARY KEY (`EventId`), - KEY `IX_OutboxEventLog_State_CreationTime` (`State`, `CreationTime`), - KEY `IX_OutboxEventLog_TransactionId` (`TransactionId`) - ) CHARACTER SET utf8mb4; - """, - cancellationToken); - - await db.Database.ExecuteSqlRawAsync( - """ - CREATE TABLE IF NOT EXISTS `InboxEventLog` ( - `EventId` char(36) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL, - `EventTypeName` varchar(512) NOT NULL, - `State` int NOT NULL, - `ProcessedTime` datetime(6) NOT NULL, - `Content` longtext NOT NULL, - `ErrorMessage` longtext NULL, - PRIMARY KEY (`EventId`), - KEY `IX_InboxEventLog_ProcessedTime` (`ProcessedTime`) - ) CHARACTER SET utf8mb4; - """, - cancellationToken); - } -} diff --git a/src/SimpleAdmin.Api/appsettings.Development.json b/src/SimpleAdmin.Api/appsettings.Development.json deleted file mode 100644 index 03d2137..0000000 --- a/src/SimpleAdmin.Api/appsettings.Development.json +++ /dev/null @@ -1,158 +0,0 @@ -{ - "UseLocalConfigs": false, - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning", - "Microsoft.EntityFrameworkCore": "Information" - } - }, - "ConnectionStrings": { - "Default": "Server=127.0.0.1;Port=3306;Database=oms;Uid=root;Pwd=你的密码;CharSet=utf8mb4;" - }, - "App": { - "Urls": ["http://localhost:5281"], - "CorsOrigins": [ - "http://localhost:5173", - "http://localhost:5281", - "https://oms.nanafa.com", - "http://oms.nanafa.com" - ], - "SendStartupNotification": false - }, - "Jwt": { - "SecretKey": "local-dev-secret-key-change-me", - "Issuer": "SimpleAdmin.Api", - "Audience": "SimpleAdmin.Api", - "ExpiryInMinutes": "480", - "RefreshExpiryInDays": "7", - "ClockSkewMinutes": "5" - }, - "JwtSettings": { - "SecretKey": "local-dev-secret-key-change-me", - "Issuer": "SimpleAdmin.Api", - "Audience": "SimpleAdmin.Api", - "ExpiryInMinutes": "480", - "RefreshExpiryInDays": "7", - "ClockSkewMinutes": "5" - }, - "FeiShuNotice": { - "Webhook": "https://example.com/webhook", - "EnableFeiShuExceptionSubscribe": false - }, - "Redis": { - "Host": "127.0.0.1:6379", - "Password": "", - "Database": 0, - "MaxPoolSize": 50, - "MinPoolSize": 1, - "IdleTimeout": 20000, - "ConnectTimeout": 5000 - }, - "WeChat": { - "Mp": { - "AppId": "wxfffea62e089ee15f", - "Secret": "379f51a89419dc36fbb9167feef6f89a", - "Token": "c6ca74013df823c0e1da0feaaaf8bf66", - "EncodingAesKey": "", - "OAuthRedirectBase": "https://oms.nanafa.com", - "FollowUrl": "" - } - }, - "ObjectStorage": { - "Provider": "Local", - "KeyPrefix": "", - "SignUrlsByDefault": true, - "DefaultSignedUrlExpiresSeconds": 3600, - "DefaultUploadExpiresSeconds": 600, - "Local": { - "BasePath": "wwwroot", - "BaseUrl": "" - }, - "TencentCos": { - "SecretId": "", - "SecretKey": "", - "Region": "ap-guangzhou", - "Bucket": "your-bucket-1250000000", - "BaseUrl": "", - "SignUrls": true, - "UseHttps": true, - "DurationSecond": 600 - } - }, - "FileManagement": { - "SignUrlsByDefault": true, - "DefaultSignedUrlExpiresSeconds": 3600, - "DefaultMaxSizeBytes": 20971520, - "DefaultStorageSource": "default" - }, - "Oms": { - "TrackService": { - "Enabled": true, - "BaseUrl": "http://api.nanafa.com/track", - "AppKey": "W2606001", - "AppSecret": "ziK8UzlQ39m3kdL346XEBg8nljY8os52", - "TimeoutSeconds": 30 - }, - "Itfx": { - "BaseUrl": "http://api.nanafa.com/itfx", - "TimeoutSeconds": 30, - "Customs9610StandardCode": "customs9610Declare", - "Customs9610ManifestStandardCode": "customs9610Manifest", - "Customs9610DeclarationFormStandardCode": "customs9610DeclarationForm" - }, - "PlatformShop": { - "FrontendBaseUrl": "http://localhost:5173", - "Lazada": { - "AppKey": "123631", - "AppSecret": "7vBz2EaD6rIupeGEfwrgkabsTNsXt2ix", - "AuthorizeUrl": "https://auth.lazada.com/oauth/authorize", - "AccessTokenUrl": "https://auth.lazada.com/rest" - }, - "Shopee": { - "PartnerId": 2004112, - "PartnerKey": "2f385d7ea38b087d5d71f7292e06a09c9f19022ca6c3f60ec0110a8214ef7d65", - "HostUrl": "https://openplatform.shopee.cn", - "HostAuthUrl": "https://partner.shopeemobile.com" - }, - "Tiktok": { - "AppKey": "6hc64lc6vl312", - "AppSecret": "5a691a96ee6d844534769bab5c21de1f848fb678", - "HostAuth": "https://auth.tiktok-shops.com", - "HostApi": "https://open-api.tiktokglobalshop.com" - }, - "Temu": { - "AppKey": "4ebbc9190ae410443d65b4c2faca981f", - "AppSecret": "4782d2d827276688bf4758bed55dbdd4bbe79a79", - "HostAuthUrl": "https://openapi-b-us.temu.com/openapi/router" - } - } - }, - "RabbitMQ": { - "Connections": { - "Default": { - "HostName": "127.0.0.1", - "Port": 5672, - "UserName": "oms", - "Password": "oms123" - } - }, - "EventBus": { - "QueueName": "nanafa.oms", - "RetryCount": 5 - } - }, - "OrderBatch": { - "RabbitMq": { - "Enabled": false - } - }, - "IntegrationEventLog": { - "OutboxPublisher": { - "StartupDelay": "00:00:05", - "ScanInterval": "00:00:10", - "BatchSize": 100, - "MaxDegreeOfParallelism": 8 - } - } -} diff --git a/src/SimpleAdmin.Api/appsettings.json b/src/SimpleAdmin.Api/appsettings.json index 860fa46..06ba18d 100644 --- a/src/SimpleAdmin.Api/appsettings.json +++ b/src/SimpleAdmin.Api/appsettings.json @@ -1,7 +1,7 @@ { "UseLocalConfigs": false, "Consul": { - "Address": "https://consul.nanafa.com", - "Token": "97217125-df0b-5c0a-dbfc-8885def5e471" + "Address": "http://test.ideship.com:30850", + "Token": "c0aea902-dca0-ac29-299b-a0d47e5402aa" } }