From ba48b2f2d203b4c43d6b475abb5993f12ef13f29 Mon Sep 17 00:00:00 2001
From: wxw <Administrator@DESKTOP-5BIMHQ3>
Date: 星期日, 15 十二月 2024 09:55:59 +0800
Subject: [PATCH] 修改问题

---
 Wms/WMS.BLL/BllTransServer/RcsServer.cs      |  419 ++++++++++++++++++++++++++-----------
 Wms/Model/InterFaceModel/RCSModel.cs         |    7 
 Wms/WMS.IBLL/IBllTransServer/IRcsServer.cs   |   18 +
 HTML/views/HouseWithinSetting/CRLogTask.html |   12 
 Wms/Wms/Controllers/BllCheckController.cs    |    8 
 Wms/Wms/Controllers/DownApiController.cs     |  147 ++++++++----
 6 files changed, 417 insertions(+), 194 deletions(-)

diff --git a/HTML/views/HouseWithinSetting/CRLogTask.html b/HTML/views/HouseWithinSetting/CRLogTask.html
index 26d6a65..27d537a 100644
--- a/HTML/views/HouseWithinSetting/CRLogTask.html
+++ b/HTML/views/HouseWithinSetting/CRLogTask.html
@@ -646,10 +646,7 @@
 						var param = {
 							taskNo: data.TaskNo
 						};
