1
wankeda
2026-03-12 5bedccab71622d4c0f3b9e75966802be704ee019
WMS/WIDESEA_WMSServer/WIDESEA_InboundService/Base/InboundOrderService.cs
@@ -20,6 +20,7 @@
using WIDESEA_Core.CodeConfigEnum;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
using WIDESEA_Core.Log;
using WIDESEA_Core.Utilities;
using WIDESEA_DTO;
using WIDESEA_DTO.Basic;
@@ -110,7 +111,7 @@
                    {
                        string serialNumber = serialNumberObj?.ToString();
                        if (!string.IsNullOrEmpty(serialNumber))
                        {
                        {
                            serialNumbers.Add(serialNumber);
                        }
                        else
@@ -322,7 +323,7 @@
                decimal totalQuantity = stockInfo.Details.Sum(x => x.StockQuantity);
                inboundOrder.OrderStatus = InOrderStatusEnum.入库中.ObjToInt();
                _unitOfWorkManage.BeginTran();
                if (stockInfo.Id == 0)
                {
@@ -454,7 +455,7 @@
                        Materialweight = 0,
                        Wlstatus = (int)InventoryMaterialStatus.合格,
                        Mgeneratetime = DateTime.Now,
                        WarehouseId = warehouse.WarehouseId,
                        WarehouseId = 0,
                        System = inboundOrder.System,
                        Details = new List<Dt_StockInfoDetail>()
                    };
@@ -469,7 +470,16 @@
                    Dt_InboundOrderDetail notGroupDetail = new Dt_InboundOrderDetail();
                    notGroupDetail = inboundOrder.Details.Where(x => x.OrderDetailStatus <= OrderDetailStatusEnum.Inbounding.ObjToInt() && x.MaterielCode == model.MaterielCode && x.BatchNo == model.LotNo).FirstOrDefault();
                    notGroupDetail = inboundOrder.Details.Where(x => x.OrderDetailStatus <= OrderDetailStatusEnum.Inbounding.ObjToInt() && x.MaterielCode == model.MaterielCode && x.BatchNo == model.LotNo && x.OrderQuantity > x.ReceiptQuantity).FirstOrDefault();
                    if (notGroupDetail.MaterielType == 1)
                    {
                        stockInfo.WarehouseId = 6;
                    }
                    else if (notGroupDetail.MaterielType == 2)
                    {
                        stockInfo.WarehouseId = 5;
                    }
                    if (notGroupDetail == null)
                    {
@@ -565,29 +575,6 @@
                var quantities = new List<decimal>();
                var lotNos = new List<string>();
                var materielCodes = new List<string>();
                foreach (var item in saveModel.DelKeys)
                {
                    var delKeyDict = item as IDictionary<string, object>;
                    if (delKeyDict == null)
                    {
                        string json = JsonConvert.SerializeObject(item);
                        delKeyDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
                    }
                    // 处理序列号
                    if (!delKeyDict.TryGetValue("serialNumber", out object serialNumberObj) || serialNumberObj == null)
                    {
                        return WebResponseContent.Instance.Error("缺少serialNumber字段或值为空");
                    }
                    string serialNumber = serialNumberObj.ToString();
                    if (string.IsNullOrWhiteSpace(serialNumber))
                    {
                        return WebResponseContent.Instance.Error("serialNumber的值为空");
                    }
                    serialNumbers.Add(serialNumber);
                }
                // 获取仓库信息
                Dt_Warehouse warehouse = _warehouseService.Repository.QueryFirst(x => x.WarehouseId == warehouseId);
                if (warehouse == null)
@@ -612,8 +599,7 @@
                    .LeftJoin<Dt_InboundOrder>((cp, d, o) => d.OrderId == o.Id)
                    .Where((cp, d, o) =>
                        o.OrderNo == orderNo &&
                        o.WarehouseId == warehouse.WarehouseId &&
                        serialNumbers.Contains(cp.BoxCode)
                        o.WarehouseId == warehouse.WarehouseId
                    )
                    .Select((cp, d, o) => cp)
                    .ToList();
@@ -621,28 +607,25 @@
                //float totalQty = CPinboundOrderDetails.Sum(x => x.QtyOfpcs);
                // 验证查询到的数据数量是否匹配
                if (CPinboundOrderDetails.Count < serialNumbers.Count)
                {
                    return WebResponseContent.Instance.Error($"未找到所有对应的箱号信息,找到{CPinboundOrderDetails.Count}条,期望{serialNumbers.Count}条");
                }
                // 按照箱号分组,用于后续处理
                var cpDetailsByBoxCode = CPinboundOrderDetails
                    .GroupBy(x => x.BoxCode)
                    .ToDictionary(g => g.Key, g => g.ToList());
                var boxCodesToCheck = CPinboundOrderDetails
                    .Select(x => x.BoxCode)
                    .Where(bc => !string.IsNullOrEmpty(bc))
                    .Distinct()
                    .ToList();
                // 3. 查询这些箱号是否已存在于库存中
                var existingStockBoxCodes = _stockRepository.StockInfoRepository.Db
                .Queryable<Dt_StockInfo>()
                .LeftJoin<Dt_StockInfoDetail>((s, d) => s.Id == d.StockId)
                .LeftJoin<Dt_StockInfoDetailCP>((s, d, cp) => d.Id == cp.StockDetailId)
                .Where((s, d, cp) =>
                    serialNumbers.Contains(cp.BoxCode))
                .Select((s, d, cp) => cp.BoxCode)
                .Distinct()
                .ToList();
                    .Queryable<Dt_StockInfo>()
                    .LeftJoin<Dt_StockInfoDetail>((s, d) => s.Id == d.StockId)
                    .LeftJoin<Dt_StockInfoDetailCP>((s, d, cp) => d.Id == cp.StockDetailId)
                    .Where((s, d, cp) => boxCodesToCheck.Contains(cp.BoxCode) && !string.IsNullOrEmpty(cp.BoxCode))
                    .Select((s, d, cp) => cp.BoxCode)
                    .Distinct()
                    .ToList();
                // 4. 检查是否有重复
                if (existingStockBoxCodes.Any())
                {
                    return WebResponseContent.Instance.Error($"以下箱号已在库存中:{string.Join(",", existingStockBoxCodes)}");
@@ -855,7 +838,7 @@
        }
        #endregion
        #region 弃用
        public WebResponseContent CP1MaterielGroup(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
@@ -868,6 +851,29 @@
                var quantities = new List<decimal>();
                var lotNos = new List<string>();
                var materielCodes = new List<string>();
                foreach (var item in saveModel.DelKeys)
                {
                    var delKeyDict = item as IDictionary<string, object>;
                    if (delKeyDict == null)
                    {
                        string json = JsonConvert.SerializeObject(item);
                        delKeyDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
                    }
                    // 处理序列号
                    if (!delKeyDict.TryGetValue("serialNumber", out object serialNumberObj) || serialNumberObj == null)
                    {
                        return WebResponseContent.Instance.Error("缺少serialNumber字段或值为空");
                    }
                    string serialNumber = serialNumberObj.ToString();
                    if (string.IsNullOrWhiteSpace(serialNumber))
                    {
                        return WebResponseContent.Instance.Error("serialNumber的值为空");
                    }
                    serialNumbers.Add(serialNumber);
                }
                // 获取仓库信息
                Dt_Warehouse warehouse = _warehouseService.Repository.QueryFirst(x => x.WarehouseId == warehouseId);
                if (warehouse == null)
@@ -892,7 +898,8 @@
                    .LeftJoin<Dt_InboundOrder>((cp, d, o) => d.OrderId == o.Id)
                    .Where((cp, d, o) =>
                        o.OrderNo == orderNo &&
                        o.WarehouseId == warehouse.WarehouseId
                        o.WarehouseId == warehouse.WarehouseId &&
                        serialNumbers.Contains(cp.BoxCode)
                    )
                    .Select((cp, d, o) => cp)
                    .ToList();
@@ -900,25 +907,28 @@
                //float totalQty = CPinboundOrderDetails.Sum(x => x.QtyOfpcs);
                // 验证查询到的数据数量是否匹配
                if (CPinboundOrderDetails.Count < serialNumbers.Count)
                {
                    return WebResponseContent.Instance.Error($"未找到所有对应的箱号信息,找到{CPinboundOrderDetails.Count}条,期望{serialNumbers.Count}条");
                }
                // 按照箱号分组,用于后续处理
                var boxCodesToCheck = CPinboundOrderDetails
                    .Select(x => x.BoxCode)
                    .Where(bc => !string.IsNullOrEmpty(bc))
                    .Distinct()
                    .ToList();
                var cpDetailsByBoxCode = CPinboundOrderDetails
                    .GroupBy(x => x.BoxCode)
                    .ToDictionary(g => g.Key, g => g.ToList());
                // 3. 查询这些箱号是否已存在于库存中
                var existingStockBoxCodes = _stockRepository.StockInfoRepository.Db
                    .Queryable<Dt_StockInfo>()
                    .LeftJoin<Dt_StockInfoDetail>((s, d) => s.Id == d.StockId)
                    .LeftJoin<Dt_StockInfoDetailCP>((s, d, cp) => d.Id == cp.StockDetailId)
                    .Where((s, d, cp) => boxCodesToCheck.Contains(cp.BoxCode) && !string.IsNullOrEmpty(cp.BoxCode))
                    .Select((s, d, cp) => cp.BoxCode)
                    .Distinct()
                    .ToList();
                .Queryable<Dt_StockInfo>()
                .LeftJoin<Dt_StockInfoDetail>((s, d) => s.Id == d.StockId)
                .LeftJoin<Dt_StockInfoDetailCP>((s, d, cp) => d.Id == cp.StockDetailId)
                .Where((s, d, cp) =>
                    serialNumbers.Contains(cp.BoxCode))
                .Select((s, d, cp) => cp.BoxCode)
                .Distinct()
                .ToList();
                // 4. 检查是否有重复
                if (existingStockBoxCodes.Any())
                {
                    return WebResponseContent.Instance.Error($"以下箱号已在库存中:{string.Join(",", existingStockBoxCodes)}");
@@ -1127,6 +1137,7 @@
            return content;
        }
        #endregion
        public string ReceiveWMSTaskin = WIDESEA_Core.Helper.AppSettings.Configuration["ReceiveWMSTaskin"];
@@ -1289,17 +1300,7 @@
        public int GetPalletType(Dt_Warehouse warehouse, string palletCode)
        {
            if (warehouse.WarehouseCode == WarehouseEnum.SC01_DW.ObjToString())
            {
                Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.CodeStartStr == palletCode.Substring(0, 2));
                if (palletTypeInfo == null)
                {
                    throw new Exception($"托盘号错误");
                }
                return palletTypeInfo.PalletType;
            }
            if (warehouse.WarehouseCode == WarehouseEnum.SC01_BC.ObjToString())
            if (warehouse.WarehouseCode.Contains("BC"))
            {
                Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.CodeStartStr == palletCode.Substring(0, 3));
                if (palletTypeInfo == null)
@@ -1308,35 +1309,16 @@
                }
                return palletTypeInfo.PalletType;
            }
            //else if (warehouse.WarehouseCode == WarehouseEnum.HA152.ObjToString())
            //{
            //    Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.CodeStartStr == palletCode.Substring(0, 2));
            //    if (palletTypeInfo == null)
            //    {
            //        throw new Exception($"托盘号错误");
            //    }
            //    return palletTypeInfo.PalletType;
            //}
            //else if (warehouse.WarehouseCode == WarehouseEnum.HA57.ObjToString())
            //{
            //    Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.CodeStartStr == palletCode.Substring(0, 3));
            //    if (palletTypeInfo == null)
            //    {
            //        throw new Exception($"托盘号错误");
            //    }
            //    return palletTypeInfo.PalletType;
            //}
            //else if (warehouse.WarehouseCode == WarehouseEnum.HA58.ObjToString())
            //{
            //    Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.CodeStartStr == palletCode.Substring(0, 2));
            //    if (palletTypeInfo == null)
            //    {
            //        throw new Exception($"托盘号错误");
            //    }
            //    return palletTypeInfo.PalletType;
            //}
            return -1;
            else
            {
                Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.CodeStartStr == palletCode.Substring(0, 2));
                if (palletTypeInfo == null)
                {
                    throw new Exception($"托盘号错误");
                }
                return palletTypeInfo.PalletType;
            }
            return 0;
        }
        /// <summary>
        /// 判断正确时间格式
