dengjunjie
2025-02-11 8467804705615f7614c29e7ef7ac3e99f5c13a54
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Inbound.cs
@@ -8,6 +8,8 @@
using WIDESEA_Core;
using WIDESEA_Model.Models;
using WIDESEA_Core.Helper;
using WIDESEAWCS_DTO.WCSInfo;
using System.Transactions;
namespace WIDESEA_TaskInfoService
{
@@ -111,7 +113,7 @@
                        Roadway = locationInfo.RoadwayNo,
                        SourceAddress = stationCode,
                        TargetAddress = locationInfo.LocationCode,
                        TaskStatus = InTaskStatusEnum.InNew.ObjToInt(),
                        TaskState = InTaskStatusEnum.InNew.ObjToInt(),
                        TaskType = taskType,
                    };
                    BaseDal.AddData(task);
@@ -120,7 +122,7 @@
                    locationInfo.LocationStatus = LocationStatusEnum.PalletLock.ObjToInt();
                    if (isUpdateStock)
                    {
                        locationInfo.LocationStatus = LocationStatusEnum.Lock.ObjToInt();
                        locationInfo.LocationStatus = LocationStatusEnum.OutLock.ObjToInt();
                        if (stockInfo != null && stockInfo.Details != null && stockInfo.Details.Count > 0)
                        {
                            orderNo = stockInfo.Details.FirstOrDefault()?.OrderNo ?? "";
@@ -148,51 +150,152 @@
        }
        /// <summary>
        /// éªŒè¯æ•°æ®
        /// å †åž›æœºç”³è¯·å…¥åº“
        /// </summary>
        /// <param name="stationCode">起始地址</param>
        /// <param name="palletCode">托盘编号</param>
        /// <param name="isCheckStock">是否检查组盘信息--区分物料入库和空托入库</param>
        /// <param name="stockInfo">组盘信息--可空</param>
        /// <returns>返回处理结果</returns>
        private (bool, string) CheckRequestInbound(string stationCode, string palletCode, bool isCheckStock = true, Dt_StockInfo? stockInfo = null)
        /// <param name="task"></param>
        /// <returns></returns>
        public WebResponseContent StackerCraneRequestInbound(ConveyorLineDTO lineDTO)
        {
            if (BaseDal.QueryFirst(x => x.PalletCode == palletCode) != null)
            WebResponseContent content = new WebResponseContent();
            try
            {
                return (false, "该托盘号已有任务");
            }
            if (BaseDal.QueryFirst(x => (x.SourceAddress == stationCode || x.CurrentAddress == stationCode) && x.TaskStatus == InTaskStatusEnum.InNew.ObjToInt()) != null)
            {
                return (false, "当前入库站台已有一条新建任务");
            }
            if (isCheckStock)
            {
                if (stockInfo == null)
                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())
                {
                    return (false, "未找到组盘信息");
                    throw new Exception("该巷道不可入库,请检查巷道禁用信息");
                }
                if (stockInfo.StockStatus != StockStatusEmun.组盘暂存.ObjToInt())
                if (roadwayInfo.AreaId > 0)
                {
                    return (false, "该组盘状态不可入库");
                    Dt_AreaInfo areaInfo = _basicRepository.AreaInfoRepository.QueryFirst(x => x.Id == roadwayInfo.AreaId);
                    if (areaInfo != null && areaInfo.AreaStatus == EnableEnum.Disable.ObjToInt())
                    {
                        throw new Exception("区域被禁用,不可入库");
                    }
                }
                if (!string.IsNullOrEmpty(stockInfo.LocationCode))
                {
                    return (false, "该托盘已绑定货位");
                }
                if (stockInfo.Details == null || stockInfo.Details.Count == 0)
                {
                    return (false, "没有库存明细信息");
                }
            }
            else
            {
                if (_stockService.StockInfoService.Repository.QueryFirst(x => x.PalletCode == palletCode) != null)
                {
                    return (false, "该托盘已存在库内");
                }
            }
                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}]的入库任务状态不匹配");
            return (true, "成功");
                Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(lineDTO.Barcode);
                if (stockInfo == null) throw new Exception($"未找到托盘[{lineDTO.Barcode}]的组盘信息");
                Dt_StockInfoDetail? stockInfoDetail = stockInfo.Details.Where(x => x.StockId == stockInfo.Id).FirstOrDefault();
                if (stockInfoDetail == null) throw new Exception($"未找到托盘[{lineDTO.Barcode}]的组盘详情");
                if (stockInfo.StockStatus != StockStatusEmun.入库确认.ObjToInt() || !string.IsNullOrEmpty(stockInfo.LocationCode))
                    throw new Exception($"托盘[{lineDTO.Barcode}],该组盘状态不可入库");
                Dt_InboundOrder inboundOrder = _inboundService.InbounOrderService.GetInboundOrder(stockInfoDetail.OrderNo);
                if (inboundOrder == null) throw new Exception($"未找到托盘[{lineDTO.Barcode}]的入库单信息");
                #region åˆ¤æ–­æ˜¯å¦æŒ‡å®šè´§ä½
                Dt_InboundOrderDetail? orderDetail = inboundOrder.Details.FirstOrDefault(x => x.BatchNo == stockInfoDetail.BatchNo);
                if (orderDetail == null) throw new Exception($"未找到托盘[{lineDTO.Barcode}]的入库单明细信息");
                Dt_LocationInfo? locationInfo = null;
                if (!string.IsNullOrEmpty(orderDetail.LocationCode))
                {
                    locationInfo = _basicService.LocationInfoService.GetLocation(orderDetail.LocationCode);
                }
                #endregion
                #region åˆ¤æ–­å½“前入库托盘批次号是否存在已分配入库
                else
                {
                    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;
                    }
                    #endregion
                    else
                    {
                        instockInfoDetail = _stockService.StockInfoDetailService.Get_StockInfoDetail(stockInfoDetail.OrderNo);//入库单存在库存,判断货位
                        if (instockInfoDetail != null) instockInfo = _stockService.StockInfoService.Repository.GetStockInfo(instockInfoDetail.StockId);
                        if (instockInfo != null)
                        {
                            locationInfo = _basicService.LocationInfoService.GetLocation(instockInfo.LocationCode);//查询已存在库存货位状态
                            #region MyRegion
                            //if (locationInfo.MaxQty == 12)
                            //{
                            //    locationInfo.EnableStatus = EnableStatusEnum.OnlyOut.ObjToInt();
                            //    _basicService.LocationInfoService.Repository.UpdateData(locationInfo);
                            //    locationInfo = null;
                            //}
                            //if (locationInfo.EnableStatus == EnableStatusEnum.OnlyOut.ObjToInt()) locationInfo = null;
                            #endregion
                            if (locationInfo.LocationStatus > LocationStatusEnum.Inbounding.ObjToInt()) locationInfo = null;
                            else
                            {
                                #region åˆ¤æ–­è´§ä½
                                if (locationInfo.Row == 1)//外侧货位,判断内侧货位
                                {
                                    var newLocation = Db.Queryable<Dt_LocationInfo>().Where(x => x.LocationCode != locationInfo.LocationCode && x.Remark == locationInfo.Remark).First();
                                    if (newLocation != null)
                                    {
                                        if (newLocation.LocationStatus == LocationStatusEnum.Free.ObjToInt() &&
                                            (newLocation.EnableStatus == EnableStatusEnum.OnlyIn.ObjToInt() ||
                                            newLocation.EnableStatus == EnableStatusEnum.Normal.ObjToInt()))
                                        {
                                            locationInfo = newLocation;
                                        }
                                    }
                                }
                                #endregion
                                //List<Dt_StockInfoDetail> stockInfoDetails = _stockService.StockInfoDetailService.Get_StockInfoDetails(stockInfoDetail.OrderNo);//获取工单所有已入库或入库中库存
                                //if (stockInfoDetails.GroupBy(x => x.BatchNo).Count() < 2) locationInfo.EnableStatus = EnableStatusEnum.OnlyOut.ObjToInt();
                                //else locationInfo = null;
                            }
                            //if (locationInfo?.MaxQty <= locationInfo?.CurrentQty) locationInfo = null;
                        }
                    }
                    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();
                        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.IsPickPlace = locationInfo.MaxQty - locationInfo.CurrentQty == 1;
                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) locationInfo.EnableStatus = EnableStatusEnum.OnlyOut.ObjToInt();
                locationInfo.LocationStatus = LocationStatusEnum.Inbounding.ObjToInt();
                Db.Ado.BeginTran();
                UpdateData(task);
                _stockService.StockInfoService.Repository.UpdateData(stockInfo);
                _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetail);
                _basicService.LocationInfoService.Repository.UpdateData(locationInfo);
                Db.Ado.CommitTran();
                #endregion
                content.OK(data: new ReceiveWMSInfo()
                {
                    TargetAddress = task.TargetAddress,
                    IsPickPlace = task.IsPickPlace,
                });
            }
            catch (Exception ex)
            {
                Db.Ado.RollbackTran();
                content.Error(ex.Message);
            }
            return content;
        }