‘liusuyi’
2023-07-12 18fa1385119350cebf6fb55a33a31fda263dba95
ard-work/src/main/java/com/ruoyi/alarm/globalAlarm/service/impl/GlobalAlarmServiceImpl.java
@@ -1,8 +1,12 @@
package com.ruoyi.alarm.globalAlarm.service.impl;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.alarm.accessAlarm.domain.ArdAlarmAccess;
import com.ruoyi.alarm.accessAlarm.mapper.ArdAlarmAccessMapper;
import com.ruoyi.alarm.cameraAlarm.domain.ArdAlarmCamera;
import com.ruoyi.alarm.cameraAlarm.mapper.ArdAlarmCameraMapper;
import com.ruoyi.alarm.externalAlarm.domain.ArdAlarmExternal;
import com.ruoyi.alarm.externalAlarm.mapper.ArdAlarmExternalMapper;
import com.ruoyi.alarm.globalAlarm.domain.GlobalAlarmCondition;
import com.ruoyi.alarm.globalAlarm.domain.GlobalAlarmData;
import com.ruoyi.alarm.globalAlarm.domain.GuidePriorityQueue;
@@ -21,21 +25,23 @@
import com.ruoyi.alarmpoints.tube.mapper.ArdTubesMapper;
import com.ruoyi.alarmpoints.well.domain.ArdAlarmpointsWell;
import com.ruoyi.alarmpoints.well.mapper.ArdAlarmpointsWellMapper;
import com.ruoyi.common.constant.CacheConstants;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.constant.CamPriority;
import com.ruoyi.device.external.domain.ArdEquipExternal;
import com.ruoyi.device.external.mapper.ArdEquipExternalMapper;
import com.ruoyi.utils.tools.ArdTool;
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;
@@ -46,10 +52,9 @@
import java.util.concurrent.PriorityBlockingQueue;
import java.util.stream.Collectors;
/**
 * @Description: 全局报警业务
 * @ClassName: globalAlarmServiceImpl
 * @Description:
 * @Author: Administrator
 * @Date: 2023年03月10日 11:03
 * @Version: 1.0
@@ -58,6 +63,12 @@
@Slf4j(topic = "mqtt")
public class GlobalAlarmServiceImpl implements IGlobalAlarmService {
    //region 依赖注入
    @Resource
    private ArdEquipExternalMapper ardEquipExternalMapper;
    @Resource
    private ArdAlarmAccessMapper ardAlarmAccessMapper;
    @Resource
    private ArdAlarmExternalMapper ardAlarmExternalMapper;
    @Resource
    private ArdAlarmRadarMapper ardAlarmRadarMapper;
    @Resource
@@ -76,8 +87,6 @@
    private ISysConfigService configService;
    @Resource
    private ArdCamerasMapper ardCamerasMapper;
    @Resource
    private IHikClientService hikClientService;
    @Resource
    private RedisCache redisCache;
    @Resource
@@ -105,6 +114,12 @@
        countMap.put("1003", count1003);
        int count1004 = ardAlarmRadarMapper.selectCountByAlarmTime(refreshTime, "热源检测");
        countMap.put("1004", count1004);
        int count1007 = ardAlarmRadarMapper.selectCountByAlarmTime(refreshTime, "雷达抽油机停机");
        countMap.put("1007", count1007);
        int count1005 = ardAlarmExternalMapper.selectCountByAlarmTime(refreshTime, "防区报警");
        countMap.put("1005", count1005);
        int count1006 = ardAlarmAccessMapper.selectCountByAlarmTime(refreshTime);
        countMap.put("1006", count1006);
        int count1014 = ardAlarmTubeMapper.selectCountByAlarmTime(refreshTime);
        countMap.put("1014", count1014);
        map.put("20000", countMap);
@@ -137,8 +152,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 +166,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 +180,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 +194,49 @@
                                    .setCount(ardAlarmRadar.getCount())
                                    .setTotal(ardAlarmRadar.getTotal());
                            return globalAlarmData;
                        })
                        .collect(Collectors.toList());
                        }).collect(Collectors.toList());
            case 1005:
                List<ArdAlarmExternal> ardAlarmExternals = ardAlarmExternalMapper.selectListAllByCommand(refreshTime, "防区报警");
                return ardAlarmExternals.stream()
                        .map(ardAlarmExternal -> {
                            GlobalAlarmData globalAlarmData = new GlobalAlarmData()
                                    .setId(ardAlarmExternal.getId())
                                    .setName(ardAlarmExternal.getAlarmName())
                                    .setAlarmTime(ardAlarmExternal.getAlarmTime())
                                    .setLongitude(ardAlarmExternal.getLongitude())
                                    .setLatitude(ardAlarmExternal.getLatitude())
                                    .setCount(ardAlarmExternal.getCount())
                                    .setTotal(ardAlarmExternal.getTotal());
                            return globalAlarmData;
                        }).collect(Collectors.toList());
            case 1006:
                List<ArdAlarmAccess> ardAlarmAccesses = ardAlarmAccessMapper.selectListAllByCommand(refreshTime);
                return ardAlarmAccesses.stream()
                        .map(ardAlarmAccess -> {
                            GlobalAlarmData globalAlarmData = new GlobalAlarmData()
                                    .setId(ardAlarmAccess.getId())
                                    .setName(ardAlarmAccess.getAcsName())
                                    .setAlarmTime(ardAlarmAccess.getAlarmTime())
                                    .setLongitude(ardAlarmAccess.getLongitude())
                                    .setLatitude(ardAlarmAccess.getLatitude())
                                    .setCount(ardAlarmAccess.getCount())
                                    .setTotal(ardAlarmAccess.getTotal());
                            return globalAlarmData;
                        }).collect(Collectors.toList());
            case 1007:
                ardAlarmRadars = ardAlarmRadarMapper.selectListAllByCommand(refreshTime, "雷达抽油机停机");
                return ardAlarmRadars.stream()
                        .map(ardAlarmRadar -> {
                            GlobalAlarmData globalAlarmData = new GlobalAlarmData()
                                    .setId(ardAlarmRadar.getId())
                                    .setName(ardAlarmRadar.getName())
                                    .setAlarmTime(ardAlarmRadar.getAlarmTime())
                                    .setLongitude(ardAlarmRadar.getLongitude())
                                    .setLatitude(ardAlarmRadar.getLatitude())
                                    .setCount(ardAlarmRadar.getCount())
                                    .setTotal(ardAlarmRadar.getTotal());
                            return globalAlarmData;
                        }).collect(Collectors.toList());
            case 1014:
                List<ArdAlarmTube> ardAlarmTubes = ardAlarmTubeMapper.selectListAllByCommand(refreshTime);
                return ardAlarmTubes.stream()
@@ -198,8 +251,7 @@
                                    .setCount(ardAlarmTube.getCount())
                                    .setTotal(ardAlarmTube.getTotal());
                            return globalAlarmData;
                        })
                        .collect(Collectors.toList());
                        }).collect(Collectors.toList());
            default:
                return null;
        }
@@ -224,38 +276,54 @@
                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 1007:
                ArdAlarmRadar aarrr = new ArdAlarmRadar();
                aarrr.setParams(params);
                aarrr.setPageNum(pageNum);
                aarrr.setPageSize(pageSize);
                aarrr.setAlarmType("雷达抽油机停机");
                return ardAlarmRadarMapper.selectArdAlarmRadarList(aarrr);
            case 1005:
                ArdAlarmExternal aae = new ArdAlarmExternal();
                aae.setParams(params);
                aae.setPageNum(pageNum);
                aae.setPageSize(pageSize);
                aae.setAlarmType("防区报警");
                return ardAlarmExternalMapper.selectArdAlarmExternalList(aae);
            case 1006:
                ArdAlarmAccess aaa = new ArdAlarmAccess();
                aaa.setParams(params);
                aaa.setPageNum(pageNum);
                aaa.setPageSize(pageSize);
                aaa.setAlarmType("防区报警");
                return ardAlarmAccessMapper.selectArdAlarmAccessList(aaa);
            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,15 +345,51 @@
                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 1002:
                ArdAlarmCamera ardAlarmCamera = ardAlarmCameraMapper.selectArdAlarmCameraById(condition.getId());
                if (StringUtils.isNotNull(ardAlarmCamera)) {
                    String cameraName = ardAlarmCamera.getCameraName();
                    String alarmTime = fmt.format(ardAlarmCamera.getAlarmTime());
                    ardAlarmCameraMapper.updateViewTimeByCameraName(cameraName, alarmTime, DateUtils.getTime());
                    return ardAlarmCamera;
                }
            case 1003:
            case 1004:
            case 1007:
                ArdAlarmRadar ardAlarmRadar = ardAlarmRadarMapper.selectArdAlarmRadarById(condition.getId());
                if (StringUtils.isNotNull(ardAlarmRadar)) {
                    String name = ardAlarmRadar.getName();
                    String alarmType = ardAlarmRadar.getAlarmType();
                    String alarmTime = fmt.format(ardAlarmRadar.getAlarmTime());
                    ardAlarmRadarMapper.updateViewTimeByCondition(name, alarmType, alarmTime, DateUtils.getTime());
                    return ardAlarmRadar;
                }
            case 1005:
                ArdAlarmExternal ardAlarmExternal = ardAlarmExternalMapper.selectArdAlarmExternalById(condition.getId());
                if (StringUtils.isNotNull(ardAlarmExternal)) {
                    String defenseName = ardAlarmExternal.getDefenseName();
                    String alarmType = ardAlarmExternal.getAlarmType();
                    String alarmTime = fmt.format(ardAlarmExternal.getAlarmTime());
                    ardAlarmExternalMapper.updateViewTimeByCondition(defenseName, alarmType, alarmTime, DateUtils.getTime());
                    return ardAlarmExternal;
                }
            case 1006:
                ArdAlarmAccess ardAlarmAccess = ardAlarmAccessMapper.selectArdAlarmAccessById(condition.getId());
                if (StringUtils.isNotNull(ardAlarmAccess)) {
                    String acsId = ardAlarmAccess.getAcsId();
                    String alarmTime = fmt.format(ardAlarmAccess.getAlarmTime());
                    ardAlarmAccessMapper.updateViewTimeByAcsId(acsId, alarmTime, DateUtils.getTime());
                    return ardAlarmAccess;
                }
            case 1014:
                ArdAlarmTube ardAlarmTube = ardAlarmTubeMapper.selectArdAlarmTubeById(condition.getId());
                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:
@@ -332,6 +436,7 @@
                        ardAlarmTube.setColor(ardTubes.getColor());
                        ardAlarmTube.setPipeDiameter(ardTubes.getPipeDiameter());
                        ardAlarmTube.setTubeType(ardTubes.getType());
                        ardAlarmTube.setCreateTime(new Date());
                        GeoPoint geoPoint = TubeTools.CalculateCoordinates(ardTubesDetails, ardAlarmTube.getPosition());
                        if (StringUtils.isNotNull(geoPoint)) {
                            ardAlarmTube.setLongitude(geoPoint.getLongitude());
@@ -342,10 +447,18 @@
                    int aat = ardAlarmTubeMapper.insertArdAlarmTube(ardAlarmTube);
                    if (aat > 0) {
                        log.debug("tube入库成功:" + ardAlarmTube);
                        String nearbyCamera = getNearbyCamera(new double[]{ardAlarmTube.getLongitude(), ardAlarmTube.getLatitude()});
                        if (StringUtils.isNotEmpty(nearbyCamera)) {
                            messagesEnqueued(nearbyCamera, ardAlarmTube.getId(), "sys_tube_leak", ardAlarmTube.getAlarmTime(), 1,1);
                        //region 引导录像
                        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);
                        }
                        //endregion
                    }
                    //endregion
                    break;
@@ -353,7 +466,6 @@
                    //region 处理通用光电报警
                    ArdAlarmCamera ardAlarmCamera = JSONObject.parseObject(message, ArdAlarmCamera.class);
                    ardAlarmCamera.setId(IdUtils.simpleUUID());
                    int aac = ardAlarmCameraMapper.insertArdAlarmCamera(ardAlarmCamera);
                    if (aac > 0) {
                        log.debug("camera入库成功:" + ardAlarmCamera);
@@ -366,11 +478,12 @@
                    List<ArdAlarmRadar> ardAlarmRadars = radarAlarmData.getArdAlarmRadars();
                    for (ArdAlarmRadar ardAlarmRadar : ardAlarmRadars) {
                        String uuid = IdUtils.simpleUUID();
                        ardAlarmRadar.setId(uuid);
                        ardAlarmRadar.setAlarmTime(radarAlarmData.getAlarmTime());
                        String name = ardAlarmRadar.getName() + "(" + radarAlarmData.getRadarName() + ")";
                        ardAlarmRadar.setName(name);
                        ardAlarmRadar.setCreateTime(new Date());
                        ardAlarmRadar.setId(uuid);//报警ID
                        ardAlarmRadar.setAlarmTime(radarAlarmData.getAlarmTime());//报警时间
                        String alarmpointName = ardAlarmRadar.getName();//兴趣点名称
                        ardAlarmRadar.setName(ardAlarmRadar.getName() + "(" + radarAlarmData.getRadarName() + ")");//报警点名称
                        ardAlarmRadar.setCreateTime(new Date());//接收时间
                        String alarmType = "";
                        switch (ardAlarmRadar.getAlarmType()) {
                            case "运动目标检测":
@@ -379,7 +492,19 @@
                            case "热源检测":
                                alarmType = "sys_radar_fire";
                                break;
                            case "雷达抽油机停机":
                                alarmType = "sys_radar_pumpshutdown";
                                ArdAlarmpointsWell ardAlarmpointsWell = ardAlarmpointsWellMapper.selectArdAlarmpointsWellByWellId(alarmpointName);
                                if (StringUtils.isNotNull(ardAlarmpointsWell)) {
                                    ardAlarmRadar.setLongitude(ardAlarmpointsWell.getLongitude());
                                    ardAlarmRadar.setLatitude(ardAlarmpointsWell.getLatitude());
                                }
                                break;
                        }
                        if (StringUtils.isNull(ardAlarmRadar.getLongitude()) || StringUtils.isNull(ardAlarmRadar.getLatitude())) {
                            continue;
                        }
                        double[] coordinate = new double[]{ardAlarmRadar.getLongitude(), ardAlarmRadar.getLatitude()};//报警坐标
                        //判断当前报警点5分钟内是否已引导
                        ardAlarmRadar.setGuideFlag(1);
                        ArdAlarmRadar AlarmRadar = ardAlarmRadarMapper.getArdAlarmRadarWithGuide(ardAlarmRadar);
@@ -389,8 +514,20 @@
                            //获取雷达所在塔上的大光电
                            String cameraIdWithTower = ardAlarmRadarMapper.getCameraByRadar(radarAlarmData.getRadarId());
                            if (StringUtils.isNotNull(cameraIdWithTower) && StringUtils.isNotEmpty(cameraIdWithTower)) {
                                //入队列待引导
                                messagesEnqueued(cameraIdWithTower, uuid, alarmType, ardAlarmRadar.getAlarmTime(), 1,1);
                                log.info("获取到雷达塔上的光电:" + cameraIdWithTower);
                                //如果雷达塔上有光电
                                messagesEnqueued(cameraIdWithTower, uuid, alarmType, ardAlarmRadar.getCreateTime(), 1, 1, coordinate);
                            }
                            //获取报警点关联的大光电
                            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);
                            }
                        } else {
                            //5分钟内有引导
@@ -400,20 +537,23 @@
                            if (count >= 3) {
                                ardAlarmRadar.setGuideFlag(1);
                                ardAlarmRadarMapper.insertArdAlarmRadar(ardAlarmRadar);
                                //获取雷达所在塔上的大光电
                                String cameraIdWithTower = ardAlarmRadarMapper.getCameraByRadar(radarAlarmData.getRadarId());
                                if (StringUtils.isNotNull(cameraIdWithTower) && StringUtils.isNotEmpty(cameraIdWithTower)) {
                                    log.info("获取到雷达塔上的光电:" + cameraIdWithTower);
                                    //如果雷达塔上有光电
                                    messagesEnqueued(cameraIdWithTower, uuid, alarmType, ardAlarmRadar.getAlarmTime(), count,1);
                                    messagesEnqueued(cameraIdWithTower, uuid, alarmType, ardAlarmRadar.getCreateTime(), count, 1, coordinate);
                                }
                                //获取报警点关联的大光电
                                ArdAlarmpointsWell ardAlarmpointsWell = ardAlarmpointsWellMapper.selectArdAlarmpointsWellByWellId(ardAlarmRadar.getName());
                                if(StringUtils.isNotNull(ardAlarmpointsWell) && StringUtils.isNotEmpty(ardAlarmpointsWell.getCameraId()))
                                {
                                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.getAlarmTime(), count,1);
                                    messagesEnqueued(cameraId, uuid, alarmType, ardAlarmRadar.getCreateTime(), count, 2, coordinate);
                                }
                            } else {
                                //未引导未超过3次,直接入库
@@ -423,46 +563,136 @@
                    }
                    //endregion
                    break;
                case "external":
                    //region 处理外联报警
                    ArdAlarmExternal ardAlarmExternal = JSONObject.parseObject(message, ArdAlarmExternal.class);
                    ardAlarmExternal.setId(IdUtils.simpleUUID());
                    ardAlarmExternal.setCreateTime(new Date());//接收时间
                    //外联防区名称就是兴趣点,查兴趣点坐标
                    String defenseName = ardAlarmExternal.getDefenseName();
                    ArdAlarmpointsWell ardAlarmpointsWell = ardAlarmpointsWellMapper.selectArdAlarmpointsWellByWellId(defenseName);
                    if (StringUtils.isNotNull(ardAlarmpointsWell)) {
                        ardAlarmExternal.setLongitude(ardAlarmpointsWell.getLongitude());
                        ardAlarmExternal.setLatitude(ardAlarmpointsWell.getLatitude());
                    }
                    int aae = ardAlarmExternalMapper.insertArdAlarmExternal(ardAlarmExternal);
                    if (aae > 0) {
                        log.debug("external入库成功:" + ardAlarmExternal);
                        //region 引导录像
                        if (StringUtils.isNull(ardAlarmExternal.getLongitude()) || StringUtils.isNull(ardAlarmExternal.getLatitude())) {
                            return;
                        }
                        double[] guideCoordinate = new double[]{ardAlarmExternal.getLongitude(), ardAlarmExternal.getLatitude()};//引导坐标
                        String nearbyCameraId = getNearbyCamera(guideCoordinate);//最近相机ID
                        if (StringUtils.isNotEmpty(nearbyCameraId)) {
                            messagesEnqueued(nearbyCameraId, ardAlarmExternal.getId(), "sys_external", ardAlarmExternal.getCreateTime(), 1, 1, guideCoordinate);
                        }
                        //endregion
                    }
                    //endregion
                    break;
                case "accessControl":
                    //region 处理门禁报警
                    ArdAlarmAccess ardAlarmAccess = JSONObject.parseObject(message, ArdAlarmAccess.class);
                    ardAlarmAccess.setId(IdUtils.simpleUUID());
                    ardAlarmAccess.setCreateTime(new Date());//接收时间
                    //查管理的门禁主机信息
                    String acsId = ardAlarmAccess.getAcsId();
                    ArdEquipExternal ardEquipExternal = ardEquipExternalMapper.selectArdEquipExternalById(acsId);
                    if (StringUtils.isNotNull(ardEquipExternal)) {
                        ardAlarmAccess.setLongitude(ardEquipExternal.getLongitude());
                        ardAlarmAccess.setLatitude(ardEquipExternal.getLatitude());
                        ardAlarmAccess.setAltitude(ardEquipExternal.getAltitude());
                        ardAlarmAccess.setAcsId(ardEquipExternal.getId());
                        ardAlarmAccess.setAcsName(ardEquipExternal.getName());
                    }
                    int aaa = ardAlarmAccessMapper.insertArdAlarmAccess(ardAlarmAccess);
                    if (aaa > 0) {
                        log.debug("external入库成功:" + ardAlarmAccess);
                        //region 引导录像
                        if (StringUtils.isNull(ardAlarmAccess.getLongitude()) || StringUtils.isNull(ardAlarmAccess.getLatitude())) {
                            return;
                        }
                        double[] guideCoordinate = new double[]{ardAlarmAccess.getLongitude(), ardAlarmAccess.getLatitude()};//引导坐标
                        String nearbyCameraId = getNearbyCamera(guideCoordinate);//最近相机ID
                        if (StringUtils.isNotEmpty(nearbyCameraId)) {
                            messagesEnqueued(nearbyCameraId, ardAlarmAccess.getId(), "sys_access_control", ardAlarmAccess.getCreateTime(), 1, 1, guideCoordinate);
                        }
                        //endregion
                    }
                    //endregion
                    break;
            }
            GuidePriorityQueue.printPriorityQueue();//打印队列
        } catch (Exception ex) {
            log.error("接收报警异常:" + ex.getMessage());
        }
    }
    /**
     * 消息入队
     * <p>
     * cameraId 相机ID
     * alarmId  报警ID
     * alarmType 报警类型
     * num  报警次数
     * recordSn 录像存储位置 1-recordUrl1 2-recordUrl2
     * targetPosition 报警点位置坐标
     */
    private void messagesEnqueued(String cameraId, String alarmId, String alarmType, Date alarmTime, Integer num, Integer recordSn) {
    private void messagesEnqueued(String cameraId, String alarmId, String alarmType, Date receiveTime, Integer num, Integer recordSn, double[] targetPosition) {
        try {
            if (!IsEnableGuide(cameraId)) {
                log.info("相机:" + cameraId + "未开启报警引导功能");
                return;
            }
        GuideTask guideTask = new GuideTask();
        /*配置相机ID*/
        guideTask.setCameraId(cameraId);
        /*根据配置时间配置通道*/
        String dayNightTime = redisCache.getCacheObject("sys_config:dayNightTime");
        Integer channel = ArdTool.getChannelBydayNightTime(dayNightTime);
        guideTask.setChanNum(channel);
        /*配置报警ID*/
        guideTask.setAlarmId(alarmId);
        /*配置报警时间*/
        SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        guideTask.setAlarmTime(fmt.format(alarmTime));
        /*配置报警优先级*/
        Integer priority = CamPriority.priorityMap.get(alarmType);
        guideTask.setPriority(priority);
        /*配置报警次数*/
        guideTask.setNum(num);
        /*配置录像存储位置*/
        guideTask.setRecordSn(recordSn);
        /*消息入队*/
        queueManager.addTaskToQueue(cameraId, guideTask);
//        PriorityBlockingQueue<GuideTask> priorityBlockingQueue = GuidePriorityQueue.cameraQueueMap.get(guideTask.getCameraId());
//        priorityBlockingQueue.add(guideTask);
            SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            GuideTask guideTask = new GuideTask();
            //相机ID
            guideTask.setCameraId(cameraId);
            //报警类型
            guideTask.setAlarmType(alarmType);
            //通道(通过日夜时间研判)
            String dayNightTime = redisCache.getCacheObject("sys_config:dayNightTime");
            Integer channel = ArdTool.getChannelBydayNightTime(dayNightTime);
            guideTask.setChanNum(channel);
            //报警ID
            guideTask.setAlarmId(alarmId);
            //接收时间
            guideTask.setReceiveTime(fmt.format(receiveTime));
            //报警优先级(通过优先级字典)
            Integer priority = CamPriority.priorityMap.get(alarmType);
            guideTask.setPriority(priority);
            //报警次数
            guideTask.setNum(num);
            //录像存储位置
            guideTask.setRecordSn(recordSn);
            //目标经纬度
            guideTask.setTargetPosition(targetPosition);
            //消息入队
            queueManager.addTaskToQueue(cameraId, guideTask);
            //打印队列
            GuidePriorityQueue.printPriorityQueue();
        } catch (Exception ex) {
            log.error("报警入队异常:" + ex.getMessage());
        }
    }
    /**
     * 查找附近开启报警引导功能光电
     * 光电是否开启报警引导功能
     * 刘苏义
     * 2023/7/7 14:03
     */
    private Boolean IsEnableGuide(String cameraId) {
        boolean enabled = false;
        ArdCameras ardCameras = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId);
        if (ardCameras.getCamAlarmGuideEnable().equals(1)) {
            enabled = true;
        }
        return enabled;
    }
    /**
     * 获取附近开启报警引导功能光电
     */
    private String getNearbyCamera(double[] targetPosition) {
        String minDistanceCameraId = "";
@@ -495,66 +725,37 @@
        return minDistanceCameraId;
    }
    /**
     * @描述 引导最近的大光电指向目标
     * @参数 [cmd]
     * @返回值 boolean
     * @创建人 刘苏义
     * @创建时间 2023/6/28 16:34
     * @修改人和其它信息
     */
    private boolean guideCamera(CameraCmd cmd) {
        try {
            String dayNightTime = redisCache.getCacheObject("sys_config:dayNightTime");
            String nearbyCamera = getNearbyCamera(cmd.getTargetPosition());
            if (StringUtils.isNotEmpty(nearbyCamera)) {
                //引导光电
                cmd.setCameraId(nearbyCamera);
                cmd.setChannelNum(ArdTool.getChannelBydayNightTime(dayNightTime));
                boolean guideRes = hikClientService.guideTargetPosition(cmd);
                return guideRes;
            } else {
                log.debug("未查找到最近光电");
                return false;
            }
        } catch (
                Exception ex) {
            log.error("引导异常:" + ex.getMessage());
            return false;
        }
    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 (queue.size() > 0) {
            Obj task = (Obj) queue.poll();
            log.info("正在排队【priority】" + task.getPriority() + "【num】" + task.getNum() + "【alarmTime】" + task.getAlarmTime());
        }
    }
    /**
     * @描述 报警录像
     * @参数 [cmd]
     * @返回值 java.lang.String
     * @创建人 刘苏义
     * @创建时间 2023/6/28 16:33
     * @修改人和其它信息
     */
    private String alarmToRecord(CameraCmd cmd) {
        String url = "";
        try {
            log.debug("引导成功,尝试录像");
            String cameraId = cmd.getCameraId();
            hikClientService.controlLock(cmd);//上锁
            cmd.setEnable(true);//开始录像
            hikClientService.recordToMinio(cmd);//开始录像
            GlobalVariable.threadMap.put(cameraId, Thread.currentThread().getName());//将相机id与当前处理线程名称绑定
            Thread.sleep(cmd.getExpired() * 1000);//录像时长
            String thread = GlobalVariable.threadMap.get(cameraId);
            String currentThread = Thread.currentThread().getName();
            //判断相机绑定线程是否是当前线程,如果是,停止录像,如果不是,说明相机被其他线程抢占,不停止录像
            if (thread.equals(currentThread)) {
                cmd.setEnable(false);//停止录像
                cmd.setUploadMinio(true);//上传minio
                url = hikClientService.recordToMinio(cmd);//停止录像返回url
            }
        } catch (Exception ex) {
            log.error("录像异常:" + ex.getMessage());
        }
        return url;
    @Data
    @AllArgsConstructor
    static class Obj {
        Integer priority;
        Integer num;
        String alarmTime;
    }
}