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.
 
 

221 lines
7.3 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. /// 分页查询
  130. /// </summary>
  131. /// <param name="clientId">客户端ID</param>
  132. /// <param name="starttime">开始时间</param>
  133. /// <param name="endtime">结束时间</param>
  134. /// <param name="PageNumber">页码</param>
  135. /// <param name="PageSize">每页大小</param>
  136. /// <returns></returns>
  137. [HttpGet]
  138. public JsonMsg<PaginationListModel<DeviceTable>> BasePagQuery(string clientId, string deviceId, DateTime starttime, DateTime endtime, int PageNumber = 1, int PageSize = 100)
  139. {
  140. st = System.Reflection.MethodBase.GetCurrentMethod().Name;
  141. try
  142. {
  143. return JsonMsg<PaginationListModel<DeviceTable>>.OK(mg.BasePagQuery(clientId, deviceId, starttime, endtime, PageNumber, PageSize), st);
  144. }
  145. catch (Exception ex)
  146. {
  147. return JsonMsg<PaginationListModel<DeviceTable>>.Error(null, st, ex.Message);
  148. }
  149. }
  150. /// <summary>
  151. /// 删除数据(假删除-只做标记)
  152. /// </summary>
  153. /// <param name="id">唯一id</param>
  154. [HttpGet]
  155. public JsonMsg<string> Delete(string id)
  156. {
  157. st = System.Reflection.MethodBase.GetCurrentMethod().Name;
  158. try
  159. {
  160. if (string.IsNullOrEmpty(id))
  161. {
  162. return JsonMsg<string>.Error(null, st, "设备ID不能为空"); ;
  163. }
  164. else
  165. {
  166. mg.Modify(id, "State", "n");
  167. return JsonMsg<string>.OK("success!", st);
  168. }
  169. }
  170. catch (Exception ex)
  171. {
  172. return JsonMsg<string>.Error(null, st, ex.Message);
  173. }
  174. }
  175. /// <summary>
  176. /// 删除数据
  177. /// </summary>
  178. /// <param name="id">唯一id</param>
  179. [HttpGet]
  180. public JsonMsg<string> DeleteDate(string id)
  181. {
  182. st = System.Reflection.MethodBase.GetCurrentMethod().Name;
  183. try
  184. {
  185. if (string.IsNullOrEmpty(id))
  186. {
  187. return JsonMsg<string>.Error(null, st, "设备ID不能为空"); ;
  188. }
  189. else
  190. {
  191. mg.Delete(id);
  192. return JsonMsg<string>.OK("success!", st);
  193. }
  194. }
  195. catch (Exception ex)
  196. {
  197. return JsonMsg<string>.Error(null, st, ex.Message);
  198. }
  199. }
  200. /// <summary>
  201. /// 刷新设备
  202. /// </summary>
  203. [HttpGet]
  204. public JsonMsg<string> FlushedDevice()
  205. {
  206. st = System.Reflection.MethodBase.GetCurrentMethod().Name;
  207. try
  208. {
  209. ProcessServer.Instance.LoadingShopInformation();
  210. return JsonMsg<string>.OK("success!", st);
  211. }
  212. catch (Exception ex)
  213. {
  214. return JsonMsg<string>.Error(null, st, ex.Message);
  215. }
  216. }
  217. }
  218. }