xiazhengtongxue
2026-04-07 b0b5deb5825684bca5b3fa7c2ab59f60ce0e799f
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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
using MailKit.Search;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Logical;
using System;
using System.Collections.Generic;
using System.DirectoryServices.Protocols;
using System.Linq;
using System.Reflection;
using System.Reflection.Metadata;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common.LocationEnum;
using WIDESEA_Common.Log;
using WIDESEA_Common.StockEnum;
using WIDESEA_Common.TaskEnum;
using WIDESEA_Common.WareHouseEnum;
using WIDESEA_Core;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
using WIDESEA_DTO.Inbound;
using WIDESEA_DTO.Task;
using WIDESEA_IStockService;
using WIDESEA_ITaskInfoService;
using WIDESEA_Model.Models;
using static WIDESEA_ITaskInfoService.ITaskService;
 
namespace WIDESEA_TaskInfoService
{
    public partial class TaskService
    {
        public static List<string> InStationareaList = new List<string>() { "1113", "1114", "1115", "1116", "1117", "1118", "1119", "1120", "1121", "1122" ,"1123"};
        //入库,空盘回库
        public ApiResponse AddInStoreDoc(MES_InTask mES_In)
        {
            WriteLog.Write_Log("MES_接收入库任务下发", $"任务接收参数", "接收参数", $"参数:{mES_In.ToJson()}");
            ApiResponse apiResponse = new ApiResponse();
            try
            {
                if (mES_In == null) return apiResponse.Error("WMS接收道的数据为空");
                if (string.IsNullOrWhiteSpace(mES_In.warehouseNo)) return apiResponse.Error("仓库编码不能为空");
                if (string.IsNullOrWhiteSpace(mES_In.transNo)) return apiResponse.Error("单据编号不能为空");
                if (mES_In.transDate == default(DateTime)) return apiResponse.Error("单据日期不能为空");
                if (string.IsNullOrWhiteSpace(mES_In.status)) return apiResponse.Error("状态不能为空");
                if (string.IsNullOrWhiteSpace(mES_In.containerNo)) return apiResponse.Error("托盘码不能为空");
                if (string.IsNullOrWhiteSpace(mES_In.startPosition)) return apiResponse.Error("起点位置不能为空");
                if (string.IsNullOrWhiteSpace(mES_In.endPosition)) return apiResponse.Error("目标位置不能为空");
                if (string.IsNullOrWhiteSpace(mES_In.containerType)) return apiResponse.Error("载具类型不能为空");  //载具类型,布料-1,松布卷-2,成品-1
 
                Dt_Task setask = BaseDal.QueryData(x => x.PalletCode == mES_In.containerNo).FirstOrDefault();
                if (setask != null) return apiResponse.Error($"WMS已有当前任务,不可重复下发,托盘编号:{mES_In.containerNo}");
 
                // 判断下发的托盘编号是否库存托盘编号有重复
                if (_stockInfoService.IsContainerNoExist(mES_In.containerNo)) return apiResponse.Error($"当前库位已有该托盘编号,托盘编号:{mES_In.containerNo}");
                Dt_Warehouse dt_Warehouse = _warehouseService.QueryWarehouse(mES_In.warehouseNo);
                int LocationType = 1;
                string Roadway = "0";
 
                if(mES_In.startPosition == "1206")
                {
                    mES_In.startPosition = "1205";
                }
 
                string SourceAddress = mES_In.startPosition;
                string TargetAddress = "";
                string CurrentAddress = mES_In.startPosition;
                string NextAddress = "";
                int WarehouseId = dt_Warehouse.WarehouseId;
 
 
                if (dt_Warehouse.WarehouseCode == mES_In.endPosition)
                {
                    if (dt_Warehouse.WarehouseType == (int)WarehouseEnum.YMYL)
                    {
                        if (mES_In.containerType == "2") LocationType = 2;
                    }
                    else if (dt_Warehouse.WarehouseType == (int)WarehouseEnum.YMCP)
                    {
                        LocationType = 3;
                    }
 
                    // 查询每个巷道号的任务数量
                    List<RoadwayTaskCount> roadwayTaskCounts;
 
                    // 根据 WarehouseId 获取对应的巷道列表
                    var roadwayList = WarehouseId == 1
                        ? new[] { "1", "2" }
                        : new[] { "3", "4", "5" };
 
                    // 查询数据库中的实际数据
                    var queryData = BaseDal.QueryData(x => x.WarehouseId == WarehouseId && x.PalletType == (LocationType.ToString() == "3" ? "1" : LocationType.ToString()))
                        .GroupBy(x => x.Roadway)
                        .Select(g => new RoadwayTaskCount
                        {
                            Roadway = g.Key,
                            TaskCount = g.Count()
                        })
                        .ToList();
 
                    // 合并所有需要的巷道,确保每个巷道都有对应的 TaskCount
                    roadwayTaskCounts = roadwayList
                        .Select(roadway => new RoadwayTaskCount
                        {
                            Roadway = roadway,
                            TaskCount = queryData.FirstOrDefault(x => x.Roadway == roadway)?.TaskCount ?? 0
                        })
                        .ToList();
 
                    //var taskCount = BaseDal.QueryData(x => x.WarehouseId == WarehouseId && x.PalletType == LocationType.ToString()).Count();
 
                    Roadway = _locationInfoService.AccessingTunnel(dt_Warehouse.WarehouseId, LocationType, roadwayTaskCounts);
 
                    //if (Roadway == "0") return apiResponse.Error($"WMS未能查询道对应巷道编号,仓库编码:{mES_In.warehouseNo}");
                    if (Roadway == "0") return apiResponse.Error($"当前仓库已经满:{mES_In.warehouseNo}");
                    //获取对应PLC站台信息
                    Dt_roadwayinfo _Roadwayinfo = _roadWayinfoService.QbtainPlatform(Roadway);
                    NextAddress = _Roadwayinfo.InStationCode;
                }
                else
                {
                    if (dt_Warehouse.WarehouseType == (int)WarehouseEnum.YMYL)
                    {
                        Roadway="1";
                    }
                    else if (dt_Warehouse.WarehouseType == (int)WarehouseEnum.YMCP)
                    {
                        Roadway = "2";
                    }
                    TargetAddress = mES_In.endPosition;
                    NextAddress = mES_In.endPosition;
                }
 
                Dt_Task task = new Dt_Task();
                task.TaskNum = mES_In.transNo;
                task.PalletCode = mES_In.containerNo;
                task.PalletType = mES_In.containerType;
                task.Roadway = Roadway;
                task.TaskType = (int)TaskTypeEnum.Inbound;
                task.TaskStatus = (int)InTaskStatusEnum.InNew;
                task.SourceAddress = SourceAddress;
                task.TargetAddress = TargetAddress;
                task.CurrentAddress = CurrentAddress;
                task.NextAddress = NextAddress;
                task.WarehouseId = WarehouseId;
                task.OrderNo = mES_In.transDate.ToString();
                task.Grade = 1;
                task.Creater = "MES";
                task.CreateDate = DateTime.Now;
                int taskid=BaseDal.AddData(task);
 
                //创建任务后,判断是否是产线回库的任务
                if (!InStationareaList.Contains(task.SourceAddress))
                {
                    WriteLog.Write_Log("MES_接收入库任务下发", $"反馈信息", "成功", $"任务添加成功,托盘条码:{task.PalletCode}");
                    return apiResponse.OK();
                }
                else
                {
                    WCSginseng result = PLC_IssueTasks(
                        taskid, // 不是task.Taskid
                        task.WarehouseId,
                        task.TaskNum,
                        task.PalletCode,
                        int.Parse(task.PalletType),
                        task.CurrentAddress,
                        task.NextAddress,
                        "");
                    if (result.IsSuccess)
                    {
                        Dt_Task deltaskin = BaseDal.QueryData(x => x.TaskId == taskid).FirstOrDefault();
                        deltaskin.TaskStatus = (int)InTaskStatusEnum.PLC_InExecuting;
                        deltaskin.Dispatchertime = DateTime.Now;
                        string Result = MesInTaskStatusEnum.Start.GetDescription();
                        BaseDal.UpdateData(deltaskin);
                        //调取上游系统反馈开始任务
                        InStoreDocCallback(task.TaskNum, Result, "操作成功", task.PalletCode, "");
                        return apiResponse.OK();
                    }
                    else
                    {
                        Dt_Task deltask= BaseDal.QueryData(x => x.TaskId == taskid).FirstOrDefault();
                        BaseDal.DeleteData(deltask);
                        return apiResponse.Error($"下发任务失败,下发WCS失败,原因:{result.Message}");
                    }
                }
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                WriteLog.Write_Log("MES_接收入库任务下发", $"反馈信息", "失败", $"任务添加失败,托盘条码:{mES_In.containerNo},系统出错原因:{ex.Message}");
                return apiResponse.Error($"WMS任务添加错误,原因:{ex.Message}");
            }
 
 
        }
    