@@ -1573,6 +1555,7 @@
                                {
                                    OrderId = orderDetail1.OrderId,
                                    MaterielCode = item.MaterielCode,
                                    MaterielType = item.MaterielType,
                                    BatchNo = item.BatchNo,
                                    OrderQuantity = item.OrderQuantity,
                                    ReceiptQuantity = 0,
@@ -1592,6 +1575,7 @@
                        {
                            Dt_InboundOrderDetail orderDetail = new Dt_InboundOrderDetail()
                            {
                                MaterielType = item.MaterielType,
                                MaterielCode = item.MaterielCode,
                                BatchNo = item.BatchNo,
                                OrderQuantity = item.OrderQuantity,
@@ -1622,46 +1606,12 @@
                                System = model.System,
                                Details = new List<Dt_InboundOrderDetail> { orderDetail }
                            };
                            //switch (model.OrderType)//单据类型
                            //{
                            //    case 1:
                            //        inboundOrder.OrderType = InOrderTypeEnum.Allocat.ObjToInt();
                            //        break;
                            //    case 3:
                            //        inboundOrder.OrderType = InOrderTypeEnum.CustomerRecovery.ObjToInt();
                            //        break;
                            //    case 6:
                            //        inboundOrder.OrderType = InOrderTypeEnum.SaleReturn.ObjToInt();
                            //        break;
                            //    default:
                            //        break;
                            //};
                            Db.InsertNav(inboundOrder).Include(x => x.Details).ExecuteCommand();
                        }
                    }
                }
                _unitOfWorkManage.CommitTran();
                content = WebResponseContent.Instance.OK();
                //InboundOrderAddDTO orderAddDTO1 = new InboundOrderAddDTO();
                //orderAddDTO1.OrderNo = orderAddDTO.AsnNo;
                //orderAddDTO1.UpperOrderNo = orderAddDTO.AsnNo;
                //orderAddDTO1.OutWareHouse = orderAddDTO.InWarehouse;
                //orderAddDTO1.TransactionCode = orderAddDTO.TransactionCode;
                //orderAddDTO1.InoutType = orderAddDTO.OrderType;
                //orderAddDTO1.OrderType = orderAddDTO.InoutType.ObjToInt();
                //orderAddDTO1.Details = orderAddDTO.DetailList.DicToIEnumerable<InboundOrderDetailAddDTO>();
                //#region 验证数据
                //(bool, string, object?) result = CheckInboundOrderAddData(orderAddDTO1);
                //if (!result.Item1) return content = WebResponseContent.Instance.Error(result.Item2);
                //#endregion
                //Dt_InboundOrder inboundOrder = _mapper.Map<Dt_InboundOrder>(orderAddDTO1);
                //inboundOrder.OrderStatus = InboundStatusEnum.未开始.ObjToInt();
                //inboundOrder.Creater = "WMS";
                //inboundOrder.CreateDate = DateTime.Now;
                //bool a = BaseDal.Db.InsertNav(inboundOrder).Include(x => x.Details).ExecuteCommand();
            }
            catch (Exception ex)
            {
@@ -1777,6 +1727,7 @@
                    _inboundOrderDetailService.DeleteData(item);
                }
                BaseDal.DeleteData(oldOutboundOrder);
                WriteLog.Write_Log("API", "SMOM推送入库单据取消", "请求成功", new { 请求报文 = oldOutboundOrder, 接收报文 = content });
                content = WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
