终端一体化运控平台
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

345 satır
9.4 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 Device1 { get; set; }
  71. /// <summary>
  72. /// 设备二状态
  73. /// </summary>
  74. public string Device2 { get; set; }
  75. /// <summary>
  76. /// 设备三状态
  77. /// </summary>
  78. public string Device3 { get; set; }
  79. /// <summary>
  80. /// 节点状态
  81. /// </summary>
  82. public string NodeStatus { get; set; }
  83. /// <summary>
  84. /// 维修保护
  85. /// </summary>
  86. public string Maintain { get; set; }
  87. ///// <summary>
  88. ///// 运行告警
  89. ///// </summary>
  90. //public string GJXX { get; set; }
  91. /// <summary>
  92. /// Model
  93. /// </summary>
  94. public IOTDevSXModel()
  95. {
  96. }
  97. /// <summary>
  98. /// 序列化为JSON
  99. /// </summary>
  100. /// <returns></returns>
  101. public string Tojson()
  102. {
  103. try
  104. {
  105. IotModel<IOTDevSXModel> iotModel = new IotModel<IOTDevSXModel> { @params = this };
  106. string json = Tools.JsonConvertTools(iotModel);
  107. return json;
  108. }
  109. catch (Exception ex)
  110. {
  111. return string.Empty;
  112. }
  113. }
  114. ///// <summary>
  115. ///// 设置基本属性
  116. ///// </summary>
  117. ///// <param name="devSX"></param>
  118. ///// <returns></returns>
  119. //public void SetJBSX(DevSX devSX)
  120. //{
  121. // try
  122. // {
  123. // JBSX = Tools.JsonConvertTools(devSX);
  124. // }
  125. // catch (Exception ex)
  126. // {
  127. // JBSX = string.Empty;
  128. // }
  129. //}
  130. ///// <summary>
  131. ///// 设置基本属性状态
  132. ///// </summary>
  133. ///// <param name="devSX"></param>
  134. ///// <returns></returns>
  135. //public void SetJBSXStatus(DevSXBase sXBase, bool Status)
  136. //{
  137. // try
  138. // {
  139. // if (sXBase == null) return;
  140. // DevSX dev = Tools.JsonToObjectTools<DevSX>(JBSX);
  141. // dev.data?.ForEach(x =>
  142. // {
  143. // if (x.SXMC == sXBase.SXMC && x.SXLX == sXBase.SXLX)
  144. // {
  145. // x.SXStatus = Status;
  146. // }
  147. // });
  148. // JBSX = Tools.JsonConvertTools(dev);
  149. // }
  150. // catch (Exception ex)
  151. // {
  152. // JBSX = string.Empty;
  153. // }
  154. //}
  155. ///// <summary>
  156. ///// 设置扩展属性
  157. ///// </summary>
  158. ///// <param name="devSX"></param>
  159. //public void SetKZSX(DevSX devSX)
  160. //{
  161. // try
  162. // {
  163. // KZSX = Tools.JsonConvertTools(devSX);
  164. // }
  165. // catch (Exception ex)
  166. // {
  167. // KZSX = string.Empty;
  168. // }
  169. //}
  170. ///// <summary>
  171. ///// 设置扩展属性状态
  172. ///// </summary>
  173. ///// <param name="devSX"></param>
  174. ///// <returns></returns>
  175. //public void SetKZSXStatus(DevSXBase sXBase, bool Status)
  176. //{
  177. // try
  178. // {
  179. // if (sXBase == null) return;
  180. // DevSX dev = Tools.JsonToObjectTools<DevSX>(KZSX);
  181. // dev.data?.ForEach(x =>
  182. // {
  183. // if (x.SXMC == sXBase.SXMC && x.SXLX == sXBase.SXLX)
  184. // {
  185. // x.SXStatus = Status;
  186. // }
  187. // });
  188. // KZSX = Tools.JsonConvertTools(dev);
  189. // }
  190. // catch (Exception ex)
  191. // {
  192. // KZSX = string.Empty;
  193. // }
  194. //}
  195. }
  196. /// <summary>
  197. /// 告警消息
  198. /// </summary>
  199. public class AlarmMessage
  200. {
  201. public List<AlarmModel> data { get; set; }
  202. }
  203. /// <summary>
  204. /// 告警Model
  205. /// </summary>
  206. public class AlarmModel : DeviceBase
  207. {
  208. /// <summary>
  209. /// 告警程度:提示 一般 严重
  210. /// </summary>
  211. public string AlarmCD
  212. {
  213. get { return _AlarmCD; }
  214. set
  215. {
  216. _AlarmCD = value;
  217. if (_AlarmCD == "提示") DeviceColor = new ALYColor { r = 13, g = 254, b = 73, a = 1 };
  218. else if (_AlarmCD == "一般") DeviceColor = new ALYColor { r = 245, g = 216, b = 13, a = 1 };
  219. else if (_AlarmCD == "严重") DeviceColor = new ALYColor { r = 245, g = 13, b = 13, a = 1 };
  220. }
  221. }
  222. private string _AlarmCD { get; set; }
  223. /// <summary>
  224. /// 颜色
  225. /// </summary>
  226. public ALYColor DeviceColor { get; set; }
  227. }
  228. /// <summary>
  229. /// 设备上报属性
  230. /// </summary>
  231. public class DevSX
  232. {
  233. public List<DevSXBase> data { get; set; }
  234. }
  235. /// <summary>
  236. /// 设备基本属性Model
  237. /// </summary>
  238. public class DevSXBase
  239. {
  240. /// <summary>
  241. /// 属性名称
  242. /// </summary>
  243. public string SXMC { get; set; }
  244. /// <summary>
  245. /// 属性类型
  246. /// </summary>
  247. public string SXLX { get; set; }
  248. /// <summary>
  249. /// 属性状态
  250. /// </summary>
  251. private bool _SXStatus { get; set; }
  252. public bool SXStatus
  253. {
  254. get { return _SXStatus; }
  255. set
  256. {
  257. _SXStatus = value;
  258. if (_SXStatus)
  259. {
  260. SXZT = "正常";
  261. }
  262. else
  263. {
  264. SXZT = "异常";
  265. }
  266. }
  267. }
  268. private string _SXZT { get; set; }
  269. /// <summary>
  270. /// 属性状态:正常 异常
  271. /// </summary>
  272. public string SXZT
  273. {
  274. get { return _SXZT; }
  275. set
  276. {
  277. _SXZT = value;
  278. if (_SXZT == "正常")
  279. {
  280. SXYC = new ALYColor { r = 13, g = 254, b = 73, a = 1 };//绿色
  281. SXYCMS = "";
  282. YCZT = "";
  283. ButtonText = "";
  284. ButtonYC = new ALYColor { r = 0, g = 0, b = 0, a = 0 };
  285. }
  286. else if (_SXZT == "异常")
  287. {
  288. SXYC = new ALYColor { r = 245, g = 13, b = 13, a = 1 };//红色
  289. ButtonText = "详情";
  290. ButtonYC = new ALYColor { r = 48, g = 109, b = 201, a = 0.18 };
  291. }
  292. }
  293. }
  294. /// <summary>
  295. /// 属性异常描述
  296. /// </summary>
  297. public string SXYCMS { get; set; }
  298. public string YCZT { get; set; }
  299. /// <summary>
  300. /// 属性颜色
  301. /// </summary>
  302. public ALYColor SXYC { get; set; }
  303. /// <summary>
  304. /// 按钮文字
  305. /// </summary>
  306. public string ButtonText { get; set; }
  307. /// <summary>
  308. /// 按钮颜色
  309. /// </summary>
  310. public ALYColor ButtonYC { get; set; }
  311. public DevSXBase()
  312. {
  313. SXZT = "";
  314. SXYC = new ALYColor { r = 13, g = 254, b = 73, a = 1 };//绿色
  315. SXYCMS = "";
  316. YCZT = "";
  317. ButtonText = "";
  318. ButtonYC = new ALYColor { r = 0, g = 0, b = 0, a = 0 };
  319. }
  320. }
  321. /// <summary>
  322. /// 设备颜色
  323. /// </summary>
  324. public class ALYColor
  325. {
  326. public int r { get; set; }
  327. public int g { get; set; }
  328. public int b { get; set; }
  329. public double a { get; set; }
  330. }
  331. /// <summary>
  332. /// 变量
  333. /// </summary>
  334. public class Vls
  335. {
  336. public long time { get; set; }
  337. public string value { get; set; }
  338. }
  339. }