123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- package com.example.unusualsounds.project.vox.controller;
- import com.example.unusualsounds.common.utils.UUID;
- import com.example.unusualsounds.project.vox.config.VideoTaskManager;
- import com.example.unusualsounds.project.vox.service.impl.AlarmsServiceImpl;
- import com.example.unusualsounds.project.vox.service.impl.VideoServiceImpl;
- import com.example.unusualsounds.project.vox.service.impl.VoiceTicketLogsServiceImpl;
- import com.example.unusualsounds.project.vox.service.impl.VoxServiceImpl;
- import com.example.unusualsounds.web.entity.AjaxResult;
- import com.example.unusualsounds.web.jsonobj.CameraDTO;
- import com.example.unusualsounds.web.jsonobj.Device;
- import com.example.unusualsounds.web.jsonobj.Skill;
- import io.swagger.v3.oas.annotations.Operation;
- import io.swagger.v3.oas.annotations.tags.Tag;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import java.util.HashMap;
- import java.util.List;
- @RestController
- @Tag(name = "vox 异音模块")
- @Slf4j
- @RequestMapping("/vox")
- public class CheckVoxController {
- @Autowired
- private VoxServiceImpl voxServiceImpl;
- @Autowired
- private VideoServiceImpl videoServiceImpl;
- @Autowired
- private VideoTaskManager videoTaskManager;
- @Autowired
- private AlarmsServiceImpl alarmsServiceImpl;
- @Autowired
- private VoiceTicketLogsServiceImpl voiceTicketLogsServiceImpl;
- @Operation(summary = "算法启停接口")
- @PostMapping("/start_stop")
- public AjaxResult startStopVox(@RequestBody Device device) throws InterruptedException {
- String openUuid = UUID.generateUUIDWithoutHyphens();
- //校验设备是否开启(包含传感器、摄像头),当前只做摄像头校验
- CameraDTO camera = voxServiceImpl.checkDevice(device.getDeviceId());
- //-----测试(本地模拟rtsp流)
- // camera.setSrcURL("rtsp://192.168.1.112:8554/video");
- // camera.setVideoType("");
- //-----测试(本地模拟rtsp流)
- if(camera == null || "offline".equals(camera.getStatus()) || "error".equals(camera.getStatus())){
- //保存启停接口的设备信息到数据库,便于后续定时任务调用
- voiceTicketLogsServiceImpl.saveStartStop(device,openUuid,"设备离线或出错");
- return AjaxResult.error("设备离线或出错");
- }
- System.out.println("摄像头查询:"+camera.toString());
- Skill skill = device.getSkills().get(0);
- boolean skillOpen = device.getSkills().get(0).isOpen();
- if(skillOpen){
- //添加校验视频流地址是否有效,无效则不启动算法(考虑现场网络环境差,不进行15s校验rtsp)
- // boolean checkStream = videoServiceImpl.checkStream(camera);
- // log.info("视频流地址校验结果:{}",checkStream);
- // if(!checkStream){
- // //保存启停接口的设备信息到数据库,便于后续定时任务调用
- // voiceTicketLogsServiceImpl.saveStartStop(device,openUuid,"视频流地址无效");
- // return AjaxResult.error("视频流地址无效");
- // }
- //开启处理视频流和接入算法
- videoServiceImpl.handlesStream(device.getDeviceId(),camera.getSrcURL(),skill,camera.getName(),openUuid);
- //保存启停接口的设备信息到数据库,便于后续定时任务调用
- voiceTicketLogsServiceImpl.saveStartStop(device,openUuid,"算法已启动(视频流解析)");
- return AjaxResult.success("算法已启动");
- }else{
- //关闭处理视频流和接入算法 (使用定时任务的方式清理视频分片)
- videoTaskManager.stopTask(device.getDeviceId()+"_"+skill.getName());
- //保存启停接口的设备信息到数据库,便于后续定时任务调用
- voiceTicketLogsServiceImpl.saveStartStop(device,openUuid,"算法已关闭(视频流解析)");
- return AjaxResult.success("算法已关闭");
- }
- }
- @Operation(summary = "返回vox分析结果")
- @PostMapping("/resultAnalysis")
- public AjaxResult resultVoxAnalysis(@RequestBody HashMap<String,String> resultAnalysis){
- boolean saveResult = alarmsServiceImpl.saveResultAnalysis(resultAnalysis);
- return AjaxResult.success("测试成功");
- }
- @Operation(summary = "列出当前工单正在运行的任务")
- @GetMapping("/tasks")
- public List<VideoTaskManager.TaskStatus> listActiveTasks() {
- return videoTaskManager.listTasks();
- }
- }
|