chengsc
2025-04-22 06119d5fc554b81637265470caf1d3363e2b027c
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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
using DocumentFormat.OpenXml.EMMA;
using Elastic.Clients.Elasticsearch;
using Furion.Logging;
using Furion.RemoteRequest.Extensions;
using Newtonsoft.Json;
using System.Text;
using WCS.Application.Entity;
using static SKIT.FlurlHttpClient.Wechat.Api.Models.ComponentTCBBatchCreateContainerServiceVersionResponse.Types;
 
namespace WCS.Application;
public class HttpService
{
    private dynamic Urls;
 
    private static readonly ISqlSugarClient _db = SqlSugarSetup.ITenant.GetConnectionScope(SqlSugarConst.MainConfigId);
    public HttpService()
    {
        var _sysConfigService = App.GetService<SysConfigService>();
        Urls = _sysConfigService.GetSystemInfo().Result;
    }
 
 
    /// <summary>
    /// 调用WMS接口申请巷道接口
    /// </summary>
    /// <param name="palletNo"></param>
    /// <param name="startLocat"></param>
    /// <param name="taskModel"></param>
    /// <param name="ceng"></param>
    /// <param name="endLocat"></param>
    /// <param name="taskNo"></param>
    /// <returns></returns>
    public string RequestRoadWay(string palletNo, string startLocat, string taskModel, string ceng, ref string endLocat, ref string taskNo)
    {
        string returnStr = "";
 
 
        var task = _db.Queryable<WcsTask>().First(m => m.IsDelete == false && (m.Status == TaskStatusEnum.Wait || m.Status == TaskStatusEnum.Doing) && m.TaskType == TaskTypeEnum.In && m.PalletNo == palletNo);
 
        if (task == null)
        {
            var model = new RequestAsnTask()
            {
                PalletNo = palletNo,
                HouseNo = "W01",
                TaskModel = taskModel
            };
 
            string url = Urls.WMSAddress + ":" + Urls.WMSPort;
            var result = (url + "/api/DownAPi/RequestRoadWay").SetBody(model, "application/json", Encoding.UTF8).PostAsAsync<ResponseTasks>().Result;
            Log.Information("调用WMS接口反馈任务接口" + result.ToJson());
            if (result.Success == 0)
            {
 
                var taskAdd = new WcsTask()
                {
                    TaskType = TaskTypeEnum.In,
                    Status = TaskStatusEnum.Wait,
                    Origin = "WMS",
                    StartLocate = startLocat,
                    PalletNo = palletNo,
                    TaskNo = result.TaskList.TaskNo,
                    Levels = 999,
                    EndLocate = result.TaskList.EndLocate,
                    EndRoadway = result.TaskList.EndRoadway
                };
 
                _db.Insertable(taskAdd).ExecuteCommand();
                endLocat = result.TaskList.EndRoadway;
                taskNo = result.TaskList.TaskNo;
                returnStr = result.TaskList.EndLocate;
 
            }
            else
            {
                returnStr = "-1:" + result.Message;
                return returnStr;
            }
        }
        else
        {
            returnStr = task.EndLocate;
            endLocat = task.EndRoadway;
            taskNo = task.TaskNo;
        }
 
        endLocat = PLCCommon.RoadwayToStationNum(endLocat, ceng);
 
        return returnStr;
    }
 
