diff --git a/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs b/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs
index d04c0fa2..8928ae11 100644
--- a/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs
+++ b/src/SJZY.Track.Application.Contract/Services/ITrackPushCacheService.cs
@@ -12,6 +12,14 @@ public interface ITrackPushCacheService
///
Task?> GetPushContentConfigsAsync(int subSystemId, int customId);
+ ///
+ /// 设置服务商拉取配置缓存
+ ///
+ ///
+ ///
+ ///
+ Task?> SetPushContentConfigsAsync(int subSystemId, int customId);
+
///
/// 获取服务商拉取配置
///
@@ -33,14 +41,4 @@ public interface ITrackPushCacheService
Task IsValidPushAsync(int subSystemId, int customId,
string? latestPushTrackCode,
string? trackCode);
-
- ///
- /// 设置推送配置缓存
- ///
- ///
- /// 子系统id
- /// 客户id
- ///
- 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/TrackPush/TrackPushCacheService.cs b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs
index 88d6b079..bf365f28 100644
--- a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs
+++ b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs
@@ -1,5 +1,4 @@
-using System.Linq.Expressions;
-using SJZY.Expand.ABP.Core;
+using SJZY.Expand.ABP.Core;
using SJZY.Track.Application.Contract.Dtos.TrackPush;
using SJZY.Track.Application.Contract.Services;
using SJZY.Track.Domain.Aggregates.TrackPushAggregate;
@@ -22,11 +21,23 @@ public class TrackPushCacheService : ITrackPushCacheService, ITransientDependenc
public async Task?> GetPushContentConfigsAsync(int subSystemId, int customId)
{
- var data = await RedisHelper.Client.GetAsync>(
- TrackPushContentKey(subSystemId, customId));
+ var exists = await RedisHelper.Client.ExistsAsync(TrackPushContentKey(subSystemId, customId));
+ if (exists)
+ {
+ return await RedisHelper.Client.GetAsync>(
+ TrackPushContentKey(subSystemId, customId));
+ }
- data ??= await SetPushContentConfigsAsync(subSystemId: subSystemId, customId: customId);
+ return await SetPushContentConfigsAsync(subSystemId, customId);
+ }
+ public async Task?> SetPushContentConfigsAsync(int subSystemId, int customId)
+ {
+ // maybe is null
+ var data = await DoGetPushContentConfigsAsync(subSystemId, customId);
+ // ttl 3days
+ await RedisHelper.Client.SetAsync(TrackPushContentKey(subSystemId, customId),
+ data, 3 * 24 * 60 * 60);
return data;
}
@@ -58,23 +69,23 @@ public class TrackPushCacheService : ITrackPushCacheService, ITransientDependenc
return matched != null && matched.TrackCode == trackCode && matched.IsAutoPush ? matched : default;
}
- public async Task?> SetPushContentConfigsAsync(int? id = null,
- int? subSystemId = null,
- int? customId = null)
+ private async Task?> DoGetPushContentConfigsAsync(int subSystemId, int customId)
{
- 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;
-
- var trackPushConfig = await _trackPushConfigRepository.GetFirstAsync(exp, x => new
+ 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
+ });
+ if (trackPushConfig == null)
{
- x.Id, x.IsAutoPush, x.IsAllPush, x.IsCanDelete, x.IsCanUpdate, x.SubSystemId, x.CustomId
- });
- if (trackPushConfig == null) return null;
+ return null;
+ }
var trackPushContentList = await _trackPushConfigRepository.GetContentListAsync(trackPushConfig.Id);
- if (trackPushContentList.Count == 0) return null;
+ if (trackPushContentList.Count == 0)
+ {
+ return null;
+ }
// tips:hot path,auto mapper性能不如原生
var res = trackPushContentList.Select(item => new TrackPushContentConfigDto
@@ -95,9 +106,6 @@ public class TrackPushCacheService : ITrackPushCacheService, ITransientDependenc
ExpandFieldsValue = item.ExpandFieldsValue,
}).ToList();
- await RedisHelper.Client.SetAsync(TrackPushContentKey(trackPushConfig.SubSystemId, trackPushConfig.CustomId),
- res);
-
return res;
}
}
\ No newline at end of file
diff --git a/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs b/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs
index 5225e8db..f7d69e1d 100644
--- a/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs
+++ b/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs
@@ -95,12 +95,17 @@ public class TrackPushService : ApplicationService
throw new BusinessException(message: _stringLocalizer["IsTrackPushConfigAny"]);
}
+ using var ts = TransactionScopeHelper.Create();
+
switch (input.Options)
{
case OptionTypeNoNull.新增:
{
var trackPushEntity = ObjectMapper.Map(input);
+
await _trackPushConfigRepository.InsertReturnIdentityAsync(trackPushEntity);
+ await _trackPushCacheService.SetPushContentConfigsAsync(trackPushEntity.SubSystemId,
+ trackPushEntity.CustomId);
}
break;
@@ -111,21 +116,19 @@ public class TrackPushService : ApplicationService
ObjectMapper.Map(input, oldTrackPushEntity);
await _trackPushConfigRepository.UpdateAsync(oldTrackPushEntity);
-
- if (input.IsAutoPush!.Value) await _trackPushCacheService.SetPushContentConfigsAsync(input.Id);
+ await _trackPushCacheService.SetPushContentConfigsAsync(oldTrackPushEntity.SubSystemId,
+ oldTrackPushEntity.CustomId);
}
break;
case OptionTypeNoNull.删除:
{
- _ = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == input.Id) ??
- throw new BusinessException(message: _stringLocalizer["NotFindData"]);
+ var entity = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == input.Id) ??
+ throw new BusinessException(message: _stringLocalizer["NotFindData"]);
- using var ts = TransactionScopeHelper.Create();
await _trackPushConfigRepository.SoftDeleteAsync(x => x.Id == input.Id);
await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.TrackPushConfigId == input.Id);
-
- ts.Complete();
+ await _trackPushCacheService.SetPushContentConfigsAsync(entity.SubSystemId, entity.CustomId);
}
break;
@@ -134,6 +137,7 @@ public class TrackPushService : ApplicationService
nameof(EditTrackPushConfigInput.Options)]);
}
+ ts.Complete();
return true;
}
@@ -172,6 +176,10 @@ public class TrackPushService : ApplicationService
throw new BusinessException(message: _stringLocalizer["IsTrackPushEnContentValueAny"]);
}
+ var trackPushConfigId = input.TrackPushConfigId;
+
+ using var ts = TransactionScopeHelper.Create();
+
switch (input.Options)
{
case OptionTypeNoNull.新增:
@@ -181,10 +189,7 @@ public class TrackPushService : ApplicationService
var entity = ObjectMapper.Map(input);
entity.Sort = maxSort + 1;
-
await _trackPushConfigRepository.InsertContentAsync(entity);
- await _trackPushCacheService.SetPushContentConfigsAsync(input.TrackPushConfigId);
-
break;
}
@@ -194,10 +199,7 @@ public class TrackPushService : ApplicationService
throw new BusinessException(message: _stringLocalizer["NotFindData"]);
ObjectMapper.Map(input, entity);
-
await _trackPushConfigRepository.UpdateContentAsync(entity);
- await _trackPushCacheService.SetPushContentConfigsAsync(entity.TrackPushConfigId);
-
break;
}
@@ -205,18 +207,10 @@ public class TrackPushService : ApplicationService
{
var entity = await _trackPushConfigRepository.GetContentByIdAsync(input.Id!.Value) ??
throw new BusinessException(message: _stringLocalizer["NotFindData"]);
-
- using (var ts = TransactionScopeHelper.Create())
- {
- await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.Id == input.Id);
- await _trackPushConfigRepository.UpdateContentAsync(x => x.Sort == x.Sort - 1,
- x => x.TrackPushConfigId == entity.TrackPushConfigId && x.Sort > entity.Sort);
-
- ts.Complete();
- }
-
- await _trackPushCacheService.SetPushContentConfigsAsync(entity.TrackPushConfigId);
-
+ trackPushConfigId = entity.TrackPushConfigId;
+ await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.Id == input.Id);
+ await _trackPushConfigRepository.UpdateContentAsync(x => x.Sort == x.Sort - 1,
+ x => x.TrackPushConfigId == entity.TrackPushConfigId && x.Sort > entity.Sort);
break;
}
@@ -225,6 +219,14 @@ public class TrackPushService : ApplicationService
nameof(EditTrackPushContentInput.Options)]);
}
+ var pushConfig = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == trackPushConfigId);
+ if (pushConfig != null)
+ {
+ await _trackPushCacheService.SetPushContentConfigsAsync(pushConfig.SubSystemId, pushConfig.CustomId);
+ }
+
+ ts.Complete();
+
return true;
}
@@ -247,8 +249,19 @@ public class TrackPushService : ApplicationService
if (trackPushContentEntities.Count > 0)
{
+ using var ts = TransactionScopeHelper.Create();
+
await _trackPushConfigRepository.UpdateContentRangeAsync(trackPushContentEntities);
- await _trackPushCacheService.SetPushContentConfigsAsync(trackPushContentEntities[0].TrackPushConfigId);
+
+ var pushConfig =
+ await _trackPushConfigRepository.GetFirstAsync(x =>
+ x.Id == trackPushContentEntities[0].TrackPushConfigId);
+ if (pushConfig != null)
+ {
+ await _trackPushCacheService.SetPushContentConfigsAsync(pushConfig.SubSystemId, pushConfig.CustomId);
+ }
+
+ ts.Complete();
}
return true;