62 lines
2.5 KiB
C#
62 lines
2.5 KiB
C#
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 Volo.Abp.DependencyInjection;
|
|
using Volo.Abp.ObjectMapping;
|
|
|
|
namespace SJZY.Track.Application.Services.TrackPull;
|
|
|
|
public class TrackPullCacheService : ITransientDependency, ITrackPullCacheService
|
|
{
|
|
private readonly IObjectMapper _objectMapper;
|
|
private readonly ITrackPullConfigRepository _trackPullConfigRepository;
|
|
|
|
public TrackPullCacheService(ITrackPullConfigRepository trackPullConfigRepository, IObjectMapper objectMapper)
|
|
{
|
|
_trackPullConfigRepository = trackPullConfigRepository;
|
|
_objectMapper = objectMapper;
|
|
}
|
|
|
|
public string TrackPullKey(string subSystemCode, string serviceProviderCode) =>
|
|
$"{GlobalConst.TrackPullKeyPrefix}:{subSystemCode}:{serviceProviderCode}";
|
|
|
|
public string TrackPullContentKey(string subSystemCode, string serviceProviderCode) =>
|
|
$"{GlobalConst.TrackPullContentKeyPrefix}:{subSystemCode}:{serviceProviderCode}";
|
|
|
|
public async Task<TrackPullParamsWithContentDto?> GetPullParamsWithContentAsync(string subSystemCode,
|
|
string serviceProviderCode)
|
|
{
|
|
var data = await RedisHelper.Client.GetAsync<TrackPullParamsWithContentDto>(TrackPullContentKey(
|
|
subSystemCode, serviceProviderCode));
|
|
|
|
var pullId = await _trackPullConfigRepository.FindIdAsync(subSystemCode, serviceProviderCode);
|
|
data ??= await SetPullConfigAsync(pullId);
|
|
|
|
return data;
|
|
}
|
|
|
|
public async Task<TrackPullParamsWithContentDto?> SetPullConfigAsync(int id)
|
|
{
|
|
var trackPullConfigDetail = await _trackPullConfigRepository.GetDetailAsync(id);
|
|
if (trackPullConfigDetail == null) return null;
|
|
|
|
var trackPullContentList = await _trackPullConfigRepository.GetContentListCacheAsync(id);
|
|
if (trackPullContentList.Count == 0) return null;
|
|
|
|
var data = new TrackPullParamsWithContentDto
|
|
{
|
|
ParamConfig =
|
|
_objectMapper.Map<GetTrackPullConfigDetailOutputVO, TrackPullParamConfigDto>(trackPullConfigDetail),
|
|
ContentConfigs = _objectMapper.Map<List<GetTrackPullContentListCacheVO>, List<TrackPullContentConfigDto>>(
|
|
trackPullContentList)
|
|
};
|
|
|
|
await RedisHelper.Client.SetAsync(
|
|
TrackPullContentKey(trackPullConfigDetail.SubSystemCode, trackPullConfigDetail.ServiceProviderCode), data);
|
|
|
|
return data;
|
|
}
|
|
}
|