Merge remote-tracking branch 'origin/S06' into S06

# Conflicts:
#	src/SJZY.Track.Application/CAP/EventHandlers/TrackUpsertEventHandler.cs
This commit is contained in:
xiaolipro 2024-12-27 11:42:48 +08:00
commit b750579887
9 changed files with 89 additions and 77 deletions

View File

@ -129,4 +129,9 @@ public class BatchUpsertTrackInput : OrderNosInfo
/// 是否强制推送
/// </summary>
public bool ForcedPush { get; set; }
/// <summary>
/// 指定是否推送
/// </summary>
public bool IsToMq { get; set; }
}

View File

@ -133,4 +133,9 @@ public class UpsertTrackInput : OrderNoInfo
/// 是否强制推送
/// </summary>
public bool ForcedPush { get; set; }
/// <summary>
/// 指定是否推送
/// </summary>
public bool IsToMq { get; set; }
}

View File

@ -151,6 +151,10 @@ public class TrackUpsertEvent
/// </summary>
public bool ForcedPush { get; set; }
/// <summary>
/// 指定是否推送
/// </summary>
public bool IsToMq { get; set; }
public override string ToString()
{

View File

@ -5,7 +5,7 @@
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Version>7.0.9</Version>
<Version>7.0.10</Version>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>

View File

@ -69,6 +69,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
if (@event.ForcedPush)
{
//当为强制推送,会走手动推送逻辑
await DoPushAsync(@event);
return;
}
@ -95,7 +96,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
var items = new List<TrackPushInput>();
TrackPushContentConfigDto? config;
var isSystemPush = @event.OperationMan == null;
if (isSystemPush)
if (isSystemPush && !@event.ForcedPush)
{
foreach (var order in _orders)
{
@ -139,13 +140,18 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
if (config == null) return;
var tracks = await _trackDetailsEsRepository.GetListAsync(@event.OrderIds, @event.TrackCode);
tracks = tracks.DistinctBy(x => x.OrderId).ToList(); // 防止重复推送
if (tracks.Count == 0) return; // 一个能推的轨迹都不存在
// tips:人工推送只要能推就推了,不会校验已推和顺序问题,因为可能是更新
foreach (var track in tracks)
foreach (var order in _orders)
{
var order = _orders.First(x => x.Id == track.OrderId);
//取订单的下某个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 })
{
// 强制推送只需直接查出配置

View File

@ -15,12 +15,12 @@ namespace SJZY.Track.Application.CAP.EventHandlers;
public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
{
private readonly BroadcastingService _broadcastingService;
private readonly ICapPublisher _capPublisher;
private readonly IOrderOperationRecordEsRepository _orderOperationRecordEsRepository;
private readonly IOrderRepository _orderRepository;
private readonly IProvideQueries _provideQueries;
private readonly ITrackDetailsEsRepository _trackDetailsEsRepository;
private readonly BroadcastingService _broadcastingService;
private readonly IOrderOperationRecordEsRepository _orderOperationRecordEsRepository;
public TrackUpsertEventHandler(
IOrderRepository orderRepository,
@ -49,9 +49,8 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
var content = await HandleTrackAsync(@event, canNextOrderIds);
// 处理广播事件
if (content is { IsToMq: true })
// todo: review BroadcastingService抽一层接口,面向抽象编程
await _broadcastingService.TrackChangePublicTopicAsync(@event, content);
if (content != null && (content.IsToMq || @event.IsToMq))
_broadcastingService.TrackChangePublicTopicAsync(@event, content);
if (canNextOrderIds.Count == 0) return;
// 根据订单关联关系异步向下刷(异步)
@ -220,7 +219,7 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
Extra = @event.Extra
},
ForcedPush = @event.ForcedPush,
IsToMq = trackContent.IsToMq
IsToMq = (trackContent.IsToMq || @event.IsToMq)
};
await _capPublisher.PublishAsync(GlobalConst.TrackPushSubscribe, trackPushEvent);

View File

@ -70,7 +70,7 @@ public class TrackPushCompletedEventHandler : ITransientDependency, IRabbitHandl
// 推送广播
if (log.IsToMq)
await _broadcastingService.TrackPushCompletedPublicTopicAsync(log);
_broadcastingService.TrackPushCompletedPublicTopicAsync(log);
// 往es 写推送日志
await _trackPushRecordEsRepository.AddAsync(log);

View File

@ -26,47 +26,43 @@ public class BroadcastingService : ITransientDependency
/// <param name="eto"></param>
/// <param name="content"></param>
/// <returns></returns>
public Task TrackChangePublicTopicAsync(TrackUpsertEvent eto, TrackContentVO content)
public void TrackChangePublicTopicAsync(TrackUpsertEvent eto, TrackContentVO content)
{
return Task.Run(() =>
var data = new TrackChangeEto
{
var data = new TrackChangeEto
{
EstimatedDeliveryDate = eto.EstimatedDeliveryDate,
TrackPlacePostcode = eto.TrackPlacePostcode,
TrackPlaceNation = eto.TrackPlaceNation,
TrackPlaceNationId = eto.TrackPlaceNationId,
TrackPlaceProvince = eto.TrackPlaceProvince,
TrackPlaceProvinceId = eto.TrackPlaceProvinceId,
TrackPlaceCity = eto.TrackPlaceCity,
TrackPlaceCityId = eto.TrackPlaceCityId,
Files = eto.Files,
Remarks = eto.Remarks,
Source = eto.Source,
IsVisibility = eto.IsVisibility,
TrackTimeZone = eto.TrackTimeZone,
TrackTime = eto.TrackTime,
TrackPlace = eto.TrackPlace,
TrackStatusCode = content.TrackStatusCode,
EnStatus = eto.EnStatus,
Content = eto.Content,
TrackCode = eto.TrackCode,
OperationMan = eto.OperationMan,
OrderIdentifiers = eto.OrderIdentifiers,
CustomId = eto.CustomId,
SubSystemId = eto.SubSystemId,
Extra = eto.Extra
};
EstimatedDeliveryDate = eto.EstimatedDeliveryDate,
TrackPlacePostcode = eto.TrackPlacePostcode,
TrackPlaceNation = eto.TrackPlaceNation,
TrackPlaceNationId = eto.TrackPlaceNationId,
TrackPlaceProvince = eto.TrackPlaceProvince,
TrackPlaceProvinceId = eto.TrackPlaceProvinceId,
TrackPlaceCity = eto.TrackPlaceCity,
TrackPlaceCityId = eto.TrackPlaceCityId,
Files = eto.Files,
Remarks = eto.Remarks,
Source = eto.Source,
IsVisibility = eto.IsVisibility,
TrackTimeZone = eto.TrackTimeZone,
TrackTime = eto.TrackTime,
TrackPlace = eto.TrackPlace,
TrackStatusCode = content.TrackStatusCode,
EnStatus = eto.EnStatus,
Content = eto.Content,
TrackCode = eto.TrackCode,
OperationMan = eto.OperationMan,
OrderIdentifiers = eto.OrderIdentifiers,
CustomId = eto.CustomId,
SubSystemId = eto.SubSystemId,
Extra = eto.Extra
};
if (eto.IsAdd)
data.Option = 1;
else
data.Option = 3;
if (eto.IsAdd)
data.Option = 1;
else
data.Option = 3;
_rabbitClientBus.Publish(GlobalConst.TrackChangeExchange, $"TrackChange.{content.SubSystemCode}",
Encoding.UTF8.GetBytes(data.ToJson()));
return Task.CompletedTask;
});
_rabbitClientBus.Publish(GlobalConst.TrackChangeExchange, $"TrackChange.{content.SubSystemCode}",
Encoding.UTF8.GetBytes(data.ToJson()));
}
/// <summary>
@ -74,34 +70,29 @@ public class BroadcastingService : ITransientDependency
/// </summary>
/// <param name="log"></param>
/// <returns></returns>
public Task TrackPushCompletedPublicTopicAsync(TrackPushRecordIndex log)
public void TrackPushCompletedPublicTopicAsync(TrackPushRecordIndex log)
{
// todo: 不需要异步
return Task.Run(() =>
var data = new TrackPushCompletedEvent
{
var data = new TrackPushCompletedEvent
{
RequestId = log.RequestId,
IsSuccess = log.IsSuccess,
Message = log.Message,
OperationMan = log.CreateUser,
PushTime = DateTime.Now,
OptionType = log.OptionType,
IsManualPush = !string.Equals(log.CreateUser, GlobalConst.SystemUser), //操作人不为系统用户,则认为是仍推送
PushContent = log.PushContent,
OrderNo = log.OrderNo,
TrackStatus = log.TrackStatus,
TrackContent = log.TrackContent,
TrackTimeZone = log.TrackTimeZone,
TrackTime = log.TrackTime,
TrackPlace = log.TrackPlace,
TrackCode = log.TrackCode,
Extra = log.Extra
};
RequestId = log.RequestId,
IsSuccess = log.IsSuccess,
Message = log.Message,
OperationMan = log.CreateUser,
PushTime = DateTime.Now,
OptionType = log.OptionType,
IsManualPush = !string.Equals(log.CreateUser, GlobalConst.SystemUser), //操作人不为系统用户,则认为是仍推送
PushContent = log.PushContent,
OrderNo = log.OrderNo,
TrackStatus = log.TrackStatus,
TrackContent = log.TrackContent,
TrackTimeZone = log.TrackTimeZone,
TrackTime = log.TrackTime,
TrackPlace = log.TrackPlace,
TrackCode = log.TrackCode,
Extra = log.Extra
};
_rabbitClientBus.Publish(GlobalConst.TrackPushExchange, $"TrackPush.{log.SubSystemCode}",
Encoding.UTF8.GetBytes(data.ToJson()));
return Task.CompletedTask;
});
_rabbitClientBus.Publish(GlobalConst.TrackPushExchange, $"TrackPush.{log.SubSystemCode}",
Encoding.UTF8.GetBytes(data.ToJson()));
}
}

View File

@ -145,6 +145,7 @@ public partial class TrackService : ApplicationService, ITrackService
{
//todo:保留之前的方式 后续可去除
userInfo = await _requestCurrentUserService.Service.GetCurrentUserBasicInfoAsync(input.OptionUserId);
if (userInfo.Code != GlobalConst.SuccessCode || userInfo.Data is null)
//TODO: log || ex
throw new BusinessException(message: $"调用用户中心,获取用户信息失败:{userInfo.Msg}");
@ -477,7 +478,8 @@ public partial class TrackService : ApplicationService, ITrackService
EstimatedDeliveryDate = input.EstimatedDeliveryDate,
DestinationTimeZone = input.DestinationTimeZone,
Extra = input.Extra,
ForcedPush = input.ForcedPush
ForcedPush = input.ForcedPush,
IsToMq = input.IsToMq,
};
await _capPublisher.PublishAsync(GlobalConst.TrackUpsertSubscribe, @event);
}