杨前锦
2025-05-26 0e9cab9c1424692caa2003ecf6b951d57ffdb765
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HH.WCS.Mobox3.FJJT.util;
using HH.WCS.Mobox3.FJJT.wms;
using Newtonsoft.Json;
using static HH.WCS.Mobox3.FJJT.api.ApiModel;
using static HH.WCS.Mobox3.FJJT.util.ExcetionHelper;
 
namespace HH.WCS.Mobox3.FJJT.dispatch
{
    internal class WCSDispatch
    {
        private static readonly HttpHelper apiHelper = new HttpHelper();
        private static readonly string baseUrl = "http://10.30.10.8:8100/dev-api";
 
        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 + "/api/hecWms/produceProcessTracing/trayMaterialUnBind", 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
                    {
                        WMSHelper.addAlarmRecord("流程异常", "高", $"下发WCS任务失败,WCS反馈原因:{dataResult.msg}");
                        throw new BusinessException($"下发WCS任务失败,WCS反馈原因:{dataResult.msg}");
                    }
                }
                else
                {
                    WMSHelper.addAlarmRecord("流程异常", "高", $"下发WCS任务失败,WCS没有返回数据");
                    throw new BusinessException($"下发WCS任务失败,WCS没有返回数据");
                }
            }
            catch (BusinessException be) 
            {
                throw be;
            }
            catch (Exception ex)
            {
                WMSHelper.addAlarmRecord("系统异常", "高", $"下发WCS任务错误,错误原因:{ex.Message}");
                throw new BusinessException($"下发WCS任务错误,错误原因:{ex.Message}");
            }
            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
                    {
                        WMSHelper.addAlarmRecord("流程异常", "高", $"取消WCS任务失败,WCS反馈原因:{dataResult.msg}");
                        throw new BusinessException($"取消WCS任务失败,WCS反馈原因:{dataResult.msg}");
                    }
                }
                else
                {
                    WMSHelper.addAlarmRecord("流程异常", "高", $"取消WCS任务失败,WCS没有返回数据");
                    throw new BusinessException($"取消WCS任务失败,WCS没有返回数据");
                }
            }
            catch (BusinessException be)
            {
                throw be;
            }
            catch (Exception ex)
            {
                WMSHelper.addAlarmRecord("系统异常", "高", $"取消WCS任务错误,错误原因:{ex.Message}");
                throw new BusinessException($"取消WCS任务错误,错误原因:{ex.Message}");
            }
            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
                    {
                        WMSHelper.addAlarmRecord("流程异常", "高", $"获取设备状态失败,WCS反馈原因:{dataResult.msg}");
                        throw new BusinessException($"获取设备状态失败,WCS反馈原因:{dataResult.msg}");
                    }
                }
                else
                {
                    WMSHelper.addAlarmRecord("流程异常", "高", $"获取设备状态失败,WCS没有返回数据");
                    throw new BusinessException($"获取设备状态失败,WCS没有返回数据");
                }
            }
            catch (BusinessException be)
            {
                throw be;
            }
            catch (Exception ex)
            {
                WMSHelper.addAlarmRecord("系统异常", "高", $"获取设备状态错误,错误原因:{ex.Message}");
                throw new BusinessException($"获取设备状态错误,错误原因:{ex.Message}");
            }
            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
                    {
                        WMSHelper.addAlarmRecord("流程异常", "高", $"修改任务优先级失败,WCS反馈原因:{dataResult.msg}");
                        throw new BusinessException($"修改任务优先级失败,WCS反馈原因:{dataResult.msg}");
                    }
                }
                else
                {
                    WMSHelper.addAlarmRecord("流程异常", "高", $"修改任务优先级失败,WCS没有返回数据");
                    throw new BusinessException($"修改任务优先级失败,WCS没有返回数据");
                }
            }
            catch (BusinessException be)
            {
                throw be;
            }
            catch (Exception ex)
            {
                WMSHelper.addAlarmRecord("系统异常", "高", $"修改任务优先级错误,错误原因:{ex.Message}");
                throw new BusinessException($"修改任务优先级错误,错误原因:{ex.Message}");
            }
            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
                    {
                        WMSHelper.addAlarmRecord("流程异常", "高", $"AGV安全交互请求失败,WCS反馈原因:{dataResult.msg}");
                        throw new BusinessException($"AGV安全交互请求失败,WCS反馈原因:{dataResult.msg}");
                    }
                }
                else
                {
                    WMSHelper.addAlarmRecord("流程异常", "高", $"AGV安全交互请求失败,WCS没有返回数据");
                    throw new BusinessException($"AGV安全交互请求失败,WCS没有返回数据");
                }
            }
            catch (BusinessException be)
            {
                throw be;
            }
            catch (Exception ex)
            {
                WMSHelper.addAlarmRecord("系统异常", "高", $"AGV安全交互请求错误,错误原因:{ex.Message}");
                throw new BusinessException($"AGV安全交互请求错误,错误原因:{ex.Message}");
            }
            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不可用
            public int photoStatus { get; set; } // 光电状态 1是空载 ,2是有载
            public int manualStatus { get; set; } //手动状态  0.禁用 1.启用 
        }
 
        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; } // 容器类型
 
        }
    }
}