Merge branch 'master' into develop_wei
This commit is contained in:
commit
d338cbb135
@ -12,7 +12,9 @@ public interface AlertDetail {
|
||||
|
||||
String getInfo();
|
||||
|
||||
String getDeviceInfo();
|
||||
boolean isMock();
|
||||
|
||||
String getReason();
|
||||
// String getDeviceInfo();
|
||||
//
|
||||
// String getReason();
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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;
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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)));
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
// 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);
|
||||
// });
|
||||
// }
|
||||
}
|
||||
} else {
|
||||
if (now.getSecond() % 30 == 0) {
|
||||
AlertType alertType = AlertType.BLUE_DISPLAY;
|
||||
|
||||
private Integer getAlertTipId(AlertType alertType, AlertTipLocationType locationType) {
|
||||
LambdaQueryWrapper<AlertTip> queryWrapper = Wrappers.lambdaQuery(AlertTip.class);
|
||||
queryWrapper.eq(AlertTip::getAlertType, alertType)
|
||||
.eq(AlertTip::getLocationType, AlertTipLocationType.QX);
|
||||
.eq(AlertTip::getLocationType, locationType);
|
||||
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);
|
||||
alertTriggered = true;
|
||||
}
|
||||
}
|
||||
return alertTip == null ? null : alertTip.getId();
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
// }
|
||||
}
|
||||
|
@ -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);
|
||||
// }
|
||||
}
|
||||
|
@ -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;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public class AlertManager extends EventEmitter {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public static AlertManager getInstance() {
|
||||
public static AlertManager getDefault() {
|
||||
return getInstance("default");
|
||||
}
|
||||
|
||||
|
@ -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,12 @@ 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 +63,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 +106,40 @@ 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);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取线路的区段集合
|
||||
*
|
||||
@ -370,9 +418,6 @@ public class LineGraphicDataRepository {
|
||||
if (sectionMap.containsKey(sid)) {
|
||||
DeviceInfoProto.Section.Builder sectionBuilder =
|
||||
(DeviceInfoProto.Section.Builder) sectionMap.get(sid);
|
||||
if (sectionBuilder.getPhysicalSectionId().equals("118")) {
|
||||
log.info("");
|
||||
}
|
||||
sectionBuilder.setCode(section.getCode());
|
||||
// 获取到物理区段信息
|
||||
DeviceInfoProto.Section.Builder physicalSection =
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
13
src/main/java/club/joylink/xiannccda/dto/AlertMockDTO.java
Normal file
13
src/main/java/club/joylink/xiannccda/dto/AlertMockDTO.java
Normal 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;
|
||||
}
|
@ -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)
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
@ -8,24 +8,27 @@ 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",
|
||||
"protoc-23.1", "bin", "win64",
|
||||
private static final String EXE_BIN_FILE =
|
||||
String.join(
|
||||
File.separator,
|
||||
System.getProperty("user.dir"),
|
||||
"xian-ncc-da-message",
|
||||
"protoc-23.1",
|
||||
"bin",
|
||||
"win64",
|
||||
"protoc");
|
||||
private File protoFilePath;
|
||||
private String outPath;
|
||||
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");
|
||||
String sourcePath = String.join(File.separator, rootPath, "xian-ncc-da-message", "protos");
|
||||
|
||||
this.outPath = String.join(File.separator, rootPath,
|
||||
"src", "main", "java");
|
||||
this.outPath = String.join(File.separator, rootPath, "src", "main", "java");
|
||||
this.protoFilePath = new File(sourcePath);
|
||||
if (!protoFilePath.exists() || !protoFilePath.isDirectory()) {
|
||||
throw new RuntimeException("proto不是目录或目录不存在");
|
||||
@ -41,8 +44,13 @@ public class GenertateProtoBufUtil {
|
||||
this.PullTmmsMessage();
|
||||
}
|
||||
for (File file : this.findFiles()) {
|
||||
String command = String.format("%s --proto_path=%s -I=%s --java_out=%s %s", EXE_BIN_FILE,
|
||||
this.protoFilePath.getPath(), file.getParentFile().getAbsolutePath(), this.outPath,
|
||||
String command =
|
||||
String.format(
|
||||
"%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);
|
||||
}
|
||||
@ -74,8 +82,8 @@ public class GenertateProtoBufUtil {
|
||||
}
|
||||
|
||||
private void PullTmmsMessage() throws IOException {
|
||||
InputStream inputStream = Runtime.getRuntime()
|
||||
.exec("git pull", null, protoFilePath).getInputStream();
|
||||
InputStream inputStream =
|
||||
Runtime.getRuntime().exec("git pull", null, protoFilePath).getInputStream();
|
||||
byte[] ebs = new byte[512];
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int size;
|
||||
@ -87,7 +95,7 @@ public class GenertateProtoBufUtil {
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
@ -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 4f27cc3670bcb4071706bb0e66d6fdfd817e27a4
|
||||
Subproject commit edc9973662bc4f02198f72919de9408fa9ea9043
|
Loading…
Reference in New Issue
Block a user