From 2b4f8907a65c347400432c8db1bccb97c6a26d30 Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期五, 11 四月 2025 15:30:50 +0800 Subject: [PATCH] 修改视频播放bug --- ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CarServiceImpl.java | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 103 insertions(+), 4 deletions(-) diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CarServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CarServiceImpl.java index 2e30d27..71f10ed 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CarServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CarServiceImpl.java @@ -1,26 +1,39 @@ package com.ruoyi.system.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.common.core.web.page.PageInfo; import com.ruoyi.dataInterchange.api.feignClient.UPExgMsgRegisterClient; import com.ruoyi.dataInterchange.api.model.enums.VehicleColorEnum; +import com.ruoyi.dataInterchange.api.vo.GnssDataVo; import com.ruoyi.dataInterchange.api.vo.UPExgMsgRegisterVo; import com.ruoyi.system.api.model.Car; +import com.ruoyi.system.api.model.CarType; import com.ruoyi.system.api.model.Driver; import com.ruoyi.system.api.model.Enterprise; import com.ruoyi.system.mapper.CarMapper; import com.ruoyi.system.query.CarListReq; import com.ruoyi.system.query.CarListResp; import com.ruoyi.system.service.ICarService; +import com.ruoyi.system.service.ICarTypeService; import com.ruoyi.system.service.IDriverService; import com.ruoyi.system.service.IEnterpriseService; +import com.ruoyi.system.util.JavaCVStreamUtil; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.time.LocalDateTime; import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; +import java.util.Optional; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; /** * @author zhibing.pu @@ -28,6 +41,9 @@ */ @Service public class CarServiceImpl extends ServiceImpl<CarMapper, Car> implements ICarService { + + @Value("${live.hls.output-path}") + private String hlsOutputPath; @Resource private UPExgMsgRegisterClient upExgMsgRegisterClient; @@ -37,6 +53,12 @@ @Resource private IDriverService driverService; + + @Resource + private ICarTypeService carTypeService; + + @Resource + private RedisTemplate redisTemplate; /** @@ -54,6 +76,7 @@ return; } List<Enterprise> list1 = enterpriseService.list(); + List<Driver> driverList = driverService.list(new LambdaQueryWrapper<Driver>().eq(Driver::getStatus, 1)); List<Car> carList = new ArrayList<>(); for (UPExgMsgRegisterVo vo : list) { car = new Car(); @@ -61,15 +84,29 @@ car.setLicensePlateColor(VehicleColorEnum.getName(vo.getVehicleColor())); Enterprise enterprise = list1.stream().filter(s -> s.getCode().equals(vo.getInferiorPlatformId().toString())).findFirst().get(); car.setEnterpriseId(enterprise.getId()); - Driver driver = driverService.getOne(new LambdaQueryWrapper<Driver>().eq(Driver::getVehicleNumber, vo.getVehicleNo()).eq(Driver::getStatus, 1)); - if (null != driver) { - car.setDriverId(driver.getId()); + car.setOperateType(enterprise.getOperationType()); + Optional<Driver> optional = driverList.stream().filter(s -> s.getVehicleNumber().equals(vo.getVehicleNo())).findFirst(); + if (optional.isPresent()) { + car.setDriverId(optional.get().getId()); } car.setGpsModel(vo.getTerminalModelType()); car.setGpsImei(vo.getTerminalSIMCode()); + car.setLongitude(vo.getLongitude()); + car.setLatitude(vo.getLatitude()); + car.setCreateTime(LocalDateTime.now()); carList.add(car); } - this.saveBatch(carList); + if (carList.size() > 0) { + this.saveBatch(carList); + //更新车辆类型统计数据 + List<CarType> carTypeList = carTypeService.list(); + List<Car> cars = this.list(); + for (CarType carType : carTypeList) { + long count = cars.stream().filter(s -> s.getOperateType().equals(carType.getName())).count(); + carType.setCarNum(count); + } + carTypeService.updateBatchById(carTypeList); + } } @@ -84,4 +121,66 @@ PageInfo<CarListResp> pageInfo = new PageInfo<>(carListReq.getPageCurr(), carListReq.getPageSize()); return this.baseMapper.getCarList(pageInfo, carListReq); } + + + /** + * 定时任务修改车辆状态 + */ + @Override + public void taskUpdateCarStatus() { + List<Car> list = this.list(); + for (Car car : list) { + LambdaUpdateWrapper<Car> updateWrapper = new LambdaUpdateWrapper<>(); + GnssDataVo gnssDataVo = (GnssDataVo) redisTemplate.opsForValue().get("location:" + car.getVehicleNumber()); + if (null == gnssDataVo) { + if (car.getStatus() == 1) { + updateWrapper.set(Car::getDownlineTime, LocalDateTime.now()); + } + updateWrapper.set(Car::getStatus, 4); + this.update(updateWrapper); + } else { + String dateTime = gnssDataVo.getDate() + " " + gnssDataVo.getTime(); + LocalDateTime localDateTime = LocalDateTime.parse(dateTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); + long second = localDateTime.toEpochSecond(ZoneOffset.ofHours(8)); + if (System.currentTimeMillis() / 1000 > second + 60) { + if (car.getStatus() == 1) { + updateWrapper.set(Car::getDownlineTime, LocalDateTime.now()); + } + updateWrapper.set(Car::getStatus, 4); + this.update(updateWrapper); + } else { + if (car.getStatus() != 1) { + updateWrapper.set(Car::getDownlineTime, null); + updateWrapper.set(Car::getOnlineTime, LocalDateTime.now()); + } + updateWrapper.set(Car::getStatus, 1); + this.update(updateWrapper); + } + } + } + } + + + /** + * 检测视频播放,清除没有播放的视频流 + */ + @Override + public void taskPlayDetection(Integer deviceNumber) { + Car car = this.getById(deviceNumber); + try { + ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1); + executorService.scheduleWithFixedDelay(new Runnable() { + @Override + public void run() { + if(!redisTemplate.hasKey("live:" + car.getId())){ + String folderPath = hlsOutputPath + "hls\\" + car.getVehicleNumber(); + JavaCVStreamUtil.close(car.getId(), folderPath); + } + }}, 1, 1, TimeUnit.MINUTES); + }catch (Exception e){ + e.printStackTrace(); + } + } + + } -- Gitblit v1.7.1