dengjunjie
2025-02-24 733e63cb362f17aea4a1020654fa348a0d0c1f06
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA_StockService/Service/StockInfoService.cs
@@ -43,21 +43,18 @@
            try
            {
                var materielCode = productionlineDTO.traytype.ToString();
                if (inboundOrder != null)
                {
                    var inboundOrderDetail = inboundOrder.Details.FirstOrDefault(x => x.BatchNo == productionlineDTO.batchNo);
                    materielCode = inboundOrderDetail.MaterielCode;
                    inboundOrderDetail.ReceiptQuantity++;
                    inboundOrderDetail.OrderDetailStatus = inboundOrderDetail.OverInQuantity == inboundOrderDetail.OrderQuantity ? OrderDetailStatusEnum.Over.ObjToInt() : OrderDetailStatusEnum.GroupAndInbound.ObjToInt();
                var inboundOrderDetail = inboundOrder.Details.FirstOrDefault(x => x.BatchNo == productionlineDTO.batchNo);
                materielCode = inboundOrderDetail.MaterielCode;
                inboundOrderDetail.ReceiptQuantity++;
                inboundOrderDetail.OrderDetailStatus = inboundOrderDetail.OverInQuantity == inboundOrderDetail.OrderQuantity ? OrderDetailStatusEnum.Over.ObjToInt() : OrderDetailStatusEnum.GroupAndInbound.ObjToInt();
                    if (inboundOrder.Details.FirstOrDefault(x => x.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt()) == null)
                    {
                        inboundOrder.OrderStatus = InboundStatusEnum.入库完成.ObjToInt();
                    }
                    else if (inboundOrder.OrderStatus == InboundStatusEnum.未开始.ObjToInt())
                    {
                        inboundOrder.OrderStatus = InboundStatusEnum.入库中.ObjToInt();
                    }
                if (inboundOrder.Details.FirstOrDefault(x => x.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt()) == null)
                {
                    inboundOrder.OrderStatus = InboundStatusEnum.入库完成.ObjToInt();
                }
                else if (inboundOrder.OrderStatus == InboundStatusEnum.未开始.ObjToInt())
                {
                    inboundOrder.OrderStatus = InboundStatusEnum.入库中.ObjToInt();
                }
                var materielInfo = _basicRepository.MaterielInfoRepository.QueryFirst(x => x.MaterielCode == materielCode);
                if (materielInfo == null) throw new Exception($"未找到物料信息,物料编码【{materielCode}】");
@@ -68,7 +65,7 @@
                    StockId = stockInfo.Id != 0 ? stockInfo.Id : 0,
                    MaterielName = materielInfo.MaterielName,
                    MaterielCode = materielInfo.MaterielCode,
                    BatchNo = inboundOrder.Details.FirstOrDefault().BatchNo,
                    BatchNo = inboundOrderDetail.BatchNo,
                    StockQuantity = 1,// productionlineDTO.QtySum,
                    SerialNumber = "",
                    //SerialNumber = $"{inboundOrder.OrderNo} | {materielInfo.MaterielCode} | {pdaMaterielGroupDTO.BatchNo} | {pdaMaterielGroupDTO.ReceiptQuantity}",
@@ -165,67 +162,34 @@
        /// <returns></returns>
        public List<StockSelectViewDTO> GetStockSelectViews(string materielCode)
        {
            List<string> roadways = _basicRepository.RoadwayInfoRepository.CanOutRoadwayNos;
            List<int> warehouseIds = _basicRepository.WarehouseRepository.EnableWarehouseIds;
            List<int> areaIds = _basicRepository.AreaInfoRepository.GetEnableAreaIds(warehouseIds);
            List<string> locationCodes = _basicRepository.LocationInfoRepository.GetCanOutLocationCodes(roadways, areaIds);
            #region æŒ‰ç‰©æ–™æ•°é‡æŸ¥è¯¢
            //var StockSelectViewDTOs = BaseDal.QueryTabs<Dt_StockInfo, Dt_StockInfoDetail, StockSelectViewDTO>((a, b) => a.Id == b.StockId, (a, b) => new StockSelectViewDTO
            //{
            //    LocationCode = a.LocationCode,
            //    MaterielCode = b.MaterielCode,
            //    MaterielName = b.MaterielName,
            //    PalletCode = a.PalletCode,
            //    UseableQuantity = b.StockQuantity - b.OutboundQuantity
            //}, a => locationCodes.Contains(a.LocationCode), b => b.StockQuantity > b.OutboundQuantity && b.Status == StockStatusEmun.已入库.ObjToInt() && b.MaterielCode == materielCode, x => true).GroupBy(x => x.PalletCode).Select(x => new StockSelectViewDTO
            //{
            //    LocationCode = x.FirstOrDefault()?.LocationCode ?? "",
            //    MaterielCode = x.FirstOrDefault()?.MaterielCode ?? "",
            //    MaterielName = x.FirstOrDefault()?.MaterielName ?? "",
            //    PalletCode = x.Key,
            //    UseableQuantity = x.Sum(x => x.UseableQuantity)
            //}).ToList();
            #endregion
            #region æŒ‰æ‰¹å·å’Œæ‰˜ç›˜æ•°é‡æŸ¥è¯¢
            //StockSelectViewDTOs = BaseDal.QueryTabs<Dt_StockInfo, Dt_StockInfoDetail, StockSelectViewDTO>((a, b) => a.Id == b.StockId, (a, b) => new StockSelectViewDTO
            //{
            //    LocationCode = a.LocationCode,
            //    MaterielCode = b.MaterielCode,
            //    MaterielName = b.MaterielName,
            //    PalletCode = a.PalletCode,
            //    BatchNo = b.BatchNo,
            //    UseableQuantity = 1
            //}, a => locationCodes.Contains(a.LocationCode), b => b.StockQuantity > b.OutboundQuantity && b.Status == StockStatusEmun.已入库.ObjToInt() && b.MaterielCode == materielCode, x => true).GroupBy(x => x.PalletCode).Select(x => new StockSelectViewDTO
            //{
            //    LocationCode = x.FirstOrDefault()?.LocationCode ?? "",
            //    MaterielCode = x.FirstOrDefault()?.MaterielCode ?? "",
            //    MaterielName = x.FirstOrDefault()?.MaterielName ?? "",
            //    BatchNo = x.FirstOrDefault()?.BatchNo ?? "",
            //    PalletCode = x.Key,
            //    UseableQuantity = x.Sum(x => x.UseableQuantity)
            //}).ToList();
            #endregion
            #region æŸ¥è¯¢ç‰©æ–™åº“存按批号分组
            var StockSelectViewDTOs = BaseDal.QueryTabs<Dt_StockInfo, Dt_StockInfoDetail, StockSelectViewDTO>((a, b) => a.Id == b.StockId, (a, b) => new StockSelectViewDTO
            try
            {
                MaterielCode = b.MaterielCode,
                MaterielName = b.MaterielName,
                BatchNo = b.BatchNo,
            }, a => locationCodes.Contains(a.LocationCode), b => b.StockQuantity > b.OutboundQuantity && b.Status == StockStatusEmun.已入库.ObjToInt() && b.MaterielCode == materielCode, x => true).GroupBy(x => x.BatchNo).Select(x => new StockSelectViewDTO
                //Dt_MaterielInfo materielInfo = _basicRepository.MaterielInfoRepository.QueryFirst(x => x.MaterielCode == materielCode);
                //if (materielInfo == null) throw new Exception($"未找到物料信息");
                return BaseDal.QueryTabs<Dt_StockInfo, Dt_StockInfoDetail, StockSelectViewDTO>((a, b) => a.Id == b.StockId, (a, b) => new StockSelectViewDTO
                {
                    LocationCode = a.LocationCode,
                    MaterielCode = b.MaterielCode,
                    MaterielName = b.MaterielName,
                    PalletCode = a.PalletCode,
                    //UseableQuantity = b.StockQuantity - b.OutboundQuantity
                    UseableQuantity = b.StockQuantity,
                    BatchNo = b.BatchNo,
                }, a => a.StockStatus == StockStatusEmun.已入库.ObjToInt(), b => b.Status == StockStatusEmun.已入库.ObjToInt() && b.MaterielCode == materielCode, x => true).GroupBy(x => x.LocationCode).Select(x => new StockSelectViewDTO
                {
                    LocationCode = x.FirstOrDefault()?.LocationCode ?? "",
                    MaterielCode = x.FirstOrDefault()?.MaterielCode ?? "",
                    MaterielName = x.FirstOrDefault()?.MaterielName ?? "",
                    PalletCode = string.Join(",", x.Select(x => x.PalletCode).ToList()),
                    //UseableQuantity = x.Sum(x => x.UseableQuantity)
                    UseableQuantity = x.Sum(x => x.UseableQuantity),
                    BatchNo = x.FirstOrDefault()?.BatchNo ?? ""
                }).ToList();
            }
            catch (Exception ex)
            {
                MaterielCode = x.FirstOrDefault()?.MaterielCode ?? "",
                MaterielName = x.FirstOrDefault()?.MaterielName ?? "",
                BatchNo = x.Key,
                UseableQuantity = x.Count()
            }).ToList();
            #endregion
            return StockSelectViewDTOs;
                return null;
            }
        }
        /// <summary>
        /// è®¡ç®—库存