feat:轨迹推送处理中,广播推送失败原因(配置存在与否/是否自动推送/订单类型是否一致/顺序/异常单/调用接口通失败)
This commit is contained in:
parent
94702e4c56
commit
8287e6a437
@ -30,7 +30,7 @@ public class TrackPushRecordDto
|
||||
/// <summary>
|
||||
/// 接口通请求Id
|
||||
/// </summary>
|
||||
public Guid RequestId { get; set; }
|
||||
public Guid? RequestId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 信息
|
||||
|
||||
@ -27,8 +27,9 @@ public class TrackPushCompletedEvent
|
||||
|
||||
/// <summary>
|
||||
/// 接口通请求Id
|
||||
/// 在请求接口通前被拦截,就不会有请求Id
|
||||
/// </summary>
|
||||
public Guid RequestId { get; set; }
|
||||
public Guid? RequestId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 信息
|
||||
|
||||
@ -27,4 +27,10 @@ public interface IBroadcastingService : ITransientDependency
|
||||
/// </summary>
|
||||
/// <param name="log"></param>
|
||||
void TrackPushCompletedPublicTopic(TrackPushRecordDto log);
|
||||
|
||||
/// <summary>
|
||||
/// 轨迹推送失败广播(推送前置被拦截,或调用接口通失败)
|
||||
/// </summary>
|
||||
/// <param name="log"></param>
|
||||
void TrackPushFailedPubilcTopic(TrackPushRecordDto log);
|
||||
}
|
||||
|
||||
@ -25,19 +25,23 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
|
||||
private readonly IOrderRepository _orderRepository;
|
||||
private readonly ITrackPushCacheService _trackPushCacheService;
|
||||
private readonly ITrackPushRecordEsRepository _trackPushRecordEsRepository;
|
||||
private readonly IBroadcastingService _broadcastingService;
|
||||
private List<OrderEntity> _orders = null!;
|
||||
private List<TrackPushContentConfigDto> _pushConfigs = null!;
|
||||
|
||||
public TrackPushEventHandler(IHttpClientProxy<IInterfaceForwardServiceV2> httpClientProxy,
|
||||
IOrderRepository orderRepository, ITrackPushCacheService trackPushCacheService,
|
||||
IOrderRepository orderRepository,
|
||||
ITrackPushCacheService trackPushCacheService,
|
||||
ITrackPushRecordEsRepository trackPushRecordEsRepository,
|
||||
IOptionsMonitor<InterfaceRelayParamsConfigOptions> options)
|
||||
IOptionsMonitor<InterfaceRelayParamsConfigOptions> options,
|
||||
IBroadcastingService broadcastingService)
|
||||
{
|
||||
_httpClientProxy = httpClientProxy;
|
||||
_orderRepository = orderRepository;
|
||||
_trackPushCacheService = trackPushCacheService;
|
||||
_trackPushRecordEsRepository = trackPushRecordEsRepository;
|
||||
_options = options;
|
||||
_broadcastingService = broadcastingService;
|
||||
}
|
||||
|
||||
[CapSubscribe(GlobalConst.TrackPushSubscribe, Group = GlobalConst.TrackPushSubscribe)]
|
||||
@ -97,16 +101,44 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
|
||||
var isSystemPush = @event.OperationMan == null;
|
||||
if (isSystemPush && !@event.ForcedPush)
|
||||
{
|
||||
config = _pushConfigs.FirstOrDefault(x => x.TrackCode == @event.TrackCode);
|
||||
foreach (var order in _orders)
|
||||
{
|
||||
if (order.QuestionType == (int) TrackProblemType.Error) continue; // 系统不推异常单,只能人工操作
|
||||
if (config == null)
|
||||
{
|
||||
TrackPushFailedPublicTopic($"没有在推送映射配置中找到关于轨迹代码[{@event.TrackCode}]的配置", @event, order);
|
||||
return;
|
||||
}
|
||||
|
||||
// 系统不推异常单,只能人工操作
|
||||
if (order.QuestionType == (int) TrackProblemType.Error)
|
||||
{
|
||||
TrackPushFailedPublicTopic("系统不推异常单,只能人工操作", @event, order);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 推送新增,需要根据上一次的推送 推断 本次推送 是否可行,为了约束顺序
|
||||
config = GetValidPushConfigAsync(_pushConfigs, order.LatestPushTrackCode, @event.TrackCode);
|
||||
if (config == null) continue;
|
||||
var (resultConfig, nextCode) = GetValidPushConfigAsync(_pushConfigs, order.LatestPushTrackCode, @event.TrackCode);
|
||||
if (resultConfig == null)
|
||||
{
|
||||
TrackPushFailedPublicTopic($"推送顺序异常,下一个要推送的应为[{nextCode}]", @event, order);
|
||||
continue;
|
||||
}
|
||||
config = resultConfig;
|
||||
|
||||
// 是否自动推送
|
||||
if (!config.IsAutoPush) continue;
|
||||
if (!config.IsAutoPush)
|
||||
{
|
||||
TrackPushFailedPublicTopic($"没有设置为自动推送,如果要推送请手动推送", @event, order);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 配置的类型如何和订单类型不一致则不允许推送
|
||||
if (config.OrderType != order.OrderType) continue;
|
||||
if (config.OrderType != order.OrderType)
|
||||
{
|
||||
TrackPushFailedPublicTopic($"订单类型{order.OrderType}和配置中的订单类型[{config.OrderType}]不一致,不能推送", @event, order);
|
||||
continue;
|
||||
}
|
||||
|
||||
var log = new TrackPushRecordIndex
|
||||
{
|
||||
@ -131,26 +163,42 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
|
||||
}
|
||||
// 手工或强制推送,不会校验已推和顺序问题,因为可能是更新
|
||||
else
|
||||
|
||||
{
|
||||
config = _pushConfigs.FirstOrDefault(x => x.TrackCode == @event.TrackCode);
|
||||
if (config == null) return;
|
||||
|
||||
foreach (var order in _orders)
|
||||
{
|
||||
if (config is { IsAllPush: true })
|
||||
if (config == null)
|
||||
{
|
||||
// 强制推送只需直接查出配置
|
||||
if (@event.ForcedPush)
|
||||
config = _pushConfigs.FirstOrDefault(x => x.TrackCode == @event.TrackCode);
|
||||
// 推断 本次推送 是否可行
|
||||
else
|
||||
config = GetValidPushConfigAsync(_pushConfigs, order.LatestPushTrackCode, @event.TrackCode);
|
||||
TrackPushFailedPublicTopic($"没有在推送映射配置中找到关于轨迹代码[{@event.TrackCode}]的配置", @event, order);
|
||||
return;
|
||||
}
|
||||
|
||||
if (config is { IsAllPush: true })
|
||||
{
|
||||
// 非强制推送需要 推断 本次推送 是否可行
|
||||
if (!@event.ForcedPush)
|
||||
{
|
||||
var (resultConfig, nextCode) = GetValidPushConfigAsync(_pushConfigs, order.LatestPushTrackCode, @event.TrackCode);
|
||||
if (resultConfig == null)
|
||||
{
|
||||
TrackPushFailedPublicTopic($"推送顺序异常,下一个要推送的应为[{nextCode}]", @event, order);
|
||||
continue;
|
||||
}
|
||||
|
||||
config = resultConfig;
|
||||
}
|
||||
|
||||
// tips:强制推送直接使用配置
|
||||
}
|
||||
|
||||
if (config == null) continue;
|
||||
|
||||
//配置的类型如何和订单类型不一致则不允许推送
|
||||
if (config.OrderType != order.OrderType) continue;
|
||||
if (config.OrderType != order.OrderType)
|
||||
{
|
||||
TrackPushFailedPublicTopic($"订单类型{order.OrderType}和配置中的订单类型[{config.OrderType}]不一致,不能推送", @event, order);
|
||||
continue;
|
||||
}
|
||||
|
||||
var log = new TrackPushRecordIndex
|
||||
{
|
||||
@ -188,6 +236,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
|
||||
|
||||
if (r.Code != GlobalConst.SuccessCode)
|
||||
{
|
||||
TrackPushFailedPublicTopic($"轨迹中台调用接口通失败,RequestId: {r.RequestId}; Msg: {r.Msg}", @event, r.RequestId, items.Cast<dynamic>().ToList());
|
||||
throw new BusinessException(message: $"requestId: {r.RequestId}; serviceProviderCode:{serviceProviderCode} Msg: {r.Msg}");
|
||||
}
|
||||
}
|
||||
@ -202,7 +251,11 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
|
||||
foreach (var order in _orders)
|
||||
{
|
||||
//配置的类型如何和订单类型不一致则不允许推送
|
||||
if (config.OrderType != order.OrderType) continue;
|
||||
if (config.OrderType != order.OrderType)
|
||||
{
|
||||
TrackPushFailedPublicTopic($"订单类型{order.OrderType}和配置中的订单类型[{config.OrderType}]不一致,不能推送", @event, order);
|
||||
continue;
|
||||
}
|
||||
|
||||
var log = new TrackPushRecordIndex
|
||||
{
|
||||
@ -239,6 +292,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
|
||||
|
||||
if (r.Code != GlobalConst.SuccessCode)
|
||||
{
|
||||
TrackPushFailedPublicTopic($"轨迹中台调用接口通失败,RequestId: {r.RequestId}; Msg: {r.Msg}", @event, r.RequestId, items.Cast<dynamic>().ToList());
|
||||
throw new BusinessException(message: $"requestId: {r.RequestId}; serviceProviderCode:{serviceProviderCode} Msg: {r.Msg}");
|
||||
}
|
||||
}
|
||||
@ -330,7 +384,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
|
||||
/// 根据轨迹代码推断下一个(升序)要推送的内容,如果找不到或者已经是最后一个了
|
||||
/// 则查询有没有可交换的推送,没有就返回null
|
||||
/// </summary>
|
||||
private static TrackPushContentConfigDto? GetValidPushConfigAsync(List<TrackPushContentConfigDto> cache,
|
||||
private static (TrackPushContentConfigDto? config, string nextCode) GetValidPushConfigAsync(List<TrackPushContentConfigDto> cache,
|
||||
string? latestPushTrackCode, string? trackCode)
|
||||
{
|
||||
var idx = cache.FindIndex(x => x.TrackCode == latestPushTrackCode);
|
||||
@ -344,7 +398,10 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
|
||||
// find swap
|
||||
cache.FirstOrDefault(x => x.TrackCode == cache[idx + 1].SwapTrackCode);
|
||||
|
||||
return matched != null && matched.TrackCode == trackCode ? matched : default;
|
||||
//没推完,可能不符合推送顺序
|
||||
return matched != null && matched.TrackCode == trackCode
|
||||
? (matched, matched.TrackCode)
|
||||
: (default, matched?.TrackCode ?? cache[idx + 1].TrackCode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -391,4 +448,64 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//轨迹推送失败(被拦截)
|
||||
private void TrackPushFailedPublicTopic(
|
||||
string failedMessage,
|
||||
TrackPushEvent @event,
|
||||
OrderEntity order)
|
||||
{
|
||||
_broadcastingService.TrackPushFailedPubilcTopic(new TrackPushRecordDto
|
||||
{
|
||||
//还没请求接口通
|
||||
RequestId = null,
|
||||
IsSuccess = false,
|
||||
Message = failedMessage,
|
||||
OperationMan = @event.OperationMan,
|
||||
PushTime = DateTime.Now,
|
||||
OptionType = @event.OptionType.ToString(),
|
||||
IsManualPush = @event.OperationMan != null,
|
||||
//还没到构建推送内容那一步就被拦截
|
||||
PushContent = string.Empty,
|
||||
OrderNo = order.OrderNo,
|
||||
TrackStatus = @event.SystemPushInfo.TrackStatus,
|
||||
TrackContent = @event.SystemPushInfo.TrackStatus,
|
||||
TrackTimeZone = @event.SystemPushInfo.TrackTimeZone,
|
||||
TrackTime = @event.SystemPushInfo.TrackTime,
|
||||
TrackPlace = @event.SystemPushInfo.TrackPlace,
|
||||
TrackCode = @event.TrackCode,
|
||||
Extra = @event.SystemPushInfo.Extra,
|
||||
});
|
||||
}
|
||||
|
||||
//轨迹推送失败(请求接口通)
|
||||
private void TrackPushFailedPublicTopic(
|
||||
string failedMessage,
|
||||
TrackPushEvent @event,
|
||||
Guid requestId,
|
||||
List<dynamic> pushOrUpdateInputs)
|
||||
{
|
||||
foreach (var pushInput in pushOrUpdateInputs)
|
||||
{
|
||||
_broadcastingService.TrackPushFailedPubilcTopic(new TrackPushRecordDto
|
||||
{
|
||||
RequestId = requestId,
|
||||
IsSuccess = false,
|
||||
Message = failedMessage,
|
||||
OperationMan = @event.OperationMan,
|
||||
PushTime = DateTime.Now,
|
||||
OptionType = @event.OptionType.ToString(),
|
||||
IsManualPush = @event.OperationMan != null,
|
||||
PushContent = SerializeForTextJson(pushInput),
|
||||
OrderNo = pushInput.OrderNo,
|
||||
TrackStatus = @event.SystemPushInfo.TrackStatus,
|
||||
TrackContent = @event.SystemPushInfo.TrackStatus,
|
||||
TrackTimeZone = @event.SystemPushInfo.TrackTimeZone,
|
||||
TrackTime = @event.SystemPushInfo.TrackTime,
|
||||
TrackPlace = @event.SystemPushInfo.TrackPlace,
|
||||
TrackCode = @event.TrackCode,
|
||||
Extra = @event.SystemPushInfo.Extra,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,4 +111,10 @@ public class BroadcastingService : IBroadcastingService
|
||||
_rabbitClientBus.Publish(GlobalConst.TrackPushExchange, $"TrackPush.{log.SubSystemCode}",
|
||||
Encoding.UTF8.GetBytes(data.ToJson()));
|
||||
}
|
||||
|
||||
public void TrackPushFailedPubilcTopic(TrackPushRecordDto log)
|
||||
{
|
||||
//暂时使用推送完成模型,后续可能会出现有区分度的模型
|
||||
TrackPushCompletedPublicTopic(log);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user