Merge remote-tracking branch 'origin/S03-轨迹中台优化项' into test

This commit is contained in:
dingenwen 2024-04-25 10:52:56 +08:00
commit 34d2469067
3 changed files with 59 additions and 35 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;
await _orderRepository.UpdateColumnAsync(order, x => new
{
x.QuestionType, x.LatestPushError
});
} }
else else
{ {
// 还原成正常态
order.QuestionType = (int)TrackProblemType.None; order.QuestionType = (int)TrackProblemType.None;
order.LatestPushError = null; order.LatestPushError = null;
if (log.OptionType == OptionType.新增.ToString()) order.LatestPushTrackCode = log.TrackCode;
order.LatestPushTime = log.CreateTime;
await _orderRepository.UpdateColumnAsync(order, x => new
{ {
// tips:只有新增会影响推送进度? x.LatestPushTrackCode, x.LatestPushTime, x.QuestionType, x.LatestPushError
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
{
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);
@ -144,12 +145,18 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
} }
} }
string asciiString = Base64Helper.SerializeObject(OptionType.新增.ToString());
if (items.Count == 0) return; if (items.Count == 0) return;
await _httpClientProxy.Service.BatchForwardThenPushToQueueAsync(InterfaceRelayConst.PushTrackInterfaceCode,
string asciiString = Base64Helper.SerializeObject(OptionType.新增.ToString());
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)
@ -179,9 +186,17 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
} }
if (items.Count == 0) return; if (items.Count == 0) return;
await _httpClientProxy.Service.BatchForwardThenPushToQueueAsync(InterfaceRelayConst.TrackUpdateInterfaceCode,
string asciiString = Base64Helper.SerializeObject(OptionType.修改.ToString());
var r = await _httpClientProxy.Service.BatchForwardThenPushToQueueAsync(
InterfaceRelayConst.TrackUpdateInterfaceCode,
_pushConfigs.First().ServiceProviderCode, items, GlobalConst.TrackPushCompletedSubscribe, _pushConfigs.First().ServiceProviderCode, items, GlobalConst.TrackPushCompletedSubscribe,
attach: OptionType.修改.ToString()); 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)

View File

@ -39,25 +39,33 @@ public class TrackPushService : ApplicationService
{ {
input.OrderNos = input.OrderNos.Where(x => !x.IsNullOrWhiteSpace()).Distinct().ToList(); // 单号去重、去空 input.OrderNos = input.OrderNos.Where(x => !x.IsNullOrWhiteSpace()).Distinct().ToList(); // 单号去重、去空
var orderIds = await _orderRepository.GetArrayAsync(x => var orders = await _orderRepository.GetArrayAsync(x =>
x.OrderType == input.OrderType && input.OrderNos.Contains(x.OrderNo), x => x.Id); x.OrderType == input.OrderType && input.OrderNos.Contains(x.OrderNo), x => new
{
x.Id, x.SubSystemId, x.CustomId
});
if (!orderIds.Any()) if (!orders.Any())
{ {
throw new BusinessException(message: "一个订单都不存在"); throw new BusinessException(message: "一个订单都不存在");
} }
var trackPushEvent = new TrackPushEvent foreach (var group in orders.GroupBy(x => new { x.SubSystemId, x.CustomId }))
{ {
OptionType = OptionType.新增, var trackPushEvent = new TrackPushEvent
OrderIds = orderIds, {
TrackCode = input.TrackCode, OptionType = OptionType.新增,
OperationMan = CurrentUserRequest.CurrentUser.Name, SubSystemId = group.Key.SubSystemId,
}; CustomId = group.Key.CustomId,
OrderIds = group.Select(x => x.Id).ToArray(),
TrackCode = input.TrackCode,
OperationMan = CurrentUserRequest.CurrentUser.Name,
};
await _capPublisher.PublishAsync(GlobalConst.TrackPushSubscribe, trackPushEvent); await _capPublisher.PublishAsync(GlobalConst.TrackPushSubscribe, trackPushEvent);
}
return $"即将推送轨迹代码{input.TrackCode}给{orderIds.Length}个订单"; return $"即将推送轨迹代码{input.TrackCode}给{orders.Length}个订单";
} }