| | |
| | | namespace Yw.Server |
| | | using Yw.LCache.Medis; |
| | | using Yw.Service.Basic; |
| | | using Yw.Service.Monitor; |
| | | |
| | | namespace Yw.Server |
| | | { |
| | | /// <summary> |
| | | /// 工位运行分析单任务 |
| | |
| | | |
| | | #region 运行测点 |
| | | |
| | | var monitorList = allMonitorList.Where(x => x.SignalList.Exists(t => t.SignalType.Code == Yw.Monitor.SignalType.运行状态)).ToList(); |
| | | if (monitorList == null || monitorList.Count < 1) |
| | | var signal = allMonitorList.Matching(Yw.Monitor.SignalType.运行状态, new List<string>() { Yw.Run.Flags.默认 }); |
| | | if (signal == null) |
| | | { |
| | | signal = allMonitorList.Matching(Yw.Monitor.SignalType.运行状态, null); |
| | | } |
| | | if (signal == null) |
| | | { |
| | | LogHelper.Info($"工位运行分析单任务中,设备id:{configure.ObjectID} 检索运行状态测点失败!"); |
| | | return; |
| | | } |
| | | var monitor = monitorList.Find(x => x.Flags.Contains(Yw.Monitor.Flags.默认)); |
| | | if (monitor == null) |
| | | { |
| | | monitor = monitorList.First(); |
| | | } |
| | | var monitor = allMonitorList.Find(x => x.ID == signal.MonitorPointID); |
| | | |
| | | #endregion |
| | | |
| | | #region 连续缓存 |
| | | |
| | | var lastMonitorRecord = service_monitor_record.Value.GetLastRecord(monitor.SignalList.First().ID); |
| | | EMWSRunAnalyChangeTimesHelper.Set(configure.ID, configure.ChangeTimes, lastMonitorRecord); |
| | | var lastRecord = new Yw.Service.MonitorRealRecord().GetLastRecord(signal.ID); |
| | | EMWSRunAnalyChangeTimesHelper.Set(configure.ID, configure.ChangeTimes, monitor, lastRecord); |
| | | |
| | | #endregion |
| | | |
| | | #region 数据分析 |
| | | #region 运行分析 |
| | | |
| | | var run_record = new Yw.Model.RunRealRecord() |
| | | var runRecord = new Yw.Model.RunRealRecord() |
| | | { |
| | | ObjectType = configure.ObjectType, |
| | | ObjectID = configure.ObjectID, |
| | | DataTime = DateTime.Now, |
| | | RSa = Yw.Run.RunStatus.Stop, |
| | | ContinueRunTime = 0, |
| | | RSa = Yw.Run.RunStatus.Shut, |
| | | ContinueTime = 0, |
| | | TotalShutTime = 0, |
| | | TotalRunTime = 0, |
| | | BootTimes = 0, |
| | | AnalyStatus = Yw.Run.AnalyStatus.Normal, |
| | | AnalyInfo = null |
| | | }; |
| | | |
| | | var lastRunRecord = service_run_record.Value.GetLastRecord(configure.ObjectType, configure.ObjectID); |
| | | var lastRunRecord = new Yw.Service.RunRealRecord().GetLastRecord(configure.ObjectType, configure.ObjectID); |
| | | if (lastRunRecord == null) |
| | | { |
| | | run_record.AnalyInfo = "首次分析"; |
| | | if (lastMonitorRecord == null) |
| | | { |
| | | run_record.AnalyStatus = Yw.Run.AnalyStatus.Missing; |
| | | } |
| | | else |
| | | { |
| | | if (double.TryParse(lastMonitorRecord.DataValue, out double outDataValue)) |
| | | { |
| | | if (outDataValue > 0) |
| | | { |
| | | run_record.RSa = Yw.Run.RunStatus.Run; |
| | | run_record.ContinueRunTime += configure.Frequency; |
| | | run_record.TotalRunTime += configure.Frequency; |
| | | run_record.BootTimes += 1; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | run_record.AnalyStatus = Yw.Run.AnalyStatus.Abnormal; |
| | | } |
| | | } |
| | | runRecord.AnalyInfo = "首次分析"; |
| | | } |
| | | else |
| | | { |
| | | run_record.RSa = lastRunRecord.RSa; |
| | | run_record.ContinueRunTime = lastRunRecord.ContinueRunTime; |
| | | run_record.TotalRunTime = lastRunRecord.TotalRunTime; |
| | | run_record.BootTimes = lastRunRecord.BootTimes; |
| | | if (lastMonitorRecord == null) |
| | | runRecord.RSa = lastRunRecord.RSa; |
| | | runRecord.ContinueTime = lastRunRecord.ContinueTime; |
| | | runRecord.TotalShutTime = lastRunRecord.TotalShutTime; |
| | | runRecord.TotalRunTime = lastRunRecord.TotalRunTime; |
| | | runRecord.BootTimes = lastRunRecord.BootTimes; |
| | | } |
| | | |
| | | var rsa = Yw.Run.RunStatus.Shut; |
| | | if (lastRecord == null) |
| | | { |
| | | runRecord.AnalyStatus = Yw.Run.AnalyStatus.Missing; |
| | | } |
| | | else |
| | | { |
| | | if (Yw.Monitor.DataStatus.HasError(lastRecord.DataStatus)) |
| | | { |
| | | run_record.AnalyStatus = Yw.Run.AnalyStatus.Missing; |
| | | runRecord.AnalyStatus = Yw.Run.AnalyStatus.Abnormal; |
| | | } |
| | | else |
| | | var enable_interrupt = Yw.Run.SysParas.EnableMonitorInterruptJudgement.GetPValue<bool?>(); |
| | | if (enable_interrupt.HasValue && enable_interrupt.Value) |
| | | { |
| | | if (double.TryParse(lastMonitorRecord.DataValue, out double outDataValue)) |
| | | if (monitor.IsInterrupt(lastRecord)) |
| | | { |
| | | var run_status = outDataValue > 0 ? Yw.Run.RunStatus.Run : Yw.Run.RunStatus.Stop; |
| | | if (run_status != run_record.RSa) |
| | | { |
| | | if (EMWSRunAnalyChangeTimesHelper.HasChanged(configure.ID, configure.ChangeTimes)) |
| | | { |
| | | run_record.RSa = run_status; |
| | | if (run_status == Yw.Run.RunStatus.Run) |
| | | { |
| | | run_record.BootTimes += 1; |
| | | } |
| | | if (run_record.RSa == Yw.Run.RunStatus.Stop) |
| | | { |
| | | run_record.ContinueRunTime = 0; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | run_record.AnalyStatus = Yw.Run.AnalyStatus.Abnormal; |
| | | runRecord.AnalyStatus = Yw.Run.AnalyStatus.Interrupt; |
| | | } |
| | | } |
| | | if (run_record.RSa == Yw.Run.RunStatus.Run) |
| | | if (int.TryParse(lastRecord.DataValue, out int intDataValue)) |
| | | { |
| | | run_record.TotalRunTime += configure.Frequency; |
| | | run_record.ContinueRunTime += configure.Frequency; |
| | | rsa = intDataValue > Yw.Monitor.RunStatus.Shut ? Yw.Run.RunStatus.Run : Yw.Run.RunStatus.Shut; |
| | | } |
| | | } |
| | | |
| | | //发生改变 |
| | | if (runRecord.RSa != rsa) |
| | | { |
| | | if (EquipmentRunAnalyChangeTimesHelper.HasChanged(configure.ID, configure.ChangeTimes)) |
| | | { |
| | | runRecord.RSa = rsa; |
| | | runRecord.ContinueTime = 0; |
| | | if (runRecord.RSa == Yw.Run.RunStatus.Run) |
| | | { |
| | | runRecord.BootTimes += 1; |
| | | } |
| | | } |
| | | } |
| | | |
| | | //持续时间 |
| | | runRecord.ContinueTime += configure.Frequency; |
| | | |
| | | //总关机时间 |
| | | if (runRecord.RSa == Yw.Run.RunStatus.Shut) |
| | | { |
| | | runRecord.TotalShutTime += configure.Frequency; |
| | | } |
| | | |
| | | //总运行时间 |
| | | if (runRecord.RSa == Yw.Run.RunStatus.Run) |
| | | { |
| | | runRecord.TotalRunTime += configure.Frequency; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 数据存储 |
| | | |
| | | var bol = service_run_record.Value.InsertLastRecord(run_record); |
| | | var bol = service_run_record.Value.InsertLastRecord(runRecord); |
| | | if (bol) |
| | | { |
| | | LogHelper.Info($"工位运行分析单任务中,工位名称:{currentWorkSite.Name},工位id:{currentWorkSite.ID}, 运行记录分析成功!"); |