Pu Zhibing
2025-03-03 05df94f5658524d5c404415ab63e95bc139d8b3f
修改模型3的bug
4个文件已修改
1个文件已添加
155 ■■■■■ 已修改文件
guns-admin/src/main/java/com/stylefeng/guns/modular/api/PatrolTaskController.java 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/PatrolTaskServiceImpl.java 103 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/videoGateway/VideoGateway.java 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-admin/src/main/java/com/stylefeng/guns/modular/system/warpper/VehicleSpeed.java 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-admin/src/main/resources/application.yml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
guns-admin/src/main/java/com/stylefeng/guns/modular/api/PatrolTaskController.java
@@ -1,5 +1,6 @@
package com.stylefeng.guns.modular.api;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.JwtConstants;
@@ -15,9 +16,11 @@
import com.stylefeng.guns.modular.system.util.videoGateway.VideoGateway;
import com.stylefeng.guns.modular.system.util.videoGateway.model.Ship;
import com.stylefeng.guns.modular.system.util.videoGateway.model.Vehicle;
import com.stylefeng.guns.modular.system.warpper.VehicleSpeed;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@@ -29,6 +32,7 @@
 * @author zhibing.pu
 * @Date 2024/12/17 20:18
 */
@Slf4j
@RestController
@RequestMapping("")
public class PatrolTaskController extends BaseController {
@@ -226,7 +230,7 @@
    }
    
    
    @PutMapping("/base/patrolTask/vehicleSpeed")
    @PostMapping("/base/patrolTask/vehicleSpeed")
    @ApiOperation(value = "变更车辆状态", tags = {"互联互通接口"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "车牌号", name = "vehicleNum", dataType = "String", required = true),
@@ -237,8 +241,10 @@
            @ApiImplicitParam(value = "纬度", name = "latitude", dataType = "double", required = true),
            @ApiImplicitParam(value = "经度", name = "longitude", dataType = "double", required = true),
    })
    public ResultUtil vehicleSpeed(String vehicleNum, Integer vehicleStatus, Integer vehicleType, String communicationNum, String vehicleGpsProtocol, Double latitude, Double longitude){
        patrolTaskService.vehicleSpeed(vehicleNum, vehicleStatus, vehicleType, communicationNum, vehicleGpsProtocol, latitude, longitude);
    public ResultUtil vehicleSpeed(@RequestBody VehicleSpeed vehicleSpeed){
        log.info("推送车辆状态:{}", JSON.toJSONString(vehicleSpeed));
        patrolTaskService.vehicleSpeed(vehicleSpeed.getVehicleNum(), vehicleSpeed.getVehicleStatus(), vehicleSpeed.getVehicleType(),
                vehicleSpeed.getCommunicationNum(), vehicleSpeed.getVehicleGpsProtocol(), vehicleSpeed.getLatitude(), vehicleSpeed.getLongitude());
        return ResultUtil.success();
    }
}
guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/PatrolTaskServiceImpl.java
@@ -281,8 +281,6 @@
                                            //2018 协议
                                            String fileId = VideoGateway.cameraShot2018(terminalId, videoChannel, 0);
                                            if(ToolUtil.isNotEmpty(fileId)){
                                                //等待30秒
                                                Thread.sleep(30000);
                                                String fileUrl = VideoGateway.getCameraShotByFileId2018(terminalId, fileId, 0);
                                                if(ToolUtil.isNotEmpty(fileUrl)){
                                                    taskDetailVehiclesChannel.setImageUrl(fileUrl);
@@ -301,8 +299,6 @@
                                            //2023 协议
                                            String fileId = VideoGateway.cameraShot2023(vehicleId, vehicleType, terminalId, videoChannel, 0);
                                            if(ToolUtil.isNotEmpty(fileId)){
                                                //等待30秒
                                                Thread.sleep(30000);
                                                String fileUrl = VideoGateway.getCameraShotByFileId2023(fileId, 0);
                                                if(ToolUtil.isNotEmpty(fileUrl)){
                                                    taskDetailVehiclesChannel.setImageUrl(fileUrl);
@@ -347,6 +343,105 @@
            int count = taskDetailVehiclesService.selectCount(new EntityWrapper<TaskDetailVehicles>().eq("task_detail_id", id).eq("status", 5));
            taskDetail.setStatus(count > 0 ? 4 : 3);
            taskDetailService.updateById(taskDetail);
        }else{
            //只处理不在线的车辆
            //获取所有在线车船
            //2018年协议车辆在线
            List<VehicleOnline> vehicleOnlines2018 = VideoGateway.queryRuntimeInfoByCache(0);
            //2023年协议车辆在线
            List<VehicleOnline> vehicleOnlines203 = VideoGateway.locationRealTimeInfoCache(0);
            //获取当前任务中的车船信息
            List<TaskDetailVehicles> taskDetailVehicles = taskDetailVehiclesService.selectList(new EntityWrapper<TaskDetailVehicles>().eq("task_detail_id", id));
            //根据车辆数量,分组线程数
            int num;
            int threadCount;
            if(taskDetailVehicles.size() <= maxThreadCount){
                threadCount = taskDetailVehicles.size();
                num = 1;
            }else{
                num = taskDetailVehicles.size() / maxThreadCount;
                if(taskDetailVehicles.size() % maxThreadCount > 0){
                    num++;
                }
                threadCount = taskDetailVehicles.size() / num;
                if(taskDetailVehicles.size() % num > 0){
                    threadCount++;
                }
            }
            //定义线程池
            ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(threadCount, threadCount, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
            //定义多线程阻塞
            CountDownLatch countDownLatch = new CountDownLatch(threadCount);
            for (int i = 0; i < threadCount; i++) {
                int start = i * num;
                int end = (i + 1) * num;
                if((i + 1) == threadCount){
                    end = taskDetailVehicles.size();
                }
                List<TaskDetailVehicles> vehicles = taskDetailVehicles.subList(start, end);
                threadPoolExecutor.execute(new Runnable() {
                    @Override
                    public void run() {
                        for (TaskDetailVehicles taskDetailVehicle : vehicles) {
                            try {
                                taskDetailVehicle.setStartExecutionTime(LocalDateTime.now());
                                Integer taskDetailVehicleId = taskDetailVehicle.getId();
                                //车船类型:1 车辆设备 2 船舶设备
                                Integer vehicleType = taskDetailVehicle.getVehicleType();
                                //车船id
                                Integer vehicleId = taskDetailVehicle.getVehicleId();
                                VehicleOnline vehicleOnline1 = null;
                                for (VehicleOnline vehicleOnline : vehicleOnlines2018) {
                                    if(null != vehicleOnline.getVehicleId() && vehicleOnline.getVehicleId().equals(vehicleId) &&
                                            null != vehicleOnline.getVehicleType() && vehicleOnline.getVehicleType().equals(vehicleType)){
                                        vehicleOnline1 = vehicleOnline;
                                        String vehicleGpsProtocol = vehicleOnline.getVehicleGpsProtocol();
                                        vehicleOnline1.setVehicleGpsProtocol("808-guangzhou".equals(vehicleGpsProtocol) ? "1" : "2");
                                        break;
                                    }
                                }
                                if(null == vehicleOnline1){
                                    for (VehicleOnline vehicleOnline : vehicleOnlines203) {
                                        if(null != vehicleOnline.getVehicleId() && vehicleOnline.getVehicleId().equals(vehicleId) &&
                                                null != vehicleOnline.getVehicleType() && vehicleOnline.getVehicleType().equals(vehicleType)){
                                            vehicleOnline1 = vehicleOnline;
                                            vehicleOnline1.setVehicleGpsProtocol(vehicleOnline.getVehicleGpsProtocol());
                                            break;
                                        }
                                    }
                                }
                                //不在线
                                if(null == vehicleOnline1){
                                    taskDetailVehicle.setEndExecutionTime(LocalDateTime.now());
                                    taskDetailVehicle.setStatus(4);
                                    taskDetailVehiclesService.updateById(taskDetailVehicle);
                                }
                            }catch (Exception e){
                                e.printStackTrace();
                                //失败
                                taskDetailVehicle.setEndExecutionTime(LocalDateTime.now());
                                taskDetailVehicle.setStatus(5);
                                taskDetailVehiclesService.updateById(taskDetailVehicle);
                            }
                        }
                        //当前线程执行完成后减少等待数
                        countDownLatch.countDown();
                    }
                });
            }
            try {
                countDownLatch.await();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            int count = taskDetailVehiclesService.selectCount(new EntityWrapper<TaskDetailVehicles>().eq("task_detail_id", id).in("status", Arrays.asList(1, 2)));
            if(count == 0){
                count = taskDetailVehiclesService.selectCount(new EntityWrapper<TaskDetailVehicles>().eq("task_detail_id", id).eq("status", 5));
                taskDetail.setStatus(count > 0 ? 4 : 3);
                taskDetailService.updateById(taskDetail);
            }
        }
        
    }
guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/videoGateway/VideoGateway.java
@@ -417,13 +417,13 @@
        //图片地址
        String data = result.getString("data");
        if(ToolUtil.isEmpty(data)){
            if(num == 12){
            if(num == 60){
                log.error(result.getString("msg"));
                throw new RuntimeException("【2018年协议车辆获取拍摄图片】12次(1分钟)失败:" + execute.body());
                throw new RuntimeException("【2018年协议车辆获取拍摄图片】60次(1分钟)失败:" + execute.body());
            }
            num++;
            try {
                Thread.sleep(5000);
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
@@ -468,13 +468,13 @@
        //图片地址
        String data = result.getString("data");
        if(ToolUtil.isEmpty(data)){
            if(num == 12){
            if(num == 60){
                log.error(result.getString("msg"));
                throw new RuntimeException("【2023年协议车辆获取拍摄图片】12次(1分钟)失败:" + execute.body());
                throw new RuntimeException("【2023年协议车辆获取拍摄图片】60次(1分钟)失败:" + execute.body());
            }
            num++;
            try {
                Thread.sleep(5000);
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
guns-admin/src/main/java/com/stylefeng/guns/modular/system/warpper/VehicleSpeed.java
New file
@@ -0,0 +1,24 @@
package com.stylefeng.guns.modular.system.warpper;
import lombok.Data;
/**
 * @author zhibing.pu
 * @Date 2025/3/3 16:45
 */
@Data
public class VehicleSpeed {
    private String vehicleNum;
    private Integer vehicleStatus;
    private Integer vehicleType;
    private String communicationNum;
    private String vehicleGpsProtocol;
    private Double latitude;
    private Double longitude;
}
guns-admin/src/main/resources/application.yml
@@ -12,7 +12,7 @@
spring:
  redis:
    database: 0
    host: 139.129.201.21
    host: 10.25.14.40
    port: 6379
    password: 34b7b13ce8a711e4:chengshI2014
@@ -109,4 +109,4 @@
            
---
# 任务执行最大线程数
maxThreadCount: 20
maxThreadCount: 50