diff --git a/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/BatchUpsertTrackInput.cs b/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/BatchUpsertTrackInput.cs
index 90e159cc..276ad83b 100644
--- a/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/BatchUpsertTrackInput.cs
+++ b/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/BatchUpsertTrackInput.cs
@@ -120,6 +120,11 @@ public class BatchUpsertTrackInput : OrderNosInfo
[Range(-12, 12)]
public float? DestinationTimeZone { get; set; }
+ ///
+ /// 重复的情况下,用什么比较
+ ///
+ public string? CompareFields { get; set; }
+
///
/// 扩展信息字段,用与轨迹推送的附加字段
///
diff --git a/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/UpsertTrackInput.cs b/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/UpsertTrackInput.cs
index 2b15e904..d7679cda 100644
--- a/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/UpsertTrackInput.cs
+++ b/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/UpsertTrackInput.cs
@@ -129,6 +129,11 @@ public class UpsertTrackInput : OrderNoInfo
///
public int OptionUserId { get; set; }
+ ///
+ /// 重复的情况下,用什么比较
+ ///
+ public string? CompareFields { get; set; }
+
///
/// 扩展信息字段,用与轨迹推送的附加字段
///
diff --git a/src/SJZY.Track.Application.Contract/Dtos/TrackPush/EditTrackPushConfigInput.cs b/src/SJZY.Track.Application.Contract/Dtos/TrackPush/EditTrackPushConfigInput.cs
index 745cdf56..9d7c58d9 100644
--- a/src/SJZY.Track.Application.Contract/Dtos/TrackPush/EditTrackPushConfigInput.cs
+++ b/src/SJZY.Track.Application.Contract/Dtos/TrackPush/EditTrackPushConfigInput.cs
@@ -44,10 +44,15 @@ public class EditTrackPushConfigInput
///
public bool? IsAllPush { get; set; }
+ ///
+ /// 是否全量推送
+ ///
+ public bool? IsAllPushWithLatest { get; set; }
+
///
/// 时间格式枚举
///
- public int DateTimeFormatType { get; set; }
+ public int? DateTimeFormatType { get; set; } = 0;
///
/// 日期时间格式模板
diff --git a/src/SJZY.Track.Application.Contract/Dtos/TrackPush/TrackPushContentConfigDto.cs b/src/SJZY.Track.Application.Contract/Dtos/TrackPush/TrackPushContentConfigDto.cs
index 345bec99..7c1c1568 100644
--- a/src/SJZY.Track.Application.Contract/Dtos/TrackPush/TrackPushContentConfigDto.cs
+++ b/src/SJZY.Track.Application.Contract/Dtos/TrackPush/TrackPushContentConfigDto.cs
@@ -17,6 +17,11 @@ public class TrackPushContentConfigDto
///
public bool IsAllPush { get; set; }
+ ///
+ /// 是否全量推送(最新轨迹)
+ ///
+ public bool IsAllPushWithLatest { get; set; }
+
///
/// 是否支持删除
///
diff --git a/src/SJZY.Track.Application.Contract/Dtos/TrackPush/TrackPushInput.cs b/src/SJZY.Track.Application.Contract/Dtos/TrackPush/TrackPushInput.cs
index 1111637f..eae08b81 100644
--- a/src/SJZY.Track.Application.Contract/Dtos/TrackPush/TrackPushInput.cs
+++ b/src/SJZY.Track.Application.Contract/Dtos/TrackPush/TrackPushInput.cs
@@ -19,15 +19,3 @@ public class TrackUpdateInput
public string Log { get; set; }
}
-
-public class TrackItem
-{
- public string Location { get; set; } = null!;
- public string Date { get; set; }
- public double TimeZone { get; set; }
- public string? Description { get; set; }
- public string? DescriptionCn { get; set; }
- public string? Code { get; set; }
- public string? Status { get; set; }
- public string? Extra { get; set; }
-}
diff --git a/src/SJZY.Track.Application.Contract/Dtos/TrackPush/TrackPushRecordDto.cs b/src/SJZY.Track.Application.Contract/Dtos/TrackPush/TrackPushRecordDto.cs
index 7bb84c1c..a2d88e3b 100644
--- a/src/SJZY.Track.Application.Contract/Dtos/TrackPush/TrackPushRecordDto.cs
+++ b/src/SJZY.Track.Application.Contract/Dtos/TrackPush/TrackPushRecordDto.cs
@@ -29,8 +29,9 @@ public class TrackPushRecordDto
///
/// 接口通请求Id
+ /// 在请求接口通前被拦截,就不会有请求Id
///
- public Guid RequestId { get; set; }
+ public Guid? RequestId { get; set; }
///
/// 信息
diff --git a/src/SJZY.Track.Application.Contract/Events/TrackPushCompletedEvent.cs b/src/SJZY.Track.Application.Contract/Events/TrackPushCompletedEvent.cs
index 6e3d3987..c7f4801d 100644
--- a/src/SJZY.Track.Application.Contract/Events/TrackPushCompletedEvent.cs
+++ b/src/SJZY.Track.Application.Contract/Events/TrackPushCompletedEvent.cs
@@ -27,8 +27,9 @@ public class TrackPushCompletedEvent
///
/// 接口通请求Id
+ /// 在请求接口通前被拦截,就不会有请求Id
///
- public Guid RequestId { get; set; }
+ public Guid? RequestId { get; set; }
///
/// 信息
diff --git a/src/SJZY.Track.Application.Contract/Events/TrackPushEvent.cs b/src/SJZY.Track.Application.Contract/Events/TrackPushEvent.cs
index ab033510..9be77fbc 100644
--- a/src/SJZY.Track.Application.Contract/Events/TrackPushEvent.cs
+++ b/src/SJZY.Track.Application.Contract/Events/TrackPushEvent.cs
@@ -80,6 +80,11 @@ public struct SystemPushStruct
///
public float TrackTimeZone { get; set; }
+ ///
+ /// 重复的情况下,用什么比较
+ ///
+ public string? CompareFields { get; set; }
+
///
/// 扩展信息字段,用与轨迹推送的附加字段
///
diff --git a/src/SJZY.Track.Application.Contract/Events/TrackUpsertEvent.cs b/src/SJZY.Track.Application.Contract/Events/TrackUpsertEvent.cs
index dbf754d7..fef7ab3f 100644
--- a/src/SJZY.Track.Application.Contract/Events/TrackUpsertEvent.cs
+++ b/src/SJZY.Track.Application.Contract/Events/TrackUpsertEvent.cs
@@ -146,6 +146,11 @@ public class TrackUpsertEvent
///
public float? DestinationTimeZone { get; set; }
+ ///
+ /// 重复的情况下,用什么比较
+ ///
+ public string? CompareFields { get; set; }
+
///
/// 扩展信息字段,用与轨迹推送的附加字段
///
diff --git a/src/SJZY.Track.Application.Contract/SJZY.Track.Application.Contract.csproj b/src/SJZY.Track.Application.Contract/SJZY.Track.Application.Contract.csproj
index 48722a57..f0778d54 100644
--- a/src/SJZY.Track.Application.Contract/SJZY.Track.Application.Contract.csproj
+++ b/src/SJZY.Track.Application.Contract/SJZY.Track.Application.Contract.csproj
@@ -5,7 +5,7 @@
net7.0
True
- 7.0.12
+ 7.0.14
True
diff --git a/src/SJZY.Track.Application.Contract/Services/IBroadcastingService.cs b/src/SJZY.Track.Application.Contract/Services/IBroadcastingService.cs
index 0f79f83d..4a1cb510 100644
--- a/src/SJZY.Track.Application.Contract/Services/IBroadcastingService.cs
+++ b/src/SJZY.Track.Application.Contract/Services/IBroadcastingService.cs
@@ -26,5 +26,11 @@ public interface IBroadcastingService : ITransientDependency
/// 轨迹推送完成广播(推送完成回调)
///
///
- void TrackPushCompletedPublicTopicAsync(TrackPushRecordDto log);
+ void TrackPushCompletedPublicTopic(TrackPushRecordDto log);
+
+ ///
+ /// 轨迹推送失败广播(推送前置被拦截,或调用接口通失败)
+ ///
+ ///
+ void TrackPushFailedPubilcTopic(TrackPushRecordDto log);
}
diff --git a/src/SJZY.Track.Application/CAP/EventHandlers/TrackDeleteEventHandler.cs b/src/SJZY.Track.Application/CAP/EventHandlers/TrackDeleteEventHandler.cs
index 7568071b..7e798eba 100644
--- a/src/SJZY.Track.Application/CAP/EventHandlers/TrackDeleteEventHandler.cs
+++ b/src/SJZY.Track.Application/CAP/EventHandlers/TrackDeleteEventHandler.cs
@@ -158,6 +158,7 @@ public class TrackDeleteEventHandler : ITransientDependency, ICapSubscribe
}
}
+ // todo:多个相同code的轨迹删除,也需要考虑??
private async Task> DeleteTrackAsync(TrackDeleteEvent @event)
{
List orderIds;
diff --git a/src/SJZY.Track.Application/CAP/EventHandlers/TrackPushEventHandler.cs b/src/SJZY.Track.Application/CAP/EventHandlers/TrackPushEventHandler.cs
index 14d063bc..1b5dab76 100644
--- a/src/SJZY.Track.Application/CAP/EventHandlers/TrackPushEventHandler.cs
+++ b/src/SJZY.Track.Application/CAP/EventHandlers/TrackPushEventHandler.cs
@@ -1,3 +1,4 @@
+using System.Text.Json;
using DotNetCore.CAP;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
@@ -10,7 +11,6 @@ using SJZY.Track.Application.Helpers;
using SJZY.Track.Application.Options;
using SJZY.Track.Application.Track2InterfaceRelay;
using SJZY.Track.Domain.Aggregates.OrderAggregate;
-using SJZY.Track.Domain.Aggregates.TrackDetailsAggregate;
using SJZY.Track.Domain.Aggregates.TrackPushAggregate;
using SJZY.Track.Domain.Enums;
using Volo.Abp.DependencyInjection;
@@ -23,23 +23,25 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
private readonly IHttpClientProxy _httpClientProxy;
private readonly IOptionsMonitor _options;
private readonly IOrderRepository _orderRepository;
- private readonly ITrackDetailsEsRepository _trackDetailsEsRepository;
private readonly ITrackPushCacheService _trackPushCacheService;
private readonly ITrackPushRecordEsRepository _trackPushRecordEsRepository;
+ private readonly IBroadcastingService _broadcastingService;
private List _orders = null!;
private List _pushConfigs = null!;
public TrackPushEventHandler(IHttpClientProxy httpClientProxy,
- IOrderRepository orderRepository, ITrackPushCacheService trackPushCacheService,
- ITrackDetailsEsRepository trackDetailsEsRepository, ITrackPushRecordEsRepository trackPushRecordEsRepository,
- IOptionsMonitor options)
+ IOrderRepository orderRepository,
+ ITrackPushCacheService trackPushCacheService,
+ ITrackPushRecordEsRepository trackPushRecordEsRepository,
+ IOptionsMonitor options,
+ IBroadcastingService broadcastingService)
{
_httpClientProxy = httpClientProxy;
_orderRepository = orderRepository;
_trackPushCacheService = trackPushCacheService;
- _trackDetailsEsRepository = trackDetailsEsRepository;
_trackPushRecordEsRepository = trackPushRecordEsRepository;
_options = options;
+ _broadcastingService = broadcastingService;
}
[CapSubscribe(GlobalConst.TrackPushSubscribe, Group = GlobalConst.TrackPushSubscribe)]
@@ -93,25 +95,50 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
private async Task DoPushAsync(TrackPushEvent @event)
{
+ // todo: 轨迹中台推送逻辑致使的未推送,也需要广播到mq,告知业务系统缘故
var items = new List();
TrackPushContentConfigDto? config;
var isSystemPush = @event.OperationMan == null;
if (isSystemPush && !@event.ForcedPush)
{
+ config = _pushConfigs.FirstOrDefault(x => x.TrackCode == @event.TrackCode);
foreach (var order in _orders)
{
- if (order.QuestionType == (int) TrackProblemType.Error) continue; // 系统不推异常单,只能人工操作
- // 强制推送只需直接查出配置
- if (@event.ForcedPush)
- config = _pushConfigs.FirstOrDefault(x => x.TrackCode == @event.TrackCode);
+ if (config == null)
+ {
+ TrackPushFailedPublicTopic($"没有在推送映射配置中找到关于轨迹代码[{@event.TrackCode}]的配置", @event, order);
+ return;
+ }
+
+ // 系统不推异常单,只能人工操作
+ if (order.QuestionType == (int) TrackProblemType.Error)
+ {
+ TrackPushFailedPublicTopic("系统不推异常单,只能人工操作", @event, order);
+ continue;
+ }
+
// 推送新增,需要根据上一次的推送 推断 本次推送 是否可行,为了约束顺序
- else
- config = GetValidPushConfigAsync(_pushConfigs, order.LatestPushTrackCode, @event.TrackCode);
- if (config == null) continue;
+ var (resultConfig, nextCode) = GetValidPushConfigAsync(_pushConfigs, order.LatestPushTrackCode, @event.TrackCode);
+ if (resultConfig == null)
+ {
+ TrackPushFailedPublicTopic($"推送顺序异常,下一个要推送的应为[{nextCode}]", @event, order);
+ continue;
+ }
+ config = resultConfig;
+
// 是否自动推送
- if (!config.IsAutoPush) continue;
+ if (!config.IsAutoPush)
+ {
+ TrackPushFailedPublicTopic($"没有设置为自动推送,如果要推送请手动推送", @event, order);
+ continue;
+ }
+
// 配置的类型如何和订单类型不一致则不允许推送
- if (config.OrderType != order.OrderType) continue;
+ if (config.OrderType != order.OrderType)
+ {
+ TrackPushFailedPublicTopic($"订单类型{order.OrderType}和配置中的订单类型[{config.OrderType}]不一致,不能推送", @event, order);
+ continue;
+ }
var log = new TrackPushRecordIndex
{
@@ -129,33 +156,49 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
IsToMq = @event.IsToMq,
Extra = @event.SystemPushInfo.Extra
};
- var item = await BuiltPushItem(config, log, @event.SystemPushInfo.Extra);
+ var item = await BuiltPushItem(config, log, @event.SystemPushInfo.CompareFields);
item.Log = JsonConvert.SerializeObject(log);
items.Add(item);
}
}
// 手工或强制推送,不会校验已推和顺序问题,因为可能是更新
else
+
{
config = _pushConfigs.FirstOrDefault(x => x.TrackCode == @event.TrackCode);
- if (config == null) return;
-
foreach (var order in _orders)
{
- if (config is { IsAllPush: true })
+ if (config == null)
{
- // 强制推送只需直接查出配置
- if (@event.ForcedPush)
- config = _pushConfigs.FirstOrDefault(x => x.TrackCode == @event.TrackCode);
- // 推断 本次推送 是否可行
- else
- config = GetValidPushConfigAsync(_pushConfigs, order.LatestPushTrackCode, @event.TrackCode);
+ TrackPushFailedPublicTopic($"没有在推送映射配置中找到关于轨迹代码[{@event.TrackCode}]的配置", @event, order);
+ return;
+ }
+
+ if (config is { IsAllPush: true })
+ {
+ // 非强制推送需要 推断 本次推送 是否可行
+ if (!@event.ForcedPush)
+ {
+ var (resultConfig, nextCode) = GetValidPushConfigAsync(_pushConfigs, order.LatestPushTrackCode, @event.TrackCode);
+ if (resultConfig == null)
+ {
+ TrackPushFailedPublicTopic($"推送顺序异常,下一个要推送的应为[{nextCode}]", @event, order);
+ continue;
+ }
+
+ config = resultConfig;
+ }
+
+ // tips:强制推送直接使用配置
}
- if (config == null) continue;
//配置的类型如何和订单类型不一致则不允许推送
- if (config.OrderType != order.OrderType) continue;
+ if (config.OrderType != order.OrderType)
+ {
+ TrackPushFailedPublicTopic($"订单类型{order.OrderType}和配置中的订单类型[{config.OrderType}]不一致,不能推送", @event, order);
+ continue;
+ }
var log = new TrackPushRecordIndex
{
@@ -173,7 +216,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
IsToMq = @event.IsToMq,
Extra = @event.SystemPushInfo.Extra
};
- var item = await BuiltPushItem(config, log, @event.SystemPushInfo.Extra);
+ var item = await BuiltPushItem(config, log, @event.SystemPushInfo.CompareFields);
item.Log = JsonConvert.SerializeObject(log);
items.Add(item);
}
@@ -193,6 +236,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
if (r.Code != GlobalConst.SuccessCode)
{
+ TrackPushFailedPublicTopic($"轨迹中台调用接口通失败,RequestId: {r.RequestId}; Msg: {r.Msg}", @event, r.RequestId, items.Cast().ToList());
throw new BusinessException(message: $"requestId: {r.RequestId}; serviceProviderCode:{serviceProviderCode} Msg: {r.Msg}");
}
}
@@ -207,7 +251,11 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
foreach (var order in _orders)
{
//配置的类型如何和订单类型不一致则不允许推送
- if (config.OrderType != order.OrderType) continue;
+ if (config.OrderType != order.OrderType)
+ {
+ TrackPushFailedPublicTopic($"订单类型{order.OrderType}和配置中的订单类型[{config.OrderType}]不一致,不能推送", @event, order);
+ continue;
+ }
var log = new TrackPushRecordIndex
{
@@ -225,7 +273,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
IsToMq = @event.IsToMq,
Extra = @event.SystemPushInfo.Extra
};
- var item = BuiltUpdateItem(config, log, @event.SystemPushInfo.Extra);
+ var item = BuiltUpdateItem(config, log);
item.Log = JsonConvert.SerializeObject(log);
items.Add(item);
}
@@ -244,12 +292,13 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
if (r.Code != GlobalConst.SuccessCode)
{
+ TrackPushFailedPublicTopic($"轨迹中台调用接口通失败,RequestId: {r.RequestId}; Msg: {r.Msg}", @event, r.RequestId, items.Cast().ToList());
throw new BusinessException(message: $"requestId: {r.RequestId}; serviceProviderCode:{serviceProviderCode} Msg: {r.Msg}");
}
}
}
- private TrackUpdateInput BuiltUpdateItem(TrackPushContentConfigDto config, TrackPushRecordIndex log, string? extraJson)
+ private TrackUpdateInput BuiltUpdateItem(TrackPushContentConfigDto config, TrackPushRecordIndex log)
{
var trackDatetime = log.TrackTime.AddHours(config.TrackTimeZone ?? log.TrackTimeZone - log.TrackTimeZone);
var trackDateStr = DateTimeFormat(trackDatetime, config.TrackTimeZone ?? log.TrackTimeZone, config);
@@ -268,7 +317,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
{ "descriptionCn", config.TrackContentValue },
{ "code", config.TrackContentCodeValue },
{ "status", config.TrackStatusValue },
- { "extra", DeserializeForTextJson