yuyou_x
2024-03-16 cd8800f471c9d7ee62dd915c4407f809638471af
Wms/WMS.BLL/BllPdaServer/PdaCrServer.cs
@@ -885,22 +885,33 @@
            if (!string.IsNullOrEmpty(areaNo) && !string.IsNullOrEmpty(ruku))
            {
                throw new Exception("目标区域和入库口不能同时选择!");
            }
            string EndLocat = string.Empty;//目标位置
            if (!string.IsNullOrEmpty(areaNo))
            {
                EndLocat = areaNo;
            }
            else
            {
                EndLocat = ruku;
            }
            }
            try
            {
                string EndLocat = string.Empty;//目标位置
                var log = Db.Queryable<LogTask>().First(w => w.IsDel == "0" && w.PalletNo == palletNo && (w.Status == "0" || w.Status == "1"));
                if (log != null)
                {
                    throw new Exception("该托盘已有小车等待执行或正在执行的任务!");
                }
                var stockDetail = Db.Queryable<DataStockDetail>().First(w => w.IsDel == "0" && w.PalletNo == palletNo);
                if (stockDetail == null)
                {
                    throw new Exception("托盘上物料库存明细信息不存在,请检查!");
                }
                if (!string.IsNullOrEmpty(areaNo))
                {
                    var storageArea = Db.Queryable<SysStorageArea>().First(w => w.IsDel == "0" && w.AreaNo == areaNo);
                    if (storageArea == null)
                    {
                        throw new Exception("所选区域信息不存在,请检查!");
                    }
                    EndLocat = GetLocat(areaNo, stockDetail.SkuNo, stockDetail.LotNo,palletNo);
                }
                else
                {
                    EndLocat = ruku;
                }
                var stock = Db.Queryable<DataStock>().First(w => w.IsDel == "0" && w.SkuNo == stockDetail.SkuNo && w.LotNo == stockDetail.LotNo);
                if (stock == null)
@@ -915,11 +926,23 @@
                {
                    throw new Exception("该托盘未在平库内,请检查!");
                }
                //起始储位信息
                var storageLocat = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == stockDetail.LocatNo);
                if (storageLocat == null)
                {
                    throw new Exception("储位信息不存在,请检查!");
                }
                //目标储位信息
                var storageLocatEnd = new SysStorageLocat();
                if (!string.IsNullOrEmpty(areaNo))
                {
                    storageLocatEnd = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == EndLocat && w.Flag == "0" && w.Status == "0");
                    if (storageLocatEnd == null)
                    {
                        throw new Exception("目标储位信息不存在,请检查!");
                    }
                }
                //开启事务
                Db.BeginTran();
@@ -954,10 +977,16 @@
                stock.LockQty += (decimal)stockDetail.Qty;
                Db.Updateable(stock).ExecuteCommand();
                //修改储位地址状态
                storageLocat.Status = "3";//0:空储位 1:有物品 2:入库中 3:出库中 4:移入中 5:移出中
                //修改起始储位地址状态
                storageLocat.Status = "5";//0:空储位 1:有物品 2:入库中 3:出库中 4:移入中 5:移出中
                Db.Updateable(storageLocat).ExecuteCommand();
                //修改目标储位地址状态
                if (storageLocatEnd != null)
                {
                    storageLocatEnd.Status = "4";//0:空储位 1:有物品 2:入库中 3:出库中 4:移入中 5:移出中
                    Db.Updateable(storageLocatEnd).ExecuteCommand();
                }
                //添加操作日志记录
                var k = new OperationCrServer().AddLogOperationCr("PDA模块", "AGV转运", palletNo, "移库", $"PDA呼叫小车对托盘号:{palletNo}发起转运", userId);
                //提交事务