        //出库任务
        public ApiResponse AddOutStoreDoc(MES_InTask mES_In)
        {
            WriteLog.Write_Log("MES_接收MES出库任务下发", $"任务接收参数", "接收参数", $"参数:{mES_In.ToJson()}");
 
            ApiResponse apiResponse = new ApiResponse();
            try
            {
                if (mES_In == null) return apiResponse.Error("WMS接收道的数据为空");
                if (string.IsNullOrWhiteSpace(mES_In.warehouseNo)) return apiResponse.Error("仓库编码不能为空");
                if (string.IsNullOrWhiteSpace(mES_In.transNo)) return apiResponse.Error("单据编号不能为空");
                if (mES_In.transDate == default(DateTime)) return apiResponse.Error("单据日期不能为空");
                if (string.IsNullOrWhiteSpace(mES_In.status)) return apiResponse.Error("状态不能为空");
                if (string.IsNullOrWhiteSpace(mES_In.containerNo)) return apiResponse.Error("托盘码不能为空");
                if (string.IsNullOrWhiteSpace(mES_In.endPosition)) return apiResponse.Error("目标位置不能为空");
 
                // 当前任务mES_In.endPosition目标位置1113 - 1122
                var restrictedPositions = new List<string> { "1113", "1114", "1115", "1116", "1117", "1118", "1119", "1120", "1121", "1122", "1123" };
                bool isRestrictedPosition = restrictedPositions.Contains(mES_In.endPosition);
                if (isRestrictedPosition)
                {
                    bool hasExistingTask = BaseDal.QueryData(x => x.TargetAddress == mES_In.endPosition).Any();
                    if (hasExistingTask)
                    {
                        // 目标位置在1113-1122范围内的处理逻辑
                        return apiResponse.Error($"当前有去目标位置{mES_In.endPosition}的任务,请重新操作");
                    }
                }
                Dt_StockInfo dt_Stock=_stockInfoService.Repository.QueryData(x=>x.PalletCode== mES_In.containerNo).FirstOrDefault();
                if (dt_Stock == null) return apiResponse.Error($"WMS未能查找道该托盘条码的库存货位信息,条码:{mES_In.containerNo}");
 
                if(dt_Stock.StockStatus == (int)StockStatusEmun.已入库)
                {
                    Dt_LocationInfo dt_LocationInfo = _locationInfoService.Repository.QueryData(x => x.LocationCode == dt_Stock.LocationCode && x.LocationStatus == (int)LocationStatusEnum.InStock).FirstOrDefault();
                    if (dt_LocationInfo == null) return apiResponse.Error($"WMS未能查找道该托盘条码的库存货位信息,条码:{mES_In.containerNo},未找到货位号:{dt_Stock.LocationCode}");
 
                    Dt_roadwayinfo _Roadwayinfo = _roadWayinfoService.QbtainPlatform(dt_LocationInfo.RoadwayNo);
 
                    Dt_Task setask = BaseDal.QueryData(x => x.PalletCode == mES_In.containerNo).FirstOrDefault();
                    if (setask != null) return apiResponse.Error($"WMS已有当前任务,不可重复下发,托盘编号:{mES_In.containerNo}");
 
                    Dt_Task task = new Dt_Task();
                    task.TaskNum = mES_In.transNo;
                    task.PalletCode = dt_Stock.PalletCode;
                    task.PalletType = dt_Stock.PalletType;
                    task.Roadway = dt_LocationInfo.RoadwayNo;
                    task.TaskType = (int)TaskTypeEnum.Outbound;
                    task.TaskStatus = (int)OutTaskStatusEnum.OutNew;
                    task.SourceAddress = dt_LocationInfo.LocationCode;
                    task.TargetAddress = mES_In.endPosition;
                    task.CurrentAddress = dt_LocationInfo.LocationCode;
                    task.NextAddress = _Roadwayinfo.OutSCStationCode;
                    task.WarehouseId = dt_LocationInfo.WarehouseId;
                    task.OrderNo = mES_In.transDate.ToString();
                    task.Grade = 1;
                    task.Creater = "MES";
                    task.CreateDate = DateTime.Now;
 
                    dt_Stock.StockStatus = (int)StockStatusEmun.出库中;
                    dt_LocationInfo.LocationStatus = (int)LocationStatusEnum.Lock;
 
                    _unitOfWorkManage.BeginTran();
                    BaseDal.AddData(task);
                    _stockInfoService.Repository.UpdateData(dt_Stock);
                    _locationInfoService.Repository.UpdateData(dt_LocationInfo);
                    _unitOfWorkManage.CommitTran();
 
 
                    WriteLog.Write_Log("MES_接收MES出库任务下发", $"出库任务添加", "成功", $"添加成功,托盘条码:{dt_Stock.PalletCode}");
                    return apiResponse.OK();
                }else if(dt_Stock.StockStatus == (int)StockStatusEmun.移库锁定)
                {
                    Dt_LocationInfo dt_LocationInfo = _locationInfoService.Repository.QueryData(x => x.LocationCode == dt_Stock.LocationCode && x.LocationStatus == (int)LocationStatusEnum.Lock).FirstOrDefault();
                    if (dt_LocationInfo == null) return apiResponse.Error($"WMS未能查找道该托盘条码的库存货位信息,条码:{mES_In.containerNo},未找到货位号:{dt_Stock.LocationCode}");
 
                    Dt_roadwayinfo _Roadwayinfo = _roadWayinfoService.QbtainPlatform(dt_LocationInfo.RoadwayNo);
 
                    Dt_Task task = new Dt_Task();
                    task.TaskNum = mES_In.transNo;
                    task.PalletCode = dt_Stock.PalletCode;
                    task.PalletType = dt_Stock.PalletType;
                    task.Roadway = dt_LocationInfo.RoadwayNo;
                    task.TaskType = (int)TaskTypeEnum.Outbound;
                    task.TaskStatus = (int)OutTaskStatusEnum.OutWait;
                    task.SourceAddress = dt_LocationInfo.LocationCode;
                    task.TargetAddress = mES_In.endPosition;
                    task.CurrentAddress = dt_LocationInfo.LocationCode;
                    task.NextAddress = _Roadwayinfo.OutSCStationCode;
                    task.WarehouseId = dt_LocationInfo.WarehouseId;
                    task.OrderNo = mES_In.transDate.ToString();
                    task.Grade = 1;
                    task.Creater = "MES";
                    task.CreateDate = DateTime.Now;
 
                    _unitOfWorkManage.BeginTran();
                    BaseDal.AddData(task);
                    _unitOfWorkManage.CommitTran();
                    WriteLog.Write_Log("MES_接收MES出库任务下发", $"出库任务添加", "成功", $"添加成功,托盘条码:{dt_Stock.PalletCode}");
                    return apiResponse.OK();
 
                }
                else
                {
                    WriteLog.Write_Log("MES_接收MES出库任务下发", $"出库任务添加", $"失败,托盘条码:{dt_Stock.PalletCode}", $"库存状态错误,请查看WMS系统库存,库存状态:{dt_Stock.StockStatus}");
                    return apiResponse.Error("库存状态错误,请查看WMS系统库存");
                }
 
                
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                WriteLog.Write_Log("MES_接收MES出库任务下发", $"出库任务添加", "失败", $"任务添加失败,托盘条码:{mES_In.containerNo},系统出错原因:{ex.Message}");
                return apiResponse.Error($"WMS任务添加错误,原因:{ex.Message}");
            }
        }
 
