From 15b3879cd259108e7ebb755fe02c190f28f1e20c Mon Sep 17 00:00:00 2001
From: leiqunqing <zhengqifeng@hnkhzn.com>
Date: 星期五, 06 二月 2026 14:46:23 +0800
Subject: [PATCH] 完善项目

---
 代码管理/WIDESEAWCS_Server/WIDESEAWCS_Server/WIDESEAWCS_Tasks/PLCJob.cs |  477 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 387 insertions(+), 90 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WIDESEAWCS_Server/WIDESEAWCS_Server/WIDESEAWCS_Tasks/PLCJob.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WIDESEAWCS_Server/WIDESEAWCS_Server/WIDESEAWCS_Tasks/PLCJob.cs"
index e373ad1..34303d0 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WIDESEAWCS_Server/WIDESEAWCS_Server/WIDESEAWCS_Tasks/PLCJob.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WIDESEAWCS_Server/WIDESEAWCS_Server/WIDESEAWCS_Tasks/PLCJob.cs"
@@ -1,10 +1,15 @@
-锘縰sing System.Text;
+锘縰sing 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;
@@ -45,7 +50,7 @@
         }
         public Task Execute(IJobExecutionContext context)
         {
-            
+
             bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
             if (flag && value != null)
             {
@@ -54,33 +59,43 @@
                     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)
+                        if (/*Heart &&*/ !EMG && AutoExecuting && OnlineExecuting && !Error)
                         {
-                            #region 涓婄嚎鎵爜
-                            HandleOnlineScan(device);
-                            #endregion
+                            //#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)
                     {
@@ -91,50 +106,159 @@
             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)
         {
-            var Location1ScanStart = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolLocation1ScanStart);
-            var Location1ScanDone = device.GetValue<W_PLCDBName, bool>(W_PLCDBName.wboolLocation1ScanDone);
-            if (Location1ScanStart && !Location1ScanDone)//鎺у埗鎵爜鏋壂鎻忔墭鐩樼爜锛屾牴鎹墭鐩樼爜鏌ヨ缁勭洏鏁版嵁锛屽垽鏂墭鐩樼粦瀹氭垚鍝佹槸鍚﹀凡缁戝畾鎵�鏈夋墍闇�闆朵欢
+            //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())
+                    if (!PalletCode.IsNotEmptyOrNull() || PalletCode == "NoRead")
                     {
                         throw new InvalidOperationException("鎵樼洏涓虹┖");
                     }
-                    var boxing = _boxingService.Repository.QueryFirst(x => x.PalletCode == PalletCode);
-                    if (boxing == null)
+
+                    if (_boxingService.Repository.QueryFirst(x => x.PalletCode == PalletCode && x.ProductCode != null) != null)
                     {
-                        throw new InvalidOperationException("鏈坊鍔犵粍鐩樹俊鎭�");
+                        device.SetValue(W_PLCDBName.wboolLocation5ScanDone, true);
+                        throw new InvalidOperationException("鎵樼洏浠ュ瓨鍦�");
                     }
-                    List<Dt_BoxingDetail> dt_BoxingDetails = _boxingDetailService.Repository.QueryData(x => x.BoxingId == boxing.Id);
-                    Dt_Formula dt_Formula = _formulaService.Repository.QueryFirst(x => x.ProductCode == boxing.ProductCode);
-                    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 (!_boxingDetailService.IsComponentCodesEqual(dt_BoxingDetails, dt_FormulaDetails))
-                    {
-                        throw new InvalidOperationException("闆朵欢鏈夐棶棰橈紝璇峰鐞�");
-                    }
-                    device.SetValue(W_PLCDBName.wboolLocation1ScanDone, true);
+
+                    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 (!Location1ScanStart && Location1ScanDone)
+            else if (!Location5ScanStart && Location5ScanDone)
             {
-                device.SetValue(W_PLCDBName.wboolLocation1ScanDone, false);
+                device.SetValue(W_PLCDBName.wboolLocation5ScanDone, false);
             }
         }
 
@@ -144,6 +268,7 @@
         /// <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)//鎺у埗鎵爜鏋壂鎻忔墭鐩樼爜锛屾牴鎹墭鐩樼爜鏌ヨ鎵樼洏缁戝畾鎴愬搧鍔犲伐鎵�闇�鏁版嵁锛屽啓鍏LC
@@ -152,36 +277,40 @@
 
                 try
                 {
-                    if (!PalletCode.IsNotEmptyOrNull())
+                    if (!PalletCode.IsNotEmptyOrNull() || PalletCode == "NoRead")
                     {
-                        throw new InvalidOperationException("鎵樼洏涓虹┖");
+                        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.wrealScrewTorqueOutput, dt_Formula.ScrewTorqueOutput);
-                    device.SetValue(W_PLCDBName.wDintAutoScrewOn, dt_Formula.DintAutoScrewOn);
+                    //涓績楂樺害
+                    device.SetValue(W_PLCDBName.wrealScrewTorque, dt_Formula.ScrewTorqueOutput);
+                    device.SetValue(W_PLCDBName.wrealAutoScrewProgramNo, dt_Formula.DintAutoScrewOn);
                     //鍘嬭鎵爜瀹屾垚
                     device.SetValue(W_PLCDBName.wboolLocation2ScanDone, true);
-                    //鎺ユ敹鏁版嵁
-                    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);
-                    //娣诲姞鍒版暟鎹簱
-                    Dt_ProcessInfo dt_ProcessInfo = new Dt_ProcessInfo()
-                    {
-                        PalletCode = PalletCode,
-                        ProductCode = dt_Formula.ProductCode,
-                        ProductName = dt_Formula.ProductName,
-                        PressHeight = PressHeight,
-                        ScrewTorque = ScrewTorque,
-                        ScrewAngle = ScrewAngle
-                    };
-                    _processInfoService.Repository.AddData(dt_ProcessInfo);
+
+
                 }
                 catch (Exception ex)
                 {
@@ -194,50 +323,123 @@
             }
         }
 
