杨前锦
2025-07-01 a93b0e99036c24b9bd58c79bf5e7364b1ba28bae
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HH.WCS.Mobox3.YNJT_PT.util;
using HH.WCS.Mobox3.YNJT_PT.wms;
using Newtonsoft.Json;
using static HH.WCS.Mobox3.YNJT_PT.api.ApiModel;
 
namespace HH.WCS.Mobox3.YNJT_PT.dispatch
{
    public class WCSDispatch
    {
        private static readonly HttpHelper apiHelper = new HttpHelper();
        private static readonly string baseUrl = "http://192.168.1.99:2000/";
 
 
        internal static string GenerateReqId()
        {
            var id = SYSHelper.GetSerialNumber("请求ID", "RE");
            var date = DateTime.Now.ToString("yyMMdd");
            return $"{date}{id.ToString().PadLeft(4, '0')}";
        }
 
        /// <summary>
        /// 任务下发
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool sendTask(SendTaskModel model)
        {
            var result = false;
            model.reqId = GenerateReqId();
            model.reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            var request = JsonConvert.SerializeObject(model);
            try
            {
                var response = apiHelper.Post(baseUrl + "/sendTask", request);
                LogHelper.Info($"[WCS-sendTask] request={request} response={response}", "WMS");
                if (response != null && response != "")
                {
                    var dataResult = JsonConvert.DeserializeObject<ResponseResult>(response);
                    if (dataResult.code == 200)
                    {
                        result = true;
                    }
                    else
                    {
                        LogHelper.Info($"调用WCS任务下发接口成功,但WCS反馈下发任务失败,失败原因:{dataResult.msg}", "WMS");
                    }
                }
                else
                {
                    LogHelper.Info("调用WCS任务下发接口失败", "WMS");
                }
            }
            catch (Exception ex)
            {
                LogHelper.Info($"调用WCS任务下发接口错误,错误原因:{ex.Message}", "WMS");
            }
            return result;
        }
 
        /// <summary>
        /// 任务取消(任务执行中不允许取消)
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool cancelTask(CancelTaskModel model)
        {
            var result = false;
            model.reqId = GenerateReqId();
            model.reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            var request = JsonConvert.SerializeObject(model);
            try
            {
                var response = apiHelper.Post(baseUrl + "/api/hecWms/produceProcessTracing/trayMaterialUnBind", request);
                LogHelper.Info($"[WCS-cancelTask] request={request} response={response}", "WMS");
                if (response != null && response != "")
                {
 
                    var dataResult = JsonConvert.DeserializeObject<ResponseResult>(response);
                    if (dataResult.code == 200)
                    {
                        result = true;
                    }
 
                }
                else
                {
                    LogHelper.Info("调用WCS任务取消接口失败", "WMS");
                }
            }
            catch (Exception ex)
            {
                LogHelper.Info($"调用WCS任务取消接口错误,错误原因:{ex.Message}", "WMS");
            }
            return result;
        }
 
        /// <summary>
        /// 获取设备状态
        /// </summary>
        /// <param name="deviceNoList"></param>
        /// <returns></returns>
        public static List<DeviceStatusData> getDeviceStatus(List<string> deviceNoList)
        {
            List<DeviceStatusData> deviceStatusDatas = new List<DeviceStatusData>();
 
            DeviceStatusModel model = new DeviceStatusModel()
            {
                reqId = GenerateReqId(),
                reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                deviceNoList = deviceNoList
            };
 
            var request = JsonConvert.SerializeObject(model);
            try
            {
                var response = apiHelper.Post(baseUrl + "/api/hecWms/produceProcessTracing/trayMaterialUnBind", request);
                LogHelper.Info($"[WCS-getDeviceStatus] request={request} response={response}", "WMS");
                if (response != null && response != "")
                {
 
                    var dataResult = JsonConvert.DeserializeObject<ResponseResult>(response);
                    if (dataResult.code == 200)
                    {
                        deviceStatusDatas = JsonConvert.DeserializeObject<List<DeviceStatusData>>(response);
                    }
 
                }
                else
                {
                    LogHelper.Info("调用WCS获取设备状态接口失败", "WMS");
                }
            }
            catch (Exception ex)
            {
                LogHelper.Info($"调用WCS获取设备状态接口错误,错误原因:{ex.Message}", "WMS");
            }
            return deviceStatusDatas;
        }
 
