From 2be1922b035c182c3c516427aa68be54badd6938 Mon Sep 17 00:00:00 2001
From: IPC-610 <IPC-610@DESKTOP-6LEOOS3>
Date: 星期四, 26 九月 2024 15:15:52 +0800
Subject: [PATCH] 登录页修改

---
 Wms/WMS.BLL/BllPdaServer/PdaCrServer.cs |  405 +++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 278 insertions(+), 127 deletions(-)

diff --git a/Wms/WMS.BLL/BllPdaServer/PdaCrServer.cs b/Wms/WMS.BLL/BllPdaServer/PdaCrServer.cs
index 7b98079..5fe710b 100644
--- a/Wms/WMS.BLL/BllPdaServer/PdaCrServer.cs
+++ b/Wms/WMS.BLL/BllPdaServer/PdaCrServer.cs
@@ -2,9 +2,12 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
+using Model.InterFaceModel;
 using Model.ModelDto.BllCheckDto;
 using Model.ModelDto.PdaDto;
+using Newtonsoft.Json;
 using SqlSugar;
+using Utility.Tools;
 using WMS.BLL.LogServer;
 using WMS.DAL;
 using WMS.Entity.BllAsnEntity;
@@ -139,7 +142,7 @@
                     {
                         PalletNo = palletNo,
                         SkuNo = sku,
-                        Qty = (int?)stockDetail.Qty,
+                        Qty = stockDetail.Qty,
                         CheckResult = 4,
                     };
 
@@ -171,7 +174,7 @@
             }
         }
 
