From 3298d3cb886a418e170f0f6125080c3e538f1a1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=B3=E6=96=87=E7=BF=94?= <878130837@qq.com> Date: Mon, 4 Mar 2024 11:43:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/TrackPush/TrackPushCacheService.cs | 7 ++++--- .../Services/TrackPush/TrackPushService.cs | 14 +++++++++----- src/SJZY.Track.Domain/GlobalConst.cs | 5 ----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs index 468d69a8..62df4046 100644 --- a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs +++ b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs @@ -6,16 +6,17 @@ using Volo.Abp.DependencyInjection; namespace SJZY.Track.Application.Services.TrackPush; -public class TrackPushCacheService:ITrackPushCacheService, ITransientDependency +public class TrackPushCacheService : ITrackPushCacheService, ITransientDependency { private readonly IBasicQuery _trackPushConfigQuery; + private string RedisKey(int customId) => GlobalConst.TrackPushKeyPrefix + customId; public TrackPushCacheService(IBasicQuery trackPushConfigQuery) { _trackPushConfigQuery = trackPushConfigQuery; } - + public async Task IsPushAsync(int customId) { var isPush = @@ -30,7 +31,7 @@ public class TrackPushCacheService:ITrackPushCacheService, ITransientDependency return (bool)isPush; } - + public async Task UpdateAsync(int customId, bool isPush) { await RedisHelper.Client.SetAsync(RedisKey(customId), isPush); diff --git a/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs b/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs index dfdeba35..fa106f23 100644 --- a/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs +++ b/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs @@ -3,6 +3,7 @@ using SJZY.Expand.ABP.Core; using SJZY.Expand.ABP.Core.Localization; using SJZY.Expand.ABP.Core.PublicMethords; using SJZY.Track.Application.Contract.Dtos.TrackPush; +using SJZY.Track.Application.Contract.Services; using SJZY.Track.Application.Localization; using SJZY.Track.Domain.Aggregates.TrackPullAggregate; using SJZY.Track.Domain.Aggregates.TrackPushAggregate; @@ -26,17 +27,20 @@ public class TrackPushService : ApplicationService, ITransientDependency private readonly ITrackPushConfigRepository _trackPushConfigRepository; private readonly ITrackTemplateRepository _trackTemplateRepository; private readonly ITrackPullConfigRepository _trackPullConfigRepository; + private readonly ITrackPushCacheService _trackPushCacheService; public TrackPushService( IStringLocalizer stringLocalizer, ITrackPushConfigRepository trackPushConfigRepository, ITrackTemplateRepository trackTemplateRepository, - ITrackPullConfigRepository trackPullConfigRepository) + ITrackPullConfigRepository trackPullConfigRepository, + ITrackPushCacheService trackPushCacheService) { _stringLocalizer = stringLocalizer; _trackPushConfigRepository = trackPushConfigRepository; _trackTemplateRepository = trackTemplateRepository; _trackPullConfigRepository = trackPullConfigRepository; + _trackPushCacheService = trackPushCacheService; } /// @@ -129,7 +133,7 @@ public class TrackPushService : ApplicationService, ITransientDependency trackPushParamsEntity.PullOrPushConfigId = id; await _trackPullConfigRepository.InsertParamsAsync(trackPushParamsEntity); - if (input.IsAutoPush) await RedisHelper.Client.SAddAsync(GlobalConst.AutoPushRosterRedisKey, input.CustomId); + if (input.IsAutoPush) await _trackPushCacheService.IsPushAsync(input.CustomId); ts.Complete(); } @@ -154,8 +158,8 @@ public class TrackPushService : ApplicationService, ITransientDependency await _trackPushConfigRepository.UpdateAsync(oldTrackPushEntity); await _trackPullConfigRepository.UpdateParamsAsync(oldTrackPushParamsEntity); - await RedisHelper.Client.SRemAsync(GlobalConst.AutoPushRosterRedisKey, oldCustomId); - if (input.IsAutoPush) await RedisHelper.Client.SAddAsync(GlobalConst.AutoPushRosterRedisKey, input.CustomId); + await _trackPushCacheService.UpdateAsync(oldCustomId, false); + if (input.IsAutoPush) await _trackPushCacheService.IsPushAsync(input.CustomId); ts.Complete(); } @@ -173,7 +177,7 @@ public class TrackPushService : ApplicationService, ITransientDependency x.PullOrPushConfigId == input.Id && x.IsPush); await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.TrackPushConfigId == input.Id); - await RedisHelper.Client.SRemAsync(GlobalConst.AutoPushRosterRedisKey, oldTrackPushEntity.CustomId); + await _trackPushCacheService.UpdateAsync(oldTrackPushEntity.CustomId, false); ts.Complete(); } diff --git a/src/SJZY.Track.Domain/GlobalConst.cs b/src/SJZY.Track.Domain/GlobalConst.cs index fcf3d893..91cbeca4 100644 --- a/src/SJZY.Track.Domain/GlobalConst.cs +++ b/src/SJZY.Track.Domain/GlobalConst.cs @@ -21,9 +21,4 @@ public class GlobalConst /// 轨迹要推送的客户redis key前缀 /// public const string TrackPushKeyPrefix = "TrackPush:"; - - /// - /// 自动推送名单RedisKey - /// - public const string AutoPushRosterRedisKey = "AutoPushRoster"; } \ No newline at end of file