using System; using System.Collections.Generic; using System.Linq; namespace ProductionLineMonitor.Web.Services.LineService { public class LineDayFaultRecord { /// /// 设备类型 /// public string MechineName { get; set; } /// /// 开始时间 /// public DateTime StartTime { get; set; } /// /// 结束时间 /// public DateTime? EndTime { get; set; } /// /// 故障码 /// public string FaultCode { get; set; } /// /// 故障详情 /// public string FaultInfo { get; set; } /// /// 持续时间 /// public double Duration { get; set; } /// /// 数据源 0: 系统自动抓取 1:人工录入 /// public int DataSource { get; set; } } public class ProductionLineFaultViewModel : ProductionLineViewModel { public ProductionLineFaultViewModel(int floor, int line, string date, string[] topics) { Floor = floor; Line = line; Date = date; KeyInInfos = MesApiService.GetKeyInInfos(floor, line, date); foreach (var key in KeyInInfos) { if (key.KeyInType == 2 || key.KeyInType == 3 || key.KeyInType == 4 || key.KeyInType == 6 || key.KeyInType == 7 || key.KeyInType == 9 || key.KeyInType == 0) LineDayFaultRecords.Add(new LineDayFaultRecord { FaultCode = key.KeyInType.ToString(), FaultInfo = key.Description, EndTime = key.EndTime, MechineName = "Line", StartTime = key.StartTime.Value, Duration = key.AffectTime }); } // string[] topics = Global.App.ProductionLines.Find(x => x.Floor == floor && x.Line == line)?.Topics; foreach (var topic in topics) { MachineFaultViewModel model = new MachineFaultViewModel(topic, date); var faults = model.FaultRecords.Where(x => x.Duration >= 3 && !x.FaultInfo.Contains("安全门")).ToList(); foreach (var fault in faults) { LineDayFaultRecords.Add(new LineDayFaultRecord { FaultCode = fault.FaultCode, FaultInfo = fault.FaultInfo, EndTime = fault.EndTime, MechineName = model.Type, StartTime = fault.StartTime, Duration = fault.Duration }); } } LineDayFaultRecords = LineDayFaultRecords.OrderBy(x => x.StartTime).ToList(); } public List LineDayFaultRecords { get; set; } = new List(); } }