|  | @@ -12,6 +12,9 @@ import io.swagger.annotations.ApiImplicitParams;
 | 
	
		
			
				|  |  |  import io.swagger.annotations.ApiOperation;
 | 
	
		
			
				|  |  |  import lombok.AllArgsConstructor;
 | 
	
		
			
				|  |  |  import lombok.extern.slf4j.Slf4j;
 | 
	
		
			
				|  |  | +import org.slf4j.Logger;
 | 
	
		
			
				|  |  | +import org.slf4j.LoggerFactory;
 | 
	
		
			
				|  |  | +import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  import org.springframework.web.bind.annotation.DeleteMapping;
 | 
	
		
			
				|  |  |  import org.springframework.web.bind.annotation.GetMapping;
 | 
	
		
			
				|  |  |  import org.springframework.web.bind.annotation.PathVariable;
 | 
	
	
		
			
				|  | @@ -37,10 +40,14 @@ import java.util.Map;
 | 
	
		
			
				|  |  |  @Slf4j
 | 
	
		
			
				|  |  |  public class VideoController {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    private static final Logger logger = LoggerFactory.getLogger(VideoController.class);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  |      private VideoService videoService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -//    @Autowired
 | 
	
		
			
				|  |  | -//    private TaskServiceV2 taskServiceV2;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    // FFmpegManager 作为单例
 | 
	
		
			
				|  |  | +    private final FFmpegManager ffmpegManager;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /** Windows系统* */
 | 
	
		
			
				|  |  |      private static final boolean IS_WINDOWS = System.getProperty("os.name").toLowerCase().contains("win");
 | 
	
	
		
			
				|  | @@ -85,6 +92,7 @@ public class VideoController {
 | 
	
		
			
				|  |  |  //        }
 | 
	
		
			
				|  |  |  //        return ResponseResult.success(videoVo);
 | 
	
		
			
				|  |  |  //    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      /** 关闭ffmpeg.exe程序 */
 | 
	
		
			
				|  |  |      @GetMapping("/videoClose")
 | 
	
		
			
				|  |  |      public ResponseResult<Void> close() {
 | 
	
	
		
			
				|  | @@ -131,13 +139,12 @@ public class VideoController {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @ApiOperation("分页查询视频列表(支持视频名称模糊查询)")
 | 
	
		
			
				|  |  |      @PostMapping("/list")
 | 
	
		
			
				|  |  | -    public Map<String, Object> listAllPaged(@RequestBody Map<String, Object> params) {
 | 
	
		
			
				|  |  | +    public Map<String, Object> listVideos(@RequestBody Map<String, Object> params) {
 | 
	
		
			
				|  |  |          int page = (int) params.getOrDefault("page", 1);
 | 
	
		
			
				|  |  |          int size = (int) params.getOrDefault("size", 10);
 | 
	
		
			
				|  |  | -        String name = (String) params.getOrDefault("name", ""); // 视频名称模糊查询
 | 
	
		
			
				|  |  | +        String name = (String) params.getOrDefault("name", "");
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          List<Video> list = videoService.listAllPaged(page, size, name);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |          PageInfo<Video> pageInfo = new PageInfo<>(list);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          Map<String, Object> result = new HashMap<>();
 | 
	
	
		
			
				|  | @@ -146,68 +153,61 @@ public class VideoController {
 | 
	
		
			
				|  |  |          return result;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    @ApiOperation("分页查询视频列表(支持视频名称模糊查询)")
 | 
	
		
			
				|  |  | -    @PostMapping("/listVideo")
 | 
	
		
			
				|  |  | -    public Map<String, Object> listVideoAllPaged(@RequestBody Map<String, Object> params) {
 | 
	
		
			
				|  |  | -        int page = (int) params.getOrDefault("page", 1);
 | 
	
		
			
				|  |  | -        int size = (int) params.getOrDefault("size", 10);
 | 
	
		
			
				|  |  | -        String name = (String) params.getOrDefault("name", ""); // 视频名称模糊查询
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        List<Video> list = videoService.listVideoAllPaged(page, size, name);
 | 
	
		
			
				|  |  | +    @ApiOperation("播放视频,点击时才推流")
 | 
	
		
			
				|  |  | +    @GetMapping("/play/{id}")
 | 
	
		
			
				|  |  | +    public ResponseResult<String> playVideo(@PathVariable Long id) {
 | 
	
		
			
				|  |  | +        Video video = videoService.getById(id);
 | 
	
		
			
				|  |  | +        if (video == null) {
 | 
	
		
			
				|  |  | +            return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        PageInfo<Video> pageInfo = new PageInfo<>(list);
 | 
	
		
			
				|  |  | +        String cameraId = video.getId() + "_" + video.getChannel();
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            ffmpegManager.ensureStream(cameraId, video.getRtspUrl());
 | 
	
		
			
				|  |  | +        } catch (Exception e) {
 | 
	
		
			
				|  |  | +            log.error("FFmpeg生成流失败: {}-{}", video.getId(), video.getChannel(), e);
 | 
	
		
			
				|  |  | +            return ResponseResult.error(ErrorCodeEnum.FFMPEG_GENERATE_STREAM_FAILED);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        Map<String, Object> result = new HashMap<>();
 | 
	
		
			
				|  |  | -        result.put("total", pageInfo.getTotal());
 | 
	
		
			
				|  |  | -        result.put("list", list);
 | 
	
		
			
				|  |  | -        return result;
 | 
	
		
			
				|  |  | +        return ResponseResult.success(ffmpegManager.getPlayUrl(cameraId));
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    /**
 | 
	
		
			
				|  |  | -     * 根据ID查询单个视频
 | 
	
		
			
				|  |  | -     * @param id 视频ID
 | 
	
		
			
				|  |  | -     * @return 视频对象
 | 
	
		
			
				|  |  | -     */
 | 
	
		
			
				|  |  |      @ApiOperation("根据ID查询视频")
 | 
	
		
			
				|  |  |      @GetMapping("/{id}")
 | 
	
		
			
				|  |  | -    public Video getById(@PathVariable Long id) {
 | 
	
		
			
				|  |  | -        return videoService.getById(id);
 | 
	
		
			
				|  |  | +    public ResponseResult<Video> getById(@PathVariable Long id) {
 | 
	
		
			
				|  |  | +        Video video = videoService.getById(id);
 | 
	
		
			
				|  |  | +        if (video == null) {
 | 
	
		
			
				|  |  | +            return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return ResponseResult.success(video);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    /**
 | 
	
		
			
				|  |  | -     * 新增视频
 | 
	
		
			
				|  |  | -     * @param video 视频对象
 | 
	
		
			
				|  |  | -     * @return 操作结果
 | 
	
		
			
				|  |  | -     */
 | 
	
		
			
				|  |  |      @ApiOperation("新增视频")
 | 
	
		
			
				|  |  | -    @PostMapping
 | 
	
		
			
				|  |  | -    public String add(@RequestBody Video video) {
 | 
	
		
			
				|  |  | +    @PostMapping("/add")
 | 
	
		
			
				|  |  | +    public ResponseResult<String> add(@RequestBody Video video) {
 | 
	
		
			
				|  |  |          videoService.add(video);
 | 
	
		
			
				|  |  | -        return "新增成功";
 | 
	
		
			
				|  |  | +        return ResponseResult.success("新增成功");
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    /**
 | 
	
		
			
				|  |  | -     * 更新视频
 | 
	
		
			
				|  |  | -     * @param video 视频对象
 | 
	
		
			
				|  |  | -     * @return 操作结果
 | 
	
		
			
				|  |  | -     */
 | 
	
		
			
				|  |  |      @ApiOperation("更新视频")
 | 
	
		
			
				|  |  | -    @PutMapping
 | 
	
		
			
				|  |  | -    public String update(@RequestBody Video video) {
 | 
	
		
			
				|  |  | +    @PutMapping("/update")
 | 
	
		
			
				|  |  | +    public ResponseResult<String> update(@RequestBody Video video) {
 | 
	
		
			
				|  |  |          videoService.update(video);
 | 
	
		
			
				|  |  | -        return "更新成功";
 | 
	
		
			
				|  |  | +        return ResponseResult.success("更新成功");
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    /**
 | 
	
		
			
				|  |  | -     * 删除视频
 | 
	
		
			
				|  |  | -     * @param id 视频ID
 | 
	
		
			
				|  |  | -     * @return 操作结果
 | 
	
		
			
				|  |  | -     */
 | 
	
		
			
				|  |  |      @ApiOperation("删除视频")
 | 
	
		
			
				|  |  | -    @DeleteMapping("/{id}")
 | 
	
		
			
				|  |  | -    public String delete(@PathVariable Long id) {
 | 
	
		
			
				|  |  | +    @DeleteMapping("/delete/{id}")
 | 
	
		
			
				|  |  | +    public ResponseResult<String> delete(@PathVariable Long id) {
 | 
	
		
			
				|  |  |          videoService.delete(id);
 | 
	
		
			
				|  |  | -        return "删除成功";
 | 
	
		
			
				|  |  | +        return ResponseResult.success("删除成功");
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @ApiOperation("删除本地TS缓存文件")
 | 
	
		
			
				|  |  | +    @GetMapping("/deleteTs")
 | 
	
		
			
				|  |  | +    public ResponseResult<Void> deleteTsFiles() {
 | 
	
		
			
				|  |  | +        videoService.deleteTsFile();
 | 
	
		
			
				|  |  | +        return ResponseResult.success();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
	
		
			
				|  | @@ -253,6 +253,7 @@ public class VideoController {
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      public void closeHistoryProgram(String processName) {
 | 
	
		
			
				|  |  |          String cmd = "taskkill /f /t /im " + processName;
 | 
	
		
			
				|  |  |  //        try {
 |