-        public void CrSetCheck(string crNo, string crDetail, string palletNo, string boxNo, string boxNo3, string result, int? qty, string isContinue, int userId)
+        public void CrSetCheck(string crNo, string crDetail, string palletNo, string boxNo, string boxNo3, string result, decimal? qty, string isContinue, int userId)
         {
             try
             {
@@ -773,32 +776,40 @@
         {
             try
             {
-                var models = Db.Queryable<DataStockDetail>().First(w => w.IsDel == "0" && w.PalletNo == palletNo);
-                if (models == null)
-                {
-                    throw new Exception("鎵樼洏搴撳瓨淇℃伅涓嶅瓨鍦�,璇锋鏌�!");
-                }
-                if (string.IsNullOrEmpty(models.LocatNo))
-                {
-                    throw new Exception("鎵樼洏鍌ㄤ綅淇℃伅涓嶅瓨鍦�,璇锋鏌�!");
-                }
-                if (models.WareHouseNo != "W02")
-                {
-                    throw new Exception("璇ユ墭鐩樻湭鍦ㄥ钩搴撳唴,璇锋鏌�!");
-                }
-                var storageLocat = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == models.LocatNo);
-                if (storageLocat == null)
-                {
-                    throw new Exception("鍌ㄤ綅淇℃伅涓嶅瓨鍦�,璇锋鏌�!");
-                }
                 var storageArea = new List<SysStorageArea>();
-                if (storageLocat.AreaNo.Contains("B0"))
+                if (string.IsNullOrEmpty(palletNo))
                 {
-                    storageArea = Db.Queryable<SysStorageArea>().Where(w => w.AreaNo.Contains("B0")).ToList();
+                    storageArea = Db.Queryable<SysStorageArea>().Where(w => w.IsDel == "0" && w.Status == "0" && w.WareHouseNo == "W02").OrderBy(o => o.AreaNo).ToList();
                 }
                 else
                 {
-                    storageArea = Db.Queryable<SysStorageArea>().Where(w => w.AreaNo.Contains("B1")).ToList();
+                    var models = Db.Queryable<DataStockDetail>().First(w => w.IsDel == "0" && w.PalletNo == palletNo);
+                    if (models == null)
+                    {
+                        throw new Exception("鎵樼洏搴撳瓨淇℃伅涓嶅瓨鍦�,璇锋鏌�!");
+                    }
+                    if (string.IsNullOrEmpty(models.LocatNo))
+                    {
+                        throw new Exception("鎵樼洏鍌ㄤ綅淇℃伅涓嶅瓨鍦�,璇锋鏌�!");
+                    }
+                    if (models.WareHouseNo != "W02")
+                    {
+                        throw new Exception("璇ユ墭鐩樻湭鍦ㄥ钩搴撳唴,璇锋鏌�!");
+                    }
+                    var storageLocat = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == models.LocatNo);
+                    if (storageLocat == null)
+                    {
+                        throw new Exception("鍌ㄤ綅淇℃伅涓嶅瓨鍦�,璇锋鏌�!");
+                    }
+
+                    if (storageLocat.AreaNo.Contains("B0"))
+                    {
+                        storageArea = Db.Queryable<SysStorageArea>().Where(w => w.IsDel == "0" && w.Status == "0" && w.AreaNo.Contains("B0") && w.WareHouseNo == "W02").OrderBy(o => o.AreaNo).ToList();
+                    }
+                    else
+                    {
+                        storageArea = Db.Queryable<SysStorageArea>().Where(w => w.IsDel == "0" && w.Status == "0" && w.AreaNo.Contains("B1") && w.WareHouseNo == "W02").OrderBy(o => o.AreaNo).ToList();
+                    }
                 }
                 return storageArea;
             }
@@ -815,7 +826,7 @@
         {
             try
             {
-                var allotList = Db.Queryable<BllExportNotice>().Where(m => m.IsDel == "0" && m.Status == "2").Select(m => m.SONo).Distinct().ToList();
+                var allotList = Db.Queryable<BllExportNotice>().Where(m => m.IsDel == "0" && (m.Status == "3" || m.Status == "4")).Select(m => m.SONo).Distinct().ToList();
                 return allotList;
             }
             catch (Exception ex)
@@ -867,12 +878,12 @@
         }
 
         /// <summary>
-        /// agv杞繍鍛煎彨灏忚溅-寮�鍙戞湭瀹屾垚寰呯‘璁�
+        /// agv杞繍鍛煎彨灏忚溅
         /// </summary>
         /// <param name="palletNo"></param>
         /// <param name="areaNo"></param>
         /// <param name="ruku"></param>
-        public void AgvTransport(string palletNo, string areaNo, string ruku, int userId)
+        public void AgvTransport(string palletNo, string areaNo, string ruku, int userId, string url)
         {
             if (string.IsNullOrEmpty(palletNo))
             {
@@ -885,7 +896,7 @@
             if (!string.IsNullOrEmpty(areaNo) && !string.IsNullOrEmpty(ruku))
             {
                 throw new Exception("鐩爣鍖哄煙鍜屽叆搴撳彛涓嶈兘鍚屾椂閫夋嫨锛�");
-            }            
+            }
             try
             {
                 string EndLocat = string.Empty;//鐩爣浣嶇疆                
@@ -894,7 +905,7 @@
                 if (log != null)
                 {
                     throw new Exception("璇ユ墭鐩樺凡鏈夊皬杞︾瓑寰呮墽琛屾垨姝e湪鎵ц鐨勪换鍔�!");
-                }                
+                }
                 var stockDetail = Db.Queryable<DataStockDetail>().First(w => w.IsDel == "0" && w.PalletNo == palletNo);
                 if (stockDetail == null)
                 {
@@ -907,7 +918,7 @@
                     {
                         throw new Exception("鎵�閫夊尯鍩熶俊鎭笉瀛樺湪,璇锋鏌�!");
                     }
-                    EndLocat = GetLocat(areaNo, stockDetail.SkuNo, stockDetail.LotNo,palletNo);
+                    EndLocat = GetLocat(areaNo, stockDetail.SkuNo, stockDetail.LotNo, palletNo);
                 }
                 else
                 {
@@ -942,7 +953,7 @@
                         throw new Exception("鐩爣鍌ㄤ綅淇℃伅涓嶅瓨鍦�,璇锋鏌�!");
                     }
                 }
-                
+
                 //寮�鍚簨鍔�
                 Db.BeginTran();
 
@@ -958,6 +969,7 @@
                     StartLocat = stockDetail.LocatNo,//璧峰浣嶇疆
                     EndLocat = EndLocat,//鐩爣浣嶇疆
                     PalletNo = palletNo,//鎵樼洏鐮�
+                    Msg = string.Format("杞繍浠诲姟锛歿0}=>>{1}", stockDetail.LocatNo, EndLocat),
                     IsSend = 1,//鏄惁鍙啀娆′笅鍙�
                     IsCancel = 1,//鏄惁鍙彇娑�
                     IsFinish = 1,//鏄惁鍙畬鎴�
@@ -971,11 +983,11 @@
 
                 //淇敼搴撳瓨鏄庣粏淇℃伅
                 stockDetail.Status = "4";//绉诲簱閿佸畾
-                stockDetail.LockQty = stockDetail.Qty;//閿佸畾搴撳瓨鏁伴噺
+                //stockDetail.LockQty = stockDetail.Qty;//閿佸畾搴撳瓨鏁伴噺
                 Db.Updateable(stockDetail).ExecuteCommand();
                 //淇敼搴撳瓨淇℃伅
-                stock.LockQty += (decimal)stockDetail.Qty;
-                Db.Updateable(stock).ExecuteCommand();
+                //stock.LockQty += (decimal)stockDetail.Qty;
+                //Db.Updateable(stock).ExecuteCommand();
 
                 //淇敼璧峰鍌ㄤ綅鍦板潃鐘舵��
                 storageLocat.Status = "5";//0锛氱┖鍌ㄤ綅 1锛氭湁鐗╁搧 2锛氬叆搴撲腑 3锛氬嚭搴撲腑 4锛氱Щ鍏ヤ腑 5锛氱Щ鍑轰腑 
@@ -986,15 +998,63 @@
                 {
                     storageLocatEnd.Status = "4";//0锛氱┖鍌ㄤ綅 1锛氭湁鐗╁搧 2锛氬叆搴撲腑 3锛氬嚭搴撲腑 4锛氱Щ鍏ヤ腑 5锛氱Щ鍑轰腑 
                     Db.Updateable(storageLocatEnd).ExecuteCommand();
-                }               
+                }
                 //娣诲姞鎿嶄綔鏃ュ織璁板綍
                 var k = new OperationCrServer().AddLogOperationCr("PDA妯″潡", "AGV杞繍", palletNo, "绉诲簱", $"PDA鍛煎彨灏忚溅瀵规墭鐩樺彿锛歿palletNo}鍙戣捣杞繍", userId);
