平安校园
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

4 месяцев назад
3 месяцев назад
4 месяцев назад
3 месяцев назад
4 месяцев назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using MoYu.RemoteRequest.Extensions;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using SafeCampus.Application.Manager.DeepelephManager;
  5. using System.Collections.Generic;
  6. namespace SafeCampus.Application.Services.Business.CameraInfoService;
  7. public class CameraInfoService:DbRepository<CameraInfo>, ICameraInfoService
  8. {
  9. private readonly IDeepelephManager _deepelephManager;
  10. private readonly ISimpleCacheService _simpleCacheService;
  11. public CameraInfoService(IDeepelephManager deepelephManager, ISimpleCacheService simpleCacheService)
  12. {
  13. _deepelephManager = deepelephManager;
  14. _simpleCacheService = simpleCacheService;
  15. }
  16. public async Task<bool> DataSync()
  17. {
  18. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  19. var list = await Context.Queryable<CameraInfo>().ToListAsync();
  20. var str = await $"{appSettings.SXAPIURL}/device/console/v1/sensor/page_query/brief"
  21. .SetBody(new
  22. {
  23. token = _deepelephManager.GetToken(),
  24. tenantCode = appSettings.TenantCode,
  25. poiId = appSettings.PoiId,
  26. pageNo = 1,
  27. pageSize = 1000,
  28. })
  29. .SetContentType("application/json")
  30. .PostAsAsync<string>();
  31. var model = JsonConvert.DeserializeObject<JObject>(str);
  32. if (!(bool)model["success"]) throw Oops.Oh(model["message"].ToString());
  33. if (model["data"] != null)
  34. {
  35. foreach (var item in model["data"]["items"])
  36. {
  37. var old_model = list.FirstOrDefault(x => x.SensorId == item["sensorId"].ToString());
  38. if (old_model != null)
  39. {
  40. old_model.DeviceStatus = item["deviceStatus"].ToString() == "online";
  41. old_model.DirectUrlIp = item["directUrlIp"].ToString();
  42. old_model.FieldId = item["fieldId"].ToString();
  43. old_model.FieldName = item["fieldName"].ToString();
  44. old_model.LastTime = DateTime.Now;
  45. old_model.ResHeight = (int)item["resHeight"];
  46. old_model.ResWidth = (int)item["resWidth"];
  47. old_model.SensorName = item["sensorName"].ToString();
  48. old_model.SnapshotUrl = item["snapshotUrl"].ToString();
  49. await UpdateAsync(old_model);
  50. }
  51. else
  52. {
  53. await InsertAsync(new CameraInfo
  54. {
  55. DeviceStatus = item["deviceStatus"].ToString()== "online",
  56. DirectUrlIp = item["directUrlIp"].ToString(),
  57. FieldId = item["fieldId"].ToString(),
  58. FieldName = item["fieldName"].ToString(),
  59. LastTime = DateTime.Now,
  60. ResHeight = (int)item["resHeight"],
  61. ResWidth = (int)item["resWidth"],
  62. SensorId = item["sensorId"].ToString(),
  63. SensorName = item["sensorName"].ToString(),
  64. SnapshotUrl = item["snapshotUrl"].ToString(),
  65. });
  66. }
  67. }
  68. return true;
  69. }
  70. return false;
  71. }
  72. public async Task<SqlSugarPagedList<CameraInfo>> GetPageList(CameraSearch search)
  73. {
  74. var query = Context.Queryable<CameraInfo>()
  75. .WhereIF(search.DeviceStatus.HasValue, x => x.DeviceStatus == search.DeviceStatus)
  76. .WhereIF(!string.IsNullOrEmpty(search.SensorId), x => x.SensorId == search.SensorId)
  77. .WhereIF(!string.IsNullOrEmpty(search.SensorName), x => x.SensorName == search.SensorName)
  78. .WhereIF(search.GroupId.HasValue, x => (search.GroupId.Value==-1?x.GroupId==null:x.GroupId==search.GroupId.Value));
  79. var list = await query.OrderBy(x => x.LastTime)
  80. .ToPagedListAsync(search.PageNum, search.PageSize);
  81. return list;
  82. }
  83. public async Task<bool> BatchSetGroup(SetGroupInput input)
  84. {
  85. if (input.Id==-1)
  86. {
  87. var result = await Context.Updateable<CameraInfo>()
  88. .SetColumns(x => x.GroupId == null)
  89. .Where(x => input.Ids.Contains(x.Id))
  90. .ExecuteCommandAsync();
  91. return result == input.Ids.Count;
  92. }
  93. else
  94. {
  95. var result = await Context.Updateable<CameraInfo>()
  96. .SetColumns(x => x.GroupId == input.Id)
  97. .Where(x => input.Ids.Contains(x.Id))
  98. .ExecuteCommandAsync();
  99. return result == input.Ids.Count;
  100. }
  101. }
  102. public async Task<bool> BatchSetPushPersonByGroup(SetPushPersonGroupInput input)
  103. {
  104. var result = await Context.Updateable<CameraInfo>()
  105. .SetColumns(x => x.PushUserId == input.UserId)
  106. .Where(x =>x.GroupId==input.GroupId)
  107. .ExecuteCommandAsync();
  108. return result >0;
  109. }
  110. public async Task<bool> BatchSetPushPerson(SetPushPersonInput input)
  111. {
  112. var result = await Context.Updateable<CameraInfo>()
  113. .SetColumns(x => x.PushUserId == input.UserId)
  114. .Where(x => input.Ids.Contains(x.Id))
  115. .ExecuteCommandAsync();
  116. return result == input.Ids.Count;
  117. }
  118. public async Task<bool> BatchSetPushPersonByWarn(SetPushPersonWarnInput input)
  119. {
  120. var warn = _simpleCacheService.Get<List<WarnGroupInfo>>(SafeCampusConst.WarnGroup);
  121. var warnGroupInfo = warn.FirstOrDefault(x => x.Code == input.WarnCode);
  122. if (warnGroupInfo != null)
  123. {
  124. var ids = warnGroupInfo.CameraId;
  125. var result = await Context.Updateable<CameraInfo>()
  126. .SetColumns(x => x.PushUserId == input.UserId)
  127. .Where(x => ids.Contains(x.SensorId))
  128. .ExecuteCommandAsync();
  129. return result >0;
  130. }
  131. throw Oops.Oh("分组不存在");
  132. }
  133. }