From c8067da7de047d029f0888f3cde3e528bf285e26 Mon Sep 17 00:00:00 2001 From: hardstylewyl <827778732@qq.com> Date: Thu, 26 Jun 2025 15:50:25 +0800 Subject: [PATCH] =?UTF-8?q?perf:=E5=88=A0=E9=99=A4t=5Forder=5Fplatform=5Fn?= =?UTF-8?q?umber=E8=A1=A8=E5=B0=86=E8=81=8C=E8=B4=A3=E5=BD=92=E5=B1=9E?= =?UTF-8?q?=E4=BA=8Et=5Forder=5Fpull=5Fstatus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/ProvideServices/OrderService.cs | 30 ++---------- .../Aggregates/OrderAggregate/OrderEntity.cs | 14 ++---- .../OrderPlatformNumberEntity.cs | 32 ------------- .../Repositories/OrderRepository.cs | 46 +++---------------- 4 files changed, 15 insertions(+), 107 deletions(-) delete mode 100644 src/SJZY.Track.Domain/Aggregates/OrderAggregate/OrderPlatformNumberEntity.cs diff --git a/src/SJZY.Track.Application/Services/ProvideServices/OrderService.cs b/src/SJZY.Track.Application/Services/ProvideServices/OrderService.cs index 8c110fdc..71c0c7ea 100644 --- a/src/SJZY.Track.Application/Services/ProvideServices/OrderService.cs +++ b/src/SJZY.Track.Application/Services/ProvideServices/OrderService.cs @@ -84,9 +84,8 @@ public partial class OrderService : ApplicationService, IOrderService order = ObjectMapper.Map(input); order.OrderFlights = ObjectMapper.Map, List>(input.FlightInfos); order.OrderPullStatus = BuiltOrderPullStatus(input.PullConfigInfos); - order.OrderPlatformNumbers = BuiltOrderPlatformNumbers(input.PullConfigInfos); order.TemplateCodes = input.TemplateCodes == null ? null : string.Join(',', input.TemplateCodes); - order.SetThirdPartyOrderNumber(order.OrderPlatformNumbers); + order.SetThirdPartyOrderNumber(order.OrderPullStatus); var orderId = await _orderRepository.CreateOrderAsync(order); @@ -143,9 +142,8 @@ public partial class OrderService : ApplicationService, IOrderService var order2 = ObjectMapper.Map(input2, order); order2.OrderFlights = ObjectMapper.Map, List>(input2.FlightInfos); order2.OrderPullStatus = BuiltOrderPullStatus(input2.PullConfigInfos); - order2.OrderPlatformNumbers = BuiltOrderPlatformNumbers(input2.PullConfigInfos); order2.TemplateCodes = input2.TemplateCodes == null ? null : string.Join(',', input2.TemplateCodes); - order2.SetThirdPartyOrderNumber(order.OrderPlatformNumbers); + order2.SetThirdPartyOrderNumber(order.OrderPullStatus); updateOrders.Add(order2); updateRecords.Add(new OrderOperationRecordIndex { @@ -180,9 +178,8 @@ public partial class OrderService : ApplicationService, IOrderService var order = ObjectMapper.Map(insertInput); order.OrderFlights = ObjectMapper.Map, List>(insertInput.FlightInfos); order.OrderPullStatus = BuiltOrderPullStatus(insertInput.PullConfigInfos); - order.OrderPlatformNumbers = BuiltOrderPlatformNumbers(insertInput.PullConfigInfos); order.TemplateCodes = insertInput.TemplateCodes == null ? null : string.Join(',', insertInput.TemplateCodes); - order.SetThirdPartyOrderNumber(order.OrderPlatformNumbers); + order.SetThirdPartyOrderNumber(order.OrderPullStatus); insertOrders.Add(order); createRecords.Add(new OrderOperationRecordIndex { @@ -240,9 +237,8 @@ public partial class OrderService : ApplicationService, IOrderService order = ObjectMapper.Map(input, order); order.OrderFlights = ObjectMapper.Map, List>(input.FlightInfos); order.OrderPullStatus = BuiltOrderPullStatus(input.PullConfigInfos); - order.OrderPlatformNumbers = BuiltOrderPlatformNumbers(input.PullConfigInfos); order.TemplateCodes = input.TemplateCodes == null ? null : string.Join(',', input.TemplateCodes); - order.SetThirdPartyOrderNumber(order.OrderPlatformNumbers); + order.SetThirdPartyOrderNumber(order.OrderPullStatus); await _orderRepository.UpdateOrderAsync(order); } @@ -277,24 +273,6 @@ public partial class OrderService : ApplicationService, IOrderService }).ToList(); } - private static List BuiltOrderPlatformNumbers(List? pullConfigInfos) - { - if (pullConfigInfos == null) return new List(); - - return pullConfigInfos.Select(x => - { - var status = new OrderPlatformNumberEntity - { - //三方单号 - OrderNumber = x.OrderNo, - //三方平台名称,目前认为是服务商code - Platform = x.ServiceCode, - }; - - return status; - }).ToList(); - } - private void WarningCalc_OrderDeletedOrCompleted(OrderEntity order) { order.IsDeleted = true; diff --git a/src/SJZY.Track.Domain/Aggregates/OrderAggregate/OrderEntity.cs b/src/SJZY.Track.Domain/Aggregates/OrderAggregate/OrderEntity.cs index 3f963f2c..447a3989 100644 --- a/src/SJZY.Track.Domain/Aggregates/OrderAggregate/OrderEntity.cs +++ b/src/SJZY.Track.Domain/Aggregates/OrderAggregate/OrderEntity.cs @@ -206,10 +206,6 @@ public class OrderEntity : IFullAuditedBasicEntitys, IAggregateRoot [SugarColumn(IsIgnore = true)] public List OrderPullStatus { get; set; } - [Navigate(NavigateType.OneToMany, nameof(OrderPlatformNumberEntity.OrderId))] - [SugarColumn(IsIgnore = true)] - public List OrderPlatformNumbers { get; set; } - public void ResetTrackInfo() { IsCompleted = false; @@ -224,18 +220,18 @@ public class OrderEntity : IFullAuditedBasicEntitys, IAggregateRoot } // 设置三方单号字段 - public void SetThirdPartyOrderNumber(List orderPlatformNumberEntities) + public void SetThirdPartyOrderNumber(List orderPullStatusEntities) { - if (orderPlatformNumberEntities.Count == 0) + if (orderPullStatusEntities.Count == 0) { ThirdPartyOrderNumber = GlobalConst.EmptyString; return; } const string separator = "、"; - var thirdPartyOrderNumbers = orderPlatformNumberEntities - .Where(x => !string.IsNullOrWhiteSpace(x.OrderNumber)) - .Select(x => $"{x.OrderNumber}({x.Platform})") + var thirdPartyOrderNumbers = orderPullStatusEntities + .Where(x => !string.IsNullOrWhiteSpace(x.OrderNo)) + .Select(x => $"{x.OrderNo}({x.ServiceProviderCode})") .ToList(); if (thirdPartyOrderNumbers.Count == 0) { diff --git a/src/SJZY.Track.Domain/Aggregates/OrderAggregate/OrderPlatformNumberEntity.cs b/src/SJZY.Track.Domain/Aggregates/OrderAggregate/OrderPlatformNumberEntity.cs deleted file mode 100644 index b4ae68bf..00000000 --- a/src/SJZY.Track.Domain/Aggregates/OrderAggregate/OrderPlatformNumberEntity.cs +++ /dev/null @@ -1,32 +0,0 @@ -namespace SJZY.Track.Domain.Aggregates.OrderAggregate; - -/// -/// 外部单号关联表 -/// -[SugarTable("t_order_platform_number")] -public class OrderPlatformNumberEntity : IFullAuditedBasicEntitys, IEntity -{ - /// - /// 自增主键 - /// - [SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)] - public int Id { get; set; } - - /// - /// 订单id - /// - [SugarColumn(ColumnName = "OrderId")] - public int OrderId { get; set; } - - /// - /// 外部单号 - /// - [SugarColumn(ColumnName = "OrderNumber")] - public string? OrderNumber { get; set; } - - /// - /// 平台名称 - /// - [SugarColumn(ColumnName = "Platform")] - public string? Platform { get; set; } -} diff --git a/src/SJZY.Track.Repository/Repositories/OrderRepository.cs b/src/SJZY.Track.Repository/Repositories/OrderRepository.cs index 55690b31..dfca67d1 100644 --- a/src/SJZY.Track.Repository/Repositories/OrderRepository.cs +++ b/src/SJZY.Track.Repository/Repositories/OrderRepository.cs @@ -146,8 +146,8 @@ public class OrderRepository : BasicRepository, IOrderRepository, I .ToListAsync(); //匹配外部单 - var orderIdsForThirdParty = await Context.Queryable() - .Where(x => !string.IsNullOrWhiteSpace(x.OrderNumber) && orderNos.Contains(x.OrderNumber)) + var orderIdsForThirdParty = await Context.Queryable() + .Where(x => !string.IsNullOrWhiteSpace(x.OrderNo) && orderNos.Contains(x.OrderNo)) .Select(x => x.OrderId) .ToListAsync(); @@ -239,16 +239,16 @@ public class OrderRepository : BasicRepository, IOrderRepository, I public async Task<(int MainOrderId, string OrderNo, int CustomId)> GetTrackOrderByProviderAndOrderNo(string serviceProviderCode, string orderNo) { var orderList = await Context.Queryable() - .LeftJoin((a, b) => a.Id == b.OrderId && b.IsDeleted == false) + .LeftJoin((a, b) => a.Id == b.OrderId) .Where((a, b) => a.OrderNo == orderNo - || (b.Platform == serviceProviderCode && b.OrderNumber == orderNo)) + || (b.ServiceProviderCode == serviceProviderCode && b.OrderNo == orderNo)) .Select((a, b) => new { a.Id, a.CustomId, a.OrderNo, - b.Platform, - b.OrderNumber + Platform = b.ServiceProviderCode, + OrderNumber = b.OrderNo }) .ToListAsync(); @@ -274,8 +274,6 @@ public class OrderRepository : BasicRepository, IOrderRepository, I await Context.Insertable(order.OrderFlights).ExecuteCommandAsync(); order.OrderPullStatus.ForEach(x => x.OrderId = orderId); await Context.Insertable(order.OrderPullStatus).ExecuteCommandAsync(); - order.OrderPlatformNumbers.ForEach(x => x.OrderId = orderId); - await Context.Insertable(order.OrderPlatformNumbers).ExecuteCommandAsync(); tran.Complete(); @@ -289,7 +287,6 @@ public class OrderRepository : BasicRepository, IOrderRepository, I var orderFlights = orders.SelectMany(x => x.OrderFlights).ToList(); var orderPullStatus = orders.SelectMany(x => x.OrderPullStatus).ToList(); - var orderPlatformNumbers = orders.SelectMany(x => x.OrderPlatformNumbers).ToList(); try { @@ -314,12 +311,10 @@ public class OrderRepository : BasicRepository, IOrderRepository, I var orderId = orderNoIdDict[order.OrderNo]; order.OrderFlights.ForEach(x => x.OrderId = orderId); order.OrderPullStatus.ForEach(x => x.OrderId = orderId); - order.OrderPlatformNumbers.ForEach(x => x.OrderId = orderId); } await Context.Insertable(orderFlights).ExecuteCommandAsync(); await Context.Insertable(orderPullStatus).ExecuteCommandAsync(); - await Context.Insertable(orderPlatformNumbers).ExecuteCommandAsync(); } finally { @@ -356,11 +351,6 @@ public class OrderRepository : BasicRepository, IOrderRepository, I order.OrderPullStatus.ForEach(x => x.OrderId = order.Id); await Context.Insertable(order.OrderPullStatus).ExecuteCommandAsync(); - // 更新订单三方关联 - await Context.Deleteable().Where(x => x.OrderId == order.Id).ExecuteCommandAsync(); - order.OrderPlatformNumbers.ForEach(x => x.OrderId = order.Id); - await Context.Insertable(order.OrderPlatformNumbers).ExecuteCommandAsync(); - // 更新订单航班 await Context.Deleteable().Where(x => x.OrderId == order.Id).ExecuteCommandAsync(); order.OrderFlights.ForEach(x => x.OrderId = order.Id); @@ -385,11 +375,9 @@ public class OrderRepository : BasicRepository, IOrderRepository, I var orderIds = orders.Select(x => x.Id).ToHashSet(); var orderFlights = orders.SelectMany(x => x.OrderFlights).ToList(); var orderPullStatus = orders.SelectMany(x => x.OrderPullStatus).ToList(); - var orderPlatformNumbers = orders.SelectMany(x => x.OrderPlatformNumbers).ToList(); foreach (var order in orders) { order.OrderPullStatus.ForEach(x => x.OrderId = order.Id); - order.OrderPlatformNumbers.ForEach(x => x.OrderId = order.Id); order.OrderFlights.ForEach(x => x.OrderId = order.Id); } @@ -397,10 +385,6 @@ public class OrderRepository : BasicRepository, IOrderRepository, I await Context.Deleteable().Where(x => orderIds.Contains(x.OrderId)).ExecuteCommandAsync(); await Context.Insertable(orderPullStatus).ExecuteCommandAsync(); - // 更新订单三方关联 - await Context.Deleteable().Where(x => orderIds.Contains(x.OrderId)).ExecuteCommandAsync(); - await Context.Insertable(orderPlatformNumbers).ExecuteCommandAsync(); - // 更新订单航班 await Context.Deleteable().Where(x => orderIds.Contains(x.OrderId)).ExecuteCommandAsync(); await Context.Insertable(orderFlights).ExecuteCommandAsync(); @@ -522,24 +506,6 @@ public class OrderRepository : BasicRepository, IOrderRepository, I }); } - /// - /// 拼接多个三方单号,默认使用分隔符默认(、) - /// 第三方单号展示: 0000000(服务商)、0000000(服务商) - /// - /// - /// - public string BuildThirdPartyOrderNumber(List orderPlatformNumberEntities) - { - if (orderPlatformNumberEntities.Count == 0) return GlobalConst.EmptyString; - const string separator = "、"; - var thirdPartyOrderNumbers = orderPlatformNumberEntities - .Where(x => !string.IsNullOrWhiteSpace(x.OrderNumber)) - .Select(x => $"{x.OrderNumber}({x.Platform})") - .ToList(); - if (thirdPartyOrderNumbers.Count == 0) return GlobalConst.EmptyString; - return string.Join(separator, thirdPartyOrderNumbers); - } - #region 订单关联 public async Task> GetLinkedOrdersAsync(int[] orderIds)