-                //鎻愪氦浜嬪姟
-                Db.CommitTran();
 
                 #region 鍛煎彨灏忚溅浠g爜
 
+
+                List<AgvSchedulingTask> agvTaskList = new List<AgvSchedulingTask>();
+
+                AgvSchedulingTask agvTask = new AgvSchedulingTask();
+                agvTask.ReqCode = taskNo;
+                agvTask.TaskTyp = "F01";
+                agvTask.WbCode = "";
+                agvTask.PositionCodePath = null;
+                agvTask.PodCode = "-1";
+
+                agvTaskList.Add(agvTask);
+
+                var IsTrue = false;
+                while (IsTrue == true)
+                {
+                    // 姝e紡杩愯绋嬪簭鏀惧紑
+                    string str = "";
+                    var list2 = agvTaskList.Select(m => m.ReqCode).ToList();
+                    var jsonData = JsonConvert.SerializeObject(agvTaskList);
+                    string response = "";
+
+                    try
+                    {
+                        var time1 = DateTime.Now;//鍙戦�佹椂闂� .ToString("yyyy-MM-dd HH:mm:ss")
+                        response = HttpHelper.DoPost(url, jsonData, "涓嬪彂缁橝GV杞繍鍛戒护", "AGV");
+                        var time2 = DateTime.Now;//杩斿洖鏃堕棿 .ToString("yyyy-MM-dd HH:mm:ss")
+
+                        //////瑙f瀽杩斿洖鏁版嵁 
+                        var agvModel = JsonConvert.DeserializeObject<OutCommanAgvDto>(response);
+                        if (agvModel.Code == "0")
+                        {
+                            //鏇存敼浠诲姟鐨勫彂閫佽繑鍥炴椂闂�//
+                            new TaskServer().EditTaskIssueOk(list2, time1, time2);
+                            str += "涓嬪彂鎴愬姛";
+                            IsTrue = true;
+                        }
+                        if (agvModel.Code == "1")
+                        {
+                            new TaskServer().EditTaskIssueNo(list2, time1, time2, agvModel.Message);
+                            throw new Exception(agvModel.Message);
+                        }
+                    }
+                    catch (Exception ex)
+                    {
+                        throw new Exception(ex.Message);
+                    }
+                }
                 #endregion