        //储位查询接口
        public ApiResponse GetLocationByContainer(MES_InTask mES_In)
        {
            WriteLog.Write_Log("MES_储位查询接口", $"储位查询接口", "参数", $"托盘条码:{mES_In.ToJson()}");
 
            ApiResponse apiResponse = new ApiResponse();
            try
            {
                if (string.IsNullOrWhiteSpace(mES_In.containerNo)) return apiResponse.Error("托盘码不能为空");
                Dt_StockInfo dt_Stock = _stockInfoService.Repository.QueryData(x => x.PalletCode == mES_In.containerNo &&x.StockStatus==(int)StockStatusEmun.已入库).FirstOrDefault();
                if (dt_Stock == null) return apiResponse.Error($"WMS未能查找道该托盘条码的库存货位信息,条码:{mES_In.containerNo}");
                Dt_LocationInfo dt_LocationInfo = _locationInfoService.Repository.QueryData(x => x.LocationCode == dt_Stock.LocationCode).FirstOrDefault();
                if (dt_LocationInfo == null) return apiResponse.Error($"WMS未能查找道该托盘条码的库存货位信息,条码:{mES_In.containerNo},未找到货位号:{dt_Stock.LocationCode}");
 
                Dt_Warehouse dt_Warehouse = _warehouseService.Repository.QueryFirst(x=>x.WarehouseId== dt_LocationInfo.WarehouseId);
 
                apiResponse.Code = 200;
                apiResponse.Msg = "成功";
                apiResponse.Data = new ResponseData
                {
                    IsSuccess = true,
                    Message = "操作成功",
                };
                apiResponse.Data.result = new locationinfoData
                {
                    warehouseCode= dt_Warehouse.WarehouseCode,
                    locationCode = dt_LocationInfo.LocationCode,
                    areaNo = dt_LocationInfo.RoadwayNo,
                };
 
                return apiResponse;
            }
            catch (Exception ex)
            {
                WriteLog.Write_Log("MES_储位查询接口", $"储位查询接口", "查询失败", $"托盘条码:{mES_In.ToJson()}");
                return apiResponse.Error($"WMS储位查询错误,原因:{ex.Message}");
            }
            
        }
    
