From 219a08427376efdd304e9b11e481ccd8276018bb Mon Sep 17 00:00:00 2001
From: zhaowc <526854230@qq.com>
Date: 星期六, 18 十月 2025 11:14:29 +0800
Subject: [PATCH] 巷道形式存取放物料

---
 Wms/WMS.BLL/BllTransServer/HopperTransportServer.cs |  135 +++++++++++++++++++++++++--------------------
 1 files changed, 75 insertions(+), 60 deletions(-)

diff --git a/Wms/WMS.BLL/BllTransServer/HopperTransportServer.cs b/Wms/WMS.BLL/BllTransServer/HopperTransportServer.cs
index 7975829..29fb576 100644
--- a/Wms/WMS.BLL/BllTransServer/HopperTransportServer.cs
+++ b/Wms/WMS.BLL/BllTransServer/HopperTransportServer.cs
@@ -159,13 +159,14 @@
         /// <param name="palletStatus"></param>
         /// <returns></returns>
         /// <exception cref="Exception"></exception>
-        public List<string> GetSkuByStatus(string palletStatus)
+        public List<DataStockDetail> GetSkuByStatus(string palletStatus)
         {
             try
             {
                 //鑾峰彇鍌ㄤ綅涓婄殑搴撳瓨鐗╂枡
-                var detail = Db.Queryable<DataStockDetail>().Where(m => m.IsDel == "0" && !string.IsNullOrWhiteSpace(m.LocatNo) && m.PalletStatus == palletStatus).Select(m=>m.SkuNo).Distinct().ToList();
-                return detail;
+                var detail = Db.Queryable<DataStockDetail>().Where(m => m.IsDel == "0" && !string.IsNullOrWhiteSpace(m.LocatNo) && m.PalletStatus == palletStatus).ToList();
+                List<DataStockDetail> result = detail.GroupBy(x => x.SkuNo).Select(xx => xx.First()).ToList();
+                return result;
             }
             catch (Exception e)
             {
@@ -191,12 +192,14 @@
             }
         }
 
-        public List<string> GetSku()
+        public List<SysMaterials> GetSku()
         {
             try
             {
                 //鑾峰彇鍌ㄤ綅涓婄殑搴撳瓨鐗╂枡
-                var detail = Db.Queryable<SysMaterials>().Where(m => m.IsDel == "0" ).Select(m => m.SkuNo).Distinct().ToList();
+                //var detail = Db.Queryable<SysMaterials>().Where(m => m.IsDel == "0" ).Select(m => m.SkuNo).Distinct().ToList();
+
+                var detail = Db.Queryable<SysMaterials>().Where(m => m.IsDel == "0").ToList();
                 return detail;
             }
             catch (Exception e)
@@ -264,12 +267,20 @@
                     throw new Exception("娌℃湁鏌ヨ鍒颁粨搴撲俊鎭�");
                 }
                 //鏌ユ壘鐘舵�佹槸鏈垎閰嶄笖鍌ㄤ綅涓嶄负绌虹殑搴撳瓨淇℃伅
-                var stockDetail = Db.Queryable<DataStockDetail>().Where(m => m.Status == "0" && m.WareHouseNo == house.WareHouseNo && !string.IsNullOrWhiteSpace(m.LocatNo)).ToList();
+                var stockDetail = Db.Queryable<DataStockDetail>().Where(m => m.Status == "0" && m.WareHouseNo == house.WareHouseNo && !string.IsNullOrWhiteSpace(m.LocatNo) && m.IsDel=="0").ToList();
 
                 //鍑�妗�
-                if (plnStatus == "0")
+                if (plnStatus == "0")  //4L鍙噣妗朵笉鍒嗘ゼ灞�
                 {
-                    stockDetail = stockDetail.Where(m => m.PalletStatus == "0" && m.Standard == standard).OrderBy(m => m.LocatNo).ToList();
+                    if (house.WareHouseNo == "M01")
+                    {
+                        stockDetail = Db.Queryable<DataStockDetail>().Where(m => m.IsDel == "0" && m.Status == "0" && m.PalletStatus == "0" && m.Standard == standard && !string.IsNullOrWhiteSpace(m.LocatNo)).OrderBy(m => m.LocatNo).ToList();
+                    }
+                    else
+                    {
+                        stockDetail = stockDetail.Where(m => m.IsDel == "0" && m.Status == "0" && m.PalletStatus == "0" && m.Standard == standard && !string.IsNullOrWhiteSpace(m.LocatNo)).OrderBy(m => m.LocatNo).ToList();
+                    }
+                    
                 }
                 //婊℃《
                 else if (plnStatus == "2") 
