From 05573fd12d34859af0a65373b5a4089a636c91ff Mon Sep 17 00:00:00 2001 From: xiaolipro <2357729423@qq.com> Date: Wed, 25 Sep 2024 12:11:11 +0800 Subject: [PATCH] =?UTF-8?q?change=EF=BC=9A=E6=8A=BD=E7=A6=BB=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E9=80=9A=E5=8F=82=E6=95=B0=E9=85=8D=E7=BD=AE=E5=88=B0?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EventHandlers/TrackPushEventHandler.cs | 15 +++-- .../Options/CustomeOptions.cs | 9 --- .../InterfaceRelayParamsConfigOptions.cs | 64 +++++++++++++++++++ .../ForewarningNotifyService.cs | 2 +- .../ProvideServices/TrackPullService.cs | 12 ++-- .../Services/TimerTaskss/TrackPullTask.cs | 13 ++-- .../Services/TrackPull/TrackPullService.cs | 56 ++++++++-------- .../SjzyTrackApplicationModule.cs | 2 + .../Track2InterfaceRelayHttpMessageHandler.cs | 4 +- .../Consts/InterfaceRelayConst.cs | 27 -------- 10 files changed, 122 insertions(+), 82 deletions(-) delete mode 100644 src/SJZY.Track.Application/Options/CustomeOptions.cs create mode 100644 src/SJZY.Track.Application/Options/InterfaceRelayParamsConfigOptions.cs delete mode 100644 src/SJZY.Track.Domain/Consts/InterfaceRelayConst.cs diff --git a/src/SJZY.Track.Application/CAP/EventHandlers/TrackPushEventHandler.cs b/src/SJZY.Track.Application/CAP/EventHandlers/TrackPushEventHandler.cs index 2ce58497..67470ed5 100644 --- a/src/SJZY.Track.Application/CAP/EventHandlers/TrackPushEventHandler.cs +++ b/src/SJZY.Track.Application/CAP/EventHandlers/TrackPushEventHandler.cs @@ -1,4 +1,5 @@ using DotNetCore.CAP; +using Microsoft.Extensions.Options; using Newtonsoft.Json; using SJZY.Expand.ABP.Core.PublicMethords; using SJZY.InterfaceRelay.Application.Contracts; @@ -6,6 +7,7 @@ using SJZY.Track.Application.Contract.Dtos.TrackPush; using SJZY.Track.Application.Contract.Events; using SJZY.Track.Application.Contract.Services; using SJZY.Track.Application.Helpers; +using SJZY.Track.Application.Options; using SJZY.Track.Application.Track2InterfaceRelay; using SJZY.Track.Domain.Aggregates.OrderAggregate; using SJZY.Track.Domain.Aggregates.TrackDetailsAggregate; @@ -19,6 +21,7 @@ namespace SJZY.Track.Application.CAP.EventHandlers; public class TrackPushEventHandler : ITransientDependency, ICapSubscribe { private readonly IHttpClientProxy _httpClientProxy; + private readonly IOptionsMonitor _options; private readonly IOrderRepository _orderRepository; private readonly ITrackDetailsEsRepository _trackDetailsEsRepository; private readonly ITrackPushCacheService _trackPushCacheService; @@ -28,13 +31,15 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe public TrackPushEventHandler(IHttpClientProxy httpClientProxy, IOrderRepository orderRepository, ITrackPushCacheService trackPushCacheService, - ITrackDetailsEsRepository trackDetailsEsRepository, ITrackPushRecordEsRepository trackPushRecordEsRepository) + ITrackDetailsEsRepository trackDetailsEsRepository, ITrackPushRecordEsRepository trackPushRecordEsRepository, + IOptionsMonitor options) { _httpClientProxy = httpClientProxy; _orderRepository = orderRepository; _trackPushCacheService = trackPushCacheService; _trackDetailsEsRepository = trackDetailsEsRepository; _trackPushRecordEsRepository = trackPushRecordEsRepository; + _options = options; } [CapSubscribe(GlobalConst.TrackPushSubscribe, Group = GlobalConst.TrackPushSubscribe)] @@ -155,11 +160,11 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe { var asciiString = Base64Helper.SerializeObject(OptionType.新增.ToString()); var r = await _httpClientProxy.Service.BatchForwardThenPushToQueueAsync( - InterfaceRelayConst.PushTrackInterfaceCode, + _options.CurrentValue.PushTrackInterfaceCode, _pushConfigs.First().ServiceProviderCode, items, GlobalConst.TrackPushCompletedSubscribe, attach: asciiString); - if (r.Code != InterfaceRelayConst.SuccessCode) + if (r.Code != GlobalConst.SuccessCode) { throw new BusinessException(message: $"requestId: {r.RequestId}; {r.Msg}"); } @@ -199,11 +204,11 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe { var asciiString = Base64Helper.SerializeObject(OptionType.修改.ToString()); var r = await _httpClientProxy.Service.BatchForwardThenPushToQueueAsync( - InterfaceRelayConst.TrackUpdateInterfaceCode, + _options.CurrentValue.TrackUpdateInterfaceCode, _pushConfigs.First().ServiceProviderCode, items, GlobalConst.TrackPushCompletedSubscribe, attach: asciiString); - if (r.Code != InterfaceRelayConst.SuccessCode) + if (r.Code != GlobalConst.SuccessCode) { throw new BusinessException(message: $"requestId: {r.RequestId}; {r.Msg}"); } diff --git a/src/SJZY.Track.Application/Options/CustomeOptions.cs b/src/SJZY.Track.Application/Options/CustomeOptions.cs deleted file mode 100644 index bf63a828..00000000 --- a/src/SJZY.Track.Application/Options/CustomeOptions.cs +++ /dev/null @@ -1,9 +0,0 @@ -using SJZY.Expand.ABP.Core; - -namespace SJZY.Track.Application.Options; - -public class CustomeOptions : IOptionAutoInjection -{ - public int Setting1 { get; set; } - public int Setting2 { get; set; } -} diff --git a/src/SJZY.Track.Application/Options/InterfaceRelayParamsConfigOptions.cs b/src/SJZY.Track.Application/Options/InterfaceRelayParamsConfigOptions.cs new file mode 100644 index 00000000..59a6ab9c --- /dev/null +++ b/src/SJZY.Track.Application/Options/InterfaceRelayParamsConfigOptions.cs @@ -0,0 +1,64 @@ +namespace SJZY.Track.Application.Options; + +public class InterfaceRelayParamsConfigOptions +{ + /// + /// 订单路径 + /// + public string OrderPath { get; set; } = null!; + + /// + /// 单号参数名 + /// + public string OrderNoName { get; set; } = null!; + + /// + /// 轨迹明细路径 + /// + public string TrackDetailsPath { get; set; } = null!; + + /// + /// 轨迹代码参数名 + /// + public string TrackContentCodeName { get; set; } + + /// + /// 轨迹状态参数名 + /// + public string TrackStatusName { get; set; } + + /// + /// 轨迹内容参数名 + /// + public string TrackContentName { get; set; } + + /// + /// 轨迹发生地参数名 + /// + public string TrackPlaceName { get; set; } + + /// + /// 轨迹发生时间参数名 + /// + public string TrackTimeName { get; set; } + + /// + /// 轨迹时区参数名 + /// + public string TrackTimeZoneName { get; set; } + + /// + /// 获取轨迹接口代码 + /// + public string GetTrackInterfaceCode { get; set; } + + /// + /// 推送轨迹接口代码 + /// + public string PushTrackInterfaceCode { get; set; } + + /// + /// 更新轨迹接口代码 + /// + public string TrackUpdateInterfaceCode { get; set; } +} diff --git a/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningNotifyService.cs b/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningNotifyService.cs index a92e45c2..2749e8a9 100644 --- a/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningNotifyService.cs +++ b/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningNotifyService.cs @@ -24,7 +24,7 @@ namespace SJZY.Track.Application.Services.ForewarningServices; public class ForewarningNotifyService : IForewarningNotifyService, ITransientDependency { private readonly IForewarningCacheService _forewarningCacheService; - private readonly IOptionsSnapshot _options; + private readonly IOptionsSnapshot _options; // not hot path private readonly IHttpClientProxy _requestSendMessageService; private readonly IWarningQueries _warningQueries; private readonly IWarningRecordEsRepository _warningRecordEsRepository; diff --git a/src/SJZY.Track.Application/Services/ProvideServices/TrackPullService.cs b/src/SJZY.Track.Application/Services/ProvideServices/TrackPullService.cs index 28b082fd..f82db360 100644 --- a/src/SJZY.Track.Application/Services/ProvideServices/TrackPullService.cs +++ b/src/SJZY.Track.Application/Services/ProvideServices/TrackPullService.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Authorization; +using Microsoft.Extensions.Options; using SJZY.Expand.ABP.Core.Logger; using SJZY.Expand.ABP.Core.PublicMethords; using SJZY.InterfaceRelay.Application.Contracts; @@ -6,6 +7,7 @@ using SJZY.Track.Application.Contract.Dtos.ProvideServices; using SJZY.Track.Application.Contract.Dtos.TrackPull; using SJZY.Track.Application.Contract.Services.ProvideServices; using SJZY.Track.Application.Helpers; +using SJZY.Track.Application.Options; using SJZY.Track.Application.Rabbit; using SJZY.Track.Application.Track2InterfaceRelay; using SJZY.Track.Domain.Queries; @@ -21,14 +23,16 @@ namespace SJZY.Track.Application.Services.ProvideServices; public class TrackPullService : ApplicationService, ITrackPullService { private readonly IHttpClientProxy _httpClientProxy; + private readonly IOptionsMonitor _options; private readonly IProvideQueries _provideQueries; - public TrackPullService(IProvideQueries provideQueries, - IHttpClientProxy httpClientProxy) + IHttpClientProxy httpClientProxy, + IOptionsMonitor options) { _provideQueries = provideQueries; _httpClientProxy = httpClientProxy; + _options = options; } /// @@ -74,11 +78,11 @@ public class TrackPullService : ApplicationService, ITrackPullService { // 批量获取轨迹 var res = await _httpClientProxy.Service.BatchForwardThenPushToQueueAsync( - InterfaceRelayConst.GetTrackInterfaceCode, serviceProviderCode, data, + _options.CurrentValue.GetTrackInterfaceCode, serviceProviderCode, data, GlobalConst.TrackRefreshSubscribe, attach); - if (res.Code != InterfaceRelayConst.SuccessCode) + if (res.Code != GlobalConst.SuccessCode) { LogHelper.Error($"刷新轨迹失败:{res.ToJson()}"); } diff --git a/src/SJZY.Track.Application/Services/TimerTaskss/TrackPullTask.cs b/src/SJZY.Track.Application/Services/TimerTaskss/TrackPullTask.cs index 5ddc1b3c..460bd655 100644 --- a/src/SJZY.Track.Application/Services/TimerTaskss/TrackPullTask.cs +++ b/src/SJZY.Track.Application/Services/TimerTaskss/TrackPullTask.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Authorization; +using Microsoft.Extensions.Options; using SJZY.Expand.ABP.Core; using SJZY.Expand.ABP.Core.Logger; using SJZY.Expand.ABP.Core.PublicMethords; @@ -6,6 +7,7 @@ using SJZY.InterfaceRelay.Application.Contracts; using SJZY.Track.Application.Contract.Dtos.TrackPull; using SJZY.Track.Application.Contract.Services; using SJZY.Track.Application.Helpers; +using SJZY.Track.Application.Options; using SJZY.Track.Application.Track2InterfaceRelay; using SJZY.Track.Domain.Dtos.TrackPull; using SJZY.Track.Domain.Queries; @@ -61,7 +63,9 @@ public class TrackPullTask : ApplicationService, ISingletonDependency var provideQueries = serviceScope.ServiceProvider.GetRequiredService(); var httpClientProxy = serviceScope.ServiceProvider .GetRequiredService>(); - await DoRefreshAsync(config, provideQueries, httpClientProxy); + var interfaceOptions = serviceScope.ServiceProvider + .GetRequiredService>(); + await DoRefreshAsync(config, provideQueries, httpClientProxy, interfaceOptions.Value); } catch (Exception e) { @@ -72,7 +76,8 @@ public class TrackPullTask : ApplicationService, ISingletonDependency } private static async Task DoRefreshAsync(TrackPullConfigVo config, IProvideQueries provideQueries, - IHttpClientProxy httpClientProxy) + IHttpClientProxy httpClientProxy, + InterfaceRelayParamsConfigOptions interfaceOptionsValue) { using (Track2InterfaceRelaySubSystemContext.Use( new Track2InterfaceRelaySubSystemContext(config.SubSystemCode))) @@ -93,10 +98,10 @@ public class TrackPullTask : ApplicationService, ISingletonDependency var attach = Base64Helper.SerializeObject(new TrackRefreshAttach(config.ServiceProviderCode, config.SubSystemId, group.Key)); var res = await httpClientProxy.Service.BatchForwardThenPushToQueueAsync( - InterfaceRelayConst.GetTrackInterfaceCode, serviceProviderCode, data, + interfaceOptionsValue.GetTrackInterfaceCode, serviceProviderCode, data, GlobalConst.TrackRefreshSubscribe, attach); - if (res.Code != InterfaceRelayConst.SuccessCode) + if (res.Code != GlobalConst.SuccessCode) { LogHelper.Error($"刷新轨迹失败:{res.ToJson()}"); } diff --git a/src/SJZY.Track.Application/Services/TrackPull/TrackPullService.cs b/src/SJZY.Track.Application/Services/TrackPull/TrackPullService.cs index 468a61a6..48fe3dbf 100644 --- a/src/SJZY.Track.Application/Services/TrackPull/TrackPullService.cs +++ b/src/SJZY.Track.Application/Services/TrackPull/TrackPullService.cs @@ -1,11 +1,12 @@ using System.Linq.Expressions; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Options; using SJZY.Expand.ABP.Core.Localization; using SJZY.Expand.ABP.Core.PublicMethords; using SJZY.Track.Application.Contract.Dtos.TrackPull; using SJZY.Track.Application.Contract.Services; using SJZY.Track.Application.Localization; +using SJZY.Track.Application.Options; using SJZY.Track.Domain.Aggregates.TrackPullAggregate; using SJZY.Track.Domain.Dtos.Common; using SJZY.Track.Domain.Dtos.TrackPull; @@ -20,6 +21,7 @@ namespace SJZY.Track.Application.Services.TrackPull; [Route("/Track/PullConfig")] public class TrackPullService : ApplicationService { + private readonly IOptionsMonitor _options; private readonly IStringLocalizer _stringLocalizer; private readonly ITrackPullCacheService _trackPullCacheService; private readonly ITrackPullConfigRepository _trackPullConfigRepository; @@ -27,11 +29,12 @@ public class TrackPullService : ApplicationService public TrackPullService( IStringLocalizer stringLocalizer, ITrackPullConfigRepository trackPullConfigRepository, - ITrackPullCacheService trackPullCacheService) + ITrackPullCacheService trackPullCacheService, IOptionsMonitor options) { _stringLocalizer = stringLocalizer; _trackPullConfigRepository = trackPullConfigRepository; _trackPullCacheService = trackPullCacheService; + _options = options; } /// @@ -83,11 +86,9 @@ public class TrackPullService : ApplicationService /// 轨迹拉取配置编辑 /// /// - /// /// [HttpPost("Edit")] - public async Task EditAsync([FromBody] EditTrackPullConfigInput input, - [FromServices] IConfiguration configuration) + public async Task EditAsync([FromBody] EditTrackPullConfigInput input) { if (input.PullInterval < 60) input.PullInterval = 60; @@ -109,23 +110,21 @@ public class TrackPullService : ApplicationService if (input.ParseMethod == (int) ParseMethod.InterfaceRelay) { - var paramsConfig = configuration.GetSection("InterfaceRelayParamsConfig") - .Get>(); + var paramsConfig = _options.CurrentValue; if (paramsConfig == null) { throw new BusinessException(message: "未找到接口通参数配置,联系管理员添加"); } - trackPullEntity.OrderPath = paramsConfig[nameof(trackPullEntity.OrderPath)]; - trackPullEntity.OrderNoName = paramsConfig[nameof(trackPullEntity.OrderNoName)]; - trackPullEntity.TrackDetailsPath = paramsConfig[nameof(trackPullEntity.TrackDetailsPath)]; - trackPullEntity.TrackContentCodeName = - paramsConfig[nameof(trackPullEntity.TrackContentCodeName)]; - trackPullEntity.TrackStatusName = paramsConfig[nameof(trackPullEntity.TrackStatusName)]; - trackPullEntity.TrackContentName = paramsConfig[nameof(trackPullEntity.TrackContentName)]; - trackPullEntity.TrackPlaceName = paramsConfig[nameof(trackPullEntity.TrackPlaceName)]; - trackPullEntity.TrackTimeName = paramsConfig[nameof(trackPullEntity.TrackTimeName)]; - trackPullEntity.TrackTimeZoneName = paramsConfig[nameof(trackPullEntity.TrackTimeZoneName)]; + trackPullEntity.OrderPath = paramsConfig.OrderPath; + trackPullEntity.OrderNoName = paramsConfig.OrderNoName; + trackPullEntity.TrackDetailsPath = paramsConfig.TrackDetailsPath; + trackPullEntity.TrackContentCodeName = paramsConfig.TrackContentCodeName; + trackPullEntity.TrackStatusName = paramsConfig.TrackStatusName; + trackPullEntity.TrackContentName = paramsConfig.TrackContentName; + trackPullEntity.TrackPlaceName = paramsConfig.TrackPlaceName; + trackPullEntity.TrackTimeName = paramsConfig.TrackTimeName; + trackPullEntity.TrackTimeZoneName = paramsConfig.TrackTimeZoneName; } var id = await _trackPullConfigRepository.InsertReturnIdentityAsync(trackPullEntity); @@ -142,24 +141,21 @@ public class TrackPullService : ApplicationService ObjectMapper.Map(input, oldTrackPullEntity); if (input.ParseMethod == (int) ParseMethod.InterfaceRelay) { - var paramsConfig = configuration.GetSection("InterfaceRelayParamsConfig") - .Get>(); + var paramsConfig = _options.CurrentValue; if (paramsConfig == null) { throw new BusinessException(message: "未找到接口通参数配置,联系管理员添加"); } - oldTrackPullEntity.OrderPath = paramsConfig[nameof(oldTrackPullEntity.OrderPath)]; - oldTrackPullEntity.OrderNoName = paramsConfig[nameof(oldTrackPullEntity.OrderNoName)]; - oldTrackPullEntity.TrackDetailsPath = paramsConfig[nameof(oldTrackPullEntity.TrackDetailsPath)]; - oldTrackPullEntity.TrackContentCodeName = - paramsConfig[nameof(oldTrackPullEntity.TrackContentCodeName)]; - oldTrackPullEntity.TrackStatusName = paramsConfig[nameof(oldTrackPullEntity.TrackStatusName)]; - oldTrackPullEntity.TrackContentName = paramsConfig[nameof(oldTrackPullEntity.TrackContentName)]; - oldTrackPullEntity.TrackPlaceName = paramsConfig[nameof(oldTrackPullEntity.TrackPlaceName)]; - oldTrackPullEntity.TrackTimeName = paramsConfig[nameof(oldTrackPullEntity.TrackTimeName)]; - oldTrackPullEntity.TrackTimeZoneName = - paramsConfig[nameof(oldTrackPullEntity.TrackTimeZoneName)]; + oldTrackPullEntity.OrderPath = paramsConfig.OrderPath; + oldTrackPullEntity.OrderNoName = paramsConfig.OrderNoName; + oldTrackPullEntity.TrackDetailsPath = paramsConfig.TrackDetailsPath; + oldTrackPullEntity.TrackContentCodeName = paramsConfig.TrackContentCodeName; + oldTrackPullEntity.TrackStatusName = paramsConfig.TrackStatusName; + oldTrackPullEntity.TrackContentName = paramsConfig.TrackContentName; + oldTrackPullEntity.TrackPlaceName = paramsConfig.TrackPlaceName; + oldTrackPullEntity.TrackTimeName = paramsConfig.TrackTimeName; + oldTrackPullEntity.TrackTimeZoneName = paramsConfig.TrackTimeZoneName; } await _trackPullConfigRepository.UpdateAsync(oldTrackPullEntity); diff --git a/src/SJZY.Track.Application/SjzyTrackApplicationModule.cs b/src/SJZY.Track.Application/SjzyTrackApplicationModule.cs index 61dd5aad..bf5d1ede 100644 --- a/src/SJZY.Track.Application/SjzyTrackApplicationModule.cs +++ b/src/SJZY.Track.Application/SjzyTrackApplicationModule.cs @@ -152,6 +152,8 @@ public class SjzyTrackApplicationModule : AbpModule }, typeof(SjzyTrackApplicationModule).Assembly); context.Services.Configure(configuration.GetSection("TrackApp")); + context.Services.Configure( + configuration.GetSection("InterfaceRelayParamsConfig")); } public override void PreConfigureServices(ServiceConfigurationContext context) diff --git a/src/SJZY.Track.Application/Track2InterfaceRelay/Track2InterfaceRelayHttpMessageHandler.cs b/src/SJZY.Track.Application/Track2InterfaceRelay/Track2InterfaceRelayHttpMessageHandler.cs index 7f598d4e..dc807700 100644 --- a/src/SJZY.Track.Application/Track2InterfaceRelay/Track2InterfaceRelayHttpMessageHandler.cs +++ b/src/SJZY.Track.Application/Track2InterfaceRelay/Track2InterfaceRelayHttpMessageHandler.cs @@ -8,9 +8,9 @@ public class Track2InterfaceRelayHttpMessageHandler : DelegatingHandler, ITransi { private readonly Track2InterfaceRelayOptions _options; - public Track2InterfaceRelayHttpMessageHandler(IOptionsSnapshot options) + public Track2InterfaceRelayHttpMessageHandler(IOptionsMonitor options) { - _options = options.Value; + _options = options.CurrentValue; } protected override async Task SendAsync(HttpRequestMessage request, diff --git a/src/SJZY.Track.Domain/Consts/InterfaceRelayConst.cs b/src/SJZY.Track.Domain/Consts/InterfaceRelayConst.cs deleted file mode 100644 index 3cd55b3d..00000000 --- a/src/SJZY.Track.Domain/Consts/InterfaceRelayConst.cs +++ /dev/null @@ -1,27 +0,0 @@ -namespace SJZY.Track.Domain.Consts; - -/// -/// 接口通常量 -/// -public class InterfaceRelayConst -{ - /// - /// 接口通成功代码 - /// - public const string SuccessCode = GlobalConst.SuccessCode; - - /// - /// 获取轨迹接口代码 - /// - public const string GetTrackInterfaceCode = "TEST"; - - /// - /// 推送轨迹接口代码 - /// - public const string PushTrackInterfaceCode = "A024"; - - /// - /// 更新轨迹接口代码 - /// - public const string TrackUpdateInterfaceCode = "A040"; -}