pan
2025-12-03 98c5fbdce57cf9f0914ca5fb2c659c9396d3aed6
ÏîÄ¿´úÂë/WMSÎÞ²Ö´¢°æ/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundPickingService.cs
@@ -20,16 +20,20 @@
using WIDESEA_Core.BaseServices;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
using WIDESEA_Core.Utilities;
using WIDESEA_DTO.Allocate;
using WIDESEA_DTO.Basic;
using WIDESEA_DTO.Inbound;
using WIDESEA_DTO.Outbound;
using WIDESEA_IAllocateService;
using WIDESEA_IBasicService;
using WIDESEA_ICheckService;
using WIDESEA_IInboundService;
using WIDESEA_IOutboundService;
using WIDESEA_IStockService;
using WIDESEA_Model.Models;
using WIDESEA_Model.Models.Basic;
using WIDESEA_Model.Models.Check;
namespace WIDESEA_OutboundService
{
@@ -56,8 +60,8 @@
        private readonly IAllocateService _allocateService;
        private readonly IRepository<Dt_InboundOrder> _inboundOrderRepository;
        private readonly IInboundOrderDetailService _inboundOrderDetailService;
        private readonly IRepository<Dt_WarehouseArea> _warehouseAreaRepository;
        private readonly IReCheckOrderService _reCheckOrderService;
        private readonly ILogger<OutboundPickingService> _logger;
        private Dictionary<string, string> stations = new Dictionary<string, string>
@@ -77,7 +81,7 @@
        public OutboundPickingService(IRepository<Dt_PickingRecord> BaseDal, IUnitOfWorkManage unitOfWorkManage, IStockInfoService stockInfoService, IStockService stockService,
            IOutStockLockInfoService outStockLockInfoService, IStockInfoDetailService stockInfoDetailService, ILocationInfoService locationInfoService,
            IOutboundOrderDetailService outboundOrderDetailService, ISplitPackageService splitPackageService, IOutboundOrderService outboundOrderService,
            IRepository<Dt_Task> taskRepository, IESSApiService eSSApiService, ILogger<OutboundPickingService> logger, IInvokeMESService invokeMESService, IDailySequenceService dailySequenceService, IAllocateService allocateService, IRepository<Dt_InboundOrder> inboundOrderRepository,IInboundOrderDetailService inboundOrderDetailService) : base(BaseDal)
            IRepository<Dt_Task> taskRepository, IESSApiService eSSApiService, ILogger<OutboundPickingService> logger, IInvokeMESService invokeMESService, IDailySequenceService dailySequenceService, IAllocateService allocateService, IRepository<Dt_InboundOrder> inboundOrderRepository, IInboundOrderDetailService inboundOrderDetailService, IRepository<Dt_WarehouseArea> warehouseAreaRepository, IReCheckOrderService reCheckOrderService) : base(BaseDal)
        {
            _unitOfWorkManage = unitOfWorkManage;
            _stockInfoService = stockInfoService;
@@ -96,6 +100,8 @@
            _allocateService = allocateService;
            _inboundOrderRepository = inboundOrderRepository;
            _inboundOrderDetailService = inboundOrderDetailService;
            _warehouseAreaRepository = warehouseAreaRepository;
            _reCheckOrderService = reCheckOrderService;
        }
@@ -471,10 +477,21 @@
                    var completedLockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
                        .Where(it => it.CurrentBarcode == barcode &&
                                   (it.Status == (int)OutLockStockStatusEnum.拣选完成 ||
                                    it.Status == (int)OutLockStockStatusEnum.已释放 ||
                                    it.Status == (int)OutLockStockStatusEnum.已取走 ||
                                    it.PickedQty >= it.AssignQuantity)).FirstAsync();
                    if (completedLockInfo != null)
                        throw new Exception($"条码{barcode}已经完成分拣,不能重复分拣");
                    {
                        string statusMsg = completedLockInfo.Status switch
                        {
                            (int)OutLockStockStatusEnum.拣选完成 => "已经完成分拣",
                            (int)OutLockStockStatusEnum.已释放 => "已经释放",
                            (int)OutLockStockStatusEnum.已取走 => "已经取走",
                            _ => "已经完成分拣"
                        };
                        throw new Exception($"条码{barcode}{statusMsg},不能重复分拣");
                    }
                    else
                        return null;
                }
@@ -747,13 +764,13 @@
                PickTime = DateTime.Now,
                Operator = App.User.UserName,
                OutStockLockId = result.FinalLockInfo.Id,
                BarcodeUnit=result.FinalLockInfo.BarcodeUnit,
                BarcodeQty=result.FinalLockInfo.BarcodeQty,
                BatchNo= result.FinalLockInfo.BatchNo,
                lineNo= result.FinalLockInfo.lineNo ,
                SupplyCode= result.FinalLockInfo.SupplyCode ,
                WarehouseCode = result.FinalLockInfo.WarehouseCode  ,
                BarcodeUnit = result.FinalLockInfo.BarcodeUnit,
                BarcodeQty = result.FinalLockInfo.BarcodeQty,
                BatchNo = result.FinalLockInfo.BatchNo,
                lineNo = result.FinalLockInfo.lineNo,
                SupplyCode = result.FinalLockInfo.SupplyCode,
                WarehouseCode = result.FinalLockInfo.WarehouseCode,
            };