        /// <summary>
        /// 修改任务优先级
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool changePriority(ChangePriorityModel model)
        {
            var result = false;
            model.reqId = GenerateReqId();
            model.reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            var request = JsonConvert.SerializeObject(model);
            try
            {
                var response = apiHelper.Post(baseUrl + "/api/hecWms/produceProcessTracing/trayMaterialUnBind", request);
                LogHelper.Info($"[WCS-changePriority] request={request} response={response}", "WMS");
                if (response != null && response != "")
                {
 
                    var dataResult = JsonConvert.DeserializeObject<ResponseResult>(response);
                    if (dataResult.code == 200)
                    {
                        result = true;
                    }
 
                }
                else
                {
                    LogHelper.Info("调用WCS修改任务优先级接口失败", "WMS");
                }
            }
            catch (Exception ex)
            {
                LogHelper.Info($"调用WCS修改任务优先级接口错误,错误原因:{ex.Message}", "WMS");
            }
            return result;
        }
 
        /// <summary>
        /// AGV安全交互
        /// </summary>
        /// <param name="req_no"></param>
        /// <param name="locCode"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static bool safetyInteraction(string req_no, string locCode, string type)
        {
            var result = false;
            LocStateModel model = new LocStateModel()
            {
                req_no = req_no,
                loc_code = locCode,
                type = type
            };
 
            var request = JsonConvert.SerializeObject(model);
            try
            {
                var response = apiHelper.Post(baseUrl + "/api/hecWms/produceProcessTracing/trayMaterialUnBind", request);
                LogHelper.Info($"[WCS-changePriority] request={request} response={response}", "WMS");
                if (response != null && response != "")
                {
 
                    var dataResult = JsonConvert.DeserializeObject<ResponseResult>(response);
                    if (dataResult.code == 200)
                    {
                        result = true;
                    }
                }
                else
                {
                    LogHelper.Info("调用WCS安全请求接口失败", "AGV");
                }
            }
            catch (Exception ex)
            {
                LogHelper.Info($"调用WCS安全请求接口错误,错误原因:{ex.Message}", "AGV");
            }
            return result;
        }
       
 
        public class LocStateModel
        {
            public string req_no { get; set; } // 请求id
            public string loc_code { get; set; } // 货位
            public string type { get; set; } // 货位 1 请求取货 2 请求放货 3 取货完成离开信号 4 放货完成离开信号
        }
 
        public class ChangePriorityModel
        {
            public string reqId { get; set; } // 请求id
            public string reqTime { get; set; } // 请求时间
            public string taskNo { get; set; } // 任务号
            public int priority { get; set; } // 优先级
        }
 
        public class DeviceStatusData
        {
            public string deviceNo { get; set; } // 设备号
            public int workStatus { get; set; } // 工作状态  1正常 ,2禁用 ,3故障 
            public int photoStatus { get; set; } // 光电状态 1是空载 ,2是有载
            public int manualStatus { get; set; } //手动状态  1手动,2自动
        }
 
        public class DeviceStatusModel
        {
            public string reqId { get; set; } // 请求id
            public string reqTime { get; set; } // 请求时间
            public List<string> deviceNoList { get; set; } // 设备号
        }
 
        public class CancelTaskModel
        {
            public string reqId { get; set; } // 请求id
            public string reqTime { get; set; } // 请求时间
            public string taskNo { get; set; } // 任务号
        }
 
        public class SendTaskModel
        {
            public string reqId { get; set; } // 请求id
            public string reqTime { get; set; } // 请求时间
            public string taskNo { get; set; } // 任务号
            public int groupNo { get; set; } // 任务组 
            public string taskType { get; set; } // 任务类型  1.物料入库 2.物料出库
            public string from { get; set; } // 起点
            public string to { get; set; } // 终点
            public string cntrNo { get; set; } // 容器编码
            public string cntrType { get; set; } // 容器类型
            public List<object> extData { get; set; } // 
 
        }
    }
}