From 81dd45819944baa8032d942e2e28c5c859c0cc81 Mon Sep 17 00:00:00 2001 From: ‘liusuyi’ <1951119284@qq.com> Date: 星期四, 15 六月 2023 10:37:46 +0800 Subject: [PATCH] 优化巡检 --- ard-work/src/main/java/com/ruoyi/alarm/globalAlarm/service/impl/GlobalAlarmServiceImpl.java | 159 +++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 111 insertions(+), 48 deletions(-) diff --git a/ard-work/src/main/java/com/ruoyi/alarm/globalAlarm/service/impl/GlobalAlarmServiceImpl.java b/ard-work/src/main/java/com/ruoyi/alarm/globalAlarm/service/impl/GlobalAlarmServiceImpl.java index 60dae1c..0405f7a 100644 --- a/ard-work/src/main/java/com/ruoyi/alarm/globalAlarm/service/impl/GlobalAlarmServiceImpl.java +++ b/ard-work/src/main/java/com/ruoyi/alarm/globalAlarm/service/impl/GlobalAlarmServiceImpl.java @@ -8,7 +8,6 @@ import com.ruoyi.alarm.stealAlarm.mapper.ArdAlarmStealelecMapper; import com.ruoyi.alarm.tubeAlarm.domain.ArdAlarmTube; import com.ruoyi.alarm.tubeAlarm.mapper.ArdAlarmTubeMapper; -import com.ruoyi.alarm.tubeAlarm.service.IArdAlarmTubeService; import com.ruoyi.alarmpoints.tube.domain.ArdTubes; import com.ruoyi.alarmpoints.tube.domain.ArdTubesDetails; import com.ruoyi.alarmpoints.tube.mapper.ArdTubesDetailsMapper; @@ -17,21 +16,26 @@ import com.ruoyi.alarmpoints.well.mapper.ArdAlarmpointsWellMapper; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.StringUtils; -import com.ruoyi.common.utils.uuid.UUID; +import com.ruoyi.common.utils.tools.ArdTool; +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.apache.poi.ss.formula.functions.T; 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.stream.Collectors; -import static jdk.nashorn.internal.runtime.regexp.joni.Config.log; /** * @ClassName: globalAlarmServiceImpl @@ -55,7 +59,10 @@ ArdTubesDetailsMapper ardTubesDetailsMapper; @Resource private ISysConfigService configService; - + @Resource + private ArdCamerasMapper ardCamerasMapper; + @Resource + private IHikClientService hikClientService; @Override public List<GlobalAlarmData> selectAlarmLogs(GlobalAlarmCondition condition) { String refreshTime = configService.selectConfigByKey("refreshTime"); @@ -124,49 +131,105 @@ @Override @Async("alarmExecutor") public void receiveAlarm(String topic, String message) { - String uuid = UUID.randomUUID().toString().replace("-", ""); - switch (topic) { - case "stealelec": - ArdAlarmStealelec ardAlarmStealelec = JSONObject.parseObject(message, ArdAlarmStealelec.class); - ardAlarmStealelec.setId(uuid); - ArdAlarmpointsWell well = ardAlarmpointsWellMapper.selectArdAlarmpointsWellByWellId(ardAlarmStealelec.getDescribe()); - if(well!=null) - { - ardAlarmStealelec.setLongitude(well.getLongitude()); - ardAlarmStealelec.setLatitude(well.getLatitude()); - ardAlarmStealelec.setDeptId(well.getDeptId()); - } - int insertaas = ardAlarmStealelecMapper.insert(ardAlarmStealelec); - if(insertaas>0) - { - log.info("stealelec鍏ュ簱鎴愬姛锛�" +ardAlarmStealelec); - } - break; - case "tube": - ArdAlarmTube ardAlarmTube = JSONObject.parseObject(message, ArdAlarmTube.class); - ardAlarmTube.setId(uuid); - ArdTubesDetails atd = new ArdTubesDetails(); - atd.setReelNumber(ardAlarmTube.getTubeId()); - List<ArdTubesDetails> ardTubesDetails = ardTubesDetailsMapper.selectArdTubesDetailsList(atd); - if (ardTubesDetails.size() > 0) { - String tubeId = ardTubesDetails.get(0).getTubeId(); - ArdTubes ardTubes = ardTubesMapper.selectArdTubesById(tubeId); - ardAlarmTube.setTubeName(ardTubes.getName()); - ardAlarmTube.setColor(ardTubes.getColor()); - ardAlarmTube.setPipeDiameter(ardTubes.getPipeDiameter()); - ardAlarmTube.setTubeType(ardTubes.getType()); - GeoPoint geoPoint = TubeTools.CalculateCoordinates(ardTubesDetails, ardAlarmTube.getPosition()); - if (StringUtils.isNotNull(geoPoint)) { - ardAlarmTube.setLongitude(geoPoint.getLongitude()); - ardAlarmTube.setLatitude(geoPoint.getLatitude()); - ardAlarmTube.setAltitude(geoPoint.getAltitude()); + try { + String simpleUUID = IdUtils.simpleUUID(); + switch (topic) { + case "stealelec": + 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()); } - } - int i = ardAlarmTubeMapper.insertArdAlarmTube(ardAlarmTube); - if (i > 0) { - log.info("tube鍏ュ簱鎴愬姛锛�" + ardAlarmTube); - } - break; + ArdAlarmStealelec existe = ardAlarmStealelecMapper.selectByPrimaryKey(ardAlarmStealelec.getId()); + if (StringUtils.isNotNull(existe)) { + return; + } + int aas = ardAlarmStealelecMapper.insert(ardAlarmStealelec); + if (aas > 0) { + log.info("stealelec鍏ュ簱鎴愬姛锛�" + ardAlarmStealelec); + } + break; + case "tube": + ArdAlarmTube ardAlarmTube = JSONObject.parseObject(message, ArdAlarmTube.class); + ardAlarmTube.setId(simpleUUID); + ArdTubesDetails atd = new ArdTubesDetails(); + atd.setReelNumber(ardAlarmTube.getTubeId()); + List<ArdTubesDetails> ardTubesDetails = ardTubesDetailsMapper.selectArdTubesDetailsList(atd); + if (ardTubesDetails.size() > 0) { + String tubeId = ardTubesDetails.get(0).getTubeId(); + ArdTubes ardTubes = ardTubesMapper.selectArdTubesById(tubeId); + ardAlarmTube.setTubeName(ardTubes.getName()); + ardAlarmTube.setColor(ardTubes.getColor()); + ardAlarmTube.setPipeDiameter(ardTubes.getPipeDiameter()); + ardAlarmTube.setTubeType(ardTubes.getType()); + GeoPoint geoPoint = TubeTools.CalculateCoordinates(ardTubesDetails, ardAlarmTube.getPosition()); + if (StringUtils.isNotNull(geoPoint)) { + ardAlarmTube.setLongitude(geoPoint.getLongitude()); + ardAlarmTube.setLatitude(geoPoint.getLatitude()); + ardAlarmTube.setAltitude(geoPoint.getAltitude()); + } + } + 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; + } + //鑾峰彇璺濈瀛楀吀涓渶杩戠殑涓�涓浉鏈篒D + String minDistanceCameraId = ArdTool.getKeyByMinValue(distanceMap); + //寮曞鍏夌數 + CameraCmd cmd = new CameraCmd(); + cmd.setCameraId(minDistanceCameraId); + cmd.setChannelNum(1); + cmd.setTargetPosition(new double[]{ardAlarmTube.getLongitude(), ardAlarmTube.getLatitude()}); + cmd.setOperator("sys_tube_leak"); + cmd.setExpired(30); + boolean guideRes = hikClientService.setTargetPosition(cmd); + if(guideRes) { + hikClientService.controlLock(cmd); + 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());//灏嗙浉鏈篿d涓庡綋鍓嶅鐞嗙嚎绋嬪悕绉扮粦瀹� + 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); + } + } + } + break; + } + } + catch (Exception ex) + { + log.error("鎺ユ敹鎶ヨ寮傚父:"+ex.getMessage()); } } /** -- Gitblit v1.9.3