终端一体化运控平台
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.
 
 
 

137 lines
4.7 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 name = item.Key;
  54. string Ms = string.Empty;
  55. string id = string.Empty;
  56. if (item.Key.Contains("."))
  57. {
  58. string sta = item.Key.Split('.')[0];
  59. string sop = item.Key.Split('.')[item.Key.Split('.').Length - 1]; name = sop;
  60. string value = item.Value.ToString();
  61. if (keyValues.ContainsKey(sta)) sta = keyValues[sta];
  62. if (keyValues.ContainsKey(sop)) sop = keyValues[sop];
  63. if (keyValues.ContainsKey(value)) value = keyValues[value];
  64. Ms = $"[{sta}]-[{sop}]-[{value}]";
  65. id = $"[{sta}]-[{sop}]";
  66. }
  67. StatusALL.Add(new DevStatus { id = id, Name = name, Status = item.Value.ToString(), Ms = Ms });
  68. }
  69. return new { data = StatusALL };
  70. }
  71. public List<DevStatus> GetStatusT()
  72. {
  73. List<DevStatus> StatusALL = new List<DevStatus>();
  74. foreach (var item in status)
  75. {
  76. string name = item.Key;
  77. string Ms = string.Empty;
  78. string id=string.Empty;
  79. if (item.Key.Contains("."))
  80. {
  81. string sta = item.Key.Split('.')[0];
  82. string sop = item.Key.Split('.')[item.Key.Split('.').Length - 1]; name = sop;
  83. string value = item.Value.ToString();
  84. if (keyValues.ContainsKey(sta)) sta = keyValues[sta];
  85. if (keyValues.ContainsKey(sop)) sop = keyValues[sop];
  86. if (keyValues.ContainsKey(value)) value = keyValues[value];
  87. Ms = $"[{sta}]-[{sop}]-[{value}]";
  88. id= $"[{sta}]-[{sop}]";
  89. }
  90. StatusALL.Add(new DevStatus {id= id, Name = name, Status = item.Value.ToString(), Ms = Ms });
  91. }
  92. return StatusALL;
  93. }
  94. }
  95. public class DevStatus
  96. {
  97. public string id { get; set; }
  98. public string Name { get; set; }
  99. private string _status { get; set; }
  100. public string Status
  101. {
  102. get { return _status; }
  103. set
  104. {
  105. _status = value;
  106. if (_status == "False" || _status == "True")
  107. {
  108. if (_status == "True")
  109. StatusColor = new { r = 51, g = 232, b = 34, a = 1 };
  110. else
  111. StatusColor = new { r = 255, g = 0, b = 0, a = 1 };
  112. }
  113. }
  114. }
  115. public string Ms { get; set; }
  116. public object StatusColor { get; set; }
  117. public DevStatus()
  118. {
  119. StatusColor = new { r = 51, g = 232, b = 34, a = 1 };
  120. }
  121. }
  122. }