修改
This commit is contained in:
parent
3871b31af0
commit
b10f1cedfd
@ -1,5 +1,18 @@
|
||||
namespace SJZY.Track.Application.Contract.Dtos.ProvideServices;
|
||||
|
||||
public class TrackPushConfigDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否自动推送
|
||||
/// </summary>
|
||||
public bool IsAutoPush { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 轨迹推送内容配置
|
||||
/// </summary>
|
||||
public List<TrackPushContentConfigDto> ContentConfigs { get; set; }
|
||||
}
|
||||
|
||||
public class TrackPushContentConfigDto
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@ -29,5 +29,5 @@ public interface ITrackPushCacheService
|
||||
/// <param name="subSystemId">子系统id</param>
|
||||
/// <param name="customId">客户id</param>
|
||||
/// <returns></returns>
|
||||
Task<List<TrackPushContentConfigDto>> SetPushContentConfigsAsync(int? id = null, int? subSystemId = null, int? customId = null);
|
||||
Task<TrackPushConfigDto> SetPushContentConfigsAsync(int? id = null, int? subSystemId = null, int? customId = null);
|
||||
}
|
||||
@ -21,40 +21,39 @@ public class TrackPushCacheService : ApplicationService, ITrackPushCacheService,
|
||||
[NonAction]
|
||||
public async Task<List<TrackPushContentConfigDto>> GetPushContentConfigsAsync(int subSystemId, int customId)
|
||||
{
|
||||
var data = await RedisHelper.Client.GetAsync<List<TrackPushContentConfigDto>>(TrackPushContentKey(subSystemId, customId));
|
||||
var data = await GetPushConfigAsync(subSystemId, customId);
|
||||
|
||||
data ??= await SetPushContentConfigsAsync(subSystemId: subSystemId, customId: customId);
|
||||
|
||||
return data;
|
||||
return data.ContentConfigs;
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
public async Task<TrackPushContentConfigDto?> InferNextPushContentOrNullAsync(int subSystemId, int customId, int? trackContentId)
|
||||
{
|
||||
var data = await GetPushContentConfigsAsync(subSystemId, customId);
|
||||
var data = await GetPushConfigAsync(subSystemId, customId);
|
||||
if (!data.IsAutoPush) return null;
|
||||
|
||||
if (trackContentId.HasValue)
|
||||
{
|
||||
if (data.Count > 1 && data.Any(x => x.TrackContentId == trackContentId))
|
||||
if (data.ContentConfigs.Count > 1 && data.ContentConfigs.Any(x => x.TrackContentId == trackContentId))
|
||||
{
|
||||
int index = data.FindIndex(x => x.TrackContentId == trackContentId);
|
||||
int nextIndex = (index + 1) % data.Count; // 计算下一个索引,处理最后一个元素的情况
|
||||
int index = data.ContentConfigs.FindIndex(x => x.TrackContentId == trackContentId);
|
||||
int nextIndex = (index + 1) % data.ContentConfigs.Count; // 计算下一个索引,处理最后一个元素的情况
|
||||
|
||||
return data[nextIndex];
|
||||
return data.ContentConfigs[nextIndex];
|
||||
}
|
||||
else return null;
|
||||
}
|
||||
else return data.FirstOrDefault();
|
||||
else return data.ContentConfigs.FirstOrDefault();
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
public async Task<List<TrackPushContentConfigDto>> SetPushContentConfigsAsync(int? id = null, int? subSystemId = null, int? customId = null)
|
||||
public async Task<TrackPushConfigDto> SetPushContentConfigsAsync(int? id = null, int? subSystemId = null, int? customId = null)
|
||||
{
|
||||
var data = new List<TrackPushContentConfigDto>();
|
||||
var data = new TrackPushConfigDto { ContentConfigs = [] };
|
||||
|
||||
Expression<Func<TrackPushConfigEntity, bool>> exp = x => true;
|
||||
if (id.HasValue) exp = x => x.Id == id;
|
||||
else if (subSystemId.HasValue && customId.HasValue)
|
||||
exp = x => x.SubSystemId == subSystemId && x.CustomId == customId;
|
||||
else if (subSystemId.HasValue && customId.HasValue) exp = x => x.SubSystemId == subSystemId && x.CustomId == customId;
|
||||
|
||||
var trackPushConfigEntity = await _trackPushConfigRepository.GetFirstAsync(exp);
|
||||
if (trackPushConfigEntity == null) return data;
|
||||
@ -64,10 +63,20 @@ public class TrackPushCacheService : ApplicationService, ITrackPushCacheService,
|
||||
|
||||
trackPushContentList = trackPushContentList.OrderBy(x => x.Sort).ToList();
|
||||
|
||||
data = ObjectMapper.Map<List<TrackPushContentConfigEntity>, List<TrackPushContentConfigDto>>(trackPushContentList);
|
||||
data.IsAutoPush = trackPushConfigEntity.IsAutoPush;
|
||||
data.ContentConfigs = ObjectMapper.Map<List<TrackPushContentConfigEntity>, List<TrackPushContentConfigDto>>(trackPushContentList);
|
||||
|
||||
await RedisHelper.Client.SetAsync(TrackPushContentKey(trackPushConfigEntity.SubSystemId, trackPushConfigEntity.CustomId), data, (int)TimeSpan.FromDays(1).TotalSeconds);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
private async Task<TrackPushConfigDto> GetPushConfigAsync(int subSystemId, int customId)
|
||||
{
|
||||
var data = await RedisHelper.Client.GetAsync<TrackPushConfigDto>(TrackPushContentKey(subSystemId, customId));
|
||||
|
||||
data ??= await SetPushContentConfigsAsync(subSystemId: subSystemId, customId: customId);
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@ -142,6 +142,8 @@ public class TrackPushService : ApplicationService
|
||||
|
||||
ts.Complete();
|
||||
}
|
||||
|
||||
if (input.IsAutoPush!.Value) await _trackPushCacheService.SetPushContentConfigsAsync(input.Id);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user