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

  1. using Dm;
  2. using MoYu.FriendlyException;
  3. using MoYu.RemoteRequest.Extensions;
  4. using Newtonsoft.Json.Linq;
  5. using SafeCampus.Application.Manager.DeepelephManager;
  6. using SafeCampus.Application.Services.Business.ClassRoomCallService;
  7. using SafeCampus.Application.Services.Business.ClassRoomCallTaskService;
  8. using SafeCampus.Core.Extension;
  9. namespace SafeCampus.Web.Core.Controllers.Application.Business;
  10. /// <summary>
  11. /// 教室点名接口
  12. /// </summary>
  13. [Route("/business/[controller]")]
  14. [ApiDescriptionSettings(ApiGroupConsts.SYSTEM_Business, Order = 95,Tag = "教室点名管理")]
  15. public class ClassRoomCallApi : IDynamicApiController
  16. {
  17. private readonly IClassRoomCallTaskService _classRoomCallTaskService;
  18. private readonly IClassRoomCallService _classRoomCallService;
  19. private readonly IDeepelephManager _deepelephManager;
  20. public ClassRoomCallApi(IDeepelephManager deepelephManager, IClassRoomCallTaskService classRoomCallTaskService, IClassRoomCallService classRoomCallService)
  21. {
  22. _deepelephManager = deepelephManager;
  23. _classRoomCallTaskService = classRoomCallTaskService;
  24. _classRoomCallService = classRoomCallService;
  25. }
  26. /// <summary>
  27. /// 点名事件查询
  28. /// </summary>
  29. /// <param name="search">查询参数</param>
  30. /// <returns></returns>
  31. [Obsolete]
  32. public async Task<dynamic> GetRoomCall(ClassRoomCallTaskSearchRequest search)
  33. {
  34. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  35. var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/class-room-call/data/query"
  36. .SetBody(new
  37. {
  38. token = _deepelephManager.GetToken(),
  39. tenantCode = appSettings.TenantCode,
  40. poiId = appSettings.PoiId,
  41. beginTime = new DateTimeOffset(search.startTime).ToUnixTimeMilliseconds(),
  42. endTime = new DateTimeOffset(search.endTime).ToUnixTimeMilliseconds(),
  43. cameraId = search.cameraId,
  44. search.taskId,
  45. pageIndex = search.PageNum,
  46. pageSize = search.PageSize,
  47. })
  48. .SetContentType("application/json")
  49. .PostAsAsync<string>();
  50. var model = JsonConvert.DeserializeObject<JObject>(str);
  51. if (!(bool)model["success"]) throw Oops.Oh(model["message"].ToString());
  52. if (model["data"] != null)
  53. {
  54. return new
  55. {
  56. pageNum = search.PageNum,
  57. pageSize = model["data"]["size"],
  58. total = model["data"]["total"],
  59. pages = model["data"]["pages"],
  60. list = model["data"]["items"]
  61. };
  62. }
  63. return new
  64. {
  65. pageNum = search.PageNum,
  66. pageSize = 0,
  67. total = 0,
  68. pages = 0,
  69. list = new List<string>()
  70. };
  71. }
  72. /// <summary>
  73. /// 点名任务下发
  74. /// </summary>
  75. /// <returns></returns>
  76. public async Task<bool> TaskSubmit(ClassRoomCallTaskAdd input)
  77. {
  78. var taskId = DateTime.Now.ToString("yyyyMMddHHmmssss");// Guid.NewGuid().ToString("N");
  79. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  80. var str = await $"{appSettings.SXAPIURL}/dfield-api/ecology/class-room-call/task/submit"
  81. .SetBody(new
  82. {
  83. token = _deepelephManager.GetToken(),
  84. tenantCode = appSettings.TenantCode,
  85. poiId = appSettings.PoiId,
  86. taskId,
  87. continueTime = input.ContinueTime,
  88. cameraId = input.CameraId,
  89. personSetId = input.PersonSetId,
  90. similarity = input.Similarity
  91. })
  92. .SetContentType("application/json")
  93. .PostAsAsync<string>();
  94. var model = JsonConvert.DeserializeObject<JObject>(str);
  95. if (!(bool)model["success"]) throw Oops.Oh(model["message"].ToString());
  96. await _classRoomCallTaskService.Add(new ClassRoomCallTaskDto
  97. {
  98. CameraId = input.CameraId,
  99. CreateTime = DateTime.Now,
  100. ContinueTime = input.ContinueTime,
  101. EndTime = DateTime.Now.AddMinutes(input.ContinueTime),
  102. PersonSetId = input.PersonSetId,
  103. Similarity = input.Similarity,
  104. TaskId = taskId,
  105. });
  106. return true;
  107. }
  108. /// <summary>
  109. /// 删除点名任务,删除关联点名数据
  110. /// </summary>
  111. /// <param name="id"></param>
  112. /// <returns></returns>
  113. [HttpPost]
  114. public async Task<bool> Delete(BaseIdListInput input)
  115. {
  116. foreach (var inputId in input.Ids)
  117. {
  118. await _classRoomCallTaskService.Remove(inputId);
  119. }
  120. return true;
  121. }
  122. /// <summary>
  123. /// 获取点名任务列表
  124. /// </summary>
  125. /// <param name="search"></param>
  126. /// <returns></returns>
  127. public async Task<SqlSugarPagedList<ClassRoomCallTaskDto>> GetTaskPageList(ClassRoomCallTaskSearch search)
  128. {
  129. return await _classRoomCallTaskService.GetPageList(search);
  130. }
  131. /// <summary>
  132. /// 添加点名记录
  133. /// </summary>
  134. /// <param name="input"></param>
  135. /// <returns></returns>
  136. [Obsolete]
  137. public async Task<bool> Add(ClassRoomCallDto input)
  138. {
  139. return await _classRoomCallService.Add(input);
  140. }
  141. /// <summary>
  142. /// 修改点名信息,人工处理
  143. /// </summary>
  144. /// <param name="input"></param>
  145. /// <returns></returns>
  146. [Obsolete]
  147. public async Task<bool> Update(ClassRoomCallUpdate input)
  148. {
  149. return await _classRoomCallService.Update(input);
  150. }
  151. /// <summary>
  152. /// 手动点名
  153. /// </summary>
  154. /// <returns></returns>
  155. public async Task<bool> ManualRoll(List<ClassRoomCallInsert> input)
  156. {
  157. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  158. foreach (var item in input)
  159. {
  160. var model = new ClassRoomCallDto
  161. {
  162. TenantCode = appSettings.TenantCode,
  163. PoiId = appSettings.PoiId,
  164. TaskId = item.TaskId,
  165. AlarmType = "class_room_call",
  166. AlarmTypeDesc = AlarmType.class_room_call.GetDescription(),
  167. EventId ="",
  168. CameraId = "",
  169. Tick = DateTime.Now,
  170. PersonSetId = item.PersonSetId,
  171. PersonId = item.PersonId,
  172. Similarity = 1,
  173. FaceScore = 100,
  174. SnapshotUrl = "",
  175. SnapshotData = "",
  176. Rects = "",
  177. Extend = "",
  178. CreateTime = DateTime.Now,
  179. TrackId = "SDDM"+ item.PersonId
  180. };
  181. await _classRoomCallService.Add(model);
  182. }
  183. return true;
  184. }
  185. /// <summary>
  186. /// 删除点名记录(只可删除待处理的记录)
  187. /// </summary>
  188. /// <param name="id"></param>
  189. /// <returns></returns>
  190. public async Task<bool> Remove(long id)
  191. {
  192. return await _classRoomCallService.Remove(id);
  193. }
  194. /// <summary>
  195. /// 分页获取列表
  196. /// </summary>
  197. /// <returns></returns>
  198. public async Task<SqlSugarPagedList<ClassRoomCallList>> GetPageList(ClassRoomCallSearch search)
  199. {
  200. return await _classRoomCallService.GetPageList(search);
  201. }
  202. /// <summary>
  203. /// 不分页获取列表
  204. /// </summary>
  205. /// <param name="search"></param>
  206. /// <returns></returns>
  207. public async Task<List<ClassRoomCallList>> GetNoPageList(ClassRoomCallSearch search)
  208. {
  209. return await _classRoomCallService.GetNoPageList(search);
  210. }
  211. }