Merge branch 'master' into develop_wei

This commit is contained in:
weizhihong 2023-07-21 11:09:18 +08:00
commit d338cbb135
20 changed files with 509 additions and 506 deletions

View File

@ -12,7 +12,9 @@ public interface AlertDetail {
String getInfo(); String getInfo();
String getDeviceInfo(); boolean isMock();
String getReason(); // String getDeviceInfo();
//
// String getReason();
} }

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; package club.joylink.xiannccda.alert;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import lombok.AccessLevel;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
@ -8,15 +9,16 @@ import lombok.Data;
* 西安三号线报警 * 西安三号线报警
*/ */
@Data @Data
@AllArgsConstructor @AllArgsConstructor(access = AccessLevel.PACKAGE)
public class AlertDetailImpl implements AlertDetail { public class AlertDetailImpl implements AlertDetail {
private AlertType alertType; private AlertType alertType;
private LocalDateTime alertTime; private LocalDateTime alertTime;
private Integer alertTipId; private Integer alertTipId;
private String info; private String info;
private String deviceInfo; private boolean mock;
private String reason; // private String deviceInfo;
// private String reason;
@Override @Override
public AlertType getAlertType() { public AlertType getAlertType() {
@ -33,18 +35,25 @@ public class AlertDetailImpl implements AlertDetail {
return info; return info;
} }
@Override
public String getDeviceInfo() {
return deviceInfo;
}
@Override
public String getReason() {
return reason;
}
@Override @Override
public Integer getAlertTipId() { public Integer getAlertTipId() {
return alertTipId; 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 @Override
public void run(ApplicationArguments args) throws Exception { public void run(ApplicationArguments args) throws Exception {
AlertManager alertManager = AlertManager.getInstance(); AlertManager alertManager = AlertManager.getDefault();
//报警源 //报警源
alertManager.addTask(trainDelayAlertMonitoringTask); alertManager.addTask(trainDelayAlertMonitoringTask);
alertManager.addTask(blueDisplayAlertMonitoringTask); alertManager.addTask(blueDisplayAlertMonitoringTask);

View File

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

View File

@ -1,12 +1,38 @@
package club.joylink.xiannccda.alert; package club.joylink.xiannccda.alert;
import club.joylink.xiannccda.exception.BusinessExceptionAssertEnum;
import java.util.Arrays;
import lombok.Getter;
@Getter
public enum AlertTipLocationType { 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; package club.joylink.xiannccda.alert;
import club.joylink.xiannccda.alert.core.AlertManager;
import club.joylink.xiannccda.alert.core.AlertMonitoringTask; import club.joylink.xiannccda.alert.core.AlertMonitoringTask;
import club.joylink.xiannccda.entity.AlertTip; import club.joylink.xiannccda.entity.AlertTip;
import club.joylink.xiannccda.repository.IAlertTipRepository; import club.joylink.xiannccda.repository.IAlertTipRepository;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import java.time.LocalDateTime;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
public class BlueDisplayAlertMonitoringTask implements AlertMonitoringTask { public class BlueDisplayAlertMonitoringTask implements AlertMonitoringTask {
private IAlertTipRepository alertTipRepository; private IAlertTipRepository alertTipRepository;
private boolean alertTriggered;
public BlueDisplayAlertMonitoringTask(IAlertTipRepository alertTipRepository) { public BlueDisplayAlertMonitoringTask(IAlertTipRepository alertTipRepository) {
this.alertTipRepository = alertTipRepository; this.alertTipRepository = alertTipRepository;
@ -26,26 +23,41 @@ public class BlueDisplayAlertMonitoringTask implements AlertMonitoringTask {
@Override @Override
public void run() { public void run() {
LocalDateTime now = LocalDateTime.now(); // short lineId = 3;
if (alertTriggered) { // Map<Short, RtuOrBuilder> id_rtu_map = new HashMap<>();
if (now.getSecond() % 30 != 0) { // if (CollectionUtils.isEmpty(id_rtu_map)) {
alertTriggered = false; // return;
} // }
} else { //
if (now.getSecond() % 30 == 0) { // AlertManager alertManager = AlertManager.getDefault();
AlertType alertType = AlertType.BLUE_DISPLAY; // LocalDateTime now = LocalDateTime.now();
LambdaQueryWrapper<AlertTip> queryWrapper = Wrappers.lambdaQuery(AlertTip.class); // AlertType alertType = AlertType.BLUE_DISPLAY;
queryWrapper.eq(AlertTip::getAlertType, alertType) // if (id_rtu_map.values().stream().allMatch(RtuOrBuilder::getIpRtuStusDown)) {
.eq(AlertTip::getLocationType, AlertTipLocationType.QX); // AlertTipLocationType locationType = AlertTipLocationType.QX;
AlertTip alertTip = alertTipRepository.getOne(queryWrapper); // Integer alertTipId = getAlertTipId(alertType, locationType);
Integer alertTipId = alertTip == null ? null : alertTip.getId(); //
// 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(); private Integer getAlertTipId(AlertType alertType, AlertTipLocationType locationType) {
AlertDetailImpl alert = new AlertDetailImpl(alertType, now, alertTipId, "[3号线]全线蓝显", LambdaQueryWrapper<AlertTip> queryWrapper = Wrappers.lambdaQuery(AlertTip.class);
"轨旁设备", "轨旁设备故障"); queryWrapper.eq(AlertTip::getAlertType, alertType)
alertManager.emit(alert); .eq(AlertTip::getLocationType, locationType);
alertTriggered = true; 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(); return detail == null ? null : detail.getAlertTipId();
} }
public String getDeviceInfo() { public boolean isMock() {
return detail == null ? "" : detail.getDeviceInfo(); return detail == null || detail.isMock();
} }
public String getReason() { // public String getDeviceInfo() {
return detail == null ? "" : detail.getReason(); // return detail == null ? "" : detail.getDeviceInfo();
} // }
//
// public String getReason() {
// return detail == null ? "" : detail.getReason();
// }
} }

View File

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

View File

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

View File

@ -31,7 +31,7 @@ public class AlertManager extends EventEmitter {
super(id); super(id);
} }
public static AlertManager getInstance() { public static AlertManager getDefault() {
return getInstance("default"); 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;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.KilometerSystem; import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.KilometerSystem;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.RelatedRef.DeviceType; 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;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Section.SectionType; import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Section.SectionType;
import club.joylink.xiannccda.entity.PublishedGi; import club.joylink.xiannccda.entity.PublishedGi;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.google.common.collect.HashBasedTable;
import com.google.protobuf.GeneratedMessageV3.Builder; import com.google.protobuf.GeneratedMessageV3.Builder;
import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.MessageOrBuilder;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import lombok.Getter; import lombok.Getter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -31,6 +36,12 @@ public class LineGraphicDataRepository {
private static final Map<Integer, Map<String, CoordinateConvertor>> lineCoordinateMain = private static final Map<Integer, Map<String, CoordinateConvertor>> lineCoordinateMain =
new HashMap<>(); 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 +63,9 @@ public class LineGraphicDataRepository {
// 设置公里标后开始构建逻辑区段的编码公里标信息 // 设置公里标后开始构建逻辑区段的编码公里标信息
setUpLogicSectionInfo(lineDataMap, storage); setUpLogicSectionInfo(lineDataMap, storage);
lineGraphMap.put(publishGi.getLineId(), lineDataMap); lineGraphMap.put(publishGi.getLineId(), lineDataMap);
// 填充line_code_table
fillLineCodeTable(publishGi.getLineId(), storage);
} }
} catch (InvalidProtocolBufferException e) { } catch (InvalidProtocolBufferException e) {
log.error("反序列化信息失败", e); log.error("反序列化信息失败", e);
@ -92,6 +106,40 @@ public class LineGraphicDataRepository {
lineGraphMap.remove(id); 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);
// }
// }
// });
}
/** /**
* 获取线路的区段集合 * 获取线路的区段集合
* *
@ -370,9 +418,6 @@ public class LineGraphicDataRepository {
if (sectionMap.containsKey(sid)) { if (sectionMap.containsKey(sid)) {
DeviceInfoProto.Section.Builder sectionBuilder = DeviceInfoProto.Section.Builder sectionBuilder =
(DeviceInfoProto.Section.Builder) sectionMap.get(sid); (DeviceInfoProto.Section.Builder) sectionMap.get(sid);
if (sectionBuilder.getPhysicalSectionId().equals("118")) {
log.info("");
}
sectionBuilder.setCode(section.getCode()); sectionBuilder.setCode(section.getCode());
// 获取到物理区段信息 // 获取到物理区段信息
DeviceInfoProto.Section.Builder physicalSection = DeviceInfoProto.Section.Builder physicalSection =

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

@ -137,44 +137,10 @@ public final class NccAlertInfoMessageProto {
int getAlertTipId(); int getAlertTipId();
/** /**
* <pre> * <code>bool mock = 6;</code>
*故障设备信息 * @return The mock.
* </pre>
*
* <code>string device_info = 6;</code>
* @return The deviceInfo.
*/ */
java.lang.String getDeviceInfo(); boolean getMock();
/**
* <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();
} }
/** /**
* Protobuf type {@code alert.NccAlertInfoMessage.Message} * Protobuf type {@code alert.NccAlertInfoMessage.Message}
@ -193,8 +159,6 @@ public final class NccAlertInfoMessageProto {
level_ = ""; level_ = "";
alertTime_ = ""; alertTime_ = "";
info_ = ""; info_ = "";
deviceInfo_ = "";
reason_ = "";
} }
@java.lang.Override @java.lang.Override
@ -384,98 +348,15 @@ public final class NccAlertInfoMessageProto {
return alertTipId_; return alertTipId_;
} }
public static final int DEVICE_INFO_FIELD_NUMBER = 6; public static final int MOCK_FIELD_NUMBER = 6;
@SuppressWarnings("serial") private boolean mock_ = false;
private volatile java.lang.Object deviceInfo_ = "";
/** /**
* <pre> * <code>bool mock = 6;</code>
*故障设备信息 * @return The mock.
* </pre>
*
* <code>string device_info = 6;</code>
* @return The deviceInfo.
*/ */
@java.lang.Override @java.lang.Override
public java.lang.String getDeviceInfo() { public boolean getMock() {
java.lang.Object ref = deviceInfo_; return mock_;
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;
}
} }
private byte memoizedIsInitialized = -1; private byte memoizedIsInitialized = -1;
@ -507,11 +388,8 @@ public final class NccAlertInfoMessageProto {
if (alertTipId_ != 0) { if (alertTipId_ != 0) {
output.writeInt32(5, alertTipId_); output.writeInt32(5, alertTipId_);
} }
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(deviceInfo_)) { if (mock_ != false) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 6, deviceInfo_); output.writeBool(6, mock_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(reason_)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 7, reason_);
} }
getUnknownFields().writeTo(output); getUnknownFields().writeTo(output);
} }
@ -538,11 +416,9 @@ public final class NccAlertInfoMessageProto {
size += com.google.protobuf.CodedOutputStream size += com.google.protobuf.CodedOutputStream
.computeInt32Size(5, alertTipId_); .computeInt32Size(5, alertTipId_);
} }
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(deviceInfo_)) { if (mock_ != false) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(6, deviceInfo_); size += com.google.protobuf.CodedOutputStream
} .computeBoolSize(6, mock_);
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(reason_)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(7, reason_);
} }
size += getUnknownFields().getSerializedSize(); size += getUnknownFields().getSerializedSize();
memoizedSize = size; memoizedSize = size;
@ -569,10 +445,8 @@ public final class NccAlertInfoMessageProto {
.equals(other.getInfo())) return false; .equals(other.getInfo())) return false;
if (getAlertTipId() if (getAlertTipId()
!= other.getAlertTipId()) return false; != other.getAlertTipId()) return false;
if (!getDeviceInfo() if (getMock()
.equals(other.getDeviceInfo())) return false; != other.getMock()) return false;
if (!getReason()
.equals(other.getReason())) return false;
if (!getUnknownFields().equals(other.getUnknownFields())) return false; if (!getUnknownFields().equals(other.getUnknownFields())) return false;
return true; return true;
} }
@ -594,10 +468,9 @@ public final class NccAlertInfoMessageProto {
hash = (53 * hash) + getInfo().hashCode(); hash = (53 * hash) + getInfo().hashCode();
hash = (37 * hash) + ALERT_TIP_ID_FIELD_NUMBER; hash = (37 * hash) + ALERT_TIP_ID_FIELD_NUMBER;
hash = (53 * hash) + getAlertTipId(); hash = (53 * hash) + getAlertTipId();
hash = (37 * hash) + DEVICE_INFO_FIELD_NUMBER; hash = (37 * hash) + MOCK_FIELD_NUMBER;
hash = (53 * hash) + getDeviceInfo().hashCode(); hash = (53 * hash) + com.google.protobuf.Internal.hashBoolean(
hash = (37 * hash) + REASON_FIELD_NUMBER; getMock());
hash = (53 * hash) + getReason().hashCode();
hash = (29 * hash) + getUnknownFields().hashCode(); hash = (29 * hash) + getUnknownFields().hashCode();
memoizedHashCode = hash; memoizedHashCode = hash;
return hash; return hash;
@ -734,8 +607,7 @@ public final class NccAlertInfoMessageProto {
alertTime_ = ""; alertTime_ = "";
info_ = ""; info_ = "";
alertTipId_ = 0; alertTipId_ = 0;
deviceInfo_ = ""; mock_ = false;
reason_ = "";
return this; return this;
} }
@ -785,10 +657,7 @@ public final class NccAlertInfoMessageProto {
result.alertTipId_ = alertTipId_; result.alertTipId_ = alertTipId_;
} }
if (((from_bitField0_ & 0x00000020) != 0)) { if (((from_bitField0_ & 0x00000020) != 0)) {
result.deviceInfo_ = deviceInfo_; result.mock_ = mock_;
}
if (((from_bitField0_ & 0x00000040) != 0)) {
result.reason_ = reason_;
} }
} }
@ -827,15 +696,8 @@ public final class NccAlertInfoMessageProto {
if (other.getAlertTipId() != 0) { if (other.getAlertTipId() != 0) {
setAlertTipId(other.getAlertTipId()); setAlertTipId(other.getAlertTipId());
} }
if (!other.getDeviceInfo().isEmpty()) { if (other.getMock() != false) {
deviceInfo_ = other.deviceInfo_; setMock(other.getMock());
bitField0_ |= 0x00000020;
onChanged();
}
if (!other.getReason().isEmpty()) {
reason_ = other.reason_;
bitField0_ |= 0x00000040;
onChanged();
} }
this.mergeUnknownFields(other.getUnknownFields()); this.mergeUnknownFields(other.getUnknownFields());
onChanged(); onChanged();
@ -888,16 +750,11 @@ public final class NccAlertInfoMessageProto {
bitField0_ |= 0x00000010; bitField0_ |= 0x00000010;
break; break;
} // case 40 } // case 40
case 50: { case 48: {
deviceInfo_ = input.readStringRequireUtf8(); mock_ = input.readBool();
bitField0_ |= 0x00000020; bitField0_ |= 0x00000020;
break; break;
} // case 50 } // case 48
case 58: {
reason_ = input.readStringRequireUtf8();
bitField0_ |= 0x00000040;
break;
} // case 58
default: { default: {
if (!super.parseUnknownField(input, extensionRegistry, tag)) { if (!super.parseUnknownField(input, extensionRegistry, tag)) {
done = true; // was an endgroup tag done = true; // was an endgroup tag
@ -1235,186 +1092,34 @@ public final class NccAlertInfoMessageProto {
return this; return this;
} }
private java.lang.Object deviceInfo_ = ""; private boolean mock_ ;
/** /**
* <pre> * <code>bool mock = 6;</code>
*故障设备信息 * @return The mock.
* </pre>
*
* <code>string device_info = 6;</code>
* @return The deviceInfo.
*/ */
public java.lang.String getDeviceInfo() { @java.lang.Override
java.lang.Object ref = deviceInfo_; public boolean getMock() {
if (!(ref instanceof java.lang.String)) { return mock_;
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;
}
} }
/** /**
* <pre> * <code>bool mock = 6;</code>
*故障设备信息 * @param value The mock to set.
* </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.
* @return This builder for chaining. * @return This builder for chaining.
*/ */
public Builder setDeviceInfo( public Builder setMock(boolean value) {
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;
}
private java.lang.Object reason_ = ""; mock_ = value;
/** bitField0_ |= 0x00000020;
* <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;
onChanged(); onChanged();
return this; return this;
} }
/** /**
* <pre> * <code>bool mock = 6;</code>
*导致报警的原因
* </pre>
*
* <code>string reason = 7;</code>
* @return This builder for chaining. * @return This builder for chaining.
*/ */
public Builder clearReason() { public Builder clearMock() {
reason_ = getDefaultInstance().getReason(); bitField0_ = (bitField0_ & ~0x00000020);
bitField0_ = (bitField0_ & ~0x00000040); mock_ = false;
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;
onChanged(); onChanged();
return this; return this;
} }
@ -2187,14 +1892,14 @@ public final class NccAlertInfoMessageProto {
descriptor; descriptor;
static { static {
java.lang.String[] descriptorData = { 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" + "oMessage\0224\n\010messages\030\001 \003(\0132\".alert.NccAl" +
"ertInfoMessage.Message\032\201\001\n\007Message\022\n\n\002id" + "ertInfoMessage.Message\032j\n\007Message\022\n\n\002id\030" +
"\030\001 \001(\t\022\r\n\005level\030\002 \001(\t\022\022\n\nalert_time\030\003 \001(" + "\001 \001(\t\022\r\n\005level\030\002 \001(\t\022\022\n\nalert_time\030\003 \001(\t" +
"\t\022\014\n\004info\030\004 \001(\t\022\024\n\014alert_tip_id\030\005 \001(\005\022\023\n" + "\022\014\n\004info\030\004 \001(\t\022\024\n\014alert_tip_id\030\005 \001(\005\022\014\n\004" +
"\013device_info\030\006 \001(\t\022\016\n\006reason\030\007 \001(\tB=\n!cl" + "mock\030\006 \001(\010B=\n!club.joylink.xiannccda.dto" +
"ub.joylink.xiannccda.dto.protosB\030NccAler" + ".protosB\030NccAlertInfoMessageProtob\006proto" +
"tInfoMessageProtob\006proto3" "3"
}; };
descriptor = com.google.protobuf.Descriptors.FileDescriptor descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData, .internalBuildGeneratedFileFrom(descriptorData,
@ -2211,7 +1916,7 @@ public final class NccAlertInfoMessageProto {
internal_static_alert_NccAlertInfoMessage_Message_fieldAccessorTable = new internal_static_alert_NccAlertInfoMessage_Message_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_alert_NccAlertInfoMessage_Message_descriptor, 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) // @@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.Builder;
import club.joylink.xiannccda.dto.protos.NccAlertInfoMessageProto.NccAlertInfoMessage.Message; import club.joylink.xiannccda.dto.protos.NccAlertInfoMessageProto.NccAlertInfoMessage.Message;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Queue; import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
@ -82,14 +84,25 @@ public class NccAlertMessageServer implements IMessageServer {
pendingMsgQueue.add(alertInfo); 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) { private NccAlertInfoMessage.Message convertToMessage(NccAlertInfo<?> alertInfo) {
Message.Builder builder = Message.newBuilder() Message.Builder builder = Message.newBuilder()
.setId(alertInfo.getId()) .setId(alertInfo.getId())
.setLevel(alertInfo.getLevel()) .setLevel(alertInfo.getLevel())
.setAlertTime(alertInfo.getAlertTime().toString()) .setAlertTime(alertInfo.getAlertTime().toString())
.setInfo(alertInfo.getInfo()) .setInfo(alertInfo.getInfo())
.setDeviceInfo(alertInfo.getDeviceInfo()) .setMock(alertInfo.isMock());
.setReason(alertInfo.getReason()); // .setDeviceInfo(alertInfo.getDeviceInfo())
// .setReason(alertInfo.getReason());
Integer alertTipId = alertInfo.getAlertTipId(); Integer alertTipId = alertInfo.getAlertTipId();
if (alertTipId != null) { if (alertTipId != null) {
builder.setAlertTipId(alertTipId); builder.setAlertTipId(alertTipId);

View File

@ -8,24 +8,27 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import org.assertj.core.util.Lists; import org.assertj.core.util.Lists;
public class GenertateProtoBufUtil { public class GenerateProtoBufUtil {
private final static String EXE_BIN_FILE = String.join(File.separator, private static final String EXE_BIN_FILE =
System.getProperty("user.dir"), "xian-ncc-da-message", String.join(
"protoc-23.1", "bin", "win64", File.separator,
"protoc"); System.getProperty("user.dir"),
"xian-ncc-da-message",
"protoc-23.1",
"bin",
"win64",
"protoc");
private File protoFilePath; private File protoFilePath;
private String outPath; private String outPath;
private boolean pullMessage; private boolean pullMessage;
// private String gitPullPath; // private String gitPullPath;
public GenertateProtoBufUtil(String rootPath, boolean pullMessage) { public GenerateProtoBufUtil(String rootPath, boolean pullMessage) {
this.pullMessage = pullMessage; this.pullMessage = pullMessage;
String sourcePath = String.join(File.separator, rootPath, String sourcePath = String.join(File.separator, rootPath, "xian-ncc-da-message", "protos");
"xian-ncc-da-message", "protos");
this.outPath = String.join(File.separator, rootPath, this.outPath = String.join(File.separator, rootPath, "src", "main", "java");
"src", "main", "java");
this.protoFilePath = new File(sourcePath); this.protoFilePath = new File(sourcePath);
if (!protoFilePath.exists() || !protoFilePath.isDirectory()) { if (!protoFilePath.exists() || !protoFilePath.isDirectory()) {
throw new RuntimeException("proto不是目录或目录不存在"); throw new RuntimeException("proto不是目录或目录不存在");
@ -41,9 +44,14 @@ public class GenertateProtoBufUtil {
this.PullTmmsMessage(); this.PullTmmsMessage();
} }
for (File file : this.findFiles()) { for (File file : this.findFiles()) {
String command = String.format("%s --proto_path=%s -I=%s --java_out=%s %s", EXE_BIN_FILE, String command =
this.protoFilePath.getPath(), file.getParentFile().getAbsolutePath(), this.outPath, String.format(
file.getName()); "%s --proto_path=%s -I=%s --java_out=%s %s",
EXE_BIN_FILE,
this.protoFilePath.getPath(),
file.getParentFile().getAbsolutePath(),
this.outPath,
file.getName());
this.genertateFile(command); this.genertateFile(command);
} }
} }
@ -74,8 +82,8 @@ public class GenertateProtoBufUtil {
} }
private void PullTmmsMessage() throws IOException { private void PullTmmsMessage() throws IOException {
InputStream inputStream = Runtime.getRuntime() InputStream inputStream =
.exec("git pull", null, protoFilePath).getInputStream(); Runtime.getRuntime().exec("git pull", null, protoFilePath).getInputStream();
byte[] ebs = new byte[512]; byte[] ebs = new byte[512];
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
int size; int size;
@ -87,7 +95,7 @@ public class GenertateProtoBufUtil {
} }
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
GenertateProtoBufUtil gu = new GenertateProtoBufUtil(System.getProperty("user.dir"), true); GenerateProtoBufUtil gu = new GenerateProtoBufUtil(System.getProperty("user.dir"), true);
gu.execCommand(); gu.execCommand();
} }
} }

View File

@ -30,11 +30,11 @@ public class WebSocketTest {
WebSocketHttpHeaders headers = new WebSocketHttpHeaders(); WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
headers.set("Authorization", 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 stompHeaders = new StompHeaders();
stompHeaders.set("Authorization", 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() { StompSessionHandlerAdapter sessionHandler = new StompSessionHandlerAdapter() {
@Override @Override

@ -1 +1 @@
Subproject commit 4f27cc3670bcb4071706bb0e66d6fdfd817e27a4 Subproject commit edc9973662bc4f02198f72919de9408fa9ea9043