From 0b5ccdca6263cf7a2cee460f30c76ef1efea2811 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期六, 27 四月 2024 17:47:27 +0800
Subject: [PATCH] 人工出库,人工入库,人工移库,PDA扫码确认外协物料已被取走接口

---
 代码管理/PCS/WCS_Server/WIDESEA_WCS/Common/Gantry.cs |  228 +++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 141 insertions(+), 87 deletions(-)

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 c21cc86..ae19956 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"
@@ -1,4 +1,5 @@
 锘縰sing FreeSql.Internal.Model;
+using Newtonsoft.Json;
 using StackExchange.Redis;
 using System;
 using System.Collections.Generic;
@@ -434,7 +435,8 @@
                             var Wheel_SN = client.ReadByOrder<string>("R_Wheel_id", name);//杞﹁疆SN鍙�
                             if (string.IsNullOrEmpty(Wheel_SN))
                             {
-                                WriteDBLog.Error(name + "鏀炬枡瀹屾垚", $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN鍙蜂负绌�", "PCS");
+                                //WriteDBLog.Error(name + "鏀炬枡瀹屾垚", $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN鍙蜂负绌�", "PCS");
+                                WriteLog.Write_Log(name + "鏀炬枡瀹屾垚鍑洪敊", "杞﹁疆SN鍙蜂负绌�", "璇诲彇妗佹灦淇℃伅锛�", $"杞﹁疆SN鍙凤細{Wheel_SN}涓虹┖");
                                 continue;
                             }
 
@@ -443,7 +445,8 @@
                             if (Mes_Work == null)
                             {
                                 #region 鏃ュ織璁板綍
-                                WriteDBLog.Error(name, $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN鍙凤細{Wheel_SN}\n\n鏈煡璇㈠埌宸ュ崟璇︽儏", "PCS");
+                                //WriteDBLog.Error(name, $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN鍙凤細{Wheel_SN}\n\n鏈煡璇㈠埌宸ュ崟璇︽儏", "PCS");
+                                WriteLog.Write_Log(name + "鏀炬枡瀹屾垚鍑洪敊", Wheel_SN, "璇诲彇妗佹灦淇℃伅锛�", $"杞﹁疆SN鍙凤細{Wheel_SN}鏈煡璇㈠埌宸ュ崟淇℃伅");
                                 #endregion
                                 continue;
                             }
@@ -511,10 +514,14 @@
                             client.WriteByOrder("W_IndexNr", (Int16)0, name);//鎵樼洏涓婄殑绗嚑涓溅杞�
                             client.WriteByOrder("W_Storage_Type", (Int16)0, name);//鎵樼洏绫诲瀷1-妯斁;2-绔栨斁(鏆傛椂鍙湁妯斁鎵樼洏)
                             client.WriteByOrder("W_Storage_update", true, name);//璐т綅鐘舵�佹洿鏂�
-                            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");
+                            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
 
 
@@ -547,7 +554,9 @@
                         {
                             client.WriteByOrder("W_Storage_update", false, name);//璐т綅鐘舵�佹洿鏂�
                             #region 鏃ュ織璁板綍
-                            WriteDBLog.Success(name + "璐т綅鐘舵�佹洿鏂板浣�", $"璇诲彇妗佹灦淇℃伅锛歕nR_load_finished锛歿finished}\n\n鍐欏叆妗佹灦淇℃伅锛歕nW_Storage_update锛歿false}", "PCS");
+                            //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
@@ -561,13 +570,19 @@
                         #region 璇诲彇妗佹灦淇℃伅
                         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;
+                        if (string.IsNullOrEmpty(Wheel_id))
+                        {
+                            WriteLog.Write_Log(name + "鐢宠鏀炬枡寮傚父", "杞﹁疆SN鍙蜂负绌�", "", $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN鍙凤細{Wheel_id}涓虹┖");
+                            continue;
+                        }
+
 
                         var Work = workinfoRepository.Find(x => x.SN == Wheel_id && x.processCode == "17").FirstOrDefault();
                         if (Work == null)
                         {
                             client.WriteByOrder("W_Enabl_Load", false, name);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
-                            WriteDBLog.Error(name, $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN锛歿Wheel_id}\n\n鏈煡璇㈠埌宸ュ崟淇℃伅", "PCS");
+                            //WriteDBLog.Error(name, $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN锛歿Wheel_id}\n\n鏈煡璇㈠埌宸ュ崟淇℃伅", "PCS");
+                            WriteLog.Write_Log(name + "鐢宠鏀炬枡寮傚父", Wheel_id, "鏌ヨ鏈哄姞宸ュ伐鍗�", $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN鍙凤細{Wheel_id}鏈煡璇㈠埌宸ュ崟淇℃伅\n鍐欏叆妗佹灦淇℃伅锛歕n鏄惁鍏佽涓嬫枡锛歿false}");
                         }
 
                         #region MyRegion
@@ -619,7 +634,8 @@
                         {
                             #region 鏃ュ織璁板綍
                             client.WriteByOrder("W_Enabl_Load", false, name);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
-                            WriteDBLog.Error(name, $"鏈煡璇㈠埌杞﹁疆淇℃伅锛�", "PCS");
+                            //WriteDBLog.Error(name, $"鏈煡璇㈠埌杞﹁疆淇℃伅锛�", "PCS");
+                            WriteLog.Write_Log(name + "鐢宠鏀炬枡寮傚父", Wheel_id, $"鏌ヨ{Work.drawingNo}杞﹁疆鍙傛暟", $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN鍙凤細{Wheel_id}鏈煡璇㈠埌宸ュ崟淇℃伅\n鍐欏叆妗佹灦淇℃伅锛歕n鏄惁鍏佽涓嬫枡锛歿false}");
                             #endregion
                             continue;
                         }
@@ -628,7 +644,8 @@
 
                         var load_zone = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_load_zone").First(), client);
                         #region 鏃ュ織璁板綍
-                        WriteDBLog.Success(name + "鐢宠鏀炬枡", $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN锛歿Wheel_id}\n杞瀷ID锛歿Wheel_Type}\n杞﹁疆鐘舵�侊細{PartStatus}\n鏄惁杩涘叆涓嬫枡鍖猴細{load_zone}", "PCS");
+                        //WriteDBLog.Success(name + "鐢宠鏀炬枡", $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN锛歿Wheel_id}\n杞瀷ID锛歿Wheel_Type}\n杞﹁疆鐘舵�侊細{PartStatus}\n鏄惁杩涘叆涓嬫枡鍖猴細{load_zone}", "PCS");
+                        WriteLog.Write_Log(name + "鐢宠鏀炬枡", Wheel_id, "鐢宠鏀炬枡", $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN锛歿Wheel_id}\n杞瀷ID锛歿Wheel_Type}\n杞﹁疆鐘舵�侊細{PartStatus}\n鏄惁杩涘叆涓嬫枡鍖猴細{load_zone}");
                         if (load_zone) continue;
                         #endregion
                         if ((Int16)PartStatus == 1)
@@ -664,6 +681,7 @@
 
                             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)
@@ -695,15 +713,19 @@
 
                             if (Stationinfo != null)
                             {
+
+                                #region 鎹㈢被鍨嬬洿鎺ュ叆搴�
+                                var stationinfo1 = Stations.Where(x => x.enable && x.stationCode != NGStation && x.stationCode != Stationinfo.stationCode && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0 && x.stationType != Work.drawingNo).FirstOrDefault();
+                                if (stationinfo1 != null)
+                                    agvtask(stationinfoRepository, stationinfo1, Work, name == "3鍗曞厓涓嬫枡鍖�" ? "TaskType_OutsourceInbound" : "TaskType_Inbound");
+                                #endregion
+
                                 #region 鎵樼洏杞﹁疆鍫嗗灈绗洓涓椂涓嬪彂鍙﹀涓�涓倝鍙风殑鍏ュ簱浠诲姟
                                 if (Stationinfo.quantity + 1 >= 4)
                                 {
                                     var stationinfo = Stations.Where(x => x.enable && x.stationCode != NGStation && x.stationCode != Stationinfo.stationCode && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).FirstOrDefault();
-                                    //foreach (var stationinfo in stationinfos)
-                                    //{
                                     if (stationinfo != null)
                                         agvtask(stationinfoRepository, stationinfo, Work, name == "3鍗曞厓涓嬫枡鍖�" ? "TaskType_OutsourceInbound" : "TaskType_Inbound");
-                                    //}
                                 }
 
                                 #endregion
@@ -779,23 +801,32 @@
                                     client.WriteByOrder("W_Storage_Type", (Int16)1, name);//鎵樼洏绫诲瀷1-妯斁;2-绔栨斁(鏆傛椂鍙湁妯斁鎵樼洏)
                                     client.WriteByOrder("W_Enabl_Load", true, name);//鏄惁鍏佽
                                     #region 鏃ュ織璁板綍
-                                    WriteDBLog.Success(name + "鍏佽鏀炬枡", $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN锛歿Wheel_id}\n杞瀷ID锛歿Wheel_Type}\n杞﹁疆鐘舵�侊細OK" +
+                                    //WriteDBLog.Success(name + "鍏佽鏀炬枡", $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN锛歿Wheel_id}\n杞瀷ID锛歿Wheel_Type}\n杞﹁疆鐘舵�侊細OK" +$"\n璇诲彇鎵樼洏鍏夌數淇″彿锛歿PalletSignal}" +
+                                    //    $"\n\n鍐欏叆妗佹灦淇℃伅锛歕n涓嬫枡浣嶅彿锛歿area}\n绗嚑涓溅杞細{(Stationinfo.quantity + 1)}\n鎵樼洏绫诲瀷锛�1\nW_Enabl_Load锛歵rue", "PCS");
+                                    WriteLog.Write_Log(name + "鐢宠鏀炬枡", Wheel_id, "鍏佽鏀炬枡",
+                                        $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN锛歿Wheel_id}\n杞瀷ID锛歿Wheel_Type}\n杞﹁疆鐘舵�侊細鍚堟牸" +
                                         $"\n璇诲彇鎵樼洏鍏夌數淇″彿锛歿PalletSignal}" +
