647556386
2025-12-03 c7971052ec1636e58fb3f3ee95c15148f2cd5232
ÏîÄ¿´úÂë/WMSÎÞ²Ö´¢°æ/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundPickingService.cs
@@ -1935,7 +1935,7 @@
                {
                    ReqCode = Guid.NewGuid().ToString(),
                    ReqTime = DateTime.Now.ToString(),
                    BusinessType = "3",
                    BusinessType = "2",
                    FactoryArea = outboundOrder.FactoryArea,
                    OperationType = 1,
@@ -2723,6 +2723,34 @@
                    }
                    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 = 0,
                        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);
                }
                //判断入库单据明细是否全部是完成状态
                int e = inboundOrder.Details.Count();
@@ -2754,113 +2782,104 @@
                _outboundOrderService.UpdateData(outboundOrder);
                _unitOfWorkManage.CommitTran();
                if (inboundOrder.OrderStatus == InOrderStatusEnum.入库完成.ObjToInt())
                //入库回传MES
                var infeedmodel = new FeedbackInboundRequestModel
                {
                    var feedmodel = 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
                    {
                        reqCode = Guid.NewGuid().ToString(),
                        reqTime = DateTime.Now.ToString(),
                        business_type = inboundOrder.BusinessType,
                        factoryArea = inboundOrder.FactoryArea,
                        operationType = 1,
                        Operator = inboundOrder.Operator,
                        orderNo = inboundOrder.UpperOrderNo,
                        status = inboundOrder.OrderStatus,
                        details = new List<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 groupedData = inboundOrder.Details.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();
                    feedmodel.details = groupedData;
                    var result = await _invokeMESService.FeedbackInbound(feedmodel);
                    if (result != null && result.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();
                    }
                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();
                }
                if (outboundOrder.OrderStatus == OutOrderStatusEnum.出库完成.ObjToInt())
                {
                    var feedmodel = new FeedbackOutboundRequestModel
                //出库回传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 = outboundOrder.Operator,
                        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();
                    foreach (var detail in outboundOrder.Details)
                    {
                        // èŽ·å–è¯¥æ˜Žç»†å¯¹åº”çš„æ¡ç ä¿¡æ¯ï¼ˆä»Žé”å®šè®°å½•ï¼‰
                        var detailLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
                            .Where(x => x.OrderNo == outboundOrder.OrderNo &&
                                       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.BarcodeQty),
                                  currentDeliveryQty = group.Sum(x => x.BarcodeQty),
                                  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.BarcodeQty
                                  }).ToList()
                              }).ToList();
                        feedmodel.details.AddRange(groupdata);
                    }
                    var result = await _invokeMESService.FeedbackOutbound(feedmodel);
                    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();
                    }
                    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.BarcodeQty),
                                currentDeliveryQty = group.Sum(x => x.BarcodeQty),
                                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.BarcodeQty
                                }).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)