From 3450443ee68b49e539f066bd7cea23fb7fcd81c3 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期五, 07 六月 2024 17:13:11 +0800
Subject: [PATCH] 桁架模式1/2切换

---
 代码管理/PCS/WCS_Server/WIDESEA_WCS/Services/WCS/Partial/dt_patternService.cs |   78 +++++++++++++++++++++++++++++++-------
 1 files changed, 63 insertions(+), 15 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Services/WCS/Partial/dt_patternService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Services/WCS/Partial/dt_patternService.cs"
index c9977db..7cf9eb8 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Services/WCS/Partial/dt_patternService.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Services/WCS/Partial/dt_patternService.cs"
@@ -19,6 +19,10 @@
 using WIDESEA_WCS.IRepositories;
 using Microsoft.AspNetCore.Mvc.RazorPages;
 using Newtonsoft.Json;
+using WIDESEA_Core.EFDbContext;
+using WIDESEA_WCS.Repositories;
+using WIDESEA_Comm;
+using WIDESEA_WCS.WCSClient;
 
 namespace WIDESEA_WCS.Services
 {
@@ -39,29 +43,73 @@
             //澶氱鎴蜂細鐢ㄥ埌杩檌nit浠g爜锛屽叾浠栨儏鍐靛彲浠ヤ笉鐢�
             //base.Init(dbRepository);
         }
+        /// <summary>
+        /// 妯″紡1
+        /// </summary>
+        /// <param name="v"></param>
+        /// <returns></returns>
         public WebResponseContent UpdateAuto(string v)
         {
             WebResponseContent content = new WebResponseContent();
-            var model = JsonConvert.DeserializeObject<dt_pattern>(v);
-            model.pattern_state = 1;
-            var cont = _repository.Update(model, true);
-            if (cont > 0)
-                content.OK(model.pattern_name + "璁剧疆涓鸿嚜鍔ㄥ叆搴撴垚鍔燂紒");
-            else
-                content.Error(model.pattern_name + "璁剧疆涓鸿嚜鍔ㄥ叆搴撳け璐ワ紒");
+            try
+            {
+                var Gantry_client = PLCClient.Clients.FirstOrDefault(t => t.PLCName == "妗佹灦");
+                if (Gantry_client == null) throw new Exception("妗佹灦璋冨害鏈嶅姟鏈紑鍚紒");
+                if (!Gantry_client.IsConnected) throw new Exception("涓庢鏋惰繛鎺ヨ秴鏃讹紒");
+                VOLContext context = new VOLContext();
+                Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
+                var stations = stationinfoRepository.Find(x => x.stationCode == "X01001001" || x.stationCode == "X01001002" || x.stationCode == "X02001001" || x.stationCode == "X02001002").ToList();
+                if (stations.Where(x => x.tray_status == TrayStateEnum.StrogeTray.ToString()).Any())
+                    throw new Exception("璁剧疆涓烘ā寮�1澶辫触锛佷笅鏂欎綅瀛樺湪杞﹁疆锛�");
+                #region 鍐欏叆淇″彿鍛婅瘔妗佹灦鍒囨崲妯″紡
+
+                #endregion
+
+                var model = JsonConvert.DeserializeObject<dt_pattern>(v);
+                model.pattern_state = 1;
+                var cont = _repository.Update(model, true);
+                if (cont > 0)
+                    content.OK(model.pattern_name + "璁剧疆涓烘ā寮�1鎴愬姛锛�");
+                else
+                    content.Error(model.pattern_name + "璁剧疆涓烘ā寮�1澶辫触锛�");
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
             return content;
         }
+        /// <summary>
+        /// 妯″紡2
+        /// </summary>
+        /// <param name="v"></param>
+        /// <returns></returns>
         public WebResponseContent UpdateManual(string v)
         {
             WebResponseContent content = new WebResponseContent();
-            var model = JsonConvert.DeserializeObject<dt_pattern>(v);
-            model.pattern_state = 0;
-            var cont = _repository.Update(model, true);
-            if (cont > 0)
-                content.OK(model.pattern_name + "璁剧疆涓烘墜鍔ㄥ叆搴撴垚鍔燂紒");
-            else
-                content.Error(model.pattern_name + "璁剧疆涓烘墜鍔ㄥ叆搴撳け璐ワ紒");
+            try
+            {
+                var Gantry_client = PLCClient.Clients.FirstOrDefault(t => t.PLCName == "妗佹灦");
+                if (Gantry_client == null) throw new Exception("妗佹灦璋冨害鏈嶅姟鏈紑鍚紒");
+                if (!Gantry_client.IsConnected) throw new Exception("涓庢鏋惰繛鎺ヨ秴鏃讹紒");
+                VOLContext context = new VOLContext();
+                Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
+                var stations = stationinfoRepository.Find(x => x.stationCode == "X01001001" || x.stationCode == "X01001002" || x.stationCode == "X02001001" || x.stationCode == "X02001002").ToList();
+                if (stations.Where(x => x.tray_status == TrayStateEnum.StrogeTray.ToString()).Any())
+                    throw new Exception("璁剧疆涓烘ā寮�2澶辫触锛佷笅鏂欎綅瀛樺湪杞﹁疆锛�");
+                var model = JsonConvert.DeserializeObject<dt_pattern>(v);
+                model.pattern_state = 0;
+                var cont = _repository.Update(model, true);
+                if (cont > 0)
+                    content.OK(model.pattern_name + "璁剧疆涓烘ā寮�2鎴愬姛锛�");
+                else
+                    content.Error(model.pattern_name + "璁剧疆涓烘ā寮�2澶辫触锛�");
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
             return content;
         }
-  }
+    }
 }

--
Gitblit v1.9.3