CheckVoxController.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package com.example.unusualsounds.project.vox.controller;
  2. import com.example.unusualsounds.common.utils.UUID;
  3. import com.example.unusualsounds.project.vox.config.VideoTaskManager;
  4. import com.example.unusualsounds.project.vox.service.impl.AlarmsServiceImpl;
  5. import com.example.unusualsounds.project.vox.service.impl.VideoServiceImpl;
  6. import com.example.unusualsounds.project.vox.service.impl.VoiceTicketLogsServiceImpl;
  7. import com.example.unusualsounds.project.vox.service.impl.VoxServiceImpl;
  8. import com.example.unusualsounds.web.entity.AjaxResult;
  9. import com.example.unusualsounds.web.jsonobj.CameraDTO;
  10. import com.example.unusualsounds.web.jsonobj.Device;
  11. import com.example.unusualsounds.web.jsonobj.Skill;
  12. import io.swagger.v3.oas.annotations.Operation;
  13. import io.swagger.v3.oas.annotations.tags.Tag;
  14. import lombok.extern.slf4j.Slf4j;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.web.bind.annotation.*;
  17. import java.util.HashMap;
  18. import java.util.List;
  19. @RestController
  20. @Tag(name = "vox 异音模块")
  21. @Slf4j
  22. @RequestMapping("/vox")
  23. public class CheckVoxController {
  24. @Autowired
  25. private VoxServiceImpl voxServiceImpl;
  26. @Autowired
  27. private VideoServiceImpl videoServiceImpl;
  28. @Autowired
  29. private VideoTaskManager videoTaskManager;
  30. @Autowired
  31. private AlarmsServiceImpl alarmsServiceImpl;
  32. @Autowired
  33. private VoiceTicketLogsServiceImpl voiceTicketLogsServiceImpl;
  34. @Operation(summary = "算法启停接口")
  35. @PostMapping("/start_stop")
  36. public AjaxResult startStopVox(@RequestBody Device device) throws InterruptedException {
  37. String openUuid = UUID.generateUUIDWithoutHyphens();
  38. //校验设备是否开启(包含传感器、摄像头),当前只做摄像头校验
  39. CameraDTO camera = voxServiceImpl.checkDevice(device.getDeviceId());
  40. //-----测试(本地模拟rtsp流)
  41. // camera.setSrcURL("rtsp://192.168.1.112:8554/video");
  42. // camera.setVideoType("");
  43. //-----测试(本地模拟rtsp流)
  44. if(camera == null || "offline".equals(camera.getStatus()) || "error".equals(camera.getStatus())){
  45. //保存启停接口的设备信息到数据库,便于后续定时任务调用
  46. voiceTicketLogsServiceImpl.saveStartStop(device,openUuid,"设备离线或出错");
  47. return AjaxResult.error("设备离线或出错");
  48. }
  49. System.out.println("摄像头查询:"+camera.toString());
  50. Skill skill = device.getSkills().get(0);
  51. boolean skillOpen = device.getSkills().get(0).isOpen();
  52. if(skillOpen){
  53. //添加校验视频流地址是否有效,无效则不启动算法(考虑现场网络环境差,不进行15s校验rtsp)
  54. // boolean checkStream = videoServiceImpl.checkStream(camera);
  55. // log.info("视频流地址校验结果:{}",checkStream);
  56. // if(!checkStream){
  57. // //保存启停接口的设备信息到数据库,便于后续定时任务调用
  58. // voiceTicketLogsServiceImpl.saveStartStop(device,openUuid,"视频流地址无效");
  59. // return AjaxResult.error("视频流地址无效");
  60. // }
  61. //开启处理视频流和接入算法
  62. videoServiceImpl.handlesStream(device.getDeviceId(),camera.getSrcURL(),skill,camera.getName(),openUuid);
  63. //保存启停接口的设备信息到数据库,便于后续定时任务调用
  64. voiceTicketLogsServiceImpl.saveStartStop(device,openUuid,"算法已启动(视频流解析)");
  65. return AjaxResult.success("算法已启动");
  66. }else{
  67. //关闭处理视频流和接入算法 (使用定时任务的方式清理视频分片)
  68. videoTaskManager.stopTask(device.getDeviceId()+"_"+skill.getName());
  69. //保存启停接口的设备信息到数据库,便于后续定时任务调用
  70. voiceTicketLogsServiceImpl.saveStartStop(device,openUuid,"算法已关闭(视频流解析)");
  71. return AjaxResult.success("算法已关闭");
  72. }
  73. }
  74. @Operation(summary = "返回vox分析结果")
  75. @PostMapping("/resultAnalysis")
  76. public AjaxResult resultVoxAnalysis(@RequestBody HashMap<String,String> resultAnalysis){
  77. boolean saveResult = alarmsServiceImpl.saveResultAnalysis(resultAnalysis);
  78. return AjaxResult.success("测试成功");
  79. }
  80. @Operation(summary = "列出当前工单正在运行的任务")
  81. @GetMapping("/tasks")
  82. public List<VideoTaskManager.TaskStatus> listActiveTasks() {
  83. return videoTaskManager.listTasks();
  84. }
  85. }