From 1ee76c252f2dbba62e0ec34cccf9eaac51de9083 Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期三, 23 七月 2025 16:25:23 +0800 Subject: [PATCH] 修改bug --- ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CarServiceImpl.java | 70 ++++++++++++++++++++++++----------- 1 files changed, 48 insertions(+), 22 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 d5d2b6f..cd68ef1 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,6 +1,13 @@ package com.ruoyi.system.service.impl; +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; +import cn.hutool.http.HttpUtil; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.common.core.web.page.PageInfo; @@ -19,7 +26,6 @@ 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; @@ -31,8 +37,6 @@ 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; /** @@ -77,8 +81,13 @@ } List<Enterprise> list1 = enterpriseService.list(); List<Driver> driverList = driverService.list(new LambdaQueryWrapper<Driver>().eq(Driver::getStatus, 1)); + List<Car> list2 = this.list(); List<Car> carList = new ArrayList<>(); for (UPExgMsgRegisterVo vo : list) { + Optional<Car> first = list2.stream().filter(s -> s.getVehicleNumber().equals(vo.getVehicleNo())).findFirst(); + if(first.isPresent()){ + continue; + } car = new Car(); car.setVehicleNumber(vo.getVehicleNo()); car.setLicensePlateColor(VehicleColorEnum.getName(vo.getVehicleColor())); @@ -153,6 +162,7 @@ updateWrapper.set(Car::getDownlineTime, LocalDateTime.now()); } updateWrapper.set(Car::getStatus, 3); + updateWrapper.eq(Car::getId, car.getId()); this.update(updateWrapper); } else { String dateTime = gnssDataVo.getDate() + " " + gnssDataVo.getTime(); @@ -163,6 +173,7 @@ updateWrapper.set(Car::getDownlineTime, LocalDateTime.now()); } updateWrapper.set(Car::getStatus, 3); + updateWrapper.eq(Car::getId, car.getId()); this.update(updateWrapper); } else { if (car.getStatus() != 1) { @@ -170,6 +181,7 @@ updateWrapper.set(Car::getOnlineTime, LocalDateTime.now()); } updateWrapper.set(Car::getStatus, 1); + updateWrapper.eq(Car::getId, car.getId()); this.update(updateWrapper); } } @@ -177,26 +189,40 @@ } - /** - * 检测视频播放,清除没有播放的视频流 - */ - @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(); + + + + + public void taskGetCarDeviceId(){ + Object o = redisTemplate.opsForValue().get("chuzu:token"); + String access_Token = ""; + if(null == o){ + HttpRequest get = HttpUtil.createGet("http://116.169.59.170:9986/MediaAPI/Token?token=shehongchuzu"); + HttpResponse execute = get.execute(); + String body = execute.body(); + Integer expires_in = JSON.parseObject(body).getInteger("Expires_In"); + access_Token = JSON.parseObject(body).getString("Access_Token"); + redisTemplate.opsForValue().set("chuzu:token", access_Token, expires_in, TimeUnit.SECONDS); + } + //获取车辆数据 + List<Car> cars = this.list(new QueryWrapper<Car>().eq("enterprise_id", 5)); + HttpRequest get = HttpUtil.createGet("http://116.169.59.170:9986/MediaAPI/BaseInfo/GetVehicleInfo?accessToken=" + access_Token + "&tenantNo=射洪出租"); + HttpResponse execute = get.execute(); + String body = execute.body(); + JSONObject jsonObject = JSON.parseObject(body); + Integer resultState = jsonObject.getInteger("ResultState"); + if(null != resultState && 1 == resultState){ + JSONArray resultData = jsonObject.getJSONArray("ResultData"); + for (int i = 0; i < resultData.size(); i++) { + JSONObject jsonObject1 = resultData.getJSONObject(i); + String vehicleNo = jsonObject1.getString("VehicleNo"); + String Deviceid = jsonObject1.getString("Deviceid"); + cars.stream().filter(s->s.getVehicleNumber().equals(vehicleNo)).findFirst().ifPresent(car -> { + car.setDeviceId(Deviceid); + this.updateById(car); + }); + } } } - } -- Gitblit v1.7.1