From 2ca90a404fa1ab94eb6374f50c6ddd47a2b7f0e6 Mon Sep 17 00:00:00 2001
From: kazelee <1847801760@qq.com>
Date: 星期四, 31 七月 2025 17:23:57 +0800
Subject: [PATCH] 删除有问题的TCP旧代码, 优化事务处理和ERP数据模型

---
 util/Settings.cs |  172 +++++++++++++++++++++++++-------------------------------
 1 files changed, 77 insertions(+), 95 deletions(-)

diff --git a/util/Settings.cs b/util/Settings.cs
index d510507..a27282b 100644
--- a/util/Settings.cs
+++ b/util/Settings.cs
@@ -7,35 +7,34 @@
 using Newtonsoft.Json;
 using Newtonsoft.Json.Linq;
 
-namespace HH.WCS.Mobox3.DSZSH {
-    public class Settings
-    {
+namespace HH.WCS.Mobox3.DSZSH.util {
+    public class Settings {
         public static string WebApiUrl { get; set; }
         public static string NdcApiUrl { get; set; }
-        public static string ErpApiUrl { get; set; } // ERP 鍙嶉鎺ュ彛
-        public static string SqlServer { get; set; }
-        public static string TcpServerIp { get; set; }
-        public static int TcpServerPort { get; set; }
-        public static List<Config.Area> Areas { get; set; } = new List<Config.Area>();
-        public static List<Config.ProductionLine> ProductionLines { get; set; } = new List<Config.ProductionLine>();
-        public static List<Config.ProdAgvSite> ProdAgvSites { get; set; } = new List<Config.ProdAgvSite>();
-        /// <summary>
-        /// 搴撳尯瀛楀吀锛堝姞杞藉悗灏变笉鍙橈級
-        /// </summary>
-        public static Dictionary<string, List<string>> AreaMap { get; set; } = new Dictionary<string, List<string>>();
+        public static string ErpApiUrl { get; set; } // ERP 鍙嶉鎺ュ彛URL
 
-        public static Dictionary<string, int> AgvSite_ProdLineCodeMap { get; set; } = new Dictionary<string, int>();
+        public static int TcpServerPort { get; set; }
+        public static Config.ErpRoute ErpRoute { get; set; }
+
+        public static SqlSugar.DbType DbType { get; set; } = SqlSugar.DbType.SqlServer;
+        public static string DbConn { get; set; }
+        //public static string TcpServerIp { get; set; }
+        //public static int TcpServerPort { get; set; }
+        public static List<Config.ProductionLine> ProductionLines { get; set; } = new List<Config.ProductionLine>();
+
+        public static List<Config.TaskInfo> TaskInfos { get; set; } = new List<Config.TaskInfo> { };
+
+        public static Dictionary<string, int> LocProdIdMap { get; set; } = new Dictionary<string, int> { };
 
         public static void Init() {
             // 鍔犺浇閰嶇疆鏂囦欢
             LoadJson();
 
-            // 閽堝 Areas 杩涜杞崲锛氬皢 Config 鐨�List 鍔犺浇鍒�Dict 涓�-            LoadAreas();
+            LoadProdLines();
         }
 
         private static void LoadJson() {
-            LogHelper.Info("鍔犺浇閰嶇疆鏂囦欢淇℃伅 寮�");
+            LogHelper.Info("鍔犺浇閰嶇疆鏂囦欢淇℃伅:寮�!!");
             // JSON 鏂囦欢璺緞
             string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "./config/config.json");
 
@@ -46,62 +45,51 @@
                 // 鍙嶅簭鍒楀寲涓�Config 瀵硅薄
                 var root = JsonConvert.DeserializeObject<Config.Root>(jsonContent);
 
+                #region Config.Root 璧嬪�瀛楁閮ㄥ垎
                 WebApiUrl = root.WebApiUrl;
                 NdcApiUrl = root.NdcApiUrl;
                 ErpApiUrl = root.ErpApiUrl;
-                SqlServer = root.SqlServer;
-                TcpServerIp = root.TcpServerIp;
+                ErpRoute = root.ErpRoute;
                 TcpServerPort = root.TcpServerPort;
-                Areas = root.Areas;
+                DbConn = root.SqlServer;
+                //TcpServerIp = root.TcpServerIp;
+                //TcpServerPort = root.TcpServerPort;
                 ProductionLines = root.ProductionLines;
-
-                ProdAgvSites = root.ProdAgvSite;
-                foreach (var item in ProdAgvSites) {
-                    AgvSite_ProdLineCodeMap.Add(item.Code, item.ProdId);
-                }
-
+                TaskInfos = root.TaskInfos;
+                #endregion
             }   
             catch (FileNotFoundException) {
-                LogHelper.Info("JSON 鏂囦欢鏈壘鍒�);
+                LogHelper.Info("JSON鏂囦欢鏈壘鍒�!", "Exception");
             }
             catch (JsonException ex) {
-                LogHelper.Info($"JSON 瑙f瀽閿欒: {ex.Message}");
+                LogHelper.Info($"JSON瑙f瀽閿欒!!Error:{ex.Message}\n\n{ex.StackTrace}\n", "Exception");
             }
             catch (Exception ex) {
-                LogHelper.Info($"鍙戠敓閿欒: {ex.Message}");
+                LogHelper.InfoEx(ex, "Settings:");
             }
-            LogHelper.Info("鍔犺浇閰嶇疆鏂囦欢淇℃伅 瀹屾垚");
-        }
-
-        private static void LoadAreas() {
-            foreach (var area in Areas) {
-                AreaMap.Add(area.Name, area.Codes);
-            }
+            LogHelper.Info("鍔犺浇閰嶇疆鏂囦欢淇℃伅:瀹屾垚!!");
         }
 
         private static void LoadProdLines() {
-            //var db = new SqlHelper<object>().GetInstance();
-            //for (int  i = 0;  i < ProductionLines.Count;  i++) {
-            //    var line = ProductionLines[i];
-            //    // 閫氳繃OnLoc OffLoc鎵惧埌AGVsite鐒跺悗鍐欏叆瀛楀吀
-            //}
+            for (var i = 0; i < ProductionLines.Count; i++) {
+                if (ProductionLines[i].OnLoc == null) continue;
+                foreach (var onLoc in ProductionLines[i].OnLoc) {
+                    LocProdIdMap.Add(onLoc, int.Parse(ProductionLines[i].Id));
+                }
+                foreach (var offLoc in ProductionLines[i].OffLoc) {
+                    LocProdIdMap.Add(offLoc, int.Parse(ProductionLines[i].Id));
+                }
+            }
         }
-
     }
 
     // [Convert JSON to C# Classes Online - Json2CSharp Toolkit](https://json2csharp.com/)
 
     public class Config {
-
         // Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
-        public class Area {
-            public string Name { get; set; }
-            public List<string> Codes { get; set; }
-        }
-
-        public class ProdAgvSite {
-            public string Code { get; set; }
-            public int ProdId { get; set; }
+        public class ErpRoute {
+            public string CreateTaskReturn { get; set; }
+            public string PickUpReturn { get; set; }
         }
 
         public class ProductionLine {
@@ -118,58 +106,52 @@
             public string WebApiUrl { get; set; }
             public string NdcApiUrl { get; set; }
             public string ErpApiUrl { get; set; }
-            public string SqlServer { get; set; }
-            public string TcpServerIp { get; set; }
             public int TcpServerPort { get; set; }
-            public List<Area> Areas { get; set; }
-
+            public ErpRoute ErpRoute { get; set; }
+            public string SqlServer { get; set; }
+            public List<TaskInfo> TaskInfos { get; set; }
             public List<ProductionLine> ProductionLines { get; set; }
-            public List<ProdAgvSite> ProdAgvSite { get; set; }
+        }
+
+        public class TaskInfo {
+            public string TaskName { get; set; }
+            public List<string> StartAreas { get; set; }
+            public List<string> EndAreas { get; set; }
+            public List<string> EndAreas_Pallet { get; set; }
+            public List<string> EndAreas_Goodpack { get; set; }
         }
     }
 
-
-    public class AreaName {
-        public const string B鍖呰鍖�= "鍖呰鍖�;
-        public const string K绌虹鎿嶄綔鍖�= "绌虹鎿嶄綔鍖�;
-        public const string M婊$鎿嶄綔鍖�= "婊$鎿嶄綔鍖�;
-
-        public const string K绌烘墭瀛樻斁鍖�= "绌烘墭瀛樻斁鍖�;
-        public const string K绌虹璐ф灦鍖�= "绌虹璐ф灦鍖�;
-        public const string M婊℃墭璐ф灦鍖�= "婊℃墭璐ф灦鍖�;
-        public const string M婊$璐ф灦鍖�= "婊$璐ф灦鍖�;
-
-        public const string C鎶芥鍖�= "鎶芥鍖�;
-        public const string C鎶芥寮傚父鍖�= "鎶芥寮傚父鍖�;
-
-        public const string K绌烘墭鍏ュ簱鎺ラ┏鍖�= "绌烘墭鍏ュ簱鎺ラ┏鍖�;
-        public const string K绌虹鍏ュ簱鎺ラ┏鍖�= "绌虹鍏ュ簱鎺ラ┏鍖�;
-
-        public const string Q姹借溅鍑哄簱鍖�= "姹借溅鍑哄簱鍖�;
-        public const string H鐏溅鍑哄簱鍖�= "鐏溅鍑哄簱鍖�;
-        public const string Q姹借溅澶囪揣鍖�= "姹借溅澶囪揣鍖�;
-        public const string H鐏溅澶囪揣鍖�= "鐏溅澶囪揣鍖�;
+    public enum ETask {
+        M婊℃墭涓嬬嚎鍏ュ簱,
+        M婊$涓嬬嚎鍏ュ簱,
+        C鎴愬搧鑳跺嚭搴�
+        K绌烘墭涓婄嚎鍑哄簱,
+        K绌虹涓婄嚎鍑哄簱,
+        K绌烘墭鍏ュ簱,
+        K绌虹鍏ュ簱,
+        C鎶芥鍑哄簱,
+        C鎶芥鍚堟牸鍥炲簱,
+        C鎶芥涓嶅悎鏍肩Щ搴�
+        W灏炬枡鍥炲簱,
+        Y绉诲簱,
     }
 
-    public class TaskName {
-        public const string H濂借繍绠盻婊$涓嬬嚎鍏ュ簱 = "濂借繍绠�婊$涓嬬嚎鍏ュ簱";
-        public const string H濂借繍绠盻绌虹涓婄嚎 = "濂借繍绠�绌虹涓婄嚎";
-        public const string H濂借繍绠盻绌虹鍏ュ簱 = "濂借繍绠�绌虹鍏ュ簱";
-        public const string H濂借繍绠盻绌虹缁戝畾 = "濂借繍绠�绌虹缁戝畾";
+    public static class ETaskExtensions {
+        public static string Name(this ETask eTask) {
+            return Settings.TaskInfos[(int)eTask].TaskName;
+        }
 
-        public const string C鎴愬搧鑳跺嚭搴�= "鎴愬搧鑳跺嚭搴�;
+        public static Config.TaskInfo Info(this ETask eTask) {
+            return Settings.TaskInfos[(int)eTask];
+        }
 
-        public const string T鎵樼洏_婊℃墭涓嬬嚎鍏ュ簱 = "鎵樼洏-婊℃墭涓嬬嚎鍏ュ簱";
-        public const string T鎵樼洏_绌烘墭涓婄嚎 = "鎵樼洏-绌烘墭涓婄嚎";
-        public const string T鎵樼洏_绌烘墭鍏ュ簱 = "鎵樼洏-绌烘墭鍏ュ簱";
-        public const string T鎵樼洏_绌烘墭缁戝畾 = "鎵樼洏-绌烘墭缁戝畾";
+        public static List<string> StartAreas(this ETask eTask) {
+            return Settings.TaskInfos[(int)(eTask)].StartAreas;
+        }
 
-        public const string C鎶芥_涓嶅悎鏍肩Щ搴�= "鎶芥-涓嶅悎鏍肩Щ搴�;
-        public const string C鎶芥_鍑哄簱 = "鎶芥-鍑哄簱";
-        public const string C鎶芥_鍚堟牸鍥炲簱 = "鎶芥-鍚堟牸鍥炲簱";
-
-        public const string Y绉诲簱 = "绉诲簱";
-        public const string W灏剧鍥炲簱 = "灏剧鍥炲簱";
+        public static List<string> EndAreas(this ETask eTask) {
+            return Settings.TaskInfos[((int)eTask)].EndAreas;
+        }
     }
-
 }

--
Gitblit v1.9.1