@@ -1801,11 +1752,11 @@
                List<Dt_InboundOrder> dt_ReceiveOrders = new List<Dt_InboundOrder>();
                if (string.IsNullOrEmpty(orderNo))
                {
                    dt_ReceiveOrders = Db.Queryable<Dt_InboundOrder>().Where(x => x.OrderStatus < InboundStatusEnum.入库完成.ObjToInt() && x.WarehouseId == warehouseId).Includes(x => x.Details).OrderByDescending(x => x.CreateDate).ToPageList(pageNo, 10);
                    dt_ReceiveOrders = Db.Queryable<Dt_InboundOrder>().Where(x => x.OrderStatus < InboundStatusEnum.入库完成.ObjToInt() && x.WarehouseId == warehouseId).Includes(x => x.Details).OrderByDescending(x => x.CreateDate).ToPageList(pageNo, 50);
                }
                else
                {
                    dt_ReceiveOrders = Db.Queryable<Dt_InboundOrder>().Where(x => (x.OrderNo.Contains(orderNo)) && x.OrderStatus < InboundStatusEnum.入库完成.ObjToInt() && x.WarehouseId == warehouseId).Includes(x => x.Details).OrderByDescending(x => x.CreateDate).ToPageList(pageNo, 10);
                    dt_ReceiveOrders = Db.Queryable<Dt_InboundOrder>().Where(x => (x.OrderNo.Contains(orderNo)) && x.OrderStatus < InboundStatusEnum.入库完成.ObjToInt() && x.WarehouseId == warehouseId).Includes(x => x.Details).OrderByDescending(x => x.CreateDate).ToPageList(pageNo, 50);
                }
                content.OK(data: dt_ReceiveOrders);
