dengjunjie
4 天以前 b52018589bf6c7ec1d51ce8ad000a7aa993b0ab5
´úÂë¹ÜÀí/WIDESEAWCS_Server/WIDESEAWCS_Server/WIDESEAWCS_Tasks/PLCJob.cs
@@ -27,7 +27,6 @@
        private readonly IProcessInfoDetailService _processDetailInfoService;
        private readonly IUnitOfWorkManage _unitOfWorkManage;
        private readonly IScanStationService _scanStationService;
        //private readonly string PalletCode = "PL107";
        public PLCJob(IBoxingService boxingService,
            IBoxingDetailService boxingDetailService,
@@ -300,13 +299,23 @@
                    {
                        device.SetValue(W_PLCDBName.wboolLocation8ScanDone,true);
                    }
                    else
                    {
                        device.SetValue(W_PLCDBName.wboolLocation8ScanDone, false);
                    }
                    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.wrealProductHeight, dt_Formula.ProductHeight + dt_Formula.GasketHeight);
                    device.SetValue(W_PLCDBName.wrealScrewDownsetDistance, dt_Formula.ScrewDownsetDistance);
                    //中心高度
                    device.SetValue(W_PLCDBName.wrealScrewTorque, dt_Formula.ScrewTorqueOutput);
                    device.SetValue(W_PLCDBName.wrealScrewTorque, dt_Formula.ScrewTorqueOutput + dt_Formula.GasketHeight);
                    device.SetValue(W_PLCDBName.wrealAutoScrewProgramNo, dt_Formula.DintAutoScrewOn);
                    device.SetValue(W_PLCDBName.wrealPressPressure, dt_Formula.PressPressureDiff);
                    device.SetValue(W_PLCDBName.wrealTighteningTorque, dt_Formula.PressTorqueDiff);
                    device.SetValue(W_PLCDBName.wrealFastenTorque, dt_Formula.PressFastenTorque);
                    //压装扫码完成
                    device.SetValue(W_PLCDBName.wboolLocation2ScanDone, true);
@@ -354,15 +363,13 @@
                    //接收数据
                    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()
@@ -371,14 +378,22 @@
                        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,
                        ProductStatus = 1,
                        PressTightenOk = PressTightenOk ? 1 : 0,
                        PressTightenUnfinished = PressTightenUnfinished ? 1 : 0,
                        ScrewTorque = ScrewTorque,
                        ScrewAngle = ScrewAngle,
                        PressPressure = PressPressure,
                    };
                    if (
                        PressPressure > dt_Formula.ScrewDownsetDistance + dt_Formula.PressPressureDiff || PressPressure < dt_Formula.ScrewDownsetDistance - dt_Formula.PressPressureDiff ||
                        ScrewTorque > dt_Formula.PressFastenTorque + dt_Formula.PressTorqueDiff || ScrewTorque < dt_Formula.PressFastenTorque - dt_Formula.PressTorqueDiff
                        )
                    {
                        dt_ProcessInfo.ProductStatus = 0;
                    }
                    _processInfoService.Repository.AddData(dt_ProcessInfo);
                    // åŽ‹è£…ä¿¡æ¯ä¸Šä¼ å®Œæˆ
@@ -427,14 +442,27 @@
                        return;
                    }
                    Dt_Formula dt_Formula = _formulaService.Repository.QueryFirst(x => x.ProductCode == dt_Boxing.ProductCode);
                    if(dt_Formula.PressNoCheckBottomPlate == 1)
                    {
                        device.SetValue(W_PLCDBName.wboolLocation9ScanDone, true);
                    }
                    else
                    {
                        device.SetValue(W_PLCDBName.wboolLocation9ScanDone, false);
                    }
                    //写入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.wrealP1P3Height, dt_Formula.ScrewTorqueOutput + dt_Formula.GasketHeight);
                    device.SetValue(W_PLCDBName.wrealP2P3Height, dt_Formula.ProductHeight + dt_Formula.GasketHeight);
                    device.SetValue(W_PLCDBName.wrealProdHeightDiff, dt_Formula.DetectHeightDiff);
                    device.SetValue(W_PLCDBName.wrealScrewHeight, dt_Formula.ScrewPositionDiff);
                    //检测扫码完成
                    device.SetValue(W_PLCDBName.wboolLocation3ScanDone, true);
@@ -486,7 +514,14 @@
                    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);
                    if(dt_Formula.PressNoCheckBottomPlate == 1)
                    {
                        Height3 = 0;
                    }
                    //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;
