update: 轨迹推送扩展参数修改为全量的轨迹明细扩展内容。

This commit is contained in:
hardstylewyl 2024-12-23 14:29:54 +08:00
parent 97bee1e3d9
commit 017cd7ffd4

View File

@ -97,7 +97,6 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
var items = new List<TrackPushInput>();
TrackPushContentConfigDto? config;
var isSystemPush = @event.OperationMan == null;
var trackPushInputDict = new Dictionary<TrackPushInput, TrackDetailsIndex>();
if (isSystemPush)
{
foreach (var order in _orders)
@ -128,7 +127,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
TrackTimeZone = @event.SystemPushInfo.TrackTimeZone,
CreateUser = GlobalConst.SystemUser,
};
var item = await BuiltPushItem(config, log);
var item = await BuiltPushItem(config, log, @event.SystemPushInfo.Extra);
item.Log = JsonConvert.SerializeObject(log);
items.Add(item);
}
@ -174,9 +173,8 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
TrackTimeZone = track.TrackTimeZone,
CreateUser = @event.OperationMan,
};
var item = await BuiltPushItem(config, log);
var item = await BuiltPushItem(config, log, track.Extra);
item.Log = JsonConvert.SerializeObject(log);
trackPushInputDict.Add(item, track);
items.Add(item);
}
}
@ -184,18 +182,18 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
if (items.Count == 0) return;
//获取参数结构名称
var paramNames = await GetExtraParamNamesAsync(@event.SubSystemCode);
//如果为系统推送,则从事件中取出轨迹扩展内容填充
foreach (var item in items)
{
//根据事件中轨迹扩展内容填充
if (isSystemPush)
item.Data.ForEach(dict => FillExtraParam(@event.SystemPushInfo.Extra, dict, paramNames));
//根据查出的轨迹中扩展内容填充
else
item.Data.ForEach(dict => FillExtraParam(trackPushInputDict[item].Extra, dict, paramNames));
}
// var paramNames = await GetExtraParamNamesAsync(@event.SubSystemCode);
//
// //如果为系统推送,则从事件中取出轨迹扩展内容填充
// foreach (var item in items)
// {
// //根据事件中轨迹扩展内容填充
// if (isSystemPush)
// item.Data.ForEach(dict => FillExtraParam(@event.SystemPushInfo.Extra, dict, paramNames));
// //根据查出的轨迹中扩展内容填充
// else
// item.Data.ForEach(dict => FillExtraParam(trackPushInputDict[item].Extra, dict, paramNames));
// }
using (Track2InterfaceRelaySubSystemContext.Use(
new Track2InterfaceRelaySubSystemContext(@event.SubSystemCode)))
@ -237,19 +235,19 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
TrackTimeZone = @event.SystemPushInfo.TrackTimeZone,
CreateUser = GlobalConst.SystemUser,
};
var item = BuiltUpdateItem(config, log);
var item = BuiltUpdateItem(config, log, @event.SystemPushInfo.Extra);
item.Log = JsonConvert.SerializeObject(log);
items.Add(item);
}
if (items.Count == 0) return;
//获取参数结构名称
var paramNames = await GetExtraParamNamesAsync(@event.SubSystemCode);
//根据事件中轨迹扩展内容填充请求
foreach (var item in items)
item.Data.ForEach(dict => FillExtraParam(@event.SystemPushInfo.Extra, dict, paramNames));
// //获取参数结构名称
// var paramNames = await GetExtraParamNamesAsync(@event.SubSystemCode);
//
// //根据事件中轨迹扩展内容填充请求
// foreach (var item in items)
// item.Data.ForEach(dict => FillExtraParam(@event.SystemPushInfo.Extra, dict, paramNames));
using (Track2InterfaceRelaySubSystemContext.Use(
new Track2InterfaceRelaySubSystemContext(@event.SubSystemCode)))
@ -267,16 +265,16 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
}
}
private TrackUpdateInput BuiltUpdateItem(TrackPushContentConfigDto config, TrackPushRecordIndex log)
private TrackUpdateInput BuiltUpdateItem(TrackPushContentConfigDto config, TrackPushRecordIndex log, string? extraJson)
{
var trackDatetime = log.TrackTime.AddHours(config.TrackTimeZone ?? log.TrackTimeZone - log.TrackTimeZone);
var trackDateStr = DateTimeFormat(trackDatetime, config.TrackTimeZone ?? log.TrackTimeZone, config);
var body = new TrackUpdateInput
{
OrderNo = log.OrderNo,
OrderNo = log.OrderNo
};
var dict = new Dictionary<string, object>()
var dict = new Dictionary<string, object?>()
{
//推真实的发生地和发生时间(时间是计算后的)
{ "location", log.TrackPlace },
@ -286,7 +284,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
{ "descriptionCn", config.TrackContentValue },
{ "code", config.TrackContentCodeValue },
{ "status", config.TrackStatusValue },
{ "extra", config.ExpandFieldsValue }
{ "extra", DeserializeForTextJson<object>(extraJson) }
};
body.Data.Add(dict);
log.PushContent = body.ToJson();
@ -294,7 +292,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
return body;
}
private async Task<TrackPushInput> BuiltPushItem(TrackPushContentConfigDto config, TrackPushRecordIndex log)
private async Task<TrackPushInput> BuiltPushItem(TrackPushContentConfigDto config, TrackPushRecordIndex log, string? extraJson)
{
var trackDatetime = log.TrackTime.AddHours(config.TrackTimeZone ?? log.TrackTimeZone - log.TrackTimeZone);
var trackDateStr = DateTimeFormat(trackDatetime, config.TrackTimeZone ?? log.TrackTimeZone, config);
@ -303,7 +301,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
{
OrderNo = log.OrderNo,
};
var dict = new Dictionary<string, object>()
var dict = new Dictionary<string, object?>()
{
// 推真实的发生地和发生时间(时间是计算后的)
{ "location", log.TrackPlace },
@ -313,7 +311,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
{ "descriptionCn", config.TrackContentValue },
{ "code", config.TrackContentCodeValue },
{ "status", config.TrackStatusValue },
{ "extra", config.ExpandFieldsValue }
{ "extra", DeserializeForTextJson<object>(extraJson) }
};
body.Data.Add(dict);
@ -322,12 +320,12 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
var history = await _trackPushRecordEsRepository.GetLatestTrackPushRecordAsync(log.OrderId);
if (history != default)
{
body = JsonConvert.DeserializeObject<TrackPushInput>(history.PushContent);
body = DeserializeForTextJson<TrackPushInput>(history.PushContent);
body!.Data.Add(dict);
}
}
log.PushContent = body.ToJson();
log.PushContent = SerializeForTextJson(body);
return body;
}
@ -381,6 +379,15 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
return dateTime.ToString("yyyy-MM-ddTHH:mm:ss.fffK");
}
private string SerializeForTextJson(object? obj)
{
return obj == null ? string.Empty : System.Text.Json.JsonSerializer.Serialize(obj);
}
private T? DeserializeForTextJson<T>(string? json)
{
return string.IsNullOrWhiteSpace(json) ? default : System.Text.Json.JsonSerializer.Deserialize<T>(json);
}
/// <summary>
/// 获取来源系统接口的参数名
/// </summary>
@ -430,7 +437,6 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
}
}
private Dictionary<string, object> ExtractTrackExtraDict(string trackExtraStr)
{
var dict = new Dictionary<string, object>();