+
+                //鎻愪氦浜嬪姟
+                Db.CommitTran();
             }
             catch (Exception ex)
             {
@@ -1003,21 +1063,17 @@
             }
         }
         /// <summary>
-        /// agv杞繍鍛煎彨灏忚溅鍙栬揣-寮�鍙戞湭瀹屾垚寰呯‘璁�
+        /// agv杞繍鍛煎彨灏忚溅鍙栬揣
         /// </summary>
         /// <param name="soNo"></param>
         /// <param name="palletNo"></param>
         /// <param name="areaNo"></param>
         /// <param name="userId"></param>
-        public void AgvTransport2(string soNo,string palletNo, string areaNo, int userId)
+        public List<string> AgvTransport2(string soNo, string palletNo, string areaNo, int userId, string url)
         {
             if (string.IsNullOrEmpty(soNo))
             {
                 throw new Exception("璇烽�夋嫨鍑哄簱鍗曟嵁锛�");
-            }
-            if (string.IsNullOrEmpty(palletNo))
-            {
-                throw new Exception("璇锋壂鎻忔墭鐩樻潯鐮侊紒");
             }
             if (string.IsNullOrEmpty(areaNo))
             {
@@ -1025,108 +1081,203 @@
             }
             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("璇ユ墭鐩樺凡鏈夊皬杞︾瓑寰呮墽琛屾垨姝e湪鎵ц鐨勪换鍔�!");
-                }
-
+                //寮�鍚簨鍔�
+                Db.BeginTran();
+                List<AgvSchedulingTask> agvTaskList = new List<AgvSchedulingTask>();
+                var strList = new List<string>();//閿欒淇℃伅闆嗗悎  //0 锛氶儴鍒嗘墭鐩樺凡鏈夊皬杞︾瓑寰呮墽琛屾垨姝e湪鎵ц鐨勪换鍔�
+                //鍑哄簱鍗曚俊鎭�
                 var notice = Db.Queryable<BllExportNotice>().First(w => w.IsDel == "0" && w.SONo == soNo);
                 if (notice == null)
                 {
                     throw new Exception("鍑哄簱鍗曟嵁淇℃伅涓嶅瓨鍦�,璇锋鏌�!");
                 }
-                var allot = Db.Queryable<BllExportAllot>().First(w => w.IsDel == "0" && w.SONo == soNo && w.PalletNo == palletNo);
-                if (allot == null)
-                {
-                    throw new Exception("璇ユ墭鐩樺嚭搴撳垎閰嶄俊鎭笉瀛樺湪,璇锋鏌�!");
-                }
-                var stockDetail = Db.Queryable<DataStockDetail>().First(w => w.IsDel == "0" && w.PalletNo == palletNo);
-                if (stockDetail == null)
-                {
-                    throw new Exception("鎵樼洏涓婄墿鏂欏簱瀛樹俊鎭笉瀛樺湪,璇锋鏌�!");
-                }
-                var stock = Db.Queryable<DataStock>().First(w => w.IsDel == "0" && w.SkuNo == stockDetail.SkuNo && w.LotNo == stockDetail.LotNo);
-                if (stock == null)
-                {
-                    throw new Exception("鎵樼洏涓婄墿鏂欏簱瀛樹俊鎭笉瀛樺湪,璇锋鏌�!");
-                }
-                if (string.IsNullOrEmpty(stockDetail.LocatNo))
-                {
-                    throw new Exception("鎵樼洏鍌ㄤ綅淇℃伅涓嶅瓨鍦�,璇锋鏌�!");
-                }
-                if (stockDetail.WareHouseNo != "W02")
-                {
-                    throw new Exception("璇ユ墭鐩樻湭鍦ㄥ钩搴撳唴,璇锋鏌�!");
-                }
-                var storageLocat = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == stockDetail.LocatNo);
-                if (storageLocat == null)
-                {
-                    throw new Exception("鍌ㄤ綅淇℃伅涓嶅瓨鍦�,璇锋鏌�!");
-                }
+                //鐩爣鍖哄煙淇℃伅
                 var storageArea = Db.Queryable<SysStorageArea>().First(w => w.IsDel == "0" && w.AreaNo == areaNo);
                 if (storageArea == null)
                 {
                     throw new Exception("鎵�閫夊尯鍩熶俊鎭笉瀛樺湪,璇锋鏌�!");
                 }
