dengjunjie
2025-04-19 9e579eda4601ed7b492b9d19a24e8146f6ebdf8d
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA_StockService/Service/StockInfoService.cs
@@ -34,6 +34,44 @@
            return stockInfo;
        }
        /// <summary>
        /// æ·»åŠ ç©ºæ‰˜ç›˜ç»„ç›˜ä¿¡æ¯
        /// </summary>
        /// <returns></returns>
        public WebResponseContent AddStockEmpty(string palletCode)
        {
            try
            {
                Dt_MaterielInfo materielInfo = _basicRepository.MaterielInfoRepository.QueryFirst(x => x.MaterielCode == "Empty000");
                if (materielInfo == null) throw new Exception($"未找到空托盘信息,物料编号【Empty000】");
                Dt_StockInfo stockInfo = new Dt_StockInfo()
                {
                    PalletCode = palletCode,
                    StockStatus = StockStatusEmun.入库确认.ObjToInt(),
                    Creater = "System",
                    Details = new List<Dt_StockInfoDetail>()
                };
                Dt_StockInfoDetail stockInfoDetail = new Dt_StockInfoDetail()
                {
                    Status = StockStatusEmun.入库确认.ObjToInt(),
                    OrderNo = DateTime.Now.ToString("yyMMdd"),
                    StockId = stockInfo.Id != 0 ? stockInfo.Id : 0,
                    MaterielName = materielInfo.MaterielName,
                    MaterielCode = materielInfo.MaterielCode,
                    BatchNo = DateTime.Now.ToString("yyMMdd") + "E",
                    StockQuantity = 1,
                    SerialNumber = "",
                    Creater = "System"
                };
                stockInfo.Details.Add(stockInfoDetail);
                AddMaterielGroup(stockInfo);
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
        /// <summary>
        /// æ·»åŠ ç»„ç›˜/库存信息
        /// </summary>
        /// <returns></returns>
@@ -43,21 +81,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,8 +103,8 @@
                    StockId = stockInfo.Id != 0 ? stockInfo.Id : 0,
                    MaterielName = materielInfo.MaterielName,
                    MaterielCode = materielInfo.MaterielCode,
                    BatchNo = inboundOrder.Details.FirstOrDefault().BatchNo,
                    StockQuantity = productionlineDTO.QtySum,
                    BatchNo = inboundOrderDetail.BatchNo,
                    StockQuantity = 1,// productionlineDTO.QtySum,
                    SerialNumber = "",
                    //SerialNumber = $"{inboundOrder.OrderNo} | {materielInfo.MaterielCode} | {pdaMaterielGroupDTO.BatchNo} | {pdaMaterielGroupDTO.ReceiptQuantity}",
                    Creater = "System"
@@ -165,67 +200,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>
        /// è®¡ç®—库存