fix:【【轨迹订单】"是否自动推送"为否,新增轨迹明细后,异常自动推送轨迹明细】https://www.tapd.cn/60863849/bugtrace/bugs/view?bug_id=1160863849001032644

This commit is contained in:
李鹏军 2024-04-07 21:21:21 +08:00
parent d2de95a803
commit 66d5a5c4d5
3 changed files with 76 additions and 57 deletions

View File

@ -12,6 +12,14 @@ public interface ITrackPushCacheService
/// <returns></returns> /// <returns></returns>
Task<List<TrackPushContentConfigDto>?> GetPushContentConfigsAsync(int subSystemId, int customId); 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>
/// 获取服务商拉取配置 /// 获取服务商拉取配置
/// </summary> /// </summary>
@ -33,14 +41,4 @@ public interface ITrackPushCacheService
Task<TrackPushContentConfigDto?> IsValidPushAsync(int subSystemId, int customId, Task<TrackPushContentConfigDto?> IsValidPushAsync(int subSystemId, int customId,
string? latestPushTrackCode, string? latestPushTrackCode,
string? trackCode); 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);
} }

View File

@ -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.Dtos.TrackPush;
using SJZY.Track.Application.Contract.Services; using SJZY.Track.Application.Contract.Services;
using SJZY.Track.Domain.Aggregates.TrackPushAggregate; 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) 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)); 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; return data;
} }
@ -58,23 +69,23 @@ public class TrackPushCacheService : ITrackPushCacheService, ITransientDependenc
return matched != null && matched.TrackCode == trackCode && matched.IsAutoPush ? matched : default; return matched != null && matched.TrackCode == trackCode && matched.IsAutoPush ? matched : default;
} }
public async Task<List<TrackPushContentConfigDto>?> SetPushContentConfigsAsync(int? id = null, private async Task<List<TrackPushContentConfigDto>?> DoGetPushContentConfigsAsync(int subSystemId, int customId)
int? subSystemId = null,
int? customId = null)
{ {
Expression<Func<TrackPushConfigEntity, bool>> exp = x => true; var trackPushConfig = await _trackPushConfigRepository.GetFirstAsync(
if (id.HasValue) exp = x => x.Id == id; x => x.SubSystemId == subSystemId && x.CustomId == customId, x => new
else if (subSystemId.HasValue && customId.HasValue)
exp = x => x.SubSystemId == subSystemId && x.CustomId == customId;
var trackPushConfig = await _trackPushConfigRepository.GetFirstAsync(exp, x => new
{ {
x.Id, x.IsAutoPush, x.IsAllPush, x.IsCanDelete, x.IsCanUpdate, x.SubSystemId, x.CustomId 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); var trackPushContentList = await _trackPushConfigRepository.GetContentListAsync(trackPushConfig.Id);
if (trackPushContentList.Count == 0) return null; if (trackPushContentList.Count == 0)
{
return null;
}
// tips:hot path,auto mapper性能不如原生 // tips:hot path,auto mapper性能不如原生
var res = trackPushContentList.Select(item => new TrackPushContentConfigDto var res = trackPushContentList.Select(item => new TrackPushContentConfigDto
@ -95,9 +106,6 @@ public class TrackPushCacheService : ITrackPushCacheService, ITransientDependenc
ExpandFieldsValue = item.ExpandFieldsValue, ExpandFieldsValue = item.ExpandFieldsValue,
}).ToList(); }).ToList();
await RedisHelper.Client.SetAsync(TrackPushContentKey(trackPushConfig.SubSystemId, trackPushConfig.CustomId),
res);
return res; return res;
} }
} }

View File

