增加模拟故障接口;增加绘图数据维护;注释循环故障报警逻辑

This commit is contained in:
joylink_zhangsai 2023-07-21 10:23:54 +08:00
parent 604eb28066
commit bd3cbbbd6e
21 changed files with 1502 additions and 563 deletions

View File

@ -0,0 +1,79 @@
package club.joylink.xiannccda.alert;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Platform;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Station;
import club.joylink.xiannccda.entity.AlertTip;
import club.joylink.xiannccda.exception.BusinessExceptionAssertEnum;
import club.joylink.xiannccda.repository.IAlertTipRepository;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.protobuf.MessageOrBuilder;
import java.time.LocalDateTime;
import org.springframework.stereotype.Component;
@Component
public class AlertDetailFactory {
private IAlertTipRepository alertTipRepository;
public AlertDetailFactory(IAlertTipRepository alertTipRepository) {
this.alertTipRepository = alertTipRepository;
}
public AlertDetail getAlertDetail(AlertType alertType, short lineId, boolean mock,
MessageOrBuilder messageOrBuilder) {
LocalDateTime now = LocalDateTime.now();
Integer alertTipId;
String info;
switch (alertType) {
case BLUE_DISPLAY -> {
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(
messageOrBuilder instanceof Station);
Station rtu = (Station) messageOrBuilder;
AlertTipLocationType locationType = AlertTipLocationType.getByLineIdAndRtuId(lineId,
Short.parseShort(rtu.getCode()));
LambdaQueryWrapper<AlertTip> queryWrapper = Wrappers.lambdaQuery(AlertTip.class)
.eq(AlertTip::getAlertType, alertType)
.eq(AlertTip::getLocationType, locationType);
AlertTip alertTip = alertTipRepository.getOne(queryWrapper);
alertTipId = alertTip == null ? null : alertTip.getId();
info = String.format("[%s号线]%s蓝显", lineId, locationType.getDesc());
}
case TRAIN_DELAY -> {
return null;
}
case PLATFORM_DOOR_WITHOUT_LOCKED_SIGNAL -> {
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(
messageOrBuilder instanceof Platform);
Platform platform = (Platform) messageOrBuilder;
LambdaQueryWrapper<AlertTip> queryWrapper = Wrappers.lambdaQuery(AlertTip.class)
.eq(AlertTip::getAlertType, alertType);
AlertTip alertTip = alertTipRepository.getOne(queryWrapper);
alertTipId = alertTip == null ? null : alertTip.getId();
info = String.format("[%s号线]%s站台门无关闭且锁紧信号", lineId, platform.getCode());
}
case PLATFORM_DOOR_CANNOT_OPEN -> {
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(
messageOrBuilder instanceof Platform);
Platform platform = (Platform) messageOrBuilder;
LambdaQueryWrapper<AlertTip> queryWrapper = Wrappers.lambdaQuery(AlertTip.class)
.eq(AlertTip::getAlertType, alertType);
AlertTip alertTip = alertTipRepository.getOne(queryWrapper);
alertTipId = alertTip == null ? null : alertTip.getId();
info = String.format("[%s号线]%s站台门无法打开", lineId, platform.getCode());
}
case PLATFORM_DOOR_CANNOT_CLOSE -> {
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(
messageOrBuilder instanceof Platform);
Platform platform = (Platform) messageOrBuilder;
LambdaQueryWrapper<AlertTip> queryWrapper = Wrappers.lambdaQuery(AlertTip.class)
.eq(AlertTip::getAlertType, alertType);
AlertTip alertTip = alertTipRepository.getOne(queryWrapper);
alertTipId = alertTip == null ? null : alertTip.getId();
info = String.format("[%s号线]%s站台门无法关闭", lineId, platform.getCode());
}
default -> throw new IllegalStateException("Unexpected value: " + alertType);
}
return new AlertDetailImpl(alertType, now, alertTipId, info, mock);
}
}

View File

