diff --git a/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs b/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs
index 12db0f65..f0356ec3 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);
-
///
/// 获取服务商拉取配置
///
@@ -39,9 +32,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 d2bb3e2d..8bc9d408 100644
--- a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs
+++ b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs
@@ -2,45 +2,77 @@
using SJZY.Track.Application.Contract.Dtos.ProvideServices;
using SJZY.Track.Application.Contract.Services;
using SJZY.Track.Domain.Aggregates.TrackPushAggregate;
-using SJZY.Track.Domain.Queries;
+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));
- public Task> GetPushContentConfigsAsync(int subSystemId, int customId)
- {
- throw new NotImplementedException();
- }
+ data ??= await SetPushContentConfigsAsync(subSystemId: subSystemId, customId: customId);
+ return data;
+ }
+
public Task GetPushContentConfigAsync(int subSystemId, int customId, int trackContentId)
{
throw new NotImplementedException();
}
- public Task InferNextPushContentOrNullAsync(int subSystemId, int customId,
- int? trackContentId)
+ [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 async Task UpdateAsync(int customId, bool isPush)
+ [NonAction]
+ public async Task> SetPushContentConfigsAsync(int? id = null, int? subSystemId = null, int? customId = null)
{
- await RedisHelper.Client.SetAsync(RedisKey(customId), isPush);
+ 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;
+
+ 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..e7498c2c 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,
@@ -282,7 +278,11 @@ public class TrackPushService : ApplicationService
item.Sort = input.SortInfo.Single(x => x.Key == item.Id.ToString()).Value;
});
- await _trackPushConfigRepository.UpdateContentRangeAsync(trackPushContentEntities);
+ if (trackPushContentEntities.Count > 0)
+ {
+ await _trackPushConfigRepository.UpdateContentRangeAsync(trackPushContentEntities);
+ await _trackPushCacheService.SetPushContentConfigsAsync(trackPushContentEntities[0].TrackPushConfigId);
+ }
return true;
}