feat: 轨迹推送extra

This commit is contained in:
xiaolipro 2026-03-05 10:54:39 +08:00
parent ecce6b62b4
commit a431ec7ec7
12 changed files with 120 additions and 22 deletions

View File

@ -5,6 +5,7 @@ using Fake.UnitOfWork;
using InterfaceForward.Domain.Shared.Helpers;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using TrackCenter.Application.Dtos.TrackPush;
using TrackCenter.Application.Events;
using TrackCenter.Application.Helpers;
@ -30,7 +31,9 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
private readonly BroadcastingService _broadcastingService;
private List<OrderEntity> _orders = null!;
private List<TrackPushContentConfigDto> _pushConfigs = null!;
private Dictionary<TrackOrderType, List<TrackPushContentConfigDto>> _orderTypeSortedConfigsDict = null!; //订单类型,根据sort从小到大排序后的配置字典
private Dictionary<TrackOrderType, List<TrackPushContentConfigDto>>
_orderTypeSortedConfigsDict = null!; //订单类型,根据sort从小到大排序后的配置字典
public TrackPushEventHandler(
IOrderRepository orderRepository,
@ -155,7 +158,8 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
// tips:不同订单类型可能会有不同的顺序
if (!_orderTypeSortedConfigsDict.TryGetValue(order.OrderType, out var sortedConfigs))
{
TrackPushFailedPublicTopic($"应用:[{@event.AppKey}],客户:[{@event.Customer}],没有订单类型[{order.OrderType}]的推送映射配置", @event, order);
TrackPushFailedPublicTopic(
$"应用:[{@event.AppKey}],客户:[{@event.Customer}],没有订单类型[{order.OrderType}]的推送映射配置", @event, order);
continue;
}
@ -164,7 +168,8 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
if (config == null)
{
TrackPushFailedPublicTopic($"针对于订单类型[{order.OrderType}]没有找到轨迹代码[{@event.TrackCode}]对应的配置", @event, order);
TrackPushFailedPublicTopic($"针对于订单类型[{order.OrderType}]没有找到轨迹代码[{@event.TrackCode}]对应的配置", @event,
order);
continue;
}
@ -176,7 +181,8 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
if (config == null)
{
TrackPushFailedPublicTopic($"推送顺序有误,针对于订单类型[{order.OrderType}],轨迹代码[{@event.TrackCode}]", @event, order);
TrackPushFailedPublicTopic($"推送顺序有误,针对于订单类型[{order.OrderType}],轨迹代码[{@event.TrackCode}]", @event,
order);
return;
}
@ -209,7 +215,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
CreateUser = @event.OperationMan,
IsToMq = @event.IsToMq,
};
var item = await BuiltPushItem(config, log, @event.SystemPushInfo.CompareFields);
var item = await BuiltPushItem(config, log, @event.SystemPushInfo.CompareFields, order);
item.Log = JsonConvert.SerializeObject(log);
items.Add(item);
}
@ -222,7 +228,8 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
// tips:不同订单类型可能会有不同的顺序
if (!_orderTypeSortedConfigsDict.TryGetValue(order.OrderType, out var sortedConfigs))
{
TrackPushFailedPublicTopic($"应用:[{@event.AppKey}],客户:[{@event.Customer}],没有订单类型[{order.OrderType}]的推送映射配置", @event, order);
TrackPushFailedPublicTopic(
$"应用:[{@event.AppKey}],客户:[{@event.Customer}],没有订单类型[{order.OrderType}]的推送映射配置", @event, order);
continue;
}
@ -230,8 +237,9 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
var config = sortedConfigs.FirstOrDefault(x => x.TrackCode == @event.TrackCode);
if (config == null)
{
TrackPushFailedPublicTopic($"应用:[{@event.AppKey}],客户:[{@event.Customer}],没有订单类型[{order.OrderType}]的推送映射配置," +
$"没有在推送映射配置中找到关于轨迹代码[{@event.TrackCode}]的配置", @event, order);
TrackPushFailedPublicTopic(
$"应用:[{@event.AppKey}],客户:[{@event.Customer}],没有订单类型[{order.OrderType}]的推送映射配置," +
$"没有在推送映射配置中找到关于轨迹代码[{@event.TrackCode}]的配置", @event, order);
return;
}
@ -290,7 +298,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
CreateUser = GlobalConst.SystemUser,
IsToMq = @event.IsToMq,
};
var item = await BuiltPushItem(config, log, @event.SystemPushInfo.CompareFields);
var item = await BuiltPushItem(config, log, @event.SystemPushInfo.CompareFields, order);
item.Log = JsonConvert.SerializeObject(log);
items.Add(item);
}
@ -307,7 +315,8 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
// tips:不同订单类型可能会有不同的顺序
if (!_orderTypeSortedConfigsDict.TryGetValue(order.OrderType, out var sortedConfigs))
{
TrackPushFailedPublicTopic($"应用:[{@event.AppKey}],客户:[{@event.Customer}],没有订单类型[{order.OrderType}]的推送映射配置", @event, order);
TrackPushFailedPublicTopic(
$"应用:[{@event.AppKey}],客户:[{@event.Customer}],没有订单类型[{order.OrderType}]的推送映射配置", @event, order);
continue;
}
@ -315,7 +324,8 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
config = sortedConfigs.FirstOrDefault(x => x.TrackCode == @event.TrackCode);
if (config == null)
{
TrackPushFailedPublicTopic($"针对于订单类型[{order.OrderType}]没有找到轨迹代码[{@event.TrackCode}]对应的配置", @event, order);
TrackPushFailedPublicTopic($"针对于订单类型[{order.OrderType}]没有找到轨迹代码[{@event.TrackCode}]对应的配置", @event,
order);
continue;
}
@ -348,7 +358,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
CreateUser = GlobalConst.SystemUser,
IsToMq = @event.IsToMq,
};
var item = BuiltUpdateItem(config, log);
var item = BuiltUpdateItem(config, log, order);
item.Log = JsonConvert.SerializeObject(log);
items.Add(item);
}
@ -377,7 +387,8 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
}
// 构建更新推送请求体
private static TrackUpdateInput BuiltUpdateItem(TrackPushContentConfigDto config, TrackPushRecordIndex log)
private static TrackUpdateInput BuiltUpdateItem(TrackPushContentConfigDto config, TrackPushRecordIndex log,
OrderEntity order)
{
var trackDatetime = log.TrackTime.AddHours(log.TrackTimeZone - log.TrackTimeZone);
var trackDateStr = DateTimeFormat(trackDatetime, log.TrackTimeZone, config);
@ -399,7 +410,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
{ "descriptionCn", config.TrackContentValue },
{ "code", config.TrackContentCodeValue },
{ "status", config.TrackStatusValue },
{ "extra", TextJsonHelper.Deserialize<object>(log.Extra) }
{ "extra", BuildExtraObject(log.Extra, config.ExtraConfig, order) }
};
body.Data.Add(dict);
log.PushContent = body.ToJson();
@ -408,7 +419,8 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
}
// 构建新增推送请求体
private async Task<TrackPushInput> BuiltPushItem(TrackPushContentConfigDto config, TrackPushRecordIndex log, string? compareFields)
private async Task<TrackPushInput> BuiltPushItem(TrackPushContentConfigDto config, TrackPushRecordIndex log,
string? compareFields, OrderEntity order)
{
var trackDatetime = log.TrackTime.AddHours(log.TrackTimeZone - log.TrackTimeZone);
var trackDateStr = DateTimeFormat(trackDatetime, log.TrackTimeZone, config);
@ -430,7 +442,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
{ "descriptionCn", config.TrackContentValue },
{ "code", config.TrackContentCodeValue },
{ "status", config.TrackStatusValue },
{ "extra", TextJsonHelper.Deserialize<object>(log.Extra) }
{ "extra", BuildExtraObject(log.Extra, config.ExtraConfig, order) }
};
body.Data.Add(cur);
@ -514,8 +526,48 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
return body;
}
private static JObject BuildExtraObject(string? logExtra, string? extraConfig, OrderEntity orderEntity)
{
var res = new JObject();
try
{
if (!logExtra.IsNullOrWhiteSpace())
{
res = JObject.Parse(logExtra!);
}
if (!extraConfig.IsNullOrWhiteSpace())
{
var extraDic = TextJsonHelper.Deserialize<Dictionary<string, string>>(extraConfig!);
foreach (var item in extraDic!)
{
if (item.Value.StartsWith("t_order_flight."))
{
}
else
{
var field = item.Value.RemovePrefix(StringComparison.OrdinalIgnoreCase, "t_order.");
if (field.IsNullOrWhiteSpace()) continue;
var value = orderEntity.GetType().GetProperty(field)?.GetValue(orderEntity);
res.Add(item.Key, JToken.FromObject(value ?? string.Empty));
}
}
}
return res;
}
catch (Exception e)
{
Log.Error($"轨迹推送build extra失败:{e}");
return new JObject();
}
}
// 尝试根据推送事件找推送映射配置
private static TrackPushContentConfigDto? GetValidPushConfigAsync(List<TrackPushContentConfigDto> cache, string? latestPushTrackCode, TrackPushEvent @event)
private static TrackPushContentConfigDto? GetValidPushConfigAsync(List<TrackPushContentConfigDto> cache,
string? latestPushTrackCode, TrackPushEvent @event)
{
var trackCode = @event.TrackCode;
var idx = cache.FindIndex(x => x.TrackCode == latestPushTrackCode);

View File

@ -53,4 +53,9 @@ public class EditTrackPushContentInput
/// 轨迹状态参数值
/// </summary>
public string? TrackStatusValue { get; set; }
/// <summary>
/// 拓展配置
/// </summary>
public string? ExtraConfig { get; set; }
}

