update:轨迹新增/更新支持按扩展内容某个字段比较
This commit is contained in:
parent
2d6b239b8f
commit
5913929dcc
@ -120,6 +120,11 @@ public class BatchUpsertTrackInput : OrderNosInfo
|
||||
[Range(-12, 12)]
|
||||
public float? DestinationTimeZone { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 重复的情况下,用什么比较
|
||||
/// </summary>
|
||||
public string? CompareFields { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 扩展信息字段,用与轨迹推送的附加字段
|
||||
/// </summary>
|
||||
|
||||
@ -129,6 +129,11 @@ public class UpsertTrackInput : OrderNoInfo
|
||||
/// </summary>
|
||||
public int OptionUserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 重复的情况下,用什么比较
|
||||
/// </summary>
|
||||
public string? CompareFields { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 扩展信息字段,用与轨迹推送的附加字段
|
||||
/// </summary>
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
using System.Text.Json;
|
||||
using DotNetCore.CAP;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SJZY.Expand.ABP.Core.PublicMethords;
|
||||
using SJZY.InterfaceRelay.Application.Contracts;
|
||||
using SJZY.Track.Application.Contract.Dtos.TrackPush;
|
||||
@ -308,14 +308,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
|
||||
.WhereIf(!compareFields.IsNullOrWhiteSpace(), x =>
|
||||
{
|
||||
if (x["extra"] == null || log.Extra == null) return false;
|
||||
// todo:这里也改成统一使用system txt json,不用newtonsoft了
|
||||
var extra = JObject.FromObject(x["extra"]!);
|
||||
var curExtra = JObject.FromObject(log.Extra!);
|
||||
if (extra.TryGetValue(compareFields!, out var value) && curExtra.TryGetValue(compareFields!, out var curValue) )
|
||||
{
|
||||
return value == curValue;
|
||||
}
|
||||
return false;
|
||||
return EqExtraByFieldForTextJson(x["extra"]!, DeserializeForTextJson<JsonElement>(log.Extra)!, compareFields!);
|
||||
})
|
||||
.FirstOrDefault();
|
||||
if (old != null)
|
||||
@ -323,6 +316,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
|
||||
body.Data.Remove(old);
|
||||
}
|
||||
}
|
||||
|
||||
body!.Data.Add(cur);
|
||||
}
|
||||
}
|
||||
@ -383,10 +377,18 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
|
||||
return string.IsNullOrWhiteSpace(json) ? default : System.Text.Json.JsonSerializer.Deserialize<T>(json);
|
||||
}
|
||||
|
||||
private Dictionary<string, object>? GetExtraDictForTextJson(string? extraStr)
|
||||
//比较扩展中的某个字段的相等性
|
||||
private bool EqExtraByFieldForTextJson(object a, object b, string fieldName)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(extraStr)
|
||||
? null
|
||||
: System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, object>>(extraStr);
|
||||
if (a is not JsonElement aJsonElement || b is not JsonElement bJsonElement)
|
||||
return false;
|
||||
|
||||
if (aJsonElement.TryGetProperty(fieldName, out var aValue)
|
||||
&& bJsonElement.TryGetProperty(fieldName, out var bValue))
|
||||
{
|
||||
return aValue.ToString() == bValue.ToString();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System.Diagnostics;
|
||||
using System.Text.Json;
|
||||
using DotNetCore.CAP;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SJZY.Expand.ABP.Core.Logger;
|
||||
@ -237,7 +238,6 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
|
||||
{
|
||||
var orderIds = @event.OrderIdentifiers.Select(x => x.OrderId).ToArray();
|
||||
|
||||
// todo:条件命名写反了
|
||||
// important:轨迹code相同,时间、发生地不同的,可能存在多条!!
|
||||
var tracks = await _trackDetailsEsRepository.GetListAsync(orderIds, @event.TrackCode, true);
|
||||
|
||||
@ -282,7 +282,7 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
|
||||
return false;
|
||||
}
|
||||
|
||||
return oldValue == compareValue;
|
||||
return EqJsonElementObject(oldValue, compareValue);
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
@ -445,10 +445,20 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
|
||||
return track;
|
||||
}
|
||||
|
||||
private Dictionary<string, object>? GetExtraDictForTextJson(string? extraStr)
|
||||
private Dictionary<string, object?>? GetExtraDictForTextJson(string? extraStr)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(extraStr)
|
||||
? null
|
||||
: System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, object>>(extraStr);
|
||||
: System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, object?>>(extraStr);
|
||||
}
|
||||
|
||||
private bool EqJsonElementObject(object? a, object? b)
|
||||
{
|
||||
if (a is JsonElement aJsonElement && b is JsonElement bJsonElement)
|
||||
{
|
||||
return aJsonElement.ToString() == bJsonElement.ToString();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -519,6 +519,7 @@ public partial class TrackService : ApplicationService, ITrackService
|
||||
TrackPlacePostcode = input.TrackPlacePostcode,
|
||||
EstimatedDeliveryDate = input.EstimatedDeliveryDate,
|
||||
DestinationTimeZone = input.DestinationTimeZone,
|
||||
CompareFields = input.CompareFields,
|
||||
Extra = input.Extra,
|
||||
ForcedPush = input.ForcedPush,
|
||||
IsToMq = input.IsToMq,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user