using SJZY.Expand.ABP.Core; 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 System.Linq.Expressions; using Volo.Abp.DependencyInjection; namespace SJZY.Track.Application.Services.TrackPull; public class TrackPullCacheService : ApplicationService, ITrackPullCacheService, ITransientDependency { private readonly ITrackPullConfigRepository _trackPullConfigRepository; private string RedisKey(int subSystemId, int serviceProviderId) => GlobalConst.TrackPushKeyPrefix + subSystemId + ":" + serviceProviderId; public TrackPullCacheService(ITrackPullConfigRepository trackPullConfigRepository) { _trackPullConfigRepository = trackPullConfigRepository; } [NonAction] public async Task GetPullConfigAsync(int subSystemId, int serviceProviderId) { var data = await RedisHelper.Client.GetAsync(RedisKey(subSystemId, serviceProviderId)); data ??= await SetPullConfigAsync(subSystemId: subSystemId, serviceProviderId: serviceProviderId); return data; } [NonAction] public async Task SetPullConfigAsync(int? id = null, int? subSystemId = null, int? serviceProviderId = null) { var data = new TrackPullConfigDto(); Expression> exp = x => true; if (id.HasValue) exp = x => x.Id == id; else if (subSystemId.HasValue && serviceProviderId.HasValue) exp = x => x.SubSystemId == subSystemId && x.ServiceProviderId == serviceProviderId; 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); if (trackPullContentList.Count == 0) return data; data.ParamConfig = ObjectMapper.Map(trackPullConfigDetail); data.ContentConfigs = ObjectMapper.Map, List>(trackPullContentList); await RedisHelper.Client.SetAsync(RedisKey(trackPullConfigEntity.SubSystemId, trackPullConfigEntity.ServiceProviderId), data, 86400); return data; } }