        //任务查询接口
        public ApiResponse GetTaskInfo(MES_InTask mES_In)
        {
            WriteLog.Write_Log("MES_任务查询接口", $"任务查询接口", "参数", $"接收的参数:{mES_In.ToJson()}");
            ApiResponse apiResponse = new ApiResponse();
            try
            {
                if (string.IsNullOrWhiteSpace(mES_In.transNo)) return apiResponse.Error("单据编号不能为空");
                Dt_Task dt_Task = BaseDal.QueryData(x => x.TaskNum == mES_In.transNo).FirstOrDefault();
                if (dt_Task == null) return apiResponse.Error($"WMS未能查找道对应单据任务,条码:{mES_In.transNo}");
                string status = "N";
 
 
                apiResponse.Code = 200;
                apiResponse.Msg = "成功";
                apiResponse.Data = new ResponseData
                {
                    IsSuccess = true,
                    Message = "操作成功",
                };
                apiResponse.Data.result = new locationinfoData
                {
                    transNo = dt_Task.TaskNum,
                    containerNo = dt_Task.PalletCode,
                    status = status,
                };
                return apiResponse;
            }
            catch (Exception ex)
            {
                WriteLog.Write_Log("MES_任务查询接口", $"任务查询接口", "失败", $"条码:{mES_In.transNo},原因:{ex.Message}");
                return apiResponse.Error($"WMS任务查询接口错误,原因:{ex.Message}");
            }
        }
 