-                                        $"\n\n鍐欏叆妗佹灦淇℃伅锛歕n涓嬫枡浣嶅彿锛歿area}\n绗嚑涓溅杞細{(Stationinfo.quantity + 1)}\n鎵樼洏绫诲瀷锛�1\nW_Enabl_Load锛歵rue", "PCS");
+                                        $"\n\n鍐欏叆妗佹灦淇℃伅锛歕n涓嬫枡浣嶅彿锛歿area}\n绗嚑涓溅杞細{(Stationinfo.quantity + 1)}\n鎵樼洏绫诲瀷锛�1\n鏄惁鍏佽涓嬫枡锛歵rue");
                                     #endregion
                                     continue;
                                 }
                             }
-                            //else
-                            //{
-                            //    #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, Work, name == "3鍗曞厓涓嬫枡鍖�" ? "TaskType_OutsourceInbound" : "TaskType_Inbound");
-                            //    }
-                            //    #endregion
-                            //}
+                            else
+                            {
+                                #region 娌℃墭鐩樺彲鐢�,瑙﹀彂鍏ュ簱浠诲姟
+                                if (!Stations.Where(x => x.enable && x.stationCode != NGStation && x.location_state != LocationStateEnum.Stroge.ToString()).Any())
+                                {
+                                    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
+                            }
 
                         }
                         else if ((Int16)PartStatus == 2)
