From 25724888bc329401891bf1600a8a83d8aae338b3 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期六, 27 四月 2024 18:37:37 +0800
Subject: [PATCH] 叠盘入库功能开发,空托入库逻辑优化

---
 代码管理/PCS/WCS_Server/WIDESEA_Entity/DomainModels/ToAGV/AGVRequestin.cs            |    5 
 代码管理/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/新文件夹/GetLocation.cs              |   18 
 代码管理/PCS/WCS_Server/WIDESEA_WCS/Common/Gantry.cs                                 |  438 +++++-----------
 代码管理/PCS/WCS_Server/WIDESEA_WCS/Jobs/equipment/PipelineJob.cs                    |  536 +++++++++++++------
 代码管理/PCS/WCS_Server/WIDESEA_WCS/Common/Pipeline.cs                               |  268 +++++++++
 代码管理/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/ReplaceTray.cs                   |   11 
 代码管理/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/GetStation/EmptyPalletStation.cs |   16 
 代码管理/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/RestockHCJ.cs                    |  187 ++----
 代码管理/PCS/WCS_Server/WIDESEA_WCS/Jobs/Task/AutoTaskJob.cs                         |   13 
 代码管理/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/EmptyTrayIn.cs                   |   84 +++
 代码管理/PCS/WCS_Server/WIDESEA_WCS/Common/AGVandPipeline.cs                         |    6 
 项目资料/通信协议/PCS跟AGV和桁架防呆交互协议/PCS和桁架协议.xlsx                                         |    0 
 代码管理/PCS/WCS_Server/WIDESEA_WebApi/appsettings.json                              |    1 
 代码管理/WMS/WMS_Server/WIDESEA_WebApi/Controllers/ToWms/ToWMSController.cs          |   11 
 14 files changed, 984 insertions(+), 610 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_Entity/DomainModels/ToAGV/AGVRequestin.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_Entity/DomainModels/ToAGV/AGVRequestin.cs"
index b94a7fe..f169246 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_Entity/DomainModels/ToAGV/AGVRequestin.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_Entity/DomainModels/ToAGV/AGVRequestin.cs"
@@ -24,6 +24,11 @@
 
     public class AGVGteaddress
     {
+
+        /// <summary>
+        /// 浣滀笟浠诲姟鍙�
+        /// </summary>
+        public string TASK_NO { get; set; }
         /// <summary>
         /// 璐т綅鍙�
         /// </summary>
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Common/AGVandPipeline.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Common/AGVandPipeline.cs"
index bd5144e..dea096c 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Common/AGVandPipeline.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Common/AGVandPipeline.cs"
@@ -22,12 +22,12 @@
         public static Signal GetSignal(string address)
         {
             Signal signal = new Signal();
-            AGVGteaddress gteaddress=new AGVGteaddress();
+            AGVGteaddress gteaddress = new AGVGteaddress();
             try
             {
                 if (string.IsNullOrEmpty(address) || address == "null")
                     throw new Exception("鏈幏鍙栧埌璇锋眰鍙傛暟鏁版嵁");
-                 gteaddress = JsonConvert.DeserializeObject<AGVGteaddress>(address);
+                gteaddress = JsonConvert.DeserializeObject<AGVGteaddress>(address);
 
                 var Pipeline_client = PLCClient.Clients.FirstOrDefault(t => t.PLCName == "閾炬潯鏈�");
                 if (Pipeline_client == null) throw new Exception("閾炬潯鏈鸿皟搴︽湇鍔℃湭寮�鍚紒");
@@ -40,7 +40,7 @@
             {
                 signal.Message = ex.Message;
             }
-            WritePCSLog.LogAdd(address, signal.success == 1 ? "鎴愬姛 " : "澶辫触", "PCS", "AGV", address, JsonConvert.SerializeObject(signal), $"AGV鑾峰彇{gteaddress.address}鍏夌數淇″彿", "GetSignal", signal.Message);
+            WritePCSLog.LogAdd(address, signal.success == 1 ? "鎴愬姛 " : "澶辫触", "PCS", "AGV", address, JsonConvert.SerializeObject(signal), $"{gteaddress.TASK_NO}鐨凙GV鑾峰彇{gteaddress.address}鍏夌數淇″彿", "GetSignal", signal.Message);
             return signal;
         }
     }
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Common/Gantry.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Common/Gantry.cs"
index ae19956..c5d9223 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Common/Gantry.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Common/Gantry.cs"
@@ -388,43 +388,21 @@
                         var NGStation = "X01001003";
                         if (name == "2鍗曞厓涓嬫枡鍖�") NGStation = "X02001003";
                         if (name == "3鍗曞厓涓嬫枡鍖�") NGStation = "X03001002";
-                        #region MyRegion
-                        //var Wheel_Type = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Wheel_Type").First(), client);//杞﹁疆绫诲瀷
-                        //var Wheel_id = client.ReadByOrder<string>("R_Wheel_id", name);//杞﹁疆SN鍙�
-                        //if (string.IsNullOrEmpty(Wheel_id)) continue;
-                        ////var Wheel_id = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Wheel_id").First(), client).ToString();
-
-                        //var mes_Detail = mes_DetailRepository.FindFirst(x => x.SN == Wheel_id);
-                        //if (mes_Detail == null)
-                        //{
-                        //    #region 鏃ュ織璁板綍
-                        //    WriteDBLog.Error(name, $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN锛歿Wheel_id}\n\n鏈煡璇㈠埌宸ュ崟璇︽儏", "PCS");
-                        //    #endregion
-                        //    continue;
-                        //}
-                        //var mes_Head = mes_HeadRepository.FindFirst(x => x.jobID == mes_Detail.jobID);
-                        //if (mes_Head == null)
-                        //{
-                        //    #region 鏃ュ織璁板綍
-                        //    WriteDBLog.Error(name, $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN锛歿Wheel_id}\n\n鏈煡璇㈠埌宸ュ崟澶磋〃", "PCS");
-                        //    #endregion
-                        //    continue;
-                        //}
-                        #endregion
 
                         var finished = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_load_finished").First(), client);//鏀炬枡瀹屾垚
                         var updatefinished = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "W_Storage_update").First(), client);//璐т綅鐘舵�佹洿鏂�
 
                         #region 璐т綅鐘舵�佹洿鏂板浣�
-                        //if (!finished && updatefinished)
-                        //{
-                        //    client.WriteByOrder("W_Storage_update", false, name);//璐т綅鐘舵�佹洿鏂�
-                        //    #region 鏃ュ織璁板綍
-                        //    WriteDBLog.Success(name + "璐т綅鐘舵�佹洿鏂板浣�", $"璇诲彇妗佹灦淇℃伅锛歕nR_load_finished锛歿finished}\n\n鍐欏叆妗佹灦淇℃伅锛歕nW_Storage_update锛歠alse", "PCS");
-                        //    #endregion
-                        //}
+                        if (!finished && updatefinished)
+                        {
+                            client.WriteByOrder("W_Storage_update", false, name);//璐т綅鐘舵�佹洿鏂�
+                            #region 鏃ュ織璁板綍
+                            //WriteDBLog.Success(name + "璐т綅鐘舵�佹洿鏂板浣�", $"璇诲彇妗佹灦淇℃伅锛歕nR_load_finished锛歿finished}\n\n鍐欏叆妗佹灦淇℃伅锛歕nW_Storage_update锛歿false}", "PCS");
+                            WriteLog.Write_Log(name + "鏀炬枡瀹屾垚", name + "璐т綅鐘舵�佹洿鏂颁俊鍙峰浣�", "鎴愬姛锛�",
+                                $"璇诲彇妗佹灦淇℃伅锛歕n鏀炬枡瀹屾垚淇″彿锛歿finished}\n\n鍐欏叆妗佹灦淇℃伅锛歕n璐т綅鐘舵�佹洿鏂颁俊鍙凤細{false}");
+                            #endregion
+                        }
                         #endregion
-
 
                         if (finished && !updatefinished)
                         {
@@ -450,24 +428,6 @@
                                 #endregion
                                 continue;
                             }
-                            #region MyRegion
-                            //var Detail = mes_DetailRepository.FindFirst(x => x.SN == Wheel_SN);
-                            //if (Detail == null)
-                            //{
-                            //    #region 鏃ュ織璁板綍
-                            //    WriteDBLog.Error(name, $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN鍙凤細{Wheel_SN}\n\n鏈煡璇㈠埌宸ュ崟璇︽儏", "PCS");
-                            //    #endregion
-                            //    continue;
-                            //}
-                            //var Head = mes_HeadRepository.FindFirst(x => x.jobID == Detail.jobID && x.processCode == "17");
-                            //if (Head == null)
-                            //{
-                            //    #region 鏃ュ織璁板綍
-                            //    WriteDBLog.Error(name, $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN鍙凤細{Wheel_SN}\n\n鏈煡璇㈠埌宸ュ崟澶磋〃{Detail.jobID}", "PCS");
-                            //    #endregion
-                            //    continue;
-                            //}
-                            #endregion
 
                             #endregion
 
@@ -478,88 +438,90 @@
                                 continue;
                             }
 
+                            #region 鍒ゆ柇鍖哄煙鍙锋槸鍚︿竴鑷�
+                            var area = client.ReadByOrder<Int16>("place_prog", name);//鏀炬枡瀹屾垚鐨勫尯鍩熷彿
+                            
+                            if (AreaNr != area)
+                            {
+                                Pipeline_client.WriteByOrder("W_AlarmSignal", (Int16)2, name);//鎶ヨ
+                                //WriteDBLog.Error(name + "鎶ヨ", $"PCS鍖哄煙鍙凤細{AreaNr}锛涙鏋跺尯鍩熷彿锛歿area}閿欒淇℃伅锛歅CS鍖哄煙鍙蜂笌妗佹灦鍖哄煙鍙蜂笉涓�鑷达紒", "PCS");
+                                WriteLog.Write_Log(name + "鏀炬枡瀹屾垚鍑洪敊", Wheel_SN, "鍒ゆ柇鍖哄煙鍙锋槸鍚︿竴鑷�", $"PCS鍖哄煙鍙凤細{AreaNr}锛沑n妗佹灦鍖哄煙鍙凤細{area}\n閿欒淇℃伅锛歅CS鍖哄煙鍙蜂笌妗佹灦鍖哄煙鍙蜂笉涓�鑷达紒");
+                                continue;
+                            }
+                            #endregion
 
                             var areaCode = PipelineJob.area_code(name);   //鏍规嵁涓嬫枡鍙e崟鍏冨悕鑾峰彇鍖哄煙浠g爜
-                            var station = stationinfoRepository.FindFirst(x => x.area == areaCode && x.stationCode.Substring(x.stationCode.Length - 1, 1) == AreaNr.ToString());
-                            if (station.quantity >= 5)
-                                throw new Exception($"涓嬫枡浣嶄俊鎭洿鏂板け璐ワ紒涓嬫枡浣嶈溅杞暟閲忓ぇ浜�5锛歿station.stationCode}");
-                            //station.bindSN = station.bindSN == string.Empty ? Wheel_id : station.bindSN + "," + Wheel_id;
-                            if (!string.IsNullOrEmpty(station.bindSN))
+                            var station = stationinfoRepository.Find(x => x.area == areaCode && x.stationCode.Substring(x.stationCode.Length - 1, 1) == AreaNr.ToString()).FirstOrDefault();
+                            if (station != null)
                             {
-                                if (station.bindSN.Contains(Wheel_SN))
-                                    throw new Exception($"{station.stationCode}宸插瓨鍦ㄨ溅杞甋N鍙凤細{Wheel_SN}");
+                                if (station.quantity >= 5)
+                                {
+                                    Pipeline_client.WriteByOrder("W_AlarmSignal", (Int16)2, name);//鎶ヨ
+                                    WriteLog.Write_Log(name + "鏀炬枡瀹屾垚鍑洪敊", Wheel_SN, "杞﹁疆鏁伴噺宸叉弧锛�", $"鍖哄煙鍙凤細{AreaNr}锛沑n杞﹁疆鏁帮細{station.quantity}\n閿欒淇℃伅锛氬尯鍩熷彿杞﹁疆鏁伴噺宸叉弧锛�");
+                                }
+
+                                #region 鍒ゆ柇杞﹁疆鏁伴噺鏄惁涓�鑷�
+                                var quantity = client.ReadByOrder<Int16>("pos_prog", name);//妗佹灦璁板綍鐨勮溅杞暟閲�
+
+                                if (quantity != station.quantity + 1)
+                                {
+                                    Pipeline_client.WriteByOrder("W_AlarmSignal", (Int16)2, name);//鎶ヨ
+                                    WriteLog.Write_Log(name + "鏀炬枡瀹屾垚鍑洪敊", Wheel_SN, "鍒ゆ柇杞﹁疆鏁伴噺鏄惁涓�鑷�", $"鍖哄煙鍙凤細{AreaNr}锛沑n妗佹灦杞﹁疆鏁帮細{quantity}\nPCS杞﹁疆鏁帮細{station.quantity + 1}\n閿欒淇℃伅锛歅CS鍖哄煙鍙蜂笌妗佹灦鍖哄煙鍙蜂笉涓�鑷达紒");
+                                    continue;
+                                }
+                                #endregion
+
+                                if (!string.IsNullOrEmpty(station.bindSN))
+                                {
+                                    if (station.bindSN.Contains(Wheel_SN))
+                                        throw new Exception($"{station.stationCode}宸插瓨鍦ㄨ溅杞甋N鍙凤細{Wheel_SN}");
+                                }
+
+                                station.bindSN = string.IsNullOrEmpty(station.bindSN) ? Wheel_SN : station.bindSN + "," + Wheel_SN;
+                                station.billetID = string.IsNullOrEmpty(station.billetID) ? Mes_Work.billetID.ToString() : station.billetID + "," + Mes_Work.billetID;
+                                station.quantity++;
+                                if (station.quantity == 1)
+                                {
+                                    station.stationType = Mes_Work.drawingNo;
+                                    station.Number = Mes_Work.workOrder;
+                                    station.heatNumber = Mes_Work.heatID;
+                                    station.tray_status = "StrogeTray";
+                                }
+
+                                var count = stationinfoRepository.Update(station, true);
+                                if (count < 1)
+                                    throw new Exception($"涓嬫枡浣嶄俊鎭洿鏂板け璐ワ紒涓嬫枡浣嶇紪鍙凤細{station.stationCode}");
+
+                                #region 娓呯┖缁欐鏋剁殑涓嬫枡淇℃伅
+                                client.WriteByOrder("W_IndexNr", (Int16)0, name);//鎵樼洏涓婄殑绗嚑涓溅杞�
+                                client.WriteByOrder("W_Storage_Type", (Int16)0, name);//鎵樼洏绫诲瀷1-妯斁;2-绔栨斁(鏆傛椂鍙湁妯斁鎵樼洏)
+                                client.WriteByOrder("W_AreaNr", (Int16)0, name);//鍖哄煙璐т綅鍙�
+                                client.WriteByOrder("W_Storage_update", true, name);//璐т綅鐘舵�佹洿鏂�
+                                WriteLog.Write_Log(name + "鏀炬枡瀹屾垚", Wheel_SN, "鎴愬姛锛�",
+                                    $"璇诲彇妗佹灦淇℃伅锛歕n鏀炬枡瀹屾垚淇″彿锛歿finished}\n杞﹁疆SN锛歿Wheel_SN}\n杞瀷ID锛歿WheelType}\n涓嬫枡浣嶅彿锛歿AreaNr}\n\n" +
+                                    $"澶勭悊鍐欏叆妗佹灦淇℃伅锛歕n鍖哄煙璐т綅鍙凤細{0}\n鎵樼洏涓婄殑绗嚑涓溅杞細{0}\n鎵樼洏绫诲瀷锛歿0}\n\n" +
+                                    $"鍐欏叆妗佹灦淇℃伅锛歕n璐т綅鐘舵�佹洿鏂颁俊鍙凤細{true}\n鏄惁鍏佽涓嬫枡锛歿false}");
+                                //WriteDBLog.Success(name + "妗佹灦涓嬫枡瀹屾垚",
+                                //    $"璇诲彇妗佹灦淇℃伅锛歕nR_load_finished锛歿finished}\n杞﹁疆SN锛歿Wheel_SN}\n杞瀷ID锛歿WheelType}\n涓嬫枡浣嶅彿锛歿AreaNr}\n\n" +
+                                //    $"澶勭悊鍐欏叆妗佹灦淇℃伅锛歕nW_AreaNr锛歿0}\nW_IndexNr锛歿0}\nW_Storage_Type锛歿0}\n\n" +
+                                //    $"鍐欏叆妗佹灦淇℃伅锛歕nW_Storage_update锛歿true}\nW_Enabl_Load锛歿false}", "PCS");
+                                #endregion
+
+                                #region 淇敼宸ュ崟鐘舵��
+                                var Detail = mes_DetailRepository.FindFirst(x => x.jobID == Mes_Work.jobID && x.SN == Mes_Work.SN);
+                                Detail.Status = "涓嬬嚎";
+                                Detail.FinishTime = DateTime.Now;
+                                count = mes_DetailRepository.Update(Detail, true);
+                                if (count < 1)
+                                    throw new Exception($"宸ュ崟瀛愯〃淇℃伅鏇存柊澶辫触锛佽溅杞甋N鍙凤細{Detail.SN}");
+                                var Head = mes_HeadRepository.FindFirst(x => x.jobID == Detail.jobID);
+                                Head.finishNum = Head.finishNum + 1;
+                                count = mes_HeadRepository.Update(Head, true);
+                                if (count < 1)
+                                    throw new Exception($"宸ュ崟澶磋〃淇℃伅鏇存柊澶辫触锛佸伐鍗曞彿锛歿Head.jobID}");
+                                #endregion
                             }