@@ -810,13 +827,13 @@
        private async Task<bool> CanCancelPicking(Dt_OutStockLockInfo lockInfo, Dt_StockInfoDetail stockDetail)
        {
            if (lockInfo.Status == (int)OutLockStockStatusEnum.已释放 || lockInfo.Status == (int)OutLockStockStatusEnum.已取走)
                return false;
            // é”å®šä¿¡æ¯çŠ¶æ€æ£€æŸ¥
            if (lockInfo.Status != (int)OutLockStockStatusEnum.拣选完成)
                return false;
            ////// åº“存状态检查
            ////if (stockDetail.Status == StockStatusEmun.出库完成.ObjToInt())
            ////    return false;
            // å¦‚果是拆包记录,还需要检查父锁定信息状态
            if (lockInfo.IsSplitted == 1 && lockInfo.ParentLockId.HasValue)
@@ -824,7 +841,9 @@
                var parentLock = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
                    .FirstAsync(x => x.Id == lockInfo.ParentLockId.Value);
                if (parentLock == null || parentLock.Status == (int)OutLockStockStatusEnum.回库中)
                if (parentLock == null || parentLock.Status == (int)OutLockStockStatusEnum.回库中 ||
                        parentLock.Status == (int)OutLockStockStatusEnum.已释放 ||
                        parentLock.Status == (int)OutLockStockStatusEnum.已取走)
                    return false;
            }
@@ -1382,8 +1401,8 @@
            await _outStockLockInfoService.Db.Updateable<Dt_OutStockLockInfo>()
                .SetColumns(it => new Dt_OutStockLockInfo
                {
                    Status = (int)OutLockStockStatusEnum.已释放, // éœ€è¦æ–°å¢žè¿™ä¸ªçŠ¶æ€
                   // ReleaseTime = DateTime.Now,
                    Status = (int)OutLockStockStatusEnum.已释放,
                    Operator = App.User.UserName
                })
                .Where(it => lockIds.Contains(it.Id))
@@ -1670,7 +1689,7 @@
            // åˆ é™¤åŽŸå§‹å‡ºåº“ä»»åŠ¡
            _taskRepository.DeleteAndMoveIntoHty(originalTask, OperateTypeEnum.自动完成);
            // await _taskRepository.Db.Deleteable(originalTask).ExecuteCommandAsync();
            await _taskRepository.Db.Deleteable(originalTask).ExecuteCommandAsync();
@@ -1777,7 +1796,7 @@
                {
                    newStatus = (int)OutOrderStatusEnum.出库完成;
                }
                else if (hasPartial )
                else if (hasPartial)
                {
                    newStatus = (int)OutOrderStatusEnum.出库中;
                }
@@ -1799,11 +1818,7 @@
                    _logger.LogInformation($"订单状态更新 - OrderNo: {orderNo}, æ—§çŠ¶æ€: {outboundOrder.OrderStatus}, æ–°çŠ¶æ€: {newStatus}");
                    // åªæœ‰æ­£å¸¸åˆ†æ‹£å®Œæˆæ—¶æ‰å‘MES反馈
                    if (allCompleted && newStatus == (int)OutOrderStatusEnum.出库完成)
                    {
                        await HandleOrderCompletion(outboundOrder, orderNo);
                    }
                }
            }
            catch (Exception ex)
@@ -1852,7 +1867,7 @@
                    .SetColumns(it => new Dt_OutboundOrderDetail
                    {
                        OrderDetailStatus = newStatus,
                    })
                    .Where(it => it.Id == orderDetailId)
                    .ExecuteCommandAsync();
