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

LargeScreenController.cs 13 KiB

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. using SafeCampus.Application.Services.Business.CameraGroupService;
  2. using SafeCampus.Application.Services.Business.PersonInfoService;
  3. using SafeCampus.Application.Services.Business.Warn.Dto;
  4. using SafeCampus.Application.Services.Business.Warn.Service;
  5. using SafeCampus.Core.Extension;
  6. using MoYu.FriendlyException;
  7. using SafeCampus.Application.Services.Business.AttendanceService;
  8. using SafeCampus.Application.Services.Business.BuildingService;
  9. using SafeCampus.Application.Services.Business.ClassRoomCallService;
  10. using SafeCampus.Application.Services.Business.ClassRoomCallTaskService;
  11. using SafeCampus.Application.Services.Business.DormitoryService;
  12. using SafeCampus.Web.Core.Controllers.Application.Business;
  13. using MoYu.RemoteRequest.Extensions;
  14. using Newtonsoft.Json.Linq;
  15. using SafeCampus.Application.Manager.DeepelephManager;
  16. using SafeCampus.Application.Services.Business.DepartmentService;
  17. using SafeCampus.Application.Services.Business.MajorService;
  18. using SafeCampus.Application.Services.Business.PersonSetInfoService;
  19. namespace SafeCampus.Web.Core.Controllers.Application.LargeScreen;
  20. /// <summary>
  21. /// 大屏控制器
  22. /// </summary>
  23. [ApiDescriptionSettings(ApiGroupConsts.SYSTEM_Business, Tag = "大屏接口", Order = 84)]
  24. [Route("large/screen")]
  25. [AllowAnonymous]
  26. public class LargeScreenController
  27. {
  28. private readonly IPersonInfoService _personInfoService;
  29. private readonly ICameraGroupService _cameraGroupService;
  30. private readonly IWarnInfoService _warnInfoService;
  31. private readonly ISimpleCacheService _simpleCacheService;
  32. private readonly IAttendanceService _attendanceService;
  33. private readonly IBuildingService _buildingService;
  34. private readonly IDormitoryService _dormitoryService;
  35. private readonly IConfigService _configService;
  36. private readonly IClassRoomCallTaskService _classRoomCallTaskService;
  37. private readonly IClassRoomCallService _classRoomCallService;
  38. private readonly IDeepelephManager _deepelephManager;
  39. private readonly IPersonSetInfoService _personSetInfoService;
  40. private readonly IMajorService _majorService;
  41. private readonly IDepartmentService _departmentService;
  42. public LargeScreenController(IPersonInfoService personInfoService, ICameraGroupService cameraGroupService, IWarnInfoService warnInfoService, ISimpleCacheService simpleCacheService, IAttendanceService attendanceService, IBuildingService buildingService, IDormitoryService dormitoryService, IConfigService configService, IClassRoomCallTaskService classRoomCallTaskService, IClassRoomCallService classRoomCallService, IDeepelephManager deepelephManager, IPersonSetInfoService personSetInfoService, IMajorService majorService, IDepartmentService departmentService)
  43. {
  44. _personInfoService = personInfoService;
  45. _cameraGroupService = cameraGroupService;
  46. _warnInfoService = warnInfoService;
  47. _simpleCacheService = simpleCacheService;
  48. _attendanceService = attendanceService;
  49. _buildingService = buildingService;
  50. _dormitoryService = dormitoryService;
  51. _configService = configService;
  52. _classRoomCallTaskService = classRoomCallTaskService;
  53. _classRoomCallService = classRoomCallService;
  54. _deepelephManager = deepelephManager;
  55. _personSetInfoService = personSetInfoService;
  56. _majorService = majorService;
  57. _departmentService = departmentService;
  58. }
  59. /// <summary>
  60. /// 获取大屏首页数据
  61. /// </summary>
  62. /// <returns></returns>
  63. public async Task<dynamic> GetHomeData()
  64. {
  65. var startTime = DateTime.Now.Date;
  66. var entTime = DateTime.Now;
  67. //学生人数
  68. //总人数
  69. var ZRS = await _personInfoService.GetCount(null);
  70. //男生
  71. var nan = await _personInfoService.GetCount("GENDER_MALE");
  72. //女生
  73. var nv = await _personInfoService.GetCount("GENDER_FEMALE");
  74. //按设备分组统计设备数量
  75. var SheBei = await _cameraGroupService.GetBIList();
  76. //今日告警列表
  77. var warnlist = await _warnInfoService.GetListNoPage(new WarnInfoSearch
  78. {
  79. StartTick = startTime,
  80. EndTick = entTime
  81. });
  82. //今日告警统计按告警类型
  83. var warnType = typeof(AlarmType).EnumToEnumModel();
  84. var alarmStatistics = warnType.Select(x => new
  85. {
  86. Name = x.Description,
  87. //Code = x.Name,
  88. Value = warnlist.Count(xx => xx.AlarmType == x.Name)
  89. }).Where(x => x.Value > 0).ToList();
  90. //按场景统计告警类型
  91. var warnGroup= _simpleCacheService.Get<List<WarnGroupInfo>>(SafeCampusConst.WarnGroup);
  92. foreach (var item in warnGroup)
  93. {
  94. foreach (var warnGroupSubset in item.Subset)
  95. {
  96. warnGroupSubset.Value = warnlist.Count(x => x.AlarmType == warnGroupSubset.Code);
  97. }
  98. item.Value = item.Subset.Sum(x => x.Value);
  99. }
  100. var list = new List<object>
  101. {
  102. new { Name = "男生人数", Value = nan },
  103. new { Name = "女生人数", Value = nv }
  104. };
  105. return new
  106. {
  107. //数字统计
  108. StudentPersonNum=new{TotalNum=ZRS,MaleNum=nan,FemaleNum=nv},
  109. StudentPersonStatistion=list,
  110. //统计图表
  111. AlarmStatisti =new
  112. {
  113. //按类型统计
  114. TypeStatisti=alarmStatistics,
  115. //按告警分组 统计
  116. GroupStatisti=warnGroup,
  117. //告警列表
  118. WarnList=warnlist
  119. },
  120. //设备
  121. Camera= SheBei,
  122. };
  123. }
  124. /// <summary>
  125. /// 获取学生归寝大屏数据
  126. /// </summary>
  127. /// <returns></returns>
  128. public async Task<dynamic> GetStudentReturnBed(long buildId)
  129. {
  130. if (buildId<=0)
  131. {
  132. throw Oops.Oh("没有班级");
  133. }
  134. var startTime = DateTime.Now.Date;
  135. var entTime = DateTime.Now;
  136. //寝室人数
  137. var list = await _dormitoryService.GetBiReturnPageList(new ReturnDormitoryISearch
  138. {
  139. BuildId = buildId,
  140. ReturnTime = DateTime.Now
  141. });
  142. //总人数
  143. var Qsrs = list.Sum(x => x.PersonCount);
  144. //在寝人数
  145. var zqrs = list.Sum(x => x.DormitoryCount);
  146. //不在寝人数
  147. var bzqrs = Qsrs - zqrs;
  148. //寝室列表
  149. //归寝时间显示
  150. var json = await _configService.GetByConfigKey(CateGoryConst.CONFIG_BIZ_DEFINE,
  151. BizConfigConst.BIZ_DORMITORY_TIME);
  152. if (json == null)
  153. {
  154. return new ReturnTimeInput();
  155. }
  156. var config=JsonConvert.DeserializeObject<ReturnTimeInput>(json.ConfigValue);
  157. var guiqinsj= config.TimeBegin+" - "+config.TimeEnd;
  158. //出入记录
  159. var sushelou =await _buildingService.GetInfo(buildId);
  160. var crjl = await _attendanceService.GetNoPageList(new AttendanceSearch
  161. {
  162. StartTick = startTime,
  163. EndTick = entTime,
  164. CameraId = sushelou.InsCameraId,
  165. CameraIds=new List<string>{sushelou.InsCameraId,sushelou.OutCameraId}
  166. });
  167. return new
  168. {
  169. Building=new{TotalNum=Qsrs,InNum=zqrs,NoInNum=bzqrs},
  170. DormitoryList=list,
  171. ReturnTime=guiqinsj,
  172. AttendList=crjl,
  173. };
  174. }
  175. /// <summary>
  176. /// 获取智慧课堂大屏数据
  177. /// </summary>
  178. /// <returns></returns>
  179. public async Task<dynamic> GetSmartClassroom(string personSetId)
  180. {
  181. if (string.IsNullOrEmpty(personSetId))
  182. {
  183. throw Oops.Oh("没有班级");
  184. }
  185. //课堂信息
  186. var startTime = DateTime.Now.Date;
  187. var entTime = DateTime.Now;
  188. //学生信息
  189. var xuesheng = await _personInfoService.GetPageList(new PersonInfoSearch
  190. { PageSize = 1000, PageNum = 1, PersonSetId = personSetId });
  191. //点名信息
  192. var task =await _classRoomCallTaskService.GetPageList(new ClassRoomCallTaskSearch {PageNum = 1,PageSize = 10,PersonSetId = personSetId });
  193. var taskId = task.List.Any()?task.List.First().TaskId:"";
  194. var classRoom = await _classRoomCallService.GetNoPageList(new ClassRoomCallSearch { TaskId = taskId });
  195. //告警信息
  196. var warnGroup = _simpleCacheService.Get<List<WarnGroupInfo>>(SafeCampusConst.WarnGroup).FirstOrDefault(x=>x.Code=="ZHKT");
  197. var warnlist = await _warnInfoService.GetListNoPage(new WarnInfoSearch
  198. { AlarmTypes = warnGroup.Subset.Select(x => x.Code).ToArray(),StartTick = startTime, EndTick = entTime,CameraId = personSetId == "YS001" ? "SXT001" : "SXT002" });
  199. //告警信息统计
  200. var tongji = warnlist.GroupBy(x => x.AlarmTypeDesc).Select(x=>new{Labale=x.Key,Value=x.Count()}).ToList();
  201. foreach (var personInfoDto in xuesheng.List)
  202. {
  203. var rollCall=classRoom.Where(x=>x.PersonId==personInfoDto.PersonId).MinBy(x=>x.Tick);
  204. if (rollCall != null)
  205. {
  206. personInfoDto.State = rollCall.Tick.TimeOfDay> TimeSpan.Parse("09:00:00")?"迟到":"正常";
  207. personInfoDto.InsTime = rollCall.Tick;
  208. }
  209. else
  210. {
  211. personInfoDto.State = "缺勤";
  212. personInfoDto.InsTime = null;
  213. }
  214. }
  215. return new
  216. {
  217. ClassRoom=new
  218. {
  219. Teacher="王明祥",
  220. ClassTime=DateTime.Now.ToString("yyyy-MM-dd 09:00:00"),
  221. ClassBreakTime=DateTime.Now.ToString("yyyy-MM-dd 12:00:00"),
  222. CameraId= personSetId== "YS001" ? "SXT001": "SXT002"
  223. },
  224. AlarmList= warnlist,
  225. //AlarmListCount= warnlist.GroupBy(x=>x.PersonId).Count(),
  226. Statisti =new{Labale= tongji.Select(x=>x.Labale).ToList(),Value=tongji.Select(x=>x.Value).ToList()},
  227. NormalClass= xuesheng.List.Count(x=>!warnlist.Any(xx=>xx.PersonId==x.PersonId)),
  228. StudentList=xuesheng.List,
  229. //RollCall= classRoom.Where(x=>x.AlarmType!= "class_room_call").ToList()
  230. };
  231. }
  232. /// <summary>
  233. /// 直播流拉取
  234. /// 拉流的时候,选pullStreamUrls和rtsPullStreamUrls里面的链接,pushStreamUrls和h5rtsPullStreamUrls直接忽略。
  235. /// </summary>
  236. /// <param name="sensorId">摄像头id</param>
  237. /// <returns></returns>
  238. public async Task<dynamic> GetStartVideoLive(string sensorId)
  239. {
  240. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  241. var str = await $"{appSettings.SXAPIURL}/device/console/v1/sensor/start_video_live"
  242. .SetBody(new
  243. {
  244. token = _deepelephManager.GetToken(),
  245. tenantCode = appSettings.TenantCode,
  246. poiId = appSettings.PoiId,
  247. cameraId = sensorId,
  248. })
  249. .SetContentType("application/json")
  250. .PostAsAsync<string>();
  251. var model = JsonConvert.DeserializeObject<JObject>(str);
  252. if ((bool)model["success"])
  253. {
  254. return model["data"];
  255. }
  256. throw Oops.Oh(model["message"].ToString());
  257. }
  258. /// <summary>
  259. /// 直播流停止拉取
  260. /// </summary>
  261. /// <param name="sensorId">摄像头id</param>
  262. /// <param name="videoToken">视频token</param>
  263. /// <param name="streamId">流ID</param>
  264. /// <returns></returns>
  265. public async Task<dynamic> GetStopVideoLive(string sensorId, string videoToken, string streamId)
  266. {
  267. var appSettings = App.GetOptionsMonitor<AppInfoOptions>();
  268. var str = await $"{appSettings.SXAPIURL}/device/console/v1/sensor/stop_video_live"
  269. .SetBody(new
  270. {
  271. token = _deepelephManager.GetToken(),
  272. tenantCode = appSettings.TenantCode,
  273. poiId = appSettings.PoiId,
  274. cameraId = sensorId,
  275. videoToken,
  276. streamId
  277. })
  278. .SetContentType("application/json")
  279. .PostAsAsync<string>();
  280. var model = JsonConvert.DeserializeObject<JObject>(str);
  281. if ((bool)model["success"])
  282. {
  283. return model["data"]["streamId"].ToString();
  284. }
  285. throw Oops.Oh(model["message"].ToString());
  286. }
  287. /// <summary>
  288. /// 获取宿舍楼列表
  289. /// </summary>
  290. /// <returns></returns>
  291. public async Task<List<BuildingInfoDto>> GetNoPageList()
  292. {
  293. return await _buildingService.GetNoPageList();
  294. }
  295. /// <summary>
  296. /// 获取班级列表
  297. /// </summary>
  298. /// <returns></returns>
  299. public async Task<dynamic> GetPersonSetNoPageList(long? majorId,string setName)
  300. {
  301. return await _personSetInfoService.GetPageList(majorId, setName);
  302. }
  303. /// <summary>
  304. /// 获取专业
  305. /// </summary>
  306. /// <param name="depId">院系id</param>
  307. /// <returns></returns>
  308. public async Task<dynamic> GetMajorNoPageList(long? depId)
  309. {
  310. return await _majorService.GetNoPageList(new MajorSearch{DepId = depId});
  311. }
  312. /// <summary>
  313. /// 获取院系
  314. /// </summary>
  315. /// <returns></returns>
  316. public async Task<dynamic> GetDepartment()
  317. {
  318. return await _departmentService.GetNoPageList(new DepartmentSearch());
  319. }
  320. }