平安校园
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.

AlarmApi.cs 4.5 KiB

4 months ago
3 months ago
4 months ago
3 months ago
4 months ago
4 months ago
4 months ago
4 months ago
3 months ago
4 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using Microsoft.AspNetCore.SignalR;
  2. using MoYu.FriendlyException;
  3. using MoYu.RemoteRequest.Extensions;
  4. using Newtonsoft.Json.Linq;
  5. using SafeCampus.Application.Manager.DeepelephManager;
  6. using SafeCampus.Web.Core.Controllers.Application.Business.Dto;
  7. using SafeCampus.Web.Core.Hub;
  8. namespace SafeCampus.Web.Core.Controllers.Application.Business;
  9. /// <summary>
  10. /// 预警事件查询接口
  11. /// </summary>
  12. [Route("/business/[controller]")]
  13. [ApiDescriptionSettings(ApiGroupConsts.SYSTEM_Business, Order = 93,Tag = "预警数据同步")]
  14. [Obsolete]
  15. public class AlarmApi:IDynamicApiController
  16. {
  17. private readonly IDeepelephManager _deepelephManager;
  18. private readonly IHubContext<SubscribeHub, IChatClient> _hubContext;
  19. public AlarmApi(IDeepelephManager deepelephManager, IHubContext<SubscribeHub, IChatClient> hubContext)
  20. {
  21. _deepelephManager = deepelephManager;
  22. _hubContext = hubContext;
  23. }
  24. /// <summary>
  25. /// 预警列表(同步数据)
  26. /// </summary>
  27. /// <param name="search">查询信息</param>
  28. /// <returns></returns>
  29. public async Task<dynamic> GetAlarmListSync(AlarmSearch search)
  30. {
  31. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  32. var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/alarm/query-list"
  33. .SetBody(new
  34. {
  35. token = _deepelephManager.GetToken(),
  36. tenantCode = appSettings.TenantCode,
  37. poiId = appSettings.PoiId,
  38. //alarmType=search.alarmType.GetDescription(),
  39. //beginTime=search.beginTime.HasValue?search.beginTime.Value.ToString("yyyy-MM-dd HH:mm:ss") :"",
  40. //endTime= search.endTime.HasValue ? search.endTime.Value.ToString("yyyy-MM-dd HH:mm:ss") : "",
  41. //search.cameraId,
  42. pageIndex=search.PageNum,
  43. pageSize=search.PageSize,
  44. })
  45. .SetContentType("application/json")
  46. .PostAsAsync<string>();
  47. var model = JsonConvert.DeserializeObject<JObject>(str);
  48. //if ((bool)model["success"])
  49. //{
  50. // return model["data"];
  51. //}
  52. //throw Oops.Oh(model["message"].ToString());
  53. if (!(bool)model["success"]) throw Oops.Oh(model["message"].ToString());
  54. if (model["data"] != null)
  55. {
  56. return new
  57. {
  58. pageNum = search.PageNum,
  59. pageSize = model["data"]["size"],
  60. total = model["data"]["total"],
  61. pages = model["data"]["pages"],
  62. list = model["data"]["items"]
  63. };
  64. }
  65. return new
  66. {
  67. pageNum = search.PageNum,
  68. pageSize = 0,
  69. total = 0,
  70. pages = 0,
  71. list = new List<string>()
  72. };
  73. }
  74. /// <summary>
  75. /// 根据预警id查询预警(同步数据)
  76. /// </summary>
  77. /// <param name="alarmId">预警id</param>
  78. /// <returns></returns>
  79. public async Task<dynamic> GetAlarmByIdSync(string alarmId)
  80. {
  81. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  82. var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/alarm/query"
  83. .SetBody(new
  84. {
  85. token = _deepelephManager.GetToken(),
  86. tenantCode = appSettings.TenantCode,
  87. poiId = appSettings.PoiId,
  88. alarmId
  89. })
  90. .SetContentType("application/json")
  91. .PostAsAsync<string>();
  92. var model = JsonConvert.DeserializeObject<JObject>(str);
  93. if ((bool)model["success"])
  94. {
  95. return model["data"];
  96. }
  97. throw Oops.Oh(model["message"].ToString());
  98. }
  99. /// <summary>
  100. /// 发送分组消息
  101. /// </summary>
  102. /// <param name="group"></param>
  103. /// <param name="msg"></param>
  104. /// <returns></returns>
  105. public async Task<bool> SendGroupMsg(string group,string msg)
  106. {
  107. await _hubContext.Clients.Group(group).ReceiveMessage("System", msg);
  108. return true;
  109. }
  110. /// <summary>
  111. /// 发送消息
  112. /// </summary>
  113. /// <param name="user"></param>
  114. /// <param name="msg"></param>
  115. /// <returns></returns>
  116. public async Task<bool> SendMsg(string user, string msg)
  117. {
  118. await _hubContext.Clients.All.ReceiveMessage(user,msg);
  119. return true;
  120. }
  121. /// <summary>
  122. /// 测试
  123. /// </summary>
  124. /// <returns></returns>
  125. public async Task<bool> Test()
  126. {
  127. Thread.Sleep(5000);
  128. return true;
  129. }
  130. }