From 71d1dcdf796f08fa01cbc2d3faab86eea28b295b Mon Sep 17 00:00:00 2001
From: zhaowc <526854230@qq.com>
Date: 星期三, 17 十二月 2025 08:59:03 +0800
Subject: [PATCH] 物料管理页面修改

---
 Wms/WMS.BLL/BllTransServer/RcsServer.cs |  231 +++++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 172 insertions(+), 59 deletions(-)

diff --git a/Wms/WMS.BLL/BllTransServer/RcsServer.cs b/Wms/WMS.BLL/BllTransServer/RcsServer.cs
index 0417f22..3744350 100644
--- a/Wms/WMS.BLL/BllTransServer/RcsServer.cs
+++ b/Wms/WMS.BLL/BllTransServer/RcsServer.cs
@@ -7,6 +7,8 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Numerics;
+using System.Reflection;
 using System.Security.Policy;
 using System.Text;
 using System.Threading.Tasks;
@@ -336,7 +338,7 @@
                                         //logTaskEntry2.IsCancel = 0;
                                         logTaskEntry2.BackDate = DateTime.Now;
                                         logTaskEntry2.Status = "1";
-                                        Db.Insertable(logTaskEntry2).ExecuteCommand();
+                                        Db.Updateable(logTaskEntry2).ExecuteCommand();
 
                                         startLoction2.Status = "3";//鍑哄簱涓�
                                         Db.Updateable(startLoction2).ExecuteCommand();
@@ -348,7 +350,7 @@
                                     {
                                         logTaskEntry2.IsSuccess = 0;
                                         logTaskEntry2.Information = agvMsg;
-                                        Db.Insertable(logTaskEntry2).ExecuteCommand();
+                                        Db.Updateable(logTaskEntry2).ExecuteCommand();
 
                                     }
                                     //鎻愪氦浜嬪姟
@@ -412,7 +414,7 @@
                         //logTaskEntry.IsCancel = 0;
                         logTaskEntry.BackDate = DateTime.Now;
                         logTaskEntry.Status = "1";//姝e湪鎵ц
-                        Db.Insertable(logTaskEntry).ExecuteCommand();
+                        Db.Updateable(logTaskEntry).ExecuteCommand();
 
                         startLoction.Status = "3";//鍑哄簱涓�
                         Db.Updateable(startLoction).ExecuteCommand();
@@ -424,7 +426,7 @@
                     {
                         logTaskEntry.IsSuccess = 0;
                         logTaskEntry.Information = agvMsg;
-                        Db.Insertable(logTaskEntry).ExecuteCommand();
+                        Db.Updateable(logTaskEntry).ExecuteCommand();
 
                     }
                     //鎻愪氦浜嬪姟
@@ -704,7 +706,7 @@
                         //logTaskEntry.IsCancel = 0;
                         logTaskEntry.BackDate = DateTime.Now;
                         logTaskEntry.Status = "1";//姝e湪鎵ц
-                        Db.Insertable(logTaskEntry).ExecuteCommand();
+                        Db.Updateable(logTaskEntry).ExecuteCommand();
 
                         deviceLocatInfo.Status = "3";//鍑哄簱涓�
                         Db.Updateable(deviceLocatInfo).ExecuteCommand();
@@ -716,7 +718,7 @@
                     {
                         logTaskEntry.IsSuccess = 0;
                         logTaskEntry.Information = agvMsg;
-                        Db.Insertable(logTaskEntry).ExecuteCommand();
+                        Db.Updateable(logTaskEntry).ExecuteCommand();
                     }
                     //鎻愪氦浜嬪姟
                     Db.CommitTran();
@@ -941,17 +943,12 @@
                     stockDetail.PalletStatus = "0";
                     stockDetail.Status = "0";//寰呭垎閰�
                 }
-                else if (endAreaInfo.Type == "1")//棰勬贩鍖�
-                {
-                    stockDetail.PalletStatus = "1";
-                    stockDetail.Status = "0";//寰呭垎閰�
-                }
-                else if (endAreaInfo.Type == "2")//鍗婃垚鍝佸尯
+                else if (endAreaInfo.Type == "1")//婊℃《
                 {
                     stockDetail.PalletStatus = "2";
                     stockDetail.Status = "0";//寰呭垎閰�
                 }
