Pu Zhibing
7 天以前 1ee76c252f2dbba62e0ec34cccf9eaac51de9083
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/OrderController.java
@@ -2,7 +2,6 @@
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.hutool.core.io.FileUtil;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.dataInterchange.api.feignClient.PlaybackMsgClient;
@@ -19,10 +18,10 @@
import com.ruoyi.system.service.IDriverService;
import com.ruoyi.system.service.IEnterpriseService;
import com.ruoyi.system.service.IOrderService;
import com.ruoyi.system.util.JavaCVStreamUtil;
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;
@@ -34,22 +33,19 @@
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
 * @author zhibing.pu
 * @Date 2025/3/24 17:50
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
@@ -150,6 +146,7 @@
         order.setDrivingLicenseNumber(driver.getDrivingLicenseNumber());
      }
      order.setVehicleNumber(car.getVehicleNumber());
      order.setDeviceId(car.getDeviceId());
      order.setEnterpriseName(enterprise.getName());
      return R.ok(order);
   }
@@ -182,7 +179,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());
      //手动加一次状态数据,避免定时任务结束任务线程
@@ -200,54 +197,15 @@
//         live_hls(data.getUrl(), car);
//         resp.setServerIp(hlsIp);
//         resp.setServerPort(hlsPort);
         live_flv(data.getUrl(), car.getId());
         resp.setUrl(data.getUrl());
//         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);
   }
}