From 1d80a8de4eb58ed77808373a2110ae13412cc600 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 16:09:27 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8E=A8=E9=80=81=E9=85=8D?=
=?UTF-8?q?=E7=BD=AE=E7=BC=93=E5=AD=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Services/ITrackPushCacheService.cs | 17 +-
.../AutoMapper/TrackPushAutoMapperProfile.cs | 3 +
.../TrackPull/TrackPullCacheService.cs | 6 +-
.../Services/TrackPull/TrackPullService.cs | 11 +-
.../TrackPush/TrackPushCacheService.cs | 71 ++++++--
.../Services/TrackPush/TrackPushService.cs | 160 +++++++++---------
6 files changed, 153 insertions(+), 115 deletions(-)
diff --git a/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs b/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs
index acc00b72..cc7fec74 100644
--- a/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs
+++ b/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs
@@ -4,13 +4,6 @@ namespace SJZY.Track.Application.Contract.Services;
public interface ITrackPushCacheService
{
- ///
- /// 判断客户是否需要推送
- ///
- ///
- ///
- Task IsPushAsync(int customId);
-
///
/// 获取服务商拉取配置
///
@@ -30,9 +23,11 @@ public interface ITrackPushCacheService
int? trackContentId);
///
- /// 更新缓存
+ /// 设置推送配置缓存
///
- ///
- ///
- Task UpdateAsync(int customId, bool isPush);
+ ///
+ /// 子系统id
+ /// 客户id
+ ///
+ Task> SetPushContentConfigsAsync(int? id = null, int? subSystemId = null, int? customId = null);
}
\ No newline at end of file
diff --git a/src/SJZY.Track.Application/AutoMapper/TrackPushAutoMapperProfile.cs b/src/SJZY.Track.Application/AutoMapper/TrackPushAutoMapperProfile.cs
index eed8b90b..6be69d46 100644
--- a/src/SJZY.Track.Application/AutoMapper/TrackPushAutoMapperProfile.cs
+++ b/src/SJZY.Track.Application/AutoMapper/TrackPushAutoMapperProfile.cs
@@ -1,4 +1,5 @@
using AutoMapper;
+using SJZY.Track.Application.Contract.Dtos.ProvideServices;
using SJZY.Track.Application.Contract.Dtos.TrackPush;
using SJZY.Track.Domain.Aggregates.TrackPullAggregate;
using SJZY.Track.Domain.Aggregates.TrackPushAggregate;
@@ -14,5 +15,7 @@ public class TrackPushAutoMapperProfile : Profile
CreateMap(MemberList.None).Ignore(dest => dest.Id)
.ForMember(dest => dest.IsPush, opt => opt.MapFrom(source => true));
CreateMap(MemberList.None);
+ CreateMap(MemberList.None)
+ .ForMember(dest => dest.OrderType, opt => opt.MapFrom(source => source.OrderNoType));
}
}
\ No newline at end of file
diff --git a/src/SJZY.Track.Application/Services/TrackPull/TrackPullCacheService.cs b/src/SJZY.Track.Application/Services/TrackPull/TrackPullCacheService.cs
index 26541474..1a57ea08 100644
--- a/src/SJZY.Track.Application/Services/TrackPull/TrackPullCacheService.cs
+++ b/src/SJZY.Track.Application/Services/TrackPull/TrackPullCacheService.cs
@@ -4,10 +4,11 @@ using SJZY.Track.Application.Contract.Dtos.TrackPull;
using SJZY.Track.Application.Contract.Services;
using SJZY.Track.Domain.Aggregates.TrackPullAggregate;
using SJZY.Track.Domain.Dtos.TrackPull;
+using Volo.Abp.DependencyInjection;
namespace SJZY.Track.Application.Services.TrackPull;
-public class TrackPullCacheService : ApplicationService, ITrackPullCacheService
+public class TrackPullCacheService : ApplicationService, ITrackPullCacheService, ITransientDependency
{
private readonly ITrackPullConfigRepository _trackPullConfigRepository;
@@ -59,6 +60,7 @@ public class TrackPullCacheService : ApplicationService, ITrackPullCacheService
var trackPullConfigEntity = await _trackPullConfigRepository.GetFirstAsync(exp);
if (trackPullConfigEntity == null) return data;
+
var trackPullConfigDetail = await _trackPullConfigRepository.GetDetailAsync(trackPullConfigEntity.Id);
if (trackPullConfigDetail is null) return data;
var trackPullContentList = await _trackPullConfigRepository.GetContentListCacheAsync(trackPullConfigEntity.Id);
@@ -72,7 +74,7 @@ public class TrackPullCacheService : ApplicationService, ITrackPullCacheService
await RedisHelper.Client.SetAsync(
TrackPullContentKey(trackPullConfigEntity.SubSystemId, trackPullConfigEntity.ServiceProviderId), data,
- 86400);
+ (int)TimeSpan.FromDays(1).TotalSeconds);
return data;
}
diff --git a/src/SJZY.Track.Application/Services/TrackPull/TrackPullService.cs b/src/SJZY.Track.Application/Services/TrackPull/TrackPullService.cs
index 61f2cb2d..daba134c 100644
--- a/src/SJZY.Track.Application/Services/TrackPull/TrackPullService.cs
+++ b/src/SJZY.Track.Application/Services/TrackPull/TrackPullService.cs
@@ -212,16 +212,21 @@ public class TrackPullService : ApplicationService, ITransientDependency
ObjectMapper.Map(input, oldTrackPullContentEntity);
await _trackPullConfigRepository.UpdateContentAsync(oldTrackPullContentEntity);
- await _trackPullCacheService.SetPullConfigAsync(input.TrackPullConfigId);
+ await _trackPullCacheService.SetPullConfigAsync(oldTrackPullContentEntity.TrackPullConfigId);
break;
}
case OptionTypeNoNull.删除:
+ {
+ var oldTrackPullContentEntity = await _trackPullConfigRepository.GetContentByIdAsync(input.Id!.Value) ??
+ throw new BusinessException(message: _stringLocalizer["NotFindData"]);
- await _trackPullConfigRepository.SoftDeleteContentAsync(x => x.Id == input.Id);
+ await _trackPullConfigRepository.SoftDeleteContentAsync(x => x.Id == input.Id);
+ await _trackPullCacheService.SetPullConfigAsync(oldTrackPullContentEntity.TrackPullConfigId);
- break;
+ break;
+ }
default:
throw new BusinessException(message: _stringLocalizer[SjzyBasicLocalization.Validation_IsInEnum,
diff --git a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs
index eb11ae2c..c8581b7c 100644
--- a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs
+++ b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs
@@ -1,41 +1,78 @@
-using SJZY.Expand.ABP.Core;
+using Microsoft.Extensions.DependencyInjection;
+using Nest;
+using SJZY.Expand.ABP.Core;
using SJZY.Track.Application.Contract.Dtos.ProvideServices;
using SJZY.Track.Application.Contract.Services;
+using SJZY.Track.Domain.Aggregates.TrackPullAggregate;
using SJZY.Track.Domain.Aggregates.TrackPushAggregate;
using SJZY.Track.Domain.Queries;
+using SJZY.UserCenter.SharedModel.Dtos.PHP.User;
+using System.Linq.Expressions;
using Volo.Abp.DependencyInjection;
namespace SJZY.Track.Application.Services.TrackPush;
-public class TrackPushCacheService : ITrackPushCacheService, ITransientDependency
+public class TrackPushCacheService : ApplicationService, ITrackPushCacheService, ITransientDependency
{
- private readonly IBasicQuery _trackPushConfigQuery;
+ private readonly ITrackPushConfigRepository _trackPushConfigRepository;
- private string RedisKey(int customId) => $"{GlobalConst.TrackPushKeyPrefix}:{customId}";
+ private string TrackPushContentKey(int subSystemId, int customId) => $"{GlobalConst.TrackPushKeyPrefix}:{subSystemId}:{customId}";
- public TrackPushCacheService(IBasicQuery trackPushConfigQuery)
+ public TrackPushCacheService(ITrackPushConfigRepository trackPushConfigRepository)
{
- _trackPushConfigQuery = trackPushConfigQuery;
+ _trackPushConfigRepository = trackPushConfigRepository;
}
- public Task IsPushAsync(int customId)
+ [NonAction]
+ public async Task> GetPushContentConfigsAsync(int subSystemId, int customId)
{
- throw new NotImplementedException();
+ var data = await RedisHelper.Client.GetAsync>(TrackPushContentKey(subSystemId, customId));
+
+ data ??= await SetPushContentConfigsAsync(subSystemId: subSystemId, customId: customId);
+
+ return data;
}
- public Task> GetPushContentConfigsAsync(int subSystemId, int customId)
+ [NonAction]
+ public async Task InferNextPushContentOrNullAsync(int subSystemId, int customId, int? trackContentId)
{
- throw new NotImplementedException();
+ var data = await GetPushContentConfigsAsync(subSystemId, customId);
+
+ if (trackContentId.HasValue)
+ {
+ if (data.Count > 1 && data.Any(x => x.TrackContentId == trackContentId))
+ {
+ int index = data.FindIndex(x => x.TrackContentId == trackContentId);
+ int nextIndex = (index + 1) % data.Count; // 计算下一个索引,处理最后一个元素的情况
+
+ return data[nextIndex];
+ }
+ else return null;
+ }
+ else return data.FirstOrDefault();
}
- public Task InferNextPushContentOrNullAsync(int subSystemId, int customId,
- int? trackContentId)
+ [NonAction]
+ public async Task> SetPushContentConfigsAsync(int? id = null, int? subSystemId = null, int? customId = null)
{
- throw new NotImplementedException();
- }
+ var data = new List();
+ 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;
- public async Task UpdateAsync(int customId, bool isPush)
- {
- await RedisHelper.Client.SetAsync(RedisKey(customId), isPush);
+ var trackPushConfigEntity = await _trackPushConfigRepository.GetFirstAsync(exp);
+ if (trackPushConfigEntity == null) return data;
+
+ var trackPushContentList = await _trackPushConfigRepository.GetContentListAsync(x => x.TrackPushConfigId == trackPushConfigEntity.Id);
+ if (trackPushContentList.Count == 0) return data;
+
+ trackPushContentList = trackPushContentList.OrderBy(x => x.Sort).ToList();
+
+ data = ObjectMapper.Map, List>(trackPushContentList);
+
+ await RedisHelper.Client.SetAsync(TrackPushContentKey(trackPushConfigEntity.SubSystemId, trackPushConfigEntity.CustomId), data, (int)TimeSpan.FromDays(1).TotalSeconds);
+
+ 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 34903f75..e2771645 100644
--- a/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs
+++ b/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs
@@ -94,8 +94,7 @@ public class TrackPushService : ApplicationService
if (input.Options != OptionTypeNoNull.删除)
{
Expression> isAnyExp = x =>
- x.SubSystemId == input.SubSystemId && x.CustomId == input.CustomId &&
- x.ServiceProviderId == input.ServiceProviderId;
+ x.SubSystemId == input.SubSystemId && x.CustomId == input.CustomId;
if (input.Options == OptionTypeNoNull.修改) isAnyExp = isAnyExp.And(x => x.Id != input.Id);
if (await _trackPushConfigRepository.IsAnyAsync(isAnyExp))
@@ -105,68 +104,62 @@ public class TrackPushService : ApplicationService
switch (input.Options)
{
case OptionTypeNoNull.新增:
- {
- var trackPushEntity = ObjectMapper.Map(input);
- var trackPushParamsEntity =
- ObjectMapper.Map(input);
-
- using (var ts = TransactionScopeHelper.Create())
{
- int id = await _trackPushConfigRepository.InsertReturnIdentityAsync(trackPushEntity);
+ var trackPushEntity = ObjectMapper.Map(input);
+ var trackPushParamsEntity =
+ ObjectMapper.Map(input);
- trackPushParamsEntity.PullOrPushConfigId = id;
- await _trackPullConfigRepository.InsertParamsAsync(trackPushParamsEntity);
+ using (var ts = TransactionScopeHelper.Create())
+ {
+ int id = await _trackPushConfigRepository.InsertReturnIdentityAsync(trackPushEntity);
- if (input.IsAutoPush!.Value) await _trackPushCacheService.IsPushAsync(input.CustomId!.Value);
+ trackPushParamsEntity.PullOrPushConfigId = id;
+ await _trackPullConfigRepository.InsertParamsAsync(trackPushParamsEntity);
- ts.Complete();
+ ts.Complete();
+ }
}
- }
break;
case OptionTypeNoNull.修改:
- {
- var oldTrackPushEntity = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == input.Id) ??
- throw new BusinessException(message: _stringLocalizer["NotFindData"]);
-
- int oldCustomId = oldTrackPushEntity.CustomId;
-
- var oldTrackPushParamsEntity =
- await _trackPullConfigRepository.GetParamsSingleAsync(x =>
- x.PullOrPushConfigId == input.Id && x.IsPush);
-
- ObjectMapper.Map(input, oldTrackPushEntity);
- ObjectMapper.Map(input, oldTrackPushParamsEntity);
-
- using (var ts = TransactionScopeHelper.Create())
{
- await _trackPushConfigRepository.UpdateAsync(oldTrackPushEntity);
- await _trackPullConfigRepository.UpdateParamsAsync(oldTrackPushParamsEntity);
+ var oldTrackPushEntity = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == input.Id) ??
+ throw new BusinessException(message: _stringLocalizer["NotFindData"]);
- await _trackPushCacheService.UpdateAsync(oldCustomId, false);
- if (input.IsAutoPush!.Value) await _trackPushCacheService.IsPushAsync(input.CustomId!.Value);
+ int oldCustomId = oldTrackPushEntity.CustomId;
- ts.Complete();
+ var oldTrackPushParamsEntity =
+ await _trackPullConfigRepository.GetParamsSingleAsync(x =>
+ x.PullOrPushConfigId == input.Id && x.IsPush);
+
+ ObjectMapper.Map(input, oldTrackPushEntity);
+ ObjectMapper.Map(input, oldTrackPushParamsEntity);
+
+ using (var ts = TransactionScopeHelper.Create())
+ {
+ await _trackPushConfigRepository.UpdateAsync(oldTrackPushEntity);
+ await _trackPullConfigRepository.UpdateParamsAsync(oldTrackPushParamsEntity);
+
+ ts.Complete();
+ }
}
- }
break;
case OptionTypeNoNull.删除:
- {
- var oldTrackPushEntity = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == input.Id) ??
- throw new BusinessException(message: _stringLocalizer["NotFindData"]);
-
- using (var ts = TransactionScopeHelper.Create())
{
- await _trackPushConfigRepository.SoftDeleteAsync(x => x.Id == input.Id);
- await _trackPullConfigRepository.SoftDeleteParamsAsync(x =>
- x.PullOrPushConfigId == input.Id && x.IsPush);
- await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.TrackPushConfigId == input.Id);
- await _trackPushCacheService.UpdateAsync(oldTrackPushEntity.CustomId, false);
+ var oldTrackPushEntity = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == input.Id) ??
+ throw new BusinessException(message: _stringLocalizer["NotFindData"]);
- ts.Complete();
+ using (var ts = TransactionScopeHelper.Create())
+ {
+ await _trackPushConfigRepository.SoftDeleteAsync(x => x.Id == input.Id);
+ await _trackPullConfigRepository.SoftDeleteParamsAsync(x =>
+ x.PullOrPushConfigId == input.Id && x.IsPush);
+ await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.TrackPushConfigId == input.Id);
+
+ ts.Complete();
+ }
}
- }
break;
default:
@@ -215,47 +208,50 @@ public class TrackPushService : ApplicationService
switch (input.Options)
{
case OptionTypeNoNull.新增:
- {
- int maxSort = await _trackPushConfigRepository.ContentMaxAsync(x => x.Sort,
- x => x.TrackPushConfigId == input.TrackPushConfigId);
-
- var entity = ObjectMapper.Map(input);
- entity.Sort = maxSort + 1;
-
- await _trackPushConfigRepository.InsertContentAsync(entity);
-
- break;
- }
-
- case OptionTypeNoNull.修改:
- {
- var entity = await _trackPushConfigRepository.GetContentByIdAsync(input.Id!.Value) ??
- throw new BusinessException(message: _stringLocalizer["NotFindData"]);
-
- ObjectMapper.Map(input, entity);
-
- await _trackPushConfigRepository.UpdateContentAsync(entity);
-
- break;
- }
-
- case OptionTypeNoNull.删除:
- {
- var entity = await _trackPushConfigRepository.GetContentByIdAsync(input.Id!.Value) ??
- throw new BusinessException(message: _stringLocalizer["NotFindData"]);
-
- using (var ts = TransactionScopeHelper.Create())
{
- await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.Id == input.Id);
+ int maxSort = await _trackPushConfigRepository.ContentMaxAsync(x => x.Sort,
+ x => x.TrackPushConfigId == input.TrackPushConfigId);
- await _trackPushConfigRepository.UpdateContentAsync(x => x.Sort == x.Sort - 1,
- x => x.TrackPushConfigId == entity.TrackPushConfigId && x.Sort > entity.Sort);
+ var entity = ObjectMapper.Map(input);
+ entity.Sort = maxSort + 1;
- ts.Complete();
+ await _trackPushConfigRepository.InsertContentAsync(entity);
+ await _trackPushCacheService.SetPushContentConfigsAsync(input.TrackPushConfigId);
+
+ break;
}
- break;
- }
+ case OptionTypeNoNull.修改:
+ {
+ var entity = await _trackPushConfigRepository.GetContentByIdAsync(input.Id!.Value) ??
+ throw new BusinessException(message: _stringLocalizer["NotFindData"]);
+
+ ObjectMapper.Map(input, entity);
+
+ await _trackPushConfigRepository.UpdateContentAsync(entity);
+ await _trackPushCacheService.SetPushContentConfigsAsync(entity.TrackPushConfigId);
+
+ break;
+ }
+
+ case OptionTypeNoNull.删除:
+ {
+ var entity = await _trackPushConfigRepository.GetContentByIdAsync(input.Id!.Value) ??
+ throw new BusinessException(message: _stringLocalizer["NotFindData"]);
+
+ using (var ts = TransactionScopeHelper.Create())
+ {
+ await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.Id == input.Id);
+ await _trackPushConfigRepository.UpdateContentAsync(x => x.Sort == x.Sort - 1,
+ x => x.TrackPushConfigId == entity.TrackPushConfigId && x.Sort > entity.Sort);
+
+ ts.Complete();
+ }
+
+ await _trackPushCacheService.SetPushContentConfigsAsync(entity.TrackPushConfigId);
+
+ break;
+ }
default:
throw new BusinessException(message: _stringLocalizer[SjzyBasicLocalization.Validation_IsInEnum,