diff --git a/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/TrackPushContentConfigDto.cs b/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/TrackPushContentConfigDto.cs
index ed2e02d0..578c298d 100644
--- a/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/TrackPushContentConfigDto.cs
+++ b/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/TrackPushContentConfigDto.cs
@@ -1,5 +1,18 @@
namespace SJZY.Track.Application.Contract.Dtos.ProvideServices;
+public class TrackPushConfigDto
+{
+ ///
+ /// 是否自动推送
+ ///
+ public bool IsAutoPush { get; set; }
+
+ ///
+ /// 轨迹推送内容配置
+ ///
+ public List ContentConfigs { get; set; }
+}
+
public class TrackPushContentConfigDto
{
///
diff --git a/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs b/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs
index f0356ec3..a4a57bc0 100644
--- a/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs
+++ b/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs
@@ -38,5 +38,5 @@ public interface ITrackPushCacheService
/// 子系统id
/// 客户id
///
- Task> SetPushContentConfigsAsync(int? id = null, int? subSystemId = null, int? customId = null);
+ Task SetPushContentConfigsAsync(int? id = null, int? subSystemId = null, int? customId = null);
}
\ No newline at end of file
diff --git a/src/SJZY.Track.Application/Services/TrackPull/TrackPullCacheService.cs b/src/SJZY.Track.Application/Services/TrackPull/TrackPullCacheService.cs
index 1a57ea08..b5418f24 100644
--- a/src/SJZY.Track.Application/Services/TrackPull/TrackPullCacheService.cs
+++ b/src/SJZY.Track.Application/Services/TrackPull/TrackPullCacheService.cs
@@ -73,8 +73,7 @@ public class TrackPullCacheService : ApplicationService, ITrackPullCacheService,
trackPullContentList);
await RedisHelper.Client.SetAsync(
- TrackPullContentKey(trackPullConfigEntity.SubSystemId, trackPullConfigEntity.ServiceProviderId), data,
- (int)TimeSpan.FromDays(1).TotalSeconds);
+ TrackPullContentKey(trackPullConfigEntity.SubSystemId, trackPullConfigEntity.ServiceProviderId), data);
return data;
}
diff --git a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs
index 8bc9d408..30766856 100644
--- a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs
+++ b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs
@@ -21,45 +21,47 @@ public class TrackPushCacheService : ApplicationService, ITrackPushCacheService,
[NonAction]
public async Task> GetPushContentConfigsAsync(int subSystemId, int customId)
{
- var data = await RedisHelper.Client.GetAsync>(TrackPushContentKey(subSystemId, customId));
+ var data = await GetPushConfigAsync(subSystemId, customId);
- data ??= await SetPushContentConfigsAsync(subSystemId: subSystemId, customId: customId);
-
- return data;
+ return data.ContentConfigs;
}
-
- public Task GetPushContentConfigAsync(int subSystemId, int customId, int trackContentId)
+
+ [NonAction]
+ public async Task GetPushContentConfigAsync(int subSystemId, int customId, int trackContentId)
{
- throw new NotImplementedException();
+ var data = await GetPushContentConfigsAsync(subSystemId, customId);
+
+ return data.Single(x => x.TrackContentId == trackContentId);
}
[NonAction]
public async Task 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> SetPushContentConfigsAsync(int? id = null, int? subSystemId = null, int? customId = null)
+ public async Task SetPushContentConfigsAsync(int? id = null, int? subSystemId = null, int? customId = null)
{
- var data = new List();
+ var data = new TrackPushConfigDto { ContentConfigs = [] };
+
Expression> 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;
@@ -69,9 +71,19 @@ public class TrackPushCacheService : ApplicationService, ITrackPushCacheService,
trackPushContentList = trackPushContentList.OrderBy(x => x.Sort).ToList();
- data = ObjectMapper.Map, List>(trackPushContentList);
+ data.IsAutoPush = trackPushConfigEntity.IsAutoPush;
+ data.ContentConfigs = ObjectMapper.Map, List>(trackPushContentList);
- await RedisHelper.Client.SetAsync(TrackPushContentKey(trackPushConfigEntity.SubSystemId, trackPushConfigEntity.CustomId), data, (int)TimeSpan.FromDays(1).TotalSeconds);
+ await RedisHelper.Client.SetAsync(TrackPushContentKey(trackPushConfigEntity.SubSystemId, trackPushConfigEntity.CustomId), data);
+
+ return data;
+ }
+
+ private async Task GetPushConfigAsync(int subSystemId, int customId)
+ {
+ var data = await RedisHelper.Client.GetAsync(TrackPushContentKey(subSystemId, customId));
+
+ data ??= await SetPushContentConfigsAsync(subSystemId: subSystemId, customId: customId);
return data;
}
diff --git a/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs b/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs
index e7498c2c..712bbc3c 100644
--- a/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs
+++ b/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs
@@ -142,6 +142,8 @@ public class TrackPushService : ApplicationService
ts.Complete();
}
+
+ if (input.IsAutoPush!.Value) await _trackPushCacheService.SetPushContentConfigsAsync(input.Id);
}
break;