From 73a926018601d9a5a5a3d3f4c051537f45a8eff4 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期四, 14 三月 2024 09:33:38 +0800
Subject: [PATCH] 优化代码逻辑

---
 代码管理/PCS/WCS_Server/WIDESEA_WCS/Common/Gantry.cs |  284 ++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 230 insertions(+), 54 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 7b6af49..7f19a23 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,11 +1,14 @@
-锘縰sing StackExchange.Redis;
+锘縰sing FreeSql.Internal.Model;
+using StackExchange.Redis;
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using WIDESEA_Comm;
+using WIDESEA_Comm.LogInfo;
 using WIDESEA_Core.EFDbContext;
+using WIDESEA_Core.FreeDB;
 using WIDESEA_WCS.IRepositories;
 using WIDESEA_WCS.Repositories;
 using WIDESEA_WCS.WCSClient;
@@ -15,20 +18,26 @@
 {
     public class Gantry
     {
-        static 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_geometry_data_detectionlineRepository detectionlineRepository = new dt_geometry_data_detectionlineRepository(Context);
-        Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
-        Idt_mes_detailRepository mes_DetailRepository = new dt_mes_detailRepository(Context);
-        Idt_mes_headRepository mes_HeadRepository = new dt_mes_headRepository(Context);
-        Idt_patternRepository patternRepository = new dt_patternRepository(Context);
+        //FreeDB freeDB = new FreeDB();
+        //static 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_geometry_data_detectionlineRepository detectionlineRepository = new dt_geometry_data_detectionlineRepository(Context);
+        ////Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
+        //Idt_mes_detailRepository mes_DetailRepository = new dt_mes_detailRepository(Context);
+        //Idt_mes_headRepository mes_HeadRepository = new dt_mes_headRepository(Context);
+        //Idt_patternRepository patternRepository = new dt_patternRepository(Context);
         #region 鏌ヨ杞﹁疆鏁版嵁
         public void QueryWheeldata(PLCClient client)
         {
             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_geometry_data_detectionlineRepository detectionlineRepository = new dt_geometry_data_detectionlineRepository(Context);
                 var plc = repository.FindFirst(x => x.plcinfo_name == client.PLCName);
                 List<string> names = new List<string>() { "1鍗曞厓杈婇亾涓嬫枡鏌ヨ杞﹁疆", "2鍗曞厓杈婇亾涓嬫枡鏌ヨ杞﹁疆", "3鍗曞厓杈婇亾涓嬫枡鏌ヨ杞﹁疆", "杈婇亾涓婃枡鏌ヨ杞﹁疆" };
                 foreach (string name in names)
@@ -47,6 +56,9 @@
                                 //1-鎵惧埌鏁版嵁锛�2-鏈壘鍒板伐浠剁被鍨嬫暟鎹�
                                 client.WriteByOrder("W_i_status", (byte)2, name);
                                 client.WriteByOrder("R_oi_on", (byte)0, name);
+                                #region 鏃ュ織璁板綍
+                                WriteDBLog.Error(name, $"璇诲彇妗佹灦淇℃伅锛歕n杞瀷ID锛歿wp_type}\n\n鍐欏叆妗佹灦淇℃伅锛歕nW_i_status锛�2\nR_oi_on锛�0\n\n鏈煡璇㈠埌鏈哄姞宸ヨ溅杞俊鎭�", "PCS");
+                                #endregion
                             }
                             else
                             {
@@ -61,6 +73,10 @@
                                 client.WriteByOrder("W_i_parameter_g", (float)geometry.g, name);
                                 client.WriteByOrder("W_i_parameter_h", (float)geometry.h, name);
                                 client.WriteByOrder("R_oi_on", (byte)0, name);
+                                #region 鏃ュ織璁板綍
+                                WriteDBLog.Success(name, $"璇诲彇妗佹灦淇℃伅锛歕n杞瀷ID锛歿wp_type}\n\n鍐欏叆妗佹灦淇℃伅锛歕nW_i_status锛�1" + $"\na锛歿(float)geometry.a}\nb锛歿(float)geometry.b}\nc锛歿(float)geometry.c}\n" +
+                                    $"d锛歿(float)geometry.d}\ne锛歿(float)geometry.e}\nf锛歿(float)geometry.f}\ng锛歿(float)geometry.g}\nh锛歿(float)geometry.h}\nR_oi_on锛�0", "PCS");
+                                #endregion
                             }
                         }
                         else
@@ -70,6 +86,9 @@
                             {
                                 client.WriteByOrder("W_i_status", (byte)2, name);
                                 client.WriteByOrder("R_oi_on", (byte)0, name);
+                                #region 鏃ュ織璁板綍
+                                WriteDBLog.Error(name, $"璇诲彇妗佹灦淇℃伅锛歕n杞瀷ID锛歿wp_type}\n\n鍐欏叆妗佹灦淇℃伅锛歕nW_i_status锛�2\nR_oi_on锛�0\n\n鏈煡璇㈠埌妫�娴嬬嚎杞﹁疆淇℃伅", "PCS");
+                                #endregion
                             }
                             else
                             {
@@ -83,6 +102,10 @@
                                 client.WriteByOrder("W_i_parameter_g", (float)geometry.g, name);
                                 client.WriteByOrder("W_i_parameter_h", (float)geometry.h, name);
                                 client.WriteByOrder("R_oi_on", (byte)0, name);
+                                #region 鏃ュ織璁板綍
+                                WriteDBLog.Success(name, $"璇诲彇妗佹灦淇℃伅锛歕n杞瀷ID锛歿wp_type}\n\n鍐欏叆妗佹灦淇℃伅锛歕nW_i_status锛�1" + $"\na锛歿(float)geometry.a}\nb锛歿(float)geometry.b}\nc锛歿(float)geometry.c}\n" +
+                                    $"d锛歿(float)geometry.d}\ne锛歿(float)geometry.e}\nf锛歿(float)geometry.f}\ng锛歿(float)geometry.g}\nh锛歿(float)geometry.h}\nR_oi_on锛�0", "PCS");
+                                #endregion
                             }
                         }
 
