leiqunqing
2026-02-06 15b3879cd259108e7ebb755fe02c190f28f1e20c
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
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using Quartz;
using System.Linq;
using System.Text;
using WIDESEAWCS_BasicInfoService;
using WIDESEAWCS_Common;
using WIDESEAWCS_Common.PLCEnum;
using WIDESEAWCS_Communicator;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.BaseRepository;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.BasicInfo;
using WIDESEAWCS_IBasicInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
 
namespace WIDESEAWCS_Tasks
{
    [DisallowConcurrentExecution]
    public class PLCJob : JobBase, IJob
    {
        private readonly IBoxingService _boxingService;
        private readonly IBoxingDetailService _boxingDetailService;
        private readonly IFormulaService _formulaService;
        private readonly IFormulaDetailService _formulaDetailService;
        private readonly IProcessInfoService _processInfoService;
        private readonly IProcessInfoDetailService _processDetailInfoService;
        private readonly IUnitOfWorkManage _unitOfWorkManage;
        private readonly IScanStationService _scanStationService;
        //private readonly string PalletCode = "PL107";
 
        public PLCJob(IBoxingService boxingService,
            IBoxingDetailService boxingDetailService,
            IFormulaService formulaService,
            IFormulaDetailService formulaDetailService,
            IProcessInfoService processInfoService,
            IProcessInfoDetailService processDetailInfoService,
            IUnitOfWorkManage unitOfWorkManage,
            IScanStationService scanStationService
            )
        {
            _boxingService = boxingService;
            _boxingDetailService = boxingDetailService;
            _formulaService = formulaService;
            _formulaDetailService = formulaDetailService;
            _processInfoService = processInfoService;
            _processDetailInfoService = processDetailInfoService;
            _unitOfWorkManage = unitOfWorkManage;
            _scanStationService = scanStationService;
        }
        public Task Execute(IJobExecutionContext context)
        {
 
            bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
            if (flag && value != null)
            {
                if (value is OtherDevice)
                {
                    OtherDevice device = (OtherDevice)value;
                    try
                    {
                        if (!device.IsConnected) throw new Exception(device.DeviceName + "连接失败");
                        var Heart = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolHeart);
                        var EMG = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolEMG);
                        var AutoExecuting = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolAutoExecuting);
                        var OnlineExecuting = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolOnlineExecuting);
                        var Error = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolError);
 
