wangxinhui
2025-05-26 ef3870bb8d578457b310e58518ca814f3d4f932c
´úÂë¹ÜÀí/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/ProOutOrderService.cs
@@ -53,7 +53,7 @@
            _invokeERPService = invokeERPService;
        }
        /// <summary>
        /// æŽ¥æ”¶ERP成品出库单
        /// æŽ¥æ”¶ERP成品出库单信息(订单出库/寄售出库)
        /// </summary>
        /// <returns></returns>
        public async Task<WebResponseContent> ProductDeliveryOrder(ErpProOutOrderDTO outOrderDTO)
@@ -201,6 +201,69 @@
            return content;
        }
        /// <summary>
        /// é”€å”®æŒ‡æ´¾
        /// </summary>
        /// <returns></returns>
        public async Task<WebResponseContent> ProductSpecifyVer(ErpProductSpecifyVerDTO erpProductSpecifyVerDTO)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x=>x.WarehouseCode==erpProductSpecifyVerDTO.WaType);
                if (warehouse == null)
                    return await Task.FromResult(content.Error($"未找到{erpProductSpecifyVerDTO.WaType}仓库信息"));
                //查询可指派库存
                List<Dt_ProStockInfo> proStockInfos = Db.Queryable<Dt_ProStockInfo>().Where(x => x.ProStockAttribute == ProStockAttributeEnum.成品.ObjToInt())
                .Includes(x => x.proStockInfoDetails)
                .Where(x => x.proStockInfoDetails
                .Any(v =>
                     v.SaleOrder == erpProductSpecifyVerDTO.OrderNo
                    && v.ProductCode == erpProductSpecifyVerDTO.PCode
                    && v.ProductVersion == erpProductSpecifyVerDTO.PVer
                    && v.LotNumber == erpProductSpecifyVerDTO.PLot
                    && v.DateCode == erpProductSpecifyVerDTO.DateCode
                    && (v.SpecifyVer==null||v.SpecifyVer=="")
                ))
                .ToList();
                List<Dt_ProStockInfoDetail> proStockInfoDetails = new List<Dt_ProStockInfoDetail>();
                List<Dt_ProStockInfoDetail> specifyVerDetails = new List<Dt_ProStockInfoDetail>();
                if (proStockInfos==null)
                    return await Task.FromResult(content.Error("可指派库存不存在"));
                proStockInfos = proStockInfos.OrderBy(x => x.proStockInfoDetails.FirstOrDefault()?.DateCode).ThenBy(x => x.CreateDate).ThenBy(x => x.proStockInfoDetails.Sum(x => x.StockPcsQty)).ToList();
                foreach (var item in proStockInfos)
                {
                    proStockInfoDetails.AddRange(item.proStockInfoDetails);
                }
                if (proStockInfoDetails.Sum(x=>x.StockPcsQty)< erpProductSpecifyVerDTO.QtyPcs)
                    return await Task.FromResult(content.Error($"可指派库存数量不足,可用:{proStockInfoDetails.Sum(x => x.StockPcsQty)}"));
                float overQty = 0;
                foreach (var item in proStockInfoDetails)
                {
                    specifyVerDetails.Add(item);
                    overQty += item.StockPcsQty;
                    //已满足获取数量不再更改
                    if (overQty>= erpProductSpecifyVerDTO.QtyPcs)
                    {
                        break;
                    }
                }
                specifyVerDetails.ForEach(x =>
                {
                    x.SpecifyVer = erpProductSpecifyVerDTO.Ver;
                });
                _unitOfWorkManage.BeginTran();
                _stockRepository.ProStockInfoDetailRepository.UpdateData(specifyVerDetails);
                _unitOfWorkManage.CommitTran();
                content.OK("指派成功");
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                content.Error(ex.Message);
            }
            return await Task.FromResult(content);
        }
        /// <summary>
        /// æˆå“å‡ºå¾…发货区(平库)+同步ERP出库(绑定了出库单库存)
        /// </summary>
        /// <returns></returns>