-
-                            station.bindSN = string.IsNullOrEmpty(station.bindSN) ? Wheel_SN : station.bindSN + "," + Wheel_SN;
-                            station.billetID = string.IsNullOrEmpty(station.billetID) ? Mes_Work.billetID.ToString() : station.billetID + "," + Mes_Work.billetID;
-                            station.quantity++;
-                            if (station.quantity == 1)
-                            {
-                                station.stationType = Mes_Work.drawingNo;
-                                station.Number = Mes_Work.workOrder;
-                                station.heatNumber = Mes_Work.heatID;
-                                station.tray_status = "StrogeTray";
-                            }
-                            //else if (station.stationCode == NGStation)
-                            //{
-                            //    station.heatNumber = string.IsNullOrEmpty(station.heatNumber) ? Mes_Work.heatID : station.heatNumber + "," + Mes_Work.heatID;
-                            //}
-
-                            var count = stationinfoRepository.Update(station, true);
-                            if (count < 1)
-                                throw new Exception($"涓嬫枡浣嶄俊鎭洿鏂板け璐ワ紒涓嬫枡浣嶇紪鍙凤細{station.stationCode}");
-
-                            #region 娓呯┖缁欐鏋剁殑涓嬫枡淇℃伅
-                            client.WriteByOrder("W_AreaNr", (Int16)0, name);//鍖哄煙璐т綅鍙�
-                            client.WriteByOrder("W_IndexNr", (Int16)0, name);//鎵樼洏涓婄殑绗嚑涓溅杞�
-                            client.WriteByOrder("W_Storage_Type", (Int16)0, name);//鎵樼洏绫诲瀷1-妯斁;2-绔栨斁(鏆傛椂鍙湁妯斁鎵樼洏)
-                            client.WriteByOrder("W_Storage_update", true, name);//璐т綅鐘舵�佹洿鏂�
-                            WriteLog.Write_Log(name + "鏀炬枡瀹屾垚", Wheel_SN, "鎴愬姛锛�",
-                                $"璇诲彇妗佹灦淇℃伅锛歕n鏀炬枡瀹屾垚淇″彿锛歿finished}\n杞﹁疆SN锛歿Wheel_SN}\n杞瀷ID锛歿WheelType}\n涓嬫枡浣嶅彿锛歿AreaNr}\n\n" +
-                                $"澶勭悊鍐欏叆妗佹灦淇℃伅锛歕n鍖哄煙璐т綅鍙凤細{0}\n鎵樼洏涓婄殑绗嚑涓溅杞細{0}\n鎵樼洏绫诲瀷锛歿0}\n\n" +
-                                $"鍐欏叆妗佹灦淇℃伅锛歕n璐т綅鐘舵�佹洿鏂颁俊鍙凤細{true}\n鏄惁鍏佽涓嬫枡锛歿false}");
-                            //WriteDBLog.Success(name + "妗佹灦涓嬫枡瀹屾垚",
-                            //    $"璇诲彇妗佹灦淇℃伅锛歕nR_load_finished锛歿finished}\n杞﹁疆SN锛歿Wheel_SN}\n杞瀷ID锛歿WheelType}\n涓嬫枡浣嶅彿锛歿AreaNr}\n\n" +
-                            //    $"澶勭悊鍐欏叆妗佹灦淇℃伅锛歕nW_AreaNr锛歿0}\nW_IndexNr锛歿0}\nW_Storage_Type锛歿0}\n\n" +
-                            //    $"鍐欏叆妗佹灦淇℃伅锛歕nW_Storage_update锛歿true}\nW_Enabl_Load锛歿false}", "PCS");
-                            #endregion
-
-
-                            //client.WriteByOrder("W_Enabl_Load", false, name);//鏄惁鍏佽
-
-                            #region 淇敼宸ュ崟鐘舵��
-                            var Detail = mes_DetailRepository.FindFirst(x => x.jobID == Mes_Work.jobID && x.SN == Mes_Work.SN);
-                            Detail.Status = "涓嬬嚎";
-                            Detail.FinishTime = DateTime.Now;
-                            count = mes_DetailRepository.Update(Detail, true);
-                            if (count < 1)
-                                throw new Exception($"宸ュ崟瀛愯〃淇℃伅鏇存柊澶辫触锛佽溅杞甋N鍙凤細{Detail.SN}");
-                            var Head = mes_HeadRepository.FindFirst(x => x.jobID == Detail.jobID);
-                            Head.finishNum = Head.finishNum + 1;
-                            count = mes_HeadRepository.Update(Head, true);
-                            if (count < 1)
-                                throw new Exception($"宸ュ崟澶磋〃淇℃伅鏇存柊澶辫触锛佸伐鍗曞彿锛歿Head.jobID}");
-                            #endregion
-
-                            #region 鏃ュ織璁板綍
-                            //WriteDBLog.Success(name + "鏀炬枡瀹屾垚", $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN锛歿Wheel_id}\n杞瀷ID锛歿Wheel_Type}\n涓嬫枡浣嶅彿锛歿AreaNr}" +
-                            //    $"\n\n鍐欏叆妗佹灦淇℃伅锛歕nW_Storage_update锛歵rue" + $"\nW_Enabl_Load锛歠alse", "PCS");
-                            #endregion
                         }
-
-                        #region 璐т綅鐘舵�佹洿鏂板浣�
-                        finished = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_load_finished").First(), client);//鏀炬枡瀹屾垚
-                        updatefinished = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "W_Storage_update").First(), client);//璐т綅鐘舵�佹洿鏂�
-                        if (!finished && updatefinished)
-                        {
-                            client.WriteByOrder("W_Storage_update", false, name);//璐т綅鐘舵�佹洿鏂�
-                            #region 鏃ュ織璁板綍
-                            //WriteDBLog.Success(name + "璐т綅鐘舵�佹洿鏂板浣�", $"璇诲彇妗佹灦淇℃伅锛歕nR_load_finished锛歿finished}\n\n鍐欏叆妗佹灦淇℃伅锛歕nW_Storage_update锛歿false}", "PCS");
-                            WriteLog.Write_Log(name + "鏀炬枡瀹屾垚", name + "璐т綅鐘舵�佹洿鏂颁俊鍙峰浣�", "鎴愬姛锛�",
-                                $"璇诲彇妗佹灦淇℃伅锛歕n鏀炬枡瀹屾垚淇″彿锛歿finished}\n\n鍐欏叆妗佹灦淇℃伅锛歕n璐т綅鐘舵�佹洿鏂颁俊鍙凤細{false}");
-                            #endregion
-                        }
-                        #endregion
 
                         var Request = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Request_Load").First(), client);
                         if (!Request) continue;
@@ -585,39 +547,18 @@
                             WriteLog.Write_Log(name + "鐢宠鏀炬枡寮傚父", Wheel_id, "鏌ヨ鏈哄姞宸ュ伐鍗�", $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN鍙凤細{Wheel_id}鏈煡璇㈠埌宸ュ崟淇℃伅\n鍐欏叆妗佹灦淇℃伅锛歕n鏄惁鍏佽涓嬫枡锛歿false}");
                         }
 
-                        #region MyRegion
-                        //var mes_Detail = mes_DetailRepository.FindFirst(x => x.SN == Wheel_id);
-                        //if (mes_Detail == null)
-                        //{
-                        //    #region 鏃ュ織璁板綍
-                        //    client.WriteByOrder("W_Enabl_Load", false, name);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
-                        //    WriteDBLog.Error(name, $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN锛歿Wheel_id}\n\n鏈煡璇㈠埌宸ュ崟璇︽儏", "PCS");
-                        //    #endregion
-                        //    continue;
-                        //}
-                        //var mes_Head = mes_HeadRepository.FindFirst(x => x.jobID == mes_Detail.jobID);
-                        //if (mes_Head == null)
-                        //{
-                        //    #region 鏃ュ織璁板綍
-                        //    client.WriteByOrder("W_Enabl_Load", false, name);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
-                        //    WriteDBLog.Error(name, $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN锛歿Wheel_id}\n\n鏈煡璇㈠埌宸ュ崟澶磋〃", "PCS");
-                        //    #endregion
-                        //    continue;
-                        //}
-                        #endregion
 
                         #endregion
 
 
                         var Stations = stationinfoRepository.Find(x => x.area == PipelineJob.area_code(name)).OrderBy(x => x.lastUpdateTime).ToList();
 
-
-
-                        //foreach (var station in Stations)     //浠讳綍涓�涓笅鏂欎綅涓虹┖鎴栫鐢ㄦ椂,閮戒細鍋滄妗佹灦
-                        //{
-                        //    if (!station.enable || station.location_state == LocationStateEnum.Empty.ToString())
-                        //        client.WriteByOrder("W_Enabl_Load", false, name);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
-                        //}
+                        #region 涓嬫枡浣嶆槸鍚︿负绌虹姸鎬佸悓姝ョ粰妗佹灦
+                        foreach (var station in Stations)
+                        {
+                            client.WriteByOrder(station.stationCode, station.location_state != LocationStateEnum.Stroge.ToString(), name);
+                        }
+                        #endregion
 
                         #region MyRegion
                         //var currentAreaNr = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "W_Are00aNr").First(), client);
@@ -648,6 +589,8 @@
                         WriteLog.Write_Log(name + "鐢宠鏀炬枡", Wheel_id, "鐢宠鏀炬枡", $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN锛歿Wheel_id}\n杞瀷ID锛歿Wheel_Type}\n杞﹁疆鐘舵�侊細{PartStatus}\n鏄惁杩涘叆涓嬫枡鍖猴細{load_zone}");
                         if (load_zone) continue;
                         #endregion
+
+                        #region 鍚堟牸
                         if ((Int16)PartStatus == 1)
                         {
                             dt_stationinfo Stationinfo = null;
@@ -659,7 +602,6 @@
                            && x.location_state == LocationStateEnum.Stroge.ToString()
                            && x.quantity < 5
                            && x.stationType == Work.drawingNo
-                           //&& x.tray_type == ((wheel == null ? wheel1.e : wheel.e) < 1100 ? "SmallTray" : "LargeTray")
                            && x.Number == Work.workOrder
                            && x.heatNumber == Work.heatID)
                            .OrderByDescending(x => x.quantity)
@@ -673,7 +615,6 @@
                            && x.location_state == LocationStateEnum.Stroge.ToString()
                            && x.quantity < 5
                            && x.stationType == Work.drawingNo
-                           //&& x.tray_type == ((wheel == null ? wheel1.e : wheel.e) < 1100 ? "SmallTray" : "LargeTray")
                            && x.Number == Work.workOrder)
                            .OrderByDescending(x => x.quantity)
                            .FirstOrDefault();
@@ -681,16 +622,6 @@
 
                             if (Stationinfo == null)
                             {
-
-                                #region 涓嬫枡浣嶆潯浠朵笉鍖归厤鐩存帴瑙﹀彂鍏ュ簱浠诲姟
-                                //var stationinfos = Stations.Where(x => x.enable && x.stationCode != NGStation && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).ToList();
-                                //foreach (var stationinfo in stationinfos)
-                                //{
-                                //    agvtask(stationinfoRepository, stationinfo, (wheel == null ? wheel1.e : wheel.e), name == "3鍗曞厓涓嬫枡鍖�" ? "TaskType_OutsourceInbound" : "TaskType_Inbound");
-                                //}
-                                #endregion
-
-
                                 #region 瑙﹀彂NG浠诲姟
                                 var NG = Stations.Where(x => x.enable && x.stationCode == NGStation && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).FirstOrDefault();
                                 if (NG != null)
@@ -702,13 +633,6 @@
 
                                 Stationinfo = Stations.Where(x => x.enable && x.stationCode != NGStation && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity == 0).FirstOrDefault();
 
-                                #region MyRegion
-                                //var stationinfo = Stations.Where(x => x.enable && x.stationCode != NGStation && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).FirstOrDefault();
-                                //if (stationinfo != null)
-                                //{
-                                //    agvtask(stationinfoRepository, mes_Head, stationinfo, (wheel == null ? wheel1.e : wheel.e), name == "3鍗曞厓涓嬫枡鍖�" ? "TaskType_OutsourceInbound" : "TaskType_Inbound");
-                                //}
-                                #endregion
                             }
 
                             if (Stationinfo != null)
@@ -731,7 +655,6 @@
                                 #endregion
 
                                 #region 鎵樼洏绫诲瀷涓嶄竴鑷撮渶鏇存崲鎵樼洏
-                                //if (Stationinfo.tray_type != ((wheel == null ? wheel1.e : wheel.e) < 1100 ? "SmallTray" : "LargeTray"))
                                 if (Stationinfo.tray_type != "LargeTray" && (wheel == null ? wheel1.e : wheel.e) > 1100)
                                 {
                                     client.WriteByOrder("W_Enabl_Load", false, name);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
@@ -748,7 +671,6 @@
 
                                 var MaterialSignal = (Int16)DBExtension.Read(Pipelinedetails.Where(x => x.plcdetail_name == "R_MaterialSignal").First(), Pipeline_client);//璇诲彇璐х墿淇″彿:1:鏈�,2鏃�
 
-                                //var Wheel_id = client.ReadByOrder<string>("R_Wheel_id", name);
                                 if (PalletSignal == 1)
                                 {
                                     List<string> list = new List<string>();
@@ -763,25 +685,26 @@
                                     }
 
                                     #region 璐т綅鏁伴噺涓庡厜鐢典笉鍖归厤锛屾姤璀�
-                                    if (list.Count > 0 && MaterialSignal != 1)
-                                    {
-                                        client.WriteByOrder("W_Enabl_Load", false, name);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
-                                        Pipeline_client.WriteByOrder("W_AlarmSignal", (Int16)2, name);//鎶ヨ
-                                        Stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
-                                        Stationinfo.remark = "杞﹁疆鏁伴噺涓庡厜鐢典笉鍖归厤";
-                                        stationinfoRepository.Update(Stationinfo, true);
-                                        WriteDBLog.Error(name + "鎶ヨ", $"璐т綅缂栧彿锛歿Stationinfo.stationCode}锛涢敊璇俊鎭細{Stationinfo.remark}", "PCS");
-                                        //WriteDBLog.Error(name+"鐢宠涓嬫枡",$"{Stationinfo.stationCode}鐨勮揣浣�","PCS");
-                                    }
-                                    else if (list.Count < 1 && MaterialSignal == 1)
-                                    {
-                                        client.WriteByOrder("W_Enabl_Load", false, name);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
-                                        Pipeline_client.WriteByOrder("W_AlarmSignal", (Int16)2, name);//鎶ヨ
-                                        Stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
-                                        Stationinfo.remark = "杞﹁疆鏁伴噺涓庡厜鐢典笉鍖归厤";
-                                        stationinfoRepository.Update(Stationinfo, true);
-                                        WriteDBLog.Error(name + "鎶ヨ", $"璐т綅缂栧彿锛歿Stationinfo.stationCode}锛涢敊璇俊鎭細{Stationinfo.remark}", "PCS");
-                                    }
+                                    //if (list.Count > 0 && MaterialSignal != 1)
+                                    //{
+                                    //    client.WriteByOrder("W_Enabl_Load", false, name);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
+                                    //    Pipeline_client.WriteByOrder("W_AlarmSignal", (Int16)2, name);//鎶ヨ
+                                    //    Stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
+                                    //    Stationinfo.remark = "杞﹁疆鏁伴噺涓庡厜鐢典笉鍖归厤";
+                                    //    stationinfoRepository.Update(Stationinfo, true);
+                                    //    WriteDBLog.Error(name + "鎶ヨ", $"璐т綅缂栧彿锛歿Stationinfo.stationCode}锛涢敊璇俊鎭細{Stationinfo.remark}", "PCS");
+                                    //    continue;
+                                    //}
+                                    //else if (list.Count < 1 && MaterialSignal == 1)
+                                    //{
+                                    //    client.WriteByOrder("W_Enabl_Load", false, name);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
+                                    //    Pipeline_client.WriteByOrder("W_AlarmSignal", (Int16)2, name);//鎶ヨ
+                                    //    Stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
+                                    //    Stationinfo.remark = "杞﹁疆鏁伴噺涓庡厜鐢典笉鍖归厤";
+                                    //    stationinfoRepository.Update(Stationinfo, true);
+                                    //    WriteDBLog.Error(name + "鎶ヨ", $"璐т綅缂栧彿锛歿Stationinfo.stationCode}锛涢敊璇俊鎭細{Stationinfo.remark}", "PCS");
+                                    //    continue;
+                                    //}
 
                                     #endregion
 
@@ -819,44 +742,20 @@
                                     var station = Stations.Where(x => x.enable && x.stationCode != NGStation).OrderBy(x => x.lastUpdateTime).FirstOrDefault();
                                     agvtask(stationinfoRepository, station, Work, name == "3鍗曞厓涓嬫枡鍖�" ? "TaskType_OutsourceInbound" : "TaskType_Inbound");
                                 }
-
-                                //var stationinfos = Stations.Where(x => x.enable && x.Number != Work.workOrder && x.stationCode != NGStation && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).ToList();
-                                //foreach (var stationinfo in stationinfos)
-                                //{
-                                //    agvtask(stationinfoRepository, stationinfo, Work, name == "3鍗曞厓涓嬫枡鍖�" ? "TaskType_OutsourceInbound" : "TaskType_Inbound");
-                                //}
                                 #endregion
                             }
 
                         }