View File

@ -88,6 +88,11 @@ public class TrackPushContentConfigDto
/// </summary>
public string? TrackStatusValue { get; set; }
/// <summary>
/// 拓展配置
/// </summary>
public string? ExtraConfig { get; set; }
/// <summary>
/// 时间格式枚举
/// </summary>

View File

@ -33,4 +33,9 @@ public class TrackPushContentDto
/// 服务商轨迹内容英文
/// </summary>
public string ContentEn { get; set; }
/// <summary>
/// 拓展配置
/// </summary>
public string ExtraConfig { get; set; }
}

View File

@ -90,7 +90,8 @@ public class TrackPushCacheService : ITransientDependency
TrackStatusValue = item.TrackStatusValue,
TrackContentCodeValue = item.TrackContentCodeValue,
TrackContentValue = item.TrackContentValue,
TrackEnContentValue = item.TrackEnContentValue
TrackEnContentValue = item.TrackEnContentValue,
ExtraConfig = item.ExtraConfig
}).ToList();
return res;

View File

@ -68,4 +68,10 @@ public class TrackPushContentConfigEntity : FullAuditedEntity<int, int>
/// </summary>
[SugarColumn(ColumnName = "TrackStatusValue")]
public string TrackStatusValue { get; set; }
/// <summary>
/// 拓展配置
/// </summary>
[SugarColumn(ColumnName = "ExtraConfig")]
public string ExtraConfig { get; set; }
}

