杨前锦
2025-06-05 01cc5773457f68274ef1b2d9d9daca8983761828
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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
using HH.WCS.Mobox3.ZS7412
    .util;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Web.Services.Description;
using static HH.WCS.Mobox3.ZS7412.dispatch.HanAo;
 
namespace HH.WCS.Mobox3.ZS7412.dispatch {
    /// <summary>
    /// 国自调度辅助类
    /// </summary>
    public class HanAo {
        private static readonly HttpHelper apiHelper = new HttpHelper();
        private static readonly string baseUrl = Settings.HASeverUrl;
        //private static readonly string logName = "hanao";
 
       /* private static readonly HttpHelper apiHelper = new HttpHelper();
        private static readonly string baseUrl = "http://192.168.1.99:2000/";   //待定*/
 
 
        public static bool CreateOrder(TaskInfoModel model) {
            var msg = "";
            var result = true;
            var request = JsonConvert.SerializeObject(model);
            var response = apiHelper.Post(baseUrl + ":9001/wcs-admin/api/receive", request);
            msg = $"[hanao-CreateOrder] request={request} response={response}";
            Console.WriteLine(msg);
            if (response != "") {
                try {
                    var dataResult = JsonConvert.DeserializeObject<HAResult>(response);
                    if (dataResult.code == "0") {
                        result = true;
                    }
                }
                catch (Exception ex) {
                    Console.WriteLine(ex.Message);
                }
            }
            else {
                msg = "[hanao-CreateOrder]创建订单失败";
                Console.WriteLine(msg);
            }
 
            LogHelper.Info(msg,"杭奥");
            return result;
        }
        public static bool CancelOrder(CancelModel model) {
            bool result = false;
            string msg = "";
            var request = JsonConvert.SerializeObject(model);
            var response = apiHelper.Post(baseUrl + ":9002/wcs-admin/api/cancel", request);
            msg = $"[hanao-CancelOrder] request={request};response={response}";
            Console.WriteLine(msg);
            if (response != "") {
                var dataResult = JsonConvert.DeserializeObject<HAResult>(response);
                if (dataResult.code == "0") {
                    result = true;
                }
            }
            else {
                msg = "[hanao-CancelOrder]取消订单失败";
                Console.WriteLine(msg);
            }
            LogHelper.Info(msg, "杭奥");
            return result;
        }
        public static bool QueryDevice(DeviceInfoModel model) {
            bool result = false;
            string msg = "";
            var request = JsonConvert.SerializeObject(model);
            var response = apiHelper.Get(baseUrl + ":9003//wcs-admin/api/dvc-state/", request);
            msg = $"[hanao-QueryDeviceResult] request={request};response={response}";
            Console.WriteLine(msg);
            if (response != "") {
                var dataResult = JsonConvert.DeserializeObject<HAResult>(response);
                if (dataResult.code == "0") {
                    result = true;
                }
            }
            else {
                msg = "[hanao-QueryOrderResult]查询订单信息失败";
                Console.WriteLine(msg);
            }
            LogHelper.Info(msg, "杭奥");
            return result;
        }
 
      
 
