Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

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