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.
 
 

237 lines
8.2 KiB

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