From 23f9331460f22b8ae74219ff8d728d3fd4504584 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Thu, 13 Apr 2023 17:59:05 +0200 Subject: [PATCH] Production tracing bug fix : Previous workstep result was not checked, mere existence of a record was sufficient for a WM to pass --- .../Output/DB/ProductionTracing/Tracing.cs | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/TBF/Rig/Output/DB/ProductionTracing/Tracing.cs b/TBF/Rig/Output/DB/ProductionTracing/Tracing.cs index 3cadbca15..38fff7635 100644 --- a/TBF/Rig/Output/DB/ProductionTracing/Tracing.cs +++ b/TBF/Rig/Output/DB/ProductionTracing/Tracing.cs @@ -35,6 +35,7 @@ namespace TBF.Rig.Output.DB.ProductionTracing public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); } public const string WorkstepName = "Test_bench"; + public const int WorkstepRsltOK = 0; MonitoringCfg tracingCfg; string workplace @@ -394,22 +395,23 @@ namespace TBF.Rig.Output.DB.ProductionTracing Workstep workstep = null; ProjectionList projections = Projections.ProjectionList(); - projections.Add(Projections.Property(() => refRecord.Id)); /// rslt[0] = reference record ID - projections.Add(Projections.Property(() => workstep.Id)); /// rslt[1] = workstep ID - projections.Add(Projections.Property(() => refRecord.Process.Id)); /// rslt[2] = process ID - projections.Add(Projections.Property(() => refRecord.TimeStamp)); /// rslt[3] = reference record time stamp + projections.Add(Projections.Property(() => refRecord.Id)); /// rcrd[0] = reference record ID + projections.Add(Projections.Property(() => workstep.Id)); /// rcrd[1] = workstep ID + projections.Add(Projections.Property(() => refRecord.Process.Id)); /// rcrd[2] = process ID + projections.Add(Projections.Property(() => refRecord.TimeStamp)); /// rcrd[3] = reference record time stamp + projections.Add(Projections.Property(() => refRecord.Result)); /// rcrd[4] = result: =0...OK, >0...error code /// /// Get all reference records with Code == SerialNr from all worksteps different from 'Test_bench' /// - IList results = session.QueryOver(() => refRecord) + IList records = session.QueryOver(() => refRecord) .Where(rr => (rr.Code == wm.SerialNr)) .JoinQueryOver(rr => rr.Workstep, () => workstep) .And(ws => (ws.Name != WorkstepName)) .Select(projections) .List(); - if (results.Count == 0) + if (records.Count == 0) { /// No records found wm.ProcessId = 0; @@ -422,27 +424,29 @@ namespace TBF.Rig.Output.DB.ProductionTracing /// /// Get processId of the last record /// - int processId = 0; + int lastProcessId = 0; + int lastResult = 0; DateTime lastTimeStamp = DateTime.MinValue; - foreach (var rslt in results) + foreach (var rcrd in records) { - if (DateTime.Compare((DateTime)rslt[3], lastTimeStamp) > 0) + if (DateTime.Compare((DateTime)rcrd[3], lastTimeStamp) > 0) { - lastTimeStamp = (DateTime)rslt[3]; - processId = (int)rslt[2]; + lastTimeStamp = (DateTime)rcrd[3]; + lastProcessId = (int)rcrd[2]; + lastResult = (int)rcrd[4]; } } - if (processId == 0) return Retv.Error; /// This should never happen + if (lastProcessId == 0) return Retv.Error; /// This should never happen - if ((currentProcess == null) || (currentProcess.Id != processId)) + if ((currentProcess == null) || (currentProcess.Id != lastProcessId)) { /// /// Process changed ==> update currentProcess / currentWorkstep / verifiedWorkstep / verifiedPart / verifyReferencePart /// var processes = session.QueryOver() - .Where(p => (p.Id == processId)) + .Where(p => (p.Id == lastProcessId)) .List(); if (processes.Count != 1) return Retv.Error; @@ -472,9 +476,9 @@ namespace TBF.Rig.Output.DB.ProductionTracing wm.ProcessId = currentProcess.Id; wm.SessionId = sessionId; wm.LastRecordIsNok = true; /// NOK (=default if no matching record found) - foreach (var rslt in results) + foreach (var rcrd in records) { - if ((verifiedWorkstep.Id == (int)rslt[1]) && (processId == (int)rslt[2])) + if ((verifiedWorkstep.Id == (int)rcrd[1]) && (lastProcessId == (int)rcrd[2]) && (int)rcrd[4] == WorkstepRsltOK) { /// This record fits verification requirements wm.LastRecordIsNok = false; /// OK