wangxinhui
2025-04-08 dcecb039035f4b2e82e31c39b74db9402444c536
´úÂë¹ÜÀí/WMS/WIDESEA_WMSServer/WIDESEA_StockRepository/ProStockInfoRepository.cs
@@ -4,9 +4,11 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common.CommonEnum;
using WIDESEA_Common.StockEnum;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.Helper;
using WIDESEA_IBasicRepository;
using WIDESEA_IStockRepository;
using WIDESEA_Model.Models;
@@ -14,8 +16,10 @@
{
    public class ProStockInfoRepository : RepositoryBase<Dt_ProStockInfo>, IProStockInfoRepository
    {
        public ProStockInfoRepository(IUnitOfWorkManage unitOfWorkManage) : base(unitOfWorkManage)
        private readonly IBasicRepository _basicRepository;
        public ProStockInfoRepository(IUnitOfWorkManage unitOfWorkManage,IBasicRepository basicRepository) : base(unitOfWorkManage)
        {
            _basicRepository = basicRepository;
        }
        //根据明细数据查找可用库存库存
        public List<Dt_ProStockInfo> GetProStocks(Dt_ProOutOrderDetail proOutOrderDetail,List<string> locationInfos)
@@ -24,18 +28,40 @@
            bool isCanLot= string.IsNullOrEmpty(proOutOrderDetail.PLot);
            bool isCanDate = string.IsNullOrEmpty(proOutOrderDetail.DateCode);
            bool isCanVer = string.IsNullOrEmpty(proOutOrderDetail.OutSpecifyVer);
            proStockInfos = Db.Queryable<Dt_ProStockInfo>().Where(x => locationInfos.Contains(x.LocationCode) && x.ProStockAttribute == ProStockAttributeEnum.成品.ObjToInt())
            ////判断客户出入规则
            //Dt_CustomerInfo customerInfo = _basicRepository.CustomerInfoRepository.QueryFirst(x=>x.Code== proOutOrderDetail.Customer);
            //if (customerInfo==null)
            //{
            //    throw new Exception("未找到客户信息");
            //}
            //if (customerInfo.OutRule==CustomerOutRuleEnum.SaleOrderRule.ObjToInt())
            //{
            //    proStockInfos = Db.Queryable<Dt_ProStockInfo>().Where(x => locationInfos.Contains(x.LocationCode) && x.ProStockAttribute == ProStockAttributeEnum.成品.ObjToInt())
            //    .Includes(x => x.proStockInfoDetails)
            //    .Where(x => x.proStockInfoDetails
            //    .Any(v =>
            //        v.SaleOrder==proOutOrderDetail.SaleOrder
            //        && v.ProductCode == proOutOrderDetail.PCode
            //        && v.ProductVersion == proOutOrderDetail.PVer
            //        && (isCanLot ? isCanLot : v.BagNo == proOutOrderDetail.PLot)
            //        && (isCanDate ? isCanDate : v.DateCode == proOutOrderDetail.DateCode)
            //    ))
            //    .ToList();
            //}
            //else
            //{
                proStockInfos = Db.Queryable<Dt_ProStockInfo>().Where(x => locationInfos.Contains(x.LocationCode) && x.ProStockAttribute == ProStockAttributeEnum.成品.ObjToInt())
                .Includes(x => x.proStockInfoDetails)
                .Where(x => x.proStockInfoDetails
                .Any(v => v.SaleOrder == proOutOrderDetail.SaleOrder
                && v.ProductCode == proOutOrderDetail.PCode
                && v.ProductVersion == proOutOrderDetail.PVer
                && (isCanLot ? isCanLot : v.LotNumber == proOutOrderDetail.PLot)
                && (isCanDate ? isCanDate : v.DateCode == proOutOrderDetail.DateCode)
                .Any(v =>
                    v.ProductCode == proOutOrderDetail.PCode
                    && v.ProductVersion == proOutOrderDetail.PVer
                    && (isCanLot ? isCanLot : v.BagNo == proOutOrderDetail.PLot)
                    && (isCanDate ? isCanDate : v.DateCode == proOutOrderDetail.DateCode)
                ))
            .ToList();
            proStockInfos = proStockInfos.OrderBy(x => x.proStockInfoDetails.FirstOrDefault()?.DateCode).ThenBy(x=>x.proStockInfoDetails.Sum(x=>x.StockPcsQty)).ToList();
                .ToList();
            //}
            proStockInfos = proStockInfos?.OrderBy(x => x.proStockInfoDetails.FirstOrDefault()?.DateCode).ThenBy(x=>x.CreateDate).ThenBy(x=>x.proStockInfoDetails.Sum(x=>x.StockPcsQty)).ToList();
            return proStockInfos;
        }
        /// <summary>