Merge branch 'S07' into test

This commit is contained in:
hardstylewyl 2025-02-21 11:49:56 +08:00
commit 0bc171e140
9 changed files with 78 additions and 73 deletions

View File

@ -93,6 +93,11 @@ public class TrackOrderDto
/// </summary> /// </summary>
public string? OrderDetails { get; set; } public string? OrderDetails { get; set; }
/// <summary>
/// 最新轨迹状态
/// </summary>
public string? NewestTrackStatus { get; set; }
/// <summary> /// <summary>
/// 最新轨迹内容 /// 最新轨迹内容
/// </summary> /// </summary>
@ -113,6 +118,11 @@ public class TrackOrderDto
/// </summary> /// </summary>
public DateTime? NewestTrackTime { get; set; } public DateTime? NewestTrackTime { get; set; }
/// <summary>
/// 最新轨迹时区
/// </summary>
public float? NewestTrackTimeZone { get; set; }
/// <summary> /// <summary>
/// 是否完结 /// 是否完结
/// </summary> /// </summary>

View File

@ -12,6 +12,11 @@ public class TrackChangeAfterUpdateOrderEvent
/// </summary> /// </summary>
public bool IsCompleted { get; set; } public bool IsCompleted { get; set; }
/// <summary>
/// 轨迹状态
/// </summary>
public string TrackStatus { get; set; } = null!;
/// <summary> /// <summary>
/// 轨迹内容 /// 轨迹内容
/// </summary> /// </summary>

View File

@ -50,6 +50,7 @@ public class TrackChangeAfterUpdateOrderEventHandler : ITransientDependency, ICa
order.IsCompleted = @event.IsCompleted; order.IsCompleted = @event.IsCompleted;
} }
order.LatestTrackStatus = @event.TrackStatus;
order.LatestTrackContent = @event.TrackContent; order.LatestTrackContent = @event.TrackContent;
order.LatestTrackEnContent = @event.TrackEnContent; order.LatestTrackEnContent = @event.TrackEnContent;
order.LatestTrackPlace = @event.TrackPlace; order.LatestTrackPlace = @event.TrackPlace;

View File

@ -205,6 +205,7 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
{ {
OrderIds = canNextOrderIds.ToArray(), OrderIds = canNextOrderIds.ToArray(),
IsCompleted = trackContent.IsCompleted, IsCompleted = trackContent.IsCompleted,
TrackStatus = trackContent.TrackStatus,
TrackContent = trackContent.TrackContent, TrackContent = trackContent.TrackContent,
TrackEnContent = trackContent.TrackEnContent, TrackEnContent = trackContent.TrackEnContent,
TrackPlace = @event.TrackPlace, TrackPlace = @event.TrackPlace,

View File

@ -77,6 +77,7 @@ public partial class OrderService : ApplicationService, IOrderService
order.OrderPullStatus = BuiltOrderPullStatus(input.PullConfigInfos); order.OrderPullStatus = BuiltOrderPullStatus(input.PullConfigInfos);
order.OrderPlatformNumbers = BuiltOrderPlatformNumbers(input.PullConfigInfos); order.OrderPlatformNumbers = BuiltOrderPlatformNumbers(input.PullConfigInfos);
order.TemplateCodes = input.TemplateCodes == null ? null : string.Join(',', input.TemplateCodes); order.TemplateCodes = input.TemplateCodes == null ? null : string.Join(',', input.TemplateCodes);
order.SetThirdPartyOrderNumber(order.OrderPlatformNumbers);
var orderId = await _orderRepository.CreateOrderAsync(order); var orderId = await _orderRepository.CreateOrderAsync(order);
@ -132,6 +133,7 @@ public partial class OrderService : ApplicationService, IOrderService
order.OrderPullStatus = BuiltOrderPullStatus(input.PullConfigInfos); order.OrderPullStatus = BuiltOrderPullStatus(input.PullConfigInfos);
order.OrderPlatformNumbers = BuiltOrderPlatformNumbers(input.PullConfigInfos); order.OrderPlatformNumbers = BuiltOrderPlatformNumbers(input.PullConfigInfos);
order.TemplateCodes = input.TemplateCodes == null ? null : string.Join(',', input.TemplateCodes); order.TemplateCodes = input.TemplateCodes == null ? null : string.Join(',', input.TemplateCodes);
order.SetThirdPartyOrderNumber(order.OrderPlatformNumbers);
await _orderRepository.UpdateOrderAsync(order); await _orderRepository.UpdateOrderAsync(order);
} }

View File

