From 93c20ce82e56710f7cf93789e7ac7a06153111a1 Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期三, 04 六月 2025 16:13:28 +0800
Subject: [PATCH] 优化附件

---
 ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/OrderController.java |  101 +++++++++++++++++++++++++++++++++++---------------
 1 files changed, 70 insertions(+), 31 deletions(-)

diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/OrderController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/OrderController.java
index 1c062f0..2e2b60b 100644
--- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/OrderController.java
+++ b/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")
@@ -141,6 +152,7 @@
 			order.setDrivingLicenseNumber(driver.getDrivingLicenseNumber());
 		}
 		order.setVehicleNumber(car.getVehicleNumber());
+		order.setDeviceId(car.getDeviceId());
 		order.setEnterpriseName(enterprise.getName());
 		return R.ok(order);
 	}
@@ -173,7 +185,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 +199,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);
+			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);
 	}
 }

--
Gitblit v1.7.1