-                string EndLocat = string.Empty;//鐩爣浣嶇疆
-                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)
+                List<DataStockDetail> stockDetailList = new List<DataStockDetail>();//闇�瑕佺殑鎵樼洏鏄庣粏
+                if (!string.IsNullOrEmpty(palletNo))//鍗曟墭鐩樺彨璐�
                 {
-                    throw new Exception("鐩爣鍌ㄤ綅淇℃伅涓嶅瓨鍦�,璇锋鏌�!");
+                    stockDetailList = Db.Queryable<DataStockDetail>().Where(w => w.IsDel == "0" && w.PalletNo == palletNo).ToList();
                 }
-                //寮�鍚簨鍔�
-                Db.BeginTran();
-
-                //娣诲姞鍑哄簱浠诲姟
-                var taskNo = new Common().GetMaxNo("TK");
-                var exTask = new LogTask
+                else//鏁翠釜鍑哄簱鍗曞彨璐�
                 {
-                    TaskNo = taskNo,
-                    Sender = "WMS",
-                    Receiver = "AGV",
-                    IsSuccess = 0, //鏄惁涓嬪彂鎴愬姛 0澶辫触 1鎴愬姛
+                //    string sqlStr = $"select * from DataStockDetail where PalletNo in (select PalletNo from BllExportAllot where IsDel='0' and SONo='{soNo}')";
+                //    stockDetailList = Db.Ado.SqlQuery<DataStockDetail>(sqlStr).ToList();
+                    stockDetailList = Db.Queryable<DataStockDetail>().Where(w => w.IsDel == "0" && w.SONo == soNo).ToList();
+                }
+                if (stockDetailList.Count <= 0)
+                {
+                    throw new Exception("鎵樼洏鏄庣粏涓嶅瓨鍦�,璇锋鏌�!");
+                }
 
-                    StartLocat = stockDetail.LocatNo,//璧峰浣嶇疆
-                    EndLocat = EndLocat,//鐩爣浣嶇疆
-                    PalletNo = palletNo,//鎵樼洏鐮�
-                    IsSend = 1,//鏄惁鍙啀娆′笅鍙�
-                    IsCancel = 1,//鏄惁鍙彇娑�
-                    IsFinish = 1,//鏄惁鍙畬鎴�
-                    Type = "2",//浠诲姟绫诲瀷 0 鍏ュ簱浠诲姟 1 鍑哄簱浠诲姟  2 绉诲簱浠诲姟
-                    Status = "0",//浠诲姟鐘舵��0锛氱瓑寰呮墽琛�1姝e湪鎵ц2鎵ц瀹屾垚
-                    OrderType = "3",//0 鍏ュ簱鍗� 1 鍑哄簱鍗�  2 鐩樼偣鍗�  3 绉诲簱鍗�
+                var log = Db.Queryable<LogTask>().Where(w => w.IsDel == "0" && (w.Status == "0" || w.Status == "1"));//浠诲姟琛�
+                var storageLocat = Db.Queryable<SysStorageLocat>().Where(w => w.IsDel == "0");//鍌ㄤ綅琛�
+                var stock = Db.Queryable<DataStock>().Where(w => w.IsDel == "0");//搴撳瓨鎬昏〃
+                string EndLocat = string.Empty;//鐩爣浣嶇疆
+                string hasLocatNoList = string.Empty;//宸插垎閰嶇殑鍌ㄤ綅
 