        //任务取消接口
        public ApiResponse CancelTask(MES_InTask mES_In)
        {
            ApiResponse apiResponse = new ApiResponse();
            try
            {
                if (string.IsNullOrWhiteSpace(mES_In.transNo)) return apiResponse.Error("单据编号不能为空");
                Dt_Task dt_Task = BaseDal.QueryData(x => x.TaskNum == mES_In.transNo).FirstOrDefault();
                if (dt_Task == null) {
                    WriteLog.Write_Log("MES_任务取消接口", $"任务取消接口", "成功", $"单据编号:{mES_In.transNo},注意!!WMS未能查找道对应单据任务");
                    return apiResponse.OK();
                    //return apiResponse.Error($"WMS未能查找道对应单据任务,条码:{mES_In.transNo}");
                } 
                if(dt_Task.TaskStatus== (int)InTaskStatusEnum.InNew)
                {
                    BaseDal.DeleteData(dt_Task);
                    return apiResponse.OK();
                }else if(dt_Task.TaskStatus == (int)OutTaskStatusEnum.OutNew)
                {
                    Dt_StockInfo dt_StockInfo = _stockInfoService.Repository.QueryData(x => x.PalletCode == dt_Task.PalletCode).FirstOrDefault();
                    Dt_LocationInfo dt_LocationInfo= _locationInfoService.Repository.QueryData(x=>x.LocationCode== dt_StockInfo.LocationCode).FirstOrDefault();
                    dt_StockInfo.StockStatus = (int)StockStatusEmun.已入库;
                    dt_LocationInfo.LocationStatus = (int)LocationStatusEnum.InStock;
 
                    _stockInfoService.Repository.UpdateData(dt_StockInfo);
                    _locationInfoService.Repository.UpdateData(dt_LocationInfo);
                    BaseDal.DeleteData(dt_Task);
                    WriteLog.Write_Log("MES_任务取消接口", $"任务取消接口", "成功", $"单据编号:{mES_In.transNo}");
                    return apiResponse.OK();
                }
                else
                {
                    WriteLog.Write_Log("MES_任务取消接口", $"任务取消接口", "失败", $"单据编号:{mES_In.transNo},任务已经在执行中,不可取消");
                    return apiResponse.Error("任务已经在执行中,不可取消");
                }
                
            }
            catch (Exception ex)
            {
                WriteLog.Write_Log("MES_任务取消接口", $"任务取消接口", "失败", $"单据编号:{mES_In.transNo},原因:{ex.Message}");
                return apiResponse.Error($"WMS任务取消接口错误,原因:{ex.Message}");
            }
        }
 