@ -104,7 +104,7 @@ public class TrackPushService : ApplicationService, ITrackPushService
throw new BusinessException(message: $"当前轨迹不存在扩展信息,无法利用扩展字段:{input.CompareFields}"); throw new BusinessException(message: $"当前轨迹不存在扩展信息,无法利用扩展字段:{input.CompareFields}");
} }
var extraDict = GetExtraDictForTextJson(x.Extra); var extraDict = TextJsonHelper.DeserializeToDictionary(x.Extra);
if (extraDict == null || !extraDict.TryGetValue(input.CompareFields, out var compareValue)) if (extraDict == null || !extraDict.TryGetValue(input.CompareFields, out var compareValue))
{ {
throw new BusinessException(message: $"请检查拓展字段,为什么找不到比较字段:{input.CompareFields}"); throw new BusinessException(message: $"请检查拓展字段,为什么找不到比较字段:{input.CompareFields}");
@ -148,24 +148,6 @@ public class TrackPushService : ApplicationService, ITrackPushService
await _capPublisher.PublishAsync(GlobalConst.TrackManualPushSubscribe, trackPushEvent); await _capPublisher.PublishAsync(GlobalConst.TrackManualPushSubscribe, trackPushEvent);
} }
// foreach (var group in orders.GroupBy(x => x.CustomId))
// {
// var trackPushEvent = new TrackPushEvent
// {
// OptionType = OptionType.新增,
// SubSystemId = input.SubSystemId,
// SubSystemCode = subSystemCode,
// CustomId = group.Key,
// OrderIds = group.Select(x => x.Id).ToArray(),
// TrackCode = input.TrackCode,
// OperationMan = name,
// SystemPushInfo = new SystemPushStruct()
// };
//
// await _capPublisher.PublishAsync(GlobalConst.TrackManualPushSubscribe, trackPushEvent);
// }
return new UnifyResultDto(true, $"即将推送轨迹代码{input.TrackCode}给{orders.Length}个订单"); return new UnifyResultDto(true, $"即将推送轨迹代码{input.TrackCode}给{orders.Length}个订单");
} }
@ -210,10 +192,5 @@ public class TrackPushService : ApplicationService, ITrackPushService
return new UnifyResultDto<List<TrackPushRecordOutput>>(true, res, "操作成功"); return new UnifyResultDto<List<TrackPushRecordOutput>>(true, res, "操作成功");
} }
private Dictionary<string, object?>? GetExtraDictForTextJson(string? extraStr)
{
return string.IsNullOrWhiteSpace(extraStr)
? null
: System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, object?>>(extraStr);
}
} }

View File

@ -1,3 +1,5 @@
using SJZY.Track.Domain.Consts;
namespace SJZY.Track.Domain.Aggregates.OrderAggregate; namespace SJZY.Track.Domain.Aggregates.OrderAggregate;
/// <summary> /// <summary>
@ -60,6 +62,12 @@ public class OrderEntity : IFullAuditedBasicEntitys, IAggregateRoot
[SugarColumn(ColumnName = "LatestPushError")] [SugarColumn(ColumnName = "LatestPushError")]
public string? LatestPushError { get; set; } public string? LatestPushError { get; set; }
/// <summary>
/// 最新轨迹状态(异步维护)
/// </summary>
[SugarColumn(ColumnName = "LatestTrackStatus")]
public string? LatestTrackStatus { get; set; }
/// <summary> /// <summary>
/// 最新轨迹内容(异步维护) /// 最新轨迹内容(异步维护)
/// </summary> /// </summary>
@ -186,6 +194,12 @@ public class OrderEntity : IFullAuditedBasicEntitys, IAggregateRoot
[SugarColumn(ColumnName = "TemplateCodes")] [SugarColumn(ColumnName = "TemplateCodes")]
public string? TemplateCodes { get; set; } public string? TemplateCodes { get; set; }
/// <summary>
/// 冗余订单第三方订单号(创建订单,更新订单时维护)
/// </summary>
[SugarColumn(ColumnName = "ThirdPartyOrderNumber")]
public string? ThirdPartyOrderNumber { get; set; } //
[SugarColumn(IsIgnore = true)] [SugarColumn(IsIgnore = true)]
public List<OrderFlightEntity> OrderFlights { get; set; } public List<OrderFlightEntity> OrderFlights { get; set; }
@ -207,4 +221,27 @@ public class OrderEntity : IFullAuditedBasicEntitys, IAggregateRoot
EstimatedDeliveryDate = null; EstimatedDeliveryDate = null;
DestinationTimeZone = null; DestinationTimeZone = null;
} }
// 设置三方单号字段
public void SetThirdPartyOrderNumber(List<OrderPlatformNumberEntity> orderPlatformNumberEntities)
{
if (orderPlatformNumberEntities.Count == 0)
{
ThirdPartyOrderNumber = GlobalConst.EmptyString;
return;
}
const string separator = "、";
var thirdPartyOrderNumbers = orderPlatformNumberEntities
.Where(x => !string.IsNullOrWhiteSpace(x.OrderNumber))
.Select(x => $"{x.OrderNumber}({x.Platform})")
.ToList();
if (thirdPartyOrderNumbers.Count == 0)
{
ThirdPartyOrderNumber = GlobalConst.EmptyString;
return;
}
ThirdPartyOrderNumber = string.Join(separator, thirdPartyOrderNumbers);
}
} }