@@ -101,21 +124,51 @@
         {
             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_geometry_data_detectionlineRepository detectionlineRepository = new dt_geometry_data_detectionlineRepository(Context);
+                Idt_mes_detailRepository mes_DetailRepository = new dt_mes_detailRepository(Context);
+                Idt_mes_headRepository mes_HeadRepository = new dt_mes_headRepository(Context);
+                Idt_patternRepository patternRepository = new dt_patternRepository(Context);
                 var plc = repository.FindFirst(x => x.plcinfo_name == client.PLCName);
                 List<string> names = new List<string>() { "1鍗曞厓杈婇亾涓嬫枡鏌ヨ璁㈠崟", "2鍗曞厓杈婇亾涓嬫枡鏌ヨ璁㈠崟", "3鍗曞厓杈婇亾涓嬫枡鏌ヨ璁㈠崟", "杈婇亾涓婃枡鏌ヨ璁㈠崟" };
                 foreach (string name in names)
                 {
                     var details = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep && x.plcdetail_number == name).ToList();
                     var on = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_oi_on").First(), client);
+                    //var on = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_oi_on" && x.plcdetail_number == name).First(), client);
                     if ((byte)on == 1)
                     {
                         //var wp_id = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_o_wp_id").First(), client).ToString();
                         var wp_id = client.ReadByOrder<string>("R_o_wp_id", name);
+                        if (string.IsNullOrEmpty(wp_id))
+                        {
+                            #region 鏃ュ織璁板綍
+                            client.WriteByOrder("W_i_status", (byte)2, name);
+                            client.WriteByOrder("R_oi_on", (byte)0, name);
+                            WriteDBLog.Error(name, $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN锛歿wp_id}\n\n鍐欏叆妗佹灦淇℃伅锛歕nW_i_status锛�2\nR_oi_on锛�0\n\n杞﹁疆SN鍙蜂负绌�", "PCS");
+                            #endregion
+                            continue;
+                        }
+                        var wp_type = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_o_wp_type").First(), client);
                         var mes_Detail = mes_DetailRepository.FindFirst(x => x.SN == wp_id);
+                        #region 娴嬭瘯浣跨敤
+                        if (mes_Detail == null)
+                        {
+                            mes_Detail = mes_DetailRepository.FindFirst(x => x.jobID == (name == "3鍗曞厓杈婇亾涓嬫枡鏌ヨ璁㈠崟" ? "01180127004-2" : "01180127004-1"));
+                            mes_Detail.SN = wp_id;
+                            mes_DetailRepository.Update(mes_Detail, true);
+                        }
+                        #endregion
                         if (mes_Detail == null)
                         {
                             client.WriteByOrder("W_i_status", (byte)2, name);
                             client.WriteByOrder("R_oi_on", (byte)0, name);
+                            #region 鏃ュ織璁板綍
+                            WriteDBLog.Error(name, $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN锛歿wp_id}\n\n鍐欏叆妗佹灦淇℃伅锛歕nW_i_status锛�2\nR_oi_on锛�0\n\n鏈煡璇㈠埌宸ュ崟璇︽儏", "PCS");
+                            #endregion
                             continue;
                         }
                         var mes_Head = mes_HeadRepository.FindFirst(x => x.jobID == mes_Detail.jobID);
@@ -123,6 +176,9 @@
                         {
                             client.WriteByOrder("W_i_status", (byte)2, name);
                             client.WriteByOrder("R_oi_on", (byte)0, name);
+                            #region 鏃ュ織璁板綍
+                            WriteDBLog.Error(name, $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN锛歿wp_id}\n\n鍐欏叆妗佹灦淇℃伅锛歕nW_i_status锛�2\nR_oi_on锛�0\n\n鏈煡璇㈠埌宸ュ崟澶磋〃", "PCS");
+                            #endregion
                             continue;
                         }
 
@@ -134,16 +190,21 @@
                             {
                                 client.WriteByOrder("W_i_status", (byte)4, name);
                                 client.WriteByOrder("R_oi_on", (byte)0, name);
+                                #region 鏃ュ織璁板綍
+                                WriteDBLog.Error(name, $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN锛歿wp_id}\n\n鍐欏叆妗佹灦淇℃伅锛歕nW_i_status锛�4\nR_oi_on锛�0\n\n鎵嬪姩鍏ュ簱妯″紡鏈�夋嫨搴撳尯", "PCS");
+                                #endregion
                                 continue;
                             }
-                            var wp_type = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_o_wp_type").First(), client);
                             //var geometry = dataRepository.FindFirst(x => x.TypeId == (Int32)wp_type);
-                            var geometry = dataRepository.FindFirst(x => x.Description == mes_Head.drawingNo);
+                            var geometry = dataRepository.Find(x => x.Description == mes_Head.drawingNo && x.TypeId == (Int32)wp_type).FirstOrDefault();
                             if (geometry == null)
                             {
                                 //1-濂�,鍏佽鍔犲伐锛�2-涓嶅湪鍒楄〃涓紝3-涓嶅姞宸ヨ溅杞被鍨嬶紝4-鎵嬪姩鍏ュ簱妯″紡浜哄伐鏈�夋嫨搴撳尯
                                 client.WriteByOrder("W_i_status", (byte)2, name);
                                 client.WriteByOrder("R_oi_on", (byte)0, name);
+                                #region 鏃ュ織璁板綍
+                                WriteDBLog.Error(name, $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN锛歿wp_id}\n杞瀷ID锛歿wp_type}\n\n鍐欏叆妗佹灦淇℃伅锛歕nW_i_status锛�2\nR_oi_on锛�0\n\n鏈煡璇㈠埌鏈哄姞宸ヨ溅杞俊鎭�", "PCS");
+                                #endregion
                                 continue;
                             }
                             else
@@ -159,22 +220,30 @@
                                 //灞忚斀宸ヨ壓(灞忚斀瑙嗚妫�娴�/灞忚斀娑傛补)
                                 //if (name != "杈婇亾涓婃枡鏌ヨ杞﹁疆")
                                 //{
-                                client.WriteByOrder("W_i_skip_op_SJ1", mes_Head.skip_op_1, name);//灞忚斀瑙嗚妫�娴嬭澶�1
-                                client.WriteByOrder("W_i_skip_op_SJ2", mes_Head.skip_op_2, name);//灞忚斀瑙嗚妫�娴嬭澶�2
+                                client.WriteByOrder("W_i_skip_op_SJ1", name == "3鍗曞厓杈婇亾涓嬫枡鏌ヨ璁㈠崟" ? true : mes_Head.skip_op_1, name);//灞忚斀瑙嗚妫�娴嬭澶�1
+                                client.WriteByOrder("W_i_skip_op_SJ2", name == "3鍗曞厓杈婇亾涓嬫枡鏌ヨ璁㈠崟" ? true : mes_Head.skip_op_2, name);//灞忚斀瑙嗚妫�娴嬭澶�2
                                 client.WriteByOrder("W_i_skip_op_LT", mes_Head.skip_op_3, name);//灞忚斀閾炬潯鏈�
                                 //}
                                 client.WriteByOrder("R_oi_on", (byte)0, name);
-
+                                #region 鏃ュ織璁板綍
+                                WriteDBLog.Success(name, $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN锛歿wp_id}\n杞瀷ID锛歿wp_type}\n\n鍐欏叆妗佹灦淇℃伅锛歕nW_i_status锛�1" +
+                                    $"\nW_i_job_id锛歿mes_Detail.jobID}\nW_i_drawing_id锛歿mes_Head.drawingNo}\nW_i_heat_id锛歿mes_Detail.heatID}\nW_i_batch_id锛歿mes_Detail.heatBatchID}" +
+                                    $"\nW_i_skip_op_SJ1锛歿(name == "3鍗曞厓杈婇亾涓嬫枡鏌ヨ璁㈠崟" ? true : mes_Head.skip_op_1)}\nW_i_skip_op_SJ2锛歿(name == "3鍗曞厓杈婇亾涓嬫枡鏌ヨ璁㈠崟" ? true : mes_Head.skip_op_2)}" +
+                                    $"\nW_i_skip_op_LT锛歿mes_Head.skip_op_3}\nR_oi_on锛�0", "PCS");
+                                #endregion
                             }
                         }
                         else
                         {
-                            var geometry = dataRepository.FindFirst(x => x.Description == mes_Head.drawingNo);
+                            var geometry = detectionlineRepository.Find(x => x.Description == mes_Head.drawingNo && x.TypeId == (Int32)wp_type).FirstOrDefault();
                             if (geometry == null)
                             {
                                 //1-濂�,鍏佽鍔犲伐锛�2-涓嶅湪鍒楄〃涓紝3-涓嶅姞宸ヨ溅杞被鍨嬶紝4-鎵嬪姩鍏ュ簱妯″紡浜哄伐鏈�夋嫨搴撳尯
                                 client.WriteByOrder("W_i_status", (byte)2, name);
                                 client.WriteByOrder("R_oi_on", (byte)0, name);
+                                #region 鏃ュ織璁板綍
+                                WriteDBLog.Error(name, $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN锛歿wp_id}\n杞瀷ID锛歿wp_type}\n\n鍐欏叆妗佹灦淇℃伅锛歕nW_i_status锛�2\nR_oi_on锛�0\n\n鏈煡璇㈠埌妫�娴嬬嚎杞﹁疆淇℃伅", "PCS");
+                                #endregion
                                 continue;
                             }
                             else