        //入库任务反馈接口
        public MES_parameter InStoreDocCallback(string TransNo, string Result, string ResultMsg, string ContainerNo, string LocationCode)
        {
            MES_parameter mES_Parame= new MES_parameter();
            try
            {
                MesInResultResponse mesInResult = new MesInResultResponse();
                mesInResult.TransNo = TransNo;
                mesInResult.Result = Result;
                mesInResult.ResultMsg = ResultMsg;
                mesInResult.ContainerNo = ContainerNo;
                mesInResult.LocationCode = LocationCode;
                mES_Parame = HttpHelper.Post<MES_parameter>(MES_InReporttask, mesInResult, "入库任务汇报");
 
                WriteLog.Write_Log("MES_入库任务反馈接口", $"入库任务反馈接口", "成功", $"订单编号:{TransNo},执行结果:{Result},执行结果描述:{ResultMsg},托盘条码:{ContainerNo},库位编号:{LocationCode},上传的参数:{mesInResult.ToJson()},回传的参数:{mES_Parame.ToJson()}");
                return mES_Parame;
            }
            catch (Exception ex)
            {
                mES_Parame.Result = "N";
                mES_Parame.ResultMsg= $"入库:WMS系统上传失败,原因:{ex.Message}";
                WriteLog.Write_Log("MES_入库任务反馈接口", $"入库任务反馈接口", "失败", $"订单编号:{TransNo},执行结果:{Result},执行结果描述:{ResultMsg},托盘条码:{ContainerNo},库位编号:{LocationCode},上传失败,原因:{ex.Message}");
                return mES_Parame;
            }
 
        }
        //出库任务反馈接口
        public MES_parameter OutStoreDocCallback(string TransNo,string Result,string ResultMsg)
        {
            MES_parameter mES_Parame = new MES_parameter();
            try
            {
                MesOutResultResponse mesInResult = new MesOutResultResponse();
                mesInResult.TransNo = TransNo;
                mesInResult.Result = Result;
                mesInResult.ResultMsg = ResultMsg;
                mES_Parame = HttpHelper.Post<MES_parameter>(MES_OutReporttask, mesInResult, "出库任务汇报");
                WriteLog.Write_Log("MES_出库任务反馈接口", $"出库任务反馈接口", "成功", $"订单编号:{TransNo},执行结果:{Result},执行结果描述:{ResultMsg},上传的参数:{mesInResult.ToJson()},回传的参数:{mES_Parame.ToJson()}");
                return mES_Parame;
            }
            catch (Exception ex)
            {
                mES_Parame.Result = "N";
                mES_Parame.ResultMsg = $"出库:WMS系统上传失败,原因:{ex.Message}";
                WriteLog.Write_Log("MES_出库任务反馈接口", $"出库任务反馈接口", "失败", $"订单编号:{TransNo},执行结果:{Result},执行结果描述:{ResultMsg},上传失败,原因:{ex.Message}");
                return mES_Parame;
            }
        }
 
