SharedDatabase.WorkflowSummary.ReadFromDB(), int wm.ProcessId -> string wm.Workflow, etc.
This commit is contained in:
@@ -78,28 +78,8 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
/// </summary>
|
||||
Results.Entities.Batch batch;
|
||||
|
||||
|
||||
public ISessionFactory SessionFactory; /// Factory to create database sessions that is initialized in the constructor
|
||||
|
||||
IList<SharedDatabase.Entities.Process> workflows;
|
||||
Dictionary<int, SharedDatabase.Entities.Process> workflowDictionary;
|
||||
Dictionary<int, IList<SharedDatabase.Entities.Workstep>> workstepsDictionary;
|
||||
|
||||
ISessionFactory sessionFactory2; /// Factory to create database sessions that is initialized in the constructor
|
||||
IList<SharedDatabase.Entities.Process> processes2;
|
||||
Dictionary<int, SharedDatabase.Entities.Process> processDictionary2;
|
||||
Dictionary<int, IList<SharedDatabase.Entities.Workstep>> workstepsDictionary2;
|
||||
|
||||
///
|
||||
/// Previous workstep verification info
|
||||
///
|
||||
OrderInfo currentOrder;
|
||||
Process currentWorkflow; /// Currently used workflow
|
||||
Workstep currentWorkstep; /// Currently used workstep of this test bench
|
||||
Workstep verifiedWorkstep;
|
||||
Part verifiedPart; /// Applicable when verifyReferencePart == false
|
||||
bool verifyReferencePart;
|
||||
|
||||
|
||||
public Tracing() {}
|
||||
|
||||
@@ -138,18 +118,6 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
.ExposeConfiguration(SharedDatabase.TracingDB.BuildSchema)
|
||||
.BuildSessionFactory();
|
||||
|
||||
///
|
||||
/// Session factory 2 is used to create the 2nd database sessions
|
||||
///
|
||||
if (!string.IsNullOrEmpty(tracingCfg.ConnStr2))
|
||||
{
|
||||
sessionFactory2 = FluentNHibernate.Cfg.Fluently.Configure()
|
||||
.Database(FluentNHibernate.Cfg.Db.MySQLConfiguration.Standard.ConnectionString(tracingCfg.ConnStr2))
|
||||
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Process>())
|
||||
.ExposeConfiguration(SharedDatabase.TracingDB.BuildSchema)
|
||||
.BuildSessionFactory();
|
||||
}
|
||||
|
||||
ISession session = SessionFactory.OpenSession();
|
||||
|
||||
///
|
||||
@@ -177,8 +145,6 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
session.Close();
|
||||
SharedDatabase.TracingDB.SessionFactory = SessionFactory;
|
||||
if (session != null) session.Dispose();
|
||||
|
||||
currentWorkflow = null;
|
||||
}
|
||||
///
|
||||
string GetIPAddress()
|
||||
@@ -225,7 +191,7 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
}
|
||||
}
|
||||
|
||||
public OrderInfo ReReadOneOrder(OrderInfo order, ISession session = null)
|
||||
public OrderInfo ReReadOneOrder(string poName, ISession session = null)
|
||||
{
|
||||
bool openAndCloseSession = (session == null) || !session.IsOpen;
|
||||
|
||||
@@ -234,7 +200,7 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
if (openAndCloseSession) session = SessionFactory.OpenSession();
|
||||
|
||||
var list = session.QueryOver<OrderInfo>()
|
||||
.Where(x => (x.Id == order.Id))
|
||||
.Where(x => (x.POName == poName))
|
||||
.List();
|
||||
|
||||
if (openAndCloseSession) session.Close();
|
||||
@@ -243,14 +209,15 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
log.ErrorFormat("Cannot read orders from the tracing DB: {0}", exc.Message);
|
||||
log.ErrorFormat("Cannot re-read order {0} from the tracing DB: {1}", poName, exc.Message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Read reference records belonging to a specified order
|
||||
/// Read reference records belonging to a specified order.
|
||||
/// Used when retrieving housing S/N-s belonging to obtained eRegister numbers.
|
||||
/// </summary>
|
||||
/// <param name="session">DB sesson</param>
|
||||
/// <param name="order">Order</param>
|
||||
@@ -469,7 +436,7 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
|
||||
Retv CheckPreviousRecordOfSingleWM(ISession session, Results.Entities.WaterMeter wm)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(wm.SerialNr))
|
||||
if (!string.IsNullOrEmpty(wm.SerialNr) && ProcessData.WorkflowSummary != null)
|
||||
{
|
||||
/// Get all reference records with Code == SerialNr from all worksteps different from 'Test_bench'
|
||||
var refRecords = session.QueryOver<ReferenceRecord>()
|
||||
@@ -479,13 +446,15 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
if (refRecords.Count == 1)
|
||||
{
|
||||
ReferenceRecord refRecord = refRecords[0];
|
||||
StepRecord previousStep = refRecord.StepRecords.FirstOrDefault(x => x.Workstep == ProcessData.PreviousStepName);
|
||||
StepRecord previousStep = string.IsNullOrEmpty(ProcessData.WorkflowSummary.PreviousWorkstepName) ? null
|
||||
: refRecord.StepRecords.FirstOrDefault(x => x.Workstep == ProcessData.WorkflowSummary.PreviousWorkstepName);
|
||||
|
||||
if (refRecord.Name1 == ProcessData.Part1Name &&
|
||||
refRecord.Name2 == ProcessData.Part2Name &&
|
||||
(ProcessData.PreviousStepName == null || (previousStep != null && previousStep.Workstep == ProcessData.PreviousStepName)))
|
||||
if (refRecord.Name1 == ProcessData.WorkflowSummary.Part1Name &&
|
||||
refRecord.Name2 == ProcessData.WorkflowSummary.Part2Name &&
|
||||
(ProcessData.WorkflowSummary.PreviousWorkstepName == null ||
|
||||
(previousStep != null && previousStep.Workstep == ProcessData.WorkflowSummary.PreviousWorkstepName)))
|
||||
{
|
||||
wm.ProcessId = 0;
|
||||
wm.Workflow = ProcessData.WorkflowSummary.Workflow.Name;
|
||||
wm.LastRecordIsNok = false; /// OK
|
||||
return Retv.OK;
|
||||
}
|
||||
@@ -493,7 +462,7 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
}
|
||||
|
||||
/// S/N is missing OR no records found OR workflows do not match OR previous StepRecord is missing
|
||||
wm.ProcessId = 0;
|
||||
wm.Workflow = string.Empty;
|
||||
wm.LastRecordIsNok = true; /// NOK
|
||||
return Retv.OK;
|
||||
}
|
||||
@@ -510,7 +479,7 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
ISession session = null;
|
||||
|
||||
var order = ProcessData.OrderInfo as SharedDatabase.Entities.OrderInfo;
|
||||
if (order != null)
|
||||
if (order != null && ProcessData.WorkflowSummary != null && !string.IsNullOrEmpty(ProcessData.WorkflowSummary.WorkstepName))
|
||||
{
|
||||
///
|
||||
/// Save to regular tracing DB
|
||||
@@ -521,7 +490,7 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
transaction = session.BeginTransaction();
|
||||
|
||||
var reloadedOrder = session.QueryOver<OrderInfo>()
|
||||
.Where(x => x.Id == order.Id)
|
||||
.Where(x => x.POName == order.POName)
|
||||
.List();
|
||||
if (reloadedOrder.Count == 1)
|
||||
{
|
||||
@@ -541,23 +510,20 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
log.ErrorFormat("Unexpected reloadedOrder.Count == {0} in SaveTracingRecords()", reloadedOrder.Count);
|
||||
}
|
||||
|
||||
string workplace = (ProcessData.BenchInfo != null) ? ProcessData.BenchInfo.TestBenchName : "TestBench";
|
||||
int writtenRecordsCount = 0;
|
||||
if (ProcessData.Workflow != null && ProcessData.Workstep != null)
|
||||
foreach (var wm in batch.WaterMeters)
|
||||
{
|
||||
foreach (var wMtr in batch.WaterMeters)
|
||||
if (!wm.Disabled && !string.IsNullOrEmpty(wm.SerialNr))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(wMtr.SerialNr))
|
||||
{
|
||||
SaveSingleWM2DB(session, order, wMtr, ProcessData.Workflow, ProcessData.Workstep);
|
||||
writtenRecordsCount++;
|
||||
}
|
||||
writtenRecordsCount += SaveSingleWM2DB(session, wm, order.POName, ProcessData.WorkflowSummary, workplace);
|
||||
}
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
session.Flush();
|
||||
|
||||
log.ErrorFormat("Batch {0}: {1} of {2} watermeters written to the regular production tracing DB",
|
||||
log.WarnFormat("Batch {0}: {1} of {2} watermeters written to the regular production tracing DB",
|
||||
batch.BatchNr, writtenRecordsCount, batch.WaterMeters.Count);
|
||||
}
|
||||
catch (Exception exc)
|
||||
@@ -587,45 +553,55 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
/// </summary>
|
||||
/// <param name="session">DB session</param>
|
||||
/// <param name="wm">Watermeter entity</param>
|
||||
void SaveSingleWM2DB(ISession session, OrderInfo order, Results.Entities.WaterMeter wm, Process workflow, Workstep workstep)
|
||||
int SaveSingleWM2DB(ISession session, Results.Entities.WaterMeter wm, string poName, WorkflowSummary wflowSummary, string worplace)
|
||||
{
|
||||
if (string.IsNullOrEmpty(wflowSummary.WorkstepName)) return 0;
|
||||
|
||||
IList<ReferenceRecord> existingRecords = session.QueryOver<ReferenceRecord>()
|
||||
.Where(x => (x.Code1 == wm.SerialNr))
|
||||
.List();
|
||||
ReferenceRecord refRecord = null;
|
||||
if (existingRecords.Count > 1)
|
||||
{
|
||||
/// Unexpected error
|
||||
throw new Exception("Unexpected error when saving production tracing records");
|
||||
log.ErrorFormat("Multiple reference records exist: Code1 = {0}", wm.SerialNr);
|
||||
return 0;
|
||||
}
|
||||
else if (existingRecords.Count == 1)
|
||||
|
||||
///
|
||||
/// Reference record
|
||||
///
|
||||
ReferenceRecord refRecord = null;
|
||||
if (existingRecords.Count == 1)
|
||||
{
|
||||
/// TODO: Check if the selected worflow is the same as in the found record
|
||||
refRecord = existingRecords[0];
|
||||
|
||||
refRecord.POName = (order != null) ? order.POName : null;
|
||||
refRecord.Workflow = (workflow != null) ? workflow.Name : null;
|
||||
refRecord.POName = poName;
|
||||
refRecord.Workflow = wflowSummary.Workflow.Name;
|
||||
refRecord.Code2 = wm.SerialNrAux;
|
||||
refRecord.Code3 = wm.CompleteSerialNr;
|
||||
refRecord.Code4 = wm.RadioAddress;
|
||||
}
|
||||
else
|
||||
{
|
||||
refRecord = new ReferenceRecord((order != null) ? order.POName : null,
|
||||
(workflow != null) ? workflow.Name : null,
|
||||
ProcessData.Part1Name, /// PCB (iPERL) or housing (620/640) SAP number
|
||||
wm.SerialNr, /// PcbNumber (iPERL) or housing S/N (620/640)
|
||||
ProcessData.Part2Name, /// Flowtube SAP nummber (iPERL) or "eRegister#" (640) or empty
|
||||
wm.SerialNrAux, /// Flowtube S/N (iPERL) or eRegister number (640) or empty
|
||||
wm.CompleteSerialNr, /// Complete assigned S/N
|
||||
wm.RadioAddress); /// Radio address (iPERL and 640)
|
||||
refRecord = new ReferenceRecord(poName,
|
||||
wflowSummary.Workflow.Name,
|
||||
wflowSummary.Part1Name, /// PCB (iPERL) or housing (620/640) SAP number
|
||||
wm.SerialNr, /// PcbNumber (iPERL) or housing S/N (620/640)
|
||||
wflowSummary.Part2Name, /// Flowtube SAP nummber (iPERL) or "eRegister#" (640) or empty
|
||||
wm.SerialNrAux, /// Flowtube S/N (iPERL) or eRegister number (640) or empty
|
||||
wm.CompleteSerialNr, /// Complete assigned S/N
|
||||
wm.RadioAddress); /// Radio address (iPERL and 640)
|
||||
}
|
||||
|
||||
///
|
||||
/// Step record
|
||||
///
|
||||
StepRecord stepRecord = new StepRecord(refRecord,
|
||||
"Test",
|
||||
(TBF.Rig.Sequences.ProcessData.BenchInfo != null) ? TBF.Rig.Sequences.ProcessData.BenchInfo.TestBenchName : "TestBench",
|
||||
Common.GlobalData.GetCurrentUserName());
|
||||
|
||||
wflowSummary.WorkstepName,
|
||||
workplace,
|
||||
Common.GlobalData.GetCurrentUserName(),
|
||||
wm.PassedFromTests() ? 0 : 1);
|
||||
if (refRecord.StepRecords == null)
|
||||
{
|
||||
refRecord.StepRecords = new List<StepRecord> { stepRecord };
|
||||
@@ -637,6 +613,7 @@ namespace TBF.Rig.Output.DB.ProductionTracing
|
||||
|
||||
session.SaveOrUpdate(refRecord);
|
||||
session.SaveOrUpdate(stepRecord);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user