+                        #endregion
+
+                        #region 涓嶅悎鏍�
                         else if ((Int16)PartStatus == 2)
                         {
-                            dt_stationinfo Stationinfo = null;
-                            //if (mes_Detail.heatID != null)
-                            //{
-                            //    Stationinfo = Stations
-                            //.Where(x => x.enable
-                            //&& x.stationCode == NGStation
-                            //&& x.location_state == LocationStateEnum.Stroge.ToString()
-                            //&& x.quantity < 5
-                            //&& x.stationType == mes_Head.drawingNo
-                            //&& x.tray_type == ((wheel == null ? wheel1.e : wheel.e) < 1100 ? "SmallTray" : "LargeTray")
-                            //&& x.Number == mes_Detail.jobID
-                            //&& x.heatNumber == mes_Detail.heatID).FirstOrDefault();
-                            //}
-                            //else
-                            //{
-                            //var tray_type = "SmallTray";
-                            //if ((wheel == null ? wheel1.e : wheel.e) > 1100) tray_type = "LargeTray";
-                            Stationinfo = Stations
-                        .Where(x => x.enable
-                        && x.stationCode == NGStation
-                        && x.location_state == LocationStateEnum.Stroge.ToString()
-                        && x.quantity < 5
-                        && x.stationType == Work.drawingNo
-                        //&& x.tray_type == ((wheel == null ? wheel1.e : wheel.e) < 1100 ? "SmallTray" : "LargeTray")
-                        /*&& x.Number == mes_Detail.jobID*/).FirstOrDefault();
-                            //}
+                            dt_stationinfo Stationinfo = Stations.Where(x => x.enable
+                            && x.stationCode == NGStation
+                            && x.location_state == LocationStateEnum.Stroge.ToString()
+                            && x.quantity < 5
+                            && x.stationType == Work.drawingNo).FirstOrDefault();
 
                             if (Stationinfo == null)
                             {
@@ -901,31 +800,25 @@
                                     }
 
                                     #region 璐т綅鏁伴噺涓庡厜鐢典笉鍖归厤锛屾姤璀�
+
                                     //if (list.Count > 0 && MaterialSignal != 1)
+                                    //{
+                                    //    client.WriteByOrder("W_Enabl_Load", false, name);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
                                     //    Pipeline_client.WriteByOrder("W_AlarmSignal", (Int16)2, name);//鎶ヨ
+                                    //    Stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
+                                    //    Stationinfo.remark = "杞﹁疆鏁伴噺涓庡厜鐢典笉鍖归厤";
+                                    //    stationinfoRepository.Update(Stationinfo, true);
+                                    //    WriteDBLog.Error(name + "鎶ヨ", $"璐т綅缂栧彿锛歿Stationinfo.stationCode}锛涢敊璇俊鎭細{Stationinfo.remark}", "PCS");
+                                    //}
                                     //else if (list.Count < 1 && MaterialSignal == 1)
+                                    //{
+                                    //    client.WriteByOrder("W_Enabl_Load", false, name);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
                                     //    Pipeline_client.WriteByOrder("W_AlarmSignal", (Int16)2, name);//鎶ヨ
-
-                                    if (list.Count > 0 && MaterialSignal != 1)
-                                    {
-                                        client.WriteByOrder("W_Enabl_Load", false, name);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
-                                        Pipeline_client.WriteByOrder("W_AlarmSignal", (Int16)2, name);//鎶ヨ
-                                        Stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
-                                        Stationinfo.remark = "杞﹁疆鏁伴噺涓庡厜鐢典笉鍖归厤";
-                                        stationinfoRepository.Update(Stationinfo, true);
-                                        WriteDBLog.Error(name + "鎶ヨ", $"璐т綅缂栧彿锛歿Stationinfo.stationCode}锛涢敊璇俊鎭細{Stationinfo.remark}", "PCS");
-
-                                        //WriteDBLog.Error(name+"鐢宠涓嬫枡",$"{Stationinfo.stationCode}鐨勮揣浣�","PCS");
-                                    }
-                                    else if (list.Count < 1 && MaterialSignal == 1)
-                                    {
-                                        client.WriteByOrder("W_Enabl_Load", false, name);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
-                                        Pipeline_client.WriteByOrder("W_AlarmSignal", (Int16)2, name);//鎶ヨ
-                                        Stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
-                                        Stationinfo.remark = "杞﹁疆鏁伴噺涓庡厜鐢典笉鍖归厤";
-                                        stationinfoRepository.Update(Stationinfo, true);
-                                        WriteDBLog.Error(name + "鎶ヨ", $"璐т綅缂栧彿锛歿Stationinfo.stationCode}锛涢敊璇俊鎭細{Stationinfo.remark}", "PCS");
-                                    }
+                                    //    Stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
+                                    //    Stationinfo.remark = "杞﹁疆鏁伴噺涓庡厜鐢典笉鍖归厤";
+                                    //    stationinfoRepository.Update(Stationinfo, true);
+                                    //    WriteDBLog.Error(name + "鎶ヨ", $"璐т綅缂栧彿锛歿Stationinfo.stationCode}锛涢敊璇俊鎭細{Stationinfo.remark}", "PCS");
+                                    //}
                                     #endregion
 
                                     //缂撳瓨鏋朵笂杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�
@@ -935,8 +828,6 @@
                                         Stationinfo.remark = "杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�";
                                         stationinfoRepository.Update(Stationinfo, true);
                                         continue;
-                                        //鍐欏叆妗佹灦鎶ヨ淇″彿
-                                        //throw new Exception("涓嬫枡浣嶈溅杞暟閲忎笌SN鍙锋暟閲忎笉涓�鑷达紝涓嬫枡浣嶇紪鍙凤細" + Stationinfo.stationCode);
                                     }
                                     var area = Convert.ToInt16(Stationinfo.stationCode.Substring(Stationinfo.stationCode.Length - 1, 1));
                                     client.WriteByOrder("W_AreaNr", (Int16)area, name);//鍖哄煙璐т綅鍙�
@@ -955,59 +846,8 @@
                                 }
                             }
                         }
-                        #region
-                        //var Stationinfo = Stations
-                        //    .Where(x => x.enable
-                        //    && x.location_state == LocationStateEnum.Stroge.ToString()
-                        //    && x.quantity < 5
-                        //    && x.stationType == PipelineJob.QueryMateriel(Wheel_Type)
-                        //    && x.Number == mes_Detail.jobID
-                        //    && x.heatNumber == mes_Detail.heatID).FirstOrDefault();
-                        //if (Stationinfo == null)
-                        //    Stationinfo = Stations.Where(x => x.enable && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity == 0).FirstOrDefault();
-                        //if (Stationinfo != null)
-                        //{
-
-                        //}
-
-                        //List<string> StationCodes = new List<string>() { "X01001001", "X01001002", "X01001003" };
-                        //if (name == "2鍗曞厓涓嬫枡鍖�")
-                        //    StationCodes = new List<string>() { "X02001001", "X02001002", "X02001003" };
-                        //if (name == "3鍗曞厓涓嬫枡鍖�")
-                        //    StationCodes = new List<string>() { "X03001001", "X03001002" };
-
                         #endregion
 
-                        #region
-                        //for (int i = 0; i < StationCodes.Count - 1; i++)
-                        //{
-                        //    var PartStatus = (Int32)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_PartStatus").First(), client);//1:ok;2:nok
-                        //    string NG = StationCodes[StationCodes.Count - 1];//NG璐т綅
-                        //    var station = stationinfoRepository.FindFirst(x => x.stationCode == StationCodes[i] && x.enable && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity < 5);
-                        //    if (station == null) continue;
-                        //    var Pipelinedetails = plcRepository.Find(x => x.plcdetail_iotype == Pipelineplc.plcinfo_iotyep && x.plcdetail_number == StationCodes[i]).ToList();
-                        //    var PalletSignal = (Int16)DBExtension.Read(Pipelinedetails.Where(x => x.plcdetail_name == "R_PalletSignal").First(), client);//璇诲彇鎵樼洏淇″彿:1:鏈�,2鏃�
-                        //    if (PalletSignal == 1)
-                        //    {
-                        //        if (PartStatus == 1 && NG != station.stationCode)
-                        //        {
-                        //            client.WriteByOrder("W_AreaNr", (Int16)i + 1, name);//鍖哄煙璐т綅鍙�
-                        //            client.WriteByOrder("W_IndexNr", (Int16)station.quantity + 1, name);//鎵樼洏涓婄殑绗嚑涓溅杞�
-                        //            client.WriteByOrder("W_Storage_Type", (Int16)1, name);//鎵樼洏绫诲瀷1-妯斁;2-绔栨斁(鏆傛椂鍙湁妯斁鎵樼洏)
-                        //            client.WriteByOrder("W_Enabl_Load", true, name);//鏄惁鍏佽
-                        //            return;
-                        //        }
-                        //        else if (PartStatus == 2 && NG == station.stationCode)
-                        //        {
-                        //            client.WriteByOrder("W_AreaNr", (Int16)i + 1, name);//鍖哄煙璐т綅鍙�
-                        //            client.WriteByOrder("W_IndexNr", (Int16)station.quantity + 1, name);//鎵樼洏涓婄殑绗嚑涓溅杞�
-                        //            client.WriteByOrder("W_Storage_Type", (Int16)1, name);//鎵樼洏绫诲瀷1-妯斁;2-绔栨斁(鏆傛椂鍙湁妯斁鎵樼洏)
-                        //            client.WriteByOrder("W_Enabl_Load", true, name);//鏄惁鍏佽
-                        //            return;
-                        //        }
-                        //    }
-                        //}
-                        #endregion
                     }
                     catch (Exception ex)
                     {
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Common/Pipeline.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Common/Pipeline.cs"
new file mode 100644
index 0000000..0fd93d7
--- /dev/null
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Common/Pipeline.cs"
@@ -0,0 +1,268 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using WIDESEA_Comm.LogInfo;
+using WIDESEA_Comm;
+using WIDESEA_Core.EFDbContext;
+using WIDESEA_WCS.IRepositories;
+using WIDESEA_WCS.Repositories;
+using WIDESEA_WCS.WCSClient;
+using WIDESEA_WMS.IRepositories;
+using WIDESEA_WMS.Repositories;
+using HslCommunication;
+using WIDESEA_Entity.DomainModels;
+
+namespace WIDESEA_WCS
+{
+    public class Pipeline
+    {
+        /// <summary>
+        /// 涓婃枡鍖�
+        /// </summary>
+        /// <param name="client"></param>
+        /// <param name="number"></param>
+        public void Loadinglevel(PLCClient client, string number = "涓婃枡鍖�")
+        {
+            try
+            {
+                VOLContext Context = new VOLContext();
+                Idt_plcinfoheadRepository repository = new dt_plcinfoheadRepository(Context);
+                Idt_plcinfodetailRepository plcRepository = new dt_plcinfodetailRepository(Context);
+                Idt_geometry_dataRepository dataRepository = new dt_geometry_dataRepository(Context);
+                Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
+                var plc = repository.FindFirst(x => x.plcinfo_name == client.PLCName);
+                var Gantry_client = PLCClient.Clients.FirstOrDefault(t => t.PLCName == "妗佹灦");
+                if (Gantry_client == null) throw new Exception("妗佹灦璋冨害鏈嶅姟鏈紑鍚紒");
+                if (!Gantry_client.IsConnected) throw new Exception("涓庢鏋惰繛鎺ヨ秴鏃讹紒");
+                var Gantryplc = repository.FindFirst(x => x.plcinfo_name == Gantry_client.PLCName);
+
+
+                ///鏌ユ壘涓婃枡鍖虹殑璐т綅
+                var Stations = stationinfoRepository.Find(x => x.area == area_code(number)).OrderBy(x => x.lastUpdateTime);//鏍规嵁鏃堕棿鍏堝悗鎺掑簭
+
+                var Station = Stations?.Where(x => x.enable && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).OrderBy(x => x.quantity).FirstOrDefault();
+                if (Station != null)
+                {
+
+                    var SNS = Station.bindSN.Split(",");
+
+                    var details = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep && x.plcdetail_number == Station.stationCode).ToList();
+                    var PalletSignal = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_PalletSignal").First(), client);//璇诲彇鎵樼洏淇″彿:1:鏈�,2鏃�
+                    var MaterialSignal = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_MaterialSignal").First(), client);//璇诲彇璐х墿淇″彿:1:鏈�,2鏃�
+                    #region 涓婃枡瀹屾垚
+                    var Gantrydetails = plcRepository.Find(x => x.plcdetail_iotype == Gantryplc.plcinfo_iotyep && x.plcdetail_number == number).ToList();
+                    var Gantry_Out_of_Area = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "R_Gantry_Out_of_Area").First(), Gantry_client);//妗佹灦鏄惁鍦ㄥ尯鍩熷唴
+
+                    var QueryDate = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "R_QueryDate").First(), Gantry_client);//淇℃伅鏌ヨ
+                    if (QueryDate)
+                    {
+                        var Date_Vaild = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "R_Date_Vaild").First(), Gantry_client);//淇℃伅纭
+                        if (!Date_Vaild)//淇℃伅鏈夎锛岃褰曟棩蹇�
+                        {
+                            Gantry_client.WriteByOrder("W_RequestUnload", false, number);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
+                            Station.location_state = LocationStateEnum.Abnormal.ToString();
+                            Station.remark = $"鏈煡璇㈠埌SN鍙凤細{SNS[SNS.Length - 1]}鐨勮鍗�";
+                            stationinfoRepository.Update(Station, true);
+                            WriteDBLog.Error("涓婃枡鍖轰俊鎭煡璇�", $"鍐欏叆妗佹灦淇℃伅锛歕nW_RequestUnload锛歠alse\n\n{Station.stationCode}鏈煡璇㈠埌SN鍙凤細{SNS[SNS.Length - 1]}鐨勮鍗�", "PCS");
+                            return;
+                        }
+                    }
+                    var finished = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "R_Unlod_finished").First(), Gantry_client);//澶瑰彇瀹屾垚
+                    var updatefinished = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "W_Storage_update").First(), Gantry_client);//璐т綅鐘舵�佹洿鏂�
+                    if (!finished && updatefinished)
+                        Gantry_client.WriteByOrder("W_Storage_update", false, number);//璐т綅鐘舵�佹洿鏂�
+                    if (finished && !updatefinished)
+                    {
+                        Gantry_client.WriteByOrder("W_RequestUnload", false, number);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
+                        Updatemes(SNS[SNS.Length - 1]);
+                        Station.quantity = Station.quantity - 1;
+                        Station.bindSN = OperStr(SNS);
+                        if (Station.quantity <= 0)
+                        {
+                            Station.stationType = string.Empty;
+                            Station.Number = string.Empty;
+                            Station.heatNumber = string.Empty;
+                            Station.tray_status = "EmptyTray";
+                        }
+                        var count = stationinfoRepository.Update(Station, true);
+                        if (count < 1)
+                        {
+                            WriteDBLog.Error("鍙栨枡瀹屾垚", $"涓婃枡浣嶄俊鎭洿鏂板け璐ワ紒涓婃枡浣嶇紪鍙凤細{Station.stationCode}", "PCS");
+                            return;
+                        }
+
+                        #region 娓呯┖淇℃伅
+                        Gantry_client.WriteByOrder("W_AreaNr", (Int16)0, number);//鍖哄煙璐т綅鍙�
+                        Gantry_client.WriteByOrder("W_IndexNr", (Int16)0, number);//鎵樼洏涓婄殑绗嚑涓溅杞�
+                        Gantry_client.WriteByOrder("W_Storage_Type", (Int16)0, number); //鎵樼洏绫诲瀷1-妯斁;2-绔栨斁
+                        Gantry_client.WriteByOrder("W_Wheel_Type", (Int16)0, number);//杞﹁疆绫诲瀷
+                        #endregion
+
+                        Gantry_client.WriteByOrder("W_Storage_update", true, number);//璐т綅鐘舵�佹洿鏂�
+                        #region 鏃ュ織璁板綍
+                        WriteDBLog.Success("鍙栨枡瀹屾垚", $"鍐欏叆妗佹灦淇℃伅锛歕n璐т綅鐘舵�佹洿鏂帮細{true}\nW_RequestUnload锛歿false}", "PCS");
+                        #endregion
+
+                        PalletSignal = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_PalletSignal").First(), client);//璇诲彇鎵樼洏淇″彿:1:鏈�,2鏃�
+                        MaterialSignal = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_MaterialSignal").First(), client);//璇诲彇璐х墿淇″彿:1:鏈�,2鏃�
+                        if (Station.quantity > 0 && (PalletSignal != 1 || MaterialSignal != 1))
+                        {
+                            Station.location_state = LocationStateEnum.Abnormal.ToString();
+                            Station.remark = "杞﹁疆鏁伴噺澶т簬0锛屽厜鐢垫娴嬫棤鎵樼洏鎴栨棤杞﹁疆";
+                            stationinfoRepository.Update(Station, true);
+                            client.WriteByOrder("W_AlarmSignal", (Int16)2, number);//鎶ヨ
+                            WriteDBLog.Error(number + "鎶ヨ", $"璐т綅缂栧彿锛歿Station.stationCode}锛涢敊璇俊鎭細{Station.remark}", "PCS");
+                        }
+                        else if (Station.quantity < 1 && MaterialSignal == 1)
+                        {
+                            Station.location_state = LocationStateEnum.Abnormal.ToString();
+                            Station.remark = "杞﹁疆鏁伴噺灏忎簬0锛屽厜鐢垫娴嬫湁杞﹁疆";
+                            stationinfoRepository.Update(Station, true);
+                            client.WriteByOrder("W_AlarmSignal", (Int16)2, number);//鎶ヨ
+                            WriteDBLog.Error(number + "鎶ヨ", $"璐т綅缂栧彿锛歿Station.stationCode}锛涢敊璇俊鎭細{Station.remark}", "PCS");
+                        }
+                    }
+                    #endregion
+
+                    #region 鐢宠涓婃枡
+                    //var SNS = Station.bindSN.Split(",");
+                    if (Gantry_client.ReadByOrder<bool>("W_RequestUnload", number)) return;
+
+                    Station = stationinfoRepository.Find(x => x.stationCode == Station.stationCode).FirstOrDefault();
+                    if (Station.quantity < 1) return;
+                    List<string> list = new List<string>();
+                    SNS = Station.bindSN.Split(",");
+                    foreach (var SN in SNS)
+                    {
+                        if (!string.IsNullOrEmpty(SN))
+                            list.Add(SN);
+                    }
+                    //缂撳瓨鏋朵笂杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�
+                    if (list.Count != Station.quantity)
+                    {
+                        Station.location_state = LocationStateEnum.Abnormal.ToString();
+                        Station.remark = "杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�";
+                        stationinfoRepository.Update(Station, true);
+                        Gantry_client.WriteByOrder("W_RequestUnload", false, number);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
+                        #region 鏃ュ織璁板綍
+                        WriteDBLog.Error("涓婃枡鍖�", $"鍐欏叆妗佹灦淇℃伅锛歕nW_RequestUnload锛歠alse\n\n{Station.stationCode}杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�", "PCS");
+                        #endregion
+                        return;
+                    }
+                    //var details = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep && x.plcdetail_number == Station.stationCode).ToList();
+                    PalletSignal = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_PalletSignal").First(), client);//璇诲彇鎵樼洏淇″彿:1:鏈�,2鏃�
+                    MaterialSignal = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_MaterialSignal").First(), client);//璇诲彇璐х墿淇″彿:1:鏈�,2鏃�
+
+                    var AreaNr = Gantry_client.ReadByOrder<Int16>("W_AreaNr", number);//璇诲彇璐т綅鍙蜂俊鎭�
+                    if (PalletSignal == 1 && MaterialSignal == 1)
+                    {
+                        if (AreaNr == 0)
+                        {
+                            Gantry_client.WriteByOrder("W_Wheel_Type", (Int16)Convert.ToInt16(QueryMateriel(Station.stationType) == null ? QueryMateriel1(Station.stationType).TypeId : QueryMateriel(Station.stationType).TypeId), number);//杞﹁疆绫诲瀷
+                            var area = Convert.ToInt16(Station.stationCode.Substring(Station.stationCode.Length - 1, 1));
+                            Gantry_client.WriteByOrder("W_AreaNr", (Int16)area, number);//鍖哄煙璐т綅鍙�
+                            Gantry_client.WriteByOrder("W_IndexNr", (Int16)SNS.Length, number);//鎵樼洏涓婄殑绗嚑涓溅杞�
+                            Gantry_client.WriteByOrder("W_Storage_Type", (Int16)1, number); //鎵樼洏绫诲瀷1-妯斁;2-绔栨斁
+                            Gantry_client.WriteByOrder("W_Wheel_id", SNS[SNS.Length - 1], number);//杞﹁疆SN鍙�
+                            Gantry_client.WriteByOrder("W_RequestUnload", true, number);
+                            #region 鏃ュ織璁板綍
+                            WriteDBLog.Success("涓婃枡鍖虹敵璇�", $"璇诲彇鎵樼洏鍏夌數淇″彿锛歿PalletSignal}\n璇诲彇绗竴涓溅杞厜鐢典俊鍙凤細{MaterialSignal}\n\n" +
+                                $"鍐欏叆妗佹灦淇℃伅锛歕n鍖哄煙璐т綅鍙凤細{area}\n鎵樼洏涓婄殑绗嚑涓溅杞細{SNS.Length}\n鎵樼洏绫诲瀷锛歿1}\n杞﹁疆绫诲瀷锛歿(QueryMateriel(Station.stationType).TypeId == null ? QueryMateriel1(Station.stationType).TypeId : QueryMateriel(Station.stationType).TypeId)}" +
+                                $"\n杞﹁疆SN鍙凤細{SNS[SNS.Length - 1]}\nW_RequestUnload锛歵rue", "PCS");
+                            #endregion
+                        }
+                    }
+                    else
+                    {
+                        Gantry_client.WriteByOrder("W_RequestUnload", false, number);
+                    }
+                    #endregion
+
+                    #region 鏇存柊涓�涓娴嬩笂鏂欎换鍔�
+                    Idt_agvtaskRepository agvtaskService = new dt_agvtaskRepository(Context);
+                    if (!agvtaskService.Find(x => x.agv_toaddress == Station.stationCode).Any())
+                    {
+                        var task = agvtaskService.Find(x => x.agv_taskstate == "Queue" && (x.agv_tasktype == "TaskType_OutsourceOutbound" || x.agv_tasktype == "TaskType_Outbound") && x.agv_toaddress == "").OrderByDescending(x => x.agv_grade).ThenBy(x => x.agv_createtime).FirstOrDefault();
+                        if (task != null)
+                        {
+                            task.agv_taskstate = "Create";
+                            task.agv_toaddress = Station.stationCode;
+                            agvtaskService.Update(task, true);
+                            WriteDBLog.Success("鏇存柊涓�涓娴嬩笂鏂欎换鍔�", $"浠诲姟缂栧彿锛歿task.agv_tasknum}", "PCS");
+                        }
+                    }
+                    #endregion
+
+                }
+                else
+                    Gantry_client.WriteByOrder("W_RequestUnload", false, number);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
+            }
+            catch (Exception ex)
+            {
+                WriteDBLog.Error("涓婃枡鍖�", $"閿欒淇℃伅锛歿ex.Message}", "PCS");
+            }
+        }
+
+        private string OperStr(string[] strArrty)
+        {
+            string[] newstr = strArrty.RemoveLast(1);
+            string Newsn = string.Join(",", newstr);
+
+            return Newsn;
+        }
+        public static dt_geometry_data QueryMateriel(string type)
+        {
+            VOLContext Context = new VOLContext();
+            Idt_geometry_dataRepository dataRepository = new dt_geometry_dataRepository(Context);
+            var materielinfo = dataRepository.Find(x => x.Description == type).OrderBy(x => x.TypeId).FirstOrDefault();
+            return materielinfo;
+        }
+        public static dt_geometry_data_detectionline QueryMateriel1(string type)
+        {
+            VOLContext Context = new VOLContext();
+            Idt_geometry_data_detectionlineRepository detectionlineRepository = new dt_geometry_data_detectionlineRepository(Context);
+            var materielinfo1 = detectionlineRepository.Find(x => x.Description == type).OrderBy(x => x.TypeId).FirstOrDefault();
+            return materielinfo1;
+        }
+
+        public static string area_code(string area_name)
+        {
+            VOLContext Context = new VOLContext();
+            Idt_areainfoRepository areainfoRepository = new dt_areainfoRepository(Context);
+            var areainfo = areainfoRepository.Find(x => x.area_name == area_name).FirstOrDefault();
+            return areainfo.area_code.ToString();
+        }
+
+        /// <summary>
+        /// 鏇存敼宸ュ崟鐘舵��
+        /// </summary>
+        /// <param name="SN"></param>
+        public static void Updatemes(string SN)
+        {
+            VOLContext Context = new VOLContext();
+            Idt_mes_detailRepository mes_DetailRepository = new dt_mes_detailRepository(Context);
+            Idt_mes_headRepository mes_HeadRepository = new dt_mes_headRepository(Context);
+            IVV_Mes_WorkinfoRepository workinfoRepository = new VV_Mes_WorkinfoRepository(Context);
+            //var mes_Detail = freeDB.Select<dt_mes_detail>().Where(x => x.SN == SN).First();
+            var Mes_Work = workinfoRepository.Find(x => x.SN == SN && x.processCode == "28").FirstOrDefault();
+            var mes_Detail = mes_DetailRepository.Find(x => x.SN == SN && x.jobID == Mes_Work.jobID).FirstOrDefault();
+            if (mes_Detail != null)
+            {
+                mes_Detail.Status = "涓婄嚎";
+                mes_Detail.FinishTime = DateTime.Now;
+                //freeDB.DataBase.Update<dt_mes_detail>().SetSource(mes_Detail).UpdateColumns(x => new { x.Status, x.FinishTime }).ExecuteAffrows();
+                mes_DetailRepository.Update(mes_Detail, true);
+                //var mes_Head = freeDB.Select<dt_mes_head>().Where(x => x.jobID == mes_Detail.jobID).First();
+                var mes_Head = mes_HeadRepository.Find(x => x.jobID == mes_Detail.jobID).FirstOrDefault();
+                if (mes_Head != null)
+                {
+                    mes_Head.finishNum = mes_Head.finishNum + 1;
+                    //freeDB.DataBase.Update<dt_mes_head>().SetSource(mes_Head).UpdateColumns(x => new { x.finishNum }).ExecuteAffrows();
+                    mes_HeadRepository.Update(mes_Head, true);
+                }
+            }
+        }
+    }
+}
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Jobs/Task/AutoTaskJob.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Jobs/Task/AutoTaskJob.cs"
index 231a254..2a95776 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Jobs/Task/AutoTaskJob.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Jobs/Task/AutoTaskJob.cs"
@@ -30,12 +30,13 @@
 
         private void DoAction(IJobExecutionContext context)
         {
-            StationTask.CreateTask();
-            OutboundTask.CreateOutboundTask();//浼樺寲鍚庡嚭搴撻�昏緫
-            ReplaceTray.ReplaceTrayTask();
-            RestockHCJ.HCJGetBarcode();
-            EmptyTrayTask.CreateEmptyTrayTask();
-            AutoUpdateWork.FinishMesWork();
+            EmptyTray.EmptyTrayIn();//绌烘墭鍙犵洏鍏ュ簱
+            StationTask.CreateTask();//鍏ュ簱
+            OutboundTask.CreateOutboundTask();//鍑哄簱
+            ReplaceTray.ReplaceTrayTask();//鏇存崲鎵樼洏
+            RestockHCJ.HCJGetBarcode();//鏇存柊闃熷垪
+            EmptyTrayTask.CreateEmptyTrayTask();//鍒涘缓琛ョ┖鎵�
+            AutoUpdateWork.FinishMesWork();//澶勭悊宸ュ崟
         }
     }
 }
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Jobs/equipment/PipelineJob.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Jobs/equipment/PipelineJob.cs"
index 045de56..4d9e22e 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Jobs/equipment/PipelineJob.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Jobs/equipment/PipelineJob.cs"
@@ -5,6 +5,7 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Net;
 using System.Reflection;
 using System.Text;
 using System.Threading.Tasks;