@@ -187,6 +256,10 @@
                                 //client.WriteByOrder("W_i_sourceheat", "", name);
                                 client.WriteByOrder("W_i_batch_id", mes_Detail.heatBatchID, name);
                                 client.WriteByOrder("R_oi_on", (byte)0, name);
+                                #region 鏃ュ織璁板綍
+                                WriteDBLog.Success(name, $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN锛歿wp_id}\n杞瀷ID锛歿wp_type}\n\n鍐欏叆妗佹灦淇℃伅锛歕nW_i_status锛�1" + $"\nW_i_job_id锛歿mes_Detail.jobID}" +
+                                    $"\nW_i_drawing_id锛歿mes_Head.drawingNo}\nW_i_heat_id锛歿mes_Detail.heatID}\nW_i_batch_id锛歿mes_Detail.heatBatchID}\nR_oi_on锛�0", "PCS");
+                                #endregion
                             }
                         }
 
@@ -207,15 +280,85 @@
         {
             try
             {
+                VOLContext Context = new VOLContext();
+                Idt_plcinfoheadRepository repository = new dt_plcinfoheadRepository(Context);
+                Idt_plcinfodetailRepository plcRepository = new dt_plcinfodetailRepository(Context);
+                Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
+                Idt_geometry_dataRepository dataRepository = new dt_geometry_dataRepository(Context);
+                Idt_geometry_data_detectionlineRepository detectionlineRepository = new dt_geometry_data_detectionlineRepository(Context);
+                Idt_mes_detailRepository mes_DetailRepository = new dt_mes_detailRepository(Context);
+                Idt_mes_headRepository mes_HeadRepository = new dt_mes_headRepository(Context);
+                Idt_patternRepository patternRepository = new dt_patternRepository(Context);
                 var plc = repository.FindFirst(x => x.plcinfo_name == client.PLCName);
                 var Pipeline_client = PLCClient.Clients.FirstOrDefault(t => t.PLCName == "閾炬潯鏈�");
                 if (Pipeline_client == null) throw new Exception("閾炬潯鏈鸿皟搴︽湇鍔℃湭寮�鍚紒");
                 if (!Pipeline_client.IsConnected) throw new Exception("涓庨摼鏉℃満杩炴帴瓒呮椂锛�");
                 var Pipelineplc = repository.FindFirst(x => x.plcinfo_name == Pipeline_client.PLCName);
                 List<string> names = new List<string>() { "1鍗曞厓涓嬫枡鍖�", "2鍗曞厓涓嬫枡鍖�", "3鍗曞厓涓嬫枡鍖�" };
+
                 foreach (string name in names)
                 {
                     var details = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep && x.plcdetail_number == name).ToList();
+
+                    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;
+                    }
+
+
+                    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);//璐т綅鐘舵�佹洿鏂�
+                    if (!finished && updatefinished)
+                    {
+                        client.WriteByOrder("W_Storage_update", false, name);//璐т綅鐘舵�佹洿鏂�
+                        #region 鏃ュ織璁板綍
+                        WriteDBLog.Success(name + "璐т綅鐘舵�佹洿鏂板浣�", $"璇诲彇妗佹灦淇℃伅锛歕n杞﹁疆SN锛歿Wheel_id}\n杞瀷ID锛歿Wheel_Type}\n\n鍐欏叆妗佹灦淇℃伅锛歕nW_Storage_update锛歠alse", "PCS");
+                        #endregion
+                    }
+                    if (finished && !updatefinished)
+                    {
+                        var AreaNr = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "W_AreaNr").First(), client);
+                        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());  //姝ゅ鏈夐棶棰� 涓嶇煡閬撴槸缁撳熬涓�1鐨勫摢涓笅鏂欏彛
+                        station.quantity++;    //todo 姝ゅ鏁伴噺涓嶄細澧炲姞  浣嗘槸鏇存柊瀹炰綋褰卞搷鎶ラ敊 鏄庢棩娴嬭瘯
+                        if (station.quantity > 5)
+                            throw new Exception($"涓嬫枡浣嶄俊鎭洿鏂板け璐ワ紒涓嬫枡浣嶈溅杞暟閲忓ぇ浜�5锛歿station.stationCode}");
+                        //station.bindSN = station.bindSN == string.Empty ? Wheel_id : station.bindSN + "," + Wheel_id;
+                        station.bindSN = string.IsNullOrEmpty(station.bindSN) ? Wheel_id : station.bindSN + "," + Wheel_id;
+                        if (station.quantity == 1)
+                        {
+                            station.stationType = mes_Head.drawingNo;
+                            station.Number = mes_Head.jobID;
+                            station.heatNumber = mes_Detail.heatID;
+                            station.tray_status = "StrogeTray";
+                        }
+                        var count = stationinfoRepository.Update(station, true);
+                        if (count < 1)
+                            throw new Exception($"涓嬫枡浣嶄俊鎭洿鏂板け璐ワ紒涓嬫枡浣嶇紪鍙凤細{station.stationCode}");
+                        client.WriteByOrder("W_Storage_update", true, name);//璐т綅鐘舵�佹洿鏂�
+                        client.WriteByOrder("W_Enabl_Load", false, name);//鏄惁鍏佽
+                        #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
+                    }
 
                     var Request = (bool)DBExtension.Read(details.Where(x => x.plcdetail_name == "R_Request_Load").First(), client);
                     if (!Request) continue;