@@ -292,12 +303,12 @@
                 bool resultYi = false;
                 #region#鏌ユ壘鍚堥�傜殑 妗跺彿 鍌ㄤ綅
                 //鐩爣浠撳簱鎵�鏈夊偍浣�
-                var locatList = Db.Queryable<SysStorageLocat>().Where(w => w.IsDel == "0" && w.WareHouseNo == house.WareHouseNo).ToList();
-                //鐩爣浠撳簱鎵�鏈変笉闇�瑕佺Щ搴撶殑鍌ㄤ綅
+                var locatList = Db.Queryable<SysStorageLocat>().Where(w => w.IsDel == "0" && w.Flag=="0" && w.WareHouseNo == house.WareHouseNo).OrderBy(w=>w.Column).ToList();
+                //鐩爣浠撳簱鎵�鏈夋渶澶栦晶鐨勫偍浣�
                 var locatListWai = locatList.Where(w => string.IsNullOrEmpty(w.AisleOne)).Select(s => s.LocatNo);
 
                 //鍏堟壘涓嶉渶瑕佺Щ搴撶殑妗�
-                var palletModel = stockDetail.Where(w => locatListWai.Contains(w.LocatNo)).OrderByDescending(w => w.UpdateTime).FirstOrDefault();
+                var palletModel = stockDetail.Where(w => locatListWai.Contains(w.LocatNo) && w.Status == "0").OrderByDescending(w => w.UpdateTime).FirstOrDefault();
                 if (palletModel == null)
                 {
                     //鎵鹃渶瑕佺Щ搴撶殑妗�
@@ -383,16 +394,12 @@
                         }
                         else//澶辫触
                         {
-                            logTaskEntry.IsSuccess = 0;
-                            logTaskEntry.Information = agvMsg;
-                            Db.Updateable(logTaskEntry).ExecuteCommand();
+                            throw new Exception("妗跺彿锛�"+ task.Pallno + ",璋冨害灏忚溅澶辫触");
                         }
                     }
                     else 
                     {
-                        logTaskEntry.IsSuccess = 0;
-                        logTaskEntry.Information = "璐ф灦涓庤揣浣嶇粦瀹氬け璐ワ紝鍘熷洜锛�"+agvBindMsg;
-                        Db.Updateable(logTaskEntry).ExecuteCommand();
+                        throw new Exception("妗跺彿锛�" + task.Pallno + ",缁戝畾璐т綅澶辫触");
                     }
                    
                 }
@@ -428,6 +435,11 @@
                 if (string.IsNullOrWhiteSpace(areaNo) || string.IsNullOrWhiteSpace(StartLocate) || string.IsNullOrWhiteSpace(plnStatus))
                 {
                     throw new Exception("鍖哄煙/璧峰浣�/妗剁被鍨嬩笉鑳戒负绌�");
+                }
+
+                if (weight < 0)
+                {
+                    throw new Exception("閲嶉噺搴斾笉灏忎簬0");
                 }
 
                 //if (plnStatus == "0" && string.IsNullOrWhiteSpace(standard))
@@ -506,7 +518,7 @@
                         BitPalletMark = "0",
                         InspectStatus = "1",
                     };
-                    Db.Insertable(stockDetailNew).ExecuteCommand();
+                    Db.Updateable(stockDetailNew).ExecuteCommand();
                 }
                 else
                 {
@@ -586,17 +598,13 @@
                     }
                     else//澶辫触
                     {
-                        logTaskEntry.IsSuccess = 0;
-                        logTaskEntry.Information = agvMsg;
-                        Db.Insertable(logTaskEntry).ExecuteCommand();
+                        throw new Exception("妗跺彿锛�" + task.Pallno + ",璋冨害灏忚溅澶辫触");
                     }
 
                 }
                 else
                 {
-                    logTaskEntry.IsSuccess = 0;
-                    logTaskEntry.Information = "璐ф灦涓庤揣浣嶇粦瀹氬け璐ワ紝鍘熷洜锛�"+agvBindMsg;
-                    Db.Insertable(logTaskEntry).ExecuteCommand();
+                    throw new Exception("妗跺彿锛�" + task.Pallno + ",缁戝畾璐т綅澶辫触");
                 }
                 
 