+
+        /// <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)//鎺у埗鎵爜鏋壂鎻忔墭鐩樼爜锛屾牴鎹墭鐩樼爜鏌ヨ鎵樼洏缁戝畾鎴愬搧鍔犲伐鎵�闇�鏁版嵁锛屽啓鍏LC
+            {
+
+                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())
+                    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.wrealXDirectionDistance1, dt_Formula.XDirectionDistance1);
-                    device.SetValue(W_PLCDBName.wrealYDirectionHeight1, dt_Formula.YDirectionHeight1);
-                    device.SetValue(W_PLCDBName.wrealXDirectionDistance2, dt_Formula.XDirectionDistance2);
-                    device.SetValue(W_PLCDBName.wrealYDirectionHeight2, dt_Formula.YDirectionHeight2);
-                    device.SetValue(W_PLCDBName.wrealXDirectionDistance3, dt_Formula.XDirectionDistance3);
-                    device.SetValue(W_PLCDBName.wrealYDirectionHeight3, dt_Formula.YDirectionHeight3);
+                    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);
 
-                    //鎺ユ敹鏁版嵁
-                    decimal Height1 = (decimal)device.GetValue<R_PLCDBName, float>(R_PLCDBName.rrealDetectHeight1);
-                    decimal Height2 = (decimal)device.GetValue<R_PLCDBName, float>(R_PLCDBName.rrealDetectHeight2);
-                    decimal Height3 = (decimal)device.GetValue<R_PLCDBName, float>(R_PLCDBName.rrealDetectHeight3);
 
-                    Dt_ProcessInfo dt_ProcessInfo = _processInfoService.Repository.QueryFirst(x => x.PalletCode == PalletCode);
-                    if (dt_ProcessInfo == null)
-                    {
-                        throw new InvalidOperationException("鎴愬搧鏈帇瑁�");
-                    }
-                    dt_ProcessInfo.Height1 = Height1;
-                    dt_ProcessInfo.Height2 = Height2;
-                    dt_ProcessInfo.Height3 = Height3;
-                    _processInfoService.Repository.UpdateData(dt_ProcessInfo);
                 }
                 catch (Exception ex)
                 {
@@ -252,11 +454,89 @@
         }
 
         /// <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)//鎺у埗鎵爜鏋壂鎻忔墭鐩樼爜锛屾牴鎹墭鐩樼爜鏌ヨ缁勭洏鏁版嵁锛屽垽鏂墭鐩樼粦瀹氭垚鍝佹槸鍚﹀凡缁戝畾鎵�鏈夋墍闇�闆朵欢
@@ -266,30 +546,46 @@
                 {
                     try
                     {
-                        if (!PalletCode.IsNotEmptyOrNull())
+                        if (!PalletCode.IsNotEmptyOrNull() || PalletCode == "NoRead")
                         {
                             throw new InvalidOperationException("鎵樼洏涓虹┖");
                         }
-                        Dt_ProcessInfo dt_ProcessInfo = _processInfoService.Repository.QueryFirst(x => x.PalletCode == PalletCode);
-                        if (dt_ProcessInfo == null)
-                        {
-                            throw new InvalidOperationException("鎴愬搧鏈帇瑁呭拰妫�娴�");
-                        }
                         Dt_Boxing dt_Boxing = _boxingService.Repository.QueryFirst(x => x.PalletCode == PalletCode);
-                        _boxingService.Repository.DeleteData(dt_Boxing);
-                        List<Dt_BoxingDetail> dt_BoxingDetails = _boxingDetailService.Repository.QueryData(x => x.BoxingId == dt_Boxing.Id);
-                        _boxingDetailService.Repository.DeleteData(dt_BoxingDetails);
-
-                        Dt_ProcessInfoDetail dt_ProcessInfoDetail = new Dt_ProcessInfoDetail()
+                        if (dt_Boxing != null)
                         {
-                            PalletCode = PalletCode,
-                            ProductCode = dt_ProcessInfo.ProductCode,
-                            ProductName = dt_ProcessInfo.ProductName,
-                            Creater = "admin",
-                            CreateDate = DateTime.Now
-                        };
-                        _processDetailInfoService.Repository.AddData(dt_ProcessInfoDetail);
-                        _processInfoService.DeleteData(dt_ProcessInfo);
+                            _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);
@@ -297,12 +593,13 @@
                     catch (Exception ex)
                     {
                         WriteError(device.DeviceName, "涓嬬嚎鎵爜娴佺▼鎵ц寮傚父", ex);
+
                     }
                 }
             }
             else if (!Location4ScanStart && Location4ScanDone)
             {
-                device.SetValue(W_PLCDBName.wboolLocation2ScanDone, false);
+                device.SetValue(W_PLCDBName.wboolLocation4ScanDone, false);
             }
         }
     }

--
Gitblit v1.9.3