1
yangpeixing
2026-03-02 c0e49798942411b5dc57169d50f707c0bb247d25
WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Outbound.cs
@@ -154,13 +154,14 @@
            {
                Dt_OutboundOrder dt_OutboundOrder = _outboundService.OutboundOrderService.Repository.QueryData(x => x.Id == outboundOrderDetails.First().OrderId).First();
                (List<Dt_StockInfo>, List<Dt_OutboundOrderDetail>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) result = new();
                if (dt_OutboundOrder.OutWareHouse.Contains("DW") || dt_OutboundOrder.OutWareHouse.Contains("YS"))
                if (dt_OutboundOrder.OutWareHouse.Contains("BC"))
                {
                   result = _outboundService.OutboundOrderDetailService.DWANDYSAssignStockOutbound(outboundOrderDetails);
                    result = _outboundService.OutboundOrderDetailService.AssignStockOutbound(outboundOrderDetails);
                }
                else
                {
                   result = _outboundService.OutboundOrderDetailService.AssignStockOutbound(outboundOrderDetails);
                    result = _outboundService.OutboundOrderDetailService.DWANDYSAssignStockOutbound(outboundOrderDetails);
                }
                if (result.Item1 != null && result.Item1.Count > 0)
                {
@@ -177,10 +178,26 @@
                    {
                        x.OrderNo = outboundOrder.OrderNo;
                    });
                    result.Item2.ForEach(x =>
                    if (dt_OutboundOrder.OutWareHouse.Contains("BC"))
                    {
                        x.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt();
                    });
                        result.Item2.ForEach(x =>
                        {
                            x.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt();
                        });
                    }
                    else
                    {
                        result.Item2.ForEach(x =>
                        {
                            if (x.LockQuantity == x.OrderQuantity)
                            {
                                x.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt();
                            }
                        });
                    }
                    result.Item3.ForEach(x =>
                    {
@@ -280,7 +297,7 @@
        /// <summary>
        /// 立库出库指令上传,出库任务下发
        /// 出库单据下发
        /// </summary>
        /// <param name="orderAddDTO"></param>
        /// <returns></returns>
@@ -297,181 +314,100 @@
                }
                if (warehouse.WarehouseCode.Contains("CP"))
                {
                    Dt_NewOutboundOrder newOutboundOrder = BaseDal.Db.Queryable<Dt_NewOutboundOrder>().Where(x => x.UpperOrderNo == orderAddDTO.No).Includes(x => x.Details).First();
                    Dt_Production production1 = new Dt_Production();
                    if (newOutboundOrder != null)
                    OutboundOrderAddDTO orderAddDTO1 = new OutboundOrderAddDTO();
                    orderAddDTO1.OrderNo = orderAddDTO.No;
                    orderAddDTO1.UpperOrderNo = orderAddDTO.No;
                    orderAddDTO1.OutWareHouse = orderAddDTO.OutWareHouse;
                    orderAddDTO1.TransactionCode = orderAddDTO.TransactionCode ?? "工单发料";
                    orderAddDTO1.InoutType = orderAddDTO.OrderType ?? InoutTypeEnum.WorkFeed.ToString();
                    orderAddDTO1.OrderType = orderAddDTO.InoutType;
                    orderAddDTO1.System = orderAddDTO.System;
                    IEnumerable<int> inOrderTypes = Enum.GetValues<OrderTypeEmun>().Cast<int>();
                    orderAddDTO1.Details = orderAddDTO.DetailList.DicToIEnumerable<OutboundOrderDetailAddDTO>();
                    #region 验证数据
                    (bool, string, object?) result = CheckOutboundOrderAddData(orderAddDTO1);
                    if (!result.Item1) return content = WebResponseContent.Instance.Error(result.Item2);
                    #endregion
                    Dt_NewOutboundOrder inboundOrder = _mapper.Map<Dt_NewOutboundOrder>(orderAddDTO1);
                    inboundOrder.OrderStatus = InboundStatusEnum.未开始.ObjToInt();
                    inboundOrder.Creater = "WMS";
                    inboundOrder.CreateDate = DateTime.Now;
                    inboundOrder.CreateType = CreateType.UpperSystemPush.ObjToInt();
                    _unitOfWorkManage.BeginTran();
                    Dt_NewOutboundOrder dt_NewOutboundOrder = BaseDal.Db.Queryable<Dt_NewOutboundOrder>().Where(x => x.OrderNo == inboundOrder.OrderNo).Includes(x => x.Details).First();
                    if(dt_NewOutboundOrder != null)
                    {
                        if (newOutboundOrder.OutWareHouse != warehouse.WarehouseCode)
                        if (dt_NewOutboundOrder.OrderStatus > 0)
                        {
                            return WebResponseContent.Instance.Error($"仓库不一致");
                            return WebResponseContent.Instance.Error($"该出库单在进行中,无法更新该出库单");
                        }
                        else
                        {
                            OutboundOrderAddDTO orderAddDTO1 = new OutboundOrderAddDTO();
                            orderAddDTO1.Details = orderAddDTO.DetailList.DicToIEnumerable<OutboundOrderDetailAddDTO>();
                            var details = orderAddDTO1.Details.FirstOrDefault();
                            Dt_NewOutboundOrderDetail outboundOrderDetail = new Dt_NewOutboundOrderDetail()
                            {
                                LPNNo = details.LPNNo,
                                BatchNo = details.BatchNo,
                                MaterielCode = details.MaterielCode,
                                MaterielName = details.MaterielName,
                                MaterieSpec = details.MaterieSpec,
                                OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(),
                                OrderQuantity = details.OrderQuantity,
                                LinId = details.LinId,
                                OrderId = newOutboundOrder.Id,
                                Creater = "WMS",
                                CreateDate = DateTime.Now,
                                Remark = details.Remark,
                                SupplierBatch = details.SupplierBatch,
                                OrinalLocation = details.OrinalLocation,
                            };
                            _newOutboundOrderDetailRepository.AddData(outboundOrderDetail);
                            foreach (var item in orderAddDTO1.Details)
                            {
                                if (string.IsNullOrWhiteSpace(item.Remark))
                                {
                                    continue;
                                }
                                string[] remarkEntries = item.Remark.Split(
                                    new[] { ';' },
                                    StringSplitOptions.RemoveEmptyEntries
                                );
                                foreach (var entry in remarkEntries)
                                {
                                    string[] keyValuePairs = entry.Split(
                                        new[] { ',' },
                                        StringSplitOptions.RemoveEmptyEntries
                                    );
                                    foreach (var kvp in keyValuePairs)
                                    {
                                        int colonIndex = kvp.IndexOf(':');
                                        if (colonIndex <= 0 || colonIndex >= kvp.Length - 1)
                                        {
                                            continue;
                                        }
                                        string key = kvp.Substring(0, colonIndex).Trim();
                                        string value = kvp.Substring(colonIndex + 1).Trim();
                                        switch (key)
                                        {
                                            case "制造单号":
                                                production1.ProductionNo = value;
                                                break;
                                            case "制造部件":
                                                production1.ManufacturingCo = value;
                                                break;
                                            case "出库数量":
                                                if (decimal.TryParse(value, out decimal outQuantity))
                                                {
                                                    production1.OutQuantity = outQuantity;
                                                }
                                                else
                                                {
                                                    Console.WriteLine($"出库数量格式错误:{value}(应为数值,如14.0000)");
                                                }
                                                break;
                                            default:
                                                Console.WriteLine($"未知键名:{key}(对应值:{value},跳过该键值对)");
                                                break;
                                        }
                                    }
                                    production1.Creater = "WMS";
                                    production1.OrderId = outboundOrderDetail.Id;
                                    _productionRepository.AddData(production1);
                                }
                            }
                        }
                        Db.DeleteNav(dt_NewOutboundOrder).Include(x => x.Details).ExecuteCommand();
                    }
                    else
                    {
                        OutboundOrderAddDTO orderAddDTO1 = new OutboundOrderAddDTO();
                        orderAddDTO1.OrderNo = orderAddDTO.No;
                        orderAddDTO1.UpperOrderNo = orderAddDTO.No;
                        orderAddDTO1.OutWareHouse = orderAddDTO.OutWareHouse;
                        orderAddDTO1.TransactionCode = orderAddDTO.TransactionCode ?? "工单发料";
                        orderAddDTO1.InoutType = orderAddDTO.OrderType ?? InoutTypeEnum.WorkFeed.ToString();
                        orderAddDTO1.OrderType = orderAddDTO.InoutType;
                        orderAddDTO1.System = orderAddDTO.System;
                        IEnumerable<int> inOrderTypes = Enum.GetValues<OrderTypeEmun>().Cast<int>();
                        orderAddDTO1.Details = orderAddDTO.DetailList.DicToIEnumerable<OutboundOrderDetailAddDTO>();
                        #region 验证数据
                        (bool, string, object?) result = CheckOutboundOrderAddData(orderAddDTO1);
                        if (!result.Item1) return content = WebResponseContent.Instance.Error(result.Item2);
                        #endregion
                        Dt_NewOutboundOrder inboundOrder = _mapper.Map<Dt_NewOutboundOrder>(orderAddDTO1);
                        inboundOrder.OrderStatus = InboundStatusEnum.未开始.ObjToInt();
                        inboundOrder.Creater = "WMS";
                        inboundOrder.CreateDate = DateTime.Now;
                        inboundOrder.CreateType = CreateType.UpperSystemPush.ObjToInt();
                        _unitOfWorkManage.BeginTran();
                        bool a = BaseDal.Db.InsertNav(inboundOrder).Include(x => x.Details).ExecuteCommand();
                    bool a = BaseDal.Db.InsertNav(inboundOrder).Include(x => x.Details).ExecuteCommand();
                        foreach (var item in orderAddDTO1.Details)
                    foreach (var item in orderAddDTO1.Details)
                    {
                        if (string.IsNullOrWhiteSpace(item.Remark))
                        {
                            if (string.IsNullOrWhiteSpace(item.Remark))
                            {
                                continue;
                            }
                            string[] remarkEntries = item.Remark.Split(
                                new[] { ';' },
                            continue;
                        }
                        string[] remarkEntries = item.Remark.Split(
                            new[] { ';' },
                            StringSplitOptions.RemoveEmptyEntries
                        );
                        foreach (var entry in remarkEntries)
                        {
                            string[] keyValuePairs = entry.Split(
                                new[] { ',' },
                                StringSplitOptions.RemoveEmptyEntries
                            );
                            foreach (var entry in remarkEntries)
                            foreach (var kvp in keyValuePairs)
                            {
                                string[] keyValuePairs = entry.Split(
                                    new[] { ',' },
                                    StringSplitOptions.RemoveEmptyEntries
                                );
                                foreach (var kvp in keyValuePairs)
                                int colonIndex = kvp.IndexOf(':');
                                if (colonIndex <= 0 || colonIndex >= kvp.Length - 1)
                                {
                                    int colonIndex = kvp.IndexOf(':');
                                    if (colonIndex <= 0 || colonIndex >= kvp.Length - 1)
                                    {
                                        continue;
                                    }
                                    string key = kvp.Substring(0, colonIndex).Trim();
                                    string value = kvp.Substring(colonIndex + 1).Trim();
                                    switch (key)
                                    {
                                        case "制造单号":
                                            production1.ProductionNo = value;
                                            break;
                                        case "制造部件":
                                            production1.ManufacturingCo = value;
                                            break;
                                        case "出库数量":
                                            if (decimal.TryParse(value, out decimal outQuantity))
                                            {
                                                production1.OutQuantity = outQuantity;
                                            }
                                            else
                                            {
                                                Console.WriteLine($"出库数量格式错误:{value}(应为数值,如14.0000)");
                                            }
                                            break;
                                        default:
                                            Console.WriteLine($"未知键名:{key}(对应值:{value},跳过该键值对)");
                                            break;
                                    }
                                    continue;
                                }
                                production1.Creater = "WMS";
                                production1.OrderId = inboundOrder.Details.FirstOrDefault().Id;
                                _productionRepository.AddData(production1);
                                string key = kvp.Substring(0, colonIndex).Trim();
                                string value = kvp.Substring(colonIndex + 1).Trim();
                                switch (key)
                                {
                                    case "制造单号":
                                        production1.ProductionNo = value;
                                        break;
                                    case "制造部件":
                                        production1.ManufacturingCo = value;
                                        break;
                                    case "出库数量":
                                        if (decimal.TryParse(value, out decimal outQuantity))
                                        {
                                            production1.OutQuantity = outQuantity;
                                        }
                                        else
                                        {
                                            Console.WriteLine($"出库数量格式错误:{value}(应为数值,如14.0000)");
                                        }
                                        break;
                                    default:
                                        Console.WriteLine($"未知键名:{key}(对应值:{value},跳过该键值对)");
                                        break;
                                }
                            }
                            production1.Creater = "WMS";
                            production1.OrderId = inboundOrder.Details.FirstOrDefault().Id;
                            _productionRepository.AddData(production1);
                        }
                        _unitOfWorkManage.CommitTran();
                    }
                    _unitOfWorkManage.CommitTran();
                }
                else
                {
@@ -494,6 +430,7 @@
                                BatchNo = details.BatchNo,
                                MaterielCode = details.MaterielCode,
                                MaterielName = details.MaterielName,
                                MaterielType = details.MaterielType,
                                MaterieSpec = details.MaterieSpec,
                                OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(),
                                OrderQuantity = details.OrderQuantity,
@@ -761,7 +698,7 @@
            }
        }
        /// <summary>
        /// 生成出库任务
        /// 生成‘任务
        /// </summary>
        /// <param name="orderDetailId"></param>
        /// <param name="stockSelectViews"></param>
@@ -1017,7 +954,7 @@
                foreach (int key in keys)
                {
                   (List<Dt_Task>, List<Dt_StockInfo>?, List<Dt_OutboundOrderDetail>?, List<Dt_OutStockLockInfo>?, List<Dt_LocationInfo>?) result = OutboundTaskDataHandle(keys);
                    (List<Dt_Task>, List<Dt_StockInfo>?, List<Dt_OutboundOrderDetail>?, List<Dt_OutStockLockInfo>?, List<Dt_LocationInfo>?) result = OutboundTaskDataHandle(keys);
                    if (result.Item2 != null && result.Item2.Count > 0)
                    {
                        stockInfos.AddRange(result.Item2);
@@ -1028,24 +965,27 @@
                    }
                    if (result.Item4 != null && result.Item4.Count > 0)
                    {
                        outStockLockInfos.AddRange(result.Item4);
                        outStockLockInfos.AddRange(result.Item4);
                    }
                    if (result.Item5 != null && result.Item5.Count > 0)
                    {
                        if (locationInfos.First().RoadwayNo.Contains("DW") || locationInfos.First().RoadwayNo.Contains("YS"))
                        if (result.Item5.Any(x => x.RoadwayNo.Contains("DW")) || result.Item5.Any(x => x.RoadwayNo.Contains("YS")))
                        {
                            locationInfos.AddRange(result.Item5.Distinct());
                            locationInfos.AddRange(result.Item5.DistinctBy(x => x.LocationCode));
                        }
                        else
                        {
                            locationInfos.AddRange(result.Item5);
                        }
                    }
                    if (result.Item1 != null && result.Item1.Count > 0)
                    {
                        tasks.AddRange(result.Item1);
                    }
                    if(locationInfos.First().RoadwayNo.Contains("DW") || locationInfos.First().RoadwayNo.Contains("YS"))
                    if (locationInfos.First().RoadwayNo.Contains("DW") || locationInfos.First().RoadwayNo.Contains("YS"))
                    {
                        break;
                    }
@@ -1176,10 +1116,6 @@
                    {
                        return content.Error($"未找到{item.PalletCode}库存明细数据");
                    }
                    if (item.System.Contains("SMOM"))
                    {
                        return content.Error($"SMOM系统库存数据不可手动盘点,托盘号{item.PalletCode}");
                    }
                    Dt_LocationInfo? locationInfo = locationInfos.FirstOrDefault(x => x.LocationCode == item.LocationCode);
                    if (locationInfo != null && (locationInfo.EnableStatus == EnableStatusEnum.OnlyOut.ObjToInt() || locationInfo.EnableStatus == EnableStatusEnum.Normal.ObjToInt()) && locationInfo.LocationStatus == LocationStatusEnum.InStock.ObjToInt() && item.StockStatus == StockStatusEmun.入库完成.ObjToInt())
                    {
@@ -1225,7 +1161,15 @@
                BaseDal.AddData(tasks);
                _basicService.LocationInfoService.Repository.UpdateLocationStatus(locationInfos, locationStatus);
                _unitOfWorkManage.CommitTran();
                PushTasksToWCS(tasks);
                if (tasks.FirstOrDefault().PalletCode.Contains("BC"))
                {
                    PushTasksToWCS(tasks);
                }
                else
                {
                    PushTasksWCS(tasks);
                }
                content.OK();
            }
            catch (Exception ex)