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

346 lines
9.4 KiB

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