    /// <summary>
    /// 调用WMS接口自动码垛绑定信息返回巷道口
    /// </summary>
    /// <returns></returns>
    public string BindRequestRoadWay(string orderNo, string palletNo, decimal qty, string type, string skuNo, string lotNo, string lotText, string supplierLot, List<WcsBoxInfo> detail,
        string startLocat, string taskModel, string ceng, ref string endLocat, ref string taskNo)
    {
        string returnStr = "";
 
        var task = _db.Queryable<WcsTask>().First(m => m.IsDelete == false && (m.Status == TaskStatusEnum.Wait || m.Status == TaskStatusEnum.Doing) && m.TaskType == TaskTypeEnum.In && m.PalletNo == palletNo);
        if (task == null)
        {
            var model = new BoxPalletBindVm()
            {
                OrderCode = "",//暂无上游系统编号
                AsnNo = orderNo,
                AsnDetailNo = 0,//暂无入库单明细编号,WMS根据物料批次查找
                PalletNo = palletNo,
                Qty = qty,
                Type = type,
                SkuNo = skuNo,
                LotNo = lotNo,
                LotText = lotText,
                SupplierLot = supplierLot,
                Detail = detail
            };
            string url = Urls.WMSAddress + ":" + Urls.WMSPort;
            var result = (url + "/api/DownAPi/BindRequestRoadWay").SetBody(model, "application/json", Encoding.UTF8).PostAsAsync<ResponseTasks>().Result;
            Log.Information("调用WMS接口反馈任务接口" + result.ToJson());
            if (result.Success == 0)
            {
                var taskAdd = new WcsTask()
                {
                    TaskType = TaskTypeEnum.In,
                    Status = TaskStatusEnum.Wait,
                    Origin = "WMS",
                    StartLocate = startLocat,
                    PalletNo = palletNo,
                    TaskNo = result.TaskList.TaskNo,
                    EndLocate = result.TaskList.EndLocate,
                    EndRoadway = result.TaskList.EndRoadway
                };
 
                _db.Insertable(taskAdd).ExecuteCommand();
                endLocat = result.TaskList.EndRoadway;
                returnStr = result.TaskList.EndLocate;
            }
            else
            {
                returnStr = "-1:" + result.Message;
                return returnStr;
            }
        }
        else
        {
            returnStr = task.EndLocate;
            endLocat = task.EndRoadway;
            taskNo = task.TaskNo;
        }
 
        endLocat = PLCCommon.RoadwayToStationNum(endLocat, ceng);
 
        return returnStr;
    }
    /// <summary>
    /// 调用WMS接口申请储位接口
    /// </summary>
    /// <param name="palletNo"></param>
    /// <param name="startLocat"></param>
    /// <param name="taskModel"></param>
    /// <param name="starRoadWay"></param>
    /// <param name="taskNo"></param>
    /// <returns></returns>
    public string RequestLocate(string palletNo, string startLocat, string taskModel, string starRoadWay, ref string taskNo)
    {
        string returnStr = "";
 
 
        var task = _db.Queryable<WcsTask>().First(m => m.IsDelete == false
        && (m.Status == TaskStatusEnum.Wait || m.Status == TaskStatusEnum.Doing)
        && m.TaskType == TaskTypeEnum.In && m.PalletNo == palletNo && !string.IsNullOrWhiteSpace(m.EndLocate));
 
        if (task == null)
        {
            var model = new RequestAsnTask()
            {
                PalletNo = palletNo,
                HouseNo = "W01",
                RoadWayNo = starRoadWay,
                TaskModel = taskModel
            };
 
            string url = Urls.WMSAddress + ":" + Urls.WMSPort;
            var result = (url + "/api/DownAPi/RequestLocation").SetBody(model, "application/json", Encoding.UTF8).PostAsAsync<ResponseTasks>().Result;
            Log.Information("调用WMS申请储位接口反馈任务接口" + result.ToJson());
            if (result.Success == 0)
            {
                var taskUp = _db.Queryable<WcsTask>().First(m => m.IsDelete == false && m.TaskNo == result.TaskList.TaskNo);
                if (taskUp == null)
                {
                    var taskAdd = new WcsTask()
                    {
                        TaskNo = result.TaskList.TaskNo,
                        TaskType = TaskTypeEnum.In,
                        Status = TaskStatusEnum.Wait,
                        //IsSuccess =TaskSuccessEnum.Success,
                        Origin = "WMS",
                        StartLocate = startLocat,
                        PalletNo = palletNo,
                        EndLocate = result.TaskList.EndLocate,
                        EndRoadway = result.TaskList.EndRoadway
                    };
                    _db.Insertable(taskAdd).ExecuteCommand();
                    HubUtil.PublicTask(taskAdd.Adapt<WcsTaskOutput>());
                }
                else
                {
                    taskUp.EndRoadway = result.TaskList.EndRoadway;
                    taskUp.EndLocate = result.TaskList.EndLocate;
                    _db.Updateable(taskUp).ExecuteCommand();
                    HubUtil.PublicTask(taskUp.Adapt<WcsTaskOutput>());
                }
 
 
                returnStr = result.TaskList.EndLocate;
                taskNo = result.TaskList.TaskNo;
            }
            else
            {
                returnStr = "-1:" + result.Message;
                return returnStr;
            }
        }
        else
        {
            returnStr = task.EndLocate;
            taskNo = task.TaskNo;
        }
 
        return returnStr;
    }
 
 
    /// <summary>
    /// 调用WMS接口 反馈任务接口
    /// </summary>
    /// <param name="model">任务完成状态</param>
    /// <returns></returns>
    public async Task<ResponseModel> RequestTask(TaskRequestWMS model)
    {
        string url = Urls.WMSAddress + ":" + Urls.WMSPort;
        var result = await (url + "/api/DownAPi/ReceiveWcsSignal").SetBody(model, "application/json", Encoding.UTF8).PostAsAsync<ResponseModel>();
        Log.Information("调用WMS接口反馈任务接口" + result.ToJson());
        return result;
    }
 
