From b10f1cedfdf0ea5dc619dd44a0cba8a621fa041e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=B3=E6=96=87=E7=BF=94?= <878130837@qq.com> Date: Fri, 15 Mar 2024 17:06:46 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TrackPushContentConfigDto.cs | 13 +++++++ .../Services/ITrackPushCacheService.cs | 2 +- .../TrackPush/TrackPushCacheService.cs | 39 ++++++++++++------- .../Services/TrackPush/TrackPushService.cs | 2 + 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/TrackPushContentConfigDto.cs b/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/TrackPushContentConfigDto.cs index ed2e02d0..578c298d 100644 --- a/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/TrackPushContentConfigDto.cs +++ b/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/TrackPushContentConfigDto.cs @@ -1,5 +1,18 @@ namespace SJZY.Track.Application.Contract.Dtos.ProvideServices; +public class TrackPushConfigDto +{ + /// + /// 是否自动推送 + /// + public bool IsAutoPush { get; set; } + + /// + /// 轨迹推送内容配置 + /// + public List ContentConfigs { get; set; } +} + public class TrackPushContentConfigDto { /// diff --git a/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs b/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs index cc7fec74..77c35661 100644 --- a/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs +++ b/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs @@ -29,5 +29,5 @@ public interface ITrackPushCacheService /// 子系统id /// 客户id /// - Task> SetPushContentConfigsAsync(int? id = null, int? subSystemId = null, int? customId = null); + Task SetPushContentConfigsAsync(int? id = null, int? subSystemId = null, int? customId = null); } \ No newline at end of file diff --git a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs index b5988ab3..c0eca26e 100644 --- a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs +++ b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs @@ -21,40 +21,39 @@ public class TrackPushCacheService : ApplicationService, ITrackPushCacheService, [NonAction] public async Task> GetPushContentConfigsAsync(int subSystemId, int customId) { - var data = await RedisHelper.Client.GetAsync>(TrackPushContentKey(subSystemId, customId)); + var data = await GetPushConfigAsync(subSystemId, customId); - data ??= await SetPushContentConfigsAsync(subSystemId: subSystemId, customId: customId); - - return data; + return data.ContentConfigs; } [NonAction] public async Task InferNextPushContentOrNullAsync(int subSystemId, int customId, int? trackContentId) { - var data = await GetPushContentConfigsAsync(subSystemId, customId); + var data = await GetPushConfigAsync(subSystemId, customId); + if (!data.IsAutoPush) return null; if (trackContentId.HasValue) { - if (data.Count > 1 && data.Any(x => x.TrackContentId == trackContentId)) + if (data.ContentConfigs.Count > 1 && data.ContentConfigs.Any(x => x.TrackContentId == trackContentId)) { - int index = data.FindIndex(x => x.TrackContentId == trackContentId); - int nextIndex = (index + 1) % data.Count; // 计算下一个索引,处理最后一个元素的情况 + int index = data.ContentConfigs.FindIndex(x => x.TrackContentId == trackContentId); + int nextIndex = (index + 1) % data.ContentConfigs.Count; // 计算下一个索引,处理最后一个元素的情况 - return data[nextIndex]; + return data.ContentConfigs[nextIndex]; } else return null; } - else return data.FirstOrDefault(); + else return data.ContentConfigs.FirstOrDefault(); } [NonAction] - public async Task> SetPushContentConfigsAsync(int? id = null, int? subSystemId = null, int? customId = null) + public async Task SetPushContentConfigsAsync(int? id = null, int? subSystemId = null, int? customId = null) { - var data = new List(); + var data = new TrackPushConfigDto { ContentConfigs = [] }; + Expression> exp = x => true; if (id.HasValue) exp = x => x.Id == id; - else if (subSystemId.HasValue && customId.HasValue) - exp = x => x.SubSystemId == subSystemId && x.CustomId == customId; + else if (subSystemId.HasValue && customId.HasValue) exp = x => x.SubSystemId == subSystemId && x.CustomId == customId; var trackPushConfigEntity = await _trackPushConfigRepository.GetFirstAsync(exp); if (trackPushConfigEntity == null) return data; @@ -64,10 +63,20 @@ public class TrackPushCacheService : ApplicationService, ITrackPushCacheService, trackPushContentList = trackPushContentList.OrderBy(x => x.Sort).ToList(); - data = ObjectMapper.Map, List>(trackPushContentList); + data.IsAutoPush = trackPushConfigEntity.IsAutoPush; + data.ContentConfigs = ObjectMapper.Map, List>(trackPushContentList); await RedisHelper.Client.SetAsync(TrackPushContentKey(trackPushConfigEntity.SubSystemId, trackPushConfigEntity.CustomId), data, (int)TimeSpan.FromDays(1).TotalSeconds); return data; } + + private async Task GetPushConfigAsync(int subSystemId, int customId) + { + var data = await RedisHelper.Client.GetAsync(TrackPushContentKey(subSystemId, customId)); + + data ??= await SetPushContentConfigsAsync(subSystemId: subSystemId, customId: customId); + + return data; + } } \ No newline at end of file diff --git a/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs b/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs index e7498c2c..712bbc3c 100644 --- a/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs +++ b/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs @@ -142,6 +142,8 @@ public class TrackPushService : ApplicationService ts.Complete(); } + + if (input.IsAutoPush!.Value) await _trackPushCacheService.SetPushContentConfigsAsync(input.Id); } break; From 2845acce761db12249e993c9964e4dd001c2844f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=B3=E6=96=87=E7=BF=94?= <878130837@qq.com> Date: Fri, 15 Mar 2024 17:10:11 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/TrackPush/TrackPushCacheService.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs index eb0f3910..0b8f4378 100644 --- a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs +++ b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs @@ -25,10 +25,13 @@ public class TrackPushCacheService : ApplicationService, ITrackPushCacheService, return data.ContentConfigs; } - - public Task GetPushContentConfigAsync(int subSystemId, int customId, int trackContentId) + + [NonAction] + public async Task GetPushContentConfigAsync(int subSystemId, int customId, int trackContentId) { - throw new NotImplementedException(); + var data = await GetPushContentConfigsAsync(subSystemId, customId); + + return data.Single(x => x.TrackContentId == trackContentId); } [NonAction] From b484a53711c37fd2d3920fc1d9ddc294af50141a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=B3=E6=96=87=E7=BF=94?= <878130837@qq.com> Date: Fri, 15 Mar 2024 17:12:24 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/TrackPull/TrackPullCacheService.cs | 3 +-- .../Services/TrackPush/TrackPushCacheService.cs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/SJZY.Track.Application/Services/TrackPull/TrackPullCacheService.cs b/src/SJZY.Track.Application/Services/TrackPull/TrackPullCacheService.cs index 1a57ea08..b5418f24 100644 --- a/src/SJZY.Track.Application/Services/TrackPull/TrackPullCacheService.cs +++ b/src/SJZY.Track.Application/Services/TrackPull/TrackPullCacheService.cs @@ -73,8 +73,7 @@ public class TrackPullCacheService : ApplicationService, ITrackPullCacheService, trackPullContentList); await RedisHelper.Client.SetAsync( - TrackPullContentKey(trackPullConfigEntity.SubSystemId, trackPullConfigEntity.ServiceProviderId), data, - (int)TimeSpan.FromDays(1).TotalSeconds); + TrackPullContentKey(trackPullConfigEntity.SubSystemId, trackPullConfigEntity.ServiceProviderId), data); return data; } diff --git a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs index 0b8f4378..30766856 100644 --- a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs +++ b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs @@ -74,7 +74,7 @@ public class TrackPushCacheService : ApplicationService, ITrackPushCacheService, data.IsAutoPush = trackPushConfigEntity.IsAutoPush; data.ContentConfigs = ObjectMapper.Map, List>(trackPushContentList); - await RedisHelper.Client.SetAsync(TrackPushContentKey(trackPushConfigEntity.SubSystemId, trackPushConfigEntity.CustomId), data, (int)TimeSpan.FromDays(1).TotalSeconds); + await RedisHelper.Client.SetAsync(TrackPushContentKey(trackPushConfigEntity.SubSystemId, trackPushConfigEntity.CustomId), data); return data; }