@ -1,6 +1,7 @@
package club.joylink.xiannccda.alert;
import java.time.LocalDateTime;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Data;
@ -8,15 +9,16 @@ import lombok.Data;
* 西安三号线报警
*/
@Data
@AllArgsConstructor
@AllArgsConstructor(access = AccessLevel.PACKAGE)
public class AlertDetailImpl implements AlertDetail {
private AlertType alertType;
private LocalDateTime alertTime;
private Integer alertTipId;
private String info;
private String deviceInfo;
private String reason;
private boolean mock;
// private String deviceInfo;
// private String reason;
@Override
public AlertType getAlertType() {
@ -33,18 +35,25 @@ public class AlertDetailImpl implements AlertDetail {
return info;
}
@Override
public String getDeviceInfo() {
return deviceInfo;
}
@Override
public String getReason() {
return reason;
}
@Override
public Integer getAlertTipId() {
return alertTipId;
}
@Override
public boolean isMock() {
return mock;
}
// @Override
// public String getDeviceInfo() {
// return deviceInfo;
// }
//
// @Override
// public String getReason() {
// return reason;
// }
}

View File

@ -26,7 +26,7 @@ public class AlertEmitJob implements ApplicationRunner {
@Override
public void run(ApplicationArguments args) throws Exception {
AlertManager alertManager = AlertManager.getInstance();
AlertManager alertManager = AlertManager.getDefault();
//报警源
alertManager.addTask(trainDelayAlertMonitoringTask);
alertManager.addTask(blueDisplayAlertMonitoringTask);

View File

@ -29,18 +29,18 @@ public class AlertListenerJob implements ApplicationRunner {
//注册西安NCC的报警ws消息发送服务
wsMessageServerManager.registerMessageServer(NccAlertMessageServer.getDefault());
//启动报警源事件监测任务
AlertManager.getInstance().taskStart();
AlertManager.getDefault().taskStart();
}
public void addAlertDetailListeners() {
AlertManager alertManager = AlertManager.getInstance();
AlertManager alertManager = AlertManager.getDefault();
//报警监听
alertManager.on(new Listener<AlertDetail>() {
private final AtomicInteger idGenerator = new AtomicInteger(1);
@Override
public void accept(AlertDetail event) {
String id = String.valueOf(idGenerator.getAndIncrement());
String level = "YELLOW";
String level = "III";
LocalDateTime alertTime = event.getAlertTime();
NccAlertInfo<AlertDetail> nccAlertInfo = new NccAlertInfo<>(id, level, alertTime, event);
alertManager.emit(nccAlertInfo);
@ -50,7 +50,7 @@ public class AlertListenerJob implements ApplicationRunner {
private void addAlertListeners() {
NccAlertMessageServer nccAlertMessageServer = NccAlertMessageServer.getDefault();
AlertManager alertManager = AlertManager.getInstance();
AlertManager alertManager = AlertManager.getDefault();
//添加消息
alertManager.on(new Listener<NccAlertInfo>() {
@Override

View File

@ -1,12 +1,38 @@
package club.joylink.xiannccda.alert;
import club.joylink.xiannccda.exception.BusinessExceptionAssertEnum;
import java.util.Arrays;
import lombok.Getter;
@Getter
public enum AlertTipLocationType {
/**
* 全线
*/
QX,
QX(0, 0, "全线"),
/**
* 鱼化寨联锁区
*/
YHZ_LSQ,
YHZ_LSQ(3, 1, "鱼化寨联锁区"),
;
private short lineId;
private short rtuId;
private String desc;
AlertTipLocationType(int lineId, int rtuId, String desc) {
this.lineId = (short) lineId;
this.rtuId = (short) rtuId;
this.desc = desc;
}
public static AlertTipLocationType getByLineIdAndRtuId(short lineId, short rtuId) {
return Arrays.stream(AlertTipLocationType.values())
.filter(type -> lineId == type.lineId && rtuId == type.rtuId)
.findFirst()
.orElseThrow(() -> BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception(
String.format("[%s:%s]未定义联锁区", lineId, rtuId)));
}
}

View File

@ -1,19 +1,16 @@
package club.joylink.xiannccda.alert;
import club.joylink.xiannccda.alert.core.AlertManager;
import club.joylink.xiannccda.alert.core.AlertMonitoringTask;
import club.joylink.xiannccda.entity.AlertTip;
import club.joylink.xiannccda.repository.IAlertTipRepository;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import java.time.LocalDateTime;
import org.springframework.stereotype.Component;
@Component
public class BlueDisplayAlertMonitoringTask implements AlertMonitoringTask {
private IAlertTipRepository alertTipRepository;
private boolean alertTriggered;
public BlueDisplayAlertMonitoringTask(IAlertTipRepository alertTipRepository) {
this.alertTipRepository = alertTipRepository;
@ -26,26 +23,41 @@ public class BlueDisplayAlertMonitoringTask implements AlertMonitoringTask {
@Override
public void run() {
LocalDateTime now = LocalDateTime.now();
if (alertTriggered) {
if (now.getSecond() % 30 != 0) {
alertTriggered = false;
}
} else {
if (now.getSecond() % 30 == 0) {
AlertType alertType = AlertType.BLUE_DISPLAY;
LambdaQueryWrapper<AlertTip> queryWrapper = Wrappers.lambdaQuery(AlertTip.class);
queryWrapper.eq(AlertTip::getAlertType, alertType)
.eq(AlertTip::getLocationType, AlertTipLocationType.QX);
AlertTip alertTip = alertTipRepository.getOne(queryWrapper);
Integer alertTipId = alertTip == null ? null : alertTip.getId();
// short lineId = 3;
// Map<Short, RtuOrBuilder> id_rtu_map = new HashMap<>();
// if (CollectionUtils.isEmpty(id_rtu_map)) {
// return;
// }
//
// AlertManager alertManager = AlertManager.getDefault();
// LocalDateTime now = LocalDateTime.now();
// AlertType alertType = AlertType.BLUE_DISPLAY;
// if (id_rtu_map.values().stream().allMatch(RtuOrBuilder::getIpRtuStusDown)) {
// AlertTipLocationType locationType = AlertTipLocationType.QX;
// Integer alertTipId = getAlertTipId(alertType, locationType);
//
// AlertDetailImpl alert = new AlertDetailImpl(alertType, now, alertTipId,
// String.format("[%s号线]%s蓝显", lineId, locationType.getDesc()));
// alertManager.emit(alert);
// } else {
// id_rtu_map.entrySet().stream()
// .filter(entry -> entry.getValue().getIpRtuStusDown())
// .forEach(entry -> {
// AlertTipLocationType locationType
// = AlertTipLocationType.getByLineIdAndRtuId(lineId, entry.getKey());
// Integer alertTipId = getAlertTipId(alertType, locationType);
// AlertDetailImpl alert = new AlertDetailImpl(alertType, now, alertTipId,
// String.format("[%s号线]%s蓝显", lineId, locationType.getDesc()));
// alertManager.emit(alert);
// });
// }
}
AlertManager alertManager = AlertManager.getInstance();
AlertDetailImpl alert = new AlertDetailImpl(alertType, now, alertTipId, "[3号线]全线蓝显",
"轨旁设备", "轨旁设备故障");
alertManager.emit(alert);
alertTriggered = true;
}
}
private Integer getAlertTipId(AlertType alertType, AlertTipLocationType locationType) {
LambdaQueryWrapper<AlertTip> queryWrapper = Wrappers.lambdaQuery(AlertTip.class);
queryWrapper.eq(AlertTip::getAlertType, alertType)
.eq(AlertTip::getLocationType, locationType);
AlertTip alertTip = alertTipRepository.getOne(queryWrapper);
return alertTip == null ? null : alertTip.getId();
}
}

View File

@ -35,11 +35,15 @@ public class NccAlertInfo<D extends AlertDetail> implements AlertInfo {
return detail == null ? null : detail.getAlertTipId();
}
public String getDeviceInfo() {
return detail == null ? "" : detail.getDeviceInfo();
public boolean isMock() {
return detail == null || detail.isMock();
}
public String getReason() {
return detail == null ? "" : detail.getReason();
}
// public String getDeviceInfo() {
// return detail == null ? "" : detail.getDeviceInfo();
// }
//
// public String getReason() {
// return detail == null ? "" : detail.getReason();
// }
}

View File

@ -1,12 +1,7 @@
package club.joylink.xiannccda.alert;
import club.joylink.xiannccda.alert.core.AlertManager;
import club.joylink.xiannccda.alert.core.AlertMonitoringTask;
import club.joylink.xiannccda.entity.AlertTip;
import club.joylink.xiannccda.repository.IAlertTipRepository;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import java.time.LocalDateTime;
import org.springframework.stereotype.Component;
@Component
@ -26,60 +21,60 @@ public class PlatformDoorAlertMonitoringTask implements AlertMonitoringTask {
@Override
public void run() {
LocalDateTime now = LocalDateTime.now();
if (alertTriggered) {
if (now.getSecond() % 30 != 0) {
alertTriggered = false;
}
} else {
if (now.getSecond() % 30 == 0) {
emitPlatformDoorWithoutLockedSignalAlert(now, alertTipRepository);
emitPlatformDoorCannotOpenAlert(now, alertTipRepository);
emitPlatformDoorCannotCloseAlert(now, alertTipRepository);
alertTriggered = true;
}
}
// LocalDateTime now = LocalDateTime.now();
// if (alertTriggered) {
// if (now.getSecond() % 30 != 0) {
// alertTriggered = false;
// }
// } else {
// if (now.getSecond() % 30 == 0) {
// emitPlatformDoorWithoutLockedSignalAlert(now, alertTipRepository);
// emitPlatformDoorCannotOpenAlert(now, alertTipRepository);
// emitPlatformDoorCannotCloseAlert(now, alertTipRepository);
// alertTriggered = true;
// }
// }
}
public void emitPlatformDoorWithoutLockedSignalAlert(LocalDateTime now,
IAlertTipRepository alertTipRepository) {
AlertType alertType = AlertType.PLATFORM_DOOR_WITHOUT_LOCKED_SIGNAL;
LambdaQueryWrapper<AlertTip> queryWrapper = Wrappers.lambdaQuery(AlertTip.class);
queryWrapper.eq(AlertTip::getAlertType, alertType);
AlertTip alertTip = alertTipRepository.getOne(queryWrapper);
Integer alertTipId = alertTip == null ? null : alertTip.getId();
AlertManager alertManager = AlertManager.getInstance();
AlertDetailImpl alert = new AlertDetailImpl(alertType, now, alertTipId,
"[3号线]站台门无关闭锁紧信号", "鱼化寨下行站台", "鱼化寨下行站台无关闭锁紧信号");
alertManager.emit(alert);
}
public void emitPlatformDoorCannotOpenAlert(LocalDateTime now,
IAlertTipRepository alertTipRepository) {
AlertType alertType = AlertType.PLATFORM_DOOR_CANNOT_OPEN;
LambdaQueryWrapper<AlertTip> queryWrapper = Wrappers.lambdaQuery(AlertTip.class);
queryWrapper.eq(AlertTip::getAlertType, alertType);
AlertTip alertTip = alertTipRepository.getOne(queryWrapper);
Integer alertTipId = alertTip == null ? null : alertTip.getId();
AlertManager alertManager = AlertManager.getInstance();
AlertDetailImpl alert = new AlertDetailImpl(alertType, now, alertTipId,
"[3号线]站台门整侧站台门无法打开", "鱼化寨下行站台", "鱼化寨下行站台整侧站台门无法打开");
alertManager.emit(alert);
}
public void emitPlatformDoorCannotCloseAlert(LocalDateTime now,
IAlertTipRepository alertTipRepository) {
AlertType alertType = AlertType.PLATFORM_DOOR_CANNOT_CLOSE;
LambdaQueryWrapper<AlertTip> queryWrapper = Wrappers.lambdaQuery(AlertTip.class);
queryWrapper.eq(AlertTip::getAlertType, alertType);
AlertTip alertTip = alertTipRepository.getOne(queryWrapper);
Integer alertTipId = alertTip == null ? null : alertTip.getId();
AlertManager alertManager = AlertManager.getInstance();
AlertDetailImpl alert = new AlertDetailImpl(alertType, now, alertTipId,
"[3号线]站台门整侧站台门无法关闭", "鱼化寨下行站台", "鱼化寨下行站台整侧站台门无法关闭");
alertManager.emit(alert);
}
// public void emitPlatformDoorWithoutLockedSignalAlert(LocalDateTime now,
// IAlertTipRepository alertTipRepository) {
// AlertType alertType = AlertType.PLATFORM_DOOR_WITHOUT_LOCKED_SIGNAL;
// LambdaQueryWrapper<AlertTip> queryWrapper = Wrappers.lambdaQuery(AlertTip.class);
// queryWrapper.eq(AlertTip::getAlertType, alertType);
// AlertTip alertTip = alertTipRepository.getOne(queryWrapper);
// Integer alertTipId = alertTip == null ? null : alertTip.getId();
//
// AlertManager alertManager = AlertManager.getDefault();
// AlertDetailImpl alert = new AlertDetailImpl(alertType, now, alertTipId,
// "[3号线]站台门无关闭锁紧信号");
// alertManager.emit(alert);
// }
//
// public void emitPlatformDoorCannotOpenAlert(LocalDateTime now,
// IAlertTipRepository alertTipRepository) {
// AlertType alertType = AlertType.PLATFORM_DOOR_CANNOT_OPEN;
// LambdaQueryWrapper<AlertTip> queryWrapper = Wrappers.lambdaQuery(AlertTip.class);
// queryWrapper.eq(AlertTip::getAlertType, alertType);
// AlertTip alertTip = alertTipRepository.getOne(queryWrapper);
// Integer alertTipId = alertTip == null ? null : alertTip.getId();
//
// AlertManager alertManager = AlertManager.getDefault();
// AlertDetailImpl alert = new AlertDetailImpl(alertType, now, alertTipId,
// "[3号线]站台门整侧站台门无法打开");
// alertManager.emit(alert);
// }
//
// public void emitPlatformDoorCannotCloseAlert(LocalDateTime now,
// IAlertTipRepository alertTipRepository) {
// AlertType alertType = AlertType.PLATFORM_DOOR_CANNOT_CLOSE;
// LambdaQueryWrapper<AlertTip> queryWrapper = Wrappers.lambdaQuery(AlertTip.class);
// queryWrapper.eq(AlertTip::getAlertType, alertType);
// AlertTip alertTip = alertTipRepository.getOne(queryWrapper);
// Integer alertTipId = alertTip == null ? null : alertTip.getId();
//
// AlertManager alertManager = AlertManager.getDefault();
// AlertDetailImpl alert = new AlertDetailImpl(alertType, now, alertTipId,
// "[3号线]站台门整侧站台门无法关闭");
// alertManager.emit(alert);
// }
}

View File

@ -1,12 +1,7 @@
package club.joylink.xiannccda.alert;
import club.joylink.xiannccda.alert.core.AlertManager;
import club.joylink.xiannccda.alert.core.AlertMonitoringTask;
import club.joylink.xiannccda.entity.AlertTip;
import club.joylink.xiannccda.repository.IAlertTipRepository;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import java.time.LocalDateTime;
import org.springframework.stereotype.Component;
@Component
@ -26,27 +21,27 @@ public class TrainDelayAlertMonitoringTask implements AlertMonitoringTask {
@Override
public void run() {
LocalDateTime now = LocalDateTime.now();
if (alertTriggered) {
if (now.getSecond() % 30 != 0) {
alertTriggered = false;
}
} else {
if (now.getSecond() % 30 == 0) {
AlertType alertType = AlertType.PLATFORM_DOOR_CANNOT_OPEN;
LambdaQueryWrapper<AlertTip> queryWrapper = Wrappers.lambdaQuery(AlertTip.class);
queryWrapper.eq(AlertTip::getAlertType, alertType)
.eq(AlertTip::getTimeType, AlertTipTimeType.CLOCK_7_9_AND_19_21);
AlertTip alertTip = alertTipRepository.getOne(queryWrapper);
Integer alertTipId = alertTip == null ? null : alertTip.getId();
AlertManager alertManager = AlertManager.getInstance();
AlertDetailImpl alert = new AlertDetailImpl(alertType, now, alertTipId,
String.format("[3号线]列车[01-1001]按计划应于%s抵达[%s],现因[%s]晚点%s分钟",
now.minusMinutes(2), "鱼化寨", "道岔P0110失表", "2"), "道岔[P0110]", "道岔[P0110]失表");
alertManager.emit(alert);
alertTriggered = true;
}
}
// LocalDateTime now = LocalDateTime.now();
// if (alertTriggered) {
// if (now.getSecond() % 30 != 0) {
// alertTriggered = false;
// }
// } else {
// if (now.getSecond() % 30 == 0) {
// AlertType alertType = AlertType.PLATFORM_DOOR_CANNOT_OPEN;
// LambdaQueryWrapper<AlertTip> queryWrapper = Wrappers.lambdaQuery(AlertTip.class);
// queryWrapper.eq(AlertTip::getAlertType, alertType)
// .eq(AlertTip::getTimeType, AlertTipTimeType.CLOCK_7_9_AND_19_21);
// AlertTip alertTip = alertTipRepository.getOne(queryWrapper);
// Integer alertTipId = alertTip == null ? null : alertTip.getId();
//
// AlertManager alertManager = AlertManager.getDefault();
// AlertDetailImpl alert = new AlertDetailImpl(alertType, now, alertTipId,
// String.format("[3号线]列车[01-1001]按计划应于%s抵达[%s],现因[%s]晚点%s分钟",
// now.minusMinutes(2), "鱼化寨", "道岔P0110失表", "2"));
// alertManager.emit(alert);
// alertTriggered = true;
// }
// }
}
}

View File

@ -31,7 +31,7 @@ public class AlertManager extends EventEmitter {
super(id);
}
public static AlertManager getInstance() {
public static AlertManager getDefault() {
return getInstance("default");
}

View File

@ -4,17 +4,22 @@ import club.joylink.xiannccda.dto.protos.DeviceInfoProto;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.KilometerSystem;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.RelatedRef.DeviceType;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.RtssGraphicStorage;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Section;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Section.SectionType;
import club.joylink.xiannccda.entity.PublishedGi;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.google.common.collect.HashBasedTable;
import com.google.protobuf.GeneratedMessageV3.Builder;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.MessageOrBuilder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
@ -31,6 +36,15 @@ public class LineGraphicDataRepository {
private static final Map<Integer, Map<String, CoordinateConvertor>> lineCoordinateMain =
new HashMap<>();
/**
* 线路-设备code-设备
*/
private static final HashBasedTable<Short, String, MessageOrBuilder> line_code_table = HashBasedTable.create();
/**
* 线路-设备由于现在许多设备code都是""使用line_code_table会覆盖临时加此map后续删除
*/
private static final HashMap<Short, List<MessageOrBuilder>> line_map = new HashMap<>();
/**
* 缓存线路数据信息
*
@ -52,6 +66,9 @@ public class LineGraphicDataRepository {
// 设置公里标后开始构建逻辑区段的编码公里标信息
setUpLogicSectionInfo(lineDataMap, storage);
lineGraphMap.put(publishGi.getLineId(), lineDataMap);
// 填充line_code_table
fillLineCodeTable(publishGi.getLineId(), storage);
}
} catch (InvalidProtocolBufferException e) {
log.error("反序列化信息失败", e);
@ -92,6 +109,38 @@ public class LineGraphicDataRepository {
lineGraphMap.remove(id);
}
public static <T> T getDevice(short lineId, String code, Class<T> cls) {
return (T) line_code_table.get(lineId, code);
}
public static <T extends MessageOrBuilder> Stream<T> getDevices(short lineId, Class<T> cls) {
return line_map.get(lineId).stream()
.filter(builder -> cls.isAssignableFrom(builder.getClass()))
.map(builder -> (T) builder);
// return line_code_table.row(lineId).values().stream()
// .filter(builder -> cls.isAssignableFrom(builder.getClass()))
// .map(builder -> (T) builder);
}
private static void fillLineCodeTable(Integer lineId, RtssGraphicStorage storage) {
Short shortLineId = lineId.shortValue();
List<MessageOrBuilder> list = storage.getAllFields().entrySet().stream()
.filter(entry -> entry.getKey().isRepeated())
.flatMap(entry -> ((List<MessageOrBuilder>) entry.getValue()).stream())
.collect(Collectors.toList());
line_map.put(shortLineId, list);
// storage.getAllFields().forEach((fd, value) -> {
// if (fd.isRepeated()) {
// List<MessageOrBuilder> list = (List<MessageOrBuilder>) value;
// for (MessageOrBuilder builder : list) {
// FieldDescriptor fieldDescriptor = builder.getDescriptorForType().findFieldByName("code");
// String code = (String) builder.getField(fieldDescriptor);
// line_code_table.put(shortLineId, code, builder);
// }
// }
// });
}
/**
* 构建程序中的区段信息
*

View File

@ -0,0 +1,41 @@
package club.joylink.xiannccda.controller;
import club.joylink.xiannccda.dto.AlertMockDTO;
import club.joylink.xiannccda.service.AlertMockService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
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;
@RestController
@RequestMapping("/api/alert/mock")
@Tag(name = "模拟故障接口")
public class AlertMockController {
private AlertMockService alertMockService;
public AlertMockController(AlertMockService alertMockService) {
this.alertMockService = alertMockService;
}
@SecurityRequirement(name = "jwt")
@Operation(summary = "设置模拟故障")
@ApiResponse(description = "设置模拟故障")
@PostMapping("/set")
public void setAlert(@RequestBody @Validated AlertMockDTO alertMockDTO) {
alertMockService.setAlert(alertMockDTO);
}
@SecurityRequirement(name = "jwt")
@Operation(summary = "清除模拟故障")
@ApiResponse(description = "清除模拟故障")
@PostMapping("/clear")
public void clearMockAlert() {
alertMockService.clearMockAlert();
}
}

View File

@ -0,0 +1,13 @@
package club.joylink.xiannccda.dto;
import club.joylink.xiannccda.alert.AlertType;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
@Data
public class AlertMockDTO {
@NotNull(message = "线路id不能为null")
private Short lineId;
@NotNull(message = "故障类型不能为null")
private AlertType alertType;
}

View File

@ -183,6 +183,26 @@ public final class DeviceInfoProto {
*/
com.google.protobuf.ByteString
getPhysicalSectionIdBytes();
/**
* <pre>
* 目的地码
* </pre>
*
* <code>string destinationCode = 7;</code>
* @return The destinationCode.
*/
java.lang.String getDestinationCode();
/**
* <pre>
* 目的地码
* </pre>
*
* <code>string destinationCode = 7;</code>
* @return The bytes for destinationCode.
*/
com.google.protobuf.ByteString
getDestinationCodeBytes();
}
/**
* <pre>
@ -208,6 +228,7 @@ public final class DeviceInfoProto {
kilometerSystem_ = java.util.Collections.emptyList();
convertKilometer_ = emptyLongList();
physicalSectionId_ = "";
destinationCode_ = "";
}
@java.lang.Override
@ -518,6 +539,53 @@ public final class DeviceInfoProto {
}
}
public static final int DESTINATIONCODE_FIELD_NUMBER = 7;
@SuppressWarnings("serial")
private volatile java.lang.Object destinationCode_ = "";
/**
* <pre>
* 目的地码
* </pre>
*
* <code>string destinationCode = 7;</code>
* @return The destinationCode.
*/
@java.lang.Override
public java.lang.String getDestinationCode() {
java.lang.Object ref = destinationCode_;
if (ref instanceof java.lang.String) {
return (java.lang.String) ref;
} else {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
destinationCode_ = s;
return s;
}
}
/**
* <pre>
* 目的地码
* </pre>
*
* <code>string destinationCode = 7;</code>
* @return The bytes for destinationCode.
*/
@java.lang.Override
public com.google.protobuf.ByteString
getDestinationCodeBytes() {
java.lang.Object ref = destinationCode_;
if (ref instanceof java.lang.String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
destinationCode_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
@ -555,6 +623,9 @@ public final class DeviceInfoProto {
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(physicalSectionId_)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 6, physicalSectionId_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(destinationCode_)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 7, destinationCode_);
}
getUnknownFields().writeTo(output);
}
@ -599,6 +670,9 @@ public final class DeviceInfoProto {
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(physicalSectionId_)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(6, physicalSectionId_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(destinationCode_)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(7, destinationCode_);
}
size += getUnknownFields().getSerializedSize();
memoizedSize = size;
return size;
@ -626,6 +700,8 @@ public final class DeviceInfoProto {
.equals(other.getConvertKilometerList())) return false;
if (!getPhysicalSectionId()
.equals(other.getPhysicalSectionId())) return false;
if (!getDestinationCode()
.equals(other.getDestinationCode())) return false;
if (!getUnknownFields().equals(other.getUnknownFields())) return false;
return true;
}
@ -655,6 +731,8 @@ public final class DeviceInfoProto {
}
hash = (37 * hash) + PHYSICALSECTIONID_FIELD_NUMBER;
hash = (53 * hash) + getPhysicalSectionId().hashCode();
hash = (37 * hash) + DESTINATIONCODE_FIELD_NUMBER;
hash = (53 * hash) + getDestinationCode().hashCode();
hash = (29 * hash) + getUnknownFields().hashCode();
memoizedHashCode = hash;
return hash;
@ -803,6 +881,7 @@ public final class DeviceInfoProto {
bitField0_ = (bitField0_ & ~0x00000008);
convertKilometer_ = emptyLongList();
physicalSectionId_ = "";
destinationCode_ = "";
return this;
}
@ -867,6 +946,9 @@ public final class DeviceInfoProto {
if (((from_bitField0_ & 0x00000020) != 0)) {
result.physicalSectionId_ = physicalSectionId_;
}
if (((from_bitField0_ & 0x00000040) != 0)) {
result.destinationCode_ = destinationCode_;
}
}
@java.lang.Override
@ -942,6 +1024,11 @@ public final class DeviceInfoProto {
bitField0_ |= 0x00000020;
onChanged();
}
if (!other.getDestinationCode().isEmpty()) {
destinationCode_ = other.destinationCode_;
bitField0_ |= 0x00000040;
onChanged();
}
this.mergeUnknownFields(other.getUnknownFields());
onChanged();
return this;
@ -1018,6 +1105,11 @@ public final class DeviceInfoProto {
bitField0_ |= 0x00000020;
break;
} // case 50
case 58: {
destinationCode_ = input.readStringRequireUtf8();
bitField0_ |= 0x00000040;
break;
} // case 58
default: {
if (!super.parseUnknownField(input, extensionRegistry, tag)) {
done = true; // was an endgroup tag
@ -1858,6 +1950,98 @@ public final class DeviceInfoProto {
onChanged();
return this;
}
private java.lang.Object destinationCode_ = "";
/**
* <pre>
* 目的地码
* </pre>
*
* <code>string destinationCode = 7;</code>
* @return The destinationCode.
*/
public java.lang.String getDestinationCode() {
java.lang.Object ref = destinationCode_;
if (!(ref instanceof java.lang.String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
destinationCode_ = s;
return s;
} else {
return (java.lang.String) ref;
}
}
/**
* <pre>
* 目的地码
* </pre>
*
* <code>string destinationCode = 7;</code>
* @return The bytes for destinationCode.
*/
public com.google.protobuf.ByteString
getDestinationCodeBytes() {
java.lang.Object ref = destinationCode_;
if (ref instanceof String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
destinationCode_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
/**
* <pre>
* 目的地码
* </pre>
*
* <code>string destinationCode = 7;</code>
* @param value The destinationCode to set.
* @return This builder for chaining.
*/
public Builder setDestinationCode(
java.lang.String value) {
if (value == null) { throw new NullPointerException(); }
destinationCode_ = value;
bitField0_ |= 0x00000040;
onChanged();
return this;
}
/**
* <pre>
* 目的地码
* </pre>
*
* <code>string destinationCode = 7;</code>
* @return This builder for chaining.
*/
public Builder clearDestinationCode() {
destinationCode_ = getDefaultInstance().getDestinationCode();
bitField0_ = (bitField0_ & ~0x00000040);
onChanged();
return this;
}
/**
* <pre>
* 目的地码
* </pre>
*
* <code>string destinationCode = 7;</code>
* @param value The bytes for destinationCode to set.
* @return This builder for chaining.
*/
public Builder setDestinationCodeBytes(
com.google.protobuf.ByteString value) {
if (value == null) { throw new NullPointerException(); }
checkByteStringIsUtf8(value);
destinationCode_ = value;
bitField0_ |= 0x00000040;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
@ -3348,16 +3532,16 @@ public final class DeviceInfoProto {
static {
java.lang.String[] descriptorData = {
"\n\021device_info.proto\022\005state\032\033stationLayou" +
"tGraphics.proto\"\243\001\n\007Section\022\n\n\002id\030\001 \001(\t\022" +
"tGraphics.proto\"\274\001\n\007Section\022\n\n\002id\030\001 \001(\t\022" +
"\014\n\004code\030\002 \001(\t\022\022\n\nchildrenId\030\003 \003(\t\0225\n\017kil" +
"ometerSystem\030\004 \003(\0132\034.graphicData.Kilomet" +
"erSystem\022\030\n\020convertKilometer\030\005 \003(\003\022\031\n\021ph" +
"ysicalSectionId\030\006 \001(\t\"t\n\007Turnout\022\n\n\002id\030\001" +
" \001(\t\022\014\n\004code\030\002 \001(\t\0225\n\017kilometerSystem\030\003 " +
"\003(\0132\034.graphicData.KilometerSystem\022\030\n\020con" +
"vertKilometer\030\004 \003(\003B4\n!club.joylink.xian" +
"nccda.dto.protosB\017DeviceInfoProtob\006proto" +
"3"
"ysicalSectionId\030\006 \001(\t\022\027\n\017destinationCode" +
"\030\007 \001(\t\"t\n\007Turnout\022\n\n\002id\030\001 \001(\t\022\014\n\004code\030\002 " +
"\001(\t\0225\n\017kilometerSystem\030\003 \003(\0132\034.graphicDa" +
"ta.KilometerSystem\022\030\n\020convertKilometer\030\004" +
" \003(\003B4\n!club.joylink.xiannccda.dto.proto" +
"sB\017DeviceInfoProtob\006proto3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
@ -3369,7 +3553,7 @@ public final class DeviceInfoProto {
internal_static_state_Section_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_state_Section_descriptor,
new java.lang.String[] { "Id", "Code", "ChildrenId", "KilometerSystem", "ConvertKilometer", "PhysicalSectionId", });
new java.lang.String[] { "Id", "Code", "ChildrenId", "KilometerSystem", "ConvertKilometer", "PhysicalSectionId", "DestinationCode", });
internal_static_state_Turnout_descriptor =
getDescriptor().getMessageTypes().get(1);
internal_static_state_Turnout_fieldAccessorTable = new

View File

@ -137,44 +137,10 @@ public final class NccAlertInfoMessageProto {
int getAlertTipId();
/**
* <pre>
*故障设备信息
* </pre>
*
* <code>string device_info = 6;</code>
* @return The deviceInfo.
* <code>bool mock = 6;</code>
* @return The mock.
*/
java.lang.String getDeviceInfo();
/**
* <pre>
*故障设备信息
* </pre>
*
* <code>string device_info = 6;</code>
* @return The bytes for deviceInfo.
*/
com.google.protobuf.ByteString
getDeviceInfoBytes();
/**
* <pre>
*导致报警的原因
* </pre>
*
* <code>string reason = 7;</code>
* @return The reason.
*/
java.lang.String getReason();
/**
* <pre>
*导致报警的原因
* </pre>
*
* <code>string reason = 7;</code>
* @return The bytes for reason.
*/
com.google.protobuf.ByteString
getReasonBytes();
boolean getMock();
}
/**
* Protobuf type {@code alert.NccAlertInfoMessage.Message}
@ -193,8 +159,6 @@ public final class NccAlertInfoMessageProto {
level_ = "";
alertTime_ = "";
info_ = "";
deviceInfo_ = "";
reason_ = "";
}
@java.lang.Override
@ -384,98 +348,15 @@ public final class NccAlertInfoMessageProto {
return alertTipId_;
}
public static final int DEVICE_INFO_FIELD_NUMBER = 6;
@SuppressWarnings("serial")
private volatile java.lang.Object deviceInfo_ = "";
public static final int MOCK_FIELD_NUMBER = 6;
private boolean mock_ = false;
/**
* <pre>
*故障设备信息
* </pre>
*
* <code>string device_info = 6;</code>
* @return The deviceInfo.
* <code>bool mock = 6;</code>
* @return The mock.
*/
@java.lang.Override
public java.lang.String getDeviceInfo() {
java.lang.Object ref = deviceInfo_;
if (ref instanceof java.lang.String) {
return (java.lang.String) ref;
} else {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
deviceInfo_ = s;
return s;
}
}
/**
* <pre>
*故障设备信息
* </pre>
*
* <code>string device_info = 6;</code>
* @return The bytes for deviceInfo.
*/
@java.lang.Override
public com.google.protobuf.ByteString
getDeviceInfoBytes() {
java.lang.Object ref = deviceInfo_;
if (ref instanceof java.lang.String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
deviceInfo_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
public static final int REASON_FIELD_NUMBER = 7;
@SuppressWarnings("serial")
private volatile java.lang.Object reason_ = "";
/**
* <pre>
*导致报警的原因
* </pre>
*
* <code>string reason = 7;</code>
* @return The reason.
*/
@java.lang.Override
public java.lang.String getReason() {
java.lang.Object ref = reason_;
if (ref instanceof java.lang.String) {
return (java.lang.String) ref;
} else {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
reason_ = s;
return s;
}
}
/**
* <pre>
*导致报警的原因
* </pre>
*
* <code>string reason = 7;</code>
* @return The bytes for reason.
*/
@java.lang.Override
public com.google.protobuf.ByteString
getReasonBytes() {
java.lang.Object ref = reason_;
if (ref instanceof java.lang.String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
reason_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
public boolean getMock() {
return mock_;
}
private byte memoizedIsInitialized = -1;
@ -507,11 +388,8 @@ public final class NccAlertInfoMessageProto {
if (alertTipId_ != 0) {
output.writeInt32(5, alertTipId_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(deviceInfo_)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 6, deviceInfo_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(reason_)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 7, reason_);
if (mock_ != false) {
output.writeBool(6, mock_);
}
getUnknownFields().writeTo(output);
}
@ -538,11 +416,9 @@ public final class NccAlertInfoMessageProto {
size += com.google.protobuf.CodedOutputStream
.computeInt32Size(5, alertTipId_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(deviceInfo_)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(6, deviceInfo_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(reason_)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(7, reason_);
if (mock_ != false) {
size += com.google.protobuf.CodedOutputStream
.computeBoolSize(6, mock_);
}
size += getUnknownFields().getSerializedSize();
memoizedSize = size;
@ -569,10 +445,8 @@ public final class NccAlertInfoMessageProto {
.equals(other.getInfo())) return false;
if (getAlertTipId()
!= other.getAlertTipId()) return false;
if (!getDeviceInfo()
.equals(other.getDeviceInfo())) return false;
if (!getReason()
.equals(other.getReason())) return false;
if (getMock()
!= other.getMock()) return false;
if (!getUnknownFields().equals(other.getUnknownFields())) return false;
return true;
}
@ -594,10 +468,9 @@ public final class NccAlertInfoMessageProto {
hash = (53 * hash) + getInfo().hashCode();
hash = (37 * hash) + ALERT_TIP_ID_FIELD_NUMBER;
hash = (53 * hash) + getAlertTipId();
hash = (37 * hash) + DEVICE_INFO_FIELD_NUMBER;
hash = (53 * hash) + getDeviceInfo().hashCode();
hash = (37 * hash) + REASON_FIELD_NUMBER;
hash = (53 * hash) + getReason().hashCode();
hash = (37 * hash) + MOCK_FIELD_NUMBER;
hash = (53 * hash) + com.google.protobuf.Internal.hashBoolean(
getMock());
hash = (29 * hash) + getUnknownFields().hashCode();
memoizedHashCode = hash;
return hash;
@ -734,8 +607,7 @@ public final class NccAlertInfoMessageProto {
alertTime_ = "";
info_ = "";
alertTipId_ = 0;
deviceInfo_ = "";
reason_ = "";
mock_ = false;
return this;
}
@ -785,10 +657,7 @@ public final class NccAlertInfoMessageProto {
result.alertTipId_ = alertTipId_;
}
if (((from_bitField0_ & 0x00000020) != 0)) {
result.deviceInfo_ = deviceInfo_;
}
if (((from_bitField0_ & 0x00000040) != 0)) {
result.reason_ = reason_;
result.mock_ = mock_;
}
}
@ -827,15 +696,8 @@ public final class NccAlertInfoMessageProto {
if (other.getAlertTipId() != 0) {
setAlertTipId(other.getAlertTipId());
}
if (!other.getDeviceInfo().isEmpty()) {
deviceInfo_ = other.deviceInfo_;
bitField0_ |= 0x00000020;
onChanged();
}
if (!other.getReason().isEmpty()) {
reason_ = other.reason_;
bitField0_ |= 0x00000040;
onChanged();
if (other.getMock() != false) {
setMock(other.getMock());
}
this.mergeUnknownFields(other.getUnknownFields());
onChanged();
@ -888,16 +750,11 @@ public final class NccAlertInfoMessageProto {
bitField0_ |= 0x00000010;
break;
} // case 40
case 50: {
deviceInfo_ = input.readStringRequireUtf8();
case 48: {
mock_ = input.readBool();
bitField0_ |= 0x00000020;
break;
} // case 50
case 58: {
reason_ = input.readStringRequireUtf8();
bitField0_ |= 0x00000040;
break;
} // case 58
} // case 48
default: {
if (!super.parseUnknownField(input, extensionRegistry, tag)) {
done = true; // was an endgroup tag
@ -1235,186 +1092,34 @@ public final class NccAlertInfoMessageProto {
return this;
}
private java.lang.Object deviceInfo_ = "";
private boolean mock_ ;
/**
* <pre>
*故障设备信息
* </pre>
*
* <code>string device_info = 6;</code>
* @return The deviceInfo.
* <code>bool mock = 6;</code>
* @return The mock.
*/
public java.lang.String getDeviceInfo() {
java.lang.Object ref = deviceInfo_;
if (!(ref instanceof java.lang.String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
deviceInfo_ = s;
return s;
} else {
return (java.lang.String) ref;
}
@java.lang.Override
public boolean getMock() {
return mock_;
}
/**
* <pre>
*故障设备信息
* </pre>
*
* <code>string device_info = 6;</code>
* @return The bytes for deviceInfo.
*/
public com.google.protobuf.ByteString
getDeviceInfoBytes() {
java.lang.Object ref = deviceInfo_;
if (ref instanceof String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
deviceInfo_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
/**
* <pre>
*故障设备信息
* </pre>
*
* <code>string device_info = 6;</code>
* @param value The deviceInfo to set.
* <code>bool mock = 6;</code>
* @param value The mock to set.
* @return This builder for chaining.
*/
public Builder setDeviceInfo(
java.lang.String value) {
if (value == null) { throw new NullPointerException(); }
deviceInfo_ = value;
bitField0_ |= 0x00000020;
onChanged();
return this;
}
/**
* <pre>
*故障设备信息
* </pre>
*
* <code>string device_info = 6;</code>
* @return This builder for chaining.
*/
public Builder clearDeviceInfo() {
deviceInfo_ = getDefaultInstance().getDeviceInfo();
bitField0_ = (bitField0_ & ~0x00000020);
onChanged();
return this;
}
/**
* <pre>
*故障设备信息
* </pre>
*
* <code>string device_info = 6;</code>
* @param value The bytes for deviceInfo to set.
* @return This builder for chaining.
*/
public Builder setDeviceInfoBytes(
com.google.protobuf.ByteString value) {
if (value == null) { throw new NullPointerException(); }
checkByteStringIsUtf8(value);
deviceInfo_ = value;
bitField0_ |= 0x00000020;
onChanged();
return this;
}
public Builder setMock(boolean value) {
private java.lang.Object reason_ = "";
/**
* <pre>
*导致报警的原因
* </pre>
*
* <code>string reason = 7;</code>
* @return The reason.
*/
public java.lang.String getReason() {
java.lang.Object ref = reason_;
if (!(ref instanceof java.lang.String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
reason_ = s;
return s;
} else {
return (java.lang.String) ref;
}
}
/**
* <pre>
*导致报警的原因
* </pre>
*
* <code>string reason = 7;</code>
* @return The bytes for reason.
*/
public com.google.protobuf.ByteString
getReasonBytes() {
java.lang.Object ref = reason_;
if (ref instanceof String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
reason_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
/**
* <pre>
*导致报警的原因
* </pre>
*
* <code>string reason = 7;</code>
* @param value The reason to set.
* @return This builder for chaining.
*/
public Builder setReason(
java.lang.String value) {
if (value == null) { throw new NullPointerException(); }
reason_ = value;
bitField0_ |= 0x00000040;
mock_ = value;
bitField0_ |= 0x00000020;
onChanged();
return this;
}
/**
* <pre>
*导致报警的原因
* </pre>
*
* <code>string reason = 7;</code>
* <code>bool mock = 6;</code>
* @return This builder for chaining.
*/
public Builder clearReason() {
reason_ = getDefaultInstance().getReason();
bitField0_ = (bitField0_ & ~0x00000040);
onChanged();
return this;
}
/**
* <pre>
*导致报警的原因
* </pre>
*
* <code>string reason = 7;</code>
* @param value The bytes for reason to set.
* @return This builder for chaining.
*/
public Builder setReasonBytes(
com.google.protobuf.ByteString value) {
if (value == null) { throw new NullPointerException(); }
checkByteStringIsUtf8(value);
reason_ = value;
bitField0_ |= 0x00000040;
public Builder clearMock() {
bitField0_ = (bitField0_ & ~0x00000020);
mock_ = false;
onChanged();
return this;
}
@ -2187,14 +1892,14 @@ public final class NccAlertInfoMessageProto {
descriptor;
static {
java.lang.String[] descriptorData = {
"\n\017alertInfo.proto\022\005alert\"\317\001\n\023NccAlertInf" +
"\n\017alertInfo.proto\022\005alert\"\267\001\n\023NccAlertInf" +
"oMessage\0224\n\010messages\030\001 \003(\0132\".alert.NccAl" +
"ertInfoMessage.Message\032\201\001\n\007Message\022\n\n\002id" +
"\030\001 \001(\t\022\r\n\005level\030\002 \001(\t\022\022\n\nalert_time\030\003 \001(" +
"\t\022\014\n\004info\030\004 \001(\t\022\024\n\014alert_tip_id\030\005 \001(\005\022\023\n" +
"\013device_info\030\006 \001(\t\022\016\n\006reason\030\007 \001(\tB=\n!cl" +
"ub.joylink.xiannccda.dto.protosB\030NccAler" +
"tInfoMessageProtob\006proto3"
"ertInfoMessage.Message\032j\n\007Message\022\n\n\002id\030" +
"\001 \001(\t\022\r\n\005level\030\002 \001(\t\022\022\n\nalert_time\030\003 \001(\t" +
"\022\014\n\004info\030\004 \001(\t\022\024\n\014alert_tip_id\030\005 \001(\005\022\014\n\004" +
"mock\030\006 \001(\010B=\n!club.joylink.xiannccda.dto" +
".protosB\030NccAlertInfoMessageProtob\006proto" +
"3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
@ -2211,7 +1916,7 @@ public final class NccAlertInfoMessageProto {
internal_static_alert_NccAlertInfoMessage_Message_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_alert_NccAlertInfoMessage_Message_descriptor,
new java.lang.String[] { "Id", "Level", "AlertTime", "Info", "AlertTipId", "DeviceInfo", "Reason", });
new java.lang.String[] { "Id", "Level", "AlertTime", "Info", "AlertTipId", "Mock", });
}
// @@protoc_insertion_point(outer_class_scope)

View File

@ -0,0 +1,56 @@
package club.joylink.xiannccda.service;
import club.joylink.xiannccda.alert.AlertDetail;
import club.joylink.xiannccda.alert.AlertDetailFactory;
import club.joylink.xiannccda.alert.AlertType;
import club.joylink.xiannccda.alert.core.AlertManager;
import club.joylink.xiannccda.ats.cache.LineGraphicDataRepository;
import club.joylink.xiannccda.dto.AlertMockDTO;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Platform;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Station;
import club.joylink.xiannccda.exception.BusinessExceptionAssertEnum;
import club.joylink.xiannccda.ws.NccAlertMessageServer;
import com.google.protobuf.MessageOrBuilder;
import java.util.stream.Stream;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class AlertMockService {
@Autowired
private AlertDetailFactory alertDetailFactory;
public void setAlert(AlertMockDTO alertMockDTO) {
short lineId = alertMockDTO.getLineId();
AlertType alertType = alertMockDTO.getAlertType();
AlertDetail alertDetail = buildAlertDetail(alertType, lineId);
AlertManager alertManager = AlertManager.getDefault();
alertManager.emit(alertDetail);
}
private AlertDetail buildAlertDetail(AlertType alertType, short lineId) {
MessageOrBuilder messageOrBuilder;
switch (alertType) {
case BLUE_DISPLAY -> {
Stream<Station> stream = LineGraphicDataRepository.getDevices(lineId, Station.class);
messageOrBuilder = stream.findFirst()
.orElseThrow(BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL::exception);
}
case TRAIN_DELAY -> {
throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception();
}
case PLATFORM_DOOR_WITHOUT_LOCKED_SIGNAL, PLATFORM_DOOR_CANNOT_OPEN, PLATFORM_DOOR_CANNOT_CLOSE -> {
Stream<Platform> stream = LineGraphicDataRepository.getDevices(lineId, Platform.class);
messageOrBuilder = stream.findFirst()
.orElseThrow(BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL::exception);
}
default -> throw new IllegalStateException("Unexpected value: " + alertType);
}
return alertDetailFactory.getAlertDetail(alertType, lineId, true, messageOrBuilder);
}
public void clearMockAlert() {
NccAlertMessageServer.getDefault().clearMockAlert();
}
}

View File

@ -5,9 +5,11 @@ import club.joylink.xiannccda.dto.protos.NccAlertInfoMessageProto.NccAlertInfoMe
import club.joylink.xiannccda.dto.protos.NccAlertInfoMessageProto.NccAlertInfoMessage.Builder;
import club.joylink.xiannccda.dto.protos.NccAlertInfoMessageProto.NccAlertInfoMessage.Message;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
@ -82,14 +84,25 @@ public class NccAlertMessageServer implements IMessageServer {
pendingMsgQueue.add(alertInfo);
}
public void clearMockAlert() {
Iterator<Entry<String, Message>> iterator = allMsg.entrySet().iterator();
for (int i = 0; iterator.hasNext() && i < 10000; i++) {
Entry<String, Message> next = iterator.next();
if (next.getValue().getMock()) {
iterator.remove();
}
}
}
private NccAlertInfoMessage.Message convertToMessage(NccAlertInfo<?> alertInfo) {
Message.Builder builder = Message.newBuilder()
.setId(alertInfo.getId())
.setLevel(alertInfo.getLevel())
.setAlertTime(alertInfo.getAlertTime().toString())
.setInfo(alertInfo.getInfo())
.setDeviceInfo(alertInfo.getDeviceInfo())
.setReason(alertInfo.getReason());
.setMock(alertInfo.isMock());
// .setDeviceInfo(alertInfo.getDeviceInfo())
// .setReason(alertInfo.getReason());
Integer alertTipId = alertInfo.getAlertTipId();
if (alertTipId != null) {
builder.setAlertTipId(alertTipId);

View File

@ -8,7 +8,7 @@ import java.util.Arrays;
import java.util.List;
import org.assertj.core.util.Lists;
public class GenertateProtoBufUtil {
public class GenerateProtoBufUtil {
private final static String EXE_BIN_FILE = String.join(File.separator,
System.getProperty("user.dir"), "xian-ncc-da-message",
@ -19,7 +19,7 @@ public class GenertateProtoBufUtil {
private boolean pullMessage;
// private String gitPullPath;
public GenertateProtoBufUtil(String rootPath, boolean pullMessage) {
public GenerateProtoBufUtil(String rootPath, boolean pullMessage) {
this.pullMessage = pullMessage;
String sourcePath = String.join(File.separator, rootPath,
"xian-ncc-da-message", "protos");

View File

@ -30,11 +30,11 @@ public class WebSocketTest {
WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
headers.set("Authorization",
"Bearer eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJzZWxmIiwic3ViIjoiMTQiLCJleHAiOjE2ODgzNDY3ODgsImlhdCI6MTY4ODA4NzU4OH0.CCAHMqzzVXDYlvIBYhOBT92_MaYTSUDMmPwkzFDMRXR_LSidyVkm3o5SmqaiORjTgx_B0kxgwgpDGdXs3A_tmDrHolIUCvSaiez-hK3v30Z3Z4DhxtE8073tAqGdM-uU1eXTGC7zm20tM5riDe_Qy5PF5lf9qe9ty0Y06s62FNRNcyCBw-DuhkQcSkWfcMiUHKYVge2weO5Mzm1nD-1yViI359-smYU5eYJInVBdOaBvOECQ4OF8GJQ9rfgktPJAUsrXT0bf8cHp-fUUSvuNv5QUVmg2j-tZDIjhlN3OkXpHDiXuMPnx_lHVS95CO0metFozU2OT7uYukV5Z6RN4JA");
"Bearer eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJzZWxmIiwic3ViIjoiMTQiLCJleHAiOjE2OTAxMDc0NzAsImlhdCI6MTY4OTg0ODI3MH0.WXwKt6M12AMW-9Fhsop-nGtwxQR4jw7t-EIN2RUKLfRSaMlMgTgHPr_p47GXmQszJndPthUN3IkLBRMfVyEK3y4e9Uq5B2gD2DBgXuFgdM85PlJF8NHThDGyH-eoc7ZbPD1geCSFTiDbzuWuY4b1AcFnP2p4VdoU9s28FHoJzQRKL2cot-ZwexEVhFzVXJkXgF2oKpbdMamVHkTRuGRzmrYFzur2mqWKPI2XMuOdZ79GKK7yFzflXGZEPAY7zw_iwZmAc-grNlHfuwam9kTKz2nPUnsZM0pqkmRvcELsz63tk4uo6FLnsFkN7XHMj5AvHO92sIspQenw1s1vHgoESw");
StompHeaders stompHeaders = new StompHeaders();
stompHeaders.set("Authorization",
"Bearer eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJzZWxmIiwic3ViIjoiMTQiLCJleHAiOjE2ODgzNDY3ODgsImlhdCI6MTY4ODA4NzU4OH0.CCAHMqzzVXDYlvIBYhOBT92_MaYTSUDMmPwkzFDMRXR_LSidyVkm3o5SmqaiORjTgx_B0kxgwgpDGdXs3A_tmDrHolIUCvSaiez-hK3v30Z3Z4DhxtE8073tAqGdM-uU1eXTGC7zm20tM5riDe_Qy5PF5lf9qe9ty0Y06s62FNRNcyCBw-DuhkQcSkWfcMiUHKYVge2weO5Mzm1nD-1yViI359-smYU5eYJInVBdOaBvOECQ4OF8GJQ9rfgktPJAUsrXT0bf8cHp-fUUSvuNv5QUVmg2j-tZDIjhlN3OkXpHDiXuMPnx_lHVS95CO0metFozU2OT7uYukV5Z6RN4JA");
"Bearer eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJzZWxmIiwic3ViIjoiMTQiLCJleHAiOjE2OTAxMDc0NzAsImlhdCI6MTY4OTg0ODI3MH0.WXwKt6M12AMW-9Fhsop-nGtwxQR4jw7t-EIN2RUKLfRSaMlMgTgHPr_p47GXmQszJndPthUN3IkLBRMfVyEK3y4e9Uq5B2gD2DBgXuFgdM85PlJF8NHThDGyH-eoc7ZbPD1geCSFTiDbzuWuY4b1AcFnP2p4VdoU9s28FHoJzQRKL2cot-ZwexEVhFzVXJkXgF2oKpbdMamVHkTRuGRzmrYFzur2mqWKPI2XMuOdZ79GKK7yFzflXGZEPAY7zw_iwZmAc-grNlHfuwam9kTKz2nPUnsZM0pqkmRvcELsz63tk4uo6FLnsFkN7XHMj5AvHO92sIspQenw1s1vHgoESw");
StompSessionHandlerAdapter sessionHandler = new StompSessionHandlerAdapter() {
@Override

@ -1 +1 @@
Subproject commit 90b6f4600e531c496d849163653acb80c6e933ea
Subproject commit e521fa9d3372987b45a4d9bdb63544cf4e1f088f