@@ -68,7 +69,6 @@
                 VOLContext Context = new VOLContext();
                 Idt_plcinfoheadRepository repository = new dt_plcinfoheadRepository(Context);
                 Idt_plcinfodetailRepository plcRepository = new dt_plcinfodetailRepository(Context);
-                Idt_geometry_dataRepository dataRepository = new dt_geometry_dataRepository(Context);
                 Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
                 var plc = repository.FindFirst(x => x.plcinfo_name == client.PLCName);
                 var Gantry_client = PLCClient.Clients.FirstOrDefault(t => t.PLCName == "妗佹灦");
@@ -77,39 +77,141 @@
                 var Gantryplc = repository.FindFirst(x => x.plcinfo_name == Gantry_client.PLCName);
 
 
-                ///鏌ユ壘涓婃枡鍖虹殑璐т綅
-                var Stations = stationinfoRepository.Find(x => x.area == area_code(number)).OrderBy(x => x.lastUpdateTime);//鏍规嵁鏃堕棿鍏堝悗鎺掑簭
+                #region 涓婃枡瀹屾垚
 
-                var Station = Stations?.Where(x => x.enable && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).OrderBy(x => x.quantity).FirstOrDefault();
-                if (Station != null)
+                var AreaNr = Gantry_client.ReadByOrder<Int16>("W_AreaNr", number);//璇诲彇璐т綅鍙蜂俊鎭�
+                if (AreaNr != 0)
                 {
-                    var SNS = Station.bindSN.Split(",");
-                    List<string> list = new List<string>();
-                    foreach (var SN in SNS)
+                    var station = stationinfoRepository.Find(x => x.area == area_code(number) && x.stationCode.Substring(x.stationCode.Length - 1, 1) == AreaNr.ToString()).FirstOrDefault();
+                    if (station != null)
                     {
-                        if (!string.IsNullOrEmpty(SN))
-                            list.Add(SN);
-                    }
-                    //缂撳瓨鏋朵笂杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�
-                    if (list.Count != Station.quantity)
-                    {
-                        Station.location_state = LocationStateEnum.Abnormal.ToString();
-                        Station.remark = "杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�";
-                        stationinfoRepository.Update(Station, true);
-                        Gantry_client.WriteByOrder("W_RequestUnload", false, number);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
-                        #region 鏃ュ織璁板綍
-                        WriteDBLog.Error("涓婃枡鍖�", $"鍐欏叆妗佹灦淇℃伅锛歕nW_RequestUnload锛歠alse\n\n{Station.stationCode}杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�", "PCS");
-                        #endregion
-                        return;
-                    }
-                    var details = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep && x.plcdetail_number == Station.stationCode).ToList();
-                    var PalletSignal = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_PalletSignal").First(), client);//璇诲彇鎵樼洏淇″彿:1:鏈�,2鏃�
-                    var MaterialSignal = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_MaterialSignal").First(), client);//璇诲彇璐х墿淇″彿:1:鏈�,2鏃�
+                        var bindSNS = station.bindSN.Split(",");
+                        var Gantrydetails = plcRepository.Find(x => x.plcdetail_iotype == Gantryplc.plcinfo_iotyep && x.plcdetail_number == number).ToList();
 
