ProductionLineFaultViewModel.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace ProductionLineMonitor.Web.Services.LineService
  5. {
  6. public class LineDayFaultRecord
  7. {
  8. /// <summary>
  9. /// 设备类型
  10. /// </summary>
  11. public string MechineName { get; set; }
  12. /// <summary>
  13. /// 开始时间
  14. /// </summary>
  15. public DateTime StartTime { get; set; }
  16. /// <summary>
  17. /// 结束时间
  18. /// </summary>
  19. public DateTime? EndTime { get; set; }
  20. /// <summary>
  21. /// 故障码
  22. /// </summary>
  23. public string FaultCode { get; set; }
  24. /// <summary>
  25. /// 故障详情
  26. /// </summary>
  27. public string FaultInfo { get; set; }
  28. /// <summary>
  29. /// 持续时间
  30. /// </summary>
  31. public double Duration { get; set; }
  32. /// <summary>
  33. /// 数据源 0: 系统自动抓取 1:人工录入
  34. /// </summary>
  35. public int DataSource { get; set; }
  36. }
  37. public class ProductionLineFaultViewModel : ProductionLineViewModel
  38. {
  39. public ProductionLineFaultViewModel(int floor, int line, string date, string[] topics)
  40. {
  41. Floor = floor;
  42. Line = line;
  43. Date = date;
  44. KeyInInfos = MesApiService.GetKeyInInfos(floor, line, date);
  45. foreach (var key in KeyInInfos)
  46. {
  47. if (key.KeyInType == 2 || key.KeyInType == 3 || key.KeyInType == 4 ||
  48. key.KeyInType == 6 || key.KeyInType == 7 || key.KeyInType == 9 ||
  49. key.KeyInType == 0)
  50. LineDayFaultRecords.Add(new LineDayFaultRecord
  51. {
  52. FaultCode = key.KeyInType.ToString(),
  53. FaultInfo = key.Description,
  54. EndTime = key.EndTime,
  55. MechineName = "Line",
  56. StartTime = key.StartTime.Value,
  57. Duration = key.AffectTime
  58. });
  59. }
  60. // string[] topics = Global.App.ProductionLines.Find(x => x.Floor == floor && x.Line == line)?.Topics;
  61. foreach (var topic in topics)
  62. {
  63. MachineFaultViewModel model = new MachineFaultViewModel(topic, date);
  64. var faults = model.FaultRecords.Where(x => x.Duration >= 3 && !x.FaultInfo.Contains("安全门")).ToList();
  65. foreach (var fault in faults)
  66. {
  67. LineDayFaultRecords.Add(new LineDayFaultRecord
  68. {
  69. FaultCode = fault.FaultCode,
  70. FaultInfo = fault.FaultInfo,
  71. EndTime = fault.EndTime,
  72. MechineName = model.Type,
  73. StartTime = fault.StartTime,
  74. Duration = fault.Duration
  75. });
  76. }
  77. }
  78. LineDayFaultRecords = LineDayFaultRecords.OrderBy(x => x.StartTime).ToList();
  79. }
  80. public List<LineDayFaultRecord> LineDayFaultRecords { get; set; }
  81. = new List<LineDayFaultRecord>();
  82. }
  83. }