opt:接口通请求失败打印异常

This commit is contained in:
李鹏军 2024-04-25 10:43:39 +08:00
parent 96b3486956
commit 4cb5f465da
2 changed files with 35 additions and 21 deletions

View File

@ -65,8 +65,14 @@ public class TrackPushCompletedEventHandler : ITransientDependency, ICapSubscrib
private async Task TrackPushAfterUpdateOrderAsync(TrackPushRecordIndex log) private async Task TrackPushAfterUpdateOrderAsync(TrackPushRecordIndex log)
{ {
var order = new OrderEntity(); // tips:只有新增会影响推送进度?
order.Id = log.OrderId; if (log.OptionType != OptionType.新增.ToString()) return;
var order = new OrderEntity
{
Id = log.OrderId
};
/* /*
* 异常:最近一条推送是失败 * 异常:最近一条推送是失败
*/ */
@ -74,27 +80,22 @@ public class TrackPushCompletedEventHandler : ITransientDependency, ICapSubscrib
{ {
order.QuestionType = (int)TrackProblemType.Error; order.QuestionType = (int)TrackProblemType.Error;
order.LatestPushError = log.Message; order.LatestPushError = log.Message;
}
else
{
order.QuestionType = (int)TrackProblemType.None;
order.LatestPushError = null;
if (log.OptionType == OptionType.新增.ToString())
{
// tips:只有新增会影响推送进度?
order.LatestPushTrackCode = log.TrackCode;
order.LatestPushTime = DateTime.Now;
await _orderRepository.UpdateColumnAsync(order, x => new
{
x.LatestPushTrackCode, x.LatestPushTime, x.QuestionType, x.LatestPushError
});
return;
}
}
await _orderRepository.UpdateColumnAsync(order, x => new await _orderRepository.UpdateColumnAsync(order, x => new
{ {
x.QuestionType, x.LatestPushError x.QuestionType, x.LatestPushError
}); });
} }
else
{
// 还原成正常态
order.QuestionType = (int)TrackProblemType.None;
order.LatestPushError = null;
order.LatestPushTrackCode = log.TrackCode;
order.LatestPushTime = log.CreateTime;
await _orderRepository.UpdateColumnAsync(order, x => new
{
x.LatestPushTrackCode, x.LatestPushTime, x.QuestionType, x.LatestPushError
});
}
}
} }

View File

@ -44,9 +44,8 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
if (pushConfigs == null || pushConfigs.Count == 0) return; if (pushConfigs == null || pushConfigs.Count == 0) return;
_pushConfigs = pushConfigs; _pushConfigs = pushConfigs;
var errorType = (int)TrackProblemType.Error;
var orders = await _orderRepository.GetListAsync(x => var orders = await _orderRepository.GetListAsync(x =>
@event.OrderIds.Contains(x.Id) && x.QuestionType != errorType, x => new OrderEntity @event.OrderIds.Contains(x.Id), x => new OrderEntity
{ {
Id = x.Id, OrderNo = x.OrderNo, LatestPushTrackCode = x.LatestPushTrackCode, Id = x.Id, OrderNo = x.OrderNo, LatestPushTrackCode = x.LatestPushTrackCode,
OrderType = x.OrderType OrderType = x.OrderType
@ -80,6 +79,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
{ {
foreach (var order in _orders) foreach (var order in _orders)
{ {
if (order.QuestionType == (int)TrackProblemType.Error) continue; // 系统不推异常单,只能人工操作
// 推送新增,需要根据上一次的推送 推断 本次推送 是否可行 // 推送新增,需要根据上一次的推送 推断 本次推送 是否可行
config = GetValidPushConfigAsync(_pushConfigs, order.LatestPushTrackCode, @event.TrackCode); config = GetValidPushConfigAsync(_pushConfigs, order.LatestPushTrackCode, @event.TrackCode);
if (config == null) continue; if (config == null) continue;
@ -114,6 +114,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
if (tracks.Count == 0) return; // 一个能推的轨迹都不存在 if (tracks.Count == 0) return; // 一个能推的轨迹都不存在
// tips:人工推送只要能推就推了,不会校验已推和顺序问题,因为可能是更新
foreach (var track in tracks) foreach (var track in tracks)
{ {
var order = _orders.First(x => x.Id == track.OrderId); var order = _orders.First(x => x.Id == track.OrderId);
@ -147,9 +148,15 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
if (items.Count == 0) return; if (items.Count == 0) return;
string asciiString = Base64Helper.SerializeObject(OptionType.新增.ToString()); string asciiString = Base64Helper.SerializeObject(OptionType.新增.ToString());
await _httpClientProxy.Service.BatchForwardThenPushToQueueAsync(InterfaceRelayConst.PushTrackInterfaceCode, var r = await _httpClientProxy.Service.BatchForwardThenPushToQueueAsync(
InterfaceRelayConst.PushTrackInterfaceCode,
_pushConfigs.First().ServiceProviderCode, items, GlobalConst.TrackPushCompletedSubscribe, _pushConfigs.First().ServiceProviderCode, items, GlobalConst.TrackPushCompletedSubscribe,
attach: asciiString); attach: asciiString);
if (r.Code != InterfaceRelayConst.SuccessCode)
{
throw new BusinessException(message: r.Msg);
}
} }
private async Task DoUpdateAsync(TrackPushEvent @event) private async Task DoUpdateAsync(TrackPushEvent @event)
@ -181,9 +188,15 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
if (items.Count == 0) return; if (items.Count == 0) return;
string asciiString = Base64Helper.SerializeObject(OptionType.修改.ToString()); string asciiString = Base64Helper.SerializeObject(OptionType.修改.ToString());
await _httpClientProxy.Service.BatchForwardThenPushToQueueAsync(InterfaceRelayConst.TrackUpdateInterfaceCode, var r = await _httpClientProxy.Service.BatchForwardThenPushToQueueAsync(
InterfaceRelayConst.TrackUpdateInterfaceCode,
_pushConfigs.First().ServiceProviderCode, items, GlobalConst.TrackPushCompletedSubscribe, _pushConfigs.First().ServiceProviderCode, items, GlobalConst.TrackPushCompletedSubscribe,
attach: asciiString); attach: asciiString);
if (r.Code != InterfaceRelayConst.SuccessCode)
{
throw new BusinessException(message: r.Msg);
}
} }
private TrackUpdateInput BuiltUpdateItem(TrackPushContentConfigDto config, TrackPushRecordIndex log) private TrackUpdateInput BuiltUpdateItem(TrackPushContentConfigDto config, TrackPushRecordIndex log)