From b31091da56446f57d21c41d009ce7b55a70a9789 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期四, 19 六月 2025 11:59:31 +0800
Subject: [PATCH] 优化报警

---
 ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/CarController.java |  170 +++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 107 insertions(+), 63 deletions(-)

diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/CarController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/CarController.java
index f5d89b4..e8e139c 100644
--- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/CarController.java
+++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/CarController.java
@@ -5,6 +5,7 @@
 import com.ruoyi.common.core.domain.R;
 import com.ruoyi.common.core.utils.StringUtils;
 import com.ruoyi.common.core.web.page.PageInfo;
+import com.ruoyi.dataInterchange.api.feignClient.HaiKangClient;
 import com.ruoyi.dataInterchange.api.feignClient.PlaybackMsgClient;
 import com.ruoyi.dataInterchange.api.feignClient.RealVideoMsgClient;
 import com.ruoyi.dataInterchange.api.feignClient.UPExgMsgRealLocationClient;
@@ -52,14 +53,23 @@
 @RequestMapping("/car")
 public class CarController {
 	
-	@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;
 	@Resource
 	private ICarService carService;
 	@Resource
@@ -76,6 +86,9 @@
 	private ICarTypeService carTypeService;
 	@Resource
 	private RedisTemplate redisTemplate;
+	
+	@Resource
+	private HaiKangClient haiKangClient;
 	
 	@GetMapping("/getCarList")
 	@ApiOperation(value = "获取车辆列表", tags = {"车辆管理"})
@@ -98,6 +111,7 @@
 		Driver driver = driverService.getOne(new LambdaQueryWrapper<Driver>().eq(Driver::getVehicleNumber, car.getVehicleNumber()).eq(Driver::getStatus, 1));
 		Enterprise enterprise = enterpriseService.getById(car.getEnterpriseId());
 		car.setEnterpriseName(enterprise.getName());
+		car.setCompanyCode(enterprise.getCode());
 		if (null != driver) {
 			car.setDriverName(driver.getName());
 			car.setDriverPhone(driver.getPhone());
@@ -115,43 +129,37 @@
 	public R<RealVideoResp> getRealVideo(@PathVariable("id") Integer id) {
 		Car car = carService.getById(id);
 		if (null == car) {
-			return R.fail("失败");
+			return R.fail("车辆信息获取失败");
 		}
 		//手动加一次状态数据,避免定时任务结束任务线程
 		redisTemplate.opsForValue().set("live:" + id, true, 1, TimeUnit.MINUTES);
 		Enterprise enterprise = enterpriseService.getById(car.getEnterpriseId());
-		R<UPRealvideoMsgStartupAckVo> msgStartupAckVoR = realVideoMsgClient.startupRealVideo(Integer.valueOf(enterprise.getCode()), car.getVehicleNumber());
-		if (200 == msgStartupAckVoR.getCode()) {
-			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);
-				}
+		//富临走协议返回flv格式视频流
+		if(enterprise.getCode().equals("17458936")){
+			R<UPRealvideoMsgStartupAckVo> msgStartupAckVoR = realVideoMsgClient.startupRealVideo(Integer.valueOf(enterprise.getCode()), car.getVehicleNumber());
+			if (200 == msgStartupAckVoR.getCode()) {
+				UPRealvideoMsgStartupAckVo data = msgStartupAckVoR.getData();
+				
+				RealVideoResp resp = new RealVideoResp();
+				resp.setCompanyCode(enterprise.getCode());
+				//执行拉流和推流
+//			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);
 			}
-			
-			UPRealvideoMsgStartupAckVo data = msgStartupAckVoR.getData();
+		}else if(enterprise.getCode().equals("25439966")){
+			//海康走API获取预览url,trsp格式
+			String data = haiKangClient.getCarPreviewURLs(car.getVehicleNumber()).getData();
 			RealVideoResp resp = new RealVideoResp();
-			//执行拉流和推流
-			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);
+			resp.setUrl(data);
 			return R.ok(resp);
 		}
-		
-		return R.fail(msgStartupAckVoR.getMsg());
+		return R.ok();
 	}
 	
 	
@@ -165,7 +173,7 @@
 		if (null == car) {
 			return R.fail("失败");
 		}
-		String folderPath = outputPath + "hls\\" + car.getVehicleNumber();
+		String folderPath = hlsOutputPath + "hls\\" + car.getVehicleNumber();
 		JavaCVStreamUtil.close(id, folderPath);
 		return R.ok();
 	}
@@ -197,30 +205,14 @@
 		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, req.getId(), 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());
@@ -262,7 +254,7 @@
 	@GetMapping("/getCarTypeList")
 	@ApiOperation(value = "获取车辆类型列表数据", tags = {"车辆类型"})
 	public R<List<CarType>> getCarTypeList(String name) {
-		List<CarType> list = carTypeService.list(new LambdaQueryWrapper<CarType>().like(StringUtils.isNotEmpty(name), CarType::getName, name));
+		List<CarType> list = carTypeService.list(new LambdaQueryWrapper<CarType>().like(StringUtils.isNotEmpty(name), CarType::getName, name).orderByAsc(CarType::getSort));
 		return R.ok(list);
 	}
 	
@@ -270,7 +262,7 @@
 	@GetMapping("/getCarCount")
 	@ApiOperation(value = "获取各种车辆类型车辆总数", tags = {"首页"})
 	public R<List<CarType>> getCarCount() {
-		List<CarType> list = carTypeService.list();
+		List<CarType> list = carTypeService.list(new LambdaQueryWrapper<CarType>().orderByAsc(CarType::getSort));
 		return R.ok(list);
 	}
 	
@@ -302,15 +294,67 @@
 	public R<List<Car>> getMapCarList() {
 		List<Car> list = carService.list(new LambdaQueryWrapper<Car>().eq(Car::getStatus, 1));
 		for (Car car : list) {
-			Long s = (null == car.getDownlineTime() ? LocalDateTime.now() : car.getDownlineTime()).toEpochSecond(ZoneOffset.ofHours(8)) - car.getOnlineTime().toEpochSecond(ZoneOffset.ofHours(8));
-			car.setDrivingTime(s / 60);
+			car.setDrivingTime(0L);
+			if(null != car.getOnlineTime()){
+				Long s = (null == car.getDownlineTime() ? LocalDateTime.now() : car.getDownlineTime()).toEpochSecond(ZoneOffset.ofHours(8)) - car.getOnlineTime().toEpochSecond(ZoneOffset.ofHours(8));
+				car.setDrivingTime(s / 60);
+			}
 			GnssDataVo gnssDataVo = (GnssDataVo) redisTemplate.opsForValue().get("location:" + car.getVehicleNumber());
 			if (null != gnssDataVo) {
 				car.setLongitude(new BigDecimal(gnssDataVo.getLon()).divide(new BigDecimal(1000000)).toString());
 				car.setLatitude(new BigDecimal(gnssDataVo.getLat()).divide(new BigDecimal(1000000)).toString());
 				car.setSpeed(gnssDataVo.getVec1());
 			}
+			Enterprise enterprise = enterpriseService.getById(car.getEnterpriseId());
+			car.setEnterpriseName(enterprise.getName());
+			car.setCompanyCode(enterprise.getCode());
 		}
 		return R.ok(list);
 	}
+	
+	
+	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