Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

337 linhas
9.0 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace DataVAPI.Tool.IOT
  7. {
  8. /// <summary>
  9. /// IOT Model
  10. /// </summary>
  11. public class IotModel<T>
  12. {
  13. public string id { get; set; } = Guid.NewGuid().ToString();
  14. public string version { get; set; } = "1.0";
  15. public T @params { get; set; }
  16. public string method { get; set; } = "thing.event.property.post";
  17. }
  18. /// <summary>
  19. /// IOT 接收数据Model
  20. /// </summary>
  21. public class ReceiveModel
  22. {
  23. /// <summary>
  24. /// 设备详细信息
  25. /// </summary>
  26. public DevBase deviceContext { get; set; }
  27. /// <summary>
  28. /// 设备属性
  29. /// </summary>
  30. public ReceiveSXModel props { get; set; }
  31. /// <summary>
  32. /// 设备上下线状态
  33. /// </summary>
  34. public Vls status { get; set; }
  35. }
  36. /// <summary>
  37. /// 接收数据Model
  38. /// </summary>
  39. public class ReceiveSXModel
  40. {
  41. /// <summary>
  42. /// 告警消息
  43. /// </summary>
  44. public Vls GJXX { get; set; }
  45. /// <summary>
  46. /// 扩展属性
  47. /// </summary>
  48. public Vls KZSX { get; set; }
  49. /// <summary>
  50. /// 基本属性
  51. /// </summary>
  52. public Vls JBSX { get; set; }
  53. /// <summary>
  54. /// 节点状态
  55. /// </summary>
  56. public Vls NodeStatus { get; set; }
  57. /// <summary>
  58. /// 日志消息
  59. /// </summary>
  60. public Vls SZXX { get; set; }
  61. }
  62. /// <summary>
  63. /// IOT 设备属性 Model
  64. /// </summary>
  65. public class IOTDevSXModel
  66. {
  67. /// <summary>
  68. /// 硬件状态
  69. /// </summary>
  70. public string HardwareStatus { get; set; }
  71. /// <summary>
  72. /// 扩展属性
  73. /// </summary>
  74. public string KZSX { get; set; }
  75. /// <summary>
  76. /// 基本属性
  77. /// </summary>
  78. public string JBSX { get; set; }
  79. /// <summary>
  80. /// 节点状态
  81. /// </summary>
  82. public string NodeStatus { get; set; }
  83. /// <summary>
  84. /// Model
  85. /// </summary>
  86. public IOTDevSXModel()
  87. {
  88. }
  89. /// <summary>
  90. /// 序列化为JSON
  91. /// </summary>
  92. /// <returns></returns>
  93. public string Tojson()
  94. {
  95. try
  96. {
  97. IotModel<IOTDevSXModel> iotModel = new IotModel<IOTDevSXModel> { @params = this };
  98. string json = Tools.JsonConvertTools(iotModel);
  99. return json;
  100. }
  101. catch (Exception ex)
  102. {
  103. return string.Empty;
  104. }
  105. }
  106. /// <summary>
  107. /// 设置基本属性
  108. /// </summary>
  109. /// <param name="devSX"></param>
  110. /// <returns></returns>
  111. public void SetJBSX(DevSX devSX)
  112. {
  113. try
  114. {
  115. JBSX = Tools.JsonConvertTools(devSX);
  116. }
  117. catch (Exception ex)
  118. {
  119. JBSX = string.Empty;
  120. }
  121. }
  122. /// <summary>
  123. /// 设置基本属性状态
  124. /// </summary>
  125. /// <param name="devSX"></param>
  126. /// <returns></returns>
  127. public void SetJBSXStatus(DevSXBase sXBase, bool Status)
  128. {
  129. try
  130. {
  131. if (sXBase == null) return;
  132. DevSX dev = Tools.JsonToObjectTools<DevSX>(JBSX);
  133. dev.data?.ForEach(x =>
  134. {
  135. if (x.SXMC == sXBase.SXMC && x.SXLX == sXBase.SXLX)
  136. {
  137. x.SXStatus = Status;
  138. }
  139. });
  140. JBSX = Tools.JsonConvertTools(dev);
  141. }
  142. catch (Exception ex)
  143. {
  144. JBSX = string.Empty;
  145. }
  146. }
  147. /// <summary>
  148. /// 设置扩展属性
  149. /// </summary>
  150. /// <param name="devSX"></param>
  151. public void SetKZSX(DevSX devSX)
  152. {
  153. try
  154. {
  155. KZSX = Tools.JsonConvertTools(devSX);
  156. }
  157. catch (Exception ex)
  158. {
  159. KZSX = string.Empty;
  160. }
  161. }
  162. /// <summary>
  163. /// 设置扩展属性状态
  164. /// </summary>
  165. /// <param name="devSX"></param>
  166. /// <returns></returns>
  167. public void SetKZSXStatus(DevSXBase sXBase, bool Status)
  168. {
  169. try
  170. {
  171. if (sXBase == null) return;
  172. DevSX dev = Tools.JsonToObjectTools<DevSX>(KZSX);
  173. dev.data?.ForEach(x =>
  174. {
  175. if (x.SXMC == sXBase.SXMC && x.SXLX == sXBase.SXLX)
  176. {
  177. x.SXStatus = Status;
  178. }
  179. });
  180. KZSX = Tools.JsonConvertTools(dev);
  181. }
  182. catch (Exception ex)
  183. {
  184. KZSX = string.Empty;
  185. }
  186. }
  187. }
  188. /// <summary>
  189. /// 告警消息
  190. /// </summary>
  191. public class AlarmMessage
  192. {
  193. public List<AlarmModel> data { get; set; }
  194. }
  195. /// <summary>
  196. /// 告警Model
  197. /// </summary>
  198. public class AlarmModel : DeviceBase
  199. {
  200. /// <summary>
  201. /// 告警程度:提示 一般 严重
  202. /// </summary>
  203. public string AlarmCD
  204. {
  205. get { return _AlarmCD; }
  206. set
  207. {
  208. _AlarmCD = value;
  209. if (_AlarmCD == "提示") DeviceColor = new ALYColor { r = 13, g = 254, b = 73, a = 1 };
  210. else if (_AlarmCD == "一般") DeviceColor = new ALYColor { r = 245, g = 216, b = 13, a = 1 };
  211. else if (_AlarmCD == "严重") DeviceColor = new ALYColor { r = 245, g = 13, b = 13, a = 1 };
  212. }
  213. }
  214. private string _AlarmCD { get; set; }
  215. /// <summary>
  216. /// 颜色
  217. /// </summary>
  218. public ALYColor DeviceColor { get; set; }
  219. }
  220. /// <summary>
  221. /// 设备上报属性
  222. /// </summary>
  223. public class DevSX
  224. {
  225. public List<DevSXBase> data { get; set; }
  226. }
  227. /// <summary>
  228. /// 设备基本属性Model
  229. /// </summary>
  230. public class DevSXBase
  231. {
  232. /// <summary>
  233. /// 属性名称
  234. /// </summary>
  235. public string SXMC { get; set; }
  236. /// <summary>
  237. /// 属性类型
  238. /// </summary>
  239. public string SXLX { get; set; }
  240. /// <summary>
  241. /// 属性状态
  242. /// </summary>
  243. private bool _SXStatus { get; set; }
  244. public bool SXStatus
  245. {
  246. get { return _SXStatus; }
  247. set
  248. {
  249. _SXStatus = value;
  250. if (_SXStatus)
  251. {
  252. SXZT = "正常";
  253. }
  254. else
  255. {
  256. SXZT = "异常";
  257. }
  258. }
  259. }
  260. private string _SXZT { get; set; }
  261. /// <summary>
  262. /// 属性状态:正常 异常
  263. /// </summary>
  264. public string SXZT
  265. {
  266. get { return _SXZT; }
  267. set
  268. {
  269. _SXZT = value;
  270. if (_SXZT == "正常")
  271. {
  272. SXYC = new ALYColor { r = 13, g = 254, b = 73, a = 1 };//绿色
  273. SXYCMS = "";
  274. YCZT = "";
  275. ButtonText = "";
  276. ButtonYC = new ALYColor { r = 0, g = 0, b = 0, a = 0 };
  277. }
  278. else if (_SXZT == "异常")
  279. {
  280. SXYC = new ALYColor { r = 245, g = 13, b = 13, a = 1 };//红色
  281. ButtonText = "详情";
  282. ButtonYC = new ALYColor { r = 48, g = 109, b = 201, a = 0.18 };
  283. }
  284. }
  285. }
  286. /// <summary>
  287. /// 属性异常描述
  288. /// </summary>
  289. public string SXYCMS { get; set; }
  290. public string YCZT { get; set; }
  291. /// <summary>
  292. /// 属性颜色
  293. /// </summary>
  294. public ALYColor SXYC { get; set; }
  295. /// <summary>
  296. /// 按钮文字
  297. /// </summary>
  298. public string ButtonText { get; set; }
  299. /// <summary>
  300. /// 按钮颜色
  301. /// </summary>
  302. public ALYColor ButtonYC { get; set; }
  303. public DevSXBase()
  304. {
  305. SXZT = "";
  306. SXYC = new ALYColor { r = 13, g = 254, b = 73, a = 1 };//绿色
  307. SXYCMS = "";
  308. YCZT = "";
  309. ButtonText = "";
  310. ButtonYC = new ALYColor { r = 0, g = 0, b = 0, a = 0 };
  311. }
  312. }
  313. /// <summary>
  314. /// 设备颜色
  315. /// </summary>
  316. public class ALYColor
  317. {
  318. public int r { get; set; }
  319. public int g { get; set; }
  320. public int b { get; set; }
  321. public double a { get; set; }
  322. }
  323. /// <summary>
  324. /// 变量
  325. /// </summary>
  326. public class Vls
  327. {
  328. public long time { get; set; }
  329. public string value { get; set; }
  330. }
  331. }