Pu Zhibing
2025-05-06 1ad5e3d97eb99662b08c0f5acff34875deca04c1
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/OrderController.java
@@ -23,6 +23,7 @@
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
@@ -50,6 +51,7 @@
 * @author zhibing.pu
 * @Date 2025/3/24 17:50
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
@@ -75,14 +77,23 @@
   @Resource
   private RedisTemplate redisTemplate;
   
   @Value("${live.output.path}")
   private String outputPath;
   @Value("${live.hls.output-path}")
   private String hlsOutputPath;
   
   @Value("${live.ip}")
   private String liveIp;
   @Value("${live.hls.ip}")
   private String hlsIp;
   
   @Value("${live.port}")
   private Integer livePort;
   @Value("${live.hls.port}")
   private Integer hlsPort;
   @Value("${live.flv.ip}")
   private String flvIp;
   @Value("${live.flv.rtmp-port}")
   private Integer flvRtmpPort;
   @Value("${live.flv.http-port}")
   private Integer flvHttpPort;
   
   
   @GetMapping("/getOrderList")
@@ -173,7 +184,7 @@
   public R<RealVideoResp> getOrderMonitoring(Integer id) {
      Order order = orderService.getById(id);
      if (null == order) {
         return R.fail("失败");
         return R.fail("获取视频失败");
      }
      Car car = carService.getById(order.getCarId());
      //手动加一次状态数据,避免定时任务结束任务线程
@@ -187,32 +198,59 @@
      if (200 == startupAckVoR.getCode()) {
         UPPlaybackMsgStartupAckVo data = startupAckVoR.getData();
         RealVideoResp resp = new RealVideoResp();
         String path = outputPath + "hls\\" + car.getVehicleNumber() + "\\live.m3u8";
         String folderPath = outputPath + "hls\\" + car.getVehicleNumber();
         FileUtil.mkParentDirs(path);
         File file = new File(path);
         if (!file.exists()) {
            try {
               file.createNewFile();
            } catch (IOException e) {
               throw new RuntimeException(e);
            }
         }
         //执行拉流和推流
         ExecutorService executorService = new ThreadPoolExecutor(1, 1,
               0L, TimeUnit.MILLISECONDS,
               new LinkedBlockingQueue<Runnable>());
         executorService.execute(new Runnable() {
            @Override
            public void run() {
               JavaCVStreamUtil.push_hls(data.getUrl(), path, id, folderPath);
            }
         });
         resp.setServerIp(liveIp);
         resp.setServerPort(livePort);
//         live_hls(data.getUrl(), car);
//         resp.setServerIp(hlsIp);
//         resp.setServerPort(hlsPort);
         live_flv(data.getUrl(), car.getId());
         resp.setServerIp(flvIp);
         resp.setServerPort(flvHttpPort);
         return R.ok(resp);
      }
      return R.fail(startupAckVoR.getMsg());
      log.error("获取视频失败:{}", startupAckVoR.getMsg());
      return R.fail("获取视频失败");
   }
   public void live_hls(String input, Car car){
      String path = hlsOutputPath + "hls\\" + car.getVehicleNumber() + "\\live.m3u8";
      String folderPath = hlsOutputPath + "hls\\" + car.getVehicleNumber();
      FileUtil.mkParentDirs(path);
      File file = new File(path);
      if (!file.exists()) {
         try {
            file.createNewFile();
         } catch (IOException e) {
            throw new RuntimeException(e);
         }
      }
      //执行拉流和推流
      ExecutorService executorService = new ThreadPoolExecutor(1, 1,
            0L, TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<Runnable>());
      executorService.execute(new Runnable() {
         @Override
         public void run() {
            JavaCVStreamUtil.push_hls(input, path, car.getId(), folderPath);
         }
      });
      carService.taskPlayDetection(car.getId());
   }
   public void live_flv(String input, Integer id){
      String url = "rtmp://" + flvIp + ":" + flvRtmpPort + "/flv/" + id;
      //执行拉流和推流
      ExecutorService executorService = new ThreadPoolExecutor(1, 1,
            0L, TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<Runnable>());
      executorService.execute(new Runnable() {
         @Override
         public void run() {
            JavaCVStreamUtil.push_flv(input, url, id);
         }
      });
      carService.taskPlayDetection(id);
   }
}