using System.Text.Json;
using Admin.NET.Plugin.AiDOP.DataPlatform.Executors;
using Admin.NET.Plugin.AiDOP.DataPlatform.Sequence;
using Admin.NET.Plugin.AiDOP.Entity.DataPlatform;
using Admin.NET.Plugin.AiDOP.WorkOrder;
using Microsoft.Extensions.Logging;
using SqlSugar;
namespace Admin.NET.Plugin.AiDOP.DataPlatform.Wms;
///
/// WP4 · 下达建领料单。移植基准:旧 DOP ResourceExamineAppService.CreatePickBill / GenerateNbr。
///
/// - 本库更新工单状态;165 经 Outbox 回写 Status/Batch(及里程碑工序 Status→r)
/// - NbrMaster/NbrDetail 在 165 直写(需 identity RecID 回填明细 NbrRecID,与旧 UoW 一致;单号走 WP2)
/// - 不做 MobileTask / QadTracking / 外协 PO / 库存占用(任务书本轮裁剪)
/// - D1:本动作不写 WorkOrdRouting C→W
///
///
[ApiDescriptionSettings(Order = 327, Description = "下达建领料单")]
[Route("api/aidop/wms-pick")]
[AllowAnonymous]
[NonUnify]
public class CreatePickBillService : IDynamicApiController, ITransient
{
public const string TargetSource = "DOPDEMORQ_SQLSERVER";
private const string NbrTypeBill = "SM";
private const string NbrTypeAllocate = "sm";
private readonly ISqlSugarClient _db;
private readonly MdpSourceScopeFactory _scopeFactory;
private readonly INbrSequenceService _seq;
private readonly KeeperResolveService _keeper;
private readonly MdpOutboxEnqueueService _enqueue;
private readonly ILogger _logger;
public CreatePickBillService(
ISqlSugarClient db,
MdpSourceScopeFactory scopeFactory,
INbrSequenceService seq,
KeeperResolveService keeper,
MdpOutboxEnqueueService enqueue,
ILogger logger)
{
_db = db;
_scopeFactory = scopeFactory;
_seq = seq;
_keeper = keeper;
_enqueue = enqueue;
_logger = logger;
}
public sealed class CreatePickBillInput
{
/// 工单号,逗号分隔;空则按 OrdDate 窗口取 Status=p
public string? WorkOrd { get; set; }
public string Domain { get; set; } = "8010";
public string UserAccount { get; set; } = "aidop";
public long TenantId { get; set; }
}
[DisplayName("下达生成领料单")]
[HttpPost("create")]
public async Task