-                    var AreaNr = Gantry_client.ReadByOrder<Int16>("W_AreaNr", number);//璇诲彇璐т綅鍙蜂俊鎭�
-                    if (PalletSignal == 1 && MaterialSignal == 1)
+                        #region 淇℃伅鏌ヨ纭
+                        var QueryDate = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "R_QueryDate").First(), Gantry_client);//淇℃伅鏌ヨ
+                        if (QueryDate)
+                        {
+                            var Date_Vaild = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "R_Date_Vaild").First(), Gantry_client);//淇℃伅纭
+                            if (!Date_Vaild)//淇℃伅鏈夎锛岃褰曟棩蹇�
+                            {
+                                Gantry_client.WriteByOrder("W_RequestUnload", false, number);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
+                                station.location_state = LocationStateEnum.Abnormal.ToString();
+                                station.remark = $"鏈煡璇㈠埌SN鍙凤細{bindSNS[bindSNS.Length - 1]}鐨勮鍗�";
+                                stationinfoRepository.Update(station, true);
+                                WriteDBLog.Error("涓婃枡鍖轰俊鎭煡璇�", $"鍐欏叆妗佹灦淇℃伅锛歕nW_RequestUnload锛歠alse\n\n{station.stationCode}鏈煡璇㈠埌SN鍙凤細{bindSNS[bindSNS.Length - 1]}鐨勮鍗�", "PCS");
+                                return;
+                            }
+                        }
+                        #endregion
+
+                        #region 璐т綅鐘舵�佹洿鏂板浣�
+                        var finished = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "R_Unlod_finished").First(), Gantry_client);//澶瑰彇瀹屾垚
+                        var updatefinished = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "W_Storage_update").First(), Gantry_client);//璐т綅鐘舵�佹洿鏂�
+                        if (!finished && updatefinished)
+                        {
+                            Gantry_client.WriteByOrder("W_Storage_update", false, number);//璐т綅鐘舵�佹洿鏂�
+                            WriteLog.Write_Log(number + "涓婃枡瀹屾垚", number + "璐т綅鐘舵�佹洿鏂颁俊鍙峰浣�", "鎴愬姛锛�",
+                                        $"璇诲彇妗佹灦淇℃伅锛歕n涓婃枡瀹屾垚淇″彿锛歿finished}\n\n鍐欏叆妗佹灦淇℃伅锛歕n璐т綅鐘舵�佹洿鏂颁俊鍙凤細{false}");
+                        }
+                        #endregion
+
+                        if (finished && !updatefinished)
+                        {
+
+                            #region 鍒ゆ柇鍖哄煙鍙锋槸鍚︿竴鑷�
+                            var area = Gantry_client.ReadByOrder<Int16>("place_prog", number);//鏀炬枡瀹屾垚鐨勫尯鍩熷彿
+
+                            WriteLog.Write_Log(number + "鍙栨枡瀹屾垚鍑洪敊", bindSNS[bindSNS.Length - 1], "鍒ゆ柇鍖哄煙鍙锋槸鍚︿竴鑷�", $"PCS鍖哄煙鍙凤細{AreaNr}锛沑n妗佹灦鍖哄煙鍙凤細{area}\n閿欒淇℃伅锛歅CS鍖哄煙鍙蜂笌妗佹灦鍖哄煙鍙蜂笉涓�鑷达紒");
+                            //if (AreaNr != area)
+                            //{
+                            //    client.WriteByOrder("W_AlarmSignal", (Int16)2, number);//鎶ヨ
+                            //    //WriteDBLog.Error(name + "鎶ヨ", $"PCS鍖哄煙鍙凤細{AreaNr}锛涙鏋跺尯鍩熷彿锛歿area}閿欒淇℃伅锛歅CS鍖哄煙鍙蜂笌妗佹灦鍖哄煙鍙蜂笉涓�鑷达紒", "PCS");
+                            //    WriteLog.Write_Log(number + "鍙栨枡瀹屾垚鍑洪敊", bindSNS[bindSNS.Length - 1], "鍒ゆ柇鍖哄煙鍙锋槸鍚︿竴鑷�", $"PCS鍖哄煙鍙凤細{AreaNr}锛沑n妗佹灦鍖哄煙鍙凤細{area}\n閿欒淇℃伅锛歅CS鍖哄煙鍙蜂笌妗佹灦鍖哄煙鍙蜂笉涓�鑷达紒");
+                            //    return;
+                            //}
+                            #endregion
+
+                            #region 鍒ゆ柇杞﹁疆鏁伴噺鏄惁涓�鑷�
+                            var quantity = Gantry_client.ReadByOrder<Int16>("pos_prog", number);//妗佹灦璁板綍鐨勮溅杞暟閲�
+
+                            WriteLog.Write_Log(number + "鍙栨枡瀹屾垚鍑洪敊", bindSNS[bindSNS.Length - 1], "鍒ゆ柇杞﹁疆鏁伴噺鏄惁涓�鑷�", $"鍖哄煙鍙凤細{AreaNr}锛沑n妗佹灦杞﹁疆鏁帮細{quantity}\nPCS杞﹁疆鏁帮細{station.quantity}\n閿欒淇℃伅锛歅CS鍖哄煙鍙蜂笌妗佹灦鍖哄煙鍙蜂笉涓�鑷达紒");
+                            //if (quantity != station.quantity)
+                            //{
+                            //    client.WriteByOrder("W_AlarmSignal", (Int16)2, number);//鎶ヨ
+                            //    WriteLog.Write_Log(number + "鍙栨枡瀹屾垚鍑洪敊", bindSNS[bindSNS.Length - 1], "鍒ゆ柇杞﹁疆鏁伴噺鏄惁涓�鑷�", $"鍖哄煙鍙凤細{AreaNr}锛沑n妗佹灦杞﹁疆鏁帮細{quantity}\nPCS杞﹁疆鏁帮細{station.quantity}\n閿欒淇℃伅锛歅CS鍖哄煙鍙蜂笌妗佹灦鍖哄煙鍙蜂笉涓�鑷达紒");
+                            //    return;
+                            //}
+                            #endregion
+
+                            Updatemes(bindSNS[bindSNS.Length - 1]);
+                            station.quantity = station.quantity - 1;
+                            station.bindSN = OperStr(bindSNS);
+                            if (station.quantity <= 0)
+                            {
+                                station.stationType = string.Empty;
+                                station.Number = string.Empty;
+                                station.heatNumber = string.Empty;
+                                station.tray_status = "EmptyTray";
+                            }
+                            var count = stationinfoRepository.Update(station, true);
+                            if (count < 1)
+                            {
+                                WriteDBLog.Error("鍙栨枡瀹屾垚", $"涓婃枡浣嶄俊鎭洿鏂板け璐ワ紒涓婃枡浣嶇紪鍙凤細{station.stationCode}", "PCS");
+                                return;
+                            }
+
+                            Gantry_client.WriteByOrder("W_Storage_update", true, number);//璐т綅鐘舵�佹洿鏂�
+                            Gantry_client.WriteByOrder("W_RequestUnload", false, number);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
+
+                            #region 娓呯┖淇℃伅
+                            Gantry_client.WriteByOrder("W_AreaNr", (Int16)0, number);//鍖哄煙璐т綅鍙�
+                            Gantry_client.WriteByOrder("W_IndexNr", (Int16)0, number);//鎵樼洏涓婄殑绗嚑涓溅杞�
+                            Gantry_client.WriteByOrder("W_Storage_Type", (Int16)0, number); //鎵樼洏绫诲瀷1-妯斁;2-绔栨斁
+                            Gantry_client.WriteByOrder("W_Wheel_Type", (Int16)0, number);//杞﹁疆绫诲瀷
+                            #endregion
+
+                            #region 鏃ュ織璁板綍
+                            WriteDBLog.Success("鍙栨枡瀹屾垚", $"鍐欏叆妗佹灦淇℃伅锛歕n璐т綅鐘舵�佹洿鏂帮細{true}\nW_RequestUnload锛歿false}", "PCS");
+                            #endregion
+                        }
+                    }
+                }
+
+                #endregion
+
+                #region 鐢宠涓婃枡
+
+                if (!Gantry_client.ReadByOrder<bool>("W_RequestUnload", number))
+                {
+                    var Station = stationinfoRepository.Find(x => x.area == area_code(number) && x.enable && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).OrderBy(x => x.lastUpdateTime).FirstOrDefault();
+                    if (Station != null)
                     {
-                        if (AreaNr == 0)
+                        var SNS = Station.bindSN.Split(",");
+                        List<string> list = new List<string>();
+                        foreach (var SN in SNS)
+                        {
+                            if (!string.IsNullOrEmpty(SN))
+                                list.Add(SN);
+                        }
+                        //缂撳瓨鏋朵笂杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�
+                        if (list.Count != Station.quantity)
+                        {
+                            Station.location_state = LocationStateEnum.Abnormal.ToString();
+                            Station.remark = "杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�";
+                            stationinfoRepository.Update(Station, true);
+                            Gantry_client.WriteByOrder("W_RequestUnload", false, number);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
+                            #region 鏃ュ織璁板綍
+                            WriteDBLog.Error("涓婃枡鍖�", $"鍐欏叆妗佹灦淇℃伅锛歕nW_RequestUnload锛歠alse\n\n{Station.stationCode}杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�", "PCS");
+                            #endregion
+                            return;
+                        }
+
+                        var details = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep && x.plcdetail_number == Station.stationCode).ToList();
+                        var PalletSignal = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_PalletSignal").First(), client);//璇诲彇鎵樼洏淇″彿:1:鏈�,2鏃�
+                        var MaterialSignal = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_MaterialSignal").First(), client);//璇诲彇璐х墿淇″彿:1:鏈�,2鏃�
+
+                        if (PalletSignal == 1 && MaterialSignal == 1)
                         {
                             Gantry_client.WriteByOrder("W_Wheel_Type", (Int16)Convert.ToInt16(QueryMateriel(Station.stationType) == null ? QueryMateriel1(Station.stationType).TypeId : QueryMateriel(Station.stationType).TypeId), number);//杞﹁疆绫诲瀷
                             var area = Convert.ToInt16(Station.stationCode.Substring(Station.stationCode.Length - 1, 1));
@@ -120,91 +222,171 @@
                             Gantry_client.WriteByOrder("W_RequestUnload", true, number);
                             #region 鏃ュ織璁板綍
                             WriteDBLog.Success("涓婃枡鍖虹敵璇�", $"璇诲彇鎵樼洏鍏夌數淇″彿锛歿PalletSignal}\n璇诲彇绗竴涓溅杞厜鐢典俊鍙凤細{MaterialSignal}\n\n" +
-                                $"鍐欏叆妗佹灦淇℃伅锛歕n鍖哄煙璐т綅鍙凤細{area}\n鎵樼洏涓婄殑绗嚑涓溅杞細{SNS.Length}\n鎵樼洏绫诲瀷锛歿1}\n杞﹁疆绫诲瀷锛歿(QueryMateriel(Station.stationType).TypeId == null ? QueryMateriel1(Station.stationType).TypeId : QueryMateriel(Station.stationType).TypeId)}" +
+                                $"鍐欏叆妗佹灦淇℃伅锛歕n鍖哄煙璐т綅鍙凤細{area}\n鎵樼洏涓婄殑绗嚑涓溅杞細{SNS.Length}\n鎵樼洏绫诲瀷锛歿1}\n杞﹁疆绫诲瀷锛歿(QueryMateriel(Station.stationType) == null ? QueryMateriel1(Station.stationType).TypeId : QueryMateriel(Station.stationType).TypeId)}" +
                                 $"\n杞﹁疆SN鍙凤細{SNS[SNS.Length - 1]}\nW_RequestUnload锛歵rue", "PCS");
                             #endregion
                         }
-                    }
-                    else
-                    {
-                        Gantry_client.WriteByOrder("W_RequestUnload", false, number);
-                    }
-
-                    var Gantrydetails = plcRepository.Find(x => x.plcdetail_iotype == Gantryplc.plcinfo_iotyep && x.plcdetail_number == number).ToList();
-                    var Gantry_Out_of_Area = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "R_Gantry_Out_of_Area").First(), Gantry_client);//妗佹灦鏄惁鍦ㄥ尯鍩熷唴
-
-                    var QueryDate = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "R_QueryDate").First(), Gantry_client);//淇℃伅鏌ヨ
-                    if (QueryDate)
-                    {
-                        var Date_Vaild = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "R_Date_Vaild").First(), Gantry_client);//淇℃伅纭
-                        if (!Date_Vaild)//淇℃伅鏈夎锛岃褰曟棩蹇�
+                        else
                         {
-                            Gantry_client.WriteByOrder("W_RequestUnload", false, number);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
-                            Station.location_state = LocationStateEnum.Abnormal.ToString();
-                            Station.remark = $"鏈煡璇㈠埌SN鍙凤細{SNS[SNS.Length - 1]}鐨勮鍗�";
-                            stationinfoRepository.Update(Station, true);
-                            WriteDBLog.Error("涓婃枡鍖轰俊鎭煡璇�", $"鍐欏叆妗佹灦淇℃伅锛歕nW_RequestUnload锛歠alse\n\n{Station.stationCode}鏈煡璇㈠埌SN鍙凤細{SNS[SNS.Length - 1]}鐨勮鍗�", "PCS");
-                            return;
-                        }
-                    }
-                    var finished = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "R_Unlod_finished").First(), Gantry_client);//澶瑰彇瀹屾垚
-                    var updatefinished = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "W_Storage_update").First(), Gantry_client);//璐т綅鐘舵�佹洿鏂�
-                    if (!finished && updatefinished)
-                        Gantry_client.WriteByOrder("W_Storage_update", false, number);//璐т綅鐘舵�佹洿鏂�
-                    if (finished && !updatefinished)
-                    {
-                        Gantry_client.WriteByOrder("W_RequestUnload", false, number);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
-                        Updatemes(SNS[SNS.Length - 1]);
-                        Station.quantity = Station.quantity - 1;
-                        Station.bindSN = OperStr(SNS);
-                        if (Station.quantity <= 0)
-                        {
-                            Station.stationType = string.Empty;
-                            Station.Number = string.Empty;
-                            Station.heatNumber = string.Empty;
-                            Station.tray_status = "EmptyTray";
-                        }
-                        var count = stationinfoRepository.Update(Station, true);
-                        if (count < 1)
-                        {
-                            WriteDBLog.Error("鍙栨枡瀹屾垚", $"涓婃枡浣嶄俊鎭洿鏂板け璐ワ紒涓婃枡浣嶇紪鍙凤細{Station.stationCode}", "PCS");
-                            return;
+                            Gantry_client.WriteByOrder("W_RequestUnload", false, number);
                         }
 
-                        #region 娓呯┖淇℃伅
-                        Gantry_client.WriteByOrder("W_AreaNr", (Int16)0, number);//鍖哄煙璐т綅鍙�
-                        Gantry_client.WriteByOrder("W_IndexNr", (Int16)0, number);//鎵樼洏涓婄殑绗嚑涓溅杞�
-                        Gantry_client.WriteByOrder("W_Storage_Type", (Int16)0, number); //鎵樼洏绫诲瀷1-妯斁;2-绔栨斁
-                        Gantry_client.WriteByOrder("W_Wheel_Type", (Int16)0, number);//杞﹁疆绫诲瀷
+                        #region 鏇存柊涓�涓娴嬩笂鏂欎换鍔�
+                        Idt_agvtaskRepository agvtaskService = new dt_agvtaskRepository(Context);
+                        if (!agvtaskService.Find(x => x.agv_toaddress == Station.stationCode).Any())
+                        {
+                            var task = agvtaskService.Find(x => x.agv_taskstate == "Queue" && (x.agv_tasktype == "TaskType_OutsourceOutbound" || x.agv_tasktype == "TaskType_Outbound") && x.agv_toaddress == "").OrderByDescending(x => x.agv_grade).ThenBy(x => x.agv_createtime).FirstOrDefault();
+                            if (task != null)
+                            {
+                                task.agv_taskstate = "Create";
+                                task.agv_toaddress = Station.stationCode;
+                                agvtaskService.Update(task, true);
+                                WriteDBLog.Success("鏇存柊涓�涓娴嬩笂鏂欎换鍔�", $"浠诲姟缂栧彿锛歿task.agv_tasknum}", "PCS");
+                            }
+                        }
                         #endregion
-
-                        Gantry_client.WriteByOrder("W_Storage_update", true, number);//璐т綅鐘舵�佹洿鏂�
-                        #region 鏃ュ織璁板綍
-                        WriteDBLog.Success("鍙栨枡瀹屾垚", $"鍐欏叆妗佹灦淇℃伅锛歕n璐т綅鐘舵�佹洿鏂帮細{true}\nW_RequestUnload锛歿false}", "PCS");
-                        #endregion
-
-                        PalletSignal = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_PalletSignal").First(), client);//璇诲彇鎵樼洏淇″彿:1:鏈�,2鏃�
-                        MaterialSignal = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_MaterialSignal").First(), client);//璇诲彇璐х墿淇″彿:1:鏈�,2鏃�
-                        if (Station.quantity > 0 && (PalletSignal != 1 || MaterialSignal != 1))
-                        {
-                            Station.location_state = LocationStateEnum.Abnormal.ToString();
-                            Station.remark = "杞﹁疆鏁伴噺澶т簬0锛屽厜鐢垫娴嬫棤鎵樼洏鎴栨棤杞﹁疆";
-                            stationinfoRepository.Update(Station, true);
-                            client.WriteByOrder("W_AlarmSignal", (Int16)2, number);//鎶ヨ
-                            WriteDBLog.Error(number + "鎶ヨ", $"璐т綅缂栧彿锛歿Station.stationCode}锛涢敊璇俊鎭細{Station.remark}", "PCS");
-                        }
-                        else if (Station.quantity < 1 && MaterialSignal == 1)
-                        {
-                            Station.location_state = LocationStateEnum.Abnormal.ToString();
-                            Station.remark = "杞﹁疆鏁伴噺灏忎簬0锛屽厜鐢垫娴嬫湁杞﹁疆";
-                            stationinfoRepository.Update(Station, true);
-                            client.WriteByOrder("W_AlarmSignal", (Int16)2, number);//鎶ヨ
-                            WriteDBLog.Error(number + "鎶ヨ", $"璐т綅缂栧彿锛歿Station.stationCode}锛涢敊璇俊鎭細{Station.remark}", "PCS");
-                        }
                     }
                 }