View File

@ -51,4 +51,9 @@ public class GetTrackPushContentDetailOutputVO
/// 推送轨迹状态
/// </summary>
public string TrackStatusValue { get; set; }
/// <summary>
/// 拓展配置
/// </summary>
public string ExtraConfig { get; set; }
}

View File

@ -33,4 +33,9 @@ public class GetTrackPushContentListVo
/// 服务商轨迹内容英文
/// </summary>
public string ContentEn { get; set; }
/// <summary>
/// 拓展配置
/// </summary>
public string ExtraConfig { get; set; }
}

View File

@ -63,4 +63,9 @@ public class GetTrackPushContentPageOutputVO
/// 推送轨迹状态
/// </summary>
public string TrackStatusValue { get; set; }
/// <summary>
/// 拓展配置
/// </summary>
public string ExtraConfig { get; set; }
}

View File

@ -76,4 +76,9 @@ public class TrackPushContentConfigVO
/// 轨迹状态参数值
/// </summary>
public string? TrackStatusValue { get; set; }
/// <summary>
/// 拓展配置
/// </summary>
public string? ExtraConfig { get; set; }
}

View File

@ -63,7 +63,7 @@ public static class TextJsonHelper
return null;
}
var dict = System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, object?>>(dictString);
var dict = JsonSerializer.Deserialize<Dictionary<string, object?>>(dictString);
if (dict == null || !dict.TryGetValue(fieldName, out var value))
{
return null;

View File

@ -49,6 +49,7 @@ public class TrackPushConfigRepository : BasicRepository<TrackPushConfigEntity>,
Sort = pushContent.Sort,
OrderNoType = pushContent.OrderNoType,
ContentId = pushContent.TrackContentId,
ExtraConfig = pushContent.ExtraConfig
}, true)
.ToPagedListAsync(input.PageIndex, input.PageSize);
}
@ -83,7 +84,8 @@ public class TrackPushConfigRepository : BasicRepository<TrackPushConfigEntity>,
.Where(pushContent => pushContent.Id == id)
.Select(pushContent => new GetTrackPushContentDetailOutputVO
{
Id = pushContent.Id
Id = pushContent.Id,
ExtraConfig = pushContent.ExtraConfig
}, true)
.SingleAsync();
}
@ -140,7 +142,8 @@ public class TrackPushConfigRepository : BasicRepository<TrackPushConfigEntity>,
TrackContentCodeValue = b.TrackContentCodeValue,
TrackContentValue = b.TrackContentValue,
TrackEnContentValue = b.TrackEnContentValue,
TrackStatusValue = b.TrackStatusValue
TrackStatusValue = b.TrackStatusValue,
ExtraConfig = b.ExtraConfig
})
.ToListAsync();
}
@ -211,7 +214,8 @@ public class TrackPushConfigRepository : BasicRepository<TrackPushConfigEntity>,
ServiceCode = b.TrackContentCodeValue,
Status = b.TrackStatusValue,
Content = b.TrackContentValue,
ContentEn = b.TrackEnContentValue
ContentEn = b.TrackEnContentValue,
ExtraConfig = b.ExtraConfig
})
.ToListAsync();
}