@@ -498,7 +533,6 @@
                            ProductCode = dt_Formula.ProductCode,
                            ProductName = dt_Formula.ProductName,
                            ProductSn = dt_Boxing.BoxingNo,
                            CheckUnfinished = CheckUnfinished?1:0,
                        };
                        id = _processInfoService.Repository.AddData(dt_ProcessInfo);
                    }
@@ -506,10 +540,23 @@
                    {
                        id = dt_ProcessInfo.Id;
                    }
                    decimal? ThreadPositionHeight = Height1 - Height3 - dt_Formula.GasketHeight;
                    decimal? ProductCheckHeight = Height2 - Height3 - dt_Formula.GasketHeight;
                    dt_ProcessInfo.Id = id;
                    dt_ProcessInfo.Height1 = Height1 = Height1 - Height3;
                    dt_ProcessInfo.Height2 = Height2 = Height2 - Height3;
                    dt_ProcessInfo.ThreadPositionHeight = ThreadPositionHeight;
                    dt_ProcessInfo.ProductCheckHeight = ProductCheckHeight;
                    dt_ProcessInfo.Height1 = Height1;
                    dt_ProcessInfo.Height2 = Height2;
                    dt_ProcessInfo.Height3 = Height3;
                    if(
                        ProductCheckHeight > dt_Formula.ProductHeight + dt_Formula.DetectHeightDiff || ProductCheckHeight < dt_Formula.ProductHeight - dt_Formula.DetectHeightDiff ||
                        ThreadPositionHeight > dt_Formula.ScrewTorqueOutput + dt_Formula.ScrewPositionDiff || ThreadPositionHeight < dt_Formula.ScrewTorqueOutput - dt_Formula.ScrewPositionDiff
                        )
                    {
                        dt_ProcessInfo.ProductStatus = 0;
                    }
                    _processInfoService.Repository.UpdateData(dt_ProcessInfo);
                    //检测信息上传完成
@@ -551,16 +598,22 @@
                            throw new InvalidOperationException("托盘为空");
                        }
                        Dt_Boxing dt_Boxing = _boxingService.Repository.QueryFirst(x => x.PalletCode == PalletCode);
                        WriteInfo("下线扫码组盘数据",$"{PalletCode}_boxingService查询{dt_Boxing}");
                        if (dt_Boxing != null)
                        {
                            WriteInfo("下线扫码组盘数据", $"{PalletCode}_boxingService删除{dt_Boxing}");
                            _boxingService.Repository.DeleteData(dt_Boxing);
                            List<Dt_BoxingDetail> dt_BoxingDetails = _boxingDetailService.Repository.QueryData(x => x.BoxingId == dt_Boxing.Id);
                            if (dt_BoxingDetails != null)
                            {
                                WriteInfo("下线扫码组盘数据", $"{PalletCode}_boxingService删除{dt_BoxingDetails}");
                                _boxingDetailService.Repository.DeleteData(dt_BoxingDetails);
                            }
                        }
                        Dt_ProcessInfo dt_ProcessInfo = _processInfoService.Repository.QueryFirst(x => x.PalletCode == PalletCode);
                        WriteInfo("下线扫码组盘数据", $"{PalletCode}_processInfoService查询{dt_ProcessInfo}");
                        if (dt_ProcessInfo != null)
                        {
                            Dt_ProcessInfoDetail dt_ProcessInfoDetail = new Dt_ProcessInfoDetail()
@@ -569,14 +622,14 @@
                                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,
                                ProductStatus = dt_ProcessInfo.ProductStatus,
                                ScrewTorque = dt_ProcessInfo.ScrewTorque,
                                ScrewAngle = dt_ProcessInfo.ScrewAngle,
                                PressPressure = dt_ProcessInfo.PressPressure,
                                ThreadPositionHeight = dt_ProcessInfo.ThreadPositionHeight,
                                ProductCheckHeight = dt_ProcessInfo.ProductCheckHeight,
                                Height1 = dt_ProcessInfo.Height1,
                                Height2 = dt_ProcessInfo.Height2,
                                Height3 = dt_ProcessInfo.Height3,
@@ -584,7 +637,9 @@
                                CreateDate = DateTime.Now
                            };
                            _processDetailInfoService.Repository.AddData(dt_ProcessInfoDetail);
                            WriteInfo("下线扫码组盘数据", $"{PalletCode}_processInfoService删除{dt_ProcessInfo}");
                            _processInfoService.DeleteData(dt_ProcessInfo);
                        }
                        uow.Commit();
                        //下线扫码完成