@@ -996,6 +1025,12 @@
            }
            try
            {
                var log = Db.Queryable<LogTask>().First(w => w.IsDel == "0" && w.PalletNo == palletNo && (w.Status == "0" || w.Status == "1"));
                if (log != null)
                {
                    throw new Exception("该托盘已有小车等待执行或正在执行的任务!");
                }
                var notice = Db.Queryable<BllExportNotice>().First(w => w.IsDel == "0" && w.SONo == soNo);
                if (notice == null)
                {
@@ -1035,7 +1070,13 @@
                    throw new Exception("所选区域信息不存在,请检查!");
                }
                string EndLocat = string.Empty;//目标位置
                EndLocat= Db.Queryable<SysStorageLocat>().Where(w => w.IsDel == "0" && w.AreaNo==storageArea.AreaNo && w.Status=="0" &&w.Flag=="0").Select(s=>s.LocatNo).First();
                EndLocat= GetLocat(areaNo, stockDetail.SkuNo, stockDetail.LotNo,palletNo);
                //目标储位信息
                var storageLocatEnd = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == EndLocat && w.Flag == "0" && w.Status == "0");
                if (storageLocatEnd == null)
                {
                    throw new Exception("目标储位信息不存在,请检查!");
                }
                //开启事务
                Db.BeginTran();
@@ -1071,8 +1112,12 @@
                Db.Updateable(stock).ExecuteCommand();
                //修改储位地址状态
                storageLocat.Status = "3";//0:空储位 1:有物品 2:入库中 3:出库中 4:移入中 5:移出中
                storageLocat.Status = "5";//0:空储位 1:有物品 2:入库中 3:出库中 4:移入中 5:移出中
                Db.Updateable(storageLocat).ExecuteCommand();
                //修改目标储位地址状态
                storageLocatEnd.Status = "4";//0:空储位 1:有物品 2:入库中 3:出库中 4:移入中 5:移出中
                Db.Updateable(storageLocatEnd).ExecuteCommand();
                //添加操作日志记录
                var k = new OperationCrServer().AddLogOperationCr("PDA模块", "AGV转运", palletNo, "移库", $"PDA呼叫小车对托盘号:{palletNo}发起转运", userId);
@@ -1089,6 +1134,51 @@
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 根据区域分配储位
        /// </summary>
        /// <param name="areaNo"></param>
        /// <param name="skuNo"></param>
        /// <param name="lotNo"></param>
        /// <returns></returns>
        private string GetLocat(string areaNo,string skuNo,string lotNo,string palletNo)
        {
            try
            {
                string endLocat = string.Empty;//目标储位
                //当然区域所有储位信息
                var storageLocatList = Db.Queryable<SysStorageLocat>().Where(w => w.WareHouseNo == "W02" && w.AreaNo == areaNo).ToList();
                //同区域同批次物料的储位信息
                List<string> locatList = Db.Queryable<DataStockDetail>().Where(w => w.IsDel == "0" && w.SkuNo == skuNo && w.LotNo == lotNo && w.WareHouseNo == "W02" && w.AreaNo == areaNo && w.PalletNo != palletNo)
                    .OrderByDescending(o=>o.LocatNo).Select(s=>s.LocatNo).Distinct().ToList();
                foreach (var item in locatList)
                {
                    var locatInfo = storageLocatList.Where(w => w.LocatNo == item).First();
                    var locatInfo2 = storageLocatList.Where(w => w.IsDel == "0" && w.Status == "0" && w.Flag == "0" && w.LocatNo != locatInfo.LocatNo && w.Row == locatInfo.Row)
                        .OrderByDescending(o => o.Column).First();
                    if (locatInfo2 != null)
                    {
                        endLocat = locatInfo2.LocatNo;
                    }
                }
                if (string.IsNullOrEmpty(endLocat))
                {
                    var locatInfo3 = storageLocatList.Where(w => w.IsDel == "0" && w.Flag == "0" && w.Status == "0")
                                .OrderByDescending(m => m.Layer).OrderByDescending(m=>m.Column).OrderByDescending(m=> m.Row).First();
                    if (locatInfo3 != null)
                    {
                        endLocat = locatInfo3.LocatNo;
                    }
                }
                return endLocat;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        #endregion
    }