        /// <summary>
        /// 储位异动申请
        /// </summary>
        /// <param name="ContainerNo">托盘条码</param>
        /// <param name="OriginalLocationCode">原储位</param>
        /// <param name="NewLocationCode">新储位</param>
        /// <returns></returns>
        public MES_parameter ApplicationChangeStorageLocation(string ContainerNo,string OriginalLocationCode,string NewLocationCode)
        {
            MES_parameter mES_Parame = new MES_parameter();
            try
            {
                MES_Storagelocation Storagelocation = new MES_Storagelocation();
                Storagelocation.ContainerNo = ContainerNo;
                Storagelocation.OriginalLocationCode = OriginalLocationCode;
                Storagelocation.NewLocationCode = NewLocationCode;
                mES_Parame = HttpHelper.Post<MES_parameter>(MES_InventoryUpdateApply, Storagelocation, "储位异动申请");
                WriteLog.Write_Log("MES_储位异动申请", $"储位异动申请", "成功", $"托盘条码:{ContainerNo},原库位:{OriginalLocationCode},新库位:{NewLocationCode},上传的参数:{Storagelocation.ToJson()},回传的参数:{mES_Parame.ToJson()}");
                return mES_Parame;
            }
            catch (Exception ex)
            {
                mES_Parame.Result = "N";
                mES_Parame.ResultMsg = $"储位异动申请:WMS系统调取失败,原因:{ex.Message}";
                WriteLog.Write_Log("MES_储位异动申请", $"储位异动申请", "失败", $"托盘条码:{ContainerNo},原库位:{OriginalLocationCode},新库位:{NewLocationCode},上传失败,原因:{ex.Message}");
                return mES_Parame;
            }
        }
 
