Merge pull request '修改缓存' (#44) from S01-轨迹中台 into test

Reviewed-on: http://192.168.80.50:3000/Dotnet/SJZY.Track.Api/pulls/44
This commit is contained in:
liuwenxiang 2024-03-04 11:43:58 +08:00
commit 764eb29168
3 changed files with 13 additions and 13 deletions

View File

@ -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<TrackPushConfigEntity> _trackPushConfigQuery;
private string RedisKey(int customId) => GlobalConst.TrackPushKeyPrefix + customId;
public TrackPushCacheService(IBasicQuery<TrackPushConfigEntity> trackPushConfigQuery)
{
_trackPushConfigQuery = trackPushConfigQuery;
}
public async Task<bool> 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);

View File

@ -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<TrackLocalizationResource> stringLocalizer,
ITrackPushConfigRepository trackPushConfigRepository,
ITrackTemplateRepository trackTemplateRepository,
ITrackPullConfigRepository trackPullConfigRepository)
ITrackPullConfigRepository trackPullConfigRepository,
ITrackPushCacheService trackPushCacheService)
{
_stringLocalizer = stringLocalizer;
_trackPushConfigRepository = trackPushConfigRepository;
_trackTemplateRepository = trackTemplateRepository;
_trackPullConfigRepository = trackPullConfigRepository;
_trackPushCacheService = trackPushCacheService;
}
/// <summary>
@ -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();
}

View File

@ -21,9 +21,4 @@ public class GlobalConst
/// 轨迹要推送的客户redis key前缀
/// </summary>
public const string TrackPushKeyPrefix = "TrackPush:";
/// <summary>
/// 自动推送名单RedisKey
/// </summary>
public const string AutoPushRosterRedisKey = "AutoPushRoster";
}