终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

142 lines
5.0 KiB

  1. using System;
  2. using System.Collections.Concurrent;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace BPASmartClient.Device
  8. {
  9. public class DeviceStatus
  10. {
  11. //字典值
  12. public Dictionary<string, string> keyValues = new Dictionary<string, string>()
  13. {
  14. {"PLC","煮面机机器人" },
  15. {"Lebai","乐白机器人" },
  16. {"SCChip","单片机" },
  17. {"DRCoffee","咖博士咖啡机器" },
  18. {"KLMCoffee","伽乐美咖啡机器" },
  19. {"GSIceCream","乐白机器人" },
  20. {"IsConnected","连接状态" },
  21. {"IsWork","工作状态" },
  22. {"CompletedOpen_SE_1","舵机1打开" },
  23. {"CompletedOpen_SE_2","舵机2打开" },
  24. {"CompletedOpen_SE_3","舵机3打开" },
  25. {"CompletedClose_SE_1","舵机1关闭" },
  26. {"CompletedClose_SE_2","舵机2关闭" },
  27. {"CompletedClose_SE_3","舵机3关闭" },
  28. {"False","异常" },
  29. {"True","正常" },
  30. {"Status","状态" },
  31. {"AppStatus","应用状态" },
  32. {"Warning","告警" },
  33. {"Fault","故障" },
  34. {"drinkType","饮品类型" },
  35. {"taskIndex","任务序号" },
  36. {"Keep","维修保护" },
  37. {"progress","工作进度" }
  38. };
  39. public ConcurrentDictionary<string, object> status = new ConcurrentDictionary<string, object>();
  40. public void Update(string key, object value)
  41. {
  42. status.AddOrUpdate(key, value, (key, value) => value);
  43. }
  44. public Dictionary<string, object> GetStatus()
  45. {
  46. return status.ToDictionary(x => x.Key, x => x.Value);
  47. }
  48. public object GetIOTStatus()
  49. {
  50. List<DevStatus> StatusALL = new List<DevStatus>();
  51. foreach (var item in status)
  52. {
  53. string sta = string.Empty;
  54. string name = item.Key;
  55. string Ms = string.Empty;
  56. string id = string.Empty;
  57. if (item.Key.Contains("."))
  58. {
  59. sta = item.Key.Split('.')[0];
  60. string sop = item.Key.Split('.')[item.Key.Split('.').Length - 1]; name = sop;
  61. string value = item.Value?.ToString();
  62. if (keyValues.ContainsKey(sta)) sta = keyValues[sta];
  63. if (keyValues.ContainsKey(sop)) sop = keyValues[sop];
  64. if (keyValues.ContainsKey(value)) value = keyValues[value];
  65. Ms = $"[{sta}]-[{sop}]-[{value}]";
  66. id = $"[{sta}]-[{sop}]";
  67. }
  68. StatusALL.Add(new DevStatus { id = id, Name = name, type = sta, Status = item.Value.ToString(), Ms = Ms });
  69. }
  70. StatusALL = StatusALL?.OrderBy(x => x.type).ToList();
  71. return new { data = StatusALL };
  72. }
  73. public List<DevStatus> GetStatusT()
  74. {
  75. List<DevStatus> StatusALL = new List<DevStatus>();
  76. foreach (var item in status)
  77. {
  78. string name = item.Key;
  79. string Ms = string.Empty;
  80. string id = string.Empty;
  81. string sta = string.Empty;
  82. if (item.Key.Contains("."))
  83. {
  84. sta = item.Key.Split('.')[0];
  85. string sop = item.Key.Split('.')[item.Key.Split('.').Length - 1]; name = sop;
  86. string value = item.Value?.ToString();
  87. if (keyValues.ContainsKey(sta)) sta = keyValues[sta];
  88. if (keyValues.ContainsKey(sop)) sop = keyValues[sop];
  89. if (keyValues.ContainsKey(value)) value = keyValues[value];
  90. Ms = $"[{sta}]-[{sop}]-[{value}]";
  91. id = $"[{sta}]-[{sop}]";
  92. }
  93. StatusALL.Add(new DevStatus { id = id, Name = name, type = sta, Status = item.Value.ToString(), Ms = Ms });
  94. }
  95. StatusALL = StatusALL?.OrderBy(x => x.type).ToList();
  96. return StatusALL;
  97. }
  98. }
  99. public class DevStatus
  100. {
  101. public string type { get; set; }
  102. public string id { get; set; }
  103. public string Name { get; set; }
  104. private string _status { get; set; }
  105. public string Status
  106. {
  107. get { return _status; }
  108. set
  109. {
  110. _status = value;
  111. if (_status == "False" || _status == "True")
  112. {
  113. if (_status == "True")
  114. StatusColor = new { r = 51, g = 232, b = 34, a = 1 };
  115. else
  116. StatusColor = new { r = 255, g = 0, b = 0, a = 1 };
  117. }
  118. }
  119. }
  120. public string Ms { get; set; }
  121. public object StatusColor { get; set; }
  122. public DevStatus()
  123. {
  124. StatusColor = new { r = 51, g = 232, b = 34, a = 1 };
  125. }
  126. }
  127. }