        /// <summary>
        /// 储位异动
        /// </summary>
        /// <param name="ContainerNo">托盘条码</param>
        /// <param name="OriginalLocationCode">原储位</param>
        /// <param name="NewLocationCode">新储位</param>
        /// <returns></returns>
        public MES_parameter AbnormalStorageLocation(string ContainerNo, string OriginalLocationCode, string NewLocationCode)
        {
            MES_parameter mES_Parame = new MES_parameter();
            try
            {
                MES_Storagelocation Storagelocation = new MES_Storagelocation();
                Storagelocation.ContainerNo = ContainerNo;
                Storagelocation.OriginalLocationCode = OriginalLocationCode;
                Storagelocation.NewLocationCode = NewLocationCode;
                mES_Parame = HttpHelper.Post<MES_parameter>(MES_InventoryUpdateCallback, Storagelocation, "储位异动");
                WriteLog.Write_Log("MES_储位异动上传", $"储位异动上传", "成功", $"托盘条码:{ContainerNo},原库位:{OriginalLocationCode},新库位:{NewLocationCode},上传的参数:{Storagelocation.ToJson()},回传的参数:{mES_Parame.ToJson()}");
                return mES_Parame;
            }
            catch (Exception ex)
            {
                mES_Parame.Result = "N";
                mES_Parame.ResultMsg = $"储位异动:WMS系统调取失败,原因:{ex.Message}";
                WriteLog.Write_Log("MES_储位异动上传", $"储位异动上传", "失败", $"托盘条码:{ContainerNo},原库位:{OriginalLocationCode},新库位:{NewLocationCode},上传失败,原因:{ex.Message}");
                return mES_Parame;
            }
        }
        /// <summary>
        /// 任务异常
        /// </summary>
        /// <param name="TransNo">单据编号</param>
        /// <param name="EquipmentType">设备类型</param>
        /// <param name="EquipmentNumber">设备编码</param>
        /// <param name="ErrorInfo">异常报文</param>MES_TaskErrorInfoCallback
        /// <returns></returns>
        public MES_parameter ToMES_TaskException(string TransNo,string EquipmentType,string EquipmentNumber,string ErrorInfo)
        {
            MES_parameter mES_Parame = new MES_parameter();
            try
            {
                MES_TaskException Storagelocation = new MES_TaskException();
                Storagelocation.TransNo = TransNo;
                Storagelocation.EquipmentType = EquipmentType;
                Storagelocation.EquipmentNumber = EquipmentNumber;
                Storagelocation.ErrorInfo = ErrorInfo;
                mES_Parame = HttpHelper.Post<MES_parameter>(MES_TaskErrorInfoCallback, Storagelocation, "任务异常");
                WriteLog.Write_Log("MES_任务异常", $"任务异常", "成功", $"单据编号:{TransNo},设备类型:{EquipmentType},设备编码:{EquipmentNumber},异常报文{ErrorInfo},,上传的参数:{Storagelocation.ToJson()},回传的参数:{mES_Parame.ToJson()}");
                return mES_Parame;
            }
            catch (Exception ex)
            {
                mES_Parame.Result = "N";
                mES_Parame.ResultMsg = $"任务异常:WMS系统调取失败,原因:{ex.Message}";
                WriteLog.Write_Log("MES_任务异常", $"任务异常", "失败", $"单据编号:{TransNo},设备类型:{EquipmentType},设备编码:{EquipmentNumber},异常报文{ErrorInfo},上传失败,原因:{ex.Message}");
                return mES_Parame;
            }
        }
    }
}