diff --git a/src/Oms.Application/Dtos/Warehouse/WarehouseDtos.cs b/src/Oms.Application/Dtos/Warehouse/WarehouseDtos.cs index 630cb9a..08888a6 100644 --- a/src/Oms.Application/Dtos/Warehouse/WarehouseDtos.cs +++ b/src/Oms.Application/Dtos/Warehouse/WarehouseDtos.cs @@ -367,6 +367,28 @@ public class WarehouseInboundConfirmReceiveInput public List Boxes { get; set; } = []; } +/// +/// H5 上架扫描:按扫码内容定位待收货入库预报。 +/// +public class WarehouseInboundLookupByScanInput +{ + /// + /// 扫码内容:预报单号 / 箱唛 MarkBoxNo / {NoticeNo}-{BoxSeqNo}。 + /// + [Required] + public string Code { get; set; } = string.Empty; + + /// + /// 当前操作仓(可选;传入则校验预报归属仓)。 + /// + public int? WarehouseId { get; set; } + + /// + /// 客户 ID(可选;管理端可空表示不限客户)。 + /// + public int? CustomerId { get; set; } +} + public class WarehouseInboundSummaryOutput { public int Forecasted { get; set; } diff --git a/src/Oms.Application/Services/Warehouse/WarehouseService.Inbound.cs b/src/Oms.Application/Services/Warehouse/WarehouseService.Inbound.cs index e3761e9..78709e2 100644 --- a/src/Oms.Application/Services/Warehouse/WarehouseService.Inbound.cs +++ b/src/Oms.Application/Services/Warehouse/WarehouseService.Inbound.cs @@ -127,31 +127,109 @@ 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 = OrderInboundBoxes(boxes); - var boxIds = boxes.Select(x => x.Id).ToArray(); - var lines = boxIds.Length == 0 - ? [] - : await InboundBoxLineRepository.GetListAsync(x => boxIds.Contains(x.InboundBoxId)); + return await BuildInboundDetailAsync(notice); + } - var output = MapInboundOutput(notice, boxes, lines); - return new WarehouseInboundDetailOutput + /// + /// H5 上架扫描:按预报单号 / 箱唛 / {NoticeNo}-{BoxSeqNo} 定位未完成收货的入库预报详情。 + /// + /// 扫码内容与可选仓库、客户过滤。 + /// 入库预报详情(含箱与明细)。 + [HttpPost("/warehouse/inbound/lookup-by-scan")] + public async Task LookupInboundByScanAsync( + WarehouseInboundLookupByScanInput input) + { + var code = input.Code?.Trim() ?? string.Empty; + if (string.IsNullOrWhiteSpace(code)) { - Id = output.Id, - CustomerId = output.CustomerId, - WarehouseId = output.WarehouseId, - NoticeNo = output.NoticeNo, - MarkReference = output.MarkReference, - InboundType = output.InboundType, - ReceiptStatus = output.ReceiptStatus, - ExpectedArrivalTime = output.ExpectedArrivalTime, - ActualArrivalTime = output.ActualArrivalTime, - Remark = output.Remark, - BoxCount = output.BoxCount, - PlannedQty = output.PlannedQty, - CreateTime = output.CreateTime, - Boxes = boxes.Select(box => MapInboundBox(box, lines.Where(l => l.InboundBoxId == box.Id))).ToList() - }; + throw new BusinessException("请扫描或输入预报单号 / 箱唛"); + } + + var customerId = await ResolveListCustomerIdAsync(input.CustomerId); + var (hasCustomerFilter, customerIdValue) = CustomerFilter(customerId); + var hasWarehouseFilter = input.WarehouseId is > 0; + var warehouseIdValue = input.WarehouseId.GetValueOrDefault(); + + CInboundNotice? notice = null; + + // 1) 精确预报单号 + var exactNotices = await InboundNoticeRepository.GetListAsync(x => + x.NoticeNo == code + && x.ReceiptStatus != WarehouseReceiptStatusCodes.Completed + && (!hasCustomerFilter || x.CustomerId == customerIdValue) + && (!hasWarehouseFilter || x.WarehouseId == warehouseIdValue)); + notice = exactNotices.OrderByDescending(x => x.UpdateTime).ThenByDescending(x => x.Id).FirstOrDefault(); + + // 2) 精确箱唛 MarkBoxNo + if (notice == null) + { + var boxes = await InboundBoxRepository.GetListAsync(x => x.MarkBoxNo == code); + if (boxes.Count > 0) + { + var noticeIds = boxes.Select(x => x.InboundNoticeId).Distinct().ToArray(); + var byBox = await InboundNoticeRepository.GetListAsync(x => + noticeIds.Contains(x.Id) + && x.ReceiptStatus != WarehouseReceiptStatusCodes.Completed + && (!hasCustomerFilter || x.CustomerId == customerIdValue) + && (!hasWarehouseFilter || x.WarehouseId == warehouseIdValue)); + notice = byBox.OrderByDescending(x => x.UpdateTime).ThenByDescending(x => x.Id).FirstOrDefault(); + } + } + + // 3) {NoticeNo}-{BoxSeqNo}(与箱唛条码 ResolveBarcode 一致) + if (notice == null) + { + var dash = code.LastIndexOf('-'); + if (dash > 0 && dash < code.Length - 1) + { + var noticeNoPart = code[..dash].Trim(); + var seqPart = code[(dash + 1)..].Trim(); + if (!string.IsNullOrWhiteSpace(noticeNoPart) && !string.IsNullOrWhiteSpace(seqPart)) + { + var byBarcode = await InboundNoticeRepository.GetListAsync(x => + x.NoticeNo == noticeNoPart + && x.ReceiptStatus != WarehouseReceiptStatusCodes.Completed + && (!hasCustomerFilter || x.CustomerId == customerIdValue) + && (!hasWarehouseFilter || x.WarehouseId == warehouseIdValue)); + var candidate = byBarcode + .OrderByDescending(x => x.UpdateTime) + .ThenByDescending(x => x.Id) + .FirstOrDefault(); + if (candidate != null) + { + var seqBoxes = await InboundBoxRepository.GetListAsync(x => + x.InboundNoticeId == candidate.Id && x.BoxSeqNo == seqPart); + if (seqBoxes.Count > 0) + { + notice = candidate; + } + } + } + } + } + + // 4) 预报单号模糊包含(兜底) + if (notice == null) + { + var fuzzy = await InboundNoticeRepository.GetListAsync(x => + x.NoticeNo.Contains(code) + && x.ReceiptStatus != WarehouseReceiptStatusCodes.Completed + && (!hasCustomerFilter || x.CustomerId == customerIdValue) + && (!hasWarehouseFilter || x.WarehouseId == warehouseIdValue)); + notice = fuzzy.OrderByDescending(x => x.UpdateTime).ThenByDescending(x => x.Id).FirstOrDefault(); + } + + if (notice == null) + { + throw new BusinessException("未找到待上架的入库预报"); + } + + if (hasWarehouseFilter && notice.WarehouseId != warehouseIdValue) + { + throw new BusinessException("该预报不属于当前仓库"); + } + + return await BuildInboundDetailAsync(notice); } /// @@ -475,6 +553,38 @@ public partial class WarehouseService return entity; } + private async Task BuildInboundDetailAsync(CInboundNotice notice) + { + var boxes = await InboundBoxRepository.GetListAsync(x => x.InboundNoticeId == notice.Id); + boxes = OrderInboundBoxes(boxes); + var boxIds = boxes.Select(x => x.Id).ToArray(); + var lines = boxIds.Length == 0 + ? [] + : await InboundBoxLineRepository.GetListAsync(x => boxIds.Contains(x.InboundBoxId)); + + var output = MapInboundOutput(notice, boxes, lines); + var customer = await CustomerRepository.FirstOrDefaultAsync(x => x.Id == notice.CustomerId); + return new WarehouseInboundDetailOutput + { + Id = output.Id, + CustomerId = output.CustomerId, + CustomerName = customer?.CustomerName, + CustomerCode = customer?.CustomerCode, + WarehouseId = output.WarehouseId, + NoticeNo = output.NoticeNo, + MarkReference = output.MarkReference, + InboundType = output.InboundType, + ReceiptStatus = output.ReceiptStatus, + ExpectedArrivalTime = output.ExpectedArrivalTime, + ActualArrivalTime = output.ActualArrivalTime, + Remark = output.Remark, + BoxCount = output.BoxCount, + PlannedQty = output.PlannedQty, + CreateTime = output.CreateTime, + Boxes = boxes.Select(box => MapInboundBox(box, lines.Where(l => l.InboundBoxId == box.Id))).ToList() + }; + } + private async Task SaveInboundLabelPdfAsync(string noticeNo, byte[] pdfBytes) { var safeNo = string.IsNullOrWhiteSpace(noticeNo) ? "inbound" : noticeNo.Trim();