From 6be6a1e453861fa0beb818236fdd8183024074c4 Mon Sep 17 00:00:00 2001
From: wxw <Administrator@DESKTOP-5BIMHQ3>
Date: 星期二, 04 十一月 2025 08:21:40 +0800
Subject: [PATCH] 增加和MES对接接口

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

diff --git a/Wms/WMS.BLL/BllTransServer/RcsServer.cs b/Wms/WMS.BLL/BllTransServer/RcsServer.cs
index 1245029..a00753c 100644
--- a/Wms/WMS.BLL/BllTransServer/RcsServer.cs
+++ b/Wms/WMS.BLL/BllTransServer/RcsServer.cs
@@ -38,7 +38,7 @@
         /// <param name="url"></param>
         /// <param name="taskNo"></param>
         /// <exception cref="Exception"></exception>
-        public void GetPalletNo(Pallnetmsg model, string url, out string taskNo)
+        public void GetPalletNo(Pallnetmsg model, string url,string urlMes, out string taskNo)
         {
             lock (GetPalleLock)
             {
@@ -60,7 +60,6 @@
                     //鍙《璁惧鎵�鍦ㄥ偍浣嶄俊鎭紙鐩爣鍌ㄤ綅锛�
                     var endLoction = new SysStorageLocat();
 
-                    var urlMes = "";//鍥炰紶MES鐨勬帴鍙e湴鍧�
                     var noticeNo = "0";//鍑哄叆搴撳崟鎹槑缁咺D
 
                     //鎵�鏈夊緟鍒嗛厤鐨勬《
@@ -252,36 +251,28 @@
                                 foreach (var item in palletList)
                                 {
                                     #region 鍘绘帀MES
-                                    //string jsonReq = JsonConvert.SerializeObject(item.PalletNo);
-                                    //var response = HttpHelper.DoPost(urlMes, jsonReq, "鍥炰紶MES鑴忔《缂栧彿", "RCS").ToString();
-                                    //var obj = JsonConvert.DeserializeObject<ReMes>(response);//瑙f瀽杩斿洖鏁版嵁
-                                    //if (obj.Success == "0")
-                                    //{
-                                    //    if (obj.Result != "1")//涓嶅彲娓呮礂锛屽皢鑴忔《鍐荤粨
-                                    //    {
-                                    //        item.Status = "5";//寮傚父鍐荤粨
-                                    //        //淇敼璇ユ《搴撳瓨鐘舵��
-                                    //        Db.Updateable(item).ExecuteCommand();
+                                    var reObj = new
+                                    {
+                                        devive = item.PackagNo
+                                    };
+                                    string jsonReq = JsonConvert.SerializeObject(reObj);
+                                    var response = HttpHelper.DoPost(urlMes, jsonReq, "鍥炰紶MES鑴忔《缂栧彿鍒ゆ柇鏄惁鍙竻娲�", "MES").ToString();
+                                    var obj = JsonConvert.DeserializeObject<ReMes>(response);//瑙f瀽杩斿洖鏁版嵁
+                                    if (obj.state == "200")
+                                    {
+                                        if (obj.data != "1")//涓嶅彲娓呮礂锛屽皢鑴忔《鍐荤粨
+                                        {
+                                            item.Status = "5";//寮傚父鍐荤粨
+                                            //淇敼璇ユ《搴撳瓨鐘舵��
+                                            Db.Updateable(item).ExecuteCommand();
 
-                                    //        continue;
-                                    //    }
-                                    //    //涓嬪彂灏忚溅浠诲姟
-                                    //    var task2 = new TaskDetial
-                                    //    {
-                                    //        Startport = item.LocatNo,
-                                    //        Endport = model.Location,
-                                    //        Pallno = item.PalletNo,
-                                    //        Type = model.Type,
-                                    //        Crtype = "1",
-                                    //        Noticedetailno = int.Parse(noticeno),
-                                    //    };
-                                    //    CreateLotTask(task2);
-                                    //    return;
-                                    //}
-                                    //else
-                                    //{
-                                    //    throw new Exception("鍥炰紶MES鍑�妗剁紪鍙峰け璐ワ紒");
-                                    //}
+                                            continue;
+                                        }
+                                    }
+                                    else
+                                    {
+                                        throw new Exception("鍙剰妗跺洖浼燤ES鍒ゆ柇澶辫触锛�");
+                                    }
                                     #endregion
 
                                     item.Status = "2";//鍒嗛厤鐘舵�� 0:寰呭垎閰嶏紝1锛氶儴鍒嗗垎閰� 锛� 2:宸插垎閰�
@@ -783,7 +774,7 @@
                 Db.BeginTran();
 
                 //鏌ユ壘鏄惁鏈夌┖浣欒剰妗朵綅
-                var endLocat = Db.Queryable<SysStorageLocat>().First(w => w.WareHouseNo == detail.WareHouseNo && w.AreaNo.Contains("04") && w.Status == "0" && w.Flag=="0");
+                var endLocat = Db.Queryable<SysStorageLocat>().First(w => w.WareHouseNo == detail.WareHouseNo && w.AreaNo.Contains("04") && w.Status == "0" && w.Flag == "0");
                 if (endLocat == null)
                 {
                     detail.Status = "5";//寮傚父閿佸畾
@@ -831,22 +822,97 @@
         {
             try
             {
+                //妗朵俊鎭�
                 var detail = Db.Queryable<DataStockDetail>().First(w => w.PalletNo == pallnetmsg.PalletNo && w.PalletStatus == "3");
                 if (detail == null)
                 {
                     throw new Exception($"搴撳瓨涓笉瀛樺湪妗跺彿涓猴細{pallnetmsg.PalletNo}鐨勫簱瀛�!");
                 }
-                //涓嬪彂灏忚溅浠诲姟
+                //璁惧淇℃伅
+                var deviceInfo = Db.Queryable<SysStorageArea>().First(w => w.IsDel == "0" && w.DeviceCode.Contains(pallnetmsg.Location));
+                if (deviceInfo == null)
+                {
+                    throw new Exception($"涓嶅瓨鍦ㄨ澶囧彿涓猴細{pallnetmsg.Location}鐨勮澶�!");
+                }
+                //鐩爣鍌ㄤ綅淇℃伅
+                var endLoction = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.WareHouseNo == deviceInfo.WareHouseNo && w.AreaNo == deviceInfo.AreaNo && w.Column == 1);// Column=1 娓呮礂鍌ㄤ綅锛孋olumn=2 娓呮礂瀹屾枡鍌ㄤ綅 
+                if (endLoction == null)
+                {
+                    throw new Exception("鍙《璁惧鐩爣鍌ㄤ綅淇℃伅涓嶅瓨鍦�");
+                }
+
+                detail.Status = "2";//鍒嗛厤鐘舵�� 0:寰呭垎閰嶏紝1锛氶儴鍒嗗垎閰� 锛� 2:宸插垎閰�
+                 //鏇存柊妗跺簱瀛樻槑缁�
+                Db.Updateable(detail).ExecuteCommand();
+
+                //璧峰鍌ㄤ綅鍦板潃淇℃伅
+                var startLoction = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == detail.LocatNo);
+                if (startLoction == null)
+                {
+                    throw new Exception($"妗跺彿锛歿detail.PalletNo}鍌ㄤ綅淇℃伅{detail.LocatNo}涓嶅瓨鍦�");
+                }
+
+                var taskNo = new Common().GetMaxNo("TN");//浠诲姟鍙�
+                var logTaskEntry = new LogTask
+                {
+                    TaskNo = taskNo,
+                    Sender = "WMS",
+                    Receiver = "RCS",
+                    //IsSuccess = 1, //鏄惁涓嬪彂鎴愬姛 0澶辫触 1鎴愬姛
+                    SendDate = DateTime.Now,  //鍙戦�佹椂闂�
+                                              //BackDate = DateTime.Now,  //杩斿洖鏃堕棿
+                    StartLocat = startLoction.LocatNo,//璧峰浣嶇疆
+                    EndLocat = endLoction.LocatNo,//鐩爣浣嶇疆
+                    PalletNo = detail.PalletNo,//鎵樼洏鐮�
+                    IsSend = 1,//鏄惁鍙啀娆′笅鍙�
+                    IsCancel = 1,//鏄惁鍙彇娑�
+                    IsFinish = 1,//鏄惁鍙畬鎴�
+                    Type = "1",//浠诲姟绫诲瀷 0 鍏ュ簱浠诲姟 1 鍑哄簱浠诲姟  2 绉诲簱浠诲姟
+                    OrderType = "3",//鍗曟嵁绫诲瀷 0 鍏ュ簱 1 鍑哄簱 3 绉诲簱
+                    Status = "0",//浠诲姟鐘舵��0锛氱瓑寰呮墽琛�1姝e湪鎵ц2鎵ц瀹屾垚
+                    NoticeDetailNo = 0,
+                    Msg = $"MES涓嬪彂娓呮礂鎸囧畾鑴忔《锛屾《鍙�:{pallnetmsg.PalletNo},璁惧鍙凤細{pallnetmsg.Location}", //鍏抽敭淇℃伅
+                    LotNo = ""//鎵规鍙�
+                };
+                //缁勭粐涓嬪彂灏忚溅浠诲姟淇℃伅
                 var task = new TaskDetial
                 {
-                    Startport = detail.LocatNo,
-                    Endport = pallnetmsg.Location,
-                    Pallno = detail.PalletNo,
-                    Crtype = "1",
+                    Taskno = taskNo,//浠诲姟鍙�
+                    Startport = startLoction.LocatNo,//璧峰浣嶇疆
+                    Endport = endLoction.LocatNo,//鐩爣浣嶇疆
+                    Pallno = detail.PalletNo,//妗跺彿
+                    Crtype = "1",//鍙《
+                    WareHouseNo = detail.WareHouseNo//杞﹂棿缂栫爜
                 };
-                string taskNo = "";
-                string agvMsg = string.Empty;
-                CreateTaskForAgv(task, url, out agvMsg);
+                //缁欎笅杞︿笅鍙戜换鍔�
+                logTaskEntry.SendDate = DateTime.Now;//鍙戦�佹椂闂�
+                string agvMsg=string.Empty;
+                var agvResult = CreateTaskForAgv(task, url, out agvMsg);
+                if (agvResult)//鎴愬姛
+                {
+                    //璇锋眰鎴愬姛淇敼浠诲姟琛ㄧ浉搴斿瓧娈电姸鎬�
+                    logTaskEntry.IsSuccess = 1;
+                    logTaskEntry.IsSend = 0;
+                    //logTaskEntry.IsCancel = 0;
+                    logTaskEntry.BackDate = DateTime.Now;
+                    logTaskEntry.Status = "1";//姝e湪鎵ц
+                    Db.Insertable(logTaskEntry).ExecuteCommand();
+
+                    startLoction.Status = "3";//鍑哄簱涓�
+                    Db.Updateable(startLoction).ExecuteCommand();
+
+                    endLoction.Status = "2";//鍏ュ簱涓�
+                    Db.Updateable(endLoction).ExecuteCommand();
+                }
+                else//澶辫触
+                {
+                    logTaskEntry.IsSuccess = 0;
+                    logTaskEntry.Information = agvMsg;
+                    Db.Insertable(logTaskEntry).ExecuteCommand();
+
+                }
+                //鎻愪氦浜嬪姟
+                Db.CommitTran();
             }
             catch (Exception ex)
             {
@@ -1294,33 +1360,42 @@
                 agvTask.taskTyp = "Z5";
             }
 
-            // 姝e紡杩愯绋嬪簭鏀惧紑
-            var jsonData = JsonConvert.SerializeObject(agvTask);
-            string response = HttpHelper.DoPost(url, jsonData, "涓嬪彂缁橝GV杞繍鍛戒护", "AGV");
-            //瑙f瀽杩斿洖鏁版嵁 
-            var agvModel = JsonConvert.DeserializeObject<OutCommanAgvDto>(response);
-            if (agvModel.Code == "0")
+            
+            if (string.IsNullOrEmpty(url))//娴嬭瘯绯荤粺
             {
-                result = true;//缁欎笅杞︿笅鍙戜换鍔℃垚鍔�
-
+                result = true;
                 agvMsg = "";
             }
-            else
+            else//姝e紡绯荤粺
             {
-                string logMsg = "";
-                if (taskDetial.Crtype == "1")//鍙《锛堟《鍑哄簱锛�
+                var jsonData = JsonConvert.SerializeObject(agvTask);
+                string response = HttpHelper.DoPost(url, jsonData, "涓嬪彂缁橝GV杞繍鍛戒护", "AGV");
+                //瑙f瀽杩斿洖鏁版嵁 
+                var agvModel = JsonConvert.DeserializeObject<OutCommanAgvDto>(response);
+                if (agvModel.Code == "0")
                 {
-                    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);
+                    result = true;//缁欎笅杞︿笅鍙戜换鍔℃垚鍔�
 
-                agvMsg = agvModel.Message;
+                    agvMsg = "";
+                }
+                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);
+
+                    agvMsg = agvModel.Message;
+                }
             }
+            
             return result;
             #endregion
         }

--
Gitblit v1.8.0