@ -95,12 +95,17 @@ public class TrackPushService : ApplicationService
throw new BusinessException(message: _stringLocalizer["IsTrackPushConfigAny"]); throw new BusinessException(message: _stringLocalizer["IsTrackPushConfigAny"]);
} }
using var ts = TransactionScopeHelper.Create();
switch (input.Options) switch (input.Options)
{ {
case OptionTypeNoNull.新增: case OptionTypeNoNull.新增:
{ {
var trackPushEntity = ObjectMapper.Map<EditTrackPushConfigInput, TrackPushConfigEntity>(input); var trackPushEntity = ObjectMapper.Map<EditTrackPushConfigInput, TrackPushConfigEntity>(input);
await _trackPushConfigRepository.InsertReturnIdentityAsync(trackPushEntity); await _trackPushConfigRepository.InsertReturnIdentityAsync(trackPushEntity);
await _trackPushCacheService.SetPushContentConfigsAsync(trackPushEntity.SubSystemId,
trackPushEntity.CustomId);
} }
break; break;
@ -111,21 +116,19 @@ public class TrackPushService : ApplicationService
ObjectMapper.Map(input, oldTrackPushEntity); ObjectMapper.Map(input, oldTrackPushEntity);
await _trackPushConfigRepository.UpdateAsync(oldTrackPushEntity); await _trackPushConfigRepository.UpdateAsync(oldTrackPushEntity);
await _trackPushCacheService.SetPushContentConfigsAsync(oldTrackPushEntity.SubSystemId,
if (input.IsAutoPush!.Value) await _trackPushCacheService.SetPushContentConfigsAsync(input.Id); oldTrackPushEntity.CustomId);
} }
break; break;
case OptionTypeNoNull.删除: 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"]); throw new BusinessException(message: _stringLocalizer["NotFindData"]);
using var ts = TransactionScopeHelper.Create();
await _trackPushConfigRepository.SoftDeleteAsync(x => x.Id == input.Id); await _trackPushConfigRepository.SoftDeleteAsync(x => x.Id == input.Id);
await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.TrackPushConfigId == input.Id); await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.TrackPushConfigId == input.Id);
await _trackPushCacheService.SetPushContentConfigsAsync(entity.SubSystemId, entity.CustomId);
ts.Complete();
} }
break; break;
@ -134,6 +137,7 @@ public class TrackPushService : ApplicationService
nameof(EditTrackPushConfigInput.Options)]); nameof(EditTrackPushConfigInput.Options)]);
} }
ts.Complete();
return true; return true;
} }
@ -172,6 +176,10 @@ public class TrackPushService : ApplicationService
throw new BusinessException(message: _stringLocalizer["IsTrackPushEnContentValueAny"]); throw new BusinessException(message: _stringLocalizer["IsTrackPushEnContentValueAny"]);
} }
var trackPushConfigId = input.TrackPushConfigId;
using var ts = TransactionScopeHelper.Create();
switch (input.Options) switch (input.Options)
{ {
case OptionTypeNoNull.新增: case OptionTypeNoNull.新增:
@ -181,10 +189,7 @@ public class TrackPushService : ApplicationService
var entity = ObjectMapper.Map<EditTrackPushContentInput, TrackPushContentConfigEntity>(input); var entity = ObjectMapper.Map<EditTrackPushContentInput, TrackPushContentConfigEntity>(input);
entity.Sort = maxSort + 1; entity.Sort = maxSort + 1;
await _trackPushConfigRepository.InsertContentAsync(entity); await _trackPushConfigRepository.InsertContentAsync(entity);
await _trackPushCacheService.SetPushContentConfigsAsync(input.TrackPushConfigId);
break; break;
} }
@ -194,10 +199,7 @@ public class TrackPushService : ApplicationService
throw new BusinessException(message: _stringLocalizer["NotFindData"]); throw new BusinessException(message: _stringLocalizer["NotFindData"]);
ObjectMapper.Map(input, entity); ObjectMapper.Map(input, entity);
await _trackPushConfigRepository.UpdateContentAsync(entity); await _trackPushConfigRepository.UpdateContentAsync(entity);
await _trackPushCacheService.SetPushContentConfigsAsync(entity.TrackPushConfigId);
break; break;
} }
@ -205,18 +207,10 @@ public class TrackPushService : ApplicationService
{ {
var entity = await _trackPushConfigRepository.GetContentByIdAsync(input.Id!.Value) ?? var entity = await _trackPushConfigRepository.GetContentByIdAsync(input.Id!.Value) ??
throw new BusinessException(message: _stringLocalizer["NotFindData"]); throw new BusinessException(message: _stringLocalizer["NotFindData"]);
trackPushConfigId = entity.TrackPushConfigId;
using (var ts = TransactionScopeHelper.Create())
{
await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.Id == input.Id); await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.Id == input.Id);
await _trackPushConfigRepository.UpdateContentAsync(x => x.Sort == x.Sort - 1, await _trackPushConfigRepository.UpdateContentAsync(x => x.Sort == x.Sort - 1,
x => x.TrackPushConfigId == entity.TrackPushConfigId && x.Sort > entity.Sort); x => x.TrackPushConfigId == entity.TrackPushConfigId && x.Sort > entity.Sort);
ts.Complete();
}
await _trackPushCacheService.SetPushContentConfigsAsync(entity.TrackPushConfigId);
break; break;
} }
@ -225,6 +219,14 @@ public class TrackPushService : ApplicationService
nameof(EditTrackPushContentInput.Options)]); 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; return true;
} }
@ -247,8 +249,19 @@ public class TrackPushService : ApplicationService
if (trackPushContentEntities.Count > 0) if (trackPushContentEntities.Count > 0)
{ {
using var ts = TransactionScopeHelper.Create();
await _trackPushConfigRepository.UpdateContentRangeAsync(trackPushContentEntities); 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; return true;