dengjunjie
2025-07-04 441b6f8d257a01b2998253ef0515a201777d7e68
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Inbound.cs
@@ -192,6 +192,7 @@
                Dt_InboundOrder inboundOrder = _inboundService.InbounOrderService.GetInboundOrder(stockInfoDetail.OrderNo);
                if (inboundOrder == null) throw new Exception($"未找到托盘[{lineDTO.Barcode}]的入库单信息");
                var BatchNo = stockInfoDetail.BatchNo;
                #region åˆ¤æ–­æ˜¯å¦æŒ‡å®šè´§ä½
                Dt_InboundOrderDetail? orderDetail = inboundOrder.Details.FirstOrDefault(x => x.BatchNo == stockInfoDetail.BatchNo);
                if (orderDetail == null) throw new Exception($"未找到托盘[{lineDTO.Barcode}]的入库单明细信息");
@@ -202,41 +203,43 @@
                }
                #endregion
                #region åˆ¤æ–­å½“前入库托盘批次号是否存在已分配入库
                else
                {
                    #region åˆ¤æ–­å½“前入库托盘批次号是否存在已分配入库
                    Dt_StockInfo? instockInfo = null;
                    Dt_StockInfoDetail instockInfoDetail = _stockService.StockInfoDetailService.Get_StockInfoDetail(stockInfoDetail.OrderNo, stockInfoDetail.BatchNo);
                    if (instockInfoDetail != null) instockInfo = _stockService.StockInfoService.Repository.GetStockInfo(instockInfoDetail.StockId);
                    if (instockInfo != null)
                    {
                        locationInfo = _basicService.LocationInfoService.GetLocation(instockInfo.LocationCode);
                        if (locationInfo.MaxQty <= locationInfo.CurrentQty) locationInfo = null;
                        if (locationInfo?.MaxQty <= locationInfo?.CurrentQty) locationInfo = null;
                    }
                    #endregion
                    else
                    {
                        instockInfoDetail = _stockService.StockInfoDetailService.Get_StockInfoDetail(stockInfoDetail.OrderNo);//入库单存在库存,判断货位
                        instockInfoDetail = _stockService.StockInfoDetailService.Get_StockInfoDetail(stockInfoDetail.OrderNo /*BatchNo*/);//入库单存在库存,判断货位
                        if (instockInfoDetail != null) instockInfo = _stockService.StockInfoService.Repository.GetStockInfo(instockInfoDetail.StockId);
                        if (instockInfo != null)
                        {
                            Dt_LocationInfo? location = _basicService.LocationInfoService.GetLocation(instockInfo.LocationCode);//查询已存在库存货位状态
                            if (location?.Row == 1)
                            {
                                var newLocation = Db.Queryable<Dt_LocationInfo>().Where(x => x.Row == 2 && x.Layer == location.Layer && x.Column == location.Column).First();
                                if (newLocation != null && newLocation.LocationStatus == LocationStatusEnum.Free.ObjToInt() && newLocation.CurrentQty == 0 && (newLocation.EnableStatus == EnableStatusEnum.OnlyIn.ObjToInt() || newLocation.EnableStatus == EnableStatusEnum.Normal.ObjToInt()))
                                var instockInfos = _stockService.StockInfoService.Repository.GetDt_StockInfos(instockInfo.LocationCode);
                                List<Dt_StockInfoDetail> Details = new List<Dt_StockInfoDetail>();
                                foreach (var item in instockInfos)
                                {
                                    locationInfo = newLocation;
                                    Details.AddRange(item.Details);
                                }
                                var count = Details.GroupBy(x => x.BatchNo).Count();
                                if (count <= 1) locationInfo = location;
                            }
                        }
                    }
                    if (locationInfo == null)//分配新货位
                    {
                        int inboundOrderCount = inboundOrder.Details.Count;
                        List<Dt_StockInfoDetail> stockInfoDetails = _stockService.StockInfoDetailService.Get_StockInfoDetails(stockInfoDetail.OrderNo);//获取工单所有已入库或入库中库存
                        if (stockInfoDetails != null || stockInfoDetails.Count > 0) inboundOrderCount -= stockInfoDetails.GroupBy(x => x.BatchNo).Count();
                        List<Dt_InboundOrderDetail> inboundOrderDetailList = inboundOrder.Details.Where(x => /*x.BatchNo.Contains(BatchNo) &&*/ x.OverInQuantity == 0).ToList();
                        int inboundOrderCount = inboundOrderDetailList.Count;
                        locationInfo = _basicService.LocationInfoService.AssignLocation(inboundOrderCount);//重新分配货位
                    }
                }