-                    CreateTime = DateTime.Now
-                };
-                Db.Insertable(exTask).ExecuteCommand();
+                foreach (var item in stockDetailList)
+                {
+                    
+                    if (string.IsNullOrEmpty(item.LocatNo))
+                    {
+                        throw new Exception($"鎵樼洏鍙凤細{item.PalletNo}鐨勫偍浣嶄俊鎭笉瀛樺湪,璇锋鏌�!");
+                    }
+                    if (item.WareHouseNo != "W02")
+                    {
+                        throw new Exception($"鎵樼洏鍙凤細{item.PalletNo}鏈湪骞冲簱鍐�,璇锋鏌�!");
+                    }
+                    //浠诲姟淇℃伅
+                    var logInfo = log.First(w => w.PalletNo == item.PalletNo);
+                    if (logInfo != null)
+                    {
+                        if (!strList.Contains("1"))
+                        {
+                            strList.Add("1");
+                        }
+                        continue;
+                        //throw new Exception($"鎵樼洏鍙凤細{item.PalletNo}宸叉湁灏忚溅绛夊緟鎵ц鎴栨鍦ㄦ墽琛岀殑浠诲姟!");
+                    }
+                    //璧峰鍌ㄤ綅淇℃伅
+                    var storageLocatBegin = storageLocat.First(w => w.LocatNo == item.LocatNo);
+                    if (storageLocat == null)
+                    {
+                        throw new Exception($"鎵樼洏鍙凤細{item.PalletNo}鎵�鍦ㄧ殑鍌ㄤ綅淇℃伅涓嶅瓨鍦�,璇锋鏌�!");
+                    }
+                    //鑾峰彇鐩爣鍌ㄤ綅
+                    EndLocat = GetLocat(areaNo, item.SkuNo, item.LotNo, palletNo);
+                    if (string.IsNullOrEmpty(EndLocat))
+                    {
+                        throw new Exception("鍒嗛厤鐩爣鍌ㄤ綅澶辫触,璇锋鏌�!");
+                    }
+                    if (string.IsNullOrEmpty(hasLocatNoList))
+                    {
+                        hasLocatNoList = EndLocat;
+                    }
+                    else
+                    {
+                        hasLocatNoList = hasLocatNoList + "," + EndLocat;
+                    }
+                    //鐩爣鍌ㄤ綅淇℃伅
+                    var storageLocatEnd = storageLocat.First(w => w.LocatNo == EndLocat && w.Flag == "0" && w.Status == "0");
+                    if (storageLocatEnd == null)
+                    {
+                        throw new Exception("鐩爣鍌ㄤ綅淇℃伅涓嶅瓨鍦�,璇锋鏌�!");
+                    }
 
-                //淇敼搴撳瓨鏄庣粏淇℃伅
-                stockDetail.Status = "4";//绉诲簱閿佸畾
-                stockDetail.LockQty = stockDetail.Qty;//閿佸畾搴撳瓨鏁伴噺
-                Db.Updateable(stockDetail).ExecuteCommand();
-                //淇敼搴撳瓨淇℃伅
-                stock.LockQty += (decimal)stockDetail.Qty;
-                Db.Updateable(stock).ExecuteCommand();
+                    //娣诲姞鍑哄簱浠诲姟
+                    var taskNo = new Common().GetMaxNo("TK");
+                    var exTask = new LogTask
+                    {
+                        TaskNo = taskNo,
+                        Sender = "WMS",
+                        Receiver = "AGV",
+                        IsSuccess = 0, //鏄惁涓嬪彂鎴愬姛 0澶辫触 1鎴愬姛
+                        Msg = string.Format("杞繍浠诲姟锛歿0}=>>{1}", item.LocatNo, EndLocat),
+                        StartLocat = item.LocatNo,//璧峰浣嶇疆
+                        EndLocat = EndLocat,//鐩爣浣嶇疆
+                        PalletNo = item.PalletNo,//鎵樼洏鐮�
+                        IsSend = 1,//鏄惁鍙啀娆′笅鍙�
+                        IsCancel = 1,//鏄惁鍙彇娑�
+                        IsFinish = 1,//鏄惁鍙畬鎴�
+                        Type = "2",//浠诲姟绫诲瀷 0 鍏ュ簱浠诲姟 1 鍑哄簱浠诲姟  2 绉诲簱浠诲姟
+                        Status = "0",//浠诲姟鐘舵��0锛氱瓑寰呮墽琛�1姝e湪鎵ц2鎵ц瀹屾垚
+                        OrderType = "3",//0 鍏ュ簱鍗� 1 鍑哄簱鍗�  2 鐩樼偣鍗�  3 绉诲簱鍗�
 
-                //淇敼鍌ㄤ綅鍦板潃鐘舵��
-                storageLocat.Status = "5";//0锛氱┖鍌ㄤ綅 1锛氭湁鐗╁搧 2锛氬叆搴撲腑 3锛氬嚭搴撲腑 4锛氱Щ鍏ヤ腑 5锛氱Щ鍑轰腑 
-                Db.Updateable(storageLocat).ExecuteCommand();
+                        CreateTime = DateTime.Now
+                    };
+                    Db.Insertable(exTask).ExecuteCommand();
 
-                //淇敼鐩爣鍌ㄤ綅鍦板潃鐘舵��
-                storageLocatEnd.Status = "4";//0锛氱┖鍌ㄤ綅 1锛氭湁鐗╁搧 2锛氬叆搴撲腑 3锛氬嚭搴撲腑 4锛氱Щ鍏ヤ腑 5锛氱Щ鍑轰腑 
-                Db.Updateable(storageLocatEnd).ExecuteCommand();
+                    AgvSchedulingTask agvTask = new AgvSchedulingTask();
+                    agvTask.ReqCode = taskNo;
+                    agvTask.TaskTyp = "F01";
+                    agvTask.WbCode = "";
+                    agvTask.PositionCodePath = null;
+                    agvTask.PodCode = "-1";
 
-                //娣诲姞鎿嶄綔鏃ュ織璁板綍
-                var k = new OperationCrServer().AddLogOperationCr("PDA妯″潡", "AGV杞繍", palletNo, "绉诲簱", $"PDA鍛煎彨灏忚溅瀵规墭鐩樺彿锛歿palletNo}鍙戣捣杞繍", userId);
-                //鎻愪氦浜嬪姟
-                Db.CommitTran();
+                    agvTaskList.Add(agvTask);
+
+                    //淇敼搴撳瓨鏄庣粏淇℃伅
+                    item.Status = "4";//绉诲簱閿佸畾
+                    //item.LockQty = item.Qty;//閿佸畾搴撳瓨鏁伴噺
+                    Db.Updateable(item).ExecuteCommand();
+
+                    //淇敼璧峰鍌ㄤ綅鍦板潃鐘舵��
+                    storageLocatBegin.Status = "5";//0锛氱┖鍌ㄤ綅 1锛氭湁鐗╁搧 2锛氬叆搴撲腑 3锛氬嚭搴撲腑 4锛氱Щ鍏ヤ腑 5锛氱Щ鍑轰腑 
+                    Db.Updateable(storageLocatBegin).ExecuteCommand();
+                    //淇敼鐩爣鍌ㄤ綅鍦板潃鐘舵��
+                    storageLocatEnd.Status = "4";//0锛氱┖鍌ㄤ綅 1锛氭湁鐗╁搧 2锛氬叆搴撲腑 3锛氬嚭搴撲腑 4锛氱Щ鍏ヤ腑 5锛氱Щ鍑轰腑 
+                    Db.Updateable(storageLocatEnd).ExecuteCommand();
+                    
+                    if (!strList.Contains("0"))
+                    {
+                        strList.Add("0");
+                    }
+
+                    //var stockInfo = stock.First(w => w.SkuNo == item.SkuNo && w.LotNo == item.LotNo);
+                    ////淇敼搴撳瓨淇℃伅
+                    //stockInfo.LockQty += (decimal)item.Qty;//閿佸畾鏁伴噺
+                    //Db.Updateable(stockInfo).ExecuteCommand();
+                }
+                if (string.IsNullOrEmpty(palletNo))
+                {
+                    //娣诲姞鎿嶄綔鏃ュ織璁板綍
+                    var k = new OperationCrServer().AddLogOperationCr("PDA妯″潡", "AGV杞繍", palletNo, "绉诲簱", $"PDA鍛煎彨灏忚溅瀵瑰嚭搴撳崟锛歿soNo}涓嬫墍鏈夋墭鐩樺彂璧疯浆杩�", userId);
+                }
+                else
+                {
+                    //娣诲姞鎿嶄綔鏃ュ織璁板綍
+                    var k = new OperationCrServer().AddLogOperationCr("PDA妯″潡", "AGV杞繍", palletNo, "绉诲簱", $"PDA鍛煎彨灏忚溅瀵规墭鐩樺彿锛歿palletNo}鍙戣捣杞繍", userId);
+                }
 
                 #region 鍛煎彨灏忚溅浠g爜
 
