feat: 抽象出轨迹发生地和轨迹时区的逻辑
This commit is contained in:
parent
0b47412077
commit
a3e395a272
@ -19,11 +19,11 @@ namespace SJZY.Track.Application.CAP.EventHandlers;
|
|||||||
|
|
||||||
public class TrackRefreshEventHandler : ITransientDependency, ICapSubscribe
|
public class TrackRefreshEventHandler : ITransientDependency, ICapSubscribe
|
||||||
{
|
{
|
||||||
private readonly IOrderRepository _orderRepository;
|
|
||||||
private readonly ICapPublisher _capPublisher;
|
private readonly ICapPublisher _capPublisher;
|
||||||
private readonly ITrackPullCacheService _trackPullCacheService;
|
private readonly IOrderRepository _orderRepository;
|
||||||
private readonly ITrackDetailsRepository _trackDetailsRepository;
|
|
||||||
private readonly ITimezoneQueries _timezoneQueries;
|
private readonly ITimezoneQueries _timezoneQueries;
|
||||||
|
private readonly ITrackDetailsRepository _trackDetailsRepository;
|
||||||
|
private readonly ITrackPullCacheService _trackPullCacheService;
|
||||||
|
|
||||||
public TrackRefreshEventHandler(IOrderRepository orderRepository,
|
public TrackRefreshEventHandler(IOrderRepository orderRepository,
|
||||||
ICapPublisher capPublisher, ITrackPullCacheService trackPullCacheService,
|
ICapPublisher capPublisher, ITrackPullCacheService trackPullCacheService,
|
||||||
@ -173,37 +173,18 @@ public class TrackRefreshEventHandler : ITransientDependency, ICapSubscribe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 轨迹发生地
|
|
||||||
var trackPlace = paramConfig.TrackPlaceName == null
|
|
||||||
? null
|
|
||||||
: trackToken[paramConfig.TrackPlaceName]?.Value<string>();
|
|
||||||
var hasPlaceBottomLine = false; //执行了兜底但是没有兜底住,需要记录
|
|
||||||
if (trackPlace.IsNullOrWhiteSpace() && matchedContentConfig?.TrackPlaceValue != null && matchedContentConfig.TrackPlaceValue.HasValue)
|
|
||||||
{
|
|
||||||
//兜底没配置的就不需要兜底,拉取的发生地没就没
|
|
||||||
trackPlace = await GetPlaceByOrder(matchedContentConfig!.TrackPlaceValue.Value,context.OrderId);
|
|
||||||
hasPlaceBottomLine = string.IsNullOrWhiteSpace(trackPlace);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 轨迹发生时间
|
// 轨迹发生时间
|
||||||
var trackTime = paramConfig.TrackTimeName == null
|
var trackTime = paramConfig.TrackTimeName == null
|
||||||
? null
|
? null
|
||||||
: trackToken[paramConfig.TrackTimeName]?.Value<DateTime>();
|
: trackToken[paramConfig.TrackTimeName]?.Value<DateTime>();
|
||||||
// 轨迹发生时区
|
|
||||||
var trackTimeZone = paramConfig.TrackTimeZoneName == null
|
|
||||||
? null
|
|
||||||
: trackToken[paramConfig.TrackTimeZoneName]?.Value<float>();
|
|
||||||
|
|
||||||
// todo:兜底时区是slow path
|
// 轨迹时区
|
||||||
var hasTimezoneBottomLine = false; //执行了兜底但是没有兜底住,需要记录
|
var (trackTimeZone, hasTimezoneBottomLine) =
|
||||||
if (!trackTimeZone.HasValue && matchedContentConfig?.TrackZonePlaceValue is not null)
|
await GetTimezone(paramConfig, matchedContentConfig, context.OrderId, trackToken);
|
||||||
{
|
|
||||||
//兜底没配置的就不需要兜底,拉取的发生地没就没
|
|
||||||
var timezone= await GetTimezone(matchedContentConfig,context.OrderId);
|
|
||||||
|
|
||||||
trackTimeZone = timezone;
|
// 轨迹发生地
|
||||||
hasTimezoneBottomLine = !timezone.HasValue;
|
var (trackPlace, hasPlaceBottomLine) =
|
||||||
}
|
await GetTrackPlace(paramConfig, matchedContentConfig, context.OrderId, trackToken);
|
||||||
|
|
||||||
if (matchedContentConfig is null)
|
if (matchedContentConfig is null)
|
||||||
{
|
{
|
||||||
@ -272,13 +253,70 @@ public class TrackRefreshEventHandler : ITransientDependency, ICapSubscribe
|
|||||||
await _capPublisher.PublishAsync(GlobalConst.TrackUpsertForRefreshSubscribe, trackUpsertEvent);
|
await _capPublisher.PublishAsync(GlobalConst.TrackUpsertForRefreshSubscribe, trackUpsertEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取轨迹时区
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="paramConfig">配置信息</param>
|
||||||
|
/// <param name="matchedContentConfig">配置信息</param>
|
||||||
|
/// <param name="orderId">订单id</param>
|
||||||
|
/// <param name="trackToken"></param>
|
||||||
|
/// <returns>时区,是否执行了兜底轨迹时区</returns>
|
||||||
|
private async Task<(float? trackTimeZone, bool hasTimezoneBottomLine)> GetTimezone(
|
||||||
|
TrackPullParamConfigDto paramConfig, TrackPullContentConfigDto? matchedContentConfig, int orderId,
|
||||||
|
JToken trackToken)
|
||||||
|
{
|
||||||
|
// 轨迹发生时区
|
||||||
|
var trackTimeZone = paramConfig.TrackTimeZoneName == null
|
||||||
|
? null
|
||||||
|
: trackToken[paramConfig.TrackTimeZoneName]?.Value<float>();
|
||||||
|
|
||||||
|
bool hasTimezoneBottomLine = false; //执行了兜底但是没有兜底住,需要记录
|
||||||
|
if (!trackTimeZone.HasValue && matchedContentConfig?.TrackZonePlaceValue is not null)
|
||||||
|
{
|
||||||
|
//兜底没配置的就不需要兜底,拉取的发生地没就没
|
||||||
|
var timezone = await GetTimezone(matchedContentConfig, orderId);
|
||||||
|
|
||||||
|
trackTimeZone = timezone;
|
||||||
|
hasTimezoneBottomLine = !timezone.HasValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (trackTimeZone, hasTimezoneBottomLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获得轨迹地址
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="paramConfig">配置信息</param>
|
||||||
|
/// <param name="matchedContentConfig">配置信息</param>
|
||||||
|
/// <param name="orderId">订单id</param>
|
||||||
|
/// <param name="trackToken"></param>
|
||||||
|
/// <returns>时区,是否执行了兜底轨迹时区</returns>
|
||||||
|
private async Task<(string? trackPlace, bool hasPlaceBottomLine)> GetTrackPlace(TrackPullParamConfigDto paramConfig,
|
||||||
|
TrackPullContentConfigDto? matchedContentConfig, int orderId, JToken trackToken)
|
||||||
|
{
|
||||||
|
// 轨迹发生地
|
||||||
|
var trackPlace = paramConfig.TrackPlaceName == null
|
||||||
|
? null
|
||||||
|
: trackToken[paramConfig.TrackPlaceName]?.Value<string>();
|
||||||
|
var hasPlaceBottomLine = false; //执行了兜底但是没有兜底住,需要记录
|
||||||
|
if (trackPlace.IsNullOrWhiteSpace() && matchedContentConfig?.TrackPlaceValue != null &&
|
||||||
|
matchedContentConfig.TrackPlaceValue.HasValue)
|
||||||
|
{
|
||||||
|
//兜底没配置的就不需要兜底,拉取的发生地没就没
|
||||||
|
trackPlace = await GetPlaceByOrder(matchedContentConfig!.TrackPlaceValue.Value, orderId);
|
||||||
|
hasPlaceBottomLine = string.IsNullOrWhiteSpace(trackPlace);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (trackPlace, hasPlaceBottomLine);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 根据订单id获取兜底位置
|
/// 根据订单id获取兜底位置
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="trackValue"></param>
|
/// <param name="trackValue"></param>
|
||||||
/// <param name="orderId"></param>
|
/// <param name="orderId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private Task<string?> GetPlaceByOrder(int trackValue,int orderId)
|
private Task<string?> GetPlaceByOrder(int trackValue, int orderId)
|
||||||
{
|
{
|
||||||
Expression<Func<OrderEntity, string?>> resultExpression =
|
Expression<Func<OrderEntity, string?>> resultExpression =
|
||||||
(TrackLocationValue)trackValue switch
|
(TrackLocationValue)trackValue switch
|
||||||
@ -291,7 +329,7 @@ public class TrackRefreshEventHandler : ITransientDependency, ICapSubscribe
|
|||||||
TrackLocationValue.LeaveCountry => x => x.LeaveCountry,
|
TrackLocationValue.LeaveCountry => x => x.LeaveCountry,
|
||||||
_ => x => x.LeaveCountry
|
_ => x => x.LeaveCountry
|
||||||
};
|
};
|
||||||
return _orderRepository.GetFirstAsync(x => x.Id == orderId, resultExpression);
|
return _orderRepository.GetFirstAsync(x => x.Id == orderId, resultExpression);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -300,13 +338,12 @@ public class TrackRefreshEventHandler : ITransientDependency, ICapSubscribe
|
|||||||
/// <param name="matchedContentConfig"></param>
|
/// <param name="matchedContentConfig"></param>
|
||||||
/// <param name="orderId"></param>
|
/// <param name="orderId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private async Task<float?> GetTimezone(TrackPullContentConfigDto matchedContentConfig,int orderId )
|
private async Task<float?> GetTimezone(TrackPullContentConfigDto matchedContentConfig, int orderId)
|
||||||
{
|
{
|
||||||
var placeOrCode = await GetPlaceByOrder(matchedContentConfig!.TrackZonePlaceValue.Value,orderId);
|
var placeOrCode = await GetPlaceByOrder(matchedContentConfig!.TrackZonePlaceValue.Value, orderId);
|
||||||
string timezone = null;
|
string timezone = null;
|
||||||
if (!string.IsNullOrEmpty(placeOrCode))
|
if (!string.IsNullOrEmpty(placeOrCode))
|
||||||
{
|
{
|
||||||
|
|
||||||
if (matchedContentConfig!.TrackZonePlaceValue.Value == (int)TrackLocationValue.ArrivalPort
|
if (matchedContentConfig!.TrackZonePlaceValue.Value == (int)TrackLocationValue.ArrivalPort
|
||||||
|| matchedContentConfig!.TrackZonePlaceValue.Value == (int)TrackLocationValue.LeavePort)
|
|| matchedContentConfig!.TrackZonePlaceValue.Value == (int)TrackLocationValue.LeavePort)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user