-                else if (endAreaInfo.Type == "3")//鑴忔《鍖�
+                else if (endAreaInfo.Type == "2")//鑴忔《鍖�
                 {
                     stockDetail.PalletStatus = "3";
                     stockDetail.LotNo = "";//鎵规
@@ -1055,7 +1052,7 @@
         /// <param name="taskNo"></param>
         /// <param name="userId"></param>
         /// <exception cref="Exception"></exception>
-        public void CancelTask(string taskNo, int userId)
+        public void CancelTask(string taskNo, string url, int userId)
         {
             try
             {
@@ -1066,6 +1063,20 @@
                 if (task == null)
                 {
                     throw new Exception("鏈煡璇㈠埌浠诲姟淇℃伅");
+                }
+                //鏍¢獙璧风偣鏄惁宸茬粡鐢熸垚浠诲姟
+                var taskHave = Db.Queryable<LogTask>().First(m => m.EndLocat == task.StartLocat && m.IsDel == "0" && (m.Status == "0"|| m.Status == "1"));
+                if (taskHave == null)
+                {
+                    var locateHave = Db.Queryable<SysStorageLocat>().First(m => m.LocatNo == task.StartLocat);
+                    if (locateHave.Status != "3")
+                    {
+                        throw new Exception("璧峰鍌ㄤ綅宸叉湁鍏朵粬鏂欐枟瀛樺湪锛屾棤娉曞彇娑堝綋鍓嶄换鍔★紒");
+                    }
+                }
+                else
+                {
+                    throw new Exception("璧峰鍌ㄤ綅宸叉湁浠诲姟鐢熸垚锛屾棤娉曞彇娑堝綋鍓嶄换鍔★紒");
                 }
                 //if (task.Status != "0")
                 //{
@@ -1097,21 +1108,28 @@
                 }
                 locatEnd.Status = "0"; //绌哄偍浣�
                 Db.Updateable(locatEnd).ExecuteCommand();
-
-                if (task.Type == "1")//鍑哄簱浠诲姟
+                
+                //淇敼搴撳瓨鏄庣粏
+                var stockDetail = Db.Queryable<DataStockDetail>().First(w => w.IsDel == "0" && w.PalletNo == task.PalletNo);
+                if (stockDetail == null)                                                                                                
                 {
-                    //淇敼搴撳瓨鏄庣粏
-                    var stockDetail = Db.Queryable<DataStockDetail>().First(w => w.IsDel == "0" && w.PalletNo == task.PalletNo && w.Status == "2");
-                    if (stockDetail == null)
-                    {
-                        throw new Exception("鏈煡璇㈠埌璇ユ《搴撳瓨淇℃伅,璇锋鏌�!");
-                    }
-                    stockDetail.Status = "0";//寰呭垎閰�
-                    Db.Updateable(stockDetail).ExecuteCommand();
+                    throw new Exception("鏈煡璇㈠埌璇ユ《搴撳瓨淇℃伅,璇锋鏌�!");
                 }
-                //娣诲姞鎿嶄綔鏃ュ織璁板綍
-                var k = new OperationCrServer().AddLogOperationCr("搴撳唴浣滀笟", "搴撳唴鏃ュ織", taskNo, "鍙栨秷", $"鐐瑰嚮鍙栨秷鎸夐挳銆佸彇娑堜簡浠诲姟鍙蜂负锛歿taskNo}鐨勪换鍔�", userId);
-                Db.CommitTran();
+                stockDetail.Status = "0";//寰呭垎閰�
+                Db.Updateable(stockDetail).ExecuteCommand();
+
+                string agvMsg = "";
+                bool t = CancleTaskForAgv(taskNo, url, out agvMsg);
+                if (t)
+                {
+                    //娣诲姞鎿嶄綔鏃ュ織璁板綍
+                    var k = new OperationCrServer().AddLogOperationCr("搴撳唴浣滀笟", "搴撳唴鏃ュ織", taskNo, "鍙栨秷", $"鐐瑰嚮鍙栨秷鎸夐挳銆佸彇娑堜簡浠诲姟鍙蜂负锛歿taskNo}鐨勪换鍔�", userId);
+                    Db.CommitTran();
+                }
+                else
+                {
+                    throw new Exception("涓嬪彂鍙栨秷灏忚溅浠诲姟澶辫触");
+                }
             }
             catch (Exception e)
             {
@@ -1125,7 +1143,7 @@
         /// <param name="taskNo"></param>
         /// <param name="userId"></param>
         /// <exception cref="Exception"></exception>
-        public void DownTask(string taskNo, int userId,string url)
+        public void DownTask(string taskNo, int userId,string url,string bindUrl)
         {
             try
             {
@@ -1142,7 +1160,7 @@
                     throw new Exception("鍙湁绛夊緟鎵ц鐨勪换鍔℃墠鍙墜鍔ㄤ笅鍙�");
                 }
                 //鏌ユ壘璇ユ《鏈夋病鏈夋鍦ㄦ墽琛岀殑浠诲姟
-                var tasking = Db.Queryable<LogTask>().First(w => w.IsDel == "0" && w.Status == "1" && w.PalletNo == logTaskEntry.PalletNo);
+                var tasking = Db.Queryable<LogTask>().First(w => w.IsDel == "0" && w.Status == "1"  && w.PalletNo == logTaskEntry.PalletNo);
                 if (tasking != null)
                 {
                     throw new Exception($"璇ユ《鏈夋鍦ㄦ墽琛岀殑浠诲姟");
@@ -1153,20 +1171,20 @@
                 {
                     throw new Exception($"鏈煡璇㈠埌璧峰鍌ㄤ綅淇℃伅");
                 }
-                if (startLocatInfo.Status != "1")
-                {
-                    throw new Exception($"璧峰鍌ㄤ綅鐘舵�佸紓甯�");
-                }
+                //if (startLocatInfo.Status != "1")
+                //{
+                //    throw new Exception($"璧峰鍌ㄤ綅鐘舵�佸紓甯�");
+                //}
                 //鐩爣鍌ㄤ綅淇℃伅
                 var endLocatInfo = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == logTaskEntry.EndLocat);
                 if (endLocatInfo == null)
                 {
                     throw new Exception($"鏈煡璇㈠埌鐩爣鍌ㄤ綅淇℃伅");
                 }
-                if (endLocatInfo.Status != "0")
-                {
-                    throw new Exception($"鐩爣鍌ㄤ綅鐘舵�佸紓甯�");
-                }
+                //if (endLocatInfo.Status != "0")
+                //{
+                //    throw new Exception($"鐩爣鍌ㄤ綅鐘舵�佸紓甯�");
+                //}
                 //缁勭粐缁欏皬杞︿笅鍙戜换鍔′俊鎭�
                 var task = new TaskDetial
                 {
@@ -1179,30 +1197,33 @@
                 string agvMsg = string.Empty;
                 //缁欎笅杞︿笅鍙戜换鍔�
                 logTaskEntry.SendDate = DateTime.Now;//鍙戦�佹椂闂�
-                var agvResult = CreateTaskForAgv(task, url, out agvMsg);
-                if (agvResult)//鎴愬姛
+                //鍏堢粰璐т綅缁戝畾杞藉叿
+                var bind = RcsHelper.BindPalletAndSite(logTaskEntry.PalletNo, logTaskEntry.StartLocat, bindUrl, out string agvBindMsg);
+                if (bind)
                 {
-                    //璇锋眰鎴愬姛淇敼浠诲姟琛ㄧ浉搴斿瓧娈电姸鎬�
-                    logTaskEntry.IsSuccess = 1;
-                    logTaskEntry.IsSend = 0;
-                    logTaskEntry.IsCancel = 0;
-                    logTaskEntry.BackDate = DateTime.Now;
-                    logTaskEntry.Status = "1";//姝e湪鎵ц
-                    Db.Insertable(logTaskEntry).ExecuteCommand();
+                    var agvResult = CreateTaskForAgv(task, url, out agvMsg);
+                    if (agvResult)//鎴愬姛
+                    {
+                        //璇锋眰鎴愬姛淇敼浠诲姟琛ㄧ浉搴斿瓧娈电姸鎬�
+                        logTaskEntry.IsSuccess = 1;
+                        logTaskEntry.IsSend = 1;
+                        logTaskEntry.IsCancel = 1;
+                        logTaskEntry.BackDate = DateTime.Now;
+                        Db.Updateable(logTaskEntry).ExecuteCommand();
 
-                    startLocatInfo.Status = "3";//鍑哄簱涓�
-                    Db.Updateable(startLocatInfo).ExecuteCommand();
+                        startLocatInfo.Status = "3";//鍑哄簱涓�
+                        Db.Updateable(startLocatInfo).ExecuteCommand();
 
-                    endLocatInfo.Status = "2";//鍏ュ簱涓�
-                    Db.Updateable(endLocatInfo).ExecuteCommand();
+                        endLocatInfo.Status = "2";//鍏ュ簱涓�
+                        Db.Updateable(endLocatInfo).ExecuteCommand();
+                    }
+                    else//澶辫触
+                    {
+                        logTaskEntry.IsSuccess = 0;
+                        logTaskEntry.Information = agvMsg;
+                        Db.Updateable(logTaskEntry).ExecuteCommand();
+                    }
                 }
-                else//澶辫触
-                {
-                    logTaskEntry.IsSuccess = 0;
-                    logTaskEntry.Information = agvMsg;
-                    Db.Insertable(logTaskEntry).ExecuteCommand();
-                }
-
                 //娣诲姞鎿嶄綔鏃ュ織璁板綍
                 var k = new OperationCrServer().AddLogOperationCr("搴撳唴浣滀笟", "搴撳唴鏃ュ織", taskNo, "涓嬪彂", $"鐐瑰嚮涓嬪彂鎸夐挳銆佷换鍔″彿涓猴細{taskNo}鐨勪换鍔�", userId);
                 Db.CommitTran();
@@ -1322,6 +1343,43 @@
                 var logStr = $@".\log\AGV\AGV{logMsg}" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
                 LogFile.SaveLogToFile($"AGV{logMsg}寮傚父锛�( {agvModel.Message} ),", logStr);
 
+                agvMsg = agvModel.Message;
+            }
+            return result;
+            #endregion
+        }
+
+        /// <summary>
+        /// 涓嬪彂鍙栨秷浠诲姟缁橝GV
+        /// </summary>
+        /// <param name="req"></param>
+        /// <returns></returns>
+        public bool CancleTaskForAgv(string taskno, string url, out string agvMsg, string priority = null)
+        {
+            bool result = false;
+            #region 鍛煎彨灏忚溅浠g爜
+            AgvCancelTask cancelTask = new AgvCancelTask();
+            cancelTask.robotTaskCode = taskno;
+            cancelTask.cancelType = "DROP";
+
+            // 姝e紡杩愯绋嬪簭鏀惧紑
+            //AGV浠诲姟涓嬪彂鏃跺鍔爃earder:X-LR-REQUEST-ID,鍊间负闅忔満鏁�
+            long ran = DateTime.Now.Ticks;
+            Dictionary<string, string> key = new Dictionary<string, string>();
+            key.Add("X-LR-REQUEST-ID", ran.ToString());
+            var jsonData = JsonConvert.SerializeObject(cancelTask);
+            string response = HttpHelper.DoPost(url, jsonData, "涓嬪彂缁橝GV杞繍鍛戒护", "AGV", key);
+            //瑙f瀽杩斿洖鏁版嵁 
+            var agvModel = JsonConvert.DeserializeObject<OutCommanAgvDto>(response);
+            if (agvModel.Code == "SUCCESS")
+            {
+                result = true;//缁欎笅杞︿笅鍙戜换鍔℃垚鍔�
+                agvMsg = "";
+            }
+            else
+            {
+                var logStr = $@".\log\AGV\AGV鍙栨秷浠诲姟" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
+                LogFile.SaveLogToFile($"AGV鍙栨秷浠诲姟寮傚父锛�( {agvModel.Message} ),", logStr);
                 agvMsg = agvModel.Message;
             }
             return result;
@@ -1460,7 +1518,7 @@
                             //logTaskEntry.IsCancel = 0;
                             logTaskEntry.BackDate = DateTime.Now;
                             logTaskEntry.Status = "1";//姝e湪鎵ц
-                            Db.Insertable(logTaskEntry).ExecuteCommand();
+                            Db.Updateable(logTaskEntry).ExecuteCommand();
 
 
                             locatInfo.Status = "5";//绉诲嚭涓�
@@ -1473,7 +1531,7 @@
                         {
                             logTaskEntry.IsSuccess = 0;
                             logTaskEntry.Information = agvMsg;
-                            Db.Insertable(logTaskEntry).ExecuteCommand();
+                            Db.Updateable(logTaskEntry).ExecuteCommand();
 
                             throw new Exception($"缁欏皬杞︿笅鍙戠Щ搴撲换鍔″け璐ワ紝妗跺彿锛歿palletInfoYi.PalletNo}");
                         }
@@ -1486,5 +1544,60 @@
                 throw new Exception(e.Message);
             }
         }
+
+        public bool DelStockWms(int stockId,string url,int userId,out string errMsg)
+        {
+            try
+            {
+                errMsg = "";
+                //鑾峰彇褰撳墠搴撳瓨淇℃伅
+                var stock = Db.Queryable<DataStockDetail>().First(w => w.IsDel == "0" && w.Id == stockId);
+                if (stock == null)
+                {
+                    throw new Exception("鏈湪搴撳瓨涓壘鍒板綋鍓嶆枡妗�");
+                }
+                //鑾峰彇褰撳墠鏂欐枟浠诲姟淇℃伅
+                var taskInfo = Db.Queryable<LogTask>().First(w => w.IsDel == "0" && w.PalletNo == stock.PalletNo && (w.Status == "0" || w.Status == "1"));
+                if (taskInfo != null)
+                {
+                    throw new Exception("褰撳墠鏂欐《鏈夌瓑寰呮墽琛屾垨姝e湪鎵ц鐨勪换鍔�");
+                }
+                //鑾峰彇褰撳墠鏂欐枟鍌ㄤ綅鐘舵��
+                var locatInfo = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == stock.LocatNo && w.Status == "1");
+                if (locatInfo == null)
+                {
+                    throw new Exception("褰撳墠鏂欐《鍌ㄤ綅鐘舵�侀敊璇�");
+                }
+                var pallnoInfo = Db.Queryable<SysPallets>().First(w => w.IsDel == "0" && w.PalletNo == stock.PalletNo);
+                if (pallnoInfo == null)
+                {
+                    throw new Exception("鏈壘鍒板綋鍓嶆枡妗舵潯鐮�");
+                }
+                Db.BeginTran();
+                //涓嬪彂缁橝GV瑙g粦淇℃伅
+                bool t = RcsHelper.UnBindPalletAndSite(stock.PalletNo, stock.LocatNo, url,out errMsg);
+                if (t)
+                {
+                    //鍒犻櫎搴撳瓨
+                    Db.Deleteable(stock).ExecuteCommand();
+                    Db.Deleteable(pallnoInfo).ExecuteCommand();
+                    locatInfo.Status = "0";
+                    Db.Updateable(locatInfo).ExecuteCommand();
+
+                    
+                    //娣诲姞鎿嶄綔鏃ュ織璁板綍
+                    var k = new OperationCrServer().AddLogOperationCr("缁熻鎶ヨ〃", "妗舵槑缁�", "", "鍒犻櫎", $"鐐瑰嚮鍒犻櫎鎸夐挳銆佸垹闄や簡妗跺彿锛歿stock.PalletNo}", userId);
+                }
+                Db.CommitTran();
+                return t;
+            }
+            catch (Exception e)
+            {
+
+                Db.RollbackTran();
+                throw new Exception(e.Message);
+            }
+            
+        }
     }
 }

--
Gitblit v1.8.0