@@ -829,11 +860,16 @@
 
                             if (Stationinfo == null)
                             {
-                                //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, stationinfo, (wheel == null ? wheel1.e : wheel.e), "TaskType_OutsourceInbound");
-                                //}
+                                #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)
+                                {
+                                    agvtask(stationinfoRepository, NG, Work, "TaskType_OutsourceInbound");
+                                    continue;
+                                }
+
+                                #endregion
+
                                 Stationinfo = Stations.Where(x => x.enable && x.stationCode == NGStation && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity == 0).FirstOrDefault();
                             }
                             if (Stationinfo != null)
@@ -878,6 +914,7 @@
                                         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)
@@ -907,9 +944,12 @@
                                     client.WriteByOrder("W_Storage_Type", (Int16)1, name);//鎵樼洏绫诲瀷1-妯斁;2-绔栨斁(鏆傛椂鍙湁妯斁鎵樼洏)
                                     client.WriteByOrder("W_Enabl_Load", true, name);//鏄惁鍏佽
                                     #region 鏃ュ織璁板綍
-                                    WriteDBLog.Success(name + "鍏佽鏀炬枡", $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN锛歿Wheel_id}\n杞瀷ID锛歿Wheel_Type}\n杞﹁疆鐘舵�侊細NG" +
+                                    //WriteDBLog.Success(name + "鍏佽鏀炬枡", $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN锛歿Wheel_id}\n杞瀷ID锛歿Wheel_Type}\n杞﹁疆鐘舵�侊細NG" +$"\n璇诲彇鎵樼洏鍏夌數淇″彿锛歿PalletSignal}" +
+                                    //    $"\n\n鍐欏叆妗佹灦淇℃伅锛歕n涓嬫枡浣嶅彿锛歿area}\n绗嚑涓溅杞細{(Stationinfo.quantity + 1)}\n鎵樼洏绫诲瀷锛�1\nW_Enabl_Load锛歵rue", "PCS");
+                                    WriteLog.Write_Log(name + "鐢宠鏀炬枡", Wheel_id, "鍏佽鏀炬枡",
+                                        $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN锛歿Wheel_id}\n杞瀷ID锛歿Wheel_Type}\n杞﹁疆鐘舵�侊細鍚堟牸" +
                                         $"\n璇诲彇鎵樼洏鍏夌數淇″彿锛歿PalletSignal}" +