@@ -619,7 +627,7 @@
         /// <param name="comeFrom"></param>
         /// <param name="userId"></param>
         /// <exception cref="Exception"></exception>
-        public void RCSFinishTask(string taskNo, string status, string comeFrom, int userId = 0)
+        public void RCSFinishTask(string taskNo, string locateNo, string status, string comeFrom, int userId = 0)
         {
             try
             {
@@ -659,7 +667,7 @@
                     return;
                 }
                 //搴撳瓨鏄庣粏
-                var stockDetail = Db.Queryable<DataStockDetail>().First(w => w.PalletNo == taskInfo.PalletNo);
+                var stockDetail = Db.Queryable<DataStockDetail>().First(w => w.PalletNo == taskInfo.PalletNo && w.IsDel=="0");
                 if (stockDetail == null)
                 {
                     throw new Exception($"妗跺簱瀛樹俊鎭笉瀛樺湪");
@@ -789,7 +797,7 @@
                                 break;
                             case "2002":
                                 deviceID = "1004";
-                                break;
+                                break;                               
                             default:
                                 throw new Exception("鍙噣妗剁偣浣嶅紓甯�");
                         }
@@ -829,7 +837,7 @@
 
                             //鍒ゆ柇褰撳墠娓呮礂鏈鸿澶囦笂鏈夊嚑涓剰妗讹紝status锛�2 姝e湪娓呮礂鐨勮剰妗讹紙鐘舵�佽Е鍙戝彉鏇翠负AGV鍙2涓剰妗舵椂瑙﹀彂锛�
                             int ztQty = Db.Queryable<DataStockDetail>().Count(w => w.IsDel == "0" && w.Status == "2" && w.LocatNo == deviceID);
-                            if (ztQty == 1)
+                            if (ztQty == 2)
                             {
                                 throw new Exception((deviceID == "1001"?"1":"2") + "鍙锋竻娲楁満鑴忔《宸叉弧锛岄噸澶嶅彨鏂欙紒");
                             }
@@ -866,6 +874,14 @@
                             {
                                 throw new Exception($"璧峰鐩爣鍌ㄤ綅淇℃伅涓嶅瓨鍦紝妗跺彿锛歿palletModel.LocatNo}");
                             }
+                            //璧峰妗朵俊鎭�
+                            var startDataDetil = Db.Queryable<DataStockDetail>().First(w => w.IsDel == "0" && w.Status == "0" && w.PalletStatus == "3");
+                            if (startDataDetil == null)
+                            {
+                                throw new Exception($"娓呮礂鏈烘墍鍙殑妗剁姸鎬侀敊璇紝妗跺彿锛歿palletModel.LocatNo}");
+                            }
+                            startDataDetil.Status = "4";
+                            Db.Updateable(startDataDetil).ExecuteCommand();
                         }
                         else
                         {
@@ -891,7 +907,7 @@
                             {
                                 palletModel.LocatNo = startLoction.LocatNo;
                                 palletModel.PalletStatus = "0";
-                                palletModel.Status = "0";
+                                palletModel.Status = "4";
                                 Db.Updateable(palletModel).ExecuteCommand();
                             }
                             //鍒嗛厤鍌ㄤ綅
@@ -903,13 +919,13 @@
                                 throw new Exception("娌℃湁绌轰綑鐨勫噣妗跺偍浣�");
                             }
                             //浼樺厛鍒嗛厤鍥涙ゼ涓棿绔欏噣妗跺尯
