feat: 入库预报按扫码定位待上架详情
All checks were successful
Build and Deploy / deploy (push) Successful in 1m21s
All checks were successful
Build and Deploy / deploy (push) Successful in 1m21s
新增 lookup-by-scan,支持预报单号/箱唛/NoticeNo-Seq,供 H5 上架扫描使用。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
884276d293
commit
2ced23e564
@ -367,6 +367,28 @@ public class WarehouseInboundConfirmReceiveInput
|
||||
public List<WarehouseInboundConfirmBoxInput> Boxes { get; set; } = [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// H5 上架扫描:按扫码内容定位待收货入库预报。
|
||||
/// </summary>
|
||||
public class WarehouseInboundLookupByScanInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 扫码内容:预报单号 / 箱唛 MarkBoxNo / {NoticeNo}-{BoxSeqNo}。
|
||||
/// </summary>
|
||||
[Required]
|
||||
public string Code { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 当前操作仓(可选;传入则校验预报归属仓)。
|
||||
/// </summary>
|
||||
public int? WarehouseId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 客户 ID(可选;管理端可空表示不限客户)。
|
||||
/// </summary>
|
||||
public int? CustomerId { get; set; }
|
||||
}
|
||||
|
||||
public class WarehouseInboundSummaryOutput
|
||||
{
|
||||
public int Forecasted { get; set; }
|
||||
|
||||
@ -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
|
||||
/// <summary>
|
||||
/// H5 上架扫描:按预报单号 / 箱唛 / {NoticeNo}-{BoxSeqNo} 定位未完成收货的入库预报详情。
|
||||
/// </summary>
|
||||
/// <param name="input">扫码内容与可选仓库、客户过滤。</param>
|
||||
/// <returns>入库预报详情(含箱与明细)。</returns>
|
||||
[HttpPost("/warehouse/inbound/lookup-by-scan")]
|
||||
public async Task<WarehouseInboundDetailOutput> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -475,6 +553,38 @@ public partial class WarehouseService
|
||||
return entity;
|
||||
}
|
||||
|
||||
private async Task<WarehouseInboundDetailOutput> 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<string> SaveInboundLabelPdfAsync(string noticeNo, byte[] pdfBytes)
|
||||
{
|
||||
var safeNo = string.IsNullOrWhiteSpace(noticeNo) ? "inbound" : noticeNo.Trim();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user