杨前锦
2025-06-04 d44e3abf0d51cfea1ed7df510974d69458cf516d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
using MQTTnet.Server;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using static HH.WCS.Mobox3.HD.util.Settings;
 
namespace HH.WCS.Mobox3.HD.util
{
    public class Settings
    {
        public static string HostToAgvServerUrl { get; set; }
        public static string HASeverUrl { get; set; }
        public static string HLSeverUrl { get; set; }
        public static string SqlServer { get; set; }
        public static string SqlServer1 { get; set; }
        public static List<deviceInfo> deviceInfos { get; set; }
        public static List<DevicePlcInfo> devicePlcInfos { get; set; }
        public static List<StoreAreaInfo> storeAreaInfos { get; set; }
        public static List<SortAreaInfo> sortAreaInfos { get; set; }
        public static List<DispatchAreaInfo> dispatchAreaInfos { get; set; }
        public static List<WeightPlcInfo> weightPlcInfos { get; set; }
        public static int port { get; set; }
        public static string WHCode { get; set; }
        public static string FacCode { get; set; }
        public static string X5SqlServer { get; set; }
        public static MQTTServer mqttServer { get; set; }
 
        public static void Init() {
            LogHelper.Info("加载配置文件信息 开始");
            try {
                var jsonFile = System.AppDomain.CurrentDomain.BaseDirectory + "/config/config.json";
                using (System.IO.StreamReader file = System.IO.File.OpenText(jsonFile)) {
                    using (JsonTextReader reader = new JsonTextReader(file)) {
                        JObject o = (JObject)JToken.ReadFrom(reader);
                        foreach (Newtonsoft.Json.Linq.JProperty keyValue in o.Properties()) {
                            Console.WriteLine(keyValue.Name);
                            if (keyValue.Name == "HostToAgvServerUrl") {
                                HostToAgvServerUrl = keyValue.Value.ToString();
                            }
                            if (keyValue.Name == "HASeverUrl") {
                                HASeverUrl = keyValue.Value.ToString();
                            }
                            if (keyValue.Name == "HLSeverUrl")
                            {
                                HLSeverUrl = keyValue.Value.ToString();
                            }
                            if (keyValue.Name == "SqlServer") {
                                SqlServer = keyValue.Value.ToString();
                            }
                            if (keyValue.Name == "SqlServer1") {
                                SqlServer1 = keyValue.Value.ToString();
                            }
                            if (keyValue.Name == "WHCode") {
                                WHCode = keyValue.Value.ToString();
                            }
                            if (keyValue.Name == "FacCode") {
                                FacCode = keyValue.Value.ToString();
                            }
                            if (keyValue.Name == "ApiPort") {
                                port = int.Parse(keyValue.Value.ToString());
                            }
                            if (keyValue.Name == "DeviceInfo") {
                                deviceInfos = JsonConvert.DeserializeObject<List<deviceInfo>>(keyValue.Value.ToString());
                            }
                            if (keyValue.Name == "DevicePlcInfo")
                            {
                                devicePlcInfos = JsonConvert.DeserializeObject<List<DevicePlcInfo>>(keyValue.Value.ToString());
                            }
                            if (keyValue.Name == "StoreAreaInfo")
                            {
                                storeAreaInfos = JsonConvert.DeserializeObject<List<StoreAreaInfo>>(keyValue.Value.ToString());
                            }
                            if (keyValue.Name == "SortAreaInfo")
                            {
                                sortAreaInfos = JsonConvert.DeserializeObject<List<SortAreaInfo>>(keyValue.Value.ToString());
                            }
                            if (keyValue.Name == "DispatchAreaInfo")
                            {
                                dispatchAreaInfos = JsonConvert.DeserializeObject<List<DispatchAreaInfo>>(keyValue.Value.ToString());
                            }
                            if (keyValue.Name == "WeightPlcInfo")
                            {
                                weightPlcInfos = JsonConvert.DeserializeObject<List<WeightPlcInfo>>(keyValue.Value.ToString());
                            }
                            if (keyValue.Name == "X5SqlServer")
                            {
                                X5SqlServer = keyValue.Value.ToString();
                            }
                            if (keyValue.Name == "MQTTServer")
                            {
                                mqttServer = JsonConvert.DeserializeObject<MQTTServer>(keyValue.Value.ToString());
                            }
                        }
                    }
                }
                LogHelper.Info("加载配置文件信息 完成");
            }
            catch (Exception ex) {
                LogHelper.Error("加载配置文件失败!" + ex.Message, ex);
            }
 
        }
        /// <summary>
        /// 查询存储库区编码
        /// 库区类型 :1.开发式立库 2.封闭式立体库
        /// 货品类型 :1.半成品/成品 2.钢卷 3.模具
        /// </summary>
        /// <param name="areaType"></param>
        /// <param name="cargoType"></param>
        /// <returns></returns>
        public static List<string> getStoreAreaCodes(int areaType,int cargoType) {
            return storeAreaInfos.Where(a => (a.areaType == areaType || 0 == areaType) && a.cargoType == cargoType).Select(a => a.areaCode).ToList();
        }
 
        /// <summary>
        /// 根据接驳库区查询存储库区
        /// </summary>
        /// <param name="accessArea"></param>
        /// <returns></returns>
        public static string getStoreAreaByAccessArea(string accessArea)
        {
            return storeAreaInfos.Where(a => a.accessArea == accessArea).Select(a => a.areaCode).FirstOrDefault();
        }
 
        /// <summary>
        /// 查询发货库区编码
        /// </summary>
        /// <returns></returns>
        public static List<string> getDispatchAreaCodes()
        {
            return dispatchAreaInfos.Select(a => a.areaCode).ToList();
        }
 
        public class MQTTServer {
            public string name { get; set; }
            public string url { get; set; }
            public string port { get; set; }
            public string clientId { get; set; }
        }
 
        public class WeightPlcInfo {
            public string deviceNo { get; set; }
            public string name { get; set; }
            public string ip { get; set; } // ip地址
            public string location { get; set; } // 称重货位
            public string command { get; set; } // 命令
        }
 
        public class DispatchAreaInfo 
        {
            public string areaCode { get; set; }
            public string areaName { get; set; }
            public string relateArea { get; set; }
        }
 
        public class SortAreaInfo 
        {
            public string areaCode { get; set; }
            public string areaName { get; set; }
            public string inLocCode { get; set; }
            public string outLocCode { get; set; }
            public string relateArea { get; set; }
        }
 
        public class StoreAreaInfo
        {
            public string areaCode { get; set; }
            public string areaName { get; set; }
            public int areaType { get; set; } // 库区类型 :1.开发式立库 2.封闭式立体库
            public int cargoType { get; set; } // 货品类型 :1.半成品/成品 2.钢卷 3.模具
            public int frequency { get; set; } // 入库频率
            public string accessArea { get; set; } // 接驳库区
        }
 
        public class DevicePlcInfo {
            public string deviceName { get; set; }
            public string deviceNo { get; set; }
            public int deviceType { get; set; } // 设备类型(1.堆垛机 2.输送线 3.拆盘机)
            public string address { get; set; }
            public short enable { get; set; }
            public string area { get; set; }
            public int roadway { get; set; }
        }
 
        public class deviceInfo
        {
            public string address { get; set; }
            public string deviceName { get; set; }
            public string[] deviceNo { get; set; }
            public string[] TN_Location { get; set; }
 
            public int deviceType { get; set; }
            public int enable { get; set; }
        }
 
        public class TableName
        {
            public string name { get; set; }
            public string code { get; set; }
        }
 
    }
}