@@ -225,18 +368,27 @@
                     var NGStation = "X01001003";
                     if (name == "2鍗曞厓涓嬫枡鍖�") NGStation = "X02001003";
                     if (name == "3鍗曞厓涓嬫枡鍖�") NGStation = "X03001002";
-                    foreach (var station in Stations)
+
+                    foreach (var station in Stations)     //浠讳綍涓�涓笅鏂欎綅涓虹┖鎴栫鐢ㄦ椂,閮戒細鍋滄妗佹灦
                     {
                         if (!station.enable || station.location_state == LocationStateEnum.Empty.ToString())
                             client.WriteByOrder("W_Enabl_Load", false, name);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
                     }
-                    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鍙�
-                    //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);
-                    var mes_Head = mes_HeadRepository.FindFirst(x => x.jobID == mes_Detail.jobID);
+                    //var currentAreaNr = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "W_Are00aNr").First(), client);
+                    //var currentAreaCode = PipelineJob.area_code(name);   //鏍规嵁涓嬫枡鍙e崟鍏冨悕鑾峰彇鍖哄煙浠g爜
+                    //var currentStation = stationinfoRepository.FindFirst(x => x.area == currentAreaCode && x.stationCode.Substring(x.stationCode.Length - 1, 1) == currentAreaNr.ToString());
+                    //if (!currentStation.enable || currentStation.location_state == LocationStateEnum.Empty.ToString())
+                    //    client.WriteByOrder("W_Enabl_Load", false, name);//淇″彿涓篺alse妗佹灦鍋滄杩涘叆
+
                     var wheel = PipelineJob.QueryMateriel(mes_Head.drawingNo);
