選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

240 行
8.0 KiB

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