@@ -1869,7 +1820,10 @@
                };
                _unitOfWorkManage.BeginTran();
                Db.InsertNav(erpProScrapSheet).Include(x => x.Details).ExecuteCommand();
                WriteLog.Write_Log("API", "erp单据下发", "请求成功", new { 请求报文 = erpProScrapSheet, 接收报文 = WebResponseContent.Instance.OK() });
                _unitOfWorkManage.CommitTran();
                return WebResponseContent.Instance.OK();
            }
@@ -1976,119 +1930,119 @@
                _unitOfWorkManage.BeginTran();
                foreach (var item in houseReturnOrder)
                {
                        int randomNum = random.Next(1, 1000);
                        string datePart = DateTime.Now.ToString("yyyyMMdd");
                        Dt_ReturnOrder returnOrder = _returnOrderRepository.QueryFirst(x => x.LPNNo == item.LPNNo && x.OrderStatus == InOrderStatusEnum.未开始.ObjToInt());
                        if (returnOrder == null)
                    int randomNum = random.Next(1, 1000);
                    string datePart = DateTime.Now.ToString("yyyyMMdd");
                    Dt_ReturnOrder returnOrder = _returnOrderRepository.QueryFirst(x => x.LPNNo == item.LPNNo && x.OrderStatus == InOrderStatusEnum.未开始.ObjToInt());
                    if (returnOrder == null)
                    {
                        Dt_ReturnOrder newReturnOrder = new Dt_ReturnOrder
                        {
                            Dt_ReturnOrder newReturnOrder = new Dt_ReturnOrder
                            {
                                OrderType = OrderTypeEnum.反拣回库单.ObjToInt(),
                                MaterielCode = item.MaterielCode,
                                MaterielName = item.MaterielName,
                            OrderType = OrderTypeEnum.反拣回库单.ObjToInt(),
                            MaterielCode = item.MaterielCode,
                            MaterielName = item.MaterielName,
                            MaterieSpec = item.MaterieSpec,
                                BatchNo = item.BatchNo,
                                OrderQuantity = item.OrderQuantity,
                            BatchNo = item.BatchNo,
                            OrderQuantity = item.OrderQuantity,
                            Remark = item.Remark,
                                LinId = item.LinId,
                                LPNNo = item.LPNNo,
                            LinId = item.LinId,
                            LPNNo = item.LPNNo,
                            LocationCode = item.LocationCode,
                            WarehouseCode = item.WarehouseCode,
                            System = item.System,
                                OrderStatus = InOrderStatusEnum.未开始.ObjToInt(),
                                Creater = "SMOM",
                                CreateDate = DateTime.Now
                            };
                            _returnOrderRepository.AddData(newReturnOrder);
                            OrderStatus = InOrderStatusEnum.未开始.ObjToInt(),
                            Creater = "SMOM",
                            CreateDate = DateTime.Now
                        };
                        _returnOrderRepository.AddData(newReturnOrder);
                        Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo, Dt_StockInfoDetail>((stock, detail) => stock.Id == detail.StockId).Where((stock, detail) => stock.PalletCode == item.LPNNo && stock.LocationCode == item.LocationCode).First();
                                Dt_OutboundOrderDetail outboundOrderDetail = new Dt_OutboundOrderDetail();
                                Dt_OutboundOrder outboundOrder = new Dt_OutboundOrder();
                                if (stockInfo == null)
                                {
                        Dt_OutboundOrderDetail outboundOrderDetail = new Dt_OutboundOrderDetail();
                        Dt_OutboundOrder outboundOrder = new Dt_OutboundOrder();
                        if (stockInfo == null)
                        {
                            Dt_Warehouse warehouse = _warehouseService.Repository.QueryData(x => x.WarehouseCode == item.WarehouseCode).FirstOrDefault();
                                    if (warehouse == null)
                                    {
                            if (warehouse == null)
                            {
                                return WebResponseContent.Instance.Error($"该仓库编号{item.WarehouseCode}未配置");
                                    }
                                    Dt_StockInfoDetail stockInfoDetail = new Dt_StockInfoDetail
                                    {
                                        MaterielCode = item.MaterielCode,
                                        MaterielName = item.MaterielName,
                            }
                            Dt_StockInfoDetail stockInfoDetail = new Dt_StockInfoDetail
                            {
                                MaterielCode = item.MaterielCode,
                                MaterielName = item.MaterielName,
                                MaterieSpec = item.MaterieSpec,
                                        BatchNo = item.BatchNo,
                                        LinId = item.LinId,
                                        Status = StockStatusEmun.组盘暂存.ObjToInt(),
                                        Creater = "SMOM",
                                        CreateDate = DateTime.Now,
                                        OrderNo = newReturnOrder.OrderNo,
                                        StockQuantity = item.OrderQuantity,
                                    };
                                    Dt_StockInfo stockInfo1 = new Dt_StockInfo
                                    {
                                        PalletCode = item.LPNNo,
                                        WarehouseId = warehouse.WarehouseId,
                                        BatchNo = item.BatchNo,
                                        PalletType = GetPalletType(warehouse, item.LPNNo),
                                        IsFull = true,
                                        StockStatus = (int)StockStatusEmun.反拣入库,
                                        Creater = "WMS",
                                        CreateDate = DateTime.Now,
                                        MaterialType = (int)InventoryMaterialType.原材料,
                                        Materialweight = 0,
                                        Wlstatus = (int)InventoryMaterialStatus.合格,
                                        Mgeneratetime = DateTime.Now,
                                        Details = new List<Dt_StockInfoDetail> { stockInfoDetail }
                                    };
                                    Db.InsertNav(stockInfo1).Include(x => x.Details).ExecuteCommand();
                                }
                                else
                                {
                                    outboundOrderDetail = new Dt_OutboundOrderDetail
                                    {
                                        MaterielCode = item.MaterielCode,
                                        MaterielName = item.MaterielName,
                                MaterieSpec = item.MaterieSpec,
                                        BatchNo = item.BatchNo,
                                        OrderQuantity = stockInfo.Details.Sum(x => x.StockQuantity),
                                Remark = item.Remark,
                                        LinId = item.LinId,
                                        LPNNo = item.LPNNo,
                                        Creater = "SMOM",
                                        CreateDate = DateTime.Now,
                                LocationName = item.LocationCode
                                    };
                                    outboundOrder = new Dt_OutboundOrder
                                    {
                                        OrderNo = "FJCK" + $"{datePart}{randomNum}",
                                        UpperOrderNo = "WMSFJCK" + $"{datePart}{randomNum}",
                                        OrderStatus = OutOrderStatusEnum.未开始.ObjToInt(),
                                        OrderType = OrderTypeEnum.反拣出库单.ObjToInt(),
                                        InoutType = InoutTypeEnum.OtherOut.ToString(),
                                System = item.System,
                                        Creater = "SMOM",
                                        CreateDate = DateTime.Now,
                                        CreateType = OrderCreateTypeEnum.UpperSystemPush.ObjToInt(),
                                        Details = new List<Dt_OutboundOrderDetail> { outboundOrderDetail }
                                    };
                                    Db.InsertNav(outboundOrder).Include(x => x.Details).ExecuteCommand();
                                }
                                BatchNo = item.BatchNo,
                                LinId = item.LinId,
                                Status = StockStatusEmun.组盘暂存.ObjToInt(),
                                Creater = "SMOM",
                                CreateDate = DateTime.Now,
                                OrderNo = newReturnOrder.OrderNo,
                                StockQuantity = item.OrderQuantity,
                            };
                            Dt_StockInfo stockInfo1 = new Dt_StockInfo
                            {
                                PalletCode = item.LPNNo,
                                WarehouseId = warehouse.WarehouseId,
                                BatchNo = item.BatchNo,
                                PalletType = GetPalletType(warehouse, item.LPNNo),
                                IsFull = true,
                                StockStatus = (int)StockStatusEmun.反拣入库,
                                Creater = "WMS",
                                CreateDate = DateTime.Now,
                                MaterialType = (int)InventoryMaterialType.原材料,
                                Materialweight = 0,
                                Wlstatus = (int)InventoryMaterialStatus.合格,
                                Mgeneratetime = DateTime.Now,
                                Details = new List<Dt_StockInfoDetail> { stockInfoDetail }
                            };
                            Db.InsertNav(stockInfo1).Include(x => x.Details).ExecuteCommand();
                        }
                        else
                        {
                            Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo, Dt_StockInfoDetail>((stock, detail) => stock.Id == detail.StockId).Where((stock, detail) => stock.PalletCode == item.LPNNo && stock.StockStatus == StockStatusEmun.余料退库.ObjToInt()).First();
                            stockInfo.StockStatus = StockStatusEmun.反拣入库.ObjToInt();
                            returnOrder.LinId = item.LinId;
                            outboundOrderDetail = new Dt_OutboundOrderDetail
                            {
                                MaterielCode = item.MaterielCode,
                                MaterielName = item.MaterielName,
                                MaterieSpec = item.MaterieSpec,
                                BatchNo = item.BatchNo,
                                OrderQuantity = stockInfo.Details.Sum(x => x.StockQuantity),
                                Remark = item.Remark,
                                LinId = item.LinId,
                                LPNNo = item.LPNNo,
                                Creater = "SMOM",
                                CreateDate = DateTime.Now,
                                LocationName = item.LocationCode
                            };
                            outboundOrder = new Dt_OutboundOrder
                            {
                                OrderNo = "FJCK" + $"{datePart}{randomNum}",
                                UpperOrderNo = "WMSFJCK" + $"{datePart}{randomNum}",
                                OrderStatus = OutOrderStatusEnum.未开始.ObjToInt(),
                                OrderType = OrderTypeEnum.反拣出库单.ObjToInt(),
                                InoutType = InoutTypeEnum.OtherOut.ToString(),
                                System = item.System,
                                Creater = "SMOM",
                                CreateDate = DateTime.Now,
                                CreateType = OrderCreateTypeEnum.UpperSystemPush.ObjToInt(),
                                Details = new List<Dt_OutboundOrderDetail> { outboundOrderDetail }
                            };
                            Db.InsertNav(outboundOrder).Include(x => x.Details).ExecuteCommand();
                        }
                    }
                    else
                    {
                        Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo, Dt_StockInfoDetail>((stock, detail) => stock.Id == detail.StockId).Where((stock, detail) => stock.PalletCode == item.LPNNo && stock.StockStatus == StockStatusEmun.余料退库.ObjToInt()).First();
                        stockInfo.StockStatus = StockStatusEmun.反拣入库.ObjToInt();
                        returnOrder.LinId = item.LinId;
                        returnOrder.System = item.System;
                        returnOrder.WarehouseCode = item.WarehouseCode;
                        returnOrder.LocationCode = item.LocationCode;
                            returnOrder.OrderType = OrderTypeEnum.反拣回库单.ObjToInt();
                            returnOrder.OrderQuantity += item.OrderQuantity;
                            returnOrder.ReceiptQuantity += item.OrderQuantity;
                            _returnOrderRepository.UpdateData(returnOrder);
                            _stockRepository.StockInfoRepository.UpdateData(stockInfo);
                        returnOrder.OrderType = OrderTypeEnum.反拣回库单.ObjToInt();
                        returnOrder.OrderQuantity += item.OrderQuantity;
                        returnOrder.ReceiptQuantity += item.OrderQuantity;
                        _returnOrderRepository.UpdateData(returnOrder);
                        _stockRepository.StockInfoRepository.UpdateData(stockInfo);
                        }
                    }
                }
                _unitOfWorkManage.CommitTran();
                return WebResponseContent.Instance.OK();