+                    if (wheel == null)
+                    {
+                        #region 鏃ュ織璁板綍
+                        WriteDBLog.Error(name, $"鏈煡璇㈠埌杞﹁疆淇℃伅锛�", "PCS");
+                        #endregion
+                        continue;
+                    }
 
                     var PartStatus = DBExtension.Read(details.Where(x => x.plcdetail_name == "R_PartStatus").First(), client);//1:ok;2:nok
                     if ((Int16)PartStatus == 1)
@@ -256,31 +408,54 @@
                             Stationinfo = Stations.Where(x => x.enable && x.stationCode != NGStation && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity == 0).FirstOrDefault();
                         if (Stationinfo != null)
                         {
+                            #region 鎵樼洏绫诲瀷涓嶄竴鑷撮渶鏇存崲鎵樼洏
+                            if (Stationinfo.tray_type != (wheel.e < 1100 ? "SmallTray" : "LargeTray"))
+                            {
+                                Stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
+                                Stationinfo.tray_type = Stationinfo.tray_type == "SmallTray" ? "SmallTray/LargeTray" : "LargeTray/SmallTray";
+                                Stationinfo.remark = "鎵樼洏绫诲瀷涓嶄竴鑷撮渶鏇存崲鎵樼洏";
+                                stationinfoRepository.Update(Stationinfo, true);
+                                continue;
+                            }
+                            #endregion
+
                             var Pipelinedetails = plcRepository.Find(x => x.plcdetail_iotype == Pipelineplc.plcinfo_iotyep && x.plcdetail_number == Stationinfo.stationCode).ToList();
                             var PalletSignal = (Int16)DBExtension.Read(Pipelinedetails.Where(x => x.plcdetail_name == "R_PalletSignal").First(), Pipeline_client);//璇诲彇鎵樼洏淇″彿:1:鏈�,2鏃�
+                            //var MaterialSignal = (Int16)DBExtension.Read(details.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)
                             {
-                                var SNS = Stationinfo.bindSN.Split(",");
                                 List<string> list = new List<string>();
-                                foreach (var SN in SNS)
+                                if (Stationinfo.bindSN != null)
                                 {
-                                    if (!string.IsNullOrEmpty(SN))
-                                        list.Add(SN);
+                                    var SNS = Stationinfo.bindSN.Split(",");
+                                    foreach (var SN in SNS)
+                                    {
+                                        if (!string.IsNullOrEmpty(SN))
+                                            list.Add(SN);
+                                    }
                                 }
+
                                 //缂撳瓨鏋朵笂杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�
                                 if (list.Count != Stationinfo.quantity)
                                 {
                                     Stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
+                                    Stationinfo.remark = "杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�";
                                     stationinfoRepository.Update(Stationinfo, true);
+                                    continue;
                                     //鍐欏叆妗佹灦鎶ヨ淇″彿
-                                    throw new Exception("涓嬫枡浣嶈溅杞暟閲忎笌SN鍙锋暟閲忎笉涓�鑷达紝涓嬫枡浣嶇紪鍙凤細" + Stationinfo.stationCode);
+                                    //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);//鍖哄煙璐т綅鍙�
                                 client.WriteByOrder("W_IndexNr", (Int16)(Stationinfo.quantity + 1), name);//鎵樼洏涓婄殑绗嚑涓溅杞�
                                 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" +
+                                    $"\n璇诲彇鎵樼洏鍏夌數淇″彿锛歿PalletSignal}" +
+                                    $"\n\n鍐欏叆妗佹灦淇℃伅锛歕n涓嬫枡浣嶅彿锛歿area}\n绗嚑涓溅杞細{(Stationinfo.quantity + 1)}\n鎵樼洏绫诲瀷锛�1\nW_Enabl_Load锛歵rue", "PCS");
+                                #endregion
                                 return;
                             }
                         }