@@ -251,20 +254,24 @@
                task.TargetAddress = task.NextAddress;
                string[] targetCodes = task.NextAddress.Split("-");
                var Row = Convert.ToInt16(targetCodes[0]);
                task.TargetIsPickPlace = Row > 1 ? locationInfo.MaxQty - locationInfo.CurrentQty == 1 : false;
                task.TargetIsPickPlace = locationInfo.MaxQty - locationInfo.CurrentQty == 1;
                task.SourceIsPickPlace = false;
                stockInfo.LocationCode = locationInfo.LocationCode;
                stockInfo.StockStatus = StockStatusEmun.入库中.ObjToInt();
                stockInfoDetail.Status = StockStatusEmun.入库中.ObjToInt();
                locationInfo.CurrentQty++;
                if (locationInfo.MaxQty < locationInfo.CurrentQty) throw new Exception();
                /*if (locationInfo.MaxQty == 12)*/
                if (locationInfo.MaxQty < locationInfo.CurrentQty) locationInfo.CurrentQty = locationInfo.MaxQty;
                stockInfo.SerialNumber = locationInfo.CurrentQty;
                orderDetail.OverInQuantity++;
                if (orderDetail.OverInQuantity > orderDetail.ReceiptQuantity)
                    orderDetail.OverInQuantity = orderDetail.ReceiptQuantity;
                locationInfo.EnableStatus = EnableStatusEnum.OnlyOut.ObjToInt();
                locationInfo.LocationStatus = LocationStatusEnum.Inbounding.ObjToInt();
                Db.Ado.BeginTran();
                UpdateData(task);
                _stockService.StockInfoService.Repository.UpdateData(stockInfo);
                _inboundService.InboundOrderDetailService.Repository.UpdateData(orderDetail);
                _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetail);
                _basicService.LocationInfoService.Repository.UpdateData(locationInfo);
                Db.Ado.CommitTran();
@@ -303,26 +310,54 @@
                Dt_LocationInfo? locationInfo = null;
                string CarChargingStation = AppSettings.Configuration[nameof(CarChargingStation)];//获取穿梭车充电位置
                var ChargingStations = CarChargingStation.Split(",");
                Dt_StockInfoDetail instockInfoDetail = _stockService.StockInfoDetailService.Repository.QueryData(x => x.MaterielCode == stockInfoDetail.MaterielCode).OrderByDescending(x => x.CreateDate).First();
                Dt_StockInfoDetail? instockInfoDetail = null;
                var instockInfoDetails = _stockService.StockInfoDetailService.Repository.QueryData(x => x.MaterielCode == stockInfoDetail.MaterielCode && x.Status == StockStatusEmun.入库中.ObjToInt());
                if (instockInfoDetails.Count > 0)
                    instockInfoDetail = instockInfoDetails.OrderByDescending(x => x.CreateDate).First();
                if (instockInfoDetails.Count < 1)
                {
                    instockInfoDetails = _stockService.StockInfoDetailService.Repository.QueryData(x => x.MaterielCode == stockInfoDetail.MaterielCode && x.Status == StockStatusEmun.已入库.ObjToInt());
                    if (instockInfoDetails.Count > 0)
                        instockInfoDetail = instockInfoDetails.OrderByDescending(x => x.CreateDate).First();
                }
                if (instockInfoDetail != null) instockInfo = _stockService.StockInfoService.Repository.GetStockInfo(instockInfoDetail.StockId);
                if (instockInfo != null)//无库存
                {
                    locationInfo = _basicRepository.LocationInfoRepository.QueryFirst(x => x.LocationCode == instockInfo.LocationCode);
                    if (ChargingStations.Contains(locationInfo.LocationCode))
                    //if (BaseDal.QueryFirst(x => x.SourceAddress == locationInfo.LocationCode && x.TaskState < OutTaskStatusEnum.SC_OutFinish.ObjToInt()) != null) locationInfo = null;
                    if (locationInfo != null && ChargingStations.Contains(locationInfo.LocationCode))
                    {
                        if (locationInfo.MaxQty - locationInfo.CurrentQty <= 1) locationInfo = null;
                    }
                    else if (locationInfo.MaxQty - locationInfo.CurrentQty < 1)
                    else if (locationInfo != null && locationInfo.MaxQty - locationInfo.CurrentQty < 1)
                    {
                        locationInfo = null;
                    }
                    if (locationInfo == null)
                    {
                        var locationInfos = _basicService.LocationInfoService.GetLocationPallet();
                        foreach (var item in locationInfos)
                        {
                            if (BaseDal.QueryFirst(x => x.SourceAddress == item.LocationCode) == null)
                            {
                                locationInfo = item;
                                break;
                            }
                        }
                    }
                }
                else
                {
                    locationInfo = _basicService.LocationInfoService.AssignLocation(ChargingStations);//查找穿梭车充电货位
                }
                //else
                //{
                //    locationInfo = _basicService.LocationInfoService.AssignLocation(ChargingStations);//查找穿梭车充电货位
                //}
                if (locationInfo == null) locationInfo = _basicService.LocationInfoService.AssignLocation(2);//重新分配货位
                if (locationInfo == null) throw new Exception($"无可入货位");
                Dt_LocationInfo? locationInfo1 = null;
                if (locationInfo.Row == 1)
                {
                    locationInfo1 = _basicService.LocationInfoService.Repository.QueryFirst(x => x.Row == 2 && x.Layer == locationInfo.Layer && x.Column == locationInfo.Column);
                    locationInfo1.LocationStatus = LocationStatusEnum.Pallet.ObjToInt();
                }
                task.TaskState = (int)InTaskStatusEnum.SC_InExecuting;
                task.CurrentAddress = task.NextAddress;
@@ -343,6 +378,7 @@
                _stockService.StockInfoService.Repository.UpdateData(stockInfo);
                _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetail);
                _basicService.LocationInfoService.Repository.UpdateData(locationInfo);
                if (locationInfo1 != null) _basicService.LocationInfoService.Repository.UpdateData(locationInfo1);
                Db.Ado.CommitTran();
                return WebResponseContent.Instance.OK(data: new ReceiveWMSInfo()