| | |
| | | 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.core.redis.RedisCache; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.tools.ArdTool; |
| | | 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.config.MinioClientSingleton; |
| | | import com.ruoyi.device.hiksdk.service.IHikClientService; |
| | | import com.ruoyi.device.hiksdk.util.hikSdkUtil.GisUtil; |
| | | import com.ruoyi.system.service.ISysConfigService; |
| | | import com.ruoyi.utils.tube.GeoPoint; |
| | | import com.ruoyi.utils.tube.TubeTools; |
| | | 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.*; |
| | |
| | | private ArdCamerasMapper ardCamerasMapper; |
| | | @Resource |
| | | private IHikClientService hikClientService; |
| | | @Resource |
| | | private RedisCache redisCache; |
| | | /** |
| | | * @描述 按条件查询报警 |
| | | * @参数 [condition] |
| | | * @返回值 java.util.List<com.ruoyi.alarm.globalAlarm.domain.GlobalAlarmData> |
| | | * @创建人 刘苏义 |
| | | * @创建时间 2023/6/15 15:48 |
| | | * @修改人和其它信息 |
| | | */ |
| | | @Override |
| | | public List<GlobalAlarmData> selectAlarmLogs(GlobalAlarmCondition condition) { |
| | | String refreshTime = configService.selectConfigByKey("refreshTime"); |
| | |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @描述 按条件更新查看时间 |
| | | * @参数 [condition] |
| | | * @返回值 java.lang.Object |
| | | * @创建人 刘苏义 |
| | | * @创建时间 2023/6/15 15:48 |
| | | * @修改人和其它信息 |
| | | */ |
| | | @Override |
| | | public Object updateAlarmViewTime(GlobalAlarmCondition condition) { |
| | | SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | switch (condition.getCommand()) { |
| | | case 1001: |
| | | ArdAlarmStealelec ardAlarmStealelec = ardAlarmStealelecMapper.selectByPrimaryKey(condition.getId()); |
| | | if(StringUtils.isNotNull(ardAlarmStealelec)) { |
| | | if (StringUtils.isNotNull(ardAlarmStealelec)) { |
| | | String describe = ardAlarmStealelec.getDescribe(); |
| | | String startTime = fmt.format(ardAlarmStealelec.getStartTime()); |
| | | int i = ardAlarmStealelecMapper.updateViewTimeByDescribe(describe, startTime, DateUtils.getTime()); |
| | |
| | | } |
| | | case 1014: |
| | | ArdAlarmTube ardAlarmTube = ardAlarmTubeMapper.selectArdAlarmTubeById(condition.getId()); |
| | | if(StringUtils.isNotNull(ardAlarmTube)) { |
| | | if (StringUtils.isNotNull(ardAlarmTube)) { |
| | | String tubeId = ardAlarmTube.getTubeId(); |
| | | String alarmTime = fmt.format(ardAlarmTube.getAlarmTime()); |
| | | int i = ardAlarmTubeMapper.updateViewTimeByTubeId(tubeId, alarmTime, DateUtils.getTime()); |
| | | return ardAlarmTube; |
| | | } |
| | | default: return null; |
| | | default: |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @描述 异步处理接收的报警 |
| | | * @参数 [topic, message] |
| | | * @返回值 void |
| | | * @创建人 刘苏义 |
| | | * @创建时间 2023/6/15 15:46 |
| | | * @修改人和其它信息 |
| | | */ |
| | | @Override |
| | | @Async("alarmExecutor") |
| | | public void receiveAlarm(String topic, String message) { |
| | |
| | | String simpleUUID = IdUtils.simpleUUID(); |
| | | switch (topic) { |
| | | case "stealelec": |
| | | //region 处理盗电报警 |
| | | ArdAlarmStealelec ardAlarmStealelec = JSONObject.parseObject(message, ArdAlarmStealelec.class); |
| | | ArdAlarmpointsWell well = ardAlarmpointsWellMapper.selectArdAlarmpointsWellByWellId(ardAlarmStealelec.getDescribe()); |
| | | if (well != null) { |
| | | ardAlarmStealelec.setLongitude(well.getLongitude()); |
| | | ardAlarmStealelec.setLatitude(well.getLatitude()); |
| | | ardAlarmStealelec.setDeptId(well.getDeptId()); |
| | | ardAlarmStealelec.setAltitude(well.getAltitude()); |
| | | } |
| | | ArdAlarmStealelec existe = ardAlarmStealelecMapper.selectByPrimaryKey(ardAlarmStealelec.getId()); |
| | | if (StringUtils.isNotNull(existe)) { |
| | | return; |
| | | } |
| | | int aas = ardAlarmStealelecMapper.insert(ardAlarmStealelec); |
| | | int aas = ardAlarmStealelecMapper.insertArdAlarmStealelec(ardAlarmStealelec); |
| | | if (aas > 0) { |
| | | log.info("stealelec入库成功:" + ardAlarmStealelec); |
| | | //引导录像 |
| | | CameraCmd cmd = new CameraCmd(); |
| | | cmd.setRecordBucketName("record"); |
| | | cmd.setRecordObjectName("stealelec"); |
| | | cmd.setOperator("sys_steal_elec"); |
| | | cmd.setExpired(30); |
| | | cmd.setTargetPosition(new double[]{well.getLongitude(), well.getLatitude(), well.getAltitude()}); |
| | | String url = guideCamera(cmd); |
| | | if (StringUtils.isNotEmpty(url)) { |
| | | //更新录像 |
| | | ardAlarmStealelec.setRecordUrl(url); |
| | | ardAlarmStealelecMapper.updateArdAlarmStealelec(ardAlarmStealelec); |
| | | } |
| | | } |
| | | //endregion |
| | | break; |
| | | case "tube": |
| | | //region 处理管线泄露报警 |
| | | ArdAlarmTube ardAlarmTube = JSONObject.parseObject(message, ArdAlarmTube.class); |
| | | ardAlarmTube.setId(simpleUUID); |
| | | ArdTubesDetails atd = new ArdTubesDetails(); |
| | |
| | | } |
| | | int aat = ardAlarmTubeMapper.insertArdAlarmTube(ardAlarmTube); |
| | | if (aat > 0) { |
| | | log.info("tube入库成功:" + ardAlarmTube); |
| | | //查询所有大光电 |
| | | ArdCameras ardCamera = new ArdCameras(); |
| | | ardCamera.setGdtype("1"); |
| | | List<ArdCameras> ardCamerasList = ardCamerasMapper.selectArdCamerasList(ardCamera); |
| | | //统计所有大光电可视范围内与报警点的距离 |
| | | Map<String, Double> distanceMap = new HashMap<>(); |
| | | for (ArdCameras camera : ardCamerasList) { |
| | | double distance = GisUtil.getDistance(ardAlarmTube.getLongitude(), ardAlarmTube.getLatitude(), camera.getLongitude(), camera.getLatitude()); |
| | | if (distance <= camera.getCamMaxVisibleDistance()) { |
| | | distanceMap.put(camera.getId(), distance); |
| | | } |
| | | } |
| | | if(distanceMap.size()<0) |
| | | { |
| | | return; |
| | | } |
| | | //获取距离字典中最近的一个相机ID |
| | | String minDistanceCameraId = ArdTool.getKeyByMinValue(distanceMap); |
| | | //引导光电 |
| | | log.debug("tube入库成功:" + ardAlarmTube); |
| | | //引导录像 |
| | | CameraCmd cmd = new CameraCmd(); |
| | | cmd.setRecordBucketName("record"); |
| | | cmd.setRecordObjectName("tube"); |
| | | cmd.setOperator("sys_tube_leak"); |
| | | cmd.setCameraId(minDistanceCameraId); |
| | | cmd.setChannelNum(1); |
| | | cmd.setTargetPosition(new double[]{ardAlarmTube.getLongitude(), ardAlarmTube.getLatitude()}); |
| | | boolean guideRes = hikClientService.setTargetPosition(cmd); |
| | | if(guideRes) { |
| | | cmd.setEnable(true); |
| | | cmd.setRecordBucketName("record"); |
| | | String time = new SimpleDateFormat("yyyyMMdd").format(new Date()); |
| | | String recordName = minDistanceCameraId + "/" + time + "/" + simpleUUID + ".mp4"; |
| | | cmd.setRecordObjectName(recordName); |
| | | hikClientService.recordToMinio(cmd); |
| | | GlobalVariable.threadMap.put(minDistanceCameraId,Thread.currentThread().getName());//将相机id与当前处理线程名称绑定 |
| | | Thread.sleep(30000); |
| | | String thread = GlobalVariable.threadMap.get(minDistanceCameraId); |
| | | String currentThread = Thread.currentThread().getName(); |
| | | //判断相机绑定线程是否是当前线程,如果是,停止录像,如果不是,说明相机被其他线程抢占,不停止录像 |
| | | if(thread.equals(currentThread)) { |
| | | cmd.setEnable(false); |
| | | cmd.setUploadMinio(true); |
| | | hikClientService.recordToMinio(cmd); |
| | | //更新录像 |
| | | String url = MinioClientSingleton.domainUrl + "/" + cmd.getRecordBucketName() + "/" + recordName; |
| | | ardAlarmTube.setRecordUrl(url); |
| | | ardAlarmTubeMapper.updateArdAlarmTube(ardAlarmTube); |
| | | } |
| | | cmd.setExpired(30); |
| | | cmd.setTargetPosition(new double[]{ardAlarmTube.getLongitude(), ardAlarmTube.getLatitude(), ardAlarmTube.getAltitude()}); |
| | | String url = guideCamera(cmd); |
| | | //更新录像 |
| | | if (StringUtils.isNotEmpty(url)) { |
| | | ardAlarmTube.setRecordUrl(url); |
| | | ardAlarmTubeMapper.updateArdAlarmTube(ardAlarmTube); |
| | | } |
| | | } |
| | | //endregion |
| | | break; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | log.error("接收报警异常:"+ex.getMessage()); |
| | | } catch (Exception ex) { |
| | | log.error("接收报警异常:" + ex.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @描述 引导最近的大光电指向目标 |
| | | * @参数 [targetPosition] |
| | | * @返回值 java.lang.String |
| | | * @创建人 刘苏义 |
| | | * @创建时间 2023/6/15 11:55 |
| | | * @修改人和其它信息 |
| | | */ |
| | | private String guideCamera(CameraCmd cmd) { |
| | | String url = ""; |
| | | try { |
| | | String dayNightTime = redisCache.getCacheObject("sys_config:dayNightTime"); |
| | | //获取所有大光电 |
| | | List<ArdCameras> ardCamerasList = ardCamerasMapper.selectArdCamerasList(new ArdCameras("1")); |
| | | //统计所有大光电可视范围内与报警点的距离 |
| | | Map<String, Double> distanceMap = new HashMap<>(); |
| | | Map<String, Integer> guideMap = new HashMap<>(); |
| | | for (ArdCameras camera : ardCamerasList) { |
| | | double[] camPosition = new double[]{camera.getLongitude(), camera.getLatitude()}; |
| | | double distance = GisTool.getDistance(cmd.getTargetPosition(), camPosition); |
| | | if (distance != 0.0 && distance <= camera.getCamMaxVisibleDistance()) { |
| | | distanceMap.put(camera.getId(), distance); |
| | | if(StringUtils.isNull(camera.getCamAlarmGuideEnable())) |
| | | { |
| | | camera.setCamAlarmGuideEnable(0); |
| | | } |
| | | guideMap.put(camera.getId(),camera.getCamAlarmGuideEnable()); |
| | | } |
| | | } |
| | | if (distanceMap.size() > 0) { |
| | | log.debug("尝试查找最近光电"); |
| | | //获取距离字典中最近的一个相机ID |
| | | String minDistanceCameraId = ArdTool.getKeyByMinValue(distanceMap); |
| | | log.debug("查找到最近光电:"+minDistanceCameraId+",尝试引导"); |
| | | if(guideMap.get(minDistanceCameraId).equals(0)) |
| | | { |
| | | log.debug("该光电未开启报警引导"); |
| | | return ""; |
| | | } |
| | | //引导光电 |
| | | cmd.setCameraId(minDistanceCameraId); |
| | | cmd.setChannelNum(ArdTool.getChannelBydayNightTime(dayNightTime)); |
| | | boolean guideRes = hikClientService.guideTargetPosition(cmd); |
| | | if (guideRes) { |
| | | log.debug("引导成功,尝试录像"); |
| | | hikClientService.controlLock(cmd);//上锁 |
| | | cmd.setEnable(true);//开始录像 |
| | | hikClientService.recordToMinio(cmd);//开始录像 |
| | | GlobalVariable.threadMap.put(minDistanceCameraId, Thread.currentThread().getName());//将相机id与当前处理线程名称绑定 |
| | | Thread.sleep(cmd.getExpired() * 1000);//录像时长 |
| | | String thread = GlobalVariable.threadMap.get(minDistanceCameraId); |
| | | String currentThread = Thread.currentThread().getName(); |
| | | //判断相机绑定线程是否是当前线程,如果是,停止录像,如果不是,说明相机被其他线程抢占,不停止录像 |
| | | if (thread.equals(currentThread)) { |
| | | cmd.setEnable(false);//停止录像 |
| | | cmd.setUploadMinio(true);//上传minio |
| | | url = hikClientService.recordToMinio(cmd);//停止录像返回url |
| | | } |
| | | } |
| | | } else { |
| | | log.debug("未查找到最近光电"); |
| | | } |
| | | } catch (Exception ex) { |
| | | log.error("引导异常:" + ex.getMessage()); |
| | | } |
| | | return url; |
| | | } |
| | | |
| | | /** |
| | | * @描述 查询所有报警的当前数量 |
| | | * @参数 [] |
| | | * @返回值 java.util.Map<java.lang.String,java.lang.Integer> |
| | | * @返回值 java.util.Map<java.lang.String, java.lang.Integer> |
| | | * @创建人 刘苏义 |
| | | * @创建时间 2023/6/13 16:30 |
| | | * @修改人和其它信息 |
| | | */ |
| | | @Override |
| | | public Map<String, Integer> selectAlarmLogsCount() { |
| | | Map<String, Integer> countMap=new HashMap<>(); |
| | | Map<String, Integer> countMap = new HashMap<>(); |
| | | String refreshTime = configService.selectConfigByKey("refreshTime"); |
| | | int count1001 = ardAlarmStealelecMapper.selectCountByStartTime(refreshTime); |
| | | countMap.put("1001",count1001); |
| | | countMap.put("1001", count1001); |
| | | int count1014 = ardAlarmTubeMapper.selectCountByStartTime(refreshTime); |
| | | countMap.put("1014 ",count1014); |
| | | countMap.put("1014 ", count1014); |
| | | return countMap; |
| | | } |
| | | } |