@@ -296,32 +471,54 @@
                         && x.tray_type == (wheel.e < 1100 ? "SmallTray" : "LargeTray")
                         && x.Number == mes_Detail.jobID
                         && x.heatNumber == mes_Detail.heatID).FirstOrDefault();
+                        if (Stationinfo == null)
+                            Stationinfo = Stations.Where(x => x.enable && x.stationCode == NGStation && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity == 0).FirstOrDefault();
                         if (Stationinfo != null)
                         {
+                            #region 鎵樼洏绫诲瀷涓嶄竴鑷撮渶鏇存崲鎵樼洏
+                            if (Stationinfo.tray_type != (wheel.e < 1100 ? "SmallTray" : "LargeTray"))
+                            {
+                                Stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
+                                Stationinfo.tray_type = Stationinfo.tray_type == "SmallTray" ? "SmallTray/LargeTray" : "LargeTray/SmallTray";
+                                Stationinfo.remark = "鎵樼洏绫诲瀷涓嶄竴鑷撮渶鏇存崲鎵樼洏";
+                                stationinfoRepository.Update(Stationinfo, true);
+                            }
+                            #endregion
                             var Pipelinedetails = plcRepository.Find(x => x.plcdetail_iotype == Pipelineplc.plcinfo_iotyep && x.plcdetail_number == Stationinfo.stationCode).ToList();
-                            var PalletSignal = (Int16)DBExtension.Read(Pipelinedetails.Where(x => x.plcdetail_name == "R_PalletSignal").First(), client);//璇诲彇鎵樼洏淇″彿:1:鏈�,2鏃�
+                            var PalletSignal = (Int16)DBExtension.Read(Pipelinedetails.Where(x => x.plcdetail_name == "R_PalletSignal").First(), Pipeline_client);//璇诲彇鎵樼洏淇″彿:1:鏈�,2鏃�
                             if (PalletSignal == 1)
                             {
                                 var SNS = Stationinfo.bindSN.Split(",");
                                 List<string> list = new List<string>();
-                                foreach (var SN in SNS)
+                                if (Stationinfo.bindSN != null)
                                 {
-                                    if (!string.IsNullOrEmpty(SN))
-                                        list.Add(SN);
+                                    foreach (var SN in SNS)
+                                    {
+                                        if (!string.IsNullOrEmpty(SN))
+                                            list.Add(SN);
+                                    }
                                 }
+
                                 //缂撳瓨鏋朵笂杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�
                                 if (list.Count != Stationinfo.quantity)
                                 {
                                     Stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
+                                    Stationinfo.remark = "杞﹁疆鏁伴噺涓嶴N鍙锋暟閲忎笉涓�鑷�";
                                     stationinfoRepository.Update(Stationinfo, true);
+                                    continue;
                                     //鍐欏叆妗佹灦鎶ヨ淇″彿
-                                    throw new Exception("涓嬫枡浣嶈溅杞暟閲忎笌SN鍙锋暟閲忎笉涓�鑷达紝涓嬫枡浣嶇紪鍙凤細" + Stationinfo.stationCode);
+                                    //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);//鍖哄煙璐т綅鍙�
                                 client.WriteByOrder("W_IndexNr", (Int16)(Stationinfo.quantity + 1), name);//鎵樼洏涓婄殑绗嚑涓溅杞�
                                 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" +
+                                    $"\n璇诲彇鎵樼洏鍏夌數淇″彿锛歿PalletSignal}" +
+                                    $"\n\n鍐欏叆妗佹灦淇℃伅锛歕n涓嬫枡浣嶅彿锛歿area}\n绗嚑涓溅杞細{(Stationinfo.quantity + 1)}\n鎵樼洏绫诲瀷锛�1\nW_Enabl_Load锛歵rue", "PCS");
+                                #endregion
                                 return;
                             }
                         }