        /// <summary>
        /// 任务状态回报上游
        /// </summary>
        /// <param name="taskreportInfo"></param>
        /// <returns></returns>
        public static bool Taskreport(TaskReportInfo taskreportInfo)
        {
            bool result = false;
            string msg;
            LogHelper.Info("Taskreport_taskreportInfo :" + JsonConvert.SerializeObject(taskreportInfo), "ZS7412");
            var response = apiHelper.Post(baseUrl + ":9007/AMS_REPORT_TO_WCS", JsonConvert.SerializeObject(taskreportInfo));
            LogHelper.Info("Taskreport_response :" + JsonConvert.SerializeObject(response), "ZS7412");
            if (response != "")
            {
                try
                {
                    var dataResult = JsonConvert.DeserializeObject<AMSResponse>(response);
                    if (dataResult.code == 0)
                    {
                        result = true;
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.Error("任务状态回报上游错误", ex, "ZS7412");
                }
            }
            else
            {
                msg = "任务状态回报上游失败";
                Console.WriteLine(msg);
            }
            return result;
        }
 
        /// <summary>
        /// 询问设备 是否可取
        /// </summary>
        /// <param name="stnNo"></param>
        /// <returns></returns>
        public static bool CanIn(string stnNo)
        {
            bool result = false;
            string msg;
            CanInInfo canInInfo = new CanInInfo() {
                stnNo = stnNo
            };
            try
            {
                var response = apiHelper.Post(baseUrl + ":9005/CAN_IN", JsonConvert.SerializeObject(canInInfo));
                LogHelper.Info("CanIn:" + JsonConvert.SerializeObject(response), "ZS7412");
                if (response != "")
                {
                        var dataResult = JsonConvert.DeserializeObject<AMSResponse>(response);
                        if (dataResult.code == 0 && dataResult.msg.Equals("success"))
                        {
                            result = true;
                        }
                }
                else
                {
                    msg = "询问设备是否可放失败";
                    Console.WriteLine(msg);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                LogHelper.Error("询问设备是否可放", ex, "ZS7412");
            }
            return result;
        }
 
        /// <summary>
        /// 询问设备 是否 可放
        /// </summary>
        /// <param name="stnNo"></param>
        /// <returns></returns>
        public static bool CanOut(string stnNo)
        {
            bool result = false;
            string msg;
            CanOutInfo canOutInfo = new CanOutInfo() {
                stnNo = stnNo
            };
            try
            {
                var response = apiHelper.Post(baseUrl + ":9006/CAN_OUT ", JsonConvert.SerializeObject(canOutInfo));
                LogHelper.Info("CanOut:"+ JsonConvert.SerializeObject(response), "ZS7412");
                if (response != "")
                {
                        var dataResult = JsonConvert.DeserializeObject<AMSResponse>(response);
                        if (dataResult.code == 0 && dataResult.msg.Equals("success"))
                        {
                            result = true;
                        }
                }
                else
                {
                    msg = "询问设备是否可取";
                    Console.WriteLine(msg);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                LogHelper.Error("询问设备是否可取", ex, "ZS7412");
            }
            return result;
        }
 
        /// <summary>
        /// 请求空托盘垛
        /// </summary>
        /// <param name="askCntrInfo"></param>
        /// <returns></returns>
        public static bool AskCntr(AskCntrInfo askCntrInfo)
        {
            bool result = false;
            string msg;
            try
            {
                var response = apiHelper.Post(baseUrl + ":9008/call_case", JsonConvert.SerializeObject(askCntrInfo));
                LogHelper.Info("AskCntr:" + JsonConvert.SerializeObject(response), "ZS7412");
                if (response != "")
                {
                        var dataResult = JsonConvert.DeserializeObject<AMSResponse1>(response);
                        if (dataResult.errCode.Equals("0") && dataResult.errMsg.Equals("success"))
                        {
                            result = true;
                        }
                }
                else
                {
                    msg = "请求空托盘垛";
                    Console.WriteLine(msg);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                LogHelper.Error("请求空托盘垛", ex, "ZS7412");
            }
            return result;
        }
 
        /// <summary>
        /// 安全退出
        /// </summary>
        /// <param name="stnNo"></param>
        /// <param name="orderid"></param>
        /// <param name="flag">1.取货完成2.卸货完成</param>
        /// <returns></returns>
        public static bool safeWithdraw(string stnNo, int orderid, int flag)
        {
            bool result = false;
            string msg;
            SafeWithdrawInfo safeWithdraw = new SafeWithdrawInfo()
            {
                stnNo = stnNo,
                taskNo = orderid.ToString(),
                state = flag,
            };
            try
            {
                LogHelper.Info("safeWithdraw:" + JsonConvert.SerializeObject(safeWithdraw), "ZS7412");
                var response = apiHelper.Post(baseUrl + ":9009/AMS_SAFE_TO_WCS", JsonConvert.SerializeObject(safeWithdraw));
                LogHelper.Info("safeWithdraw:" + JsonConvert.SerializeObject(response), "ZS7412");
                if (response != "")
                {
                    var dataResult = JsonConvert.DeserializeObject<AMSResponse>(response);
                    if (dataResult.code == 0 && dataResult.msg.Equals("success"))
                    {
                        result = true;
                    }
                }
                else
                {
                    msg = "AGV安全退出";
                    Console.WriteLine(msg);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                LogHelper.Error("AGV安全退出", ex, "ZS7412");
            }
            return result;
        }
 
        public class SafeWithdrawInfo {
            public string taskNo { get; set; }   //任务号
            public int state { get; set; }  //任务状态 
            public string stnNo { get; set; } // 站台号
        }
 
        public class TaskReportInfo
        {
            public string taskNo { get; set; }   //任务号
            public int state { get; set; }  //任务状态 
            public int agvNo { get; set; }  //执行任务车号
        }
 
        public class AMSResponse
        {
            public int code { get; set; }
 
            public string msg { get; set; }
        }
 
        public class AMSResponse1
        {
            public string errCode { get; set; }
 
            public string errMsg { get; set; }
        }
 
        public class CanInInfo
        {
            public string stnNo { get; set; } // 站台号
        }
 
        public class CanOutInfo
        {
            public string stnNo { get; set; }
        }
 
        public class AskCntrInfo
        {
            public string pos { get; set; }
 
            public string req { get; set; }
        }
    
 
    public class TaskInfoModel {
            /// <summary>
            /// 请求pk
            /// </summary>
            public string requestPk { get; set; }
            /// <summary>
            /// 托盘条码
            /// </summary>
            public string contNo { get; set; }
            /// <summary>
            /// 托盘类型
            /// </summary>
            public string contType { get; set; } = "";
            /// <summary>
            /// 任务类型  1-入库 2-出库 3-移库 
            /// </summary>
            public string trkType { get; set; }
            /// <summary>
            /// 1-999(值越大优先级越高)
            /// </summary>
            public string trkPrty { get; set; } = "1";
            public string frmPos { get; set; }
            public string toPos { get; set; }
            public string noticeInfo { get; set; } = "";
            /// <summary>
            /// 0-空托盘 1-实物
            /// </summary>
            public string isFull { get; set; } = "0";
            public string groupNo { get; set; } = "";
            public string clientCode { get; set; } = "WMS";
            /// <summary>
            /// 格式:2022-11-11 11:32:08
            /// </summary>
            public string reqTime { get; set; } = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
 
        }
        public class HAResult {
            public string code { get; set; }
            public string msg { get; set; }
            public string requestPk { get; set; }
        }
        public class CancelModel {
            public string requestPk { get; set; }
            public string contNo { get; set; }
            public string clientCode { get; set; }
            public string reqTime { get; set; } = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        }
        public class DeviceInfoModel {
            public string requestPk { get; set; }
            public string dvcNo { get; set; }
            public string clientCode { get; set; }
            public string reqTime { get; set; } = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        }
        public class TaskStateInfoModel {
            public string requestPk { get; set; }
            public string contNo { get; set; }
            /// <summary>
            /// 双方系统共同定义 1-入库 2-出库 3-移库 (后续如有增加再协定)
            /// </summary>
            public string noticeType { get; set; }
            public string curPos { get; set; }
            public string noticeInfo { get; set; }
            /// <summary>
            /// 0-成功 (入库上架完成/出库下架完成/库内移库完成:移库只上报最终移库上架) 或 其他-异常码(反馈相关结果原因,WMS根据情况处理 
            /// 1-入库有货 2-入远近有货 3-出库无货 4-出远近有货)
            /// </summary>
            public string code { get; set; }
            public string result { get; set; }
            public string clientCode { get; set; }
            public string reqTime { get; set; } = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        }
 
    }
 
 
}