View File

@ -89,6 +89,11 @@ public class TrackOrderVO
///// </summary> ///// </summary>
//public string? OrderDetails { get; set; } //public string? OrderDetails { get; set; }
/// <summary>
/// 最新轨迹状态
/// </summary>
public string? NewestTrackStatus { get; set; }
/// <summary> /// <summary>
/// 最新轨迹内容 /// 最新轨迹内容
/// </summary> /// </summary>
@ -109,6 +114,11 @@ public class TrackOrderVO
/// </summary> /// </summary>
public DateTime? NewestTrackTime { get; set; } public DateTime? NewestTrackTime { get; set; }
/// <summary>
/// 最新轨迹时区
/// </summary>
public float? NewestTrackTimeZone { get; set; }
/// <summary> /// <summary>
/// 是否完结 /// 是否完结
/// </summary> /// </summary>

View File

@ -14,52 +14,14 @@ public class OrderRepository : BasicRepository<OrderEntity>, IOrderRepository, I
//tips:后期提供缓存清理接口 //tips:后期提供缓存清理接口
//MemoryCache本身线程安全简单使用,短暂数据不一致可以容忍,每过固定时间强制清除缓存 //MemoryCache本身线程安全简单使用,短暂数据不一致可以容忍,每过固定时间强制清除缓存
private static readonly MemoryCache _memoryCache = new(new MemoryCacheOptions()); private static readonly MemoryCache _memoryCache = new(new MemoryCacheOptions());
private static readonly Dictionary<int, string> _empty = new(); private static readonly Dictionary<string, Dictionary<int, string>> _empty = new();
private static readonly Dictionary<string, Dictionary<int, string>> _empty2 = new();
private static readonly TimeSpan _thirdPartyOrderNumberCacheTimeSpan = TimeSpan.FromMinutes(3);
private static readonly TimeSpan _mainDataEnumCacheTimeSpan = TimeSpan.FromMinutes(5); private static readonly TimeSpan _mainDataEnumCacheTimeSpan = TimeSpan.FromMinutes(5);
private static readonly TimeSpan _orderTypeCacheTimeSpan = TimeSpan.FromMinutes(1); private static readonly TimeSpan _orderTypeCacheTimeSpan = TimeSpan.FromMinutes(1);
private async Task<Dictionary<int, string>> GetThirdPartyOrderNumberForCacheAsync(int[] orderIds)
{
const string key = "ThirdPartyOrderNumber";
if (orderIds.Length == 0) return _empty;
var dict = _memoryCache.Get<Dictionary<int, string>>(key);
orderIds = orderIds.Distinct().ToArray();
if (dict != null && dict.Count != 0 && !orderIds.Except(dict.Keys).Any()) return dict;
var orders = await Context.Queryable<OrderEntity>()
.Includes(a => a.OrderPlatformNumbers)
.LeftJoin<OrderPlatformNumberEntity>((a, b) => a.Id == b.OrderId && b.IsDeleted == false)
.Where((a, b) => orderIds.Contains(a.Id))
.Select(a => new OrderEntity()
{
Id = a.Id,
OrderPlatformNumbers = a.OrderPlatformNumbers
})
.ToListAsync();
if (orders.Count == 0)
return _empty;
orders = orders.DistinctBy(x => x.Id).ToList();
dict = orders.ToDictionary(x => x.Id, x => BuildThirdPartyOrderNumber(x.OrderPlatformNumbers));
_memoryCache.Set(key, dict, new MemoryCacheEntryOptions
{
AbsoluteExpirationRelativeToNow = _thirdPartyOrderNumberCacheTimeSpan,
Size = dict.Count
});
return dict;
}
private async Task<Dictionary<string, Dictionary<int, string>>> GetMainDataEnumForCacheAsync(List<int> orderTypes, List<int> questTypes) private async Task<Dictionary<string, Dictionary<int, string>>> GetMainDataEnumForCacheAsync(List<int> orderTypes, List<int> questTypes)
{ {
const string key = "EnumForMainData"; const string key = "EnumForMainData";
if (orderTypes.Count == 0 && questTypes.Count == 0) return _empty2; if (orderTypes.Count == 0 && questTypes.Count == 0) return _empty;
var dict = _memoryCache.Get<Dictionary<string, Dictionary<int, string>>>(key); var dict = _memoryCache.Get<Dictionary<string, Dictionary<int, string>>>(key);
if (dict != null && dict.Count != 0 if (dict != null && dict.Count != 0
@ -90,7 +52,7 @@ public class OrderRepository : BasicRepository<OrderEntity>, IOrderRepository, I
); );
if (dict.Count == 0) if (dict.Count == 0)
return _empty2; return _empty;
_memoryCache.Set(key, dict, new MemoryCacheEntryOptions _memoryCache.Set(key, dict, new MemoryCacheEntryOptions
{ {
@ -153,16 +115,19 @@ public class OrderRepository : BasicRepository<OrderEntity>, IOrderRepository, I
CustomerShortName = b.Abbreviation, CustomerShortName = b.Abbreviation,
CustomerCode = b.Code, CustomerCode = b.Code,
CustomerId = a.CustomId, CustomerId = a.CustomId,
NewestTrackStatus = a.LatestTrackStatus,
NewestTrackContent = a.LatestTrackContent, NewestTrackContent = a.LatestTrackContent,
NewestTrackEnContent = a.LatestTrackEnContent, NewestTrackEnContent = a.LatestTrackEnContent,
NewestTrackPlace = a.LatestTrackPlace, NewestTrackPlace = a.LatestTrackPlace,
NewestTrackTime = a.LatestTrackTime, NewestTrackTime = a.LatestTrackTime,
NewestTrackTimeZone = a.LatestTrackTimeZone,
IsFinish = a.IsCompleted, IsFinish = a.IsCompleted,
CreateTime = a.CreateTime, CreateTime = a.CreateTime,
SubSystem = c.CnName, SubSystem = c.CnName,
SubSystemId = c.Id, SubSystemId = c.Id,
DestinationTimeZone = a.DestinationTimeZone, DestinationTimeZone = a.DestinationTimeZone,
EstimatedDeliveryDate = a.EstimatedDeliveryDate EstimatedDeliveryDate = a.EstimatedDeliveryDate,
ThirdPartyOrderNumber = a.ThirdPartyOrderNumber
}) })
.ToPagedListAsync(input.PageIndex, input.PageSize); .ToPagedListAsync(input.PageIndex, input.PageSize);
} }
@ -227,26 +192,23 @@ public class OrderRepository : BasicRepository<OrderEntity>, IOrderRepository, I
CustomerShortName = b.Abbreviation, CustomerShortName = b.Abbreviation,
CustomerCode = b.Code, CustomerCode = b.Code,
CustomerId = a.CustomId, CustomerId = a.CustomId,
NewestTrackStatus = a.LatestTrackStatus,
NewestTrackContent = a.LatestTrackContent, NewestTrackContent = a.LatestTrackContent,
NewestTrackEnContent = a.LatestTrackEnContent, NewestTrackEnContent = a.LatestTrackEnContent,
NewestTrackPlace = a.LatestTrackPlace, NewestTrackPlace = a.LatestTrackPlace,
NewestTrackTime = a.LatestTrackTime, NewestTrackTime = a.LatestTrackTime,
NewestTrackTimeZone = a.LatestTrackTimeZone,
IsFinish = a.IsCompleted, IsFinish = a.IsCompleted,
CreateTime = a.CreateTime, CreateTime = a.CreateTime,
SubSystem = c.CnName, SubSystem = c.CnName,
SubSystemId = c.Id, SubSystemId = c.Id,
DestinationTimeZone = a.DestinationTimeZone, DestinationTimeZone = a.DestinationTimeZone,
EstimatedDeliveryDate = a.EstimatedDeliveryDate, EstimatedDeliveryDate = a.EstimatedDeliveryDate,
ThirdPartyOrderNumber = a.ThirdPartyOrderNumber
}) })
.ToPagedListAsync(input.PageIndex, input.PageSize); .ToPagedListAsync(input.PageIndex, input.PageSize);
} }
//补三方单号,从缓存中加速查
var orderIdArr = pageList.List.Select(x => x.Id).ToArray();
var thirdPartyOrderNumbers = await GetThirdPartyOrderNumberForCacheAsync(orderIdArr);
pageList.List.ForEach(x => x.ThirdPartyOrderNumber = thirdPartyOrderNumbers[x.Id]);
//查询订单类型描述,从缓存中加速查 //查询订单类型描述,从缓存中加速查
var orderTypes = pageList.List.Select(x => x.OrderType).Distinct().ToList(); var orderTypes = pageList.List.Select(x => x.OrderType).Distinct().ToList();
var questTypes = pageList.List.Select(x => x.QuestionType).Distinct().ToList(); var questTypes = pageList.List.Select(x => x.QuestionType).Distinct().ToList();