                        if (/*Heart &&*/ !EMG && AutoExecuting && OnlineExecuting && !Error)
                        {
                            //#region 零件检测
                            //HandlePartDetection(device);
                            //#endregion
 
                            //#region 上线扫码
                            //HandleOnlineScan(device);
                            //#endregion
 
                            #region 压装扫码
                            HandlePressScan(device);
                            #endregion
 
                            #region 压装信息上传
                            HandlePressInfoUpload(device);
                            #endregion
 
                            #region 检测扫码
                            HandleDetectScan(device);
                            #endregion
 
                            #region 检测信息上传
                            HandleDetectInfoUpload(device);
                            #endregion
 
                            #region 下线扫码
                            HandleOfflineScan(device);
                            #endregion
                        }
                    }
                    catch (Exception ex)
                    {
                        WriteError(device.DeviceName, "错误", ex);
                    }
                }
            }
            return Task.CompletedTask;
        }
 
 
 
 
        /// <summary>
        /// 零件检测
        /// </summary>
        /// <param name="device"></param>
        /// <exception cref="InvalidOperationException"></exception>
        private void HandlePartDetection(OtherDevice device)
        {
            //DB800.1.4
            var Location5ScanStart = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolLocation5ScanStart);
            var Location5ScanDone = device.GetValue<W_PLCDBName, bool>(W_PLCDBName.wboolLocation5ScanDone);
            if (Location5ScanStart && !Location5ScanDone)
            {
                try
                {
                    if (_scanStationService.Repository.QueryFirst(x => x.StationCode == "001").IsScanned == 0)
                    {
                        device.SetValue(W_PLCDBName.wboolLocation5ScanDone, true);
                        return;
                    }
                    Dt_Boxing dt_Boxing = _boxingService.Repository.QueryData(x => true, 1, "Id desc").FirstOrDefault();
                    if (dt_Boxing == null)
                    {
                        throw new InvalidOperationException("无组盘数据");
                    }
                    Dt_Formula dt_Formula = _formulaService.Repository.QueryFirst(x => x.ProductCode == dt_Boxing.ProductCode);
                    if (dt_Formula == null)
                    {
                        throw new InvalidOperationException("无成品配方");
                    }
                    List<Dt_BoxingDetail> dt_BoxingDetails = _boxingDetailService.Repository.QueryData(x => x.BoxingId == dt_Boxing.Id);
                    List<Dt_FormulaDetail> dt_FormulaDetails = _formulaDetailService.Repository.QueryData(x => x.FormulaId == dt_Formula.Id && x.IsScanned == 1);
                    if (!_boxingDetailService.CheckComponentsMatchExactly(dt_BoxingDetails.Select(x => x.ComponentCode).ToList(), dt_FormulaDetails.Select(x => x.ComponentCode).ToList()))
                    {
                        throw new InvalidOperationException("零件与配方表中不同");
                    }
                    device.SetValue(W_PLCDBName.wboolLocation5ScanDone, true);
                }
                catch (Exception ex)
                {
                    WriteError(device.DeviceName, "检测零件流程执行异常", ex);
                }
            }
            else if (!Location5ScanStart && Location5ScanDone)
            {
                device.SetValue(W_PLCDBName.wboolLocation5ScanDone, false);
            }
        }
 
        /// <summary>
        /// 上线扫码
        /// </summary>
        /// <param name="device"></param>
        private void HandleOnlineScan(OtherDevice device)
        {
            //DB800.1.4
            var Location5ScanStart = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolLocation5ScanStart);
            var Location5ScanDone = device.GetValue<W_PLCDBName, bool>(W_PLCDBName.wboolLocation5ScanDone);
            if (Location5ScanStart && !Location5ScanDone)//控制扫码枪扫描托盘码,根据托盘码查询组盘数据,判断托盘绑定成品是否已绑定所有所需零件
            {
                Dt_Boxing dt_Boxing1 = _boxingService.Repository.QueryData(x => true, 1, "Id desc").FirstOrDefault();
                if (dt_Boxing1 != null && dt_Boxing1.ProductCode == null)
                {
                    return;
                }
                //var PalletCode = "PL111";
                var PalletCode = TcpClientExample.Start("192.168.2.120", 2001);
                try
                {
                    if (!PalletCode.IsNotEmptyOrNull() || PalletCode == "NoRead")
                    {
                        throw new InvalidOperationException("托盘为空");
                    }
 
                    if (_boxingService.Repository.QueryFirst(x => x.PalletCode == PalletCode && x.ProductCode != null) != null)
                    {
                        device.SetValue(W_PLCDBName.wboolLocation5ScanDone, true);
                        throw new InvalidOperationException("托盘以存在");
                    }
 
                    Dt_Boxing dt_Boxing = new Dt_Boxing();
                    dt_Boxing.PalletCode = PalletCode;
                    _boxingService.Repository.AddData(dt_Boxing);
 
 
 
                    //Dt_ScanStation dt_ScanStation = _scanStationService.Repository.QueryFirst(x => x.StationCode == "001");
                    //if (dt_ScanStation == null)
                    //{
                    //    throw new InvalidOperationException("无工位数据");
                    //}
                    //Dt_Formula dt_Formula = _formulaService.Repository.QueryFirst(x => x.ProductCode == dt_ScanStation.StationEndProduct);
 
                    //if (dt_Formula == null)
                    //{
                    //    throw new InvalidOperationException("无成品配方");
                    //}
 
                    //List<Dt_FormulaDetail> dt_FormulaDetails = _formulaDetailService.Repository.QueryData(x => x.FormulaId == dt_Formula.Id && x.IsScanned == 1);
                    //if (dt_ScanStation.IsScanned == 0)
                    //{ 
                    //    Dt_Boxing dt_Boxing = new Dt_Boxing
                    //    {
                    //        PalletCode = PalletCode,
                    //        ProductCode = dt_Formula.ProductCode,
                    //        ProductName = dt_Formula.ProductName,
                    //        Creater = "admin",
                    //        CreateDate = new DateTime()
                    //    };
 
                    //    int id = _boxingService.Repository.AddData(dt_Boxing);
                    //    foreach (var item in dt_FormulaDetails)
                    //    {
                    //        Dt_BoxingDetail dt_BoxingDetail = new Dt_BoxingDetail()
                    //        {
                    //            BoxingId = id,
                    //            ComponentCode = item.ComponentCode,
                    //            ComponentName = item.ComponentName,
                    //            Creater = "admin",
                    //            CreateDate = new DateTime()
                    //        };
                    //        _boxingDetailService.Repository.AddData(dt_BoxingDetail);
                    //    }
                    //    device.SetValue(W_PLCDBName.wboolLocation5ScanDone, true);
                    //    return;
                    //}
 
                    //var boxing = _boxingService.Repository.QueryFirst(x => x.PalletCode == PalletCode);
                    //if (boxing == null)
                    //{
                    //    throw new InvalidOperationException("未添加组盘信息");
                    //}
 
                    //List<Dt_BoxingDetail> dt_BoxingDetails = _boxingDetailService.Repository.QueryData(x => x.BoxingId == boxing.Id);
 
 
                    //if (!_boxingDetailService.CheckComponentsMatchExactly(dt_BoxingDetails.Select(x => x.ComponentCode).ToList(), dt_FormulaDetails.Select(x => x.ComponentCode).ToList()))
                    //{
                    //    throw new InvalidOperationException("零件与配方表中不同");
                    //}
 
 
                }
                catch (Exception ex)
                {
                    WriteError(device.DeviceName, "上线扫码流程执行异常", ex);
                }
            }
            else if (!Location5ScanStart && Location5ScanDone)
            {
                device.SetValue(W_PLCDBName.wboolLocation5ScanDone, false);
            }
        }
 
        /// <summary>
        /// 压装扫码
        /// </summary>
        /// <param name="device"></param>
        private void HandlePressScan(OtherDevice device)
        {
            //DB800.1.1
            var Location2ScanStart = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolLocation2ScanStart);
            var Location2ScanDone = device.GetValue<W_PLCDBName, bool>(W_PLCDBName.wboolLocation2ScanDone);
            if (Location2ScanStart && !Location2ScanDone)//控制扫码枪扫描托盘码,根据托盘码查询托盘绑定成品加工所需数据,写入PLC
            {
                var PalletCode = TcpClientExample.Start("192.168.2.121", 2001);
 
                try
                {
                    if (!PalletCode.IsNotEmptyOrNull() || PalletCode == "NoRead")
                    {
                        throw new InvalidOperationException("托盘号为空");
                    }
                    Dt_Boxing dt_Boxing = _boxingService.Repository.QueryFirst(x => x.PalletCode == PalletCode);
                    if (dt_Boxing == null)
                    {
                        device.SetValue(W_PLCDBName.wboolLocation2ScanDone, true);
                        throw new InvalidOperationException("托盘为空");
                    }
                    if (dt_Boxing.ProductCode == null && dt_Boxing.BoxingNo == null)
                    {
                        device.SetValue(W_PLCDBName.wboolLocation2ScanDone, true);
                        return;
                    }
 
                    Dt_Formula dt_Formula = _formulaService.Repository.QueryFirst(x => x.ProductCode == dt_Boxing.ProductCode);
                    //写入PLC
                    device.SetValue(W_PLCDBName.wrealPressPalletCode, dt_Boxing.Id % 100);
                    if(dt_Formula.PressNoTighten == 1)
                    {
                        device.SetValue(W_PLCDBName.wboolLocation8ScanDone,true);
                    }
                    device.SetValue(W_PLCDBName.wrealProductLength, dt_Formula.ProductLength);
                    device.SetValue(W_PLCDBName.wrealProductWidth, dt_Formula.ProductWidth);
                    device.SetValue(W_PLCDBName.wrealProductHeight, dt_Formula.ProductHeight);
                    device.SetValue(W_PLCDBName.wrealScrewDownsetDistance, dt_Formula.ScrewDownsetDistance);
                    //中心高度
                    device.SetValue(W_PLCDBName.wrealScrewTorque, dt_Formula.ScrewTorqueOutput);
                    device.SetValue(W_PLCDBName.wrealAutoScrewProgramNo, dt_Formula.DintAutoScrewOn);
                    //压装扫码完成
                    device.SetValue(W_PLCDBName.wboolLocation2ScanDone, true);
 
 
                }
                catch (Exception ex)
                {
                    WriteError(device.DeviceName, "压装扫码流程执行异常", ex);
                }
            }
            else if (!Location2ScanStart && Location2ScanDone)
            {
                device.SetValue(W_PLCDBName.wboolLocation2ScanDone, false);
            }
        }
 
 
        /// <summary>
        /// 压装信息上传
        /// </summary>
        /// <param name="device"></param>
        /// <exception cref="NotImplementedException"></exception>
        private void HandlePressInfoUpload(OtherDevice device)
        {
            //DB800.1.5
            var Location6ScanStart = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolLocation6ScanStart);
            var Location6ScanDone = device.GetValue<W_PLCDBName, bool>(W_PLCDBName.wboolLocation6ScanDone);
            if (Location6ScanStart && !Location6ScanDone)//控制扫码枪扫描托盘码,根据托盘码查询托盘绑定成品加工所需数据,写入PLC
            {
 
                var PalletNum = device.GetValue<R_PLCDBName, int>(R_PLCDBName.rrealPressPalletCode);
                try
                {
                    if (!PalletNum.IsNotEmptyOrNull())
                    {
                        throw new InvalidOperationException("托盘为空");
                    }
                    Dt_Boxing dt_Boxing = _boxingService.Repository.QueryFirst(x => x.Id % 100 == PalletNum);
                    if (dt_Boxing == null)
                    {
                        device.SetValue(W_PLCDBName.wboolLocation6ScanDone, true);
                        throw new InvalidOperationException("未找到组盘数据");
                    }
                    Dt_Formula dt_Formula = _formulaService.Repository.QueryFirst(x => x.ProductCode == dt_Boxing.ProductCode);
 
 
                    //接收数据
                    decimal PressHeight = (decimal)device.GetValue<R_PLCDBName, float>(R_PLCDBName.rrealDetectPressHeight);
                    decimal ScrewTorque = (decimal)device.GetValue<R_PLCDBName, float>(R_PLCDBName.rrealDetectScrewTorque);
                    decimal ScrewAngle = (decimal)device.GetValue<R_PLCDBName, float>(R_PLCDBName.rrealDetectScrewAngle);
                    decimal PressPressure = (decimal)device.GetValue<R_PLCDBName, float>(R_PLCDBName.rrealDetectPressForce);
                    bool PressTightenNg = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rrealPressScrewByScrewNG);
                    bool PressTightenOk = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rrealPressScrewByScrewOK);
                    bool PressTightenUnfinished = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rrealPressScrewByProcessUnfinished);
 
                    
 
                    //添加到数据库
                    Dt_ProcessInfo dt_ProcessInfo = new Dt_ProcessInfo()
                    {
                        PalletCode = dt_Boxing.PalletCode,
                        ProductCode = dt_Formula.ProductCode,
                        ProductName = dt_Formula.ProductName,
                        ProductSn = dt_Boxing.BoxingNo,
                        PressTightenNg = PressTightenNg?1:0,
                        PressTightenOk = PressTightenOk?1:0,
                        PressTightenUnfinished = PressTightenUnfinished?1:0,
                        PressHeight = PressHeight,
                        ScrewTorque = ScrewTorque,
                        ScrewAngle = ScrewAngle,
                        PressPressure = PressPressure,
                    };
                    _processInfoService.Repository.AddData(dt_ProcessInfo);
 
                    // 压装信息上传完成
                    device.SetValue(W_PLCDBName.wboolLocation6ScanDone, true);
                }
                catch (Exception ex)
                {
                    WriteError(device.DeviceName, "压装信息上传流程执行异常", ex);
                }
            }
            else if (!Location6ScanStart && Location6ScanDone)
            {
                device.SetValue(W_PLCDBName.wboolLocation6ScanDone, false);
            }
        }
 
 
        /// <summary>
        /// 检测扫码
        /// </summary>
        /// <param name="device"></param>
        private void HandleDetectScan(OtherDevice device)
        {
            //DB800.1.2
            var Location3ScanStart = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolLocation3ScanStart);
            var Location3ScanDone = device.GetValue<W_PLCDBName, bool>(W_PLCDBName.wboolLocation3ScanDone);
            if (Location3ScanStart && !Location3ScanDone)
            {
                var PalletCode = TcpClientExample.Start("192.168.2.122", 2001);
 
                try
                {
                    if (!PalletCode.IsNotEmptyOrNull() || PalletCode == "NoRead")
                    {
                        throw new InvalidOperationException("托盘为空");
                    }
                    Dt_Boxing dt_Boxing = _boxingService.Repository.QueryFirst(x => x.PalletCode == PalletCode);
                    if (dt_Boxing == null)
                    {
                        device.SetValue(W_PLCDBName.wboolLocation3ScanDone, true);
                        throw new InvalidOperationException("托盘为空");
                    }
                    if (dt_Boxing.ProductCode == null && dt_Boxing.BoxingNo == null)
                    {
                        device.SetValue(W_PLCDBName.wboolLocation3ScanDone, true);
                        return;
                    }
                    Dt_Formula dt_Formula = _formulaService.Repository.QueryFirst(x => x.ProductCode == dt_Boxing.ProductCode);
                    //写入PLC
                    device.SetValue(W_PLCDBName.wrealCheckPalletCode, dt_Boxing.Id % 100);
                    device.SetValue(W_PLCDBName.wrealP0P1Width, dt_Formula.P0P1Width);
                    device.SetValue(W_PLCDBName.wrealP0P2Width, dt_Formula.P0P2Width);
                    device.SetValue(W_PLCDBName.wrealP0P3Width, dt_Formula.P0P3Width);
                    device.SetValue(W_PLCDBName.wrealP0P3Width, dt_Formula.P0P3Width);
                    device.SetValue(W_PLCDBName.wrealP1P3Height, dt_Formula.P1P3Height);
                    device.SetValue(W_PLCDBName.wrealP2P3Height, dt_Formula.P2P3Height);
 
                    //检测扫码完成
                    device.SetValue(W_PLCDBName.wboolLocation3ScanDone, true);
 
 
                }
                catch (Exception ex)
                {
                    WriteError(device.DeviceName, "检测扫码流程执行异常", ex);
                }
            }
            else if (!Location3ScanStart && Location3ScanDone)
            {
                device.SetValue(W_PLCDBName.wboolLocation3ScanDone, false);
            }
 
        }
 
        /// <summary>
        /// 检测信息上传
        /// </summary>
        /// <param name="device"></param>
        /// <exception cref="NotImplementedException"></exception>
        private void HandleDetectInfoUpload(OtherDevice device)
        {
 
            //DB800.1.6
            var Location7ScanStart = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolLocation7ScanStart);
            var Location7ScanDone = device.GetValue<W_PLCDBName, bool>(W_PLCDBName.wboolLocation7ScanDone);
            if (Location7ScanStart && !Location7ScanDone)
            {
                var PalletNum = device.GetValue<R_PLCDBName, int>(R_PLCDBName.rrealCheckPalletCode);
 
                try
                {
                    if (!PalletNum.IsNotEmptyOrNull())
                    {
                        throw new InvalidOperationException("托盘为空");
                    }
                    Dt_Boxing dt_Boxing = _boxingService.Repository.QueryFirst(x => x.Id % 100 == PalletNum);
 
                    if (dt_Boxing == null)
                    {
                        throw new InvalidOperationException("未找到组盘数据");
                    }
                    Dt_Formula dt_Formula = _formulaService.Repository.QueryFirst(x => x.ProductCode == dt_Boxing.ProductCode);
 
                    //接收数据
                    decimal Height1 = (decimal)device.GetValue<R_PLCDBName, float>(R_PLCDBName.rrealDetectHeight1);//113
                    decimal Height2 = (decimal)device.GetValue<R_PLCDBName, float>(R_PLCDBName.rrealDetectHeight2);//92
                    decimal Height3 = (decimal)device.GetValue<R_PLCDBName, float>(R_PLCDBName.rrealDetectHeight3);//11
                    bool CheckUnfinished = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rrealDetectByInspectUnfinished);
 
                    Dt_ProcessInfo dt_ProcessInfo = _processInfoService.Repository.QueryFirst(x => x.PalletCode == dt_Boxing.PalletCode);
                    int id = 0;
                    if (dt_ProcessInfo == null)
                    {
                        dt_ProcessInfo = new Dt_ProcessInfo()
                        {
                            PalletCode = dt_Boxing.PalletCode,
                            ProductCode = dt_Formula.ProductCode,
                            ProductName = dt_Formula.ProductName,
                            ProductSn = dt_Boxing.BoxingNo,
                            CheckUnfinished = CheckUnfinished?1:0,
                        };
                        id = _processInfoService.Repository.AddData(dt_ProcessInfo);
                    }
                    else
                    {
                        id = dt_ProcessInfo.Id;
                    }
                    dt_ProcessInfo.Id = id;
                    dt_ProcessInfo.Height1 = Height1 = Height1 - Height3;
                    dt_ProcessInfo.Height2 = Height2 = Height2 - Height3;
                    dt_ProcessInfo.Height3 = Height3;
 
                    _processInfoService.Repository.UpdateData(dt_ProcessInfo);
                    //检测信息上传完成
                    device.SetValue(W_PLCDBName.wboolLocation7ScanDone, true);
 
                }
                catch (Exception ex)
                {
                    WriteError(device.DeviceName, "检测扫码流程执行异常", ex);
                }
            }
            else if (!Location7ScanStart && Location7ScanDone)
            {
                device.SetValue(W_PLCDBName.wboolLocation7ScanDone, false);
            }
 
        }
 
 
        /// <summary>
        /// 下线扫码
        /// </summary>
        /// <param name="device"></param>
        private void HandleOfflineScan(OtherDevice device)
        {
            //DB800.1.3
 
            var Location4ScanStart = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolLocation4ScanStart);
            var Location4ScanDone = device.GetValue<W_PLCDBName, bool>(W_PLCDBName.wboolLocation4ScanDone);
            if (Location4ScanStart && !Location4ScanDone)//控制扫码枪扫描托盘码,根据托盘码查询组盘数据,判断托盘绑定成品是否已绑定所有所需零件
            {
                var PalletCode = TcpClientExample.Start("192.168.2.123", 2001);
                using (var uow = _unitOfWorkManage.CreateUnitOfWork())
                {
                    try
                    {
                        if (!PalletCode.IsNotEmptyOrNull() || PalletCode == "NoRead")
                        {
                            throw new InvalidOperationException("托盘为空");
                        }
                        Dt_Boxing dt_Boxing = _boxingService.Repository.QueryFirst(x => x.PalletCode == PalletCode);
                        if (dt_Boxing != null)
                        {
                            _boxingService.Repository.DeleteData(dt_Boxing);
                            List<Dt_BoxingDetail> dt_BoxingDetails = _boxingDetailService.Repository.QueryData(x => x.BoxingId == dt_Boxing.Id);
                            if (dt_BoxingDetails != null)
                            {
                                _boxingDetailService.Repository.DeleteData(dt_BoxingDetails);
                            }
                        }
                        Dt_ProcessInfo dt_ProcessInfo = _processInfoService.Repository.QueryFirst(x => x.PalletCode == PalletCode);
                        if (dt_ProcessInfo != null)
                        {
                            Dt_ProcessInfoDetail dt_ProcessInfoDetail = new Dt_ProcessInfoDetail()
                            {
                                PalletCode = PalletCode,
                                ProductCode = dt_ProcessInfo.ProductCode?.ToString() ?? "",
                                ProductName = dt_ProcessInfo.ProductName?.ToString() ?? "",
                                ProductSn = dt_ProcessInfo.ProductSn,
                                PressTightenNg = dt_ProcessInfo.PressTightenNg,
                                PressTightenOk = dt_ProcessInfo.PressTightenOk,
                                PressTightenUnfinished = dt_ProcessInfo.PressTightenUnfinished,
                                CheckUnfinished = dt_ProcessInfo.CheckUnfinished,
                                PressHeight = dt_ProcessInfo.PressHeight,
                                ScrewTorque = dt_ProcessInfo.ScrewTorque,
                                ScrewAngle = dt_ProcessInfo.ScrewAngle,
                                PressPressure = dt_ProcessInfo.PressPressure,
                                Height1 = dt_ProcessInfo.Height1,
                                Height2 = dt_ProcessInfo.Height2,
                                Height3 = dt_ProcessInfo.Height3,
                                Creater = "admin",
                                CreateDate = DateTime.Now
                            };
                            _processDetailInfoService.Repository.AddData(dt_ProcessInfoDetail);
                            _processInfoService.DeleteData(dt_ProcessInfo);
                        }
                        uow.Commit();
                        //下线扫码完成
                        device.SetValue(W_PLCDBName.wboolLocation4ScanDone, true);
                    }
                    catch (Exception ex)
                    {
                        WriteError(device.DeviceName, "下线扫码流程执行异常", ex);
 
                    }
                }
            }
            else if (!Location4ScanStart && Location4ScanDone)
            {
                device.SetValue(W_PLCDBName.wboolLocation4ScanDone, false);
            }
        }
    }
}