1
z8018
2025-05-05 b6837f097e9cdb2645368aed4ddb03f580c331e4
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
#region << 版 本 注 释 >>
/*----------------------------------------------------------------
 * 命名空间:WIDESEAWCS_TaskInfoService
 * 创建者:胡童庆
 * 创建时间:2024/8/2 16:13:36
 * 版本:V1.0.0
 * 描述:
 *
 * ----------------------------------------------------------------
 * 修改人:
 * 修改时间:
 * 版本:V1.0.1
 * 修改说明:
 * 
 *----------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
 
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using HslCommunication;
using HslCommunication.WebSocket;
using SqlSugar;
using WIDESEAWCS_BasicInfoRepository;
using WIDESEAWCS_BasicInfoService;
using WIDESEAWCS_Common;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.BaseRepository;
using WIDESEAWCS_Core.BaseServices;
using WIDESEAWCS_Core.Enums;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.BasicInfo;
using WIDESEAWCS_DTO.PlacedBlockDTO;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_IBasicInfoRepository;
using WIDESEAWCS_IBasicInfoService;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob.Repository;
using static Dm.net.buffer.ByteArrayBuffer;
 
namespace WIDESEAWCS_TaskInfoService
{
    public class TaskService : ServiceBase<Dt_Task, ITaskRepository>, ITaskService
    {
        private readonly IUnitOfWorkManage _unitOfWorkManage;
        private readonly IMapper _mapper;
        private readonly IContainerRepository _containerRepository;
        private readonly IContainerItemRepository _containerItemRepository;
        private readonly WebSocketServer _webSocketServer;
        private readonly IOrderDetailsRepository _orderDetailsRepository;
        private readonly IContainerService _containerService;
        private readonly IOrderDetailsService _orderDetailsService;
        private readonly IOrderrowsRepository _orderrowsRepository;
        private readonly IOrderContainerRepository _orderContainerRepository;
 
        public TaskService(ITaskRepository BaseDal, IUnitOfWorkManage unitOfWorkManage, IMapper mapper, IContainerRepository containerRepository, IContainerItemRepository containerItemRepository, WebSocketServer webSocketServer, IOrderDetailsRepository orderDetailsRepository, IContainerService containerService, IOrderDetailsService orderDetailsService, IOrderrowsRepository orderrowsRepository, IOrderContainerRepository orderContainerRepository) : base(BaseDal)
        {
            _unitOfWorkManage = unitOfWorkManage;
            _mapper = mapper;
            _containerRepository = containerRepository;
            _containerItemRepository = containerItemRepository;
            _webSocketServer = webSocketServer;
            _orderDetailsRepository = orderDetailsRepository;
            _containerService = containerService;
            _orderDetailsService = orderDetailsService;
            _orderrowsRepository = orderrowsRepository;
            _orderContainerRepository = orderContainerRepository;
        }
 
        public Dt_Task? QueryAGantryUnExecuteTask(string gantryDeviceNo)
        {
            return BaseDal.QueryFirst(x => x.TaskState == (int)TaskStatusEnum.Gantry_New && x.DeviceCode == gantryDeviceNo);
        }
 
        public WebResponseContent PlaceBlockTest(int orderRowId)
        {
            try
            {
                List<OrderDetails> orderDetails = _orderDetailsRepository.QueryData(x => x.Orderrowsid == orderRowId);
                if (orderDetails == null || orderDetails.Count == 0)
                {
                    return WebResponseContent.Instance.Error("未找到订单明细信息");
                }
 
                List<PlacedBlock> placedBlocks = new List<PlacedBlock>();
 
                string putPosition = "";
 
                for (int i = 0; i < orderDetails.Count; i++)
                {
                    try
                    {
                        lock (placedBlocks)
                        {
                            int length = Convert.ToInt32(orderDetails[i].Orderdetails_length);
                            int width = Convert.ToInt32(orderDetails[i].Orderdetails_width);
                            int height = Convert.ToInt32(orderDetails[i].Orderdetails_thickness);
 
                            if (length < 300 || width < 50)
                            {
                                continue;
                            }
 
                            OrderInfo orderInfo = _orderDetailsService.GetOrderInfoByBarcode(orderDetails[i].Orderdetails_outid);
 
                            var (flag, taskPosition, message) = _containerService.GetPosition(orderInfo.OrderHeadId, orderInfo.OrderNo, length, width, height);
                            if (flag && taskPosition != null)
                            {
                                if (string.IsNullOrEmpty(putPosition))
                                {
                                    putPosition = taskPosition.PutPosition;
                                }
 
                                if (putPosition != taskPosition.PutPosition)
                                {
                                    continue;
                                }
 
                                Dt_OrderContainer orderContainer = _orderContainerRepository.QueryFirst(x => x.OrderNo == orderInfo.OrderNo && x.ContainerCode == taskPosition.PutPosition);
 
                                Dt_Container putContainer = _containerRepository.QueryFirst(x => x.ContainerCode == taskPosition.PutPosition);
                                if (putContainer == null)
                                {
                                    //todo
                                    throw new Exception("未找到放货位置");
                                }
 
                                bool isAdd = false;
                                if (orderContainer == null)
                                {
                                    orderContainer = new Dt_OrderContainer()
                                    {
                                        OrderId = orderInfo.OrderHeadId,
                                        ContainerCode = putContainer.ContainerCode,
                                        ContainerId = putContainer.Id,
                                        OrderNo = orderInfo.OrderNo,
                                    };
                                    orderContainer.MaxLength = putContainer.ContainerLength;
                                    isAdd = true;
                                }
 
                                if (taskPosition != null)
                                {
                                    Dt_ContainerItem dt_ContainerItem = new Dt_ContainerItem()
                                    {
                                        ContainerId = putContainer.Id,
                                        ItemCode = orderInfo.Barcode,
                                        ItemLength = length,
                                        ItemWidth = width,
                                        ItemHeight = height,
                                        ItemPositionX = taskPosition.PositionX,
                                        ItemPositionY = taskPosition.PositionY,
                                        ItemPositionZ = taskPosition.PositionZ,
                                        ItemRelaPositionX = taskPosition.PutPositionX,
                                        ItemRelaPositionY = taskPosition.PutPositionY,
                                        ItemRelaPositionZ = taskPosition.PutPositionZ,
                                        ItemStatus = (int)ItemStatusEnum.Assigned,
                                        ItemName = orderInfo.Barcode
                                    };
 
                                    Dt_Task dt_Task = new Dt_Task()
                                    {
                                        PalletCode = orderInfo.Barcode,
                                        DeviceCode = putContainer.DeviceCode,
                                        TaskState = (int)TaskStatusEnum.Gantry_Wait,
                                        TaskType = 0,
                                        SourceAddress = "",
                                        TargetAddress = $"F06",
                                        CurrentAddress = $"F06*{taskPosition.TakePositionX}*{taskPosition.TakePositionY}*{taskPosition.TakePositionZ}*{taskPosition.PositionR}",
                                        NextAddress = $"{putContainer.ContainerCode}*{taskPosition.PutPositionX}*{taskPosition.PutPositionY}*{taskPosition.PutPositionZ}*{taskPosition.PositionR}",
                                        ItemInfo = $"{length}*{width}*{height}",
                                        Grade = 0,
                                    };
                                    putContainer.ContainerStatus = ContainerStatusEnum.NonEmpty.ObjToInt();
                                    _unitOfWorkManage.BeginTran();
                                    BaseDal.AddData(dt_Task);
                                    _containerRepository.UpdateData(putContainer);
                                    _containerItemRepository.AddData(dt_ContainerItem);
                                    if (isAdd)
                                    {
                                        _orderContainerRepository.AddData(orderContainer);
                                    }
                                    _unitOfWorkManage.CommitTran();
 
                                    PlacedBlock placedBlock = new PlacedBlock(new Point3D(taskPosition.PositionX, taskPosition.PositionY, taskPosition.PositionZ), length > width ? length : width, width > length ? length : width, height);
                                    placedBlocks.Add(placedBlock);
 
                                    object obj = new
                                    {
                                        x = taskPosition.PutCenterPositionX - putContainer.ContainerLength / 2,
                                        y = taskPosition.PutCenterPositionY - putContainer.ContainerWidth / 2,
                                        z = taskPosition.PutCenterPositionZ,
                                        length,
                                        width,
                                        height,
                                    };
                                    _webSocketServer.PublishAllClientPayload(obj.Serialize());
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
 
                    }
                }
                return WebResponseContent.Instance.OK(data: placedBlocks);
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
 
        public WebResponseContent CreateTask(string takePosition, string putPosition, string deviceCode, int length, int width, int height)
        {
            try
            {
                Dt_Container takeContainer = _containerRepository.QueryFirst(x => x.ContainerCode == takePosition && x.ContainerType == ContainerTypeEnum.TakeContainer.ObjToInt());
                if (takeContainer == null)
                {
                    return WebResponseContent.Instance.Error("取货位置不存在");
                }
 
                List<Dt_Container> containers = _containerRepository.QueryData(x => x.DeviceCode == deviceCode && x.ContainerType == ContainerTypeEnum.PutContainer.ObjToInt());
 
                Dt_Container putContainer = _containerRepository.QueryFirst(x => x.ContainerCode == putPosition && x.ContainerType == ContainerTypeEnum.PutContainer.ObjToInt());
                if (putContainer == null)
                {
                    return WebResponseContent.Instance.Error("放货位置不存在");
                }
 
                int edge = 0;
                if (putContainer.ContainerNo == containers.Min(x => x.ContainerNo))
                {
                    edge = 1;
                }
 
                ContainerSize containerSize = new ContainerSize(putContainer.ContainerLength, putContainer.ContainerWidth, putContainer.ContainerHeight);
                List<Dt_ContainerItem> containerItems = _containerItemRepository.QueryData(x => x.ContainerId == putContainer.Id);
 
                List<PlacedBlock> placedBlocks = containerItems.Select(x => new PlacedBlock(new Point3D(x.ItemPositionX, x.ItemPositionY, x.ItemPositionZ), x.ItemLength > x.ItemLength ? x.ItemLength : x.ItemWidth, x.ItemLength > x.ItemLength ? x.ItemWidth : x.ItemLength, x.ItemHeight)).ToList();
 
 
                TaskPosition? taskPosition = _containerService.GetTaskPosition(length, width, height, containerSize, placedBlocks, edge);
                if (taskPosition == null)
                {
                    return WebResponseContent.Instance.Error("未找到合适放置位置");
                }
 
                object obj = new
                {
                    x = taskPosition.PutCenterPositionX - putContainer.ContainerLength / 2,
                    y = taskPosition.PutCenterPositionY - putContainer.ContainerWidth / 2,
                    z = taskPosition.PutCenterPositionZ,
                    length,
                    width,
                    height,
                };
 
                _webSocketServer.PublishAllClientPayload(obj.Serialize());
 
                string code = DateTime.Now.ToString("yyyyMMddHHmmss");
 
                Dt_ContainerItem dt_ContainerItem = new Dt_ContainerItem()
                {
                    ContainerId = putContainer.Id,
                    ItemCode = code,
                    ItemLength = length,
                    ItemWidth = width,
                    ItemHeight = height,
                    ItemPositionX = taskPosition.PositionX,
                    ItemPositionY = taskPosition.PositionY,
                    ItemPositionZ = taskPosition.PositionZ,
                    ItemRelaPositionX = taskPosition.PutPositionX,
                    ItemRelaPositionY = taskPosition.PutPositionY,
                    ItemRelaPositionZ = taskPosition.PutPositionZ,
                    ItemStatus = (int)ItemStatusEnum.Assigned,
                    ItemName = code
                };
 
                Dt_Task dt_Task = new Dt_Task()
                {
                    PalletCode = code,
                    DeviceCode = putContainer.DeviceCode,
                    TaskState = (int)TaskStatusEnum.Gantry_New,
                    TaskType = 0,
                    SourceAddress = "",
                    TargetAddress = $"{takeContainer.ContainerNo}",
                    CurrentAddress = $"{takeContainer.ContainerCode}*{taskPosition.TakePositionX}*{taskPosition.TakePositionY}*{taskPosition.TakePositionZ}*{taskPosition.PositionR}",
                    NextAddress = $"{putContainer.ContainerCode}*{taskPosition.PutPositionX}*{taskPosition.PutPositionY}*{taskPosition.PutPositionZ}*{taskPosition.PositionR}",
                    ItemInfo = $"{length}*{width}*{height}",
                    Grade = 0,
                };
 
                _containerItemRepository.AddData(dt_ContainerItem);
                base.AddData(dt_Task);
 
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
 
        public (bool, Dt_Task?, string) GenerateTask(OrderInfo orderInfo)
        {
            try
            {
                int length = Convert.ToInt32(orderInfo.Length);
                int width = Convert.ToInt32(orderInfo.Width);
                int height = Convert.ToInt32(orderInfo.Thickness);
 
                var (flag, taskPosition, message) = _containerService.GetPosition(orderInfo.OrderHeadId, orderInfo.OrderNo, length, width, height);
                if (flag && taskPosition != null)
                {
                    Dt_Container putContainer = _containerRepository.QueryFirst(x => x.ContainerCode == taskPosition.PutPosition);
                    if (putContainer == null)
                    {
                        return (false, null, "未找到放货位置");
                    }
 
                    Dt_Container? takeContainer = GetTakePosition(putContainer.DeviceCode);
                    if (takeContainer == null)
                    {
                        return (false, null, "未找到取货位置");
                    }
 
                    Dt_OrderContainer orderContainer = _orderContainerRepository.QueryFirst(x => x.OrderNo == orderInfo.OrderNo && x.ContainerCode == putContainer.ContainerCode);
 
                    bool isAdd = false;
                    bool isUpdate = false;
                    if (orderContainer == null)
                    {
                        orderContainer = new Dt_OrderContainer()
                        {
                            OrderId = orderInfo.OrderHeadId,
                            ContainerCode = putContainer.ContainerCode,
                            ContainerId = putContainer.Id,
                            OrderNo = orderInfo.OrderNo,
                        };
                        orderContainer.MaxLength = putContainer.ContainerLength;
                        isAdd = true;
                    }
 
                    Dt_ContainerItem dt_ContainerItem = new Dt_ContainerItem()
                    {
                        ContainerId = putContainer.Id,
                        ItemCode = orderInfo.Barcode,
                        ItemLength = length,
                        ItemWidth = width,
                        ItemHeight = height,
                        ItemPositionX = taskPosition.PositionX,
                        ItemPositionY = taskPosition.PositionY,
                        ItemPositionZ = taskPosition.PositionZ,
                        ItemRelaPositionX = taskPosition.PutPositionX,
                        ItemRelaPositionY = taskPosition.PutPositionY,
                        ItemRelaPositionZ = taskPosition.PutPositionZ,
                        ItemStatus = (int)ItemStatusEnum.Assigned,
                        ItemName = orderInfo.Barcode,
                        Remark = $"{takeContainer.ContainerCode}*{taskPosition.TakePositionX}*{taskPosition.TakePositionY}*{taskPosition.TakePositionZ}*{taskPosition.PositionR}"
                    };
 
                    Dt_Task dt_Task = new Dt_Task()
                    {
                        PalletCode = orderInfo.Barcode,
                        DeviceCode = putContainer.DeviceCode,
                        TaskState = (int)TaskStatusEnum.Gantry_Wait,
                        TaskType = 0,
                        SourceAddress = "",
                        TargetAddress = $"{takeContainer.ContainerNo}",
                        CurrentAddress = $"{takeContainer.ContainerCode}*{taskPosition.TakePositionX}*{taskPosition.TakePositionY}*{taskPosition.TakePositionZ}*{taskPosition.PositionR}",
                        NextAddress = $"{putContainer.ContainerCode}*{taskPosition.PutPositionX}*{taskPosition.PutPositionY}*{taskPosition.PutPositionZ}*{taskPosition.PositionR}",
                        ItemInfo = $"{length}*{width}*{height}",
                        Grade = 0,
                    };
                    putContainer.ContainerStatus = ContainerStatusEnum.NonEmpty.ObjToInt();
                    _unitOfWorkManage.BeginTran();
                    BaseDal.AddData(dt_Task);
                    _containerRepository.UpdateData(putContainer);
                    _containerItemRepository.AddData(dt_ContainerItem);
                    if (isAdd)
                    {
                        _orderContainerRepository.AddData(orderContainer);
                    }
                    else if (isUpdate)
                    {
                        _orderContainerRepository.UpdateData(orderContainer);
                    }
                    _unitOfWorkManage.CommitTran();
 
                    return (true, dt_Task, "");
                }
                else
                {
                    return (false, null, $"无可放置位置,{orderInfo.Serialize()}");
                }
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return (false, null, $"错误,{ex.ExceptionToString()}");
            }
        }
 
        public Dt_Container? GetTakePosition(string deviceCode)
        {
            Dictionary<string, OrderByType> orderby = new Dictionary<string, OrderByType>() { { nameof(Dt_Container.ContainerSort), OrderByType.Asc } };
            List<Dt_Container> containers = _containerRepository.QueryData(x => x.ContainerType == ContainerTypeEnum.TakeContainer.ObjToInt() && x.DeviceCode == deviceCode && x.ContainerEnable, orderby);
 
            try
            {
                if (containers == null || containers.Count == 0)
                {
                    throw new Exception($"未找到对应的取货位置,设备编号:{deviceCode}");
                }
 
                Dictionary<string, OrderByType> taskOrderby = new Dictionary<string, OrderByType>() { { nameof(Dt_Task.TaskNum), OrderByType.Desc } };
                Dt_Task task = BaseDal.QueryFirst(x => x.DeviceCode == deviceCode, taskOrderby);
                if (task != null)
                {
                    string? sourceCode = task.SourceAddress.Split("*").FirstOrDefault();
                    if (!string.IsNullOrEmpty(sourceCode))
                    {
                        Dt_Container? container = containers.FirstOrDefault(x => x.ContainerCode == sourceCode);
                        if (container != null)
                        {
                            int index = containers.IndexOf(container);
 
                            if (index + 1 < containers.Count)
                            {
                                return containers[index + 1];
                            }
                            else
                            {
                                return containers.FirstOrDefault();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
 
            }
            return containers.FirstOrDefault();
        }
 
        public WebResponseContent TaskComplete(Dt_Task task)
        {
            try
            {
                task.TaskState = TaskStatusEnum.Gantry_Completed.ObjToInt();
                _unitOfWorkManage.BeginTran();
                OrderDetails orderDetails = _orderDetailsRepository.QueryFirst(x => x.Orderdetails_outid == task.PalletCode);
                if (orderDetails != null)
                {
                    orderDetails.Orderdetails_status = PalletingStatusEnmu.PalletingSuccess.ObjToInt();
 
                    Orderrows orderrows = _orderrowsRepository.QueryFirst(x => x.id == orderDetails.Orderrowsid);
                    if (orderrows != null)
                    {
                        orderrows.Orderrows_PalletNum = orderrows.Orderrows_PalletNum ?? 0 + 1;
 
                        Dt_Container container = _containerRepository.QueryFirst(x => task.NextAddress.Contains(x.ContainerCode));
 
                        _orderDetailsRepository.UpdateData(orderDetails);
                        _orderrowsRepository.UpdateData(orderrows);
 
                        try
                        {
                            List<string> containerItemCodes = _containerItemRepository.QueryData(x => x.ContainerId == container.Id).Select(x => x.ItemCode).ToList();
 
                            List<OrderDetails> totalDetails = _orderDetailsRepository.QueryData(x => x.Orderrowsid == orderrows.id);
                            List<OrderDetails> details = totalDetails.Where(x => x.Orderrowsid == orderrows.id && x.Orderdetails_status == PalletingStatusEnmu.PalletingSuccess.ObjToInt() && containerItemCodes.Contains(x.Orderdetails_outid)).ToList();
 
                            int sortedNum = totalDetails.Where(x => x.Orderrowsid == orderrows.id && x.Orderdetails_status == PalletingStatusEnmu.PalletingSuccess.ObjToInt()).Count();
                            object data = new object();
                            if (totalDetails.Count <= sortedNum)
                            {
                                data = new
                                {
                                    stationCode = task.NextAddress.Split("*").FirstOrDefault(),
                                    release = 1,
                                    data = new
                                    {
                                        stationCode = task.NextAddress.Split("*").FirstOrDefault(),
                                        orderTotalNum = totalDetails.Count,
                                        sortedNum = sortedNum,
                                        unsortedNum = totalDetails.Count - sortedNum,
                                        stationSortedNum = details.Count,
                                        orderId = orderrows.id,
                                        orderData = new
                                        {
                                            orderCode = orderrows.Orderrows_orderid,
                                            cusName = orderrows.Orderrows_customer,
                                            orderName = orderrows.Orderrows_name,
                                            batch = orderrows.Orderrows_batchid,
                                            productName = "",
                                        }
                                    }
                                };
                            }
                            else
                            {
                                data = new
                                {
                                    stationCode = task.NextAddress.Split("*").FirstOrDefault(),
                                    release = 0,
                                    data = new
                                    {
                                        stationCode = task.NextAddress.Split("*").FirstOrDefault(),
                                        orderTotalNum = totalDetails.Count,
                                        sortedNum = sortedNum,
                                        unsortedNum = totalDetails.Count - sortedNum,
                                        stationSortedNum = details.Count,
                                        orderId = orderrows.id,
                                        orderData = new
                                        {
                                            orderCode = orderrows.Orderrows_orderid,
                                            cusName = orderrows.Orderrows_customer,
                                            orderName = orderrows.Orderrows_name,
                                            batch = orderrows.Orderrows_batchid,
                                            productName = "",
                                        }
                                    }
                                };
                            }
                            List<WebSocketSession> webSocketSessions2 = _webSocketServer.OnlineSessions.ToList();
                            List<WebSocketSession> webSocketSessions = _webSocketServer.OnlineSessions.Where(x => x.Url.Contains(task.DeviceCode ?? "")).ToList();
                            foreach (var item in webSocketSessions)
                            {
                                _webSocketServer.SendClientPayload(item, data.Serialize());
                            }
                        }
                        catch (Exception ex)
                        {
 
                        }
                    }
                }
 
                BaseDal.DeleteAndMoveIntoHty(task, App.User?.UserId > 0 ? OperateTypeEnum.人工完成 : OperateTypeEnum.自动完成);
                _unitOfWorkManage.CommitTran();
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
    }
}