fix:【【轨迹订单】"是否自动推送"为否,新增轨迹明细后,异常自动推送轨迹明细】https://www.tapd.cn/60863849/bugtrace/bugs/view?bug_id=1160863849001032644
This commit is contained in:
parent
d2de95a803
commit
66d5a5c4d5
@ -12,6 +12,14 @@ public interface ITrackPushCacheService
|
||||
/// <returns></returns>
|
||||
Task<List<TrackPushContentConfigDto>?> GetPushContentConfigsAsync(int subSystemId, int customId);
|
||||
|
||||
/// <summary>
|
||||
/// 设置服务商拉取配置缓存
|
||||
/// </summary>
|
||||
/// <param name="subSystemId"></param>
|
||||
/// <param name="customId"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<TrackPushContentConfigDto>?> SetPushContentConfigsAsync(int subSystemId, int customId);
|
||||
|
||||
/// <summary>
|
||||
/// 获取服务商拉取配置
|
||||
/// </summary>
|
||||
@ -33,14 +41,4 @@ public interface ITrackPushCacheService
|
||||
Task<TrackPushContentConfigDto?> IsValidPushAsync(int subSystemId, int customId,
|
||||
string? latestPushTrackCode,
|
||||
string? trackCode);
|
||||
|
||||
/// <summary>
|
||||
/// 设置推送配置缓存
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <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);
|
||||
}
|
||||
@ -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<List<TrackPushContentConfigDto>?> GetPushContentConfigsAsync(int subSystemId, int customId)
|
||||
{
|
||||
var data = await RedisHelper.Client.GetAsync<List<TrackPushContentConfigDto>>(
|
||||
var exists = await RedisHelper.Client.ExistsAsync(TrackPushContentKey(subSystemId, customId));
|
||||
if (exists)
|
||||
{
|
||||
return await RedisHelper.Client.GetAsync<List<TrackPushContentConfigDto>>(
|
||||
TrackPushContentKey(subSystemId, customId));
|
||||
}
|
||||
|
||||
data ??= await SetPushContentConfigsAsync(subSystemId: subSystemId, customId: customId);
|
||||
return await SetPushContentConfigsAsync(subSystemId, customId);
|
||||
}
|
||||
|
||||
public async Task<List<TrackPushContentConfigDto>?> 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<List<TrackPushContentConfigDto>?> SetPushContentConfigsAsync(int? id = null,
|
||||
int? subSystemId = null,
|
||||
int? customId = null)
|
||||
private async Task<List<TrackPushContentConfigDto>?> DoGetPushContentConfigsAsync(int subSystemId, int customId)
|
||||
{
|
||||
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;
|
||||
|
||||
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) return null;
|
||||
if (trackPushConfig == 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;
|
||||
}
|
||||
}
|
||||
@ -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<EditTrackPushConfigInput, TrackPushConfigEntity>(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) ??
|
||||
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<EditTrackPushContentInput, TrackPushContentConfigEntity>(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())
|
||||
{
|
||||
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);
|
||||
|
||||
ts.Complete();
|
||||
}
|
||||
|
||||
await _trackPushCacheService.SetPushContentConfigsAsync(entity.TrackPushConfigId);
|
||||
|
||||
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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user