-                                        $"\n\n鍐欏叆妗佹灦淇℃伅锛歕n涓嬫枡浣嶅彿锛歿area}\n绗嚑涓溅杞細{(Stationinfo.quantity + 1)}\n鎵樼洏绫诲瀷锛�1\nW_Enabl_Load锛歵rue", "PCS");
+                                        $"\n\n鍐欏叆妗佹灦淇℃伅锛歕n涓嬫枡浣嶅彿锛歿area}\n绗嚑涓溅杞細{(Stationinfo.quantity + 1)}\n鎵樼洏绫诲瀷锛�1\n鏄惁鍏佽涓嬫枡锛歵rue");
                                     #endregion
                                     continue;
                                 }
@@ -982,66 +1022,80 @@
         }
         #endregion
 
-        /// <summary>
-        /// AGV浠诲姟
-        /// </summary>
         public void agvtask(Idt_stationinfoRepository stationinfoRepository, dt_stationinfo stationinfo, VV_Mes_Workinfo Work, string tasktype)
         {
             VOLContext Context = new VOLContext();
             Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(Context);
-            Idt_mes_headRepository mes_HeadRepository = new dt_mes_headRepository(Context);
-
             var task = agvtaskRepository.Find(x => x.agv_fromaddress == stationinfo.stationCode).FirstOrDefault();
             if (task != null) return;
-            //var mes_Head = mes_HeadRepository.Find(x => x.jobID == Work.jobID).FirstOrDefault();
-            //if (mes_Head == null)
-            //{
-            //    stationinfo.remark = "瑙﹀彂鍏ュ簱浠诲姟,浣嗘湭鎵惧埌宸ュ崟澶磋〃锛�";
-            //    stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
-            //    stationinfoRepository.Update(stationinfo, true);
-            //    return;
-            //}
-
-            dt_stationinfo TargetLocation = null;
-            //int CompeletedNum = Convert.ToInt32(mes_Head.quantity) - Convert.ToInt32(mes_Head.finishNum);
-            //if (mes_Head.quantity <= 50) tasktype = "TaskType_OutsourceInbound";
-
-            if (tasktype == "TaskType_OutsourceInbound" || !string.IsNullOrEmpty(Work.area))
-                TargetLocation = StationTask.GetEmptyLocation(stationinfoRepository);
-            else if (tasktype == "TaskType_Inbound")
-                TargetLocation = GetLocation.GetEmptyLocation(stationinfoRepository, Work, stationinfo);
-            //TargetLocation = GetLocation.GetEmptyLocation(stationinfoRepository, mes_Head, stationinfo);
-            if (TargetLocation != null)
-            {
-                dt_agvtask agvtask = new dt_agvtask()
-                {
-                    agv_fromaddress = stationinfo.stationCode,
-                    agv_id = Guid.NewGuid(),
-                    agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
-                    agv_grade = 1,
-                    agv_createtime = DateTime.Now,
-                    agv_taskstate = "Create",
-                    agv_materielid = stationinfo.stationType,
-                    agv_qty = stationinfo.quantity,
-                    agv_tasktype = tasktype,
-                    agv_toaddress = TargetLocation.stationCode,
-                    agv_userid = "绯荤粺",
-                    bindSN = stationinfo.bindSN,
-                    agv_worktype = Convert.ToInt32(Work.processCode),
-                    agv_materbarcode = Work.materialCode,
-                    agv_Traytype = stationinfo.tray_type,
-                    jobID = stationinfo.Number,
-                    agv_TrayStatus = stationinfo.tray_status
-                };
-                agvtaskRepository.Add(agvtask, true);
-                stationinfo.location_state = LocationStateEnum.InBusy.ToString();
-                stationinfoRepository.Update(stationinfo, true);
-                TargetLocation.location_state = LocationStateEnum.InBusy.ToString();
-                TargetLocation.stationType = agvtask.agv_materielid;
-                TargetLocation.heatNumber = stationinfo.heatNumber;
-                TargetLocation.Number = agvtask.jobID;
-                stationinfoRepository.Update(TargetLocation, true);
-            }
+            if (!string.IsNullOrEmpty(Work.area))
+                tasktype = "TaskType_OutsourceInbound";
+            AGVTask.AddQueueTask(stationinfoRepository, agvtaskRepository, stationinfo, tasktype, Work);
         }