-						var postUrl="/BllCheck/CancelCheckTask"
-						if(data.OrderType=='3'){
-							postUrl='/BllCheck/CancelMoveTask'
-						}
+						var postUrl='/DownApi/CancelAgvTaskWms'
 						sendData(IP + postUrl, param, 'post', function (res) {
 							console.log(res);
 							if (res.code == 0) { //鎴愬姛
@@ -676,10 +673,7 @@
 						var param = {
 							taskNo: data.TaskNo,
 						};
-						var postUrl="/BllCheck/FinishCheckTask"
-						if(data.OrderType=='3'){
-							postUrl='/BllCheck/FinishMoveTask'
-						}
+						var postUrl='/DownApi/FinshAgvTaskWms'
 						sendData(IP + postUrl, param, 'post', function (res) {
 							console.log(res);
 							if (res.code == 0) { //鎴愬姛
@@ -706,7 +700,7 @@
 						var param = {
 							taskNo: data.TaskNo
 						};
-						sendData(IP + "/DownApi/AgainSendCheckTask", param, 'get', function (res) {
+						sendData(IP + "/DownApi/SendAgvTaskWms", param, 'post', function (res) {
 							console.log(res);
 							if (res.code == 0) { //鎴愬姛
 								layer.msg(res.msg, {
diff --git a/Wms/Model/InterFaceModel/RCSModel.cs b/Wms/Model/InterFaceModel/RCSModel.cs
index 8b71478..2df3ff8 100644
--- a/Wms/Model/InterFaceModel/RCSModel.cs
+++ b/Wms/Model/InterFaceModel/RCSModel.cs
@@ -66,19 +66,12 @@
             public string Endport { get; set; }
 
             public string Pallno { get; set; }
-
-            public string Type { get; set; }
             /// <summary>
             /// 浠诲姟绫诲瀷 
             /// 0锛氱敵璇峰偍浣�
             /// 1锛氬彨妗�
             /// </summary>
             public string Crtype { get; set; }
-            /// <summary>
-            /// 搴撳瓨鍗曟嵁ID 
-            /// </summary>
-            public int? Noticedetailno { get; set; }
-            public string LotNo { get; set; }
         }
     }
 }
diff --git a/Wms/WMS.BLL/BllTransServer/RcsServer.cs b/Wms/WMS.BLL/BllTransServer/RcsServer.cs
index 0f0c2f1..7d54d41 100644
--- a/Wms/WMS.BLL/BllTransServer/RcsServer.cs
+++ b/Wms/WMS.BLL/BllTransServer/RcsServer.cs
@@ -1,5 +1,7 @@
 锘縰sing Model.InterFaceModel;
 using Model.ModelDto;
+using Model.ModelDto.DataDto;
+using Model.ModelDto.LogDto;
 using Newtonsoft.Json;
 using SqlSugar;
 using System;
@@ -9,6 +11,7 @@
 using System.Text;
 using System.Threading.Tasks;
 using Utility.Tools;
+using WMS.BLL.LogServer;
 using WMS.DAL;
 using WMS.Entity.BllAsnEntity;
 using WMS.Entity.BllSoEntity;
@@ -18,6 +21,7 @@
 using WMS.Entity.SysEntity;
 using WMS.IBLL.IBllTransServer;
 using static Model.InterFaceModel.RCSModel;
+using static System.Collections.Specialized.BitVector32;
 
 namespace WMS.BLL.BllTransServer
 {
@@ -203,7 +207,7 @@
                                 IsCancel = 1,//鏄惁鍙彇娑�
                                 IsFinish = 1,//鏄惁鍙畬鎴�
                                 Type = "1",//浠诲姟绫诲瀷 0 鍏ュ簱浠诲姟 1 鍑哄簱浠诲姟  2 绉诲簱浠诲姟
-                                OrderType = "3",//鍗曟嵁绫诲瀷 0 鍏ュ簱 1 鍑哄簱 3鍏朵粬
+                                OrderType = "3",//鍗曟嵁绫诲瀷 0 鍏ュ簱 1 鍑哄簱 3 绉诲簱
                                 Status = "0",//浠诲姟鐘舵��0锛氱瓑寰呮墽琛�1姝e湪鎵ц2鎵ц瀹屾垚
                                 NoticeDetailNo = int.Parse(noticeNo),
                                 Msg = taskMsg, //鍏抽敭淇℃伅
@@ -215,18 +219,17 @@
                                 Startport = item.LocatNo,
                                 Endport = model.Location,
                                 Pallno = item.PalletNo,
-                                Type = model.Type,
-                                Crtype = "1",
-                                Noticedetailno = int.Parse(noticeNo),
+                                Crtype = "1",//鍙《
                             };
-                            CreateLotTask(task2, url);
                             //缁欎笅杞︿笅鍙戜换鍔�
                             logTaskEntry2.SendDate = DateTime.Now;//鍙戦�佹椂闂�
-                            var agvResult2 = CreateLotTask(task2, url);
+                            var agvResult2 = CreateTaskForAgv(task2, url);
                             if (agvResult2)//鎴愬姛
                             {
                                 //璇锋眰鎴愬姛淇敼浠诲姟琛ㄧ浉搴斿瓧娈电姸鎬�
                                 logTaskEntry2.IsSuccess = 1;
+                                logTaskEntry2.IsSend = 0;
+                                logTaskEntry2.IsCancel = 0;
                                 logTaskEntry2.BackDate = DateTime.Now;
                                 logTaskEntry2.Status = "1";
                                 Db.Insertable(logTaskEntry2).ExecuteCommand();
@@ -277,7 +280,7 @@
                     IsCancel = 1,//鏄惁鍙彇娑�
                     IsFinish = 1,//鏄惁鍙畬鎴�
                     Type = "1",//浠诲姟绫诲瀷 0 鍏ュ簱浠诲姟 1 鍑哄簱浠诲姟  2 绉诲簱浠诲姟
-                    OrderType = "3",//鍗曟嵁绫诲瀷 0 鍏ュ簱 1 鍑哄簱 3鍏朵粬
+                    OrderType = "3",//鍗曟嵁绫诲瀷 0 鍏ュ簱 1 鍑哄簱 3绉诲簱
                     Status = "0",//浠诲姟鐘舵��0锛氱瓑寰呮墽琛�1姝e湪鎵ц2鎵ц瀹屾垚
                     NoticeDetailNo = int.Parse(noticeNo),
                     Msg = taskMsg, //鍏抽敭淇℃伅
@@ -291,18 +294,18 @@
                     Endport = model.Location,//鐩爣浣嶇疆
                     Pallno = pallet.PalletNo,//妗跺彿
                     Crtype = "1",//鍙《
-                    Noticedetailno = int.Parse(noticeNo),
-                    LotNo = model.LotNo,
                 };
                 //缁欎笅杞︿笅鍙戜换鍔�
                 logTaskEntry.SendDate = DateTime.Now;//鍙戦�佹椂闂�
-                var agvResult = CreateLotTask(task, url);
+                var agvResult = CreateTaskForAgv(task, url);
                 if (agvResult)//鎴愬姛
                 {
                     //璇锋眰鎴愬姛淇敼浠诲姟琛ㄧ浉搴斿瓧娈电姸鎬�
                     logTaskEntry.IsSuccess = 1;
+                    logTaskEntry.IsSend = 0;
+                    logTaskEntry.IsCancel = 0;
                     logTaskEntry.BackDate = DateTime.Now;
-                    logTaskEntry.Status = "1";
+                    logTaskEntry.Status = "1";//姝e湪鎵ц
                     Db.Insertable(logTaskEntry).ExecuteCommand();
 
                     startLoction.Status = "3";//鍑哄簱涓�
@@ -340,6 +343,12 @@
             try
             {
                 string taskMsg = "";
+                //鏌ユ壘璇ユ《鏈夋病鏈夋鍦ㄦ墽琛岀殑浠诲姟
+                var tasking = Db.Queryable<LogTask>().First(w => w.IsDel == "0" && w.Status == "1" && w.PalletNo == model.PalletNo);
+                if (tasking != null)
+                {
+                    throw new Exception($"璇ユ《鏈夋鍦ㄦ墽琛岀殑浠诲姟锛孭alletNo:{model.PalletNo}");
+                }
                 //璁惧鎵�鍦ㄥ偍浣嶄俊鎭紙璧峰鍌ㄤ綅锛�
                 var deviceLocatInfo = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == model.Location);
                 if (deviceLocatInfo == null)
@@ -455,7 +464,7 @@
                     IsCancel = 1,//鏄惁鍙彇娑�
                     IsFinish = 1,//鏄惁鍙畬鎴�
                     Type = "0",//浠诲姟绫诲瀷 0 鍏ュ簱浠诲姟 1 鍑哄簱浠诲姟  2 绉诲簱浠诲姟
-                    OrderType = "3",//鍗曟嵁绫诲瀷 0 鍏ュ簱 1 鍑哄簱 3鍏朵粬
+                    OrderType = "3",//鍗曟嵁绫诲瀷 0 鍏ュ簱 1 鍑哄簱 3 绉诲簱
                     Status = "0",//浠诲姟鐘舵��0锛氱瓑寰呮墽琛�1姝e湪鎵ц2鎵ц瀹屾垚
                     NoticeDetailNo = int.Parse(noticeno),
                     Msg = taskMsg, //鍏抽敭淇℃伅
@@ -466,20 +475,19 @@
                     Startport = model.Location,
                     Endport = loction.LocatNo,
                     Pallno = model.PalletNo,
-                    Type = model.Type,
                     Crtype = "0",//鍏ュ簱
-                    Noticedetailno = int.Parse(noticeno),
-                    LotNo = model.LotNo,
                 };
                 //缁欎笅杞︿笅鍙戜换鍔�
                 logTaskEntry.SendDate = DateTime.Now;//鍙戦�佹椂闂�
-                var agvResult = CreateLotTask(task, url);
+                var agvResult = CreateTaskForAgv(task, url);
                 if (agvResult)//鎴愬姛
                 {
                     //璇锋眰鎴愬姛淇敼浠诲姟琛ㄧ浉搴斿瓧娈电姸鎬�
                     logTaskEntry.IsSuccess = 1;
+                    logTaskEntry.IsSend = 0;
+                    logTaskEntry.IsCancel = 0;
                     logTaskEntry.BackDate = DateTime.Now;
-                    logTaskEntry.Status = "1";
+                    logTaskEntry.Status = "1";//姝e湪鎵ц
                     Db.Insertable(logTaskEntry).ExecuteCommand();
 
                     deviceLocatInfo.Status = "3";//鍑哄簱涓�
@@ -545,12 +553,10 @@
                         Startport = detail.LocatNo,
                         Endport = endLocat.LocatNo,
                         Pallno = PalletNo,
-                        Type = "3",
                         Crtype = "2",
-                        Noticedetailno = 0,
                     };
                     string taskNo = "";
-                    CreateLotTask(ztask, url);
+                    CreateTaskForAgv(ztask, url);
 
                     statrtLocat.Status = "3";//鍑哄簱涓�
                     //淇敼璧峰鍌ㄤ綅鐘舵��
@@ -589,13 +595,10 @@
                     Startport = detail.LocatNo,
                     Endport = pallnetmsg.Location,
                     Pallno = detail.PalletNo,
-                    Type = "3",
                     Crtype = "1",
-                    Noticedetailno = 0,
-                    LotNo = "",
                 };
                 string taskNo = "";
-                CreateLotTask(task,url);
+                CreateTaskForAgv(task,url);
             }
             catch (Exception ex)
             {
@@ -604,128 +607,37 @@
         }
 
         /// <summary>
-        /// 鐢熸垚浠诲姟鍗曞埌LogTask
-        /// </summary>
-        /// <param name="req"></param>
-        /// <returns></returns>
-        public bool CreateLotTask(TaskDetial taskDetial,string url)
-        {
-            bool result = false;
-
-            #region 鍛煎彨灏忚溅浠g爜
-            List<AgvSchedulingTask> agvTaskList = new List<AgvSchedulingTask>();
-
-            List<PositionCodePath> pahtList = new List<PositionCodePath>();
-            //璧峰浣嶇疆
-            PositionCodePath path1 = new PositionCodePath();
-            path1.positionCode = taskDetial.Startport;
-            if (taskDetial.Crtype == "1")//鍙《锛堟《鍑哄簱锛�
-            {
-                path1.type = "05";
-            }
-            else//鐢宠鍌ㄤ綅锛堟《鍏ュ簱锛�
-            {
-                path1.type = "05";
-            }
-            pahtList.Add(path1);
-
-            //鐩爣浣嶇疆
-            PositionCodePath path2 = new PositionCodePath();
-            path2.positionCode = taskDetial.Endport;
-            if (taskDetial.Crtype == "1")//鍙《锛堟《鍑哄簱锛�
-            {
-                path2.type = "05";
-            }
-            else//鐢宠鍌ㄤ綅锛堟《鍏ュ簱锛�
-            {
-                path2.type = "05";
-            }
-            pahtList.Add(path2);
-
-            //涓嬭溅浠诲姟鍗�
-            AgvSchedulingTask agvTask = new AgvSchedulingTask();
-            agvTask.reqCode = taskDetial.Taskno;//璇锋眰缂栧彿
-            agvTask.taskCode= taskDetial.Taskno;//浠诲姟鍙�
-            agvTask.ctnrCode = taskDetial.Pallno;//妗跺彿
-            agvTask.ctnrTyp = "1";
-            agvTask.reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");//璇锋眰鏃堕棿                
-            agvTask.wbCode = "";
-            agvTask.positionCodePath = pahtList;//灏忚溅璺緞
-            agvTask.podCode = "";
-            agvTask.userCallCode = "";//taskDetial.Endport;//鐩爣浣嶇疆
-            if (taskDetial.Crtype == "1")//鍙《锛堟《鍑哄簱锛�
-            {
-                agvTask.taskTyp = "Z3";//浠诲姟绫诲瀷 绾胯竟鍒版墭鐩樻敹闆嗗櫒 Z1锛� 鎵樼洏鍨涚敵璇峰叆搴� Z2
-            }
-            else//鐢宠鍌ㄤ綅锛堟《鍏ュ簱锛�
-            {
-                agvTask.taskTyp = "Z4";//浠诲姟绫诲瀷 绾胯竟鍒版墭鐩樻敹闆嗗櫒 Z1锛� 鎵樼洏鍨涚敵璇峰叆搴� Z2
-            }
-            agvTaskList.Add(agvTask);
-
-            // 姝e紡杩愯绋嬪簭鏀惧紑
-            var list2 = agvTaskList.Select(m => m.reqCode).ToList();
-            var jsonData = JsonConvert.SerializeObject(agvTaskList);
-            jsonData = jsonData.Substring(1);
-            jsonData = jsonData.Substring(0, jsonData.Length - 1);
-
-            string response = HttpHelper.DoPost(url, jsonData, "涓嬪彂缁橝GV杞繍鍛戒护", "AGV");
-            //瑙f瀽杩斿洖鏁版嵁 
-            var agvModel = JsonConvert.DeserializeObject<OutCommanAgvDto>(response);
-            if (agvModel.Code == "0")
-            {
-                result = true;//缁欎笅杞︿笅鍙戜换鍔℃垚鍔�
-            }
-            else
-            {
-                string logMsg = "";
-                if (taskDetial.Crtype == "1")//鍙《锛堟《鍑哄簱锛�
-                {
-                    logMsg = "鐢宠鍙《";
-                }
-                else if(taskDetial.Crtype == "0")//鐢宠鍌ㄤ綅锛堟《鍏ュ簱锛�
-                {
-                    logMsg = "鐢宠鍌ㄤ綅";
-                }
-                var logStr = $@".\log\AGV\AGV{logMsg}" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
-                LogFile.SaveLogToFile($"AGV{logMsg}寮傚父锛�( {agvModel.Message} ),", logStr);
-            }
-            return result;
-            #endregion
-        }
-
-        /// <summary>
         /// 浠诲姟瀹屾垚
         /// </summary>
         /// <param name="TaskNo"></param>
         /// <param name="Status"></param>
         /// <exception cref="Exception"></exception>
-        public void RCSFinishTask(string TaskNo, string Status)
+        public void RCSFinishTask(string taskNo, string status, string comeFrom, int userId = 0)
         {
             try
             {
                 #region 鏉′欢鍒ゆ柇
                 var resultModel = new ErpModel() { Success = -1, Message = "" };
-                if (string.IsNullOrEmpty(TaskNo))
+                if (string.IsNullOrEmpty(taskNo))
                 {
                     throw new Exception("浠诲姟鍙蜂笉鍙负绌�");
                 }
                 //浠诲姟淇℃伅
-                var taskInfo = Db.Queryable<LogTask>().First(w => w.TaskNo == TaskNo);
+                var taskInfo = Db.Queryable<LogTask>().First(w => w.TaskNo == taskNo);
                 if (taskInfo == null)
                 {
-                    throw new Exception($"浠诲姟鍙蜂负:{TaskNo}鐨勪换鍔′笉瀛樺湪!");
+                    throw new Exception($"浠诲姟鍙蜂负:{taskNo}鐨勪换鍔′笉瀛樺湪!");
                 }
-                if (taskInfo.Status != "1")
+                if (taskInfo.Status != "1" && comeFrom != "WMS")
                 {
-                    throw new Exception($"浠诲姟鍙蜂负:{TaskNo}鐨勪换鍔$姸鎬佸紓甯�");
+                    throw new Exception($"浠诲姟鍙蜂负:{taskNo}鐨勪换鍔$姸鎬佸紓甯�");
                 }
                 #endregion
                 //寮�鍚簨鍔�
                 Db.BeginTran();
                 var comTime = DateTime.Now;
 
-                if (Status == "0")
+                if (status == "0")
                 {
                     taskInfo.Status = "3";//寮傚父缁撴潫
                     //淇敼浠诲姟鐘舵��
@@ -776,7 +688,7 @@
                 stockDetail.RoadwayNo = endLocatInfo.RoadwayNo;//鎵�灞炲贩閬�
                 stockDetail.AreaNo = endLocatInfo.AreaNo;//鎵�灞炲尯鍩�
                 stockDetail.LocatNo = endLocatInfo.LocatNo;//鍌ㄤ綅鍦板潃               
-                if (endAreaInfo.Type=="0")//娲佸噣鍖�
+                if (endAreaInfo.Type == "0")//娲佸噣鍖�
                 {
                     stockDetail.PalletStatus = "0";
                     stockDetail.Status = "0";//寰呭垎閰�
@@ -803,7 +715,7 @@
                 //淇敼搴撳瓨鏄庣粏
                 Db.Updateable(stockDetail).ExecuteCommand();
                 //鍏ュ簱浠诲姟锛屽鐞嗗叆搴撳崟
-                if (taskInfo.Type == "0" && taskInfo.NoticeDetailNo!=0)
+                if (taskInfo.Type == "0" && taskInfo.NoticeDetailNo != 0)
                 {
                     var notice = Db.Queryable<BllArrivalNotice>().First(w => w.IsDel == "0" && w.Status == "1");
                     if (notice != null)
@@ -842,6 +754,11 @@
                 //淇敼浠诲姟鐘舵��
                 Db.Updateable(taskInfo).ExecuteCommand();
 
+                if (comeFrom == "WMS")
+                {
+                    //娣诲姞鎿嶄綔鏃ュ織璁板綍
+                    var k = new OperationCrServer().AddLogOperationCr("搴撳唴浣滀笟", "搴撳唴鏃ュ織", taskInfo.TaskNo, "瀹屾垚", $"鐐瑰嚮瀹屾垚鎸夐挳銆佷换鍔″彿涓猴細{taskInfo.TaskNo}鐨勪换鍔�", userId);
+                }
                 //鎻愪氦浜嬪姟
                 Db.CommitTran();
             }
@@ -852,5 +769,259 @@
                 throw new Exception(ex.Message);
             }
         }
+
+        /// <summary>
+        /// 鎵嬪姩鍙栨秷浠诲姟
+        /// </summary>
+        /// <param name="taskNo"></param>
+        /// <param name="userId"></param>
+        /// <exception cref="Exception"></exception>
+        public void CancelTask(string taskNo, int userId)
+        {
+            try
+            {
+                //寮�鍚簨鍔�
+                Db.BeginTran();
+                //浠诲姟淇℃伅
+                var task = Db.Queryable<LogTask>().First(m => m.TaskNo == taskNo && m.IsDel == "0");
+                if (task == null)
+                {
+                    throw new Exception("鏈煡璇㈠埌浠诲姟淇℃伅");
+                }
+                if (task.Status != "0")
+                {
+                    throw new Exception("鍙湁绛夊緟鎵ц鐨勪换鍔℃墠鍙彇娑�");
+                }
+                //淇敼浠诲姟 
+                task.IsSuccess = 0;
+                task.IsSend = 0;
+                task.IsCancel = 0;
+                task.IsFinish = 0;
+                task.Status = "4";//宸插彇娑�
+                task.CancelDate = DateTime.Now;
+                Db.Updateable(task).ExecuteCommand();
+
+                //淇敼璧峰鍌ㄤ綅淇℃伅
+                var locat = Db.Queryable<SysStorageLocat>().First(a => a.IsDel == "0" && a.LocatNo == task.StartLocat && a.Status == "3");//鍑哄簱涓�
+                if (locat == null)
+                {
+                    throw new Exception("鏈煡璇㈠埌璧峰浣嶇疆鍌ㄤ綅淇℃伅锛岃鏍稿疄锛�");
+                }
+                locat.Status = "1"; //鏈夌墿鍝�
+                Db.Updateable(locat).ExecuteCommand();
+
+                //淇敼鐩爣鍌ㄤ綅淇℃伅
+                var locatEnd = Db.Queryable<SysStorageLocat>().First(a => a.IsDel == "0" && a.LocatNo == task.EndLocat && a.Status == "2");//鍏ュ簱涓�
+                if (locatEnd == null)
+                {
+                    throw new Exception("鏈煡璇㈠埌鐩爣浣嶇疆鍌ㄤ綅淇℃伅锛岃鏍稿疄锛�");                    
+                }
+                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 && w.Status == "2");
+                    if (stockDetail == null)
+                    {
+                        throw new Exception("鏈煡璇㈠埌璇ユ《搴撳瓨淇℃伅,璇锋鏌�!");
+                    }
+                    stockDetail.Status = "0";//寰呭垎閰�
+                    Db.Updateable(stockDetail).ExecuteCommand();
+                }
+                //娣诲姞鎿嶄綔鏃ュ織璁板綍
+                var k = new OperationCrServer().AddLogOperationCr("搴撳唴浣滀笟", "搴撳唴鏃ュ織", taskNo, "鍙栨秷", $"鐐瑰嚮鍙栨秷鎸夐挳銆佸彇娑堜簡浠诲姟鍙蜂负锛歿taskNo}鐨勪换鍔�", userId);
+                Db.CommitTran();
+            }
+            catch (Exception e)
+            {
+                Db.RollbackTran();
+                throw new Exception(e.Message);
+            }
+        }
+        /// <summary>
+        /// 鎵嬪姩涓嬪彂浠诲姟
+        /// </summary>
+        /// <param name="taskNo"></param>
+        /// <param name="userId"></param>
+        /// <exception cref="Exception"></exception>
+        public void DownTask(string taskNo, int userId,string url)
+        {
+            try
+            {
+                //寮�鍚簨鍔�
+                Db.BeginTran();
+                //浠诲姟淇℃伅
+                var logTaskEntry = Db.Queryable<LogTask>().First(m => m.TaskNo == taskNo && m.IsDel == "0");
+                if (logTaskEntry == null)
+                {
+                    throw new Exception("鏈煡璇㈠埌浠诲姟淇℃伅");
+                }
+                if (logTaskEntry.Status != "0")
+                {
+                    throw new Exception("鍙湁绛夊緟鎵ц鐨勪换鍔℃墠鍙墜鍔ㄤ笅鍙�");
+                }
+                //鏌ユ壘璇ユ《鏈夋病鏈夋鍦ㄦ墽琛岀殑浠诲姟
+                var tasking = Db.Queryable<LogTask>().First(w => w.IsDel == "0" && w.Status == "1" && w.PalletNo == logTaskEntry.PalletNo);
+                if (tasking != null)
+                {
+                    throw new Exception($"璇ユ《鏈夋鍦ㄦ墽琛岀殑浠诲姟");
+                }
+                //璧峰鍌ㄤ綅淇℃伅
+                var startLocatInfo = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == logTaskEntry.StartLocat);
+                if (startLocatInfo == null)
+                {
+                    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($"鐩爣鍌ㄤ綅鐘舵�佸紓甯�");
+                }
+                //缁勭粐缁欏皬杞︿笅鍙戜换鍔′俊鎭�
+                var task = new TaskDetial
+                {
+                    Taskno = taskNo,//浠诲姟鍙�
+                    Startport = logTaskEntry.StartLocat,
+                    Endport = logTaskEntry.EndLocat,
+                    Pallno = logTaskEntry.PalletNo,
+                    Crtype = logTaskEntry.Type,
+                };
+                //缁欎笅杞︿笅鍙戜换鍔�
+                logTaskEntry.SendDate = DateTime.Now;//鍙戦�佹椂闂�
+                var agvResult = CreateTaskForAgv(task, url);
+                if (agvResult)//鎴愬姛
+                {
+                    //璇锋眰鎴愬姛淇敼浠诲姟琛ㄧ浉搴斿瓧娈电姸鎬�
+                    logTaskEntry.IsSuccess = 1;
+                    logTaskEntry.IsSend = 0;
+                    logTaskEntry.IsCancel = 0;
+                    logTaskEntry.BackDate = DateTime.Now;
+                    logTaskEntry.Status = "1";//姝e湪鎵ц
+                    Db.Insertable(logTaskEntry).ExecuteCommand();
+
+                    startLocatInfo.Status = "3";//鍑哄簱涓�
+                    Db.Updateable(startLocatInfo).ExecuteCommand();
+
+                    endLocatInfo.Status = "2";//鍏ュ簱涓�
+                    Db.Updateable(endLocatInfo).ExecuteCommand();
+                }
+                else//澶辫触
+                {
+                    logTaskEntry.IsSuccess = 0;
+                    Db.Insertable(logTaskEntry).ExecuteCommand();
+                }
+
+                //娣诲姞鎿嶄綔鏃ュ織璁板綍
+                var k = new OperationCrServer().AddLogOperationCr("搴撳唴浣滀笟", "搴撳唴鏃ュ織", taskNo, "涓嬪彂", $"鐐瑰嚮涓嬪彂鎸夐挳銆佷换鍔″彿涓猴細{taskNo}鐨勪换鍔�", userId);
+                Db.CommitTran();
+            }
+            catch (Exception e)
+            {
+                Db.RollbackTran();
+                throw new Exception(e.Message);
+            }
+        }
+
+        /// <summary>
+        /// 鐢熸垚浠诲姟鍗曞埌LogTask
+        /// </summary>
+        /// <param name="req"></param>
+        /// <returns></returns>
+        public bool CreateTaskForAgv(TaskDetial taskDetial, string url)
+        {
+            bool result = false;
+
+            #region 鍛煎彨灏忚溅浠g爜
+            List<AgvSchedulingTask> agvTaskList = new List<AgvSchedulingTask>();
+
+            List<PositionCodePath> pahtList = new List<PositionCodePath>();
+            //璧峰浣嶇疆
+            PositionCodePath path1 = new PositionCodePath();
+            path1.positionCode = taskDetial.Startport;
+            if (taskDetial.Crtype == "1")//鍙《锛堟《鍑哄簱锛�
+            {
+                path1.type = "05";
+            }
+            else//鐢宠鍌ㄤ綅锛堟《鍏ュ簱锛�
+            {
+                path1.type = "05";
+            }
+            pahtList.Add(path1);
+
+            //鐩爣浣嶇疆
+            PositionCodePath path2 = new PositionCodePath();
+            path2.positionCode = taskDetial.Endport;
+            if (taskDetial.Crtype == "1")//鍙《锛堟《鍑哄簱锛�
+            {
+                path2.type = "05";
+            }
+            else//鐢宠鍌ㄤ綅锛堟《鍏ュ簱锛�
+            {
+                path2.type = "05";
+            }
+            pahtList.Add(path2);
+
+            //涓嬭溅浠诲姟鍗�
+            AgvSchedulingTask agvTask = new AgvSchedulingTask();
+            agvTask.reqCode = taskDetial.Taskno;//璇锋眰缂栧彿
+            agvTask.taskCode = taskDetial.Taskno;//浠诲姟鍙�
+            agvTask.ctnrCode = taskDetial.Pallno;//妗跺彿
+            agvTask.ctnrTyp = "1";
+            agvTask.reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");//璇锋眰鏃堕棿                
+            agvTask.wbCode = "";
+            agvTask.positionCodePath = pahtList;//灏忚溅璺緞
+            agvTask.podCode = "";
+            agvTask.userCallCode = "";//taskDetial.Endport;//鐩爣浣嶇疆
+            if (taskDetial.Crtype == "1")//鍙《锛堟《鍑哄簱锛�
+            {
+                agvTask.taskTyp = "Z3";//浠诲姟绫诲瀷 绾胯竟鍒版墭鐩樻敹闆嗗櫒 Z1锛� 鎵樼洏鍨涚敵璇峰叆搴� Z2
+            }
+            else//鐢宠鍌ㄤ綅锛堟《鍏ュ簱锛�
+            {
+                agvTask.taskTyp = "Z4";//浠诲姟绫诲瀷 绾胯竟鍒版墭鐩樻敹闆嗗櫒 Z1锛� 鎵樼洏鍨涚敵璇峰叆搴� Z2
+            }
+            agvTaskList.Add(agvTask);
+
+            // 姝e紡杩愯绋嬪簭鏀惧紑
+            var list2 = agvTaskList.Select(m => m.reqCode).ToList();
+            var jsonData = JsonConvert.SerializeObject(agvTaskList);
+            jsonData = jsonData.Substring(1);
+            jsonData = jsonData.Substring(0, jsonData.Length - 1);
+
+            string response = HttpHelper.DoPost(url, jsonData, "涓嬪彂缁橝GV杞繍鍛戒护", "AGV");
+            //瑙f瀽杩斿洖鏁版嵁 
+            var agvModel = JsonConvert.DeserializeObject<OutCommanAgvDto>(response);
+            if (agvModel.Code == "0")
+            {
+                result = true;//缁欎笅杞︿笅鍙戜换鍔℃垚鍔�
+            }
+            else
+            {
+                string logMsg = "";
+                if (taskDetial.Crtype == "1")//鍙《锛堟《鍑哄簱锛�
+                {
+                    logMsg = "鐢宠鍙《";
+                }
+                else if (taskDetial.Crtype == "0")//鐢宠鍌ㄤ綅锛堟《鍏ュ簱锛�
+                {
+                    logMsg = "鐢宠鍌ㄤ綅";
+                }
+                var logStr = $@".\log\AGV\AGV{logMsg}" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
+                LogFile.SaveLogToFile($"AGV{logMsg}寮傚父锛�( {agvModel.Message} ),", logStr);
+            }
+            return result;
+            #endregion
+        }
     }
 }
diff --git a/Wms/WMS.IBLL/IBllTransServer/IRcsServer.cs b/Wms/WMS.IBLL/IBllTransServer/IRcsServer.cs
index b892e4e..66235fe 100644
--- a/Wms/WMS.IBLL/IBllTransServer/IRcsServer.cs
+++ b/Wms/WMS.IBLL/IBllTransServer/IRcsServer.cs
@@ -41,6 +41,22 @@
         /// </summary>
         /// <param name="TaskNo"></param>
         /// <param name="Status"></param>
-        void RCSFinishTask(string TaskNo, string Status);
+        void RCSFinishTask(string taskNo, string status, string comeFrom, int userId = 0);
+
+        /// <summary>
+        /// 鎵嬪姩鍙栨秷浠诲姟
+        /// </summary>
+        /// <param name="taskNo"></param>
+        /// <param name="userId"></param>
+        /// <exception cref="Exception"></exception>
+        void CancelTask(string taskNo, int userId);
+
+        /// <summary>
+        /// 鎵嬪姩涓嬪彂浠诲姟
+        /// </summary>
+        /// <param name="taskNo"></param>
+        /// <param name="userId"></param>
+        /// <exception cref="Exception"></exception>
+        void DownTask(string taskNo, int userId, string url);
     }
 }
diff --git a/Wms/Wms/Controllers/BllCheckController.cs b/Wms/Wms/Controllers/BllCheckController.cs
index 27ff38b..05bce06 100644
--- a/Wms/Wms/Controllers/BllCheckController.cs
+++ b/Wms/Wms/Controllers/BllCheckController.cs
@@ -16,6 +16,7 @@
 using Model.ModelVm.BllSoVm;
 using Wms.Tools;
 using System.Collections;
+using WMS.IBLL.IBllTransServer;
 
 namespace Wms.Controllers
 {
@@ -34,6 +35,8 @@
         private readonly IWarehouseOutsidePalletsServer _stockPallet; //搴撳鎵樼洏
         private readonly IStockFreectSetve _freect; //瑙e喕\鍐荤粨
 
+        private readonly IRcsServer _rcsserver;//RCS鐩稿叧浠诲姟
+
         /// <summary>
         /// 鏋勯�犲嚱鏁�
         /// </summary>
@@ -43,7 +46,7 @@
         /// <param name="logSvc">搴撳唴鎿嶄綔鏃ュ織Svc</param>
         /// <param name="stockPallet">搴撳鎵樼洏</param>
         /// <param name="freect">瑙e喕\鍐荤粨</param>
-        public BllCheckController(IOptions<ApiUrlConfig> setting, IStockCheckServer stockCheckSvc, IStockCheckLogServer stockCheckLogSvc, ITaskServer taskSvc, IOperationCRServer logSvc, IWarehouseOutsidePalletsServer stockPallet, IStockFreectSetve freect)
+        public BllCheckController(IOptions<ApiUrlConfig> setting, IStockCheckServer stockCheckSvc, IStockCheckLogServer stockCheckLogSvc, ITaskServer taskSvc, IOperationCRServer logSvc, IWarehouseOutsidePalletsServer stockPallet, IStockFreectSetve freect, IRcsServer rcsserver)
         {
             _config = setting.Value;
             _stockCheckSvc = stockCheckSvc;
@@ -52,6 +55,7 @@
             _logSvc = logSvc;
             _stockPallet = stockPallet;
             _freect = freect;
+            _rcsserver = rcsserver;
         }
 
         #region 鐩樼偣鍗曟嵁
@@ -493,7 +497,7 @@
                 {
                     return Ok(new { code = 1, msg = "鏈幏鍙栧埌褰撳墠鎿嶄綔浜轰俊鎭�" });
                 }
-                _stockCheckSvc.CancelMoveTask(model.taskNo, int.Parse(userId));
+                _rcsserver.CancelTask(model.taskNo, int.Parse(userId));
 
                 return Ok(new { code = 0, msg = "鎴愬姛鍙栨秷浠诲姟", data = "" });
             }
diff --git a/Wms/Wms/Controllers/DownApiController.cs b/Wms/Wms/Controllers/DownApiController.cs
index c567d93..42bd8ac 100644
--- a/Wms/Wms/Controllers/DownApiController.cs
+++ b/Wms/Wms/Controllers/DownApiController.cs
@@ -20,6 +20,7 @@
 using WMS.IBLL.IBllTransServer;
 using Microsoft.Extensions.Logging;
 using ZXing.QrCode.Internal;
+using Model.ModelVm.BllCheckVm;
 
 namespace Wms.Controllers
 {
@@ -939,7 +940,7 @@
                 LogFile.SaveLogToFile($"AGV浠诲姟鎵ц閫氱煡-浠诲姟缁撴潫-璇锋眰鎶ユ枃锛�( {jsonData} ),", logStr);
 
                 //鍏蜂綋澶勭悊鏂规硶
-                _rcsserver.RCSFinishTask(model.taskCode, "1");
+                _rcsserver.RCSFinishTask(model.taskCode, "1", "AGV");
 
 
                 resultModel = new AgvResultModel { code = "0", message = "鎴愬姛", reqCode = model.reqCode };
@@ -994,56 +995,6 @@
         }        
 
         #endregion
-        /// <summary>
-        /// Agv浠诲姟瀹屾垚鍙嶉
-        /// </summary>
-        /// <param name="model"></param>
-        /// <returns></returns>
-        [HttpPost]
-        public IActionResult agvCallBack(AgvTaskDto model)
-        {
-            //璁板綍log
-            var logStr = $@".\log\AGV\浠诲姟鎵ц閫氱煡" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
-            AgvResultModel resultModel = null;
-            try
-            {                
-                var jsonData = JsonConvert.SerializeObject(model);
-                LogFile.SaveLogToFile($"浠诲姟鎵ц閫氱煡-璇锋眰鎶ユ枃锛�( {jsonData} ),", logStr);
-
-                if (string.IsNullOrEmpty(model.taskCode))
-                {
-                    resultModel = new AgvResultModel { code = "-1", message = "璇锋眰澶辫触锛宼askCode鍙傛暟寮傚父", reqCode = model.reqCode };
-                    var jsonData2 = JsonConvert.SerializeObject(resultModel);
-                    LogFile.SaveLogToFile($"浠诲姟鎵ц閫氱煡-杩斿洖鎶ユ枃锛�( {jsonData2} ),", logStr);
-                    return Ok(resultModel);
-                }
-                switch (model.method)
-                {
-                    case "start"://浠诲姟寮�濮�
-                        return Ok(new AgvResultModel { code = "0", message = "鎴愬姛", reqCode = model.reqCode });
-
-                    case "outbin"://璧板嚭鍌ㄤ綅
-                        return Ok(new AgvResultModel { code = "0", message = "鎴愬姛", reqCode = model.reqCode });
-
-                    case "end"://浠诲姟缁撴潫
-                        _rcsserver.RCSFinishTask(model.taskCode, "1");
-                        return Ok(new AgvResultModel { code = "0", message = "鎴愬姛", reqCode = model.reqCode });
-                    case "cancel"://浠诲姟鍗曞彇娑�
-                        return Ok(new AgvResultModel { code = "0", message = "鎴愬姛", reqCode = model.reqCode });
-
-                    case "apply"://CTU鏂欑鍙栨斁鐢宠
-                        return Ok(new AgvResultModel { code = "0", message = "鎴愬姛", reqCode = model.reqCode });
-
-                    default:
-                        return Ok(new AgvResultModel { code = "-1", message = "璇锋眰澶辫触锛宮ethod浠诲姟绫诲瀷閿欒", reqCode = model.reqCode });
-                }
-            }
-            catch (Exception ex)
-            {
-                LogFile.SaveLogToFile($"AGV浠诲姟鎵ц閫氱煡寮傚父锛�( {ex.Message} ),", logStr);
-                return Ok(new AgvResultModel { code = "-1", message = ex.Message, reqCode = model.reqCode });
-            }
-        }
 
         /// <summary>
         /// 鍑哄簱鍗曟嵁涓嬪彂
@@ -1076,6 +1027,100 @@
                 return Ok(new ErpModel { Success = -1, Message = e.Message });
             }
         }
+
+        /// <summary>
+        /// 鎵嬪姩涓嬪彂灏忚溅浠诲姟
+        /// </summary>
+        /// <param name="model"></param>
+        /// <returns></returns>
+        [HttpPost]
+        public IActionResult SendAgvTaskWms(CheckTaskVm model)
+        {
+            try
+            {
+                //鑾峰彇褰撳墠鐧诲綍鐨勭敤鎴稩D
+                var claimsIdentity = this.User.Identity as ClaimsIdentity;
+                if (claimsIdentity == null)
+                {
+                    return Ok(new { code = 1, msg = "鏈幏鍙栧埌褰撳墠鎿嶄綔浜轰俊鎭�" });
+                }
+                var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
+                if (string.IsNullOrWhiteSpace(userId))
+                {
+                    return Ok(new { code = 1, msg = "鏈幏鍙栧埌褰撳墠鎿嶄綔浜轰俊鎭�" });
+                }
+                _rcsserver.DownTask(model.taskNo, int.Parse(userId), _config.AgvHost + _config.GenAgvSchedulingTask);
+
+                return Ok(new { code = 0, msg = "閲嶆柊涓嬪彂宸插畬鎴�", data = "" });
+            }
+            catch (Exception e)
+            {
+                return Ok(new { code = 1, msg = e.Message });
+            }
+        }
+
+        /// <summary>
+        /// 鎵嬪姩瀹屾垚灏忚溅浠诲姟
+        /// </summary>
+        /// <param name="model"></param>
+        /// <returns></returns>
+        [HttpPost]
+        public IActionResult FinshAgvTaskWms(CheckTaskVm model)
+        {
+            try
+            {
+                //鑾峰彇褰撳墠鐧诲綍鐨勭敤鎴稩D
+                var claimsIdentity = this.User.Identity as ClaimsIdentity;
+                if (claimsIdentity == null)
+                {
+                    return Ok(new { code = 1, msg = "鏈幏鍙栧埌褰撳墠鎿嶄綔浜轰俊鎭�" });
+                }
+                var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
+                if (string.IsNullOrWhiteSpace(userId))
+                {
+                    return Ok(new { code = 1, msg = "鏈幏鍙栧埌褰撳墠鎿嶄綔浜轰俊鎭�" });
+                }
+                //鍏蜂綋澶勭悊鏂规硶
+                _rcsserver.RCSFinishTask(model.taskNo, "1", "WMS");
+
+                return Ok(new { code = 0, msg = "閲嶆柊涓嬪彂宸插畬鎴�", data = "" });
+            }
+            catch (Exception e)
+            {
+                return Ok(new { code = 1, msg = e.Message });
+            }
+        }
+
+        /// <summary>
+        /// 鎵嬪姩鍙栨秷AGV绉诲簱浠诲姟
+        /// </summary>
+        /// <param name="model"></param>
+        /// <returns></returns>
+        [HttpPost]
+        public IActionResult CancelAgvTaskWms(CheckTaskVm model)
+        {
+            try
+            {
+                //鑾峰彇褰撳墠鐧诲綍鐨勭敤鎴稩D
+                var claimsIdentity = this.User.Identity as ClaimsIdentity;
+                if (claimsIdentity == null)
+                {
+                    return Ok(new { code = 1, msg = "鏈幏鍙栧埌褰撳墠鎿嶄綔浜轰俊鎭�" });
+                }
+                var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
+                if (string.IsNullOrWhiteSpace(userId))
+                {
+                    return Ok(new { code = 1, msg = "鏈幏鍙栧埌褰撳墠鎿嶄綔浜轰俊鎭�" });
+                }
+                _rcsserver.CancelTask(model.taskNo, int.Parse(userId));
+
+                return Ok(new { code = 0, msg = "鎴愬姛鍙栨秷浠诲姟", data = "" });
+            }
+            catch (Exception e)
+            {
+                return Ok(new { code = 1, msg = e.Message });
+            }
+        }
         #endregion
     }
 }

--
Gitblit v1.8.0