代码调整

This commit is contained in:
tiger_zhou 2023-09-21 15:30:50 +08:00
parent 417dc8b3dd
commit 46d85c4562
21 changed files with 94 additions and 109 deletions

View File

@ -96,9 +96,12 @@ public class DeviceStatusChangeResponse extends MessageResponse {
log.error("设备变更状态类型为空:{}", JSON.toJSONString(this));
return Collections.emptyList();
}
String occName = DeviceNameChangerManage.findMatch(this.type, this.devName);
// if (this.type == DeviceType.DEVICE_TYPE_SWITCH && StringUtils.startsWith(occName, "DG")) {
// this.type = DeviceType.DEVICE_TYPE_TRACK;
// }
GeneratedMessageV3.Builder builder = DeviceStatusConvertor.convert(this.type, this.deviceStatus);
// DeviceStatusConvertor.fillField(builder, "id", this.devName);
String occName = DeviceNameChangerManage.findMatch(this.type, this.devName);
DeviceStatusConvertor.fillField(builder, "id", occName);
DeviceStatusConvertor.fillField(builder, "dataFrom", MessageId.DEVICE_STATUS_CHANGE.name());
DeviceStatusConvertor.fillField(builder, "rtuId", this.rtuId);

View File

@ -13,17 +13,13 @@ import club.joylink.xiannccda.ats.warn.AxleSwitchTrackLedAlertListener.SwitchAnd
import club.joylink.xiannccda.ats.warn.AxleSwitchTrackLedInterlockAreaAlertListener.SwitchAndTrackLedInterlockAreaAlertEvent;
import club.joylink.xiannccda.ats.warn.AxleSwitchTrackLedMostAlertListener.SwitchAndTrackLedMostAlertEvent;
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;
import lombok.extern.slf4j.Slf4j;
@ -50,17 +46,32 @@ public class AxleSwitchTrackLedAlertListener implements AlertSourceEventListener
public void accept(SwitchAndTrackLedAlertEvent event) {
GeneratedMessageV3.Builder o = event.getSource();
String receiveBuildType = o.getDescriptorForType().getName();
Integer lineId = DeviceStatusDataOperate.findFieldVal(o, "lineId", Integer.class);
String id = DeviceStatusDataOperate.findFieldVal(o, "id", String.class);
log.info("区段光带检测 线路[{}] 设备[{}] 接受类型[{}]", lineId, id, receiveBuildType);
MessageOrBuilder section;
/*
// 考虑 可能 光带道岔可能会传道轨的code 也就是PT开头先保留
if (o instanceof Switch.Builder) {
if (StringUtils.startsWith(id, "DG")) {
section = LineGraphicDataRepository.getDeviceByCode(lineId, id);
MessageOrBuilder mm = LineGraphicDataRepository.getDeviceByCode(lineId, "31");
System.out.println(mm);
} else {
String sectionCode = LineGraphicDataRepository.findSectionFromLogicCode(lineId, id);
log.info("区段光带检测 线路[{}] 设备[{}] 查找对应的物理区段code[{}] 接受类型[{}]", lineId, id, sectionCode, receiveBuildType);
if (StringUtils.isEmpty(sectionCode)) {
return;
}
MessageOrBuilder section = LineGraphicDataRepository.getDeviceByCode(lineId, sectionCode);
section = LineGraphicDataRepository.getDeviceByCode(lineId, sectionCode);
}
} else {
section = LineGraphicDataRepository.getDeviceByCode(lineId, id);
}*/
String sectionCode = LineGraphicDataRepository.findSectionFromLogicCode(lineId, id);
if (StringUtils.isEmpty(sectionCode)) {
return;
}
section = LineGraphicDataRepository.getDeviceByCode(lineId, sectionCode);
TrainDataSource trainDataSource = DeviceDataRepository.findDataSouce(lineId.toString(), DataTypeEnum.TRAIN);
String trainGroupId = trainDataSource.findTrainForDeviceName(id);
if (o instanceof Switch.Builder switchBuilder) {
@ -70,6 +81,7 @@ public class AxleSwitchTrackLedAlertListener implements AlertSourceEventListener
}
}
private void switchHandle(Switch.Builder switchBuilder, String trainGroupId, MessageOrBuilder section) {
boolean ledRed = switchBuilder.getIpSingleSwitchStusCiOccupied() && !switchBuilder.getIpSingleSwitchStusCbtcOccupied() && Objects.isNull(trainGroupId);
boolean orange = switchBuilder.getIpSingleSwitchStusAtcInvalid();
@ -109,21 +121,6 @@ public class AxleSwitchTrackLedAlertListener implements AlertSourceEventListener
}
}
private String findSectionId(int lineId, Section section, String deviceCode) {
if (section.getSectionType() == SectionType.TurnoutPhysical) {
return section.getCommon().getId();
}
Map<String, Builder> sectionMaper = LineGraphicDataRepository.getLineSectionBuild(lineId);
for (String childId : section.getChildrenList()) {
Builder builder = sectionMaper.get(childId);
String code = DeviceStatusDataOperate.findFieldVal(builder, "code", String.class);
if (StringUtils.equalsIgnoreCase(code, deviceCode) && builder instanceof DeviceInfoProto.Section.Builder section1) {
return section1.getId();
}
}
return section.getCommon().getId();
}
public static class SwitchAndTrackLedAlertEvent extends DeviceAlertEvent<GeneratedMessageV3.Builder> {
public SwitchAndTrackLedAlertEvent(Builder source) {

View File

@ -52,8 +52,9 @@ public class AxleSwitchTrackLedMostAlertListener implements AlertSourceEventList
if (mostType == AlertType.AXLE_LED_ORANGE_MOST) {
overNums = guardConfig.getOrangeLedMostNums();
}
boolean isMost = alertManager.needMostShow(lineId, newName, overNums);
alertManager.putAlterDevice(lineId, newName, event.realDeviceCodeId);
if (alertManager.needMostShow(lineId, newName, overNums)) {
if (!isMost && alertManager.needMostShow(lineId, newName, overNums)) {
String ledName = event.alertType == AlertType.AXLE_LED_RED ? "红光带" : "橙光带";
String warnDevices = alertManager.findAllWarnDevice(lineId, newName);
String alertMsg = String.format("%s-出现大面积%s设备[%s]", alertInfoMostOptional.get().getAreaName(), ledName, warnDevices);

View File

@ -13,6 +13,7 @@ import club.joylink.xiannccda.dto.protos.GuardConfigProto.GuardConfig;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Turnout;
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.Optional;
import java.util.concurrent.ConcurrentHashMap;
@ -46,12 +47,14 @@ public class SwitchLostAlertMonitoringTask implements AlertMonitoringTask {
}
public void removeSwitch(Switch.Builder switchBuilder) {
Turnout turnout = LineGraphicDataRepository.getDeviceByCode(switchBuilder.getLineId(), switchBuilder.getId(), Turnout.class);
MessageOrBuilder turnoutBuild = LineGraphicDataRepository.getDeviceByCode(switchBuilder.getLineId(), switchBuilder.getId());
if (turnoutBuild instanceof Turnout turnout) {
log.info("线路[{}] 道岔[{}] 从监控中移除... 设备状态参数[{}]", switchBuilder.getLineId(), switchBuilder.getId(), switchBuilder);
deviceMap.remove(switchBuilder.getId());
alertManager.removeAlterDevice(switchBuilder.getLineId(), this.getName(), switchBuilder.getId());
alertManager.emit(new SwitchLostMostEvent(switchBuilder, false, turnout));
}
}
@Override
public String getName() {

View File

@ -60,7 +60,7 @@ public class SwitchLostMostAlertListener implements AlertSourceEventListener<Swi
}
if (event.alert) {
//检测大面积失表
alertManager.putAlterDevice(lineId, mostName, switchBuild.getId());
/*alertManager.putAlterDevice(lineId, mostName, switchBuild.getId());
if (alertManager.needMostShow(lineId, mostName, guardConfig.getSwitchLostMostNums())) {
String warnDevices = alertManager.findAllWarnDevice(lineId, mostName);
this.findDeviceIdFormCode(lineId, alertManager.findAllWarnDeviceForList(lineId, mostName));
@ -68,6 +68,16 @@ public class SwitchLostMostAlertListener implements AlertSourceEventListener<Swi
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoMostOpt, AlertType.SWITCH_LOST_MOST, switchBuild, alertMsg, warnDevices,
AlertDeviceType.DEVICE_TYPE_SWITCH, false);
alertManager.emit(alertInfo);
}*/
boolean isMost = alertManager.needMostShow(lineId, mostName, guardConfig.getSwitchLostMostNums());
alertManager.putAlterDevice(lineId, mostName, switchBuild.getId());
if (!isMost && alertManager.needMostShow(lineId, mostName, guardConfig.getSwitchLostMostNums())) {
String warnDevices = alertManager.findAllWarnDevice(lineId, mostName);
this.findDeviceIdFormCode(lineId, alertManager.findAllWarnDeviceForList(lineId, mostName));
String alertMsg = String.format("%s-大面积失表设备[%s]", mostName, warnDevices);
NccAlertInfo alertInfo = this.alertInfoService.createAlert2(alertInfoMostOpt, AlertType.SWITCH_LOST_MOST, switchBuild, alertMsg, warnDevices,
AlertDeviceType.DEVICE_TYPE_SWITCH, false);
alertManager.emit(alertInfo);
}
} else {
alertManager.removeAlterDevice(lineId, mostName, switchBuild.getId());

View File

@ -95,8 +95,6 @@ public class TrainAtpCutAlertMonitoringTask implements AlertMonitoringTask {
return "TRAIN_EB_WITH_ATP_CUT_ALTER";
}
// private final static String CUSTOM_NAME = AlertType.TRAIN_EB_ATP.name();
protected void trainAlert(TrainInfo.Builder trainInfo) {
String sectionCode = LineGraphicDataRepository.findSectionFromLogicCode(trainInfo.getLineId(), trainInfo.getDevName());

View File

@ -1,10 +1,9 @@
package club.joylink.xiannccda.controller;
import club.joylink.xiannccda.dto.AlertMockDTO;
import club.joylink.xiannccda.dto.mock.test.AlertMockDTO;
import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType;
import club.joylink.xiannccda.service.AlertMockService;
import club.joylink.xiannccda.service.AlertMockService.AlertMockDeviceInfo;
import com.google.protobuf.GeneratedMessageV3;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
@ -41,7 +40,7 @@ public class AlertMockController {
@ApiResponse(description = "设置模拟故障")
@PostMapping("/localDemoTest/{alertType}")
public void localDemoTest(@RequestBody String json, @PathVariable("alertType") AlertType alertType) {
alertMockService.newSetAlert(json, alertType);
alertMockService.alertDemoTest(json, alertType);
}
@SecurityRequirement(name = "jwt")

View File

@ -1,20 +0,0 @@
package club.joylink.xiannccda.dto.mock;
import lombok.Data;
@Data
public class PlatformCantCloseMockDTO extends NewAlertMockDTO {
@Override
public Integer deviceStatus() {
switch (this.getStatus()) {
case NORMAL -> {
return 3670016;
}
case ALERT -> {
return 3735810;
}
}
return 0;
}
}

View File

@ -1,20 +0,0 @@
package club.joylink.xiannccda.dto.mock;
import lombok.Data;
@Data
public class PlatformCantOpenMockDTO extends NewAlertMockDTO {
@Override
public Integer deviceStatus() {
switch (this.getStatus()) {
case NORMAL -> {
return 3670016;
}
case ALERT -> {
return 3735554;
}
}
return 0;
}
}

View File

@ -1,4 +1,4 @@
package club.joylink.xiannccda.dto.mock;
package club.joylink.xiannccda.dto.mock.show;
public enum AlertMockStatus {
NORMAL, BEGIN, ALERT,

View File

@ -0,0 +1,21 @@
package club.joylink.xiannccda.dto.mock.show;
import club.joylink.xiannccda.ats.message.line3.device.DeviceStatus.RTU;
import lombok.Data;
@Data
public class BlueAlertMockDTO extends NewAlertMockDTO {
@Override
public Integer deviceStatus() {
switch (this.getStatus()) {
case NORMAL -> {
return RTU.IP_RTU_STUS_IN_LOCAL_CTRL.getVal();
}
case ALERT -> {
return RTU.IP_RTU_STUS_DOWN.getVal();
}
}
return 0;
}
}

View File

@ -1,10 +1,8 @@
package club.joylink.xiannccda.dto.mock;
package club.joylink.xiannccda.dto.mock.show;
import club.joylink.xiannccda.alert.core.AlertDeviceType;
import club.joylink.xiannccda.ats.message.MessageId;
import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType;
import com.alibaba.fastjson2.annotation.JSONField;
import java.util.List;
import lombok.Data;

View File

@ -1,4 +1,4 @@
package club.joylink.xiannccda.dto.mock;
package club.joylink.xiannccda.dto.mock.show;
import lombok.Data;

View File

@ -1,4 +1,4 @@
package club.joylink.xiannccda.dto.mock;
package club.joylink.xiannccda.dto.mock.show;
import lombok.Data;

View File

@ -1,4 +1,4 @@
package club.joylink.xiannccda.dto.mock;
package club.joylink.xiannccda.dto.mock.show;
import lombok.Data;

View File

@ -1,4 +1,4 @@
package club.joylink.xiannccda.dto.mock;
package club.joylink.xiannccda.dto.mock.show;
import lombok.Data;

View File

@ -1,4 +1,4 @@
package club.joylink.xiannccda.dto;
package club.joylink.xiannccda.dto.mock.test;
import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType;
import com.baomidou.mybatisplus.core.toolkit.StringPool;

View File

@ -4,8 +4,8 @@ import club.joylink.xiannccda.ats.message.MessageData;
import club.joylink.xiannccda.ats.message.MessageId;
import club.joylink.xiannccda.ats.message.OccMessageEncoder;
import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
import club.joylink.xiannccda.dto.mock.NewAlertMockDTO;
import club.joylink.xiannccda.dto.mock.NewAlertMockDTO.DeviceNameInfo;
import club.joylink.xiannccda.dto.mock.show.NewAlertMockDTO;
import club.joylink.xiannccda.dto.mock.show.NewAlertMockDTO.DeviceNameInfo;
import club.joylink.xiannccda.mock.message.occ.req.MockDeviceStatusReq;
import club.joylink.xiannccda.mock.message.occ.req.MockTrainUpdateReq;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
@ -21,7 +21,6 @@ import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import jakarta.annotation.PostConstruct;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.locks.Lock;
@ -31,8 +30,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Component
//@RestController()

View File

@ -6,12 +6,13 @@ import club.joylink.xiannccda.alert.core.AlertDeviceType;
import club.joylink.xiannccda.alert.core.AlertManager;
import club.joylink.xiannccda.ats.cache.LineGraphicDataRepository;
import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataOperate;
import club.joylink.xiannccda.dto.AlertMockDTO;
import club.joylink.xiannccda.dto.mock.NewAlertMockDTO;
import club.joylink.xiannccda.dto.mock.OrangeAlertMockDTO;
import club.joylink.xiannccda.dto.mock.RedAlertMockDTO;
import club.joylink.xiannccda.dto.mock.SwitchAlertMockDTO;
import club.joylink.xiannccda.dto.mock.TrainSignlaAlertMockDTO;
import club.joylink.xiannccda.dto.mock.show.BlueAlertMockDTO;
import club.joylink.xiannccda.dto.mock.test.AlertMockDTO;
import club.joylink.xiannccda.dto.mock.show.NewAlertMockDTO;
import club.joylink.xiannccda.dto.mock.show.OrangeAlertMockDTO;
import club.joylink.xiannccda.dto.mock.show.RedAlertMockDTO;
import club.joylink.xiannccda.dto.mock.show.SwitchAlertMockDTO;
import club.joylink.xiannccda.dto.mock.show.TrainSignlaAlertMockDTO;
import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Rtu;
@ -29,10 +30,7 @@ import com.alibaba.fastjson2.JSONObject;
import com.google.protobuf.GeneratedMessageV3;
import com.google.protobuf.MessageOrBuilder;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
@ -71,7 +69,7 @@ public class AlertMockService {
alertManager.emit(alertInfo);
}
public void newSetAlert(String json, AlertType alertType) {
public void alertDemoTest(String json, AlertType alertType) {
Class<? extends NewAlertMockDTO> clazz = this.findMockDataObj(alertType);
NewAlertMockDTO mockDTO = JSONObject.parseObject(json, clazz);
mockDTO.setAlertType(alertType);
@ -82,6 +80,9 @@ public class AlertMockService {
private Class<? extends NewAlertMockDTO> findMockDataObj(AlertType alertType) {
switch (alertType) {
case BLUE_DISPLAY -> {
return BlueAlertMockDTO.class;
}
case AXLE_LED_RED -> {
return RedAlertMockDTO.class;
}

View File

@ -72,7 +72,7 @@ public class AlertRecordService {
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 -> {
SWITCH_All_LOST/*, AXLE_LED_ORANGE_MOST, AXLE_LED_RED_MOST, AXLE_LED_ORANGE_INTERLOCK_AREA, AXLE_LED_RED_INTERLOCK_AREA*/ -> {
Optional<AreaConfigVO> 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);
@ -87,13 +87,14 @@ public class AlertRecordService {
private static final List<String> 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) {
if (Objects.isNull(ar)) {
return this.findAlertTip(tipType, areaConfigId, Optional.empty(), hasAreaConfigId);
}
Collection<AlertTipTimeConfig> 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())) {
@ -122,14 +123,11 @@ public class AlertRecordService {
LambdaQueryWrapper<AlertTip> 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(" and find_in_set('%s',%s) > 0 ", id, AlertTip.TIP_TIME_REF));
List<AlertTip> alertTips = this.alertTipRepository.list(qw);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(CollectionUtils.isNotEmpty(alertTips), "未找到对应的决策辅助信息");
if (Objects.nonNull(id)) {
Optional<AlertTip> 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);
@ -157,7 +155,6 @@ public class AlertRecordService {
.set(AlertRecord::getAlertType, tipType)
.eq(AlertRecord::getId, recordId).isNull(AlertRecord::getAlarmStatus));
}
return tip;
}

View File

@ -13,7 +13,7 @@ logging:
path: /usr/local/joylink/logs/xianncc
occ:
host: localhost
realPort: 123
realPort: 2603
unRealPort: 123
lineId: 3
collectorData: false