-                else
-                    Gantry_client.WriteByOrder("W_RequestUnload", false, number);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
+
+                #endregion
+
+
+                #region MyRegion
+
+                /////鏌ユ壘涓婃枡鍖虹殑璐т綅
+                //var Stations = stationinfoRepository.Find(x => x.area == area_code(number)).OrderBy(x => x.lastUpdateTime);//鏍规嵁鏃堕棿鍏堝悗鎺掑簭
+                //                                                                                                           //闇�娴嬭瘯涓�涓�
+                //var Station = Stations?.Where(x => x.enable && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).OrderBy(x => x.quantity).FirstOrDefault();
+
+                //if (Station != null)
+                //{
+                //    var SNS = Station.bindSN.Split(",");
+                //    List<string> list = new List<string>();
+                //    foreach (var SN in SNS)
+                //    {
+                //        if (!string.IsNullOrEmpty(SN))
+                //            list.Add(SN);
+                //    }
+                //    //缂撳瓨鏋朵笂杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�
+                //    if (list.Count != Station.quantity)
+                //    {
+                //        Station.location_state = LocationStateEnum.Abnormal.ToString();
+                //        Station.remark = "杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�";
+                //        stationinfoRepository.Update(Station, true);
+                //        Gantry_client.WriteByOrder("W_RequestUnload", false, number);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
+                //        #region 鏃ュ織璁板綍
+                //        WriteDBLog.Error("涓婃枡鍖�", $"鍐欏叆妗佹灦淇℃伅锛歕nW_RequestUnload锛歠alse\n\n{Station.stationCode}杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�", "PCS");
+                //        #endregion
+                //        return;
+                //    }
+                //    var details = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep && x.plcdetail_number == Station.stationCode).ToList();
+                //    var PalletSignal = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_PalletSignal").First(), client);//璇诲彇鎵樼洏淇″彿:1:鏈�,2鏃�
+                //    var MaterialSignal = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_MaterialSignal").First(), client);//璇诲彇璐х墿淇″彿:1:鏈�,2鏃�
+
+                //    var AreaNr = Gantry_client.ReadByOrder<Int16>("W_AreaNr", number);//璇诲彇璐т綅鍙蜂俊鎭�
+                //    if (PalletSignal == 1 && MaterialSignal == 1)
+                //    {
+                //        if (AreaNr == 0)
+                //        {
+                //            Gantry_client.WriteByOrder("W_Wheel_Type", (Int16)Convert.ToInt16(QueryMateriel(Station.stationType) == null ? QueryMateriel1(Station.stationType).TypeId : QueryMateriel(Station.stationType).TypeId), number);//杞﹁疆绫诲瀷
+                //            var area = Convert.ToInt16(Station.stationCode.Substring(Station.stationCode.Length - 1, 1));
+                //            Gantry_client.WriteByOrder("W_AreaNr", (Int16)area, number);//鍖哄煙璐т綅鍙�
+                //            Gantry_client.WriteByOrder("W_IndexNr", (Int16)SNS.Length, number);//鎵樼洏涓婄殑绗嚑涓溅杞�
+                //            Gantry_client.WriteByOrder("W_Storage_Type", (Int16)1, number); //鎵樼洏绫诲瀷1-妯斁;2-绔栨斁
+                //            Gantry_client.WriteByOrder("W_Wheel_id", SNS[SNS.Length - 1], number);//杞﹁疆SN鍙�
+                //            Gantry_client.WriteByOrder("W_RequestUnload", true, number);
+                //            #region 鏃ュ織璁板綍
+                //            WriteDBLog.Success("涓婃枡鍖虹敵璇�", $"璇诲彇鎵樼洏鍏夌數淇″彿锛歿PalletSignal}\n璇诲彇绗竴涓溅杞厜鐢典俊鍙凤細{MaterialSignal}\n\n" +
+                //                $"鍐欏叆妗佹灦淇℃伅锛歕n鍖哄煙璐т綅鍙凤細{area}\n鎵樼洏涓婄殑绗嚑涓溅杞細{SNS.Length}\n鎵樼洏绫诲瀷锛歿1}\n杞﹁疆绫诲瀷锛歿(QueryMateriel(Station.stationType).TypeId == null ? QueryMateriel1(Station.stationType).TypeId : QueryMateriel(Station.stationType).TypeId)}" +
+                //                $"\n杞﹁疆SN鍙凤細{SNS[SNS.Length - 1]}\nW_RequestUnload锛歵rue", "PCS");
+                //            #endregion
+                //        }
+                //    }
+                //    else
+                //    {
+                //        Gantry_client.WriteByOrder("W_RequestUnload", false, number);
+                //    }
+
+                //    var Gantrydetails = plcRepository.Find(x => x.plcdetail_iotype == Gantryplc.plcinfo_iotyep && x.plcdetail_number == number).ToList();
+                //    var Gantry_Out_of_Area = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "R_Gantry_Out_of_Area").First(), Gantry_client);//妗佹灦鏄惁鍦ㄥ尯鍩熷唴
+
+                //    var QueryDate = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "R_QueryDate").First(), Gantry_client);//淇℃伅鏌ヨ
+                //    if (QueryDate)
+                //    {
+                //        var Date_Vaild = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "R_Date_Vaild").First(), Gantry_client);//淇℃伅纭
+                //        if (!Date_Vaild)//淇℃伅鏈夎锛岃褰曟棩蹇�
+                //        {
+                //            Gantry_client.WriteByOrder("W_RequestUnload", false, number);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
+                //            Station.location_state = LocationStateEnum.Abnormal.ToString();
+                //            Station.remark = $"鏈煡璇㈠埌SN鍙凤細{SNS[SNS.Length - 1]}鐨勮鍗�";
+                //            stationinfoRepository.Update(Station, true);
+                //            WriteDBLog.Error("涓婃枡鍖轰俊鎭煡璇�", $"鍐欏叆妗佹灦淇℃伅锛歕nW_RequestUnload锛歠alse\n\n{Station.stationCode}鏈煡璇㈠埌SN鍙凤細{SNS[SNS.Length - 1]}鐨勮鍗�", "PCS");
+                //            return;
+                //        }
+                //    }
+                //    var finished = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "R_Unlod_finished").First(), Gantry_client);//澶瑰彇瀹屾垚
+                //    var updatefinished = (bool)DBExtension.Read(Gantrydetails.Where(x => x.plcdetail_name == "W_Storage_update").First(), Gantry_client);//璐т綅鐘舵�佹洿鏂�
+                //    if (!finished && updatefinished)
+                //        Gantry_client.WriteByOrder("W_Storage_update", false, number);//璐т綅鐘舵�佹洿鏂�
+                //    if (finished && !updatefinished)
+                //    {
+                //        Gantry_client.WriteByOrder("W_RequestUnload", false, number);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
+                //        Updatemes(SNS[SNS.Length - 1]);
+                //        Station.quantity = Station.quantity - 1;
+                //        Station.bindSN = OperStr(SNS);
+                //        if (Station.quantity <= 0)
+                //        {
+                //            Station.stationType = string.Empty;
+                //            Station.Number = string.Empty;
+                //            Station.heatNumber = string.Empty;
+                //            Station.tray_status = "EmptyTray";
+                //        }
+                //        var count = stationinfoRepository.Update(Station, true);
+                //        if (count < 1)
+                //        {
+                //            WriteDBLog.Error("鍙栨枡瀹屾垚", $"涓婃枡浣嶄俊鎭洿鏂板け璐ワ紒涓婃枡浣嶇紪鍙凤細{Station.stationCode}", "PCS");
+                //            return;
+                //        }
+
+                //        #region 娓呯┖淇℃伅
+                //        Gantry_client.WriteByOrder("W_AreaNr", (Int16)0, number);//鍖哄煙璐т綅鍙�
+                //        Gantry_client.WriteByOrder("W_IndexNr", (Int16)0, number);//鎵樼洏涓婄殑绗嚑涓溅杞�
+                //        Gantry_client.WriteByOrder("W_Storage_Type", (Int16)0, number); //鎵樼洏绫诲瀷1-妯斁;2-绔栨斁
+                //        Gantry_client.WriteByOrder("W_Wheel_Type", (Int16)0, number);//杞﹁疆绫诲瀷
+                //        #endregion
+
+                //        Gantry_client.WriteByOrder("W_Storage_update", true, number);//璐т綅鐘舵�佹洿鏂�
+                //        #region 鏃ュ織璁板綍
+                //        WriteDBLog.Success("鍙栨枡瀹屾垚", $"鍐欏叆妗佹灦淇℃伅锛歕n璐т綅鐘舵�佹洿鏂帮細{true}\nW_RequestUnload锛歿false}", "PCS");
+                //        #endregion
+
+                //        #region 鎶ヨ
+                //        PalletSignal = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_PalletSignal").First(), client);//璇诲彇鎵樼洏淇″彿:1:鏈�,2鏃�
+                //        MaterialSignal = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_MaterialSignal").First(), client);//璇诲彇璐х墿淇″彿:1:鏈�,2鏃�
+                //        if (Station.quantity > 0 && (PalletSignal != 1 || MaterialSignal != 1))
+                //        {
+                //            Station.location_state = LocationStateEnum.Abnormal.ToString();
+                //            Station.remark = "杞﹁疆鏁伴噺澶т簬0锛屽厜鐢垫娴嬫棤鎵樼洏鎴栨棤杞﹁疆";
+                //            stationinfoRepository.Update(Station, true);
+                //            client.WriteByOrder("W_AlarmSignal", (Int16)2, number);//鎶ヨ
+                //            WriteDBLog.Error(number + "鎶ヨ", $"璐т綅缂栧彿锛歿Station.stationCode}锛涢敊璇俊鎭細{Station.remark}", "PCS");
+                //        }
+                //        else if (Station.quantity < 1 && MaterialSignal == 1)
+                //        {
+                //            Station.location_state = LocationStateEnum.Abnormal.ToString();
+                //            Station.remark = "杞﹁疆鏁伴噺灏忎簬0锛屽厜鐢垫娴嬫湁杞﹁疆";
+                //            stationinfoRepository.Update(Station, true);
+                //            client.WriteByOrder("W_AlarmSignal", (Int16)2, number);//鎶ヨ
+                //            WriteDBLog.Error(number + "鎶ヨ", $"璐т綅缂栧彿锛歿Station.stationCode}锛涢敊璇俊鎭細{Station.remark}", "PCS");
+                //        }
+                //        #endregion
+
+
+                //    }
+                //}
+                //else
+                //    Gantry_client.WriteByOrder("W_RequestUnload", false, number);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆 
+                #endregion
             }
             catch (Exception ex)
             {
@@ -226,76 +408,88 @@
                 Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
                 var plc = repository.FindFirst(x => x.plcinfo_name == client.PLCName);
                 List<string> stationCodes = new List<string>() { "S01001001", "S01001002", "W01001001", "W01001002", "W01001003" };
+                string remark = "";
                 foreach (var stationCode in stationCodes)
                 {
-                    if (agvtaskService.Find(x => x.agv_fromaddress == stationCode /*|| x.agv_toaddress == stationCode*/).Any())
-                        continue;
-                    var station = stationinfoRepository.Find(x => x.stationCode == stationCode && x.enable).FirstOrDefault();
-                    if (station == null) continue;
-                    var details = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep && x.plcdetail_number == stationCode).ToList();
-                    var PalletSignal = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_PalletSignal").First(), client);//璇诲彇鎵樼洏淇″彿:1:鏈�,2鏃�
-                    var MaterialSignal = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_MaterialSignal").First(), client);//璇诲彇璐х墿淇″彿:1:鏈�,2鏃�
-                    if (PalletSignal == 1 && MaterialSignal == 2 && (station.stationCode.Contains("S0100100") ? station.tray_status == "EmptyTray" : true))
+                    try
                     {
-                        var area = station.tray_type == "SmallTray" ? "11" : "10";
-                        var task = agvtaskService.Find(x => (x.agv_toaddress.Contains("W") || x.agv_toaddress.Contains("X")) && x.agv_taskstate == "Queue" /*&& x.agv_tasktype == "TaskType_EmptyPallet" */ && x.agv_Traytype == station.tray_type).OrderByDescending(x => x.agv_grade).ThenBy(x => x.agv_createtime).FirstOrDefault();
-                        if (task != null)
-                        {
-                            task.agv_fromaddress = station.stationCode;
-                            task.StarQuantity = 0;
-                            task.agv_taskstate = "Create";
-                            if (station.stationCode.Contains("S0100100"))
-                                task.agv_grade = 3;
-                            agvtaskService.Update(task, true);
-                            station.location_state = LocationStateEnum.Busy.ToString();
-                            stationinfoRepository.Update(station, true);
+                        remark = "鏌ヨ绔欏彴";
+                        var station = stationinfoRepository.Find(x => x.stationCode == stationCode && x.enable).FirstOrDefault();
+                        if (station == null) continue;
+                        remark = "鏌ヨ璧风偣鏄惁瀛樺湪浠诲姟";
+                        if (agvtaskService.Find(x => x.agv_fromaddress == stationCode /*|| x.agv_toaddress == stationCode*/).Any())
                             continue;
-
-                        }
-
-                        #region 绌烘墭鍙犵洏
-                        var EmptyStations = stationinfoRepository.Find(x => x.stationCode.Contains("DD") && x.quantity < 5 && x.enable).ToList();
-                        var EmptyStation = EmptyStations.Where(x => x.tray_type == station.tray_type && x.location_state == LocationStateEnum.Stroge.ToString()).FirstOrDefault();
-                        if (EmptyStation == null)
-                            EmptyStation = EmptyStations.Where(x => x.location_state == LocationStateEnum.Empty.ToString()).FirstOrDefault();
-                        #endregion
-
-                        if (EmptyStation == null)//鏌ユ壘搴撳唴绌烘墭鐩�
-                            EmptyStation = GetStation.EmptyPalletStation(area);
-
-
-                        if (EmptyStation != null)
+                        remark = "璇诲彇鍏夌數淇″彿";
+                        var details = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep && x.plcdetail_number == stationCode).ToList();
+                        var PalletSignal = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_PalletSignal").First(), client);//璇诲彇鎵樼洏淇″彿:1:鏈�,2鏃�
+                        var MaterialSignal = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_MaterialSignal").First(), client);//璇诲彇璐х墿淇″彿:1:鏈�,2鏃�
+                        if (PalletSignal == 1 && MaterialSignal == 2 && (station.stationCode.Contains("S0100100") ? station.tray_status == "EmptyTray" : true))
                         {
-                            #region 鍚屼竴涓┖鎵樹綅鍙兘鍚屾椂鐢熸垚涓�涓┖鎵樹换鍔�
-                            if (agvtaskService.Find(x => x.agv_fromaddress == EmptyStation.stationCode || x.agv_toaddress == EmptyStation.stationCode).Any())
-                                return;
-                            #endregion
-                            dt_agvtask agvtask = new dt_agvtask()
+                            var area = station.tray_type == "SmallTray" ? "11" : "10";
+                            remark = "鏌ヨ鏄惁瀛樺湪琛ョ┖鎵橀槦鍒椾换鍔�";
+                            var task = agvtaskService.Find(x => (x.agv_toaddress.Contains("W") || x.agv_toaddress.Contains("X")) && x.agv_taskstate == "Queue" && x.agv_tasktype == "TaskType_EmptyPallet" && x.agv_Traytype == station.tray_type).OrderByDescending(x => x.agv_grade).ThenBy(x => x.agv_createtime).FirstOrDefault();
+                            if (task != null)
                             {
-                                agv_fromaddress = station.stationCode,
-                                agv_id = Guid.NewGuid(),
-                                agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
-                                agv_grade = station.stationCode.Contains("S0100100") ? 3 : 1,
-                                agv_createtime = DateTime.Now,
-                                agv_taskstate = "Create",
-                                //agv_materielid = station.stationType,
-                                agv_qty = 1,
-                                StarQuantity = 0,
-                                EndQuantity = EmptyStation.quantity,
-                                agv_tasktype = "TaskType_EmptyPallet",
-                                agv_toaddress = EmptyStation.stationCode,
-                                agv_userid = "绯荤粺",
-                                agv_TrayStatus = "EmptyTray",//station.tray_status,
-                                agv_Traytype = station.tray_type,
-                            };
-                            agvtaskService.Add(agvtask, true);
-                            station.location_state = LocationStateEnum.Busy.ToString();
-                            stationinfoRepository.Update(station, true);
-                            EmptyStation.location_state = LocationStateEnum.Busy.ToString();
-                            stationinfoRepository.Update(EmptyStation, true);
-                            WriteDBLog.Success("鍒涘缓鑷姩鍙栫┖鎵樹换鍔�", $"浠诲姟缂栧彿锛歿agvtask.agv_tasknum}", "PCS");
-                            return;
+                                task.agv_fromaddress = station.stationCode;
+                                task.StarQuantity = 0;
+                                task.agv_taskstate = "Create";
+                                if (station.stationCode.Contains("S0100100"))
+                                    task.agv_grade = 3;
+                                agvtaskService.Update(task, true);
+                                station.location_state = LocationStateEnum.Busy.ToString();
+                                stationinfoRepository.Update(station, true);
+                                WriteDBLog.Success("鏇存柊绌烘墭闃熷垪浠诲姟", $"浠诲姟缂栧彿锛歿task.agv_tasknum}锛屾墭鐩樹俊鍙�:{PalletSignal},璐х墿淇″彿:{MaterialSignal}", "PCS");
+                                continue;
+                            }
+                            remark = "鏌ヨ绌烘墭鍙犵洏浣�";
+                            #region 绌烘墭鍙犵洏
+                            var EmptyStations = stationinfoRepository.Find(x => x.stationCode.Contains("DD") && x.quantity < 5 && x.enable).ToList();
+                            var EmptyStation = EmptyStations.Where(x => x.tray_type == station.tray_type && x.location_state == LocationStateEnum.Stroge.ToString()).FirstOrDefault();
+                            if (EmptyStation == null)
+                                EmptyStation = EmptyStations.Where(x => x.location_state == LocationStateEnum.Empty.ToString() && x.quantity == 0).FirstOrDefault();
+                            #endregion
+                            remark = "鏌ユ壘搴撳唴绌烘墭浣�";
+                            if (EmptyStation == null)//鏌ユ壘搴撳唴绌烘墭鐩�
+                                EmptyStation = GetStation.EmptyPalletStation(area);
+
+
+                            if (EmptyStation != null)
+                            {
+                                #region 鍚屼竴涓┖鎵樹綅鍙兘鍚屾椂鐢熸垚涓�涓┖鎵樹换鍔�
+                                remark = "鏌ヨ绌烘墭浣嶆槸鍚﹀瓨鍦ㄤ换鍔�";
+                                if (agvtaskService.Find(x => x.agv_fromaddress == EmptyStation.stationCode || x.agv_toaddress == EmptyStation.stationCode).Any())
+                                    return;
+                                #endregion
+                                dt_agvtask agvtask = new dt_agvtask()
+                                {
+                                    agv_fromaddress = station.stationCode,
+                                    agv_id = Guid.NewGuid(),
+                                    agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
+                                    agv_grade = station.stationCode.Contains("S0100100") ? 3 : 1,
+                                    agv_createtime = DateTime.Now,
+                                    agv_taskstate = "Create",
+                                    //agv_materielid = station.stationType,
+                                    agv_qty = 1,
+                                    StarQuantity = 0,
+                                    EndQuantity = EmptyStation.quantity,
+                                    agv_tasktype = "TaskType_EmptyPallet",
+                                    agv_toaddress = EmptyStation.stationCode,
+                                    agv_userid = "绯荤粺",
+                                    agv_TrayStatus = "EmptyTray",//station.tray_status,
+                                    agv_Traytype = station.tray_type,
+                                };
+                                agvtaskService.Add(agvtask, true);
+                                station.location_state = LocationStateEnum.Busy.ToString();
+                                stationinfoRepository.Update(station, true);
+                                EmptyStation.location_state = LocationStateEnum.Busy.ToString();
+                                stationinfoRepository.Update(EmptyStation, true);
+                                WriteDBLog.Success("鍒涘缓鑷姩鍙栫┖鎵樹换鍔�", $"浠诲姟缂栧彿锛歿agvtask.agv_tasknum}锛屾墭鐩樹俊鍙�:{PalletSignal},璐х墿淇″彿:{MaterialSignal}", "PCS");
+                            }
                         }
+                    }
+                    catch (Exception ex)
+                    {
+                        WriteDBLog.Error("鍒涘缓鑷姩鍙栫┖鎵樹换鍔�", $"{stationCode}锛歿remark}閿欒淇℃伅锛歿ex.Message}", "PCS");
                     }
                 }
             }