@@ -1933,14 +1948,14 @@
                {
                    ReqCode = Guid.NewGuid().ToString(),
                    ReqTime = DateTime.Now.ToString(),
                    BusinessType = "3",
                    BusinessType = "2",
                    FactoryArea = outboundOrder.FactoryArea,
                    OperationType = 1,
                    Operator = App.User.UserName,
                    OrderNo = outboundOrder.UpperOrderNo,
                   // documentsNO = outboundOrder.OrderNo,
                   // status = outboundOrder.OrderStatus,
                    // documentsNO = outboundOrder.OrderNo,
                    // status = outboundOrder.OrderStatus,
                    fromWarehouse = allocate?.FromWarehouse ?? "",
                    toWarehouse = allocate?.ToWarehouse ?? "",
                    Details = new List<AllocateDtoDetail>()
@@ -1951,31 +1966,31 @@
                    .Where(x => x.OrderNo == orderNo && x.Status == (int)OutLockStockStatusEnum.拣选完成)
                    .ToListAsync();
                var groupedData = lists.GroupBy(item => new { item.MaterielCode, item.lineNo, item.Unit, item.WarehouseCode })
                var groupedData = lists.GroupBy(item => new { item.MaterielCode, item.lineNo, item.BarcodeUnit, item.WarehouseCode })
                   .Select(group => new AllocateDtoDetail
                   {
                       MaterialCode = group.Key.MaterielCode,
                       LineNo = group.Key.lineNo,
                       WarehouseCode = group.Key.WarehouseCode,
                       Qty = group.Sum(x => x.PickedQty),
                       Unit = group.Key.Unit,
                       Unit = group.Key.BarcodeUnit,
                       Barcodes = group.Select(row => new BarcodeInfo
                       {
                           Barcode = row.CurrentBarcode,
                           SupplyCode = row.SupplyCode,
                           BatchNo = row.BatchNo,
                           Unit = row.Unit,
                           Unit = row.BarcodeUnit,
                           Qty = row.PickedQty
                       }).ToList()
                   }).ToList();
                allocatefeedmodel.Details = groupedData;
                var result = await _invokeMESService.FeedbackAllocate(allocatefeedmodel);
                if (result != null && result.code == 200)
                {
                {
                    await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>()
                           .SetColumns(x => x.ReturnToMESStatus == 1)
                           .Where(x => x.OrderId == outboundOrder.Id).ExecuteCommandAsync();
@@ -2012,10 +2027,10 @@
                    // åªèŽ·å–å·²æ‹£é€‰å®Œæˆçš„é”å®šè®°å½•
                    var lists = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
                        .Where(x => x.OrderNo == orderNo && x.Status == (int)OutLockStockStatusEnum.拣选完成)
                        .Where(x => x.OrderNo == orderNo && (x.Status == (int)OutLockStockStatusEnum.拣选完成 || x.Status == (int)OutLockStockStatusEnum.已回库))
                        .ToListAsync();
                    var groupedData = lists.GroupBy(item => new { item.MaterielCode, item.lineNo, item.Unit, item.WarehouseCode })
                    var groupedData = lists.GroupBy(item => new { item.MaterielCode, item.lineNo, item.BarcodeUnit, item.WarehouseCode })
                       .Select(group => new FeedbackOutboundDetailsModel
                       {
                           materialCode = group.Key.MaterielCode,
@@ -2023,13 +2038,13 @@
                           warehouseCode = group.Key.WarehouseCode,
                           qty = group.Sum(x => x.PickedQty),
                           currentDeliveryQty = group.Sum(x => x.PickedQty),
                           unit = group.Key.Unit,
                           unit = group.Key.BarcodeUnit,
                           barcodes = group.Select(row => new WIDESEA_DTO.Outbound.BarcodesModel
                           {
                               barcode = row.CurrentBarcode,
                               supplyCode = row.SupplyCode,
                               batchNo = row.BatchNo,
                               unit = row.Unit,
                               unit = row.BarcodeUnit,
                               qty = row.PickedQty
                           }).ToList()
                       }).ToList();
@@ -2077,8 +2092,7 @@
            {
                // 1. åˆ é™¤åº“存数量为0的明细记录
                var deleteDetailCount = await _stockInfoDetailService.Db.Deleteable<Dt_StockInfoDetail>()
                    .Where(x => x.StockId == stockId && x.StockQuantity == 0 && (x.Status == StockStatusEmun.出库完成.ObjToInt() || x.Status ==
                                          StockStatusEmun.入库完成.ObjToInt()))
                    .Where(x => x.StockId == stockId && x.StockQuantity == 0)
                    .ExecuteCommandAsync();
                await _stockInfoService.Db.Deleteable<Dt_StockInfo>()
@@ -2199,7 +2213,7 @@
                _logger.LogInformation($"订单 {orderNo} å·²æ ‡è®°ä¸ºå‡ºåº“完成");
                // å‘MES反馈订单完成(如果需要)
                await HandleOrderCompletion(outboundOrder, orderNo);
                //await HandleOrderCompletion(outboundOrder, orderNo);
            }
        }
@@ -2436,8 +2450,8 @@
                FactoryArea = originalLock.FactoryArea,
                lineNo = originalLock.lineNo,
                WarehouseCode = originalLock.WarehouseCode,
                BarcodeQty=originalLock.BarcodeQty,
                BarcodeUnit=originalLock.BarcodeUnit,
                BarcodeQty = originalLock.BarcodeQty,
                BarcodeUnit = originalLock.BarcodeUnit,
            };
@@ -2550,7 +2564,7 @@
        {
            List<Dt_InboundOrder> InOders = _inboundOrderRepository.QueryData().Where(x => x.OrderStatus != InOrderStatusEnum.入库完成.ObjToInt()).ToList();
            List<string> InOderCodes = InOders.Select(x => x.UpperOrderNo).ToList();
            return WebResponseContent.Instance.OK("成功",data: InOderCodes);
            return WebResponseContent.Instance.OK("成功", data: InOderCodes);
        }
        public WebResponseContent GetAvailablePickingOrders()
@@ -2566,7 +2580,7 @@
            try
            {
                Dt_InboundOrder inboundOrder = Db.Queryable<Dt_InboundOrder>().Where(x => x.UpperOrderNo == noStockOut.inOder && x.OrderStatus != InOrderStatusEnum.入库完成.ObjToInt()).Includes(x => x.Details).First();
                if(inboundOrder == null)
                if (inboundOrder == null)
                {
                    return WebResponseContent.Instance.Error($"未找到采购单:{noStockOut.inOder}");
                }
@@ -2593,7 +2607,7 @@
                //剩余入库数量即虚拟出入库剩余可出数量
                decimal outQuantity = matchedDetail.OrderQuantity - matchedDetail.ReceiptQuantity;
                if(outQuantity == 0)
                if (outQuantity == 0)
                {
                    return WebResponseContent.Instance.Error($"该采购单中的条码对应的可出数量为0");
                }
@@ -2607,7 +2621,7 @@
                if ((matchedCode.LockQuantity + matchedCode.NoStockOutQty) > matchedCode.OrderQuantity)
                {
                   return WebResponseContent.Instance.Error($"出库单明细数量溢出{matchedCode.LockQuantity - matchedCode.OrderQuantity}");
                    return WebResponseContent.Instance.Error($"出库单明细数量溢出{matchedCode.LockQuantity - matchedCode.OrderQuantity}");
                }
                matchedDetail.OrderDetailStatus = OrderDetailStatusEnum.Inbounding.ObjToInt();
                matchedCode.OrderDetailStatus = OrderDetailStatusEnum.AssignOver.ObjToInt();
@@ -2618,7 +2632,7 @@
                _unitOfWorkManage.CommitTran();
                return WebResponseContent.Instance.OK();
            }
            catch(Exception ex)
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
@@ -2643,7 +2657,7 @@
                }
                matchedDetail.NoStockOutQty = 0;
                if(matchedDetail.ReceiptQuantity==0 && matchedDetail.OverInQuantity==0)
                if (matchedDetail.ReceiptQuantity == 0 && matchedDetail.OverInQuantity == 0)
                {
                    matchedDetail.OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt();
                }
