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; + } }