@@ -326,7 +520,7 @@
                         if (Station.quantity > 0 && (PalletSignal != 1 || MaterialSignal != 1))//绯荤粺璐т綅鏈夎溅杞紝鍏夌數妫�娴嬫棤杞﹁疆
                         {
                             Station.location_state = LocationStateEnum.Abnormal.ToString();
-                            Station.remark = "杞﹁疆鏁伴噺澶т簬0锛屽厜鐢垫娴嬫棤鎵樼洏鎴栨棤杞﹁疆";
+                            Station.remark = $"杞﹁疆鏁伴噺澶т簬0锛屾墭鐩樺厜鐢典俊鍙蜂负锛歿PalletSignal}锛岃揣鐗╁厜鐢典俊鍙蜂负锛歿MaterialSignal}";
                             stationinfoRepository.Update(Station, true);
                             client.WriteByOrder("W_AlarmSignal", (Int16)2, name);//鎶ヨ
                             WriteDBLog.Error(name + "鎶ヨ", $"璐т綅缂栧彿锛歿Station.stationCode}锛涢敊璇俊鎭細{Station.remark}", "PCS");
@@ -335,7 +529,7 @@
                         if (Station.location_state == LocationStateEnum.Stroge.ToString() && PalletSignal != 1)
                         {
                             Station.location_state = LocationStateEnum.Abnormal.ToString();
-                            Station.remark = "鍏夌數妫�娴嬫棤鎵樼洏";
+                            Station.remark = $"璐т綅鐘舵�佷负鏈夎揣锛屾墭鐩樺厜鐢典俊鍙蜂负锛歿PalletSignal}锛岃揣鐗╁厜鐢典俊鍙蜂负锛歿MaterialSignal}";
                             stationinfoRepository.Update(Station, true);
                             client.WriteByOrder("W_AlarmSignal", (Int16)2, name);//鎶ヨ
                             WriteDBLog.Error(name + "鎶ヨ", $"璐т綅缂栧彿锛歿Station.stationCode}锛涢敊璇俊鎭細{Station.remark}", "PCS");
@@ -344,7 +538,7 @@
                         if (Station.location_state == LocationStateEnum.Empty.ToString() && (PalletSignal == 1 || MaterialSignal == 1))//绯荤粺璐т綅涓虹┖锛屽厜鐢垫娴嬫湁鏂�
                         {
                             Station.location_state = LocationStateEnum.Abnormal.ToString();
-                            Station.remark = "鍏夌數妫�娴嬫湁鏂�";
+                            Station.remark = $"璐т綅鐘舵�佷负绌鸿揣浣嶏紝鎵樼洏鍏夌數淇″彿涓猴細{PalletSignal}锛岃揣鐗╁厜鐢典俊鍙蜂负锛歿MaterialSignal}";
                             stationinfoRepository.Update(Station, true);
                             client.WriteByOrder("W_AlarmSignal", (Int16)2, name);//鎶ヨ
                             WriteDBLog.Error(name + "鎶ヨ", $"璐т綅缂栧彿锛歿Station.stationCode}锛涢敊璇俊鎭細{Station.remark}", "PCS");
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/EmptyTrayIn.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/EmptyTrayIn.cs"
new file mode 100644
index 0000000..10751c5
--- /dev/null
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/EmptyTrayIn.cs"
@@ -0,0 +1,84 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using WIDESEA_Comm.LogInfo;
+using WIDESEA_Comm.TaskNo;
+using WIDESEA_Comm;
+using WIDESEA_Core.EFDbContext;
+using WIDESEA_Entity.DomainModels;
+using WIDESEA_WCS.IRepositories;
+using WIDESEA_WCS.Repositories;
+using static System.Collections.Specialized.BitVector32;
+using WIDESEA_WMS.IRepositories;
+using WIDESEA_WMS.Repositories;
+
+namespace WIDESEA_WCS.JobsPart.Common
+{
+    public class EmptyTray
+    {
+        /// <summary>
+        /// 绌烘墭鍙犵洏鍏ュ簱
+        /// </summary>
+        public static void EmptyTrayIn()
+        {
+            try
+            {
+                VOLContext Context = new VOLContext();
+                Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
+                Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(Context);
+                var EmptyStations = stationinfoRepository.Find(x => x.stationCode.Contains("DD") && x.quantity == 5 && x.enable).ToList();
+                foreach (var EmptyStation in EmptyStations)
+                {
+                    try
+                    {
+                        if (agvtaskRepository.Find(x => x.agv_fromaddress == EmptyStation.stationCode || x.agv_toaddress == EmptyStation.stationCode).Any()) continue;
+                        var area = EmptyStation.tray_type == "SmallTray" ? "11" : "10";
+                        var toEmptyStation = GetStation.EmptyPalletStation(area);
+                        if (toEmptyStation != null)
+                        {
+                            #region 鍚屼竴涓┖鎵樹綅鍙兘鍚屾椂鐢熸垚涓�涓┖鎵樹换鍔�
+                            if (agvtaskRepository.Find(x => x.agv_fromaddress == toEmptyStation.stationCode || x.agv_toaddress == toEmptyStation.stationCode).Any()) continue;
+                            #endregion
+
+                            dt_agvtask agvtask = new dt_agvtask()
+                            {
+                                agv_fromaddress = EmptyStation.stationCode,
+                                agv_id = Guid.NewGuid(),
+                                agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
+                                agv_grade = 3,
+                                agv_createtime = DateTime.Now,
+                                agv_taskstate = "Create",
+                                //agv_materielid = station.stationType,
+                                agv_qty = EmptyStation.quantity - toEmptyStation.quantity,
+                                StarQuantity = toEmptyStation.quantity,
+                                EndQuantity = toEmptyStation.quantity,
+                                agv_tasktype = "TaskType_EmptyPallet",
+                                agv_toaddress = toEmptyStation.stationCode,
+                                agv_userid = "绯荤粺",
+                                agv_TrayStatus = "EmptyTray",//station.tray_status,
+                                agv_Traytype = EmptyStation.tray_type,
+                            };
+                            agvtaskRepository.Add(agvtask, true);
+                            EmptyStation.location_state = LocationStateEnum.Busy.ToString();
+                            stationinfoRepository.Update(EmptyStation, true);
+                            toEmptyStation.location_state = LocationStateEnum.Busy.ToString();
+                            stationinfoRepository.Update(toEmptyStation, true);
+                            WriteDBLog.Success("鍒涘缓鍙犵洏浣嶇┖鎵樺叆搴撲换鍔�", $"浠诲姟缂栧彿锛歿agvtask.agv_tasknum}", "PCS");
+                        }
+                    }
+                    catch (Exception ex)
+                    {
+                        WriteDBLog.Success("鍒涘缓鍙犵洏浣嶇┖鎵樺叆搴撲换鍔�", $"閿欒淇℃伅锛歿ex.Message}", "PCS");
+                    }
+
+                }
+            }
+            catch (Exception ex)
+            {
+                WriteDBLog.Success("鍒涘缓鍙犵洏浣嶇┖鎵樺叆搴撲换鍔�", $"閿欒淇℃伅锛歿ex.Message}", "PCS");
+            }
+        }
+    }
+}
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/GetStation/EmptyPalletStation.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/GetStation/EmptyPalletStation.cs"
index 2a341b7..5d86ef2 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/GetStation/EmptyPalletStation.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/GetStation/EmptyPalletStation.cs"
@@ -105,7 +105,7 @@
             dt_stationinfo stationinfo = null;
             try
             {
-                if (stationinfoRepository.Find(x => x.area == EmptyStation.area && x.line == EmptyStation.line && x.location_state.Contains("Busy")).Any()) return null;
+                if (stationinfoRepository.Find(x => x.area == EmptyStation.area && x.line == EmptyStation.line && x.location_state.Contains("Busy")).Any()) return stationinfo;
 
 
                 stationinfo = stationinfoRepository.Find(x => x.area == EmptyStation.area && x.line == EmptyStation.line && x.quantity > 0 && x.enable).OrderByDescending(x => x.column).FirstOrDefault();
@@ -115,8 +115,12 @@
                     else
                         stationinfo = stationinfoRepository.Find(x => x.area == EmptyStation.area && x.line == EmptyStation.line && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.column).FirstOrDefault();
                 }
+                else
+                {
+                    stationinfo = stationinfoRepository.Find(x => x.area == EmptyStation.area && x.line == EmptyStation.line && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.column).FirstOrDefault();
+                }
                 //if (stationinfo == null)
-                //    stationinfo = stationinfoRepository.Find(x => x.area == EmptyStation.area && x.line == EmptyStation.line && x.quantity < 5 && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.column).FirstOrDefault();
+
             }
             catch (Exception ex)
             {
@@ -171,12 +175,16 @@
                 }
                 else
                 {
-                    stationinfo = stationinfoRepository.Find(x => x.area == area && x.quantity > 0 /*&& x.location_state == LocationStateEnum.Stroge.ToString()*/ && x.enable).OrderBy(x => x.column).FirstOrDefault();
+                    stationinfo = stationinfoRepository.Find(x => x.area == area && x.quantity > 0 && x.enable).OrderBy(x => x.column).FirstOrDefault();
                     if (stationinfo != null)
                     {
                         if (stationinfo.quantity < 5) return stationinfo;
                         else
-                            stationinfo = stationinfoRepository.Find(x => x.area == area && x.quantity < 5 && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderByDescending(x => x.column).FirstOrDefault();
+                            stationinfo = stationinfoRepository.Find(x => x.area == area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderByDescending(x => x.column).FirstOrDefault();
+                    }
+                    else
+                    {
+                        stationinfo = stationinfoRepository.Find(x => x.area == area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderByDescending(x => x.column).FirstOrDefault();
                     }
 
                 }
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/ReplaceTray.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/ReplaceTray.cs"
index a89959d..da98f63 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/ReplaceTray.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/ReplaceTray.cs"
@@ -54,10 +54,10 @@
         {
             try
             {
-                VOLContext context = new VOLContext();
+                VOLContext context = new VOLContext(); 
                 Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
-                Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(context);
-                var stations = stationinfoRepository.Find(x => (x.stationCode.Contains("X")|| x.stationCode.Contains("W01001004") || x.stationCode.Contains("W01001005")) && x.location_state == "Abnormal" /*LocationStateEnum.Abnormal.ToString()*/ && (x.tray_type == "SmallTray/LargeTray" || x.tray_type == "LargeTray/SmallTray") && x.enable).ToList();
+                Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(context);//"Abnormal" 
+                var stations = stationinfoRepository.Find(x => (x.stationCode.Contains("X") || x.stationCode.Contains("W01001004") || x.stationCode.Contains("W01001005")) && x.location_state == LocationStateEnum.Abnormal.ToString() && (x.tray_type == "SmallTray/LargeTray" || x.tray_type == "LargeTray/SmallTray") && x.enable).ToList();
                 foreach (var station in stations)
                 {
                     if (agvtaskRepository.Find(x => x.agv_fromaddress == station.stationCode || x.agv_toaddress == station.stationCode).Any()) continue;
@@ -99,7 +99,8 @@
                         EmptyStation.location_state = LocationStateEnum.Busy.ToString();
                         stationinfoRepository.Update(EmptyStation, true);
                         WriteDBLog.Success("鍒涘缓鏇存崲绌虹洏浠诲姟", $"浠诲姟缂栧彿锛歿agvtask.agv_tasknum}", "PCS");
-                        CreatePartQueue(agvtaskRepository, agvtask, types[1]);
+                        CreatePartQueue(agvtaskRepository, agvtask, agvtask.agv_Traytype == "SmallTray" ? "LargeTray" : "SmallTray");
+                        //CreatePartQueue(agvtaskRepository, agvtask, types[1]);
                     }
                 }
             }
@@ -129,7 +130,7 @@
                 agv_toaddress = agvtask.agv_fromaddress,
                 agv_userid = "绯荤粺",
                 agv_TrayStatus = agvtask.agv_TrayStatus,
-                agv_Traytype = type == "" ? agvtask.agv_Traytype : type,
+                agv_Traytype = type,
             };
             agvtaskRepository.Add(taskPart, true);
             WriteDBLog.Success("鍒涘缓鏇存崲绌虹洏浠诲姟", $"浠诲姟缂栧彿锛歿taskPart.agv_tasknum}", "PCS");
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/RestockHCJ.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/RestockHCJ.cs"
index 9c9d9dc..2825cc2 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/RestockHCJ.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/RestockHCJ.cs"
@@ -37,131 +37,92 @@
                 var tasks = agvtaskService.Find(x => x.agv_taskstate == "Queue").OrderByDescending(x => x.agv_grade).ThenBy(x => x.agv_createtime).ToList();
                 foreach (var task in tasks)
                 {
-                    if (task.agv_tasktype == "TaskType_EmptyPallet")//绌烘墭浠诲姟
+                    try
                     {
-                        if (task.agv_fromaddress == "" && DateTime.Now - task.agv_createtime >= TimeSpan.FromMinutes(2))
+                        if (task.agv_tasktype == "TaskType_EmptyPallet")//绌烘墭浠诲姟
                         {
-                            if (task.agv_tasknum.Contains("_"))
+                            if (task.agv_fromaddress == "" && DateTime.Now - task.agv_createtime >= TimeSpan.FromMinutes(2))
                             {
-                                string mainTaskNum = task.agv_tasknum.Split('_')[0];
-                                if (agvtaskService.Find(x => x.agv_tasknum == mainTaskNum && task.agv_taskstate != "Executing" && task.agv_taskstate != "Create").Any() || !agvtaskService.Find(x => x.agv_tasknum == mainTaskNum).Any())
+                                if (task.agv_tasknum.Contains("_"))
+                                {
+                                    string mainTaskNum = task.agv_tasknum.Split('_')[0];
+                                    if (agvtaskService.Find(x => x.agv_tasknum == mainTaskNum && task.agv_taskstate != "Executing" && task.agv_taskstate != "Create").Any() || !agvtaskService.Find(x => x.agv_tasknum == mainTaskNum).Any())
+                                        GetStation.EmptyPalletStation(task);
+                                }
+                                else
                                     GetStation.EmptyPalletStation(task);
+
+                                WriteDBLog.Success("鏇存柊绌烘墭闃熷垪浠诲姟", $"浠诲姟缂栧彿锛歿task.agv_tasknum}", "PCS");
+                                continue;
                             }
-                            else
-                                GetStation.EmptyPalletStation(task);
-                            #region
-                            //var Pipeline_client = PLCClient.Clients.FirstOrDefault(t => t.PLCName == "閾炬潯鏈�");
-                            //if (Pipeline_client == null) throw new Exception("閾炬潯鏈鸿皟搴︽湇鍔℃湭寮�鍚紒");
-                            //if (!Pipeline_client.IsConnected) throw new Exception("涓庨摼鏉℃満杩炴帴瓒呮椂锛�");
-                            //var area = task.agv_Traytype == "SmallTray" ? "11" : "10";
-                            ////鎵�1搴撳尯鐨勭┖鎵樹綅
-                            //var EmptyStation = stationinfoRepository.Find(x => x.area == area && x.quantity > 0 && x.stationCode.Contains("A") /*&& x.location_state == "Stroge"*//*LocationStateEnum.Stroge.ToString()*/ && x.enable).OrderBy(x => x.column).ThenBy(x => x.line).FirstOrDefault();
-                            //if (EmptyStation != null)
-                            //    if (EmptyStation.location_state == LocationStateEnum.Busy.ToString()) EmptyStation = null;
-                            //#region 涓�涓尯鍩熷彧鑳芥湁涓�涓┖鎵樹换鍔�
-                            ////bool ok = false;
-                            ////if (EmptyStation != null)
-                            ////    ok = agvtaskService.Find(x => x.agv_fromaddress == EmptyStation.stationCode || x.agv_toaddress == EmptyStation.stationCode).Any();
-                            ////if (EmptyStation == null || ok)
-                            ////    EmptyStation = stationinfoRepository.Find(x => x.area == area && x.quantity > 0 && x.stationCode.Contains(area == "10" ? "D" : "C") && x.location_state == "Stroge" /*LocationStateEnum.Stroge.ToString()*/ && x.enable)
-                            ////    .OrderBy(x => x.line).OrderByDescending(x => x.column).FirstOrDefault();
-                            //#endregion
-                            //if (EmptyStation == null)
-                            //    EmptyStation = stationinfoRepository.Find(x => x.area == area && x.quantity > 0 && x.stationCode.Contains(area == "10" ? "D" : "C") && x.enable).OrderByDescending(x => x.column).FirstOrDefault();
-                            //if (EmptyStation == null) continue;
-                            //#region 搴撳唴瀛樺湪浠诲姟鍗犵敤
-                            //if (EmptyStation.location_state == LocationStateEnum.Busy.ToString())
-                            //    continue;
-                            //#endregion
-
-                            //if (EmptyStation == null)
-                            //    EmptyStation = stationinfoRepository.Find(x => x.area == area && x.quantity > 0 && x.stationCode.Contains(area == "10" ? "D" : "C") && x.location_state == "Stroge" && x.enable).OrderByDescending(x => x.column).FirstOrDefault();
-                            //if (EmptyStation != null)
-                            //{
-                            //    #region 搴撳唴瀛樺湪浠诲姟鍗犵敤
-                            //    //if (EmptyStation.location_state == LocationStateEnum.Busy.ToString())
-                            //    //    continue;
-                            //    #endregion
-
-                            //    //if (agvtaskService.Find(x => x.agv_fromaddress == EmptyStation.stationCode || x.agv_toaddress == EmptyStation.stationCode).Any())
-                            //    //    return;
-                            //    #region 琛ュ簱鍐呯┖鎵樼洏锛屼笉闇�瑕佸厜鐢靛垽鏂�
-                            //    var PalletSignal = Pipeline_client.ReadByOrder<Int16>("R_PalletSignal", task.agv_toaddress);//璇诲彇鎵樼洏淇″彿:1:鏈�,2鏃�
-                            //    var MaterialSignal = Pipeline_client.ReadByOrder<Int16>("R_MaterialSignal", task.agv_toaddress);//璇诲彇璐х墿淇″彿:1:鏈�,2鏃�
-                            //    if (PalletSignal == 2 && MaterialSignal == 2)
-                            //    {
-                            //        task.agv_fromaddress = EmptyStation.stationCode;
-                            //        task.StarQuantity = EmptyStation.quantity - 1;
-                            //        task.agv_taskstate = "Create";
-                            //        agvtaskService.Update(task, true);
-                            //        EmptyStation.location_state = LocationStateEnum.Busy.ToString();
-                            //        stationinfoRepository.Update(EmptyStation, true);
-                            //        WriteDBLog.Success("鏇存柊绌虹洏闃熷垪浠诲姟", $"浠诲姟缂栧彿锛歿task.agv_tasknum}", "PCS");
-                            //    }
-                            //    #endregion
-                            //}
-                            #endregion
                         }
-                    }
-                    else if (task.agv_tasktype == "TaskType_OutsourceInbound" || task.agv_tasktype == "TaskType_Inbound")//澶栧崗搴撳叆搴�/AB搴撳叆搴�
-                    {
-                        if (task.agv_toaddress == "")
+                        else if (task.agv_tasktype == "TaskType_OutsourceInbound" || task.agv_tasktype == "TaskType_Inbound")//澶栧崗搴撳叆搴�/AB搴撳叆搴�
                         {
-                            var stationinfo = stationinfoRepository.Find(x => x.stationCode == task.agv_fromaddress).FirstOrDefault();
-                            var work = workinfoRepository.Find(x => x.workOrder == stationinfo.Number && x.drawingNo == stationinfo.stationType && x.heatID == stationinfo.heatNumber && x.processCode == "17").FirstOrDefault();
-                            var TargetLocation = task.agv_tasktype == "TaskType_Inbound" ? GetLocation.GetEmptyLocation(stationinfoRepository, work, stationinfo) : StationTask.GetEmptyLocation(stationinfoRepository);
-                            if (TargetLocation != null)
+                            if (task.agv_toaddress == "")
                             {
-                                if (agvtaskService.Find(x => x.agv_toaddress == TargetLocation.stationCode).Any()) continue;
-                                task.agv_taskstate = "Create";
-                                task.agv_toaddress = TargetLocation.stationCode;
-                                TargetLocation.location_state = LocationStateEnum.InBusy.ToString();
-                                TargetLocation.billetID = stationinfo.billetID;
-                                TargetLocation.stationType = task.agv_materielid;
-                                TargetLocation.heatNumber = stationinfo.heatNumber;
-                                TargetLocation.Number = task.jobID;
-                                stationinfoRepository.Update(TargetLocation, true);
-                                agvtaskService.Update(task, true);
+                                var stationinfo = stationinfoRepository.Find(x => x.stationCode == task.agv_fromaddress).FirstOrDefault();
+                                var work = workinfoRepository.Find(x => x.workOrder == stationinfo.Number && x.drawingNo == stationinfo.stationType && x.heatID == stationinfo.heatNumber && x.processCode == "17").FirstOrDefault();
+                                var TargetLocation = task.agv_tasktype == "TaskType_Inbound" ? GetLocation.GetEmptyLocation(stationinfoRepository, work, task) : StationTask.GetEmptyLocation(stationinfoRepository);
+                                if (TargetLocation != null)
+                                {
+                                    if (agvtaskService.Find(x => x.agv_toaddress == TargetLocation.stationCode).Any()) continue;
+                                    task.agv_taskstate = "Create";
+                                    task.agv_toaddress = TargetLocation.stationCode;
+                                    TargetLocation.location_state = LocationStateEnum.InBusy.ToString();
+                                    TargetLocation.billetID = stationinfo.billetID;
+                                    TargetLocation.stationType = task.agv_materielid;
+                                    TargetLocation.heatNumber = stationinfo.heatNumber;
+                                    TargetLocation.Number = task.jobID;
+                                    stationinfoRepository.Update(TargetLocation, true);
+                                    agvtaskService.Update(task, true);
+                                    WriteDBLog.Success("鏇存柊鍏ュ簱闃熷垪浠诲姟", $"浠诲姟缂栧彿锛歿task.agv_tasknum}", "PCS");
+                                    continue;
+                                }
+                            }
+                        }
+                        else if (task.agv_tasktype == "TaskType_OutsourceOutbound" || task.agv_tasktype == "TaskType_Outbound")//澶栧崗搴撳嚭搴�/AB搴撳嚭搴�
+                        {
+                            if (task.agv_toaddress == "")
+                            {
+                                var EmptyStations = stationinfoRepository.Find(x => x.stationCode.Contains("S01001") && (x.tray_status == "EmptyTray" || x.location_state == "Empty") && x.enable).ToList();
+                                foreach (var EmptyStation in EmptyStations)
+                                {
+                                    if (agvtaskService.Find(x => x.agv_toaddress == EmptyStation.stationCode).Any()) continue;
+                                    task.agv_taskstate = "Create";
+                                    task.agv_toaddress = EmptyStation.stationCode;
+                                    EmptyStation.location_state = LocationStateEnum.Busy.ToString();
+                                    stationinfoRepository.Update(EmptyStation, true);
+                                    agvtaskService.Update(task, true);
+                                    WriteDBLog.Success("鏇存柊鍑哄簱闃熷垪浠诲姟", $"浠诲姟缂栧彿锛歿task.agv_tasknum}", "PCS");
+                                    return;
+                                }
+                            }
+                        }
+                        else if (task.agv_tasktype == "TaskType_OutsourceCarry")//绉诲簱澶栧崗
+                        {
+                            if (task.agv_toaddress == "")
+                            {
+                                var TargetLocation = StationTask.GetEmptyLocation(stationinfoRepository);
+                                if (TargetLocation != null)
+                                {
+                                    if (agvtaskService.Find(x => x.agv_toaddress == TargetLocation.stationCode).Any()) continue;
+
+                                    task.agv_taskstate = "Create";
+                                    task.agv_toaddress = TargetLocation.stationCode;
+                                    TargetLocation.location_state = LocationStateEnum.OutBusy.ToString();
+                                    TargetLocation.stationType = task.agv_materielid;
+                                    stationinfoRepository.Update(TargetLocation, true);
+                                    agvtaskService.Update(task, true);
+                                    WriteDBLog.Success("鏇存柊绉诲簱澶栧崗闃熷垪浠诲姟", $"浠诲姟缂栧彿锛歿task.agv_tasknum}", "PCS");
+                                    continue;
+                                }
                             }
                         }
                     }
-                    else if (task.agv_tasktype == "TaskType_OutsourceOutbound" || task.agv_tasktype == "TaskType_Outbound")//澶栧崗搴撳嚭搴�/AB搴撳嚭搴�
+                    catch (Exception ex)
                     {
-                        if (task.agv_toaddress == "")
-                        {
-                            var EmptyStations = stationinfoRepository.Find(x => x.stationCode.Contains("S01001") && x.tray_status == "EmptyTray" /*x.location_state == "Empty"*/ && x.enable).ToList();
-                            foreach (var EmptyStation in EmptyStations)
-                            {
-                                if (agvtaskService.Find(x => x.agv_toaddress == EmptyStation.stationCode).Any()) continue;
-                                task.agv_taskstate = "Create";
-                                task.agv_toaddress = EmptyStation.stationCode;
-                                EmptyStation.location_state = LocationStateEnum.Busy.ToString();
-                                stationinfoRepository.Update(EmptyStation, true);
-                                agvtaskService.Update(task, true);
-                                WriteDBLog.Success("鏇存柊鍑哄簱闃熷垪浠诲姟", $"浠诲姟缂栧彿锛歿task.agv_tasknum}", "PCS");
-                                return;
-                            }
-                        }
-                    }
-                    else if (task.agv_tasktype == "TaskType_OutsourceCarry")//绉诲簱澶栧崗
-                    {
-                        if (task.agv_toaddress == "")
-                        {
-                            var TargetLocation = StationTask.GetEmptyLocation(stationinfoRepository);
-                            if (TargetLocation != null)
-                            {
-                                if (agvtaskService.Find(x => x.agv_toaddress == TargetLocation.stationCode).Any()) continue;
-
-                                task.agv_taskstate = "Create";
-                                task.agv_toaddress = TargetLocation.stationCode;
-                                TargetLocation.location_state = LocationStateEnum.OutBusy.ToString();
-                                TargetLocation.stationType = task.agv_materielid;
-                                stationinfoRepository.Update(TargetLocation, true);
-                                agvtaskService.Update(task, true);
-                                WriteDBLog.Success("鏇存柊鍑哄簱闃熷垪浠诲姟", $"浠诲姟缂栧彿锛歿task.agv_tasknum}", "PCS");
-                                return;
-                            }
-                        }
+                        //WriteDBLog.Error("鏇存柊闃熷垪浠诲姟", $"閿欒淇℃伅锛歿ex.Message}", "PCS");
+                        WriteLog.Write_Log("鏇存柊闃熷垪浠诲姟","鏇存柊澶辫触", "", $"閿欒淇℃伅锛歿ex.Message}");
                     }
                 }
             }
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/\346\226\260\346\226\207\344\273\266\345\244\271/GetLocation.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/\346\226\260\346\226\207\344\273\266\345\244\271/GetLocation.cs"
index 48bcfbe..730c670 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/\346\226\260\346\226\207\344\273\266\345\244\271/GetLocation.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/\346\226\260\346\226\207\344\273\266\345\244\271/GetLocation.cs"
@@ -24,7 +24,7 @@
         /// <param name="mesinfo"></param>
         /// <param name="stationinfo"></param>
         /// <returns></returns>
-        public static dt_stationinfo GetEmptyLocation(Idt_stationinfoRepository stationinfoRepository, VV_Mes_Workinfo mesinfo, dt_stationinfo stationinfo)
+        public static dt_stationinfo GetEmptyLocation(Idt_stationinfoRepository stationinfoRepository, VV_Mes_Workinfo mesinfo, dt_agvtask agvtask)
         {
             lock (GetEmptyLocationobj)
             {
@@ -33,12 +33,12 @@
                     VOLContext context = new VOLContext();
                     Idt_inventoryRepository inventoryRepository = new dt_inventoryRepository(context);
                     string area1 = "";
-                    if (stationinfo.tray_type == "LargeTray")
+                    if (agvtask.agv_Traytype == "LargeTray")
                         area1 = "4";
 
                     #region 鏌ユ壘搴撳瓨
                     dt_inventory inventory = null;
-                    inventory = inventoryRepository.Find(x => x.FigureNumber == stationinfo.stationType).OrderByDescending(x => x.OnlineTime).FirstOrDefault();
+                    inventory = inventoryRepository.Find(x => x.FigureNumber == agvtask.agv_materielid).OrderByDescending(x => x.OnlineTime).FirstOrDefault();
                     #endregion
 
                     dt_stationinfo TargetLocation = null;
@@ -50,7 +50,7 @@
                         if (!string.IsNullOrEmpty(area1) && station.area != area1)//鍏ュぇ鎵樼洏搴撳尯
                         {
                             #region 瀵绘壘宸插垎閰嶅悓鍥惧彿鍏ュ簱浠诲姟搴撲綅
-                            TargetLocation = stationinfoRepository.Find(x => x.stationType == stationinfo.stationType && x.location_state == LocationStateEnum.InBusy.ToString() && x.area == area1).FirstOrDefault();
+                            TargetLocation = stationinfoRepository.Find(x => x.stationType == agvtask.agv_materielid && x.location_state == LocationStateEnum.InBusy.ToString() && x.area == area1).FirstOrDefault();
                             if (TargetLocation != null)
                             {
                                 TargetLocation = stationinfoRepository.Find(x => x.line == TargetLocation.line && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == TargetLocation.area).OrderBy(x => x.column).FirstOrDefault();
@@ -66,7 +66,7 @@
                             var TargetLocations1 = stationinfoRepository.Find(x => x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == area1).OrderBy(x => x.line).ThenBy(x => x.column).ToList();
                             foreach (var Location in TargetLocations1)
                             {
-                                if (!stationinfoRepository.Find(x => x.line == Location.line && x.area == Location.area && x.stationType == stationinfo.stationType && x.location_state == LocationStateEnum.OutBusy.ToString()).Any()) return Location;
+                                if (!stationinfoRepository.Find(x => x.line == Location.line && x.area == Location.area && x.stationType == agvtask.agv_materielid && x.location_state == LocationStateEnum.OutBusy.ToString()).Any()) return Location;
                             }
                             #endregion
 
@@ -95,7 +95,7 @@
                     #endregion
 
                     #region 瀵绘壘宸插垎閰嶅悓鍥惧彿鍏ュ簱浠诲姟搴撲綅
-                    TargetLocation = stationinfoRepository.Find(x => x.stationType == stationinfo.stationType && x.location_state == LocationStateEnum.InBusy.ToString() && (x.area == "1" || x.area == "2" || x.area == "3" || x.area == "4")).FirstOrDefault();
+                    TargetLocation = stationinfoRepository.Find(x => x.stationType == agvtask.agv_materielid && x.location_state == LocationStateEnum.InBusy.ToString() && (x.area == "1" || x.area == "2" || x.area == "3" || x.area == "4")).FirstOrDefault();
                     if (TargetLocation != null)
                     {
                         if (TargetLocation.area == "1")
@@ -126,17 +126,17 @@
                     {
                         if (Location.area == "1")
                         {
-                            if (stationinfoRepository.Find(x => x.column == Location.column && x.area == Location.area && x.stationType == stationinfo.stationType && x.location_state != LocationStateEnum.OutBusy.ToString()).Any()) return Location;
+                            if (stationinfoRepository.Find(x => x.column == Location.column && x.area == Location.area && x.stationType == agvtask.agv_materielid && x.location_state != LocationStateEnum.OutBusy.ToString()).Any()) return Location;
                         }
                         else
                         {
-                            if (!stationinfoRepository.Find(x => x.line == Location.line && x.area == Location.area && x.stationType == stationinfo.stationType && x.location_state == LocationStateEnum.OutBusy.ToString()).Any()) return Location;
+                            if (!stationinfoRepository.Find(x => x.line == Location.line && x.area == Location.area && x.stationType == agvtask.agv_materielid && x.location_state == LocationStateEnum.OutBusy.ToString()).Any()) return Location;
                         }
                     }
                     #endregion
 
                     #region 鏈壘鍒板簱瀛樻垨褰撳墠搴撳瓨琛屽凡婊�,瀵绘壘鏂扮殑涓�琛�
-                    var area = GetArea(mesinfo.quantity, stationinfo.tray_type);
+                    var area = GetArea(mesinfo.quantity, agvtask.agv_Traytype);
                     TargetLocation = stationinfoRepository.Find(x => x.column == 1 && x.area == area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).ThenBy(x => x.column).FirstOrDefault();
                     if (TargetLocation == null && area != "4")
                     {
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WebApi/appsettings.json" "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WebApi/appsettings.json"
index 7899d68..1d06fa1 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WebApi/appsettings.json"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WebApi/appsettings.json"
@@ -16,6 +16,7 @@
   "Connection": {
     "DBType": "MsSql", //MySql/MsSql/PgSql  //鏁版嵁搴撶被鍨嬶紝濡傛灉浣跨敤鐨勬槸sqlserver姝ゅ搴旇缃负MsSql
     //sqlserver杩炴帴瀛楃涓睵@ssw0rd
+    //"DbConnectionString": "Data Source=192.168.12.101;Initial Catalog=WIDESEA_DB;Persist Security Info=True;User ID=sa;Password=123456;Connect Timeout=500;",
     "DbConnectionString": "Data Source=.;Initial Catalog=WIDESEA_DB;Persist Security Info=True;User ID=sa;Password=P@ssw0rd;Connect Timeout=500;",
 
     //mysql杩炴帴瀛楃涓�(鍗囩骇EFCore3.1鍒版椂宸插皢mysql杩炴帴瀛楃涓蹭慨鏀�,2019-12-20)
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WMS_Server/WIDESEA_WebApi/Controllers/ToWms/ToWMSController.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WMS_Server/WIDESEA_WebApi/Controllers/ToWms/ToWMSController.cs"
index 605c66e..bf51130 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WMS_Server/WIDESEA_WebApi/Controllers/ToWms/ToWMSController.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WMS_Server/WIDESEA_WebApi/Controllers/ToWms/ToWMSController.cs"
@@ -41,6 +41,17 @@
         }
 
         /// <summary>
+        /// 澶栧崗璐т綅鎵爜纭鐗╂枡宸茶鍙栬蛋
+        /// </summary>
+        /// <param name="saveModel"></param>
+        /// <returns></returns>
+        [HttpPost, Route("Confirmedcut")]
+        public WebResponseContent Confirmedcut([FromBody] SaveModel saveModel)
+        {
+            return new ToMesServer().Confirmedcut(saveModel);
+        }
+
+        /// <summary>
         /// 鑾峰彇璐т綅
         /// </summary>
         /// <param name="request"></param>
diff --git "a/\351\241\271\347\233\256\350\265\204\346\226\231/\351\200\232\344\277\241\345\215\217\350\256\256/PCS\350\267\237AGV\345\222\214\346\241\201\346\236\266\351\230\262\345\221\206\344\272\244\344\272\222\345\215\217\350\256\256/PCS\345\222\214\346\241\201\346\236\266\345\215\217\350\256\256.xlsx" "b/\351\241\271\347\233\256\350\265\204\346\226\231/\351\200\232\344\277\241\345\215\217\350\256\256/PCS\350\267\237AGV\345\222\214\346\241\201\346\236\266\351\230\262\345\221\206\344\272\244\344\272\222\345\215\217\350\256\256/PCS\345\222\214\346\241\201\346\236\266\345\215\217\350\256\256.xlsx"
index 0bce243..206278d 100644
--- "a/\351\241\271\347\233\256\350\265\204\346\226\231/\351\200\232\344\277\241\345\215\217\350\256\256/PCS\350\267\237AGV\345\222\214\346\241\201\346\236\266\351\230\262\345\221\206\344\272\244\344\272\222\345\215\217\350\256\256/PCS\345\222\214\346\241\201\346\236\266\345\215\217\350\256\256.xlsx"
+++ "b/\351\241\271\347\233\256\350\265\204\346\226\231/\351\200\232\344\277\241\345\215\217\350\256\256/PCS\350\267\237AGV\345\222\214\346\241\201\346\236\266\351\230\262\345\221\206\344\272\244\344\272\222\345\215\217\350\256\256/PCS\345\222\214\346\241\201\346\236\266\345\215\217\350\256\256.xlsx"
Binary files differ

--
Gitblit v1.9.3