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.
 
 

262 lines
9.2 KiB

  1. using DataVAPI.Model;
  2. using DataVAPI.ModelDataBus;
  3. using DataVAPI.ServerDB.MongoDB;
  4. using DataVAPI.Tool.IOT;
  5. using Microsoft.AspNetCore.Mvc;
  6. using System;
  7. using System.Collections.Generic;
  8. namespace DataVAPI.Controllers
  9. {
  10. /// <summary>
  11. /// MG数据库:告警表 AlarmTable
  12. /// </summary>
  13. public class AlarmController : BaseController
  14. {
  15. MongoDbHelper<AlarmTable> mg = new MongoDbHelper<AlarmTable>(DataBus.connStr, DataBus.dbName);
  16. MongoDbHelper<DeviceTable> mgsb = new MongoDbHelper<DeviceTable>(DataBus.connStr, DataBus.dbName);
  17. string st = System.Reflection.MethodBase.GetCurrentMethod().Name;
  18. /// <summary>
  19. /// 新增一条数据
  20. /// </summary>
  21. [HttpPost]
  22. public JsonMsg<AlarmTable> Create(AlarmTable auth)
  23. {
  24. st = System.Reflection.MethodBase.GetCurrentMethod().Name;
  25. try
  26. {
  27. if (string.IsNullOrEmpty(auth.ClientId))
  28. {
  29. return JsonMsg<AlarmTable>.Error(null, st, "设备ID不能为空"); ;
  30. }
  31. mg.Insert(auth);
  32. return JsonMsg<AlarmTable>.OK(auth, st);
  33. }
  34. catch (Exception ex)
  35. {
  36. return JsonMsg<AlarmTable>.Error(null, st, ex.Message);
  37. }
  38. }
  39. /// <summary>
  40. /// 批量新增一条数据
  41. /// </summary>
  42. /// <param name="auth">告警消息</param>
  43. [HttpPost]
  44. public JsonMsg<List<AlarmTable>> Creates(List<AlarmTable> auth)
  45. {
  46. st = System.Reflection.MethodBase.GetCurrentMethod().Name;
  47. try
  48. {
  49. mg.Inserts(auth);
  50. return JsonMsg<List<AlarmTable>>.OK(auth, st);
  51. }
  52. catch (Exception ex)
  53. {
  54. return JsonMsg<List<AlarmTable>>.Error(null, st, ex.Message);
  55. }
  56. }
  57. /// <summary>
  58. /// 修改数据
  59. /// </summary>
  60. /// <param name="auth"></param>
  61. /// <returns></returns>
  62. [HttpPost]
  63. public JsonMsg<AlarmTable> Modify(AlarmTable auth)
  64. {
  65. st = System.Reflection.MethodBase.GetCurrentMethod().Name;
  66. try
  67. {
  68. mg.UpdateID(auth);
  69. return JsonMsg<AlarmTable>.OK(auth, st);
  70. }
  71. catch (Exception ex)
  72. {
  73. return JsonMsg<AlarmTable>.Error(null, st, ex.Message);
  74. }
  75. }
  76. /// <summary>
  77. /// 根据唯一ID查询数据
  78. /// </summary>
  79. /// <param name="id"></param>
  80. /// <returns></returns>
  81. [HttpGet]
  82. public JsonMsg<AlarmTable> QueryOne(string id)
  83. {
  84. st = System.Reflection.MethodBase.GetCurrentMethod().Name;
  85. try
  86. {
  87. return JsonMsg<AlarmTable>.OK(mg.QueryOne(id), st);
  88. }
  89. catch (Exception ex)
  90. {
  91. return JsonMsg<AlarmTable>.Error(null, st, ex.Message);
  92. }
  93. }
  94. /// <summary>
  95. /// 根据客户端ID查询当日未处理信息
  96. /// </summary>
  97. /// <param name="clientId"></param>
  98. /// <returns></returns>
  99. [HttpGet]
  100. public JsonMsg<List<AlarmTable>> QueryClientId(string clientId)
  101. {
  102. st = System.Reflection.MethodBase.GetCurrentMethod().Name;
  103. try
  104. {
  105. return JsonMsg<List<AlarmTable>>.OK(mg.QueryClientId(clientId), st);
  106. }
  107. catch (Exception ex)
  108. {
  109. return JsonMsg<List<AlarmTable>>.Error(null, st, ex.Message);
  110. }
  111. }
  112. /// <summary>
  113. /// 根据设备ID查询当日未处理信息
  114. /// </summary>
  115. /// <param name="clientId"></param>
  116. /// <returns></returns>
  117. [HttpGet]
  118. public JsonMsg<List<AlarmTable>> QueryDeviceId(string clientId, string deviceId)
  119. {
  120. st = System.Reflection.MethodBase.GetCurrentMethod().Name;
  121. try
  122. {
  123. if (string.IsNullOrEmpty(clientId))
  124. return JsonMsg<List<AlarmTable>>.Error(null, st, "客户端ID不能为空"); ;
  125. return JsonMsg<List<AlarmTable>>.OK(mg.QueryDeviceId(clientId, deviceId), st);
  126. }
  127. catch (Exception ex)
  128. {
  129. return JsonMsg<List<AlarmTable>>.Error(null, st, ex.Message);
  130. }
  131. }
  132. /// <summary>
  133. /// 根据设备名称、时间查询未处理信息
  134. /// </summary>
  135. /// <param name="clientId"></param>
  136. /// <returns></returns>
  137. [HttpGet]
  138. public JsonMsg<List<AlarmTable>> QueryDeviceName(string DeviceName, string StartTime, string StopTime)
  139. {
  140. st = System.Reflection.MethodBase.GetCurrentMethod().Name;
  141. try
  142. {
  143. DeviceTable device = mgsb.QueryDeviceName(DeviceName);
  144. if (device != null)
  145. {
  146. if (!string.IsNullOrEmpty(StartTime) && !string.IsNullOrEmpty(StopTime))
  147. {
  148. DateTime starttime, stoptime;
  149. starttime = Tools.ConvertLongToDateTime(long.Parse(StartTime));
  150. stoptime = Tools.ConvertLongToDateTime(long.Parse(StopTime));
  151. return JsonMsg<List<AlarmTable>>.OK(mg.QueryAllTime(device.ClientId, device.DeviceId, starttime, stoptime), st);
  152. }
  153. else return JsonMsg<List<AlarmTable>>.OK(mg.QueryDeviceId(device.ClientId,device.DeviceId), st);
  154. }
  155. return JsonMsg<List<AlarmTable>>.OK(null, st);
  156. }
  157. catch (Exception ex)
  158. {
  159. return JsonMsg<List<AlarmTable>>.Error(null, st, ex.Message);
  160. }
  161. }
  162. /// <summary>
  163. /// 根据客户端ID、设备ID、时间查询告警信息
  164. /// </summary>
  165. /// <param name="clientId">客户端ID</param>
  166. /// <param name="deviceId">设备ID</param>
  167. /// <param name="starttime">开始时间</param>
  168. /// <param name="endtime">结束时间</param>
  169. /// <returns></returns>
  170. [HttpGet]
  171. public JsonMsg<List<AlarmTable>> Query(string clientId, string deviceId, DateTime starttime, DateTime endtime)
  172. {
  173. st = System.Reflection.MethodBase.GetCurrentMethod().Name;
  174. try
  175. {
  176. return JsonMsg<List<AlarmTable>>.OK(mg.QueryAllTime(clientId, deviceId, starttime, endtime), st);
  177. }
  178. catch (Exception ex)
  179. {
  180. return JsonMsg<List<AlarmTable>>.Error(null, st, ex.Message);
  181. }
  182. }
  183. /// <summary>
  184. /// 分页查询
  185. /// </summary>
  186. /// <param name="clientId">客户端ID</param>
  187. /// <param name="datesta">开始时间</param>
  188. /// <param name="datastop">结束时间</param>
  189. /// <param name="PageNumber">页</param>
  190. /// <param name="PageSize">大小</param>
  191. /// <returns></returns>
  192. [HttpGet]
  193. public JsonMsg<PaginationListModel<AlarmTable>> BasePagQuery(string clientId, string deviceId, DateTime datesta, DateTime datastop, int PageNumber = 1, int PageSize = 100)
  194. {
  195. st = System.Reflection.MethodBase.GetCurrentMethod().Name;
  196. try
  197. {
  198. return JsonMsg<PaginationListModel<AlarmTable>>.OK(mg.BasePagQuery(clientId, deviceId, datesta, datastop, PageNumber, PageSize), st);
  199. }
  200. catch (Exception ex)
  201. {
  202. return JsonMsg<PaginationListModel<AlarmTable>>.Error(null, st, ex.Message);
  203. }
  204. }
  205. /// <summary>
  206. /// 删除数据(假删除-只做标记)
  207. /// </summary>
  208. /// <param name="id"></param>
  209. /// <returns></returns>
  210. [HttpGet]
  211. public JsonMsg<string> Delete(string id)
  212. {
  213. st = System.Reflection.MethodBase.GetCurrentMethod().Name;
  214. try
  215. {
  216. if (string.IsNullOrEmpty(id))
  217. {
  218. return JsonMsg<string>.Error(null, st, "设备ID不能为空"); ;
  219. }
  220. else
  221. {
  222. mg.Modify(id, "State", "n");
  223. return JsonMsg<string>.OK("success!", st);
  224. }
  225. }
  226. catch (Exception ex)
  227. {
  228. return JsonMsg<string>.Error(null, st, ex.Message);
  229. }
  230. }
  231. /// <summary>
  232. /// 删除数据
  233. /// </summary>
  234. /// <param name="id"></param>
  235. /// <returns></returns>
  236. [HttpGet]
  237. public JsonMsg<string> DeleteDate(string id)
  238. {
  239. st = System.Reflection.MethodBase.GetCurrentMethod().Name;
  240. try
  241. {
  242. if (string.IsNullOrEmpty(id))
  243. {
  244. return JsonMsg<string>.Error(null, st, "设备ID不能为空"); ;
  245. }
  246. else
  247. {
  248. mg.Delete(id);
  249. return JsonMsg<string>.OK("success!", st);
  250. }
  251. }
  252. catch (Exception ex)
  253. {
  254. return JsonMsg<string>.Error(null, st, ex.Message);
  255. }
  256. }
  257. }
  258. }