dengjunjie
4 天以前 7ca9651f81d7b84f054194d3d46fdbd1d9c8b922
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Inbound.cs
@@ -149,6 +149,119 @@
            }
            return content;
        }
        /// <summary>
        /// å †åž›æœºç”³è¯·å…¥åº“
        /// </summary>
        /// <param name="lineDTO"></param>
        /// <returns></returns>
        public WebResponseContent NewStackerCraneRequestInbound(ConveyorLineDTO lineDTO)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                Dt_RoadwayInfo roadwayInfo = _basicRepository.RoadwayInfoRepository.QueryFirst(x => x.InStationCode == lineDTO.stationCode) ?? throw new Exception("未找到该站台对应的巷道,请检查基础配置信息");
                if (roadwayInfo.EnableStatus != EnableStatusEnum.Normal.ObjToInt() && roadwayInfo.EnableStatus != EnableStatusEnum.OnlyIn.ObjToInt())
                {
                    throw new Exception("该巷道不可入库,请检查巷道禁用信息");
                }
                if (roadwayInfo.AreaId > 0)
                {
                    Dt_AreaInfo areaInfo = _basicRepository.AreaInfoRepository.QueryFirst(x => x.Id == roadwayInfo.AreaId);
                    if (areaInfo != null && areaInfo.AreaStatus == EnableEnum.Disable.ObjToInt())
                    {
                        throw new Exception("区域被禁用,不可入库");
                    }
                }
                var task = BaseDal.QueryFirst(x => x.PalletCode == lineDTO.Barcode);
                if (task == null) throw new Exception($"未找到托盘号[{lineDTO.Barcode}]的入库任务");
                if (task.TaskState >= (int)InTaskStatusEnum.SC_InExecuting) throw new Exception($"托盘号[{lineDTO.Barcode}]的入库任务状态不匹配");
                #region åˆ¤æ–­æ˜¯å¦ä¸ºç©ºæ‰˜å…¥åº“
                if (task.TaskType == TaskTypeEnum.PalletInbound.ObjToInt())
                    return GetEmptyLocation(task);
                #endregion
                Dt_InventoryInfo inventoryInfo = _stockService.InventoryInfoService.Repository.QueryFirst(x => x.PalletCode == lineDTO.Barcode);
                if (inventoryInfo == null) throw new Exception($"未找到托盘[{lineDTO.Barcode}]的组盘信息");
                if (inventoryInfo.StockStatus != StockStatusEmun.入库确认.ObjToInt()) throw new Exception($"托盘[{lineDTO.Barcode}],该组盘状态不可入库");
                if (!string.IsNullOrEmpty(inventoryInfo.LocationCode)) throw new Exception($"托盘[{lineDTO.Barcode}],已分配终点地址");
                Dt_InboundOrderDetail inboundOrderDetail = _inboundService.InboundOrderDetailService.Repository.QueryFirst(x => x.BatchNo == inventoryInfo.BatchNo);
                if (inboundOrderDetail == null) throw new Exception($"未找到托盘[{lineDTO.Barcode}]的入库单明细信息");
                Dt_LocationInfo? locationInfo = null;
                if (!string.IsNullOrEmpty(inboundOrderDetail.LocationCode))
                {
                    locationInfo = _basicService.LocationInfoService.GetLocation(inboundOrderDetail.LocationCode);
                }
                else
                {
                    Dt_InventoryInfo? _InventoryInfo = _stockService.InventoryInfoService.Repository.QueryData(x => x.BatchNo == inventoryInfo.BatchNo && (x.StockStatus == StockStatusEmun.入库中.ObjToInt() || x.StockStatus == StockStatusEmun.已入库.ObjToInt())).OrderByDescending(x => x.ModifyDate).FirstOrDefault();
                    if (_InventoryInfo != null)
                    {
                        locationInfo = _basicService.LocationInfoService.GetLocation(_InventoryInfo.LocationCode);
                        if (locationInfo?.MaxQty <= locationInfo?.CurrentQty) locationInfo = null;
                    }
                    if (locationInfo == null)//分配新货位
                    {
                        var Qty = Convert.ToInt32(inboundOrderDetail.OrderQuantity - inboundOrderDetail.OverInQuantity);
                        var ts = Qty / 320;
                        if (Qty % 320 > 0) ts++;
                        int inboundOrderCount = ts > 12 ? 2 : 1;
                        locationInfo = _basicService.LocationInfoService.AssignLocation(inboundOrderCount);//重新分配货位
                    }
                }
                if (locationInfo == null) throw new Exception($"无可入货位");
                #region ä¿®æ”¹åº“存及货位信息
                task.TaskState = (int)InTaskStatusEnum.SC_InExecuting;
                task.CurrentAddress = task.NextAddress;
                task.NextAddress = locationInfo.LocationCode;
                task.TargetAddress = task.NextAddress;
                task.TargetIsPickPlace = locationInfo.MaxQty - locationInfo.CurrentQty == 1;
                task.SourceIsPickPlace = false;
                inventoryInfo.LocationCode = locationInfo.LocationCode;
                inventoryInfo.StockStatus = StockStatusEmun.入库中.ObjToInt();
                locationInfo.CurrentQty++;
                if (locationInfo.MaxQty < locationInfo.CurrentQty) locationInfo.CurrentQty = locationInfo.MaxQty;
                inventoryInfo.SerialNumber = locationInfo.CurrentQty;
                inboundOrderDetail.OverInQuantity = inboundOrderDetail.OverInQuantity + inventoryInfo.StockQuantity;
                if (inboundOrderDetail.OverInQuantity > inboundOrderDetail.ReceiptQuantity)
                    inboundOrderDetail.OverInQuantity = inboundOrderDetail.ReceiptQuantity;
                locationInfo.EnableStatus = EnableStatusEnum.OnlyOut.ObjToInt();
                locationInfo.LocationStatus = LocationStatusEnum.Inbounding.ObjToInt();
                Db.Ado.BeginTran();
                UpdateData(task);
                _stockService.InventoryInfoService.Repository.UpdateData(inventoryInfo);
                if (inboundOrderDetail.OverInQuantity == inboundOrderDetail.OrderQuantity)
                {
                    inboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
                    Dt_InboundOrder inboundOrder = _inboundService.InbounOrderService.Repository.QueryFirst(x => x.Id == inboundOrderDetail.OrderId);
                    inboundOrder.OrderStatus = InboundStatusEnum.入库完成.ObjToInt();
                    _inboundService.InbounOrderService.Repository.DeleteAndMoveIntoHty(inboundOrder, OperateType.自动完成);
                    _inboundService.InboundOrderDetailService.Repository.DeleteAndMoveIntoHty(inboundOrderDetail, OperateType.自动完成);
                }
                else
                    _inboundService.InboundOrderDetailService.Repository.UpdateData(inboundOrderDetail);
                _basicService.LocationInfoService.Repository.UpdateData(locationInfo);
                Db.Ado.CommitTran();
                #endregion
                content.OK(data: new ReceiveWMSInfo()
                {
                    TargetAddress = task.TargetAddress,
                    SourceIsPickPlace = task.SourceIsPickPlace,
                    TargetIsPickPlace = task.TargetIsPickPlace,
                });
            }
            catch (Exception ex)
            {
                Db.Ado.RollbackTran();
                content.Error(ex.Message);
            }
            return content;
        }
        /// <summary>
        /// å †åž›æœºç”³è¯·å…¥åº“