Merge branch 'S06' into test
This commit is contained in:
commit
802a2da8ad
@ -26,8 +26,6 @@ public class TrackChangeAfterUpdateOrderEventHandler : ITransientDependency, ICa
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//指示是否需要更新【预计签收时间】【签收地时区】
|
|
||||||
var isNeedUpdate = false;
|
|
||||||
var updateOrders = new List<OrderEntity>();
|
var updateOrders = new List<OrderEntity>();
|
||||||
foreach (var order in orders)
|
foreach (var order in orders)
|
||||||
{
|
{
|
||||||
@ -62,15 +60,12 @@ public class TrackChangeAfterUpdateOrderEventHandler : ITransientDependency, ICa
|
|||||||
{
|
{
|
||||||
order.EstimatedDeliveryDate = @event.EstimatedDeliveryDate.Value;
|
order.EstimatedDeliveryDate = @event.EstimatedDeliveryDate.Value;
|
||||||
order.DestinationTimeZone = @event.DestinationTimeZone.Value;
|
order.DestinationTimeZone = @event.DestinationTimeZone.Value;
|
||||||
isNeedUpdate = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateOrders.Add(order);
|
updateOrders.Add(order);
|
||||||
}
|
}
|
||||||
|
|
||||||
await _orderRepository.UpdateRangeAsync(updateOrders,
|
await _orderRepository.UpdateRangeAsync(updateOrders, x => new
|
||||||
isNeedUpdate
|
|
||||||
? x => new
|
|
||||||
{
|
{
|
||||||
x.IsCompleted,
|
x.IsCompleted,
|
||||||
x.LatestTrackContent,
|
x.LatestTrackContent,
|
||||||
@ -79,20 +74,9 @@ public class TrackChangeAfterUpdateOrderEventHandler : ITransientDependency, ICa
|
|||||||
x.LatestTrackTime,
|
x.LatestTrackTime,
|
||||||
x.LatestTrackTimeZone,
|
x.LatestTrackTimeZone,
|
||||||
x.DeficiencyTag,
|
x.DeficiencyTag,
|
||||||
//当标识指示需要更新时添加更新列
|
|
||||||
x.EstimatedDeliveryDate,
|
x.EstimatedDeliveryDate,
|
||||||
x.DestinationTimeZone
|
x.DestinationTimeZone
|
||||||
}
|
}
|
||||||
: x => new
|
|
||||||
{
|
|
||||||
x.IsCompleted,
|
|
||||||
x.LatestTrackContent,
|
|
||||||
x.LatestTrackEnContent,
|
|
||||||
x.LatestTrackPlace,
|
|
||||||
x.LatestTrackTime,
|
|
||||||
x.LatestTrackTimeZone,
|
|
||||||
x.DeficiencyTag,
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,6 +93,8 @@ public class TrackChangeAfterUpdateOrderEventHandler : ITransientDependency, ICa
|
|||||||
LatestTrackPlace = order.LatestTrackPlace,
|
LatestTrackPlace = order.LatestTrackPlace,
|
||||||
LatestTrackTime = order.LatestTrackTime,
|
LatestTrackTime = order.LatestTrackTime,
|
||||||
LatestTrackTimeZone = order.LatestTrackTimeZone,
|
LatestTrackTimeZone = order.LatestTrackTimeZone,
|
||||||
|
DestinationTimeZone = order.DestinationTimeZone,
|
||||||
|
EstimatedDeliveryDate = order.EstimatedDeliveryDate,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -134,86 +134,12 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
|
|||||||
items.Add(item);
|
items.Add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else //手工推送
|
// 手工或强制推送,不会校验已推和顺序问题,因为可能是更新
|
||||||
|
else
|
||||||
{
|
{
|
||||||
config = _pushConfigs.FirstOrDefault(x => x.TrackCode == @event.TrackCode);
|
config = _pushConfigs.FirstOrDefault(x => x.TrackCode == @event.TrackCode);
|
||||||
if (config == null) return;
|
if (config == null) return;
|
||||||
|
|
||||||
//使用事件参数传递要推送的轨迹
|
|
||||||
await ManualPushV2Async(@event, items, config);
|
|
||||||
goto Push;
|
|
||||||
var tracks = await _trackDetailsEsRepository.GetListAsync(@event.OrderIds, @event.TrackCode);
|
|
||||||
|
|
||||||
// tips:人工推送只要能推就推了,不会校验已推和顺序问题,因为可能是更新
|
|
||||||
foreach (var order in _orders)
|
|
||||||
{
|
|
||||||
//取订单的下某个code的最新创建时间的轨迹 防止重复推送
|
|
||||||
var track = tracks
|
|
||||||
.Where(x => x.OrderId == order.Id && x.TrackCode == @event.TrackCode)
|
|
||||||
.OrderByDescending(x => x.CreateTime)
|
|
||||||
.FirstOrDefault();
|
|
||||||
|
|
||||||
if (track == null) return; // 一个能推的轨迹都不存在
|
|
||||||
|
|
||||||
if (config is { IsAllPush: true })
|
|
||||||
{
|
|
||||||
// 强制推送只需直接查出配置
|
|
||||||
if (@event.ForcedPush)
|
|
||||||
config = _pushConfigs.FirstOrDefault(x => x.TrackCode == @event.TrackCode);
|
|
||||||
// 推断 本次推送 是否可行
|
|
||||||
else
|
|
||||||
config = GetValidPushConfigAsync(_pushConfigs, order.LatestPushTrackCode, @event.TrackCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config == null) continue;
|
|
||||||
|
|
||||||
//配置的类型如何和订单类型不一致则不允许推送
|
|
||||||
if (config.OrderType != order.OrderType) continue;
|
|
||||||
|
|
||||||
var log = new TrackPushRecordIndex
|
|
||||||
{
|
|
||||||
OptionType = @event.OptionType.ToString(),
|
|
||||||
OrderId = track.OrderId,
|
|
||||||
OrderNo = order.OrderNo,
|
|
||||||
TrackStatus = track.TrackStatus,
|
|
||||||
TrackCode = @event.TrackCode,
|
|
||||||
TrackContent = track.TrackContent,
|
|
||||||
TrackPlace = track.TrackPlace,
|
|
||||||
TrackTime = track.TrackTime,
|
|
||||||
TrackTimeZone = track.TrackTimeZone,
|
|
||||||
CreateUser = @event.OperationMan,
|
|
||||||
SubSystemCode = @event.SubSystemCode,
|
|
||||||
IsToMq = @event.IsToMq,
|
|
||||||
Extra = track.Extra
|
|
||||||
};
|
|
||||||
var item = await BuiltPushItem(config, log, track.Extra);
|
|
||||||
item.Log = JsonConvert.SerializeObject(log);
|
|
||||||
items.Add(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Push:
|
|
||||||
if (items.Count == 0) return;
|
|
||||||
|
|
||||||
using (Track2InterfaceRelaySubSystemContext.Use(
|
|
||||||
new Track2InterfaceRelaySubSystemContext(@event.SubSystemCode)))
|
|
||||||
{
|
|
||||||
var asciiString = Base64Helper.SerializeObject(OptionType.新增.ToString());
|
|
||||||
var r = await _httpClientProxy.Service.BatchForwardThenPushToQueueAsync(
|
|
||||||
_options.CurrentValue.PushTrackInterfaceCode,
|
|
||||||
_pushConfigs.First().ServiceProviderCode, items.Cast<object>().ToList(), GlobalConst.TrackPushCompletedSubscribe,
|
|
||||||
attach: asciiString);
|
|
||||||
|
|
||||||
if (r.Code != GlobalConst.SuccessCode)
|
|
||||||
{
|
|
||||||
throw new BusinessException(message: $"requestId: {r.RequestId}; {r.Msg}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task ManualPushV2Async(TrackPushEvent @event, List<TrackPushInput> items, TrackPushContentConfigDto? config)
|
|
||||||
{
|
|
||||||
// tips:人工推送只要能推就推了,不会校验已推和顺序问题,因为可能是更新
|
|
||||||
foreach (var order in _orders)
|
foreach (var order in _orders)
|
||||||
{
|
{
|
||||||
if (config is { IsAllPush: true })
|
if (config is { IsAllPush: true })
|
||||||
@ -253,6 +179,24 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (items.Count == 0) return;
|
||||||
|
|
||||||
|
using (Track2InterfaceRelaySubSystemContext.Use(
|
||||||
|
new Track2InterfaceRelaySubSystemContext(@event.SubSystemCode)))
|
||||||
|
{
|
||||||
|
var asciiString = Base64Helper.SerializeObject(OptionType.新增.ToString());
|
||||||
|
var r = await _httpClientProxy.Service.BatchForwardThenPushToQueueAsync(
|
||||||
|
_options.CurrentValue.PushTrackInterfaceCode,
|
||||||
|
_pushConfigs.First().ServiceProviderCode, items.Cast<object>().ToList(), GlobalConst.TrackPushCompletedSubscribe,
|
||||||
|
attach: asciiString);
|
||||||
|
|
||||||
|
if (r.Code != GlobalConst.SuccessCode)
|
||||||
|
{
|
||||||
|
throw new BusinessException(message: $"requestId: {r.RequestId}; {r.Msg}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async Task DoUpdateAsync(TrackPushEvent @event)
|
private async Task DoUpdateAsync(TrackPushEvent @event)
|
||||||
{
|
{
|
||||||
var config = _pushConfigs.FirstOrDefault(x => x.TrackCode == @event.TrackCode);
|
var config = _pushConfigs.FirstOrDefault(x => x.TrackCode == @event.TrackCode);
|
||||||
@ -372,11 +316,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
|
|||||||
/// 根据轨迹代码推断下一个(升序)要推送的内容,如果找不到或者已经是最后一个了
|
/// 根据轨迹代码推断下一个(升序)要推送的内容,如果找不到或者已经是最后一个了
|
||||||
/// 则查询有没有可交换的推送,没有就返回null
|
/// 则查询有没有可交换的推送,没有就返回null
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cache"></param>
|
private static TrackPushContentConfigDto? GetValidPushConfigAsync(List<TrackPushContentConfigDto> cache,
|
||||||
/// <param name="latestPushTrackCode"></param>
|
|
||||||
/// <param name="trackCode"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
TrackPushContentConfigDto? GetValidPushConfigAsync(List<TrackPushContentConfigDto> cache,
|
|
||||||
string? latestPushTrackCode, string? trackCode)
|
string? latestPushTrackCode, string? trackCode)
|
||||||
{
|
{
|
||||||
var idx = cache.FindIndex(x => x.TrackCode == latestPushTrackCode);
|
var idx = cache.FindIndex(x => x.TrackCode == latestPushTrackCode);
|
||||||
@ -396,11 +336,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 转换推送时间格式
|
/// 转换推送时间格式
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dateTime"></param>
|
private static string DateTimeFormat(DateTime dateTime, double timezone, TrackPushContentConfigDto config)
|
||||||
/// <param name="timezone"></param>
|
|
||||||
/// <param name="config"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
private string DateTimeFormat(DateTime dateTime, double timezone, TrackPushContentConfigDto config)
|
|
||||||
{
|
{
|
||||||
if (config.DateTimeFormatType == (int) DateTimeFormatEnum.Timestamp)
|
if (config.DateTimeFormatType == (int) DateTimeFormatEnum.Timestamp)
|
||||||
return DateTimeHelper.ConvertToUnixTimestamp(dateTime).ToString();
|
return DateTimeHelper.ConvertToUnixTimestamp(dateTime).ToString();
|
||||||
@ -417,12 +353,12 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
|
|||||||
return dateTime.ToString("yyyy-MM-ddTHH:mm:ss.fffK");
|
return dateTime.ToString("yyyy-MM-ddTHH:mm:ss.fffK");
|
||||||
}
|
}
|
||||||
|
|
||||||
private string SerializeForTextJson(object? obj)
|
private static string SerializeForTextJson(object? obj)
|
||||||
{
|
{
|
||||||
return obj == null ? string.Empty : System.Text.Json.JsonSerializer.Serialize(obj);
|
return obj == null ? string.Empty : System.Text.Json.JsonSerializer.Serialize(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
private T? DeserializeForTextJson<T>(string? json)
|
private static T? DeserializeForTextJson<T>(string? json)
|
||||||
{
|
{
|
||||||
return string.IsNullOrWhiteSpace(json) ? default : System.Text.Json.JsonSerializer.Deserialize<T>(json);
|
return string.IsNullOrWhiteSpace(json) ? default : System.Text.Json.JsonSerializer.Deserialize<T>(json);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user