    /// <summary>
    /// 调用WMS接口反馈空取异常接口
    /// </summary>
    /// <param name="model">任务信息</param>
    /// <returns></returns>
    public async Task<ResponseTasks> RequestEmptyException(TaskRequest model)
    {
        string url = Urls.WMSAddress + ":" + Urls.WMSPort;
        var result = await (url + "/api/DownAPi/EmptyException").SetBody(model, "application/json", Encoding.UTF8).PostAsAsync<ResponseTasks>();
        Log.Information("调用WMS接口反馈空取异常接口" + result.ToJson());
        return result;
    }
 
    /// <summary>
    /// 调用WMS接口反馈满取异常接口
    /// </summary>
    /// <param name="model">任务信息</param>
    /// <returns></returns>
    public async Task<ResponseTasks> RequestFullException(TaskRequest model)
    {
        string url = Urls.WMSAddress + ":" + Urls.WMSPort;
        var result = await (url + "/api/DownAPi/FullException").SetBody(model, "application/json", Encoding.UTF8).PostAsAsync<ResponseTasks>();
        Log.Information("调用WMS接口反馈满取异常接口" + result.ToJson());
        return result;
    }
 
    /// <summary>
    /// 调用WMS接口申请空托跺出库
    /// </summary>
    /// <param name="Num"></param>
    /// <param name="OutMode"></param>
    /// <returns></returns>
    public string IssuePlnOutHouseWcs(string Num, string OutMode)
    {
        string returnStr = "";
 
        var model = new OutPalletModel()
        {
            Num = Num,//出库跺数
            OutMode = OutMode//出库口
        };
        string url = Urls.WMSAddress + ":" + Urls.WMSPort;
        var result = (url + "/api/DownAPi/IssuePlnOutHouseWcs").SetBody(model, "application/json", Encoding.UTF8).PostAsAsync<ResponseOutPallet>().Result;
        Log.Information("调用WMS接口反馈任务接口" + result.ToJson());
 
        if (result.Success == 0)
        {
            foreach (var item in result.TaskList)
            {
                var taskUp = _db.Queryable<WcsTask>().First(m => m.IsDelete == false && m.TaskNo == item.TaskNo);
                if (taskUp == null)
                {
                    var taskAdd = new WcsTask()
                    {
                        TaskNo = item.TaskNo,
                        TaskType = (TaskTypeEnum)(int.Parse(item.TaskType)),
                        Status = TaskStatusEnum.Wait,
                        //IsSuccess =TaskSuccessEnum.Success,
                        Origin = "WMS",
                        StartLocate = item.StartLocate,
                        StartRoadway = item.StartRoadway,
                        PalletNo = item.PalletNo,
                        EndLocate = item.EndLocate,
                        EndRoadway = item.EndRoadway
                    };
                    _db.Insertable(taskAdd).ExecuteCommand();
                    HubUtil.PublicTask(taskAdd.Adapt<WcsTaskOutput>());
                }
                else
                {
                    taskUp.EndRoadway = item.EndRoadway;
                    taskUp.EndLocate = item.EndLocate;
                    _db.Updateable(taskUp).ExecuteCommand();
                    HubUtil.PublicTask(taskUp.Adapt<WcsTaskOutput>());
                }
            }
        }
        else
        {
            returnStr = "-1:" + result.Message;
            return returnStr;
        }
        return returnStr;
    }
    /// <summary>
    /// 调用WMS接口申请巷道接口
    /// </summary>
    /// <param name="palletNo"></param>
    /// <returns></returns>
    public async Task<ResponseTasksModel> RequestRoadway(string palletNo)
    {
        string url = Urls.WMSAddress + ":" + Urls.WMSPort;
        var result = await (url + "/api/DownAPi/RequestRoadway").SetBody(palletNo, "application/json", Encoding.UTF8).PostAsAsync<ResponseTasksModel>();
        Log.Information("调用WMS接口申请巷道接口" + result.ToJson());
        return result;
    }
    /// <summary>
    /// 调用WMS接口申请工位接口
    /// </summary>
    /// <returns></returns>
    public async Task<ResponseStationModel> RequestStationNum(RequestStation mod)
    {
        string url = Urls.WMSAddress + ":" + Urls.WMSPort;
        var result = await (url + "/api/DownAPi/RequestStationNum").SetBody(mod, "application/json", Encoding.UTF8).PostAsAsync<ResponseStationModel>();
        Log.Information("调用WMS接口申请工位接口" + result.ToJson());
        return result;
    }
 
