From 417dc8b3dd885e35712cf87af85b43b8de4ea77f Mon Sep 17 00:00:00 2001 From: tiger_zhou Date: Wed, 20 Sep 2023 17:11:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xiannccda/alert/AlertListenerJob.java | 2 +- .../xiannccda/service/AlertMockService.java | 12 ++--- .../xiannccda/service/AlertRecordService.java | 50 +++++++++++++------ 3 files changed, 41 insertions(+), 23 deletions(-) diff --git a/src/main/java/club/joylink/xiannccda/alert/AlertListenerJob.java b/src/main/java/club/joylink/xiannccda/alert/AlertListenerJob.java index 7267732..0508bc8 100644 --- a/src/main/java/club/joylink/xiannccda/alert/AlertListenerJob.java +++ b/src/main/java/club/joylink/xiannccda/alert/AlertListenerJob.java @@ -44,7 +44,7 @@ public class AlertListenerJob implements ApplicationRunner { @Override public void accept(NccAlertInfo alertInfo) { - /*if (!alertInfo.isMock()) { +/* if (!alertInfo.isMock()) { AlertRecord record = convertToRecord(alertInfo); alertRecordRepository.save(record); alertInfo.setId(record.getId()); diff --git a/src/main/java/club/joylink/xiannccda/service/AlertMockService.java b/src/main/java/club/joylink/xiannccda/service/AlertMockService.java index 8f6d74f..a5acf76 100644 --- a/src/main/java/club/joylink/xiannccda/service/AlertMockService.java +++ b/src/main/java/club/joylink/xiannccda/service/AlertMockService.java @@ -110,7 +110,7 @@ public class AlertMockService { bb.setTimestamp(System.currentTimeMillis() / 1000); bb.setId(dto.getFrist()); bb.setIpRtuStusDown(true); - return this.alertInfoService.createAlert(dto.getAlertType(), AlertDeviceType.DEVICE_TYPE_RTU, station.getCommon().getId(), bb, station.getName(), AlertDeviceType.DEVICE_TYPE_RTU, false); + return this.alertInfoService.createAlert(dto.getAlertType(), AlertDeviceType.DEVICE_TYPE_RTU, station.getCommon().getId(), bb, station.getName(), AlertDeviceType.DEVICE_TYPE_RTU, true); } case PLATFORM_DOOR_CANNOT_OPEN -> { Optional pfOptional = LineGraphicDataRepository.getDevices(lineId, Platform.class).filter(d -> dto.getDeviceCodes().contains(d.getCode())).findAny(); @@ -121,7 +121,7 @@ public class AlertMockService { platform.setTimestamp(System.currentTimeMillis() / 1000); Platform pf = pfOptional.orElse(null); return this.alertInfoService.createAlert(dto.getAlertType(), AlertDeviceType.DEVICE_TYPE_PLATFORM, pf.getCommon().getId(), platform, platform.getId(), AlertDeviceType.DEVICE_TYPE_PLATFORM, - false); + true); } case PLATFORM_DOOR_CANNOT_CLOSE -> { Optional pfOptional = LineGraphicDataRepository.getDevices(lineId, Platform.class).filter(d -> dto.getDeviceCodes().contains(d.getCode())).findAny(); @@ -133,7 +133,7 @@ public class AlertMockService { platform.setTimestamp(System.currentTimeMillis() / 1000); Platform pf = pfOptional.orElse(null); return this.alertInfoService.createAlert(dto.getAlertType(), AlertDeviceType.DEVICE_TYPE_PLATFORM, pf.getCommon().getId(), platform, platform.getId(), AlertDeviceType.DEVICE_TYPE_PLATFORM, - false); + true); } /* case SWITCH_LOST -> { Optional turnoutOptional = LineGraphicDataRepository.getDevices(lineId, Turnout.class).filter(d -> dto.getDeviceCodes().contains(d.getCode())).findAny(); @@ -155,7 +155,7 @@ public class AlertMockService { switchs.setReceiveTime(System.currentTimeMillis()); switchs.setIpSingleSwitchStusLostIndication(true); Turnout turnout = turnoutOptional.orElse(null); - return this.alertInfoService.createAlert(dto.getAlertType(), AlertDeviceType.DEVICE_TYPE_SWITCH, turnout.getCommon().getId(), switchs, dto.getAll(), AlertDeviceType.DEVICE_TYPE_SWITCH, false); + return this.alertInfoService.createAlert(dto.getAlertType(), AlertDeviceType.DEVICE_TYPE_SWITCH, turnout.getCommon().getId(), switchs, dto.getAll(), AlertDeviceType.DEVICE_TYPE_SWITCH, true); } case AXLE_LED_RED, AXLE_LED_ORANGE, AXLE_LED_ORANGE_MOST, AXLE_LED_RED_MOST -> { Optional lsOptional = LineGraphicDataRepository.getDevices(lineId, LogicSection.class).filter(d -> dto.getDeviceCodes().contains(d.getCode())).findAny(); @@ -164,7 +164,7 @@ public class AlertMockService { track.setLineId(dto.getLineId()); track.setTimestamp(System.currentTimeMillis() / 1000); LogicSection ls = lsOptional.orElse(null); - return this.alertInfoService.createAlert(dto.getAlertType(), AlertDeviceType.DEVICE_TYPE_TRACK, ls.getCommon().getId(), track, dto.getAll(), AlertDeviceType.DEVICE_TYPE_TRACK, false); + return this.alertInfoService.createAlert(dto.getAlertType(), AlertDeviceType.DEVICE_TYPE_TRACK, ls.getCommon().getId(), track, dto.getAll(), AlertDeviceType.DEVICE_TYPE_TRACK, true); } case TRAIN_EB_ATP -> { @@ -176,7 +176,7 @@ public class AlertMockService { track.setTimestamp(System.currentTimeMillis() / 1000); LogicSection ls = lsOptional.orElse(null); - return this.alertInfoService.createAlert(AlertType.TRAIN_EB_ATP, AlertDeviceType.DEVICE_TYPE_TRAIN, ls.getCommon().getId(), track, "测试车组号", AlertDeviceType.DEVICE_TYPE_TRAIN, false); + return this.alertInfoService.createAlert(AlertType.TRAIN_EB_ATP, AlertDeviceType.DEVICE_TYPE_TRAIN, ls.getCommon().getId(), track, "测试车组号", AlertDeviceType.DEVICE_TYPE_TRAIN, true); } default -> throw new IllegalStateException("Unexpected value: " + dto.getAlertType()); diff --git a/src/main/java/club/joylink/xiannccda/service/AlertRecordService.java b/src/main/java/club/joylink/xiannccda/service/AlertRecordService.java index 0815fcb..5ebe67e 100644 --- a/src/main/java/club/joylink/xiannccda/service/AlertRecordService.java +++ b/src/main/java/club/joylink/xiannccda/service/AlertRecordService.java @@ -87,22 +87,25 @@ public class AlertRecordService { private static final List FILTER_LIST = List.of(TipTimeConfig.EVENING_PEARK.name(), TipTimeConfig.MORN_PEAK.name()/*, TipTimeConfig.NORMAL_UNPEARK.name()*/); private AlertTip findTipFromAlertTime(AlertRecord ar, String tipType, Long areaConfigId, boolean hasAreaConfigId) { - int hour = LocalDateTime.now().getHour(); - if (Objects.nonNull(ar.getAlertTime())) { - hour = ar.getAlertTime().getHour(); - } + Collection collection = this.timeConfigService.getCache(); if (CollectionUtils.isEmpty(collection)) { log.info("高低峰配置数据为空,返回默认的辅助消息"); return this.findAlertTip(tipType, areaConfigId, Optional.empty(), hasAreaConfigId); + } else if (Objects.isNull(ar)) { + return this.findAlertTip(tipType, areaConfigId, Optional.empty(), hasAreaConfigId); } else { + int hour = LocalDateTime.now().getHour(); + if (Objects.nonNull(ar.getAlertTime())) { + hour = ar.getAlertTime().getHour(); + } int finalHour = hour; Optional normalOptional = collection.stream().filter(d -> StringUtils.equals(TipTimeConfig.NORMAL_UNPEARK.name(), d.getTimeType())).findFirst(); Optional tipTimeConfigOptional = collection.stream().filter(d -> FILTER_LIST.contains(d.getTimeType()) && finalHour >= d.getStartHour() && finalHour <= d.getEndHour()) .findAny(); if (tipTimeConfigOptional.isEmpty() && normalOptional.isEmpty()) { //高低峰都没有找到 - log.info("高低峰均未匹配,告警时间(小时) {}", finalHour); + log.info("高低峰均未匹配,告警时间(小时) {}", hour); return this.findAlertTip(tipType, areaConfigId, Optional.empty(), hasAreaConfigId); } else if (tipTimeConfigOptional.isPresent()) { //匹配上高峰 @@ -135,24 +138,39 @@ public class AlertRecordService { public AlertTip confirm(Long recordId, String tipType, Long areaConfigId) { AlertRecord ar = this.alertRecordRepository.getById(recordId); - Long newAreaConfigId = this.findAreaConfig(ar, tipType); - if (Objects.isNull(newAreaConfigId)) { - newAreaConfigId = areaConfigId; + Long newAreaConfigId = null; + if (Objects.nonNull(ar)) { + newAreaConfigId = this.findAreaConfig(ar, tipType); + if (Objects.isNull(newAreaConfigId)) { + newAreaConfigId = areaConfigId; + } } + boolean hasAreaConfigId = Objects.nonNull(newAreaConfigId) && newAreaConfigId > 0L; AlertTip tip = this.findTipFromAlertTime(ar, tipType, newAreaConfigId, hasAreaConfigId); - this.alertRecordRepository.update(Wrappers.lambdaUpdate(AlertRecord.class) - .set(AlertRecord::getAlertTipId, tip.getId()).set(AlertRecord::getAlarmStatus, 1) - .set(hasAreaConfigId, AlertRecord::getAlertLocationId, newAreaConfigId) - .set(AlertRecord::getAlertType, tipType) - .eq(AlertRecord::getId, recordId).isNull(AlertRecord::getAlarmStatus)); + if (ar.getMock()) { + this.alertRecordRepository.removeById(ar.getId()); + } else { + this.alertRecordRepository.update(Wrappers.lambdaUpdate(AlertRecord.class) + .set(AlertRecord::getAlertTipId, tip.getId()).set(AlertRecord::getAlarmStatus, 1) + .set(hasAreaConfigId, AlertRecord::getAlertLocationId, newAreaConfigId) + .set(AlertRecord::getAlertType, tipType) + .eq(AlertRecord::getId, recordId).isNull(AlertRecord::getAlarmStatus)); + } + return tip; } public void failAlarm(Long recordId) { - this.alertRecordRepository.update(Wrappers.lambdaUpdate(AlertRecord.class) - .set(AlertRecord::getAlarmStatus, 0) - .eq(AlertRecord::getId, recordId).isNull(AlertRecord::getAlarmStatus)); + AlertRecord ar = this.alertRecordRepository.getById(recordId); + if (ar.getMock()) { + this.alertRecordRepository.removeById(ar.getId()); + } else { + this.alertRecordRepository.update(Wrappers.lambdaUpdate(AlertRecord.class) + .set(AlertRecord::getAlarmStatus, 0) + .eq(AlertRecord::getId, recordId).isNull(AlertRecord::getAlarmStatus)); + } + }