diff --git a/src/main/java/club/joylink/xiannccda/ats/cache/LineGraphicDataRepository.java b/src/main/java/club/joylink/xiannccda/ats/cache/LineGraphicDataRepository.java index 220c7ed..754c83b 100644 --- a/src/main/java/club/joylink/xiannccda/ats/cache/LineGraphicDataRepository.java +++ b/src/main/java/club/joylink/xiannccda/ats/cache/LineGraphicDataRepository.java @@ -122,7 +122,7 @@ public class LineGraphicDataRepository { for (String s : section.getChildrenList()) { Builder b = builderMap.get(s); if (b instanceof DeviceInfoProto.Section.Builder logicSection) { - LOGIC_SECTION_TO_SECTION_TABLE.put(publishGi.getLineId(), logicSection.getCode(), section.getCode()); + LOGIC_SECTION_TO_SECTION_TABLE.put(publishGi.getLineId(), logicSection.getCode(), logicSection.getCode()); } } @@ -172,7 +172,7 @@ public class LineGraphicDataRepository { public static MessageOrBuilder getDeviceByCodeNotException(int lineId, String code) { MessageOrBuilder mob = line_code_table.get(lineId, code); - + return mob; } diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/AxleSwitchTrackLedAlertListener.java b/src/main/java/club/joylink/xiannccda/ats/warn/AxleSwitchTrackLedAlertListener.java index 39e9ec7..367d9c8 100644 --- a/src/main/java/club/joylink/xiannccda/ats/warn/AxleSwitchTrackLedAlertListener.java +++ b/src/main/java/club/joylink/xiannccda/ats/warn/AxleSwitchTrackLedAlertListener.java @@ -16,11 +16,13 @@ import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType; import club.joylink.xiannccda.dto.protos.DeviceInfoProto; import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Switch; import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Track; +import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.CommonInfo; import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Section; import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Section.SectionType; import club.joylink.xiannccda.service.AlertInfoService; import com.google.protobuf.GeneratedMessageV3; import com.google.protobuf.GeneratedMessageV3.Builder; +import com.google.protobuf.MessageOrBuilder; import java.util.Map; import java.util.Objects; import java.util.Optional; @@ -56,10 +58,9 @@ public class AxleSwitchTrackLedAlertListener implements AlertSourceEventListener if (StringUtils.isEmpty(sectionCode)) { return; } - Section section = LineGraphicDataRepository.getDeviceByCode(lineId, sectionCode, Section.class); - if (section.getTurning()) { - return; - } + + MessageOrBuilder section = LineGraphicDataRepository.getDeviceByCode(lineId, sectionCode); + TrainDataSource trainDataSource = DeviceDataRepository.findDataSouce(lineId.toString(), DataTypeEnum.TRAIN); String trainGroupId = trainDataSource.findTrainForDeviceName(id); if (o instanceof Switch.Builder switchBuilder) { @@ -69,43 +70,41 @@ public class AxleSwitchTrackLedAlertListener implements AlertSourceEventListener } } - private void switchHandle(Switch.Builder switchBuilder, String trainGroupId, Section section) { + private void switchHandle(Switch.Builder switchBuilder, String trainGroupId, MessageOrBuilder section) { boolean ledRed = switchBuilder.getIpSingleSwitchStusCiOccupied() && !switchBuilder.getIpSingleSwitchStusCbtcOccupied() && Objects.isNull(trainGroupId); boolean orange = switchBuilder.getIpSingleSwitchStusAtcInvalid(); - log.info("区段光带 道轨区段 线路[{}] 区段[{}] 红光带占用[{}] 橙光带占用[{}]", switchBuilder.getLineId(), section.getCode(), ledRed, orange); + log.info("区段光带 道轨区段 线路[{}] 区段[{}] 红光带占用[{}] 橙光带占用[{}]", switchBuilder.getLineId(), switchBuilder.getId(), ledRed, orange); this.emit(ledRed, switchBuilder, section, AlertType.AXLE_LED_RED); this.emit(orange, switchBuilder, section, AlertType.AXLE_LED_ORANGE); } - private void trackHandle(Track.Builder trackBuild, String trainGroupId, Section section) { + private void trackHandle(Track.Builder trackBuild, String trainGroupId, MessageOrBuilder section) { boolean ledRed = trackBuild.getCiOccupied() && !trackBuild.getCbtcOccupied() && Objects.isNull(trainGroupId); boolean orange = trackBuild.getAtcInvalid(); - log.info("区段光带 区段 线路[{}] 区段[{}] 红光带占用[{}] 橙光带占用[{}]", trackBuild.getLineId(), section.getCode(), ledRed, orange); + log.info("区段光带 区段 线路[{}] 区段[{}] 红光带占用[{}] 橙光带占用[{}]", trackBuild.getLineId(), trackBuild.getId(), ledRed, orange); this.emit(ledRed, trackBuild, section, AlertType.AXLE_LED_RED); this.emit(orange, trackBuild, section, AlertType.AXLE_LED_ORANGE); } - private void emit(boolean light, Builder build, Section section, AlertType alertType) { - + private void emit(boolean light, Builder build, MessageOrBuilder turnoutOrLogicSection, AlertType alertType) { Integer lineId = DeviceStatusDataOperate.findFieldVal(build, "lineId", Integer.class); - String id = DeviceStatusDataOperate.findFieldVal(build, "id", String.class); - String layoutDeviceId = this.findSectionId(lineId, section, id); + String deviceCodeId = DeviceStatusDataOperate.findFieldVal(turnoutOrLogicSection, "code", String.class); + CommonInfo commonInfo = DeviceStatusDataOperate.findFieldVal(turnoutOrLogicSection, "common", CommonInfo.class); + String layoutDeviceId = commonInfo.getId(); String ledName = alertType == AlertType.AXLE_LED_RED ? "红光带" : "橙光带"; - String deviceCode = section.getSectionType() == SectionType.TurnoutPhysical ? section.getCode() : id; if (light) { - log.info("光带检测到[{}] 线路[{}] 设备[{}] 告警[{}]", ledName, lineId, deviceCode, alertType.name()); - if (alertManager.putAlterDevice(lineId, this.getDefaultName(alertType), deviceCode)) { - - String alertMsg = String.format("出现%s设备[%s]", ledName, deviceCode); - NccAlertInfo alertInfo = this.alertInfoService.createAlert2(Optional.empty(), alertType, build, alertMsg, section.getCommon().getId(), AlertDeviceType.DEVICE_TYPE_TRACK, false); + log.info("光带检测到[{}] 线路[{}] 设备[{}] 告警[{}]", ledName, lineId, deviceCodeId, alertType.name()); + if (alertManager.putAlterDevice(lineId, this.getDefaultName(alertType), deviceCodeId)) { + String alertMsg = String.format("出现%s设备[%s]", ledName, deviceCodeId); + NccAlertInfo alertInfo = this.alertInfoService.createAlert2(Optional.empty(), alertType, build, alertMsg, layoutDeviceId, AlertDeviceType.DEVICE_TYPE_TRACK, false); alertManager.emit(alertInfo); - alertManager.emit(new SwitchAndTrackLedMostAlertEvent(build, alertType, lineId, layoutDeviceId, section, true)); - alertManager.emit(new SwitchAndTrackLedInterlockAreaAlertEvent(build, alertType, lineId, layoutDeviceId, section, true)); + alertManager.emit(new SwitchAndTrackLedMostAlertEvent(build, alertType, lineId, layoutDeviceId, deviceCodeId, true)); + alertManager.emit(new SwitchAndTrackLedInterlockAreaAlertEvent(build, alertType, lineId, layoutDeviceId, deviceCodeId, true)); } } else { - alertManager.removeAlterDevice(lineId, this.getDefaultName(alertType), deviceCode); - alertManager.emit(new SwitchAndTrackLedMostAlertEvent(build, alertType, lineId, layoutDeviceId, section, false)); - alertManager.emit(new SwitchAndTrackLedInterlockAreaAlertEvent(build, alertType, lineId, layoutDeviceId, section, false)); + alertManager.removeAlterDevice(lineId, this.getDefaultName(alertType), deviceCodeId); + alertManager.emit(new SwitchAndTrackLedMostAlertEvent(build, alertType, lineId, layoutDeviceId, deviceCodeId, false)); + alertManager.emit(new SwitchAndTrackLedInterlockAreaAlertEvent(build, alertType, lineId, layoutDeviceId, deviceCodeId, false)); } } diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/AxleSwitchTrackLedInterlockAreaAlertListener.java b/src/main/java/club/joylink/xiannccda/ats/warn/AxleSwitchTrackLedInterlockAreaAlertListener.java index 26a4248..9257553 100644 --- a/src/main/java/club/joylink/xiannccda/ats/warn/AxleSwitchTrackLedInterlockAreaAlertListener.java +++ b/src/main/java/club/joylink/xiannccda/ats/warn/AxleSwitchTrackLedInterlockAreaAlertListener.java @@ -27,12 +27,10 @@ import org.springframework.stereotype.Component; public class AxleSwitchTrackLedInterlockAreaAlertListener implements AlertSourceEventListener { - private final DeviceGuardConfigService configService; private final AlertInfoService alertInfoService; private final AlertManager alertManager = AlertManager.getDefault(); - public AxleSwitchTrackLedInterlockAreaAlertListener(DeviceGuardConfigService configService, AlertInfoService alertInfoService) { - this.configService = configService; + public AxleSwitchTrackLedInterlockAreaAlertListener(AlertInfoService alertInfoService) { this.alertInfoService = alertInfoService; } @@ -40,21 +38,19 @@ public class AxleSwitchTrackLedInterlockAreaAlertListener implements AlertSource @Override public void accept(SwitchAndTrackLedInterlockAreaAlertEvent event) { int lineId = event.lineId; - String id = DeviceStatusDataOperate.findFieldVal(event.getSource(), "id", String.class); - String deviceCode = event.section.getSectionType() == SectionType.TurnoutPhysical ? event.section.getCode() : id; + AlertType mostType = event.alertType == AlertType.AXLE_LED_RED ? AlertType.AXLE_LED_RED_INTERLOCK_AREA : AlertType.AXLE_LED_ORANGE_INTERLOCK_AREA; Optional alertInfoMostOptional = this.alertInfoService.findAreaDevice(mostType, AlertDeviceType.DEVICE_TYPE_TRACK, event.layoutDeviceId, lineId); if (alertInfoMostOptional.isEmpty()) { - log.info("线路[{}] 联锁区[{}] 设备[{}] 未找到对应的区域配置", lineId, mostType.name(), id); + log.info("线路[{}] 联锁区[{}] 设备[{}] 未找到对应的区域配置", lineId, mostType.name(), event.realDeviceCodeId); return; } AreaConfigVO areaConfigVO = alertInfoMostOptional.get(); String newName = String.format("%s-%s", mostType.name(), areaConfigVO.getAreaName()); if (event.alert) { - boolean isSaved = alertManager.putAlterDevice(lineId, newName, deviceCode); + boolean isSaved = alertManager.putAlterDevice(lineId, newName, event.realDeviceCodeId); List saveDeviceList = alertManager.findAllWarnDeviceForList(lineId, newName); AreaConfigVO configVO = alertInfoMostOptional.get(); - if (isSaved && saveDeviceList.size() >= configVO.getDatas().length) { String ledName = event.alertType == AlertType.AXLE_LED_RED ? "红光带" : "橙光带"; String warnDevices = alertManager.findAllWarnDevice(lineId, newName); @@ -63,7 +59,7 @@ public class AxleSwitchTrackLedInterlockAreaAlertListener implements AlertSource alertManager.emit(alertInfoMost); } } else { - alertManager.removeAlterDevice(lineId, newName, deviceCode); + alertManager.removeAlterDevice(lineId, newName, event.realDeviceCodeId); } } @@ -73,15 +69,15 @@ public class AxleSwitchTrackLedInterlockAreaAlertListener implements AlertSource private int lineId; private String layoutDeviceId; private boolean alert; - private Section section; + private String realDeviceCodeId; - public SwitchAndTrackLedInterlockAreaAlertEvent(Builder source, AlertType alertType, int lineId, String layoutDeviceId, Section section, boolean alert) { + public SwitchAndTrackLedInterlockAreaAlertEvent(Builder source, AlertType alertType, int lineId, String layoutDeviceId, String realDeviceCodeId, boolean alert) { super(source); this.alertType = alertType; this.lineId = lineId; this.layoutDeviceId = layoutDeviceId; this.alert = alert; - this.section = section; + this.realDeviceCodeId = realDeviceCodeId; } } diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/AxleSwitchTrackLedMostAlertListener.java b/src/main/java/club/joylink/xiannccda/ats/warn/AxleSwitchTrackLedMostAlertListener.java index 093155d..9e6a3e1 100644 --- a/src/main/java/club/joylink/xiannccda/ats/warn/AxleSwitchTrackLedMostAlertListener.java +++ b/src/main/java/club/joylink/xiannccda/ats/warn/AxleSwitchTrackLedMostAlertListener.java @@ -38,14 +38,12 @@ public class AxleSwitchTrackLedMostAlertListener implements AlertSourceEventList @Override public void accept(SwitchAndTrackLedMostAlertEvent event) { int lineId = event.lineId; - String id = DeviceStatusDataOperate.findFieldVal(event.getSource(), "id", String.class); - String deviceCode = event.section.getSectionType() == SectionType.TurnoutPhysical ? event.section.getCode() : id; AlertType mostType = event.alertType == AlertType.AXLE_LED_RED ? AlertType.AXLE_LED_RED_MOST : AlertType.AXLE_LED_ORANGE_MOST; Optional alertInfoMostOptional = this.alertInfoService.findAreaDevice(mostType, AlertDeviceType.DEVICE_TYPE_TRACK, event.layoutDeviceId, lineId); String alertInfoMostName = alertInfoMostOptional.map(AreaConfigVO::getAreaName).orElse(null); String newName = StringUtils.isNotEmpty(alertInfoMostName) ? String.format("%s-%s", mostType.name(), alertInfoMostName) : null; if (StringUtils.isEmpty(newName)) { - log.info("线路[{}] 大面积[{}] 设备[{}] 未找到对应的区域配置", lineId, mostType.name(), id); + log.info("线路[{}] 大面积[{}] 设备[{}] 未找到对应的区域配置", lineId, mostType.name(), event.realDeviceCodeId); return; } if (event.alert) { @@ -54,7 +52,7 @@ public class AxleSwitchTrackLedMostAlertListener implements AlertSourceEventList if (mostType == AlertType.AXLE_LED_ORANGE_MOST) { overNums = guardConfig.getOrangeLedMostNums(); } - alertManager.putAlterDevice(lineId, newName, deviceCode); + alertManager.putAlterDevice(lineId, newName, event.realDeviceCodeId); if (alertManager.needMostShow(lineId, newName, overNums)) { String ledName = event.alertType == AlertType.AXLE_LED_RED ? "红光带" : "橙光带"; String warnDevices = alertManager.findAllWarnDevice(lineId, newName); @@ -63,7 +61,7 @@ public class AxleSwitchTrackLedMostAlertListener implements AlertSourceEventList alertManager.emit(alertInfoMost); } } else { - alertManager.removeAlterDevice(lineId, newName, deviceCode); + alertManager.removeAlterDevice(lineId, newName, event.realDeviceCodeId); } } @@ -73,15 +71,15 @@ public class AxleSwitchTrackLedMostAlertListener implements AlertSourceEventList private int lineId; private String layoutDeviceId; private boolean alert; - private Section section; + private String realDeviceCodeId; - public SwitchAndTrackLedMostAlertEvent(Builder source, AlertType alertType, int lineId, String layoutDeviceId, Section section, boolean alert) { + public SwitchAndTrackLedMostAlertEvent(Builder source, AlertType alertType, int lineId, String layoutDeviceId, String realDeviceCodeId, boolean alert) { super(source); this.alertType = alertType; this.lineId = lineId; this.layoutDeviceId = layoutDeviceId; this.alert = alert; - this.section = section; + this.realDeviceCodeId = realDeviceCodeId; } } diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/TrainAtpCutAlertMonitoringTask.java b/src/main/java/club/joylink/xiannccda/ats/warn/TrainAtpCutAlertMonitoringTask.java index 4e6126c..54531d8 100644 --- a/src/main/java/club/joylink/xiannccda/ats/warn/TrainAtpCutAlertMonitoringTask.java +++ b/src/main/java/club/joylink/xiannccda/ats/warn/TrainAtpCutAlertMonitoringTask.java @@ -5,15 +5,19 @@ import club.joylink.xiannccda.alert.core.AlertDeviceType; import club.joylink.xiannccda.alert.core.AlertManager; import club.joylink.xiannccda.alert.core.AlertMonitoringTask; import club.joylink.xiannccda.ats.cache.LineGraphicDataRepository; +import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataOperate; import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType; import club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode; import club.joylink.xiannccda.dto.protos.GuardConfigProto.GuardConfig; +import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.CommonInfo; +import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.LogicSection; import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Section; import club.joylink.xiannccda.dto.protos.TrainProto.TrainInfo; import club.joylink.xiannccda.dto.protos.TrainProto.TrainInfo.Builder; import club.joylink.xiannccda.dto.protos.TrainProto.TrainRemove; import club.joylink.xiannccda.service.AlertInfoService; import club.joylink.xiannccda.service.config.DeviceGuardConfigService; +import com.google.protobuf.MessageOrBuilder; import java.util.Map; import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; @@ -40,7 +44,6 @@ public class TrainAtpCutAlertMonitoringTask implements AlertMonitoringTask { public void putTrainInfoMonitor(TrainInfo.Builder train) { log.info("线路[{}] 车组号[{}] 列车状态[{}] 加入ATP检测中...", train.getLineId(), train.getGroupId(), train.getMode()); -// this.lineTrainGroupMap.put(train.getGroupId(), train.getLineId()); TrainInfo.Builder saveTrainInfo = this.trainInfoMap.get(train.getGroupId()); if (Objects.isNull(saveTrainInfo)) { this.trainInfoMap.put(train.getGroupId(), train); @@ -100,14 +103,18 @@ public class TrainAtpCutAlertMonitoringTask implements AlertMonitoringTask { if (StringUtils.isEmpty(sectionCode)) { return; } - Section section = LineGraphicDataRepository.getDeviceByCode(trainInfo.getLineId(), sectionCode, Section.class); + MessageOrBuilder turnoutOrLogicSection = LineGraphicDataRepository.getDeviceByCode(trainInfo.getLineId(), sectionCode); + CommonInfo commonInfo = DeviceStatusDataOperate.findFieldVal(turnoutOrLogicSection, "common", CommonInfo.class); + String deviceCode = DeviceStatusDataOperate.findFieldVal(turnoutOrLogicSection, "code", String.class); + String layoutDeviceId = commonInfo.getId(); if (alertManager.putAlterDevice(trainInfo.getLineId(), this.getName(), trainInfo.getGroupId())) { log.info("列车紧制ATP检测告警 线路[{}] 列车车组号[{}] 所在设备[{}]", trainInfo.getLineId(), trainInfo.getGroupId(), trainInfo.getDevName()); - String alertMsg = String.format("列车[%s] 紧制导致ATP切除所在区段[%s]", trainInfo.getGroupId(), section.getCode()); - NccAlertInfo alertInfo = this.alertInfoService.createAlert(AlertType.TRAIN_EB_ATP, AlertDeviceType.DEVICE_TYPE_TRAIN, section.getCommon().getId(), trainInfo, alertMsg, + String alertMsg = String.format("列车[%s] 紧制导致ATP切除所在区段[%s]", trainInfo.getGroupId(), deviceCode); + NccAlertInfo alertInfo = this.alertInfoService.createAlert(AlertType.TRAIN_EB_ATP, AlertDeviceType.DEVICE_TYPE_TRACK, layoutDeviceId, trainInfo, alertMsg, AlertDeviceType.DEVICE_TYPE_TRAIN, false); alertManager.emit(alertInfo); } + this.trainInfoMap.remove(trainInfo.getGroupId()); } @Override diff --git a/src/main/java/club/joylink/xiannccda/controller/AlertTipTimeConfigController.java b/src/main/java/club/joylink/xiannccda/controller/AlertTipTimeConfigController.java index 382ffa5..4e90242 100644 --- a/src/main/java/club/joylink/xiannccda/controller/AlertTipTimeConfigController.java +++ b/src/main/java/club/joylink/xiannccda/controller/AlertTipTimeConfigController.java @@ -5,6 +5,7 @@ import club.joylink.xiannccda.entity.AlertTipTimeConfig; import club.joylink.xiannccda.repository.impl.AlertTipTimeConfigRepository; import club.joylink.xiannccda.service.TipTimeConfigService; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import org.springframework.web.bind.annotation.PostMapping; @@ -43,7 +44,8 @@ public class AlertTipTimeConfigController { @Operation(summary = "保存修改") @PostMapping("page") public IPage page(AlertTipTimeQueryDTO dto) { - return this.configRepository.page(dto); + + return this.configRepository.page(dto, Wrappers.lambdaQuery(AlertTipTimeConfig.class).eq(AlertTipTimeConfig::getListShower, 1)); } diff --git a/src/main/java/club/joylink/xiannccda/dto/alertTip/AlertTipSaveDTO.java b/src/main/java/club/joylink/xiannccda/dto/alertTip/AlertTipSaveDTO.java index 0e82b0d..c8eca86 100644 --- a/src/main/java/club/joylink/xiannccda/dto/alertTip/AlertTipSaveDTO.java +++ b/src/main/java/club/joylink/xiannccda/dto/alertTip/AlertTipSaveDTO.java @@ -27,5 +27,5 @@ public class AlertTipSaveDTO { * 信息报送方面提示信息 */ private String submissionInfo; - private List tipTimeIds; + private List tipTimeIds; } diff --git a/src/main/java/club/joylink/xiannccda/entity/AlertTipTimeConfig.java b/src/main/java/club/joylink/xiannccda/entity/AlertTipTimeConfig.java index 3a246e9..0b19cac 100644 --- a/src/main/java/club/joylink/xiannccda/entity/AlertTipTimeConfig.java +++ b/src/main/java/club/joylink/xiannccda/entity/AlertTipTimeConfig.java @@ -40,7 +40,8 @@ public class AlertTipTimeConfig { @Schema(description = "公休日是否高峰0=否;1=是") private Byte publicPeak; - + @Schema(description = "列表是否显示 0=否,1=是") + private Byte listShower; public static final String ID = "id"; // public static final String TIME_NAME = "time_name"; @@ -52,4 +53,5 @@ public class AlertTipTimeConfig { public static final String TIME_TYPE = "time_type"; public static final String PUBLIC_PEAK = "public_peak"; + public static final String LIST_SHOWER = "list_shower"; } diff --git a/src/main/java/club/joylink/xiannccda/service/AlertRecordService.java b/src/main/java/club/joylink/xiannccda/service/AlertRecordService.java index 07a3ccd..0815fcb 100644 --- a/src/main/java/club/joylink/xiannccda/service/AlertRecordService.java +++ b/src/main/java/club/joylink/xiannccda/service/AlertRecordService.java @@ -18,6 +18,7 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.StringPool; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.google.common.base.Splitter; import com.google.common.collect.Lists; import java.time.LocalDateTime; import java.util.Collection; @@ -39,12 +40,15 @@ public class AlertRecordService { private final AlertTipRepository alertTipRepository; private final DeviceAreaConfigService areaConfigService; private final TipTimeConfigService timeConfigService; + private final AlertInfoService alertInfoService; - public AlertRecordService(IAlertRecordRepository alertRecordRepository, AlertTipRepository alertTipRepository, DeviceAreaConfigService areaConfigService, TipTimeConfigService timeConfigService) { + public AlertRecordService(IAlertRecordRepository alertRecordRepository, AlertTipRepository alertTipRepository, DeviceAreaConfigService areaConfigService, TipTimeConfigService timeConfigService, + AlertInfoService alertInfoService) { this.alertRecordRepository = alertRecordRepository; this.alertTipRepository = alertTipRepository; this.areaConfigService = areaConfigService; this.timeConfigService = timeConfigService; + this.alertInfoService = alertInfoService; } private Long findAreaConfig(AlertRecord ar, String tipType) { @@ -54,8 +58,10 @@ public class AlertRecordService { return null; } AlertType alertType = AlertType.valueOf(tipType); + switch (alertType) { - case BLUE_DISPLAY, AXLE_LED_RED, AXLE_LED_ORANGE, SWITCH_All_LOST, SWITCH_DW_LOST, SWITCH_FW_LOST -> { +/* case BLUE_DISPLAY, AXLE_LED_RED, AXLE_LED_ORANGE, SWITCH_All_LOST, SWITCH_DW_LOST, SWITCH_FW_LOST, + AXLE_LED_ORANGE_MOST, AXLE_LED_RED_MOST, AXLE_LED_ORANGE_INTERLOCK_AREA, AXLE_LED_RED_INTERLOCK_AREA, TRAIN_EB_ATP -> { List areaConfigList = this.areaConfigService.getCache(ar.getLineId(), AlertDeviceType.valueOf(ar.getAlertDeviceType())); List findList = areaConfigList.stream().filter(d -> d.containsAlertType(tipType)).filter(d -> d.findDataIndex(deviceId) >= 0).toList(); String findIds = findList.stream().map(AreaConfigVO::getId).map(Object::toString).collect(Collectors.joining(StringPool.COMMA)); @@ -64,6 +70,13 @@ public class AlertRecordService { return null; } return findList.get(0).getId(); + }*/ + case BLUE_DISPLAY, AXLE_LED_RED, AXLE_LED_ORANGE, SWITCH_DW_LOST, SWITCH_FW_LOST, TRAIN_EB_ATP, + SWITCH_All_LOST, AXLE_LED_ORANGE_MOST, AXLE_LED_RED_MOST, AXLE_LED_ORANGE_INTERLOCK_AREA, AXLE_LED_RED_INTERLOCK_AREA -> { + Optional areaConfigVOOptional = this.alertInfoService.findAreaDevice(alertType, AlertDeviceType.valueOf(ar.getAlertDeviceType()), deviceId, ar.getLineId()); + log.info("告警数据确认区域线路[{}] 记录id[{}] ", ar.getLineId(), ar.getId()); + return areaConfigVOOptional.map(AreaConfigVO::getId).orElse(null); + } default -> { return null; @@ -97,7 +110,6 @@ public class AlertRecordService { } else { //匹配上低峰 return this.findAlertTip(tipType, areaConfigId, normalOptional, hasAreaConfigId); - } } } @@ -107,11 +119,18 @@ public class AlertRecordService { LambdaQueryWrapper qw = Wrappers.lambdaQuery(AlertTip.class).eq(AlertTip::getAlertType, tipType); qw.eq(hasAreaConfigId, AlertTip::getAreaConfigId, areaConfigId); Long id = tipTimeConfigOptional.map(AlertTipTimeConfig::getId).orElse(null); - qw.last(Objects.nonNull(id), String.format(" find_in_set('%s',%s) > 0 ", id, AlertTip.TIP_TIME_REF)); - - AlertTip tip = alertTipRepository.getOne(qw, false); - BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(tip), "未找到对应的决策辅助信息"); - return tip; +// qw.last(Objects.nonNull(id), String.format(" and find_in_set('%s',%s) > 0 ", id, AlertTip.TIP_TIME_REF)); + List alertTips = this.alertTipRepository.list(qw); + BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(CollectionUtils.isNotEmpty(alertTips), "未找到对应的决策辅助信息"); + if (Objects.nonNull(id)) { + Optional alertTipOptional = alertTips.stream().filter(d -> StringUtils.isNotEmpty(d.getTipTimeRef())) + .filter(d -> Splitter.on(StringPool.COMMA).splitToList(d.getTipTimeRef()).contains(id.toString())).findFirst(); + /*BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(alertTipOptional.isPresent(), "未找到对应的决策辅助信息"); + return alertTipOptional.get();*/ + return alertTipOptional.orElseGet(() -> alertTips.get(0)); + } else { + return alertTips.get(0); + } } public AlertTip confirm(Long recordId, String tipType, Long areaConfigId) { @@ -120,7 +139,7 @@ public class AlertRecordService { if (Objects.isNull(newAreaConfigId)) { newAreaConfigId = areaConfigId; } - boolean hasAreaConfigId = Objects.nonNull(areaConfigId) && areaConfigId > 0L; + 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) diff --git a/src/main/java/club/joylink/xiannccda/service/AlertTipService.java b/src/main/java/club/joylink/xiannccda/service/AlertTipService.java index 932e15b..495c2a8 100644 --- a/src/main/java/club/joylink/xiannccda/service/AlertTipService.java +++ b/src/main/java/club/joylink/xiannccda/service/AlertTipService.java @@ -10,6 +10,7 @@ import club.joylink.xiannccda.repository.IAlertTipRepository; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import com.baomidou.mybatisplus.core.toolkit.StringPool; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.common.base.Joiner; @@ -69,9 +70,11 @@ public class AlertTipService { entity.setSubmissionInfo(saveDTO.getSubmissionInfo()); entity.setId(saveDTO.getId()); if (CollectionUtils.isNotEmpty(saveDTO.getTipTimeIds())) { - entity.setTipTimeRef(Joiner.on(",").skipNulls().join(saveDTO.getTipTimeIds())); + String selectIds = this.timeConfigService.getCache().stream().filter(d -> saveDTO.getTipTimeIds().contains(d.getTimeType())).map(d -> d.getId().toString()) + .collect(Collectors.joining(StringPool.COMMA)); + entity.setTipTimeRef(selectIds); } else { - entity.setTipTimeRef(null); + entity.setTipTimeRef(""); } return entity; }