@@ -348,28 +545,7 @@
                     //    StationCodes = new List<string>() { "X03001001", "X03001002" };
 
                     #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);//璐т綅鐘舵�佹洿鏂�
-                    if (!finished && updatefinished)
-                        client.WriteByOrder("W_Storage_update", false, name);//璐т綅鐘舵�佹洿鏂�
-                    if (finished && !updatefinished)
-                    {
-                        var AreaNr = (Int16)DBExtension.Read(details.Where(x => x.plcdetail_name == "W_AreaNr").First(), client);
-                        var station = stationinfoRepository.FindFirst(x => x.stationCode.Substring(x.stationCode.Length - 1, 1) == AreaNr.ToString());
-                        station.quantity = station.quantity++;
-                        station.bindSN = station.bindSN == string.Empty ? Wheel_id : station.bindSN + "," + Wheel_id;
-                        if (station.quantity == 0)
-                        {
-                            station.stationType = mes_Head.drawingNo;
-                            station.Number = mes_Head.jobID;
-                            station.heatNumber = mes_Detail.heatID;
-                        }
-                        var count = stationinfoRepository.Update(station);
-                        if (count < 1)
-                            throw new Exception($"涓嬫枡浣嶄俊鎭洿鏂板け璐ワ紒涓嬫枡浣嶇紪鍙凤細{station.stationCode}");
-                        client.WriteByOrder("W_Storage_update", true, name);//璐т綅鐘舵�佹洿鏂�
-                        client.WriteByOrder("W_Enabl_Load", false, name);//鏄惁鍏佽
-                    }
+
                     #region
                     //for (int i = 0; i < StationCodes.Count - 1; i++)
                     //{

--
Gitblit v1.9.3