From 1caca3c3579eab33d8ce7b758f3b41afe49d2527 Mon Sep 17 00:00:00 2001 From: zzh <1368735060@qq.com> Date: Sat, 24 Oct 2026 14:48:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=85=A5=E5=BA=93=E7=AE=B1=E5=94=9B?= =?UTF-8?q?=E6=8C=89=E7=AE=B1=E5=BA=8F=E5=8F=B7=E6=95=B0=E5=80=BC=E6=8E=92?= =?UTF-8?q?=E5=BA=8F=EF=BC=8C=E9=81=BF=E5=85=8D=E8=B6=85=E8=BF=87=209=20?= =?UTF-8?q?=E7=AE=B1=E6=97=B6=E4=B9=B1=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- .../Warehouse/WarehouseService.Inbound.cs | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Oms.Application/Services/Warehouse/WarehouseService.Inbound.cs b/src/Oms.Application/Services/Warehouse/WarehouseService.Inbound.cs index 4c58871..75e8fbb 100644 --- a/src/Oms.Application/Services/Warehouse/WarehouseService.Inbound.cs +++ b/src/Oms.Application/Services/Warehouse/WarehouseService.Inbound.cs @@ -128,7 +128,7 @@ public partial class WarehouseService var resolvedCustomerId = await ResolveListCustomerIdAsync(customerId); var notice = await GetInboundNoticeOrThrowAsync(resolvedCustomerId, id); var boxes = await InboundBoxRepository.GetListAsync(x => x.InboundNoticeId == notice.Id); - boxes = boxes.OrderBy(x => x.BoxSeqNo).ThenBy(x => x.Id).ToList(); + boxes = OrderInboundBoxes(boxes); var boxIds = boxes.Select(x => x.Id).ToArray(); var lines = boxIds.Length == 0 ? [] @@ -367,7 +367,8 @@ public partial class WarehouseService var customerId = await ResolveListCustomerIdAsync(input.CustomerId); var notice = await GetInboundNoticeOrThrowAsync(customerId, input.Id); var boxes = await InboundBoxRepository.GetListAsync(x => x.InboundNoticeId == notice.Id); - boxes = boxes.OrderBy(x => x.BoxSeqNo).ThenBy(x => x.Id).ToList(); + // BoxSeqNo 为字符串,必须按数值排,否则 10 会排在 2 前面导致箱唛乱序 + boxes = OrderInboundBoxes(boxes); if (boxes.Count == 0) { throw new BusinessException("该预报没有箱子,无法打印箱唛"); @@ -549,4 +550,23 @@ public partial class WarehouseService BinLocationId = line.BinLocationId }).ToList() }; + + /// + /// 按箱序号数值升序;无法解析的序号排最后,同序号再按 Id。 + /// + private static List OrderInboundBoxes(IEnumerable boxes) => + boxes + .OrderBy(x => ParseBoxSeqNo(x.BoxSeqNo)) + .ThenBy(x => x.Id) + .ToList(); + + private static int ParseBoxSeqNo(string? boxSeqNo) + { + if (string.IsNullOrWhiteSpace(boxSeqNo)) + { + return int.MaxValue; + } + + return int.TryParse(boxSeqNo.Trim(), out var n) && n > 0 ? n : int.MaxValue; + } }