+
+        #region MyRegion
+        /// <summary>
+        /// AGV浠诲姟
+        /// </summary>
+        //public void agvtask(Idt_stationinfoRepository stationinfoRepository, dt_stationinfo stationinfo, VV_Mes_Workinfo Work, string tasktype)
+        //{
+        //    VOLContext Context = new VOLContext();
+        //    Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(Context);
+        //    Idt_mes_headRepository mes_HeadRepository = new dt_mes_headRepository(Context);
+
+        //    var task = agvtaskRepository.Find(x => x.agv_fromaddress == stationinfo.stationCode).FirstOrDefault();
+        //    if (task != null) return;
+        //    //var mes_Head = mes_HeadRepository.Find(x => x.jobID == Work.jobID).FirstOrDefault();
+        //    //if (mes_Head == null)
+        //    //{
+        //    //    stationinfo.remark = "瑙﹀彂鍏ュ簱浠诲姟,浣嗘湭鎵惧埌宸ュ崟澶磋〃锛�";
+        //    //    stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
+        //    //    stationinfoRepository.Update(stationinfo, true);
+        //    //    return;
+        //    //}
+
+        //    dt_stationinfo TargetLocation = null;
+        //    //int CompeletedNum = Convert.ToInt32(mes_Head.quantity) - Convert.ToInt32(mes_Head.finishNum);
+        //    //if (mes_Head.quantity <= 50) tasktype = "TaskType_OutsourceInbound";
+
+        //    if (tasktype == "TaskType_OutsourceInbound" || !string.IsNullOrEmpty(Work.area))
+        //        TargetLocation = StationTask.GetEmptyLocation(stationinfoRepository);
+        //    else if (tasktype == "TaskType_Inbound")
+        //        TargetLocation = GetLocation.GetEmptyLocation(stationinfoRepository, Work, stationinfo);
+        //    //TargetLocation = GetLocation.GetEmptyLocation(stationinfoRepository, mes_Head, stationinfo);
+        //    if (TargetLocation != null)
+        //    {
+        //        dt_agvtask agvtask = new dt_agvtask()
+        //        {
+        //            agv_fromaddress = stationinfo.stationCode,
+        //            agv_id = Guid.NewGuid(),
+        //            agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
+        //            agv_grade = 1,
+        //            agv_createtime = DateTime.Now,
+        //            agv_taskstate = "Create",
+        //            agv_materielid = stationinfo.stationType,
+        //            agv_qty = stationinfo.quantity,
+        //            agv_tasktype = tasktype,
+        //            agv_toaddress = TargetLocation.stationCode,
+        //            agv_userid = "绯荤粺",
+        //            bindSN = stationinfo.bindSN,
+        //            agv_worktype = Convert.ToInt32(Work.processCode),
+        //            agv_materbarcode = Work.materialCode,
+        //            agv_Traytype = stationinfo.tray_type,
+        //            jobID = stationinfo.Number,
+        //            agv_TrayStatus = stationinfo.tray_status
+        //        };
+        //        agvtaskRepository.Add(agvtask, true);
+        //        stationinfo.location_state = LocationStateEnum.InBusy.ToString();
+        //        stationinfoRepository.Update(stationinfo, true);
+        //        TargetLocation.location_state = LocationStateEnum.InBusy.ToString();
+        //        TargetLocation.stationType = agvtask.agv_materielid;
+        //        TargetLocation.heatNumber = stationinfo.heatNumber;
+        //        TargetLocation.Number = agvtask.jobID;
+        //        stationinfoRepository.Update(TargetLocation, true);
+        //    }
+        //}
+        #endregion
+
     }
 }

--
Gitblit v1.9.3