using SJZY.Expand.ABP.Core; using SJZY.Track.Application.Contract.Dtos.TrackPush; using SJZY.Track.Application.Contract.Services; using SJZY.Track.Domain.Aggregates.TrackPushAggregate; using SJZY.Track.Domain.Consts; using Volo.Abp.DependencyInjection; namespace SJZY.Track.Application.Services.TrackPush; public class TrackPushCacheService : ITrackPushCacheService, ITransientDependency { private readonly ITrackPushConfigRepository _trackPushConfigRepository; private string TrackPushContentKey(int subSystemId, int customId) => $"{GlobalConst.TrackPushKeyPrefix}:{subSystemId}:{customId}"; public TrackPushCacheService(ITrackPushConfigRepository trackPushConfigRepository) { _trackPushConfigRepository = trackPushConfigRepository; } public async Task?> GetPushContentConfigsAsync(int subSystemId, int customId) { var exists = await RedisHelper.Client.ExistsAsync(TrackPushContentKey(subSystemId, customId)); if (exists) { return await RedisHelper.Client.GetAsync>( TrackPushContentKey(subSystemId, customId)); } return await SetPushContentConfigsAsync(subSystemId, customId); } public async Task?> SetPushContentConfigsAsync(int subSystemId, int customId) { // maybe is null var data = await DoGetPushContentConfigsAsync(subSystemId, customId); var ttl = 3 * 24 * 60 * 60; if (data == null) ttl = 5; // ttl 3days await RedisHelper.Client.SetAsync(TrackPushContentKey(subSystemId, customId), data, ttl); return data; } private async Task?> DoGetPushContentConfigsAsync(int subSystemId, int customId) { var trackPushConfig = await _trackPushConfigRepository.GetFirstAsync( x => x.SubSystemId == subSystemId && x.CustomId == customId, x => new { x.Id, x.IsAutoPush, x.IsAllPush, x.IsCanDelete, x.IsCanUpdate, x.SubSystemId, x.CustomId,x.DateTimeFormatType,x.DateTimeFormat,x.TimezoneFormat }); if (trackPushConfig == null) { return null; } var trackPushContentList = await _trackPushConfigRepository.GetContentListAsync(trackPushConfig.Id); if (trackPushContentList.Count == 0) { return null; } // tips:hot path,auto mapper性能不如原生 var res = trackPushContentList.Select(item => new TrackPushContentConfigDto { IsAutoPush = trackPushConfig.IsAutoPush, IsCanUpdate = trackPushConfig.IsCanUpdate, IsAllPush = trackPushConfig.IsAllPush, IsCanDelete = trackPushConfig.IsCanDelete, DateTimeFormatType = trackPushConfig.DateTimeFormatType, DateTimeFormat = trackPushConfig.DateTimeFormat, TimezoneFormat = trackPushConfig.TimezoneFormat, ServiceProviderCode = item.ServiceProviderCode, OrderType = item.OrderType, TrackCode = item.TrackCode, SwapTrackCode = item.SwapTrackCode, TrackStatusValue = item.TrackStatusValue, TrackContentCodeValue = item.TrackContentCodeValue, TrackContentValue = item.TrackContentValue, TrackEnContentValue = item.TrackEnContentValue, TrackTimeZone = item.TrackTimeZone, ExpandFieldsValue = item.ExpandFieldsValue, }).ToList(); return res; } }