@@ -2671,23 +2685,23 @@
                return WebResponseContent.Instance.OK();
            }
            catch(Exception ex)
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
        public WebResponseContent NoStockOutSubmit(NoStockOutSubmit noStockOutSubmit)
        public async Task<WebResponseContent> NoStockOutSubmit(NoStockOutSubmit noStockOutSubmit)
        {
            try
            {
                Dt_InboundOrder inboundOrder = Db.Queryable<Dt_InboundOrder>().Where(x => x.UpperOrderNo == noStockOutSubmit.InOderSubmit && x.OrderStatus != InOrderStatusEnum.入库完成.ObjToInt()).Includes(x => x.Details).First();
                Dt_InboundOrder inboundOrder = _inboundOrderRepository.Db.Queryable<Dt_InboundOrder>().Where(x => x.UpperOrderNo == noStockOutSubmit.InOderSubmit && x.OrderStatus != InOrderStatusEnum.入库完成.ObjToInt()).Includes(x => x.Details).First();
                if (inboundOrder == null)
                {
                    return WebResponseContent.Instance.Error($"未找到采购单:{noStockOutSubmit.InOderSubmit}");
                }
                Dt_OutboundOrder outboundOrder = Db.Queryable<Dt_OutboundOrder>().Where(x => x.UpperOrderNo == noStockOutSubmit.OutOderSubmit && x.OrderStatus != OutOrderStatusEnum.出库完成.ObjToInt()).Includes(x => x.Details).First();
                Dt_OutboundOrder outboundOrder = _inboundOrderRepository.Db.Queryable<Dt_OutboundOrder>().Where(x => x.UpperOrderNo == noStockOutSubmit.OutOderSubmit && x.OrderStatus != OutOrderStatusEnum.出库完成.ObjToInt()).Includes(x => x.Details).First();
                if (outboundOrder == null)
                {
                    return WebResponseContent.Instance.Error($"未找到出库单:{noStockOutSubmit.OutOderSubmit}");
@@ -2696,9 +2710,9 @@
                List<Dt_OutboundOrderDetail> outboundOrderDetails = new List<Dt_OutboundOrderDetail>();
                foreach (var BarCode in noStockOutSubmit.BarCodeSubmit)
                {
                   var inboundOrderDetail = inboundOrder.Details.FirstOrDefault(detail => detail.Barcode == BarCode && detail.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt());
                    var inboundOrderDetail = inboundOrder.Details.FirstOrDefault(detail => detail.Barcode == BarCode && detail.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt());
                    if(inboundOrderDetail == null)
                    if (inboundOrderDetail == null)
                    {
                        return WebResponseContent.Instance.Error($"在采购单 {noStockOutSubmit.InOderSubmit} ä¸­æœªæ‰¾åˆ°æ¡ç ä¸º {BarCode} çš„æ˜Žç»†ã€‚");
                    }
@@ -2715,24 +2729,62 @@
                    outboundOrderDetail.LockQuantity += outboundOrderDetail.NoStockOutQty;
                    outboundOrderDetail.OverOutQuantity = outboundOrderDetail.LockQuantity;
                    if(outboundOrderDetail.OrderQuantity == outboundOrderDetail.OverOutQuantity)
                    if (outboundOrderDetail.OrderQuantity == outboundOrderDetail.OverOutQuantity)
                    {
                        outboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
                    }
                    outboundOrderDetails.Add(outboundOrderDetail);
                    var newLockInfo = new Dt_OutStockLockInfo
                    {
                        OrderNo = outboundOrder.UpperOrderNo,
                        OrderDetailId = outboundOrderDetail.Id,
                        OutboundBatchNo = outboundOrderDetail.BatchNo,
                        MaterielCode = outboundOrderDetail.MaterielCode,
                        MaterielName = outboundOrderDetail.MaterielName,
                        StockId = 0,
                        OrderQuantity = outboundOrderDetail.OrderQuantity,
                        AssignQuantity = outboundOrderDetail.OverOutQuantity,
                        PickedQty = outboundOrderDetail.NoStockOutQty,
                        LocationCode = "空",
                        PalletCode = "空",
                        TaskNum = 0,
                        Status = (int)OutLockStockStatusEnum.拣选完成,
                        Unit = outboundOrderDetail.Unit,
                        SupplyCode = outboundOrderDetail.SupplyCode?? "无",
                        OrderType = outboundOrder.OrderType,
                        CurrentBarcode = inboundOrderDetail.Barcode,
                        IsSplitted = 1,
                        Operator = App.User.UserName,
                        lineNo= outboundOrderDetail.lineNo,
                        WarehouseCode = outboundOrderDetail.WarehouseCode ?? "无",
                        BarcodeQty=outboundOrderDetail.NoStockOutQty,
                        BarcodeUnit =outboundOrderDetail.BarcodeUnit,
                        BatchNo = outboundOrderDetail.BatchNo
                    };
                    _outStockLockInfoService.AddData(newLockInfo);
                }
                //判断入库单据明细是否全部是完成状态
                bool inoderOver = inboundOrder.Details.Count() == inboundOrder.Details.Select(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).Count();
                int e = inboundOrder.Details.Count();
                int w = inboundOrder.Details.Where(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).Count();
                bool inoderOver = inboundOrder.Details.Count() == inboundOrder.Details.Where(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).Count();
                if (inoderOver)
                {
                    inboundOrder.OrderStatus = InOrderStatusEnum.入库完成.ObjToInt();
                }
                else
                {
                    inboundOrder.OrderStatus = InOrderStatusEnum.入库中.ObjToInt();
                }
                //判断出库单据明细是否全部是完成状态
                bool outOderOver = outboundOrder.Details.Count() == outboundOrder.Details.Select(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).Count();
                bool outOderOver = outboundOrder.Details.Count() == outboundOrder.Details.Where(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).Count();
                if (outOderOver)
                {
                    outboundOrder.OrderStatus = OutOrderStatusEnum.出库完成.ObjToInt();
                }
                else
                {
                    outboundOrder.OrderStatus = OutOrderStatusEnum.出库中.ObjToInt();
                }
                //数据处理
                _unitOfWorkManage.BeginTran();
@@ -2742,9 +2794,108 @@
                _outboundOrderService.UpdateData(outboundOrder);
                _unitOfWorkManage.CommitTran();
                //入库回传MES
                var infeedmodel = new FeedbackInboundRequestModel
                {
                    reqCode = Guid.NewGuid().ToString(),
                    reqTime = DateTime.Now.ToString(),
                    business_type = inboundOrder.BusinessType,
                    factoryArea = inboundOrder.FactoryArea,
                    operationType = 1,
                    Operator = App.User.UserName,
                    orderNo = inboundOrder.UpperOrderNo,
                    status = inboundOrder.OrderStatus,
                    details = new List<FeedbackInboundDetailsModel>()
                };
                var groupedData = inboundOrderDetails.GroupBy(item => new { item.MaterielCode, item.SupplyCode, item.BatchNo, item.lineNo, item.BarcodeUnit, item.WarehouseCode })
                    .Select(group => new FeedbackInboundDetailsModel
                    {
                        materialCode = group.Key.MaterielCode,
                        supplyCode = group.Key.SupplyCode,
                        batchNo = group.Key.BatchNo,
                        lineNo = group.Key.lineNo,
                        warehouseCode = group.Key.WarehouseCode,
                        qty = group.Sum(x => x.BarcodeQty),
                        // warehouseCode= "1072",
                        unit = group.Key.BarcodeUnit,
                        barcodes = group.Select(row => new FeedbackBarcodesModel
                        {
                            barcode = row.Barcode,
                            qty = row.BarcodeQty
                        }).ToList()
                    }).ToList();
                infeedmodel.details = groupedData;
                var result1 = await _invokeMESService.FeedbackInbound(infeedmodel);
                if (result1 != null && result1.code == 200)
                {
                    _inboundOrderRepository.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 1 })
                    .Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
                    _inboundOrderDetailService.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 1 })
                    .Where(it => it.OrderId == inboundOrder.Id).ExecuteCommand();
                }
                //出库回传MES
                var outfeedmodel = new FeedbackOutboundRequestModel
                    {
                        reqCode = Guid.NewGuid().ToString(),
                        reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                        business_type = outboundOrder.BusinessType,
                        factoryArea = outboundOrder.FactoryArea,
                        operationType = 1,
                        Operator = App.User.UserName,
                        orderNo = outboundOrder.UpperOrderNo,
                        documentsNO = outboundOrder.OrderNo,
                        status = outboundOrder.OrderStatus,
                        details = new List<FeedbackOutboundDetailsModel>()
                    };
                foreach (var detail in outboundOrder.Details)
                {
                    // èŽ·å–è¯¥æ˜Žç»†å¯¹åº”çš„æ¡ç ä¿¡æ¯ï¼ˆä»Žé”å®šè®°å½•ï¼‰
                    var detailLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
                        .Where(x => x.OrderNo == outboundOrder.UpperOrderNo &&
                                    x.OrderDetailId == detail.Id &&
                                        (x.Status == (int)OutLockStockStatusEnum.拣选完成 || x.Status == (int)OutLockStockStatusEnum.已回库))
                        .ToListAsync();
                        var groupdata = detailLocks.GroupBy(item => new { item.MaterielCode, item.lineNo, item.BarcodeUnit, item.WarehouseCode })
                              .Select(group => new FeedbackOutboundDetailsModel
                              {
                                  materialCode = group.Key.MaterielCode,
                                  lineNo = group.Key.lineNo,
                                  warehouseCode = group.Key.WarehouseCode,
                                  qty = group.Sum(x => x.PickedQty),
                                  currentDeliveryQty = group.Sum(x => x.PickedQty),
                                  unit = group.Key.BarcodeUnit,
                                  barcodes = group.Select(lockInfo => new WIDESEA_DTO.Outbound.BarcodesModel
                                  {
                                      barcode = lockInfo.CurrentBarcode,
                                      supplyCode = lockInfo.SupplyCode,
                                      batchNo = lockInfo.BatchNo,
                                      unit = lockInfo.BarcodeUnit,
                                      qty = lockInfo.PickedQty
                                  }).ToList()
                              }).ToList();
                        outfeedmodel.details.AddRange(groupdata);
                    }
                    var result = await _invokeMESService.FeedbackOutbound(outfeedmodel);
                    if (result != null && result.code == 200)
                    {
                        await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>()
                            .SetColumns(x => x.ReturnToMESStatus == 1)
                            .Where(x => x.OrderId == outboundOrder.Id)
                            .ExecuteCommandAsync();
                    await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>()
                        .SetColumns(x => x.ReturnToMESStatus == 1)
                        .Where(x => x.Id == outboundOrder.Id)
                        .ExecuteCommandAsync();
                }
                return WebResponseContent.Instance.OK();
            }
            catch(Exception ex)
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
@@ -2752,11 +2903,243 @@
        }
        #endregion
        public WebResponseContent UnPalletQuantity(string orderNo)
        {
            // åˆå§‹åŒ–返回DTO(默认值都为0,避免null)
            var resultDTO = new PalletSumQuantityDTO
            {
                StockSumQuantity = 0,
                StockCount = 0,
                UniqueUnit = ""
            };
            WebResponseContent content = new WebResponseContent();
            try
            {
                if (string.IsNullOrWhiteSpace(orderNo))
                {
                    return content.Error("传入的订单号orderNo为空或空白");
                }
                var orderDetail = Db.Queryable<Dt_PickingRecord>().Where(s => s.OrderNo == orderNo).ToList();
                if (orderDetail == null)
                {
                    return content.Error("未找到单据");
                }
                var unitGroups = orderDetail.GroupBy(d => d.BarcodeUnit).ToList();
                if (unitGroups.Count == 1)
                {
                    resultDTO.UniqueUnit = unitGroups.First().Key;
                }
                else
                {
                    resultDTO.UniqueUnit = "";
                }
                var validDetails = _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>().Where(s => s.OrderNo == orderNo).ToList();
                resultDTO.StockSumQuantity = orderDetail.Sum(d => d.PickQuantity);
                resultDTO.StockCount = orderDetail.Count;
                if (validDetails.Any())
                {
                    resultDTO.StockSumQuantity -= validDetails.Sum(d => d.StockQuantity);
                    // æ˜Žç»†è®°å½•数:符合条件的有效记录条数
                    resultDTO.StockCount -= validDetails.Count;
                }
                return content.OK("", resultDTO);
            }
            catch (Exception ex)
            {
                return content.Error("SumQuantity ç»Ÿè®¡åº“存数量失败,订单号:{OrderNo}");
            }
        }
        public WebResponseContent BarcodeMaterielGroup(BarcodeMaterielGroupDTO materielGroupDTO)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                (bool, string, object?) result2 = ModelValidate.ValidateModelData(materielGroupDTO);
                if (!result2.Item1) return content = WebResponseContent.Instance.Error(result2.Item2);
                //  materielGroupDTO.WarehouseCode
                var code = _warehouseAreaRepository.Db.Queryable<Dt_WarehouseArea>().Where(x => x.Code == materielGroupDTO.WarehouseType).Select(x => x.Code).First();
                if (string.IsNullOrEmpty(code))
                {
                    return content = WebResponseContent.Instance.Error($"仓库中没有该{materielGroupDTO.WarehouseType}编号。");
                }
                if (materielGroupDTO.orderTypes == InOrderTypeEnum.ReCheck.ObjToInt())
                {
                    var dborder = _reCheckOrderService.Db.Queryable<Dt_ReCheckOrder>().First(x => x.OrderNo == materielGroupDTO.OrderNo);
                    if (dborder != null && dborder.SignSeq == 0)
                    {
                        return content.Error("只有拿到重检结果才能入库!");
                    }
                    else
                    {
                        return content.Error("没有找到重检单据数据。");
                    }
                }
                //  Dt_InboundOrder inboundOrder = GetInboundOrder(materielGroupDTO.OrderNo);
                var dbinboundOrderDetails = Db.Queryable<Dt_PickingRecord>().Where(x => x.OrderNo == materielGroupDTO.OrderNo && !x.IsCancelled && x.Barcode == materielGroupDTO.Barcodes).ToList();
                if (dbinboundOrderDetails != null && !dbinboundOrderDetails.Any())
                {
                    return content = WebResponseContent.Instance.Error($"单据中没有该{materielGroupDTO.Barcodes}条码数据。");
                }
                List<string?> materielCodes = dbinboundOrderDetails.GroupBy(x => x.Barcode).Select(x => x.Key).ToList();
                Dt_StockInfo? stockInfo = _stockService.StockInfoService.GetStockByPalletCode(materielGroupDTO.PalletCode);
                (bool, string, object?) result = CheckMaterielGroupParam(materielGroupDTO, materielCodes, stockInfo);
                if (!result.Item1) return content = WebResponseContent.Instance.Error(result.Item2);
                if (stockInfo == null)
                {
                    stockInfo = new Dt_StockInfo() { PalletType = (int)PalletTypeEnum.None, LocationType = materielGroupDTO.locationType.ObjToInt() };
                    stockInfo.Details = new List<Dt_StockInfoDetail>();
                }
                var inboindId = 0; Dt_InboundOrder dt_InboundOrder = null;
                var dbinbound = _inboundOrderRepository.QueryData(x => x.InboundOrderNo == dbinboundOrderDetails.First().OrderNo).First();
                if (dbinbound == null)
                {
                    dt_InboundOrder = new Dt_InboundOrder
                    {
                        WarehouseId = 0,
                        InboundOrderNo = dbinboundOrderDetails.First()?.OrderNo,
                        UpperOrderNo = dbinboundOrderDetails.First()?.OrderNo,
                        SupplierId = dbinboundOrderDetails.First()?.SupplyCode,
                        OrderType = materielGroupDTO.orderTypes,
                        BusinessType = materielGroupDTO.orderTypes.ToString(),
                        FactoryArea = dbinboundOrderDetails.First()?.FactoryArea,
                        Remark = "",
                        Details = new List<Dt_InboundOrderDetail>()
                    };
                    inboindId = _inboundOrderRepository.AddData(dt_InboundOrder);
                }
                else
                {
                    dt_InboundOrder = new Dt_InboundOrder { Details = new List<Dt_InboundOrderDetail>() };
                    inboindId = dbinbound.Id;
                }
                foreach (var item in dbinboundOrderDetails)
                {
                    stockInfo.Details.Add(new Dt_StockInfoDetail
                    {
                        StockId = stockInfo == null ? 0 : stockInfo.Id,
                        Barcode = item.Barcode,
                        MaterielCode = item.MaterielCode,
                        BatchNo = item.BatchNo,
                        Unit = item.BarcodeUnit,
                        InboundOrderRowNo = item.lineNo,
                        SupplyCode = item.SupplyCode,
                        WarehouseCode = materielGroupDTO.WarehouseType,
                        StockQuantity = item.PickQuantity,
                        BarcodeQty = item.BarcodeQty,
                        BarcodeUnit = item.BarcodeUnit,
                        FactoryArea = item.FactoryArea,
                        Status = 0,
                        OrderNo = item.OrderNo,
                        BusinessType = materielGroupDTO.orderTypes.ToString()
                    });
                    item.WarehouseCode = item.WarehouseCode;
                    dt_InboundOrder.Details.Add(new Dt_InboundOrderDetail
                    {
                        OrderId = inboindId,
                        MaterielCode = item.MaterielCode,
                        MaterielName = "",
                        BatchNo = item.BatchNo,
                        OrderQuantity = item.PickQuantity,
                        ReceiptQuantity = 0,
                        OverInQuantity = 0,
                        Unit = item.BarcodeUnit,
                        RowNo = 0,
                        lineNo = item.lineNo,
                        SupplyCode = item.SupplyCode,
                        WarehouseCode = item.WarehouseCode,
                        Barcode = item.Barcode,
                        OutBoxbarcodes = "",
                        BarcodeQty = (decimal)item.BarcodeQty,
                        BarcodeUnit = item.BarcodeUnit
                    });
                }
                _inboundOrderDetailService.Db.Insertable<Dt_InboundOrderDetail>(dt_InboundOrder.Details);
                if (stockInfo.Id == 0)
                {
                    stockInfo.PalletCode = materielGroupDTO.PalletCode;
                    stockInfo.StockStatus = StockStatusEmun.组盘暂存.ObjToInt();
                }
                stockInfo.PalletType = (int)PalletTypeEnum.None;
                List<int> updateDetailIds = dbinboundOrderDetails.Select(x => x.Id).ToList();
                try
                {
                    _unitOfWorkManage.BeginTran();
                    _stockService.StockInfoService.AddMaterielGroup(stockInfo);
                    _unitOfWorkManage.CommitTran();
                    return WebResponseContent.Instance.OK();
                }
                catch (Exception ex)
                {
                    _unitOfWorkManage.RollbackTran();
                    return WebResponseContent.Instance.Error(ex.Message);
                }
            }
            catch (Exception ex)
            {
                content = WebResponseContent.Instance.Error(ex.Message);
            }
            finally
            {
            }
            return content;
        }
        public (bool, string, object?) CheckMaterielGroupParam(BarcodeMaterielGroupDTO materielGroupDTO, List<string> barcodeCodes, Dt_StockInfo stockInfo)
        {
            (bool, string, object?) result = ModelValidate.ValidateModelData(materielGroupDTO);
            if (!result.Item1) return result;
            if (_taskRepository.QueryFirst(x => x.PalletCode == materielGroupDTO.PalletCode) != null)
            {
                return (false, "该托盘号已有任务", materielGroupDTO);
            }
            if (stockInfo != null && !string.IsNullOrEmpty(stockInfo.LocationCode) && stockInfo.StockStatus != StockStatusEmun.组盘暂存.ObjToInt())
            {
                return (false, "已上架的托盘不能再次组盘", materielGroupDTO);
            }
            if (_stockService.StockInfoDetailService.ExistBarcodes(barcodeCodes))
            {
                return (false, $"{barcodeCodes[0]} æ¡ç åœ¨åº“存中已存在", materielGroupDTO);
            }
            return (true, "成功", materielGroupDTO);
        }
        #endregion
    }
    #region æ”¯æŒç±»å®šä¹‰
@@ -2821,12 +3204,20 @@
        public bool HasSplitRecords { get; set; }
        public decimal RemainingLocksReturnQty { get; set; }
        public decimal PalletStockReturnQty { get; set; }
        public decimal SplitReturnQty { get; set; }
        public decimal TotalReturnQty { get; set; }
        // æœªåˆ†é…çš„锁定记录(如自动拆包产生的)
        public bool HasUnallocatedLocks { get; set; }
        public List<Dt_OutStockLockInfo> UnallocatedLocks { get; set; } = new List<Dt_OutStockLockInfo>();
        public decimal UnallocatedLocksReturnQty { get; set; }
        public List<Dt_OutStockLockInfo> RemainingLocks { get; set; } = new List<Dt_OutStockLockInfo>();
        public List<Dt_StockInfoDetail> PalletStockGoods { get; set; } = new List<Dt_StockInfoDetail>();
        public List<Dt_SplitPackageRecord> SplitRecords { get; set; } = new List<Dt_SplitPackageRecord>();
        public List<string> AllBarcodes { get; set; } = new List<string>();
        // ç©ºæ‰˜ç›˜ç›¸å…³å±žæ€§
        public bool IsEmptyPallet { get; set; }
        public bool HasActiveTasks { get; set; }