修改缓存

This commit is contained in:
柳文翔 2024-03-04 11:43:29 +08:00
parent 1b79aba439
commit 3298d3cb88
3 changed files with 13 additions and 13 deletions

View File

@ -6,9 +6,10 @@ using Volo.Abp.DependencyInjection;
namespace SJZY.Track.Application.Services.TrackPush; namespace SJZY.Track.Application.Services.TrackPush;
public class TrackPushCacheService:ITrackPushCacheService, ITransientDependency public class TrackPushCacheService : ITrackPushCacheService, ITransientDependency
{ {
private readonly IBasicQuery<TrackPushConfigEntity> _trackPushConfigQuery; private readonly IBasicQuery<TrackPushConfigEntity> _trackPushConfigQuery;
private string RedisKey(int customId) => GlobalConst.TrackPushKeyPrefix + customId; private string RedisKey(int customId) => GlobalConst.TrackPushKeyPrefix + customId;
public TrackPushCacheService(IBasicQuery<TrackPushConfigEntity> trackPushConfigQuery) public TrackPushCacheService(IBasicQuery<TrackPushConfigEntity> trackPushConfigQuery)

View File

@ -3,6 +3,7 @@ using SJZY.Expand.ABP.Core;
using SJZY.Expand.ABP.Core.Localization; using SJZY.Expand.ABP.Core.Localization;
using SJZY.Expand.ABP.Core.PublicMethords; using SJZY.Expand.ABP.Core.PublicMethords;
using SJZY.Track.Application.Contract.Dtos.TrackPush; using SJZY.Track.Application.Contract.Dtos.TrackPush;
using SJZY.Track.Application.Contract.Services;
using SJZY.Track.Application.Localization; using SJZY.Track.Application.Localization;
using SJZY.Track.Domain.Aggregates.TrackPullAggregate; using SJZY.Track.Domain.Aggregates.TrackPullAggregate;
using SJZY.Track.Domain.Aggregates.TrackPushAggregate; using SJZY.Track.Domain.Aggregates.TrackPushAggregate;
@ -26,17 +27,20 @@ public class TrackPushService : ApplicationService, ITransientDependency
private readonly ITrackPushConfigRepository _trackPushConfigRepository; private readonly ITrackPushConfigRepository _trackPushConfigRepository;
private readonly ITrackTemplateRepository _trackTemplateRepository; private readonly ITrackTemplateRepository _trackTemplateRepository;
private readonly ITrackPullConfigRepository _trackPullConfigRepository; private readonly ITrackPullConfigRepository _trackPullConfigRepository;
private readonly ITrackPushCacheService _trackPushCacheService;
public TrackPushService( public TrackPushService(
IStringLocalizer<TrackLocalizationResource> stringLocalizer, IStringLocalizer<TrackLocalizationResource> stringLocalizer,
ITrackPushConfigRepository trackPushConfigRepository, ITrackPushConfigRepository trackPushConfigRepository,
ITrackTemplateRepository trackTemplateRepository, ITrackTemplateRepository trackTemplateRepository,
ITrackPullConfigRepository trackPullConfigRepository) ITrackPullConfigRepository trackPullConfigRepository,
ITrackPushCacheService trackPushCacheService)
{ {
_stringLocalizer = stringLocalizer; _stringLocalizer = stringLocalizer;
_trackPushConfigRepository = trackPushConfigRepository; _trackPushConfigRepository = trackPushConfigRepository;
_trackTemplateRepository = trackTemplateRepository; _trackTemplateRepository = trackTemplateRepository;
_trackPullConfigRepository = trackPullConfigRepository; _trackPullConfigRepository = trackPullConfigRepository;
_trackPushCacheService = trackPushCacheService;
} }
/// <summary> /// <summary>
@ -129,7 +133,7 @@ public class TrackPushService : ApplicationService, ITransientDependency
trackPushParamsEntity.PullOrPushConfigId = id; trackPushParamsEntity.PullOrPushConfigId = id;
await _trackPullConfigRepository.InsertParamsAsync(trackPushParamsEntity); 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(); ts.Complete();
} }
@ -154,8 +158,8 @@ public class TrackPushService : ApplicationService, ITransientDependency
await _trackPushConfigRepository.UpdateAsync(oldTrackPushEntity); await _trackPushConfigRepository.UpdateAsync(oldTrackPushEntity);
await _trackPullConfigRepository.UpdateParamsAsync(oldTrackPushParamsEntity); await _trackPullConfigRepository.UpdateParamsAsync(oldTrackPushParamsEntity);
await RedisHelper.Client.SRemAsync(GlobalConst.AutoPushRosterRedisKey, oldCustomId); await _trackPushCacheService.UpdateAsync(oldCustomId, false);
if (input.IsAutoPush) await RedisHelper.Client.SAddAsync(GlobalConst.AutoPushRosterRedisKey, input.CustomId); if (input.IsAutoPush) await _trackPushCacheService.IsPushAsync(input.CustomId);
ts.Complete(); ts.Complete();
} }
@ -173,7 +177,7 @@ public class TrackPushService : ApplicationService, ITransientDependency
x.PullOrPushConfigId == input.Id && x.IsPush); x.PullOrPushConfigId == input.Id && x.IsPush);
await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.TrackPushConfigId == input.Id); await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.TrackPushConfigId == input.Id);
await RedisHelper.Client.SRemAsync(GlobalConst.AutoPushRosterRedisKey, oldTrackPushEntity.CustomId); await _trackPushCacheService.UpdateAsync(oldTrackPushEntity.CustomId, false);
ts.Complete(); ts.Complete();
} }

View File

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