-                            //endLoction = jtLocate.Where(w => w.WareHouseNo == "M01" && w.AreaNo == "C01")
-                            //                    .OrderBy(w => w.Row).OrderByDescending(w => w.Column).FirstOrDefault();
-                            //if (endLoction == null)//鍥涙ゼ涓棿绔欏噣妗跺尯娌℃湁绌哄偍浣嶏紝鍐嶄粠涓夋ゼ涓棿绔欏噣妗跺尯鏌ユ壘
-                            //{
+                            endLoction = jtLocate.Where(w => w.WareHouseNo == "M01" && w.AreaNo == "C01")
+                                                .OrderBy(w => w.Row).OrderByDescending(w => w.Column).FirstOrDefault();
+                            if (endLoction == null)//鍥涙ゼ涓棿绔欏噣妗跺尯娌℃湁绌哄偍浣嶏紝鍐嶄粠涓夋ゼ涓棿绔欏噣妗跺尯鏌ユ壘
+                            {
                             endLoction = jtLocate.Where(w => w.WareHouseNo == "M16" && w.AreaNo == "C24")
                                                 .OrderBy(w => w.Row).OrderByDescending(w => w.Column).FirstOrDefault();
-                            //}
+                            }
                             if (endLoction == null)//涓夋ゼ涓棿绔欏噣妗跺尯娌℃湁绌哄偍浣嶏紝鍐嶄粠涓夋ゼ娓呮礂闂寸紦瀛樺尯鏌ユ壘             PS锛氬皬杞︾幇鍦ㄨ繕涓嶆敮鎸佹竻娲楁満鐩存帴閫佸線4妤煎噣妗跺尯
                             {
                                 endLoction = jtLocate.Where(w => w.WareHouseNo == "M44" && w.AreaNo == "C55")
@@ -996,16 +1012,12 @@
                     }
                     else//澶辫触
                     {
-                        logTaskEntry.IsSuccess = 0;
-                        logTaskEntry.Information = agvMsg;
-                        Db.Updateable(logTaskEntry).ExecuteCommand();
+                        throw new Exception("妗跺彿锛�" + task.Pallno + ",璋冨害灏忚溅澶辫触");
                     }
                 }
                 else
                 {
-                    logTaskEntry.IsSuccess = 0;
-                    logTaskEntry.Information = agvBindMsg;
-                    Db.Updateable(logTaskEntry).ExecuteCommand();
+                    throw new Exception("妗跺彿锛�" + task.Pallno + ",缁戝畾璐т綅澶辫触");
                 }
                 
                 //鎻愪氦浜嬪姟