    /// <summary>
    /// 调用WMS接口C口到A口完成回写
    /// </summary>
    /// <returns></returns>
    public async Task<ResponseStationModel> EditLogPalletTask(RequestStation mod)
    {
        string url = Urls.WMSAddress + ":" + Urls.WMSPort;
        var result = await (url + "/api/DownAPi/EditLogPalletTask").SetBody(mod, "application/json", Encoding.UTF8).PostAsAsync<ResponseStationModel>();
        Log.Information("调用WMS接口C口到A口完成回写" + result.ToJson());
        return result;
    }
    /// <summary>
    /// 调用WMS接口申请2楼工位接口
    /// </summary>
    /// <returns></returns>
    public async Task<ResponseStationModel> RequestStationNum2(RequestStation mod)
    {
        string url = Urls.WMSAddress + ":" + Urls.WMSPort;
        var result = await (url + "/api/DownAPi/RequestStationNum2").SetBody(mod, "application/json", Encoding.UTF8).PostAsAsync<ResponseStationModel>();
        Log.Information("调用WMS接口申请工位接口" + result.ToJson());
        return result;
    }
 
    /// <summary>
    /// 调用AGV小车接口下发任务
    /// </summary>
    /// <param name="mod"></param>
    /// <returns></returns>
    public async Task<AgvResponse> GenAgvSchedulingTask(AgvTaskInput mod)
    {
        string url = Urls.RCSAddress + ":" + Urls.RCSPort;
        var result = await (url + "/rcms/services/rest/hikRpcService/genAgvSchedulingTask").SetBody(mod, "application/json", Encoding.UTF8).PostAsAsync<AgvResponse>();
        Log.Information("调用AGV小车接口下发任务" + result.ToJson());
        return result;
    }
 
    /// <summary>
    /// 调用AGV小车接口反馈开门成功
    /// </summary>
    /// <param name="mod"></param>
    /// <returns></returns>
    public async Task<AgvResponse2> NotifyExcuteResultInfo(AgvNotifyInput mod)
    {
        string url = Urls.RCSAddress + ":" + Urls.RCSPort;
        var result = await (url + "/rcms/services/rest/liftCtlService/notifyExcuteResultInfo").SetBody(mod, "application/json", Encoding.UTF8).PostAsAsync<AgvResponse2>();
        Log.Information("调用AGV小车接口反馈开门成功" + result.ToJson());
        return result;
    }
    /// <summary>
    /// 调用AGV小车接口取消任务
    /// </summary>
    /// <param name="mod"></param>
    /// <param name="url"></param>
    /// <returns></returns>
    public async Task<AgvResponse> CancelTask(CancelTaskModel mod)
    {
        string url = Urls.RCSAddress + ":" + Urls.RCSPort;
        var result = await (url + "/rcms/services/rest/hikRpcService/cancelTask").SetBody(mod, "application/json", Encoding.UTF8).PostAsAsync<AgvResponse>();
        Log.Information("调用AGV小车接口取消任务" + result.ToJson());
        return result;
    }
}