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.

LogController.cs 8.2 KiB

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