@@ -1046,6 +1058,8 @@
                 //鍒ゆ柇璇ュ偍浣嶆槸鍚︽槸鍐呬晶鍌ㄤ綅
                 if (!string.IsNullOrEmpty(locatInfo.AisleOne))
                 {
+                    ////鑾峰彇褰撳墠搴撲綅鐨勫渚у偍浣嶄俊鎭�
+                    //var waiLocatInfo = Db.Queryable<SysStorageLocat>().First(w=>w.IsDel == "0" && w.Row == locatInfo.Row && w.Column == locatInfo.Column - 1);
                     //鍒ゆ柇澶栦晶鍌ㄤ綅鏄惁鏈夋《
                     var palletInfoYi = Db.Queryable<DataStockDetail>().First(w => w.IsDel == "0" && w.LocatNo == locatInfo.AisleOne);
                     if (palletInfoYi != null)
@@ -1125,7 +1139,7 @@
                                 //logTaskEntry.IsCancel = 0;
                                 logTaskEntry.BackDate = DateTime.Now;
                                 logTaskEntry.Status = "1";//姝e湪鎵ц
-                                Db.Insertable(logTaskEntry).ExecuteCommand();
+                                Db.Updateable(logTaskEntry).ExecuteCommand();
 
                                 //淇敼绉诲嚭鍌ㄤ綅鐘舵��
                                 locatInfo.Status = "5";//绉诲嚭涓�
@@ -1139,7 +1153,7 @@
                             {
                                 logTaskEntry.IsSuccess = 0;
                                 logTaskEntry.Information = agvMsg;
-                                Db.Insertable(logTaskEntry).ExecuteCommand();
+                                Db.Updateable(logTaskEntry).ExecuteCommand();
 
                                 throw new Exception($"缁欏皬杞︿笅鍙戠Щ搴撲换鍔″け璐ワ紝妗跺彿锛歿palletInfoYi.PalletNo}");
                             }
@@ -1148,7 +1162,7 @@
                         {
                             logTaskEntry.IsSuccess = 0;
                             logTaskEntry.Information = agvBindMsg;
-                            Db.Insertable(logTaskEntry).ExecuteCommand();
+                            Db.Updateable(logTaskEntry).ExecuteCommand();
 
                             throw new Exception($"缁欏皬杞︿笅鍙戠Щ搴撲换鍔″け璐ワ紝妗跺彿锛歿palletInfoYi.PalletNo}");
                         }
@@ -1239,7 +1253,7 @@
                             //logTaskEntry.IsCancel = 0;
                             logTaskInfoZ.BackDate = DateTime.Now;
                             logTaskInfoZ.Status = "1";//姝e湪鎵ц
-                            Db.Insertable(logTaskInfoZ).ExecuteCommand();
+                            Db.Updateable(logTaskInfoZ).ExecuteCommand();
 
                             //淇敼绉诲嚭鍌ㄤ綅鐘舵��
                             startLocatInfoZ.Status = "5";//绉诲嚭涓�
@@ -1253,7 +1267,7 @@
                         {
                             logTaskInfoZ.IsSuccess = 0;
                             logTaskInfoZ.Information = agvMsg;
-                            Db.Insertable(logTaskInfoZ).ExecuteCommand();
+                            Db.Updateable(logTaskInfoZ).ExecuteCommand();
 
                             throw new Exception($"缁欏皬杞︿笅鍙戠Щ搴撲换鍔″け璐ワ紝妗跺彿锛歿logTaskInfoZ.PalletNo}");
                         }
@@ -1262,7 +1276,7 @@
                     {
                         logTaskInfoZ.IsSuccess = 0;
                         logTaskInfoZ.Information = agvBindMsg;
-                        Db.Insertable(logTaskInfoZ).ExecuteCommand();
+                        Db.Updateable(logTaskInfoZ).ExecuteCommand();
 
                         throw new Exception($"缁欏皬杞︿笅鍙戠Щ搴撲换鍔″け璐ワ紝妗跺彿锛歿logTaskInfoZ.PalletNo}");
                     }
@@ -1371,7 +1385,7 @@
                                 //logTaskEntry.IsCancel = 0;
                                 logTaskEntry.BackDate = DateTime.Now;
                                 logTaskEntry.Status = "1";//姝e湪鎵ц
-                                Db.Insertable(logTaskEntry).ExecuteCommand();
+                                Db.Updateable(logTaskEntry).ExecuteCommand();
 
                                 //淇敼绉诲嚭鍌ㄤ綅鐘舵��
                                 locatModel.Status = "5";//绉诲嚭涓�
@@ -1385,7 +1399,7 @@
                             {
                                 logTaskEntry.IsSuccess = 0;
                                 logTaskEntry.Information = agvMsg;
-                                Db.Insertable(logTaskEntry).ExecuteCommand();
+                                Db.Updateable(logTaskEntry).ExecuteCommand();
 
                                 throw new Exception($"缁欏皬杞︿笅鍙戠Щ搴撲换鍔″け璐ワ紝妗跺彿锛歿detailInfo.PalletNo}");
                             }
@@ -1394,7 +1408,7 @@
                         {
                             logTaskEntry.IsSuccess = 0;
                             logTaskEntry.Information = agvBindMsg;
-                            Db.Insertable(logTaskEntry).ExecuteCommand();
+                            Db.Updateable(logTaskEntry).ExecuteCommand();
 
                             throw new Exception($"缁欏皬杞︿笅鍙戠Щ搴撲换鍔″け璐ワ紝妗跺彿锛歿detailInfo.PalletNo}");
                         }
@@ -1429,6 +1443,7 @@
                 string areaNo = string.Empty;
                 switch (palletStatus)
                 {
+
                     case "0"://鍑�妗�
                              //鏌ュ埌鍒板噣妗跺尯鍩熺紪鍙�
                         areaNo = Db.Queryable<SysStorageArea>().Where(w => w.IsDel == "0" && w.WareHouseNo == houseNo && w.Type == "0").Select(s => s.AreaNo).First();
@@ -1442,15 +1457,15 @@
                         if (zonghong == "M12" || zonghong == "M13")
                         {
                             //鍏堟煡鍒板悓鐗╂枡鐨勭粍
-                            string sql = $@"select Row from SysStorageLocat where LocatNo in(
+                            string sql = $@"select Row,AreaNo from SysStorageLocat where LocatNo in(
 	                                                select LocatNo from DataStockDetail where SkuNo='{skuNo}' and LotNo = '{lotNo}' and Standard='{standard}' 
                                                     and AreaNo in ('C02','C25')
-                                                ) group by Row";
+                                                ) group by Row,AreaNo";
+                            var RowList = Db.Ado.SqlQuery<TableMan>(sql).ToList();
 
-                            List<int> RowList = Db.Ado.SqlQuery<int>(sql).ToList();
                             foreach (var rowItem in RowList)
                             {
-                                endLocatInfo = Db.Queryable<SysStorageLocat>().Where(w => w.IsDel == "0" && w.Status == "0" && w.Flag == "0" && w.Row == rowItem)
+                                endLocatInfo = Db.Queryable<SysStorageLocat>().Where(w => w.IsDel == "0" && w.Status == "0" && w.Flag == "0" && w.Row == rowItem.Row && w.AreaNo == rowItem.AreaNo  && (w.WareHouseNo == "M01"||w.WareHouseNo == "M16"))
                                                .OrderByDescending(o => o.Column).First();
                                 if (endLocatInfo.LocatNo != null)
                                 {
@@ -1472,15 +1487,15 @@
                             areaNo = Db.Queryable<SysStorageArea>().Where(w => w.IsDel == "0" && w.WareHouseNo == houseNo && w.Type == "1").Select(s => s.AreaNo).First();
                             //鍒嗛厤鍌ㄤ綅
                             //鍏堟煡鍒板悓鐗╂枡鐨勭粍
-                            string sql = $@"select Row from SysStorageLocat where WareHouseNo='{houseNo}' and AreaNo='{areaNo}' and Status = '0' and LocatNo in(
+                            string sql = $@"select Row,AreaNo from SysStorageLocat where WareHouseNo='{houseNo}' and AreaNo='{areaNo}' and Status = '0' and LocatNo in(
 	                                                select LocatNo from DataStockDetail where SkuNo='{skuNo}' and LotNo = '{lotNo}' and Standard='{standard}' and WareHouseNo='{houseNo}' and AreaNo='{areaNo}' 
-                                                ) group by Row";
+                                                ) group by Row,AreaNo";
 
-                            List<int> RowList = Db.Ado.SqlQuery<int>(sql).ToList();
+                            var RowList = Db.Ado.SqlQuery<TableMan>(sql).ToList();
                             foreach (var rowItem in RowList)
                             {
                                 endLocatInfo = Db.Queryable<SysStorageLocat>().Where(w => w.IsDel == "0" && w.Status == "0" && w.Flag == "0"
-                                               && w.WareHouseNo == houseNo && w.AreaNo == areaNo && w.Row == rowItem)
+                                               && w.WareHouseNo == houseNo && w.AreaNo == areaNo && w.Row == rowItem.Row && w.AreaNo == rowItem.AreaNo && (w.WareHouseNo == "M01" || w.WareHouseNo == "M16"))
                                                .OrderByDescending(o => o.Column).First();
 
                                 if (endLocatInfo.LocatNo != null)
@@ -1508,13 +1523,13 @@
                         //鍒嗛厤鍌ㄤ綅
                         //鏂欐枟娓呮礂鏆傚瓨闂�
                         endLocatInfo = ztLocat.Where(w => w.AreaNo == "C54").FirstOrDefault();
-                        if (string.IsNullOrEmpty(endLocatInfo.LocatNo))
+                        if (endLocatInfo == null)
                         {
                             endLocatInfo = ztLocat.Where(w => w.AreaNo == "C26").FirstOrDefault();
-                            if (string.IsNullOrEmpty(endLocatInfo.LocatNo))
+                            if (endLocatInfo == null)
                             {
                                 endLocatInfo = ztLocat.Where(w => w.AreaNo == "C03").FirstOrDefault();
-                                if (string.IsNullOrEmpty(endLocatInfo.LocatNo))
+                                if (endLocatInfo == null)
                                 {
                                     throw new Exception("鏃犲彲鐢ㄨ剰妗跺簱浣�");
                                 }

--
Gitblit v1.8.0