+                
+
+                var IsTrue = false;
+                while (IsTrue == true)
+                {
+                    // 姝e紡杩愯绋嬪簭鏀惧紑
+                    string str = "";
+                    var list2 = agvTaskList.Select(m => m.ReqCode).ToList();
+                    var jsonData = JsonConvert.SerializeObject(agvTaskList);
+                    string response = "";
+
+                    try
+                    {
+                        var time1 = DateTime.Now;//鍙戦�佹椂闂� .ToString("yyyy-MM-dd HH:mm:ss")
+                        response = HttpHelper.DoPost(url, jsonData, "涓嬪彂缁橝GV杞繍鍙栬揣鍛戒护", "AGV");
+                        var time2 = DateTime.Now;//杩斿洖鏃堕棿 .ToString("yyyy-MM-dd HH:mm:ss")
+
+                        //////瑙f瀽杩斿洖鏁版嵁 
+                        var agvModel = JsonConvert.DeserializeObject<OutCommanAgvDto>(response);
+                        if (agvModel.Code == "0")
+                        {
+                            //鏇存敼浠诲姟鐨勫彂閫佽繑鍥炴椂闂�//
+                            new TaskServer().EditTaskIssueOk(list2, time1, time2);
+                            str += "涓嬪彂鎴愬姛";
+                            IsTrue = true;
+                        }
+                        if (agvModel.Code == "1")
+                        {
+                            new TaskServer().EditTaskIssueNo(list2, time1, time2, agvModel.Message);
+                            throw new Exception(agvModel.Message);
+                        }
+                    }
+                    catch (Exception ex)
+                    {
+                        throw new Exception(ex.Message);
+                    }
+                }
+
                 #endregion
+
+                //鎻愪氦浜嬪姟
+                Db.CommitTran();
+                return strList;
             }
             catch (Exception ex)
             {
@@ -1141,21 +1292,21 @@
         /// <param name="skuNo"></param>
         /// <param name="lotNo"></param>
         /// <returns></returns>
-        private string GetLocat(string areaNo,string skuNo,string lotNo,string palletNo)
+        private string GetLocat(string areaNo, string skuNo, string lotNo, string palletNo, string hasLocatNoList = "")
         {
             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();
+                    .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)
+                    var locatInfo2 = storageLocatList.Where(w => w.IsDel == "0" && w.Status == "0" && w.Flag == "0" && w.LocatNo != locatInfo.LocatNo && w.Row == locatInfo.Row && !hasLocatNoList.Contains(w.LocatNo))
                         .OrderByDescending(o => o.Column).First();
                     if (locatInfo2 != null)
                     {
@@ -1164,8 +1315,8 @@
                 }
                 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();
+                    var locatInfo3 = storageLocatList.Where(w => w.IsDel == "0" && w.Flag == "0" && w.Status == "0" && !hasLocatNoList.Contains(w.LocatNo))
+                                .OrderByDescending(m => m.Layer).OrderByDescending(m => m.Column).OrderByDescending(m => m.Row).First();
 
                     if (locatInfo3 != null)
                     {

--
Gitblit v1.8.0