‘liusuyi’
2023-07-01 ef0ed9877417b7efb3a6ec72121bee56720f6939
ard-work/src/main/java/com/ruoyi/alarm/globalAlarm/service/impl/GlobalAlarmServiceImpl.java
@@ -29,23 +29,20 @@
import com.ruoyi.utils.tools.GisTool;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.device.camera.domain.ArdCameras;
import com.ruoyi.device.camera.domain.CameraCmd;
import com.ruoyi.device.camera.mapper.ArdCamerasMapper;
import com.ruoyi.device.hiksdk.common.GlobalVariable;
import com.ruoyi.device.hiksdk.service.IHikClientService;
import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.utils.tube.GeoPoint;
import com.ruoyi.utils.tube.TubeTools;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.stream.Collectors;
/**
 * @Description: 全局报警业务
@@ -76,8 +73,6 @@
    private ISysConfigService configService;
    @Resource
    private ArdCamerasMapper ardCamerasMapper;
    @Resource
    private IHikClientService hikClientService;
    @Resource
    private RedisCache redisCache;
    @Resource
@@ -137,8 +132,7 @@
                                    .setCount(ardAlarmStealelec.getCount())
                                    .setTotal(ardAlarmStealelec.getTotal());
                            return globalAlarmData;
                        })
                        .collect(Collectors.toList());
                        }).collect(Collectors.toList());
            case 1002:
                List<ArdAlarmCamera> ardAlarmCameras = ardAlarmCameraMapper.selectListAllByCommand(refreshTime);
                return ardAlarmCameras.stream()
@@ -152,8 +146,7 @@
                                    .setCount(ardAlarmCamera.getCount())
                                    .setTotal(ardAlarmCamera.getTotal());
                            return globalAlarmData;
                        })
                        .collect(Collectors.toList());
                        }).collect(Collectors.toList());
            case 1003:
                List<ArdAlarmRadar> ardAlarmRadars = ardAlarmRadarMapper.selectListAllByCommand(refreshTime, "运动目标检测");
                return ardAlarmRadars.stream()
@@ -167,8 +160,7 @@
                                    .setCount(ardAlarmRadar.getCount())
                                    .setTotal(ardAlarmRadar.getTotal());
                            return globalAlarmData;
                        })
                        .collect(Collectors.toList());
                        }).collect(Collectors.toList());
            case 1004:
                ardAlarmRadars = ardAlarmRadarMapper.selectListAllByCommand(refreshTime, "热源检测");
                return ardAlarmRadars.stream()
@@ -182,8 +174,7 @@
                                    .setCount(ardAlarmRadar.getCount())
                                    .setTotal(ardAlarmRadar.getTotal());
                            return globalAlarmData;
                        })
                        .collect(Collectors.toList());
                        }).collect(Collectors.toList());
            case 1014:
                List<ArdAlarmTube> ardAlarmTubes = ardAlarmTubeMapper.selectListAllByCommand(refreshTime);
                return ardAlarmTubes.stream()
@@ -198,8 +189,7 @@
                                    .setCount(ardAlarmTube.getCount())
                                    .setTotal(ardAlarmTube.getTotal());
                            return globalAlarmData;
                        })
                        .collect(Collectors.toList());
                        }).collect(Collectors.toList());
            default:
                return null;
        }
@@ -224,38 +214,33 @@
                aas.setParams(params);
                aas.setPageNum(pageNum);
                aas.setPageSize(pageSize);
                List<ArdAlarmStealelec> ardAlarmStealelecs = ardAlarmStealelecMapper.selectArdAlarmStealelecList(aas);
                return ardAlarmStealelecs;
                return ardAlarmStealelecMapper.selectArdAlarmStealelecList(aas);
            case 1002:
                ArdAlarmCamera aac = new ArdAlarmCamera();
                aac.setParams(params);
                aac.setPageNum(pageNum);
                aac.setPageSize(pageSize);
                List<ArdAlarmCamera> ardAlarmCameras = ardAlarmCameraMapper.selectArdAlarmCameraList(aac);
                return ardAlarmCameras;
                return ardAlarmCameraMapper.selectArdAlarmCameraList(aac);
            case 1003:
                ArdAlarmRadar aar = new ArdAlarmRadar();
                aar.setParams(params);
                aar.setPageNum(pageNum);
                aar.setPageSize(pageSize);
                aar.setAlarmType("运动目标检测");
                List<ArdAlarmRadar> ardAlarmRadar = ardAlarmRadarMapper.selectArdAlarmRadarList(aar);
                return ardAlarmRadar;
                return ardAlarmRadarMapper.selectArdAlarmRadarList(aar);
            case 1004:
                ArdAlarmRadar aarr = new ArdAlarmRadar();
                aarr.setParams(params);
                aarr.setPageNum(pageNum);
                aarr.setPageSize(pageSize);
                aarr.setAlarmType("热源检测");
                List<ArdAlarmRadar> ardAlarmRadarr = ardAlarmRadarMapper.selectArdAlarmRadarList(aarr);
                return ardAlarmRadarr;
                return ardAlarmRadarMapper.selectArdAlarmRadarList(aarr);
            case 1014:
                ArdAlarmTube aat = new ArdAlarmTube();
                aat.setParams(params);
                aat.setPageNum(pageNum);
                aat.setPageSize(pageSize);
                List<ArdAlarmTube> ardAlarmTubes = ardAlarmTubeMapper.selectArdAlarmTubeList(aat);
                return ardAlarmTubes;
                return ardAlarmTubeMapper.selectArdAlarmTubeList(aat);
        }
        return null;
    }
@@ -277,7 +262,7 @@
                if (StringUtils.isNotNull(ardAlarmStealelec)) {
                    String describe = ardAlarmStealelec.getDescribe();
                    String startTime = fmt.format(ardAlarmStealelec.getStartTime());
                    int i = ardAlarmStealelecMapper.updateViewTimeByDescribe(describe, startTime, DateUtils.getTime());
                    ardAlarmStealelecMapper.updateViewTimeByDescribe(describe, startTime, DateUtils.getTime());
                    return ardAlarmStealelec;
                }
            case 1014:
@@ -285,7 +270,7 @@
                if (StringUtils.isNotNull(ardAlarmTube)) {
                    String tubeId = ardAlarmTube.getTubeId();
                    String alarmTime = fmt.format(ardAlarmTube.getAlarmTime());
                    int i = ardAlarmTubeMapper.updateViewTimeByTubeId(tubeId, alarmTime, DateUtils.getTime());
                    ardAlarmTubeMapper.updateViewTimeByTubeId(tubeId, alarmTime, DateUtils.getTime());
                    return ardAlarmTube;
                }
            default:
@@ -343,7 +328,13 @@
                    int aat = ardAlarmTubeMapper.insertArdAlarmTube(ardAlarmTube);
                    if (aat > 0) {
                        log.debug("tube入库成功:" + ardAlarmTube);
                        double[] coordinate=new double[]{ardAlarmTube.getLongitude(),ardAlarmTube.getLatitude()};
                        Double longitude = ardAlarmTube.getLongitude();
                        Double latitude = ardAlarmTube.getLatitude();
                        if(StringUtils.isNull(longitude)||StringUtils.isNull(latitude))
                        {
                            return;
                        }
                        double[] coordinate=new double[]{longitude,latitude};
                        String nearbyCameraId = getNearbyCamera(new double[]{ardAlarmTube.getLongitude(), ardAlarmTube.getLatitude()});
                        if (StringUtils.isNotEmpty(nearbyCameraId)) {
                            messagesEnqueued(nearbyCameraId, ardAlarmTube.getId(), "sys_tube_leak",ardAlarmTube.getCreateTime(), 1,1,coordinate);
@@ -400,8 +391,11 @@
                            ArdAlarmpointsWell ardAlarmpointsWell = ardAlarmpointsWellMapper.selectArdAlarmpointsWellByWellId(alarmpointName);
                            if(StringUtils.isNotNull(ardAlarmpointsWell) && StringUtils.isNotEmpty(ardAlarmpointsWell.getCameraId()))
                            {
                                String cameraId = ardAlarmpointsWell.getCameraId();
                                if(cameraIdWithTower.equals(cameraId))
                                {
                                    return;
                                }
                                log.info("获取到报警点关联的光电:"+cameraId);
                                //如果报警点关联了光电
                                messagesEnqueued(cameraId, uuid, alarmType,ardAlarmRadar.getCreateTime(), 1,2,coordinate);
@@ -414,7 +408,6 @@
                            if (count >= 3) {
                                ardAlarmRadar.setGuideFlag(1);
                                ardAlarmRadarMapper.insertArdAlarmRadar(ardAlarmRadar);
                                //获取雷达所在塔上的大光电
                                String cameraIdWithTower = ardAlarmRadarMapper.getCameraByRadar(radarAlarmData.getRadarId());
                                if (StringUtils.isNotNull(cameraIdWithTower) && StringUtils.isNotEmpty(cameraIdWithTower)) {
@@ -427,6 +420,10 @@
                                if(StringUtils.isNotNull(ardAlarmpointsWell) && StringUtils.isNotEmpty(ardAlarmpointsWell.getCameraId()))
                                {
                                    String cameraId = ardAlarmpointsWell.getCameraId();
                                    if(cameraIdWithTower.equals(cameraId))
                                    {
                                        return;
                                    }
                                    log.info("获取到报警点关联的光电:"+cameraId);
                                    //如果报警点关联了光电
                                    messagesEnqueued(cameraId, uuid, alarmType,ardAlarmRadar.getCreateTime(), count,2,coordinate);
@@ -519,4 +516,37 @@
        return minDistanceCameraId;
    }
    public static void main(String[] args) {
        Comparator<Obj> PriorityDescCom = Comparator.comparingInt(Obj::getPriority).reversed();
        Comparator<Obj> NumDescCom = Comparator.comparingInt(Obj::getNum).reversed();
        Comparator<Obj> receiveTimeAscCom = Comparator.comparing(Obj::getAlarmTime);
        Comparator<Obj> comparator = PriorityDescCom.thenComparing(NumDescCom).thenComparing(receiveTimeAscCom);
        PriorityBlockingQueue<Obj> priorityQueue = new PriorityBlockingQueue<>(1000,comparator);
        priorityQueue.add(new Obj(999,1,"2023-07-01 16:00:01"));
        priorityQueue.add(new Obj(999,2,"2023-07-01 16:00:01"));
        priorityQueue.add(new Obj(999,3,"2023-07-01 16:00:01"));
        List<Obj> elements = new ArrayList<>(priorityQueue);
        elements.sort(priorityQueue.comparator());  // 使用队列的比较器进行排序
        for (Obj task : elements) {
            log.info("正在排队【priority】" + task.getPriority()+"【num】" + task.getNum() + "【alarmTime】" + task.getAlarmTime());
        }
        log.info("===================================================================");
        priorityQueue.add(new Obj(999,5,"2023-07-01 16:00:01"));
        PriorityBlockingQueue queue = new PriorityBlockingQueue<>(priorityQueue);
        while (priorityQueue.size() > 0) {
            Obj task = priorityQueue.poll();
            log.info("正在排队【priority】" + task.getPriority()+"【num】" + task.getNum() + "【alarmTime】" + task.getAlarmTime());
        }
    }
    @Data
    @AllArgsConstructor
    static class Obj
    {
        Integer priority;
        Integer num;
        String alarmTime;
    }
}