修改报警信息内容(proto文件同步修改)

This commit is contained in:
joylink_zhangsai 2023-07-24 16:19:51 +08:00
parent 5fed73b214
commit 49a56f880d
15 changed files with 785 additions and 298 deletions

View File

@ -1,5 +1,6 @@
package club.joylink.xiannccda.alert;
import club.joylink.xiannccda.dto.protos.NccAlertInfoMessageProto.NccAlertInfoMessage.AlertType;
import java.time.LocalDateTime;
public interface AlertDetail {
@ -10,11 +11,11 @@ public interface AlertDetail {
Integer getAlertTipId();
String getInfo();
Integer getLineId();
String getAlertObject();
String getLocatorDeviceId();
boolean isMock();
// String getDeviceInfo();
//
// String getReason();
}

View File

@ -1,13 +1,16 @@
package club.joylink.xiannccda.alert;
import club.joylink.xiannccda.ats.cache.LineGraphicDataRepository;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.CommonInfo;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Platform;
import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Station;
import club.joylink.xiannccda.dto.protos.NccAlertInfoMessageProto.NccAlertInfoMessage.AlertType;
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.Descriptors.FieldDescriptor;
import com.google.protobuf.MessageOrBuilder;
import java.time.LocalDateTime;
import org.springframework.stereotype.Component;
@ -21,11 +24,11 @@ public class AlertDetailFactory {
this.alertTipRepository = alertTipRepository;
}
public AlertDetail getAlertDetail(AlertType alertType, short lineId, boolean mock,
public AlertDetail getAlertDetail(AlertType alertType, int lineId, boolean mock,
MessageOrBuilder messageOrBuilder) {
LocalDateTime now = LocalDateTime.now();
Integer alertTipId;
String info;
String alertObject;
switch (alertType) {
case BLUE_DISPLAY -> {
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(
@ -38,13 +41,16 @@ public class AlertDetailFactory {
.eq(AlertTip::getLocationType, rtu.getCode());
AlertTip alertTip = alertTipRepository.getOne(queryWrapper);
alertTipId = alertTip == null ? null : alertTip.getId();
String interlockName = getInterlockName(rtu);
info = String.format("[%s号线][%s]蓝显", lineId, interlockName);
alertObject = getInterlockName(rtu);
}
case TRAIN_DELAY -> {
throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("尚未实现");
case TRAIN_DELAY_2, TRAIN_DELAY_10 -> {
LambdaQueryWrapper<AlertTip> queryWrapper = Wrappers.lambdaQuery(AlertTip.class)
.eq(AlertTip::getAlertType, alertType);
AlertTip alertTip = alertTipRepository.getOne(queryWrapper);
alertTipId = alertTip == null ? null : alertTip.getId();
alertObject = "列车001";
}
case PLATFORM_DOOR_WITHOUT_LOCKED_SIGNAL -> {
case PLATFORM_DOOR_WITHOUT_LOCKED_SIGNAL, PLATFORM_DOOR_CANNOT_CLOSE, PLATFORM_DOOR_CANNOT_OPEN -> {
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(
messageOrBuilder instanceof Platform);
Platform platform = (Platform) messageOrBuilder;
@ -52,37 +58,28 @@ public class AlertDetailFactory {
.eq(AlertTip::getAlertType, alertType);
AlertTip alertTip = alertTipRepository.getOne(queryWrapper);
alertTipId = alertTip == null ? null : alertTip.getId();
String platformDesc = getPlatformDesc(lineId, platform);
info = String.format("[%s号线]%s站台门无关闭且锁紧信号", lineId, platformDesc);
}
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();
String platformDesc = getPlatformDesc(lineId, platform);
info = String.format("[%s号线]%s站台门无法打开", lineId, platformDesc);
}
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();
String platformDesc = getPlatformDesc(lineId, platform);
info = String.format("[%s号线]%s站台门无法关闭", lineId, platformDesc);
alertObject = getPlatformDesc(lineId, platform);
}
default -> throw new IllegalStateException("Unexpected value: " + alertType);
}
return new AlertDetailImpl(alertType, now, alertTipId, info, mock);
String locatorDeviceId;
if (messageOrBuilder != null) {
locatorDeviceId = getId(messageOrBuilder);
} else {
locatorDeviceId = null;
}
private String getPlatformDesc(short lineId, Platform platform) {
return new AlertDetailImpl(alertType, now, alertTipId, lineId, alertObject, locatorDeviceId, mock);
}
private String getId(MessageOrBuilder messageOrBuilder) {
FieldDescriptor commonFD = messageOrBuilder.getDescriptorForType().findFieldByName("common");
MessageOrBuilder common = (MessageOrBuilder) messageOrBuilder.getField(commonFD);
return (String) common.getField(CommonInfo.getDescriptor().findFieldByName("id"));
}
private String getPlatformDesc(int lineId, Platform platform) {
Station station = LineGraphicDataRepository.getDeviceByCode(lineId,
platform.getRefStation(), Station.class);
return String.format("[%s][%s行站台]", station.getName(), platform.getUp() ? "" : "");

View File

@ -1,5 +1,6 @@
package club.joylink.xiannccda.alert;
import club.joylink.xiannccda.dto.protos.NccAlertInfoMessageProto.NccAlertInfoMessage.AlertType;
import java.time.LocalDateTime;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
@ -15,10 +16,10 @@ public class AlertDetailImpl implements AlertDetail {
private AlertType alertType;
private LocalDateTime alertTime;
private Integer alertTipId;
private String info;
private Integer lineId;
private String alertObject;
private String locatorDeviceId;
private boolean mock;
// private String deviceInfo;
// private String reason;
@Override
public AlertType getAlertType() {
@ -30,11 +31,6 @@ public class AlertDetailImpl implements AlertDetail {
return alertTime;
}
@Override
public String getInfo() {
return info;
}
@Override
public Integer getAlertTipId() {
return alertTipId;
@ -44,16 +40,4 @@ public class AlertDetailImpl implements AlertDetail {
public boolean isMock() {
return mock;
}
// @Override
// public String getDeviceInfo() {
// return deviceInfo;
// }
//
// @Override
// public String getReason() {
// return reason;
// }
}

View File

@ -1,18 +0,0 @@
package club.joylink.xiannccda.alert;
public enum AlertType {
/**
* 蓝显
*/
BLUE_DISPLAY,
/**
* 列车延误
*/
TRAIN_DELAY,
/**
* 站台门无关闭锁紧信号
*/
PLATFORM_DOOR_WITHOUT_LOCKED_SIGNAL,
PLATFORM_DOOR_CANNOT_OPEN,
PLATFORM_DOOR_CANNOT_CLOSE,
}

View File

@ -1,6 +1,7 @@
package club.joylink.xiannccda.alert;
import club.joylink.xiannccda.alert.core.AlertMonitoringTask;
import club.joylink.xiannccda.dto.protos.NccAlertInfoMessageProto.NccAlertInfoMessage.AlertType;
import club.joylink.xiannccda.entity.AlertTip;
import club.joylink.xiannccda.repository.IAlertTipRepository;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

View File

@ -3,12 +3,14 @@ package club.joylink.xiannccda.alert;
import club.joylink.xiannccda.alert.core.AlertInfo;
import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Getter;
@AllArgsConstructor
public class NccAlertInfo<D extends AlertDetail> implements AlertInfo {
private String id;
private String level;
private LocalDateTime alertTime;
@Getter
private D detail;
@Override
@ -28,22 +30,6 @@ public class NccAlertInfo<D extends AlertDetail> implements AlertInfo {
@Override
public String getInfo() {
return detail == null ? "" : detail.getInfo();
return "";
}
public Integer getAlertTipId() {
return detail == null ? null : detail.getAlertTipId();
}
public boolean isMock() {
return detail == null || detail.isMock();
}
// public String getDeviceInfo() {
// return detail == null ? "" : detail.getDeviceInfo();
// }
//
// public String getReason() {
// return detail == null ? "" : detail.getReason();
// }
}

View File

@ -47,13 +47,13 @@ public class LineGraphicDataRepository {
/**
* 线路-设备code-设备
*/
private static final HashBasedTable<Short, String, MessageOrBuilder> line_code_table =
private static final HashBasedTable<Integer, String, MessageOrBuilder> line_code_table =
HashBasedTable.create();
/**
* 线路-设备id-设备
*/
private static final HashBasedTable<Short, String, MessageOrBuilder> line_id_table = HashBasedTable.create();
private static final HashBasedTable<Integer, String, MessageOrBuilder> line_id_table = HashBasedTable.create();
/**
* 缓存线路数据信息
@ -121,28 +121,27 @@ public class LineGraphicDataRepository {
lineGraphMap.remove(id);
}
public static <T> T getDeviceByCode(short lineId, String code, Class<T> cls) {
public static <T> T getDeviceByCode(int lineId, String code, Class<T> cls) {
MessageOrBuilder mob = line_code_table.get(lineId, code);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(mob,
String.format("线路[%s]code[%s]", lineId, code));
return (T) mob;
}
public static <T> T getDeviceById(short lineId, String id, Class<T> cls) {
public static <T> T getDeviceById(int lineId, String id, Class<T> cls) {
MessageOrBuilder mob = line_id_table.get(lineId, id);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(mob,
String.format("线路[%s]id[%s]", lineId, id));
return (T) mob;
}
public static <T extends MessageOrBuilder> Stream<T> getDevices(short lineId, Class<T> cls) {
public static <T extends MessageOrBuilder> Stream<T> getDevices(int lineId, Class<T> cls) {
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();
FieldDescriptor idField = CommonInfo.getDescriptor().findFieldByName("id");
storage.getAllFields().forEach((fd, value) -> {
if (fd.isRepeated()) {
@ -151,7 +150,7 @@ public class LineGraphicDataRepository {
FieldDescriptor codeField =
builder.getDescriptorForType().findFieldByName("code");
String code = (String) builder.getField(codeField);
line_code_table.put(shortLineId, code, builder);
line_code_table.put(lineId, code, builder);
FieldDescriptor commonField =
builder.getDescriptorForType().findFieldByName("common");
@ -160,7 +159,7 @@ public class LineGraphicDataRepository {
}
MessageOrBuilder common = (MessageOrBuilder)builder.getField(commonField);
String id = (String) common.getField(idField);
line_code_table.put(shortLineId, id, builder);
line_code_table.put(lineId, id, builder);
}
}
});

View File

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

View File

@ -2,7 +2,7 @@ package club.joylink.xiannccda.dto.alertTip;
import club.joylink.xiannccda.alert.AlertTipLocationType;
import club.joylink.xiannccda.alert.AlertTipTimeType;
import club.joylink.xiannccda.alert.AlertType;
import club.joylink.xiannccda.dto.protos.NccAlertInfoMessageProto.NccAlertInfoMessage.AlertType;
import club.joylink.xiannccda.entity.AlertTip;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import lombok.Getter;

View File

@ -2,7 +2,7 @@ package club.joylink.xiannccda.dto.alertTip;
import club.joylink.xiannccda.alert.AlertTipLocationType;
import club.joylink.xiannccda.alert.AlertTipTimeType;
import club.joylink.xiannccda.alert.AlertType;
import club.joylink.xiannccda.dto.protos.NccAlertInfoMessageProto.NccAlertInfoMessage.AlertType;
import jakarta.validation.constraints.NotNull;
import lombok.Data;

View File

@ -2,12 +2,12 @@ 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.dto.protos.NccAlertInfoMessageProto.NccAlertInfoMessage.AlertType;
import club.joylink.xiannccda.exception.BusinessExceptionAssertEnum;
import club.joylink.xiannccda.ws.NccAlertMessageServer;
import com.google.protobuf.MessageOrBuilder;
@ -22,14 +22,14 @@ public class AlertMockService {
private AlertDetailFactory alertDetailFactory;
public void setAlert(AlertMockDTO alertMockDTO) {
short lineId = alertMockDTO.getLineId();
int 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) {
private AlertDetail buildAlertDetail(AlertType alertType, int lineId) {
MessageOrBuilder messageOrBuilder;
switch (alertType) {
case BLUE_DISPLAY -> {
@ -39,8 +39,8 @@ public class AlertMockService {
.findFirst()
.orElseThrow(BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL::exception);
}
case TRAIN_DELAY -> {
throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("尚未实现");
case TRAIN_DELAY_2, TRAIN_DELAY_10 -> {
messageOrBuilder = null;
}
case PLATFORM_DOOR_WITHOUT_LOCKED_SIGNAL, PLATFORM_DOOR_CANNOT_OPEN, PLATFORM_DOOR_CANNOT_CLOSE -> {
Stream<Platform> stream = LineGraphicDataRepository.getDevices(lineId, Platform.class);

View File

@ -99,14 +99,18 @@ public class NccAlertMessageServer implements IMessageServer {
.setId(alertInfo.getId())
.setLevel(alertInfo.getLevel())
.setAlertTime(alertInfo.getAlertTime().toString())
.setInfo(alertInfo.getInfo())
.setMock(alertInfo.isMock());
// .setDeviceInfo(alertInfo.getDeviceInfo())
// .setReason(alertInfo.getReason());
Integer alertTipId = alertInfo.getAlertTipId();
.setLineId(alertInfo.getDetail().getLineId())
.setAlertObject(alertInfo.getDetail().getAlertObject())
.setAlertType(alertInfo.getDetail().getAlertType())
.setMock(alertInfo.getDetail().isMock());
Integer alertTipId = alertInfo.getDetail().getAlertTipId();
if (alertTipId != null) {
builder.setAlertTipId(alertTipId);
}
String locatorDeviceId = alertInfo.getDetail().getLocatorDeviceId();
if (locatorDeviceId != null) {
builder.setLocatorDeviceId(locatorDeviceId);
}
return builder.build();
}
}

View File

@ -28,13 +28,13 @@ public class WebSocketTest {
String webSocketUrl = "ws://localhost:9081/ws-default";
CountDownLatch latch = new CountDownLatch(1);
String auth = "Bearer eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJzZWxmIiwic3ViIjoiMTQiLCJleHAiOjE2OTA0NDUyMjksImlhdCI6MTY5MDE4NjAyOX0.K9WEtP9moxydscOV6O8iTXEM6pDI-qhPOWKSGN9pmvfo3qN6mabWDd6IWqdhnMijnQLVXJ-v9O76UgvdwbYJ_9SMMVKSUuJNTRBrSrAXyug63jFaPQb0GNjPXrMO7SnYYD5539peHmiRZdEakYD5s2mmM4SLg32qhJysDKN5badsYys_WhxHQskWtZpWiRziZw8tz-cTwIRRp4wX6ing9CxtPiTQVCIShh3rlFh5-0V4NqzNfvjNO0CCnfF-adAXKudkHIv9AvkEDBM6Zbr-BR57FAxAHzsi9SK1ThBVBCZ6adkJnQ9FQDCsKAlpvMfAG8sgtIUX2THznUbGdp59dQ";
WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
headers.set("Authorization",
"Bearer eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJzZWxmIiwic3ViIjoiMTQiLCJleHAiOjE2OTAxMDc0NzAsImlhdCI6MTY4OTg0ODI3MH0.WXwKt6M12AMW-9Fhsop-nGtwxQR4jw7t-EIN2RUKLfRSaMlMgTgHPr_p47GXmQszJndPthUN3IkLBRMfVyEK3y4e9Uq5B2gD2DBgXuFgdM85PlJF8NHThDGyH-eoc7ZbPD1geCSFTiDbzuWuY4b1AcFnP2p4VdoU9s28FHoJzQRKL2cot-ZwexEVhFzVXJkXgF2oKpbdMamVHkTRuGRzmrYFzur2mqWKPI2XMuOdZ79GKK7yFzflXGZEPAY7zw_iwZmAc-grNlHfuwam9kTKz2nPUnsZM0pqkmRvcELsz63tk4uo6FLnsFkN7XHMj5AvHO92sIspQenw1s1vHgoESw");
headers.set("Authorization", auth);
StompHeaders stompHeaders = new StompHeaders();
stompHeaders.set("Authorization",
"Bearer eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJzZWxmIiwic3ViIjoiMTQiLCJleHAiOjE2OTAxMDc0NzAsImlhdCI6MTY4OTg0ODI3MH0.WXwKt6M12AMW-9Fhsop-nGtwxQR4jw7t-EIN2RUKLfRSaMlMgTgHPr_p47GXmQszJndPthUN3IkLBRMfVyEK3y4e9Uq5B2gD2DBgXuFgdM85PlJF8NHThDGyH-eoc7ZbPD1geCSFTiDbzuWuY4b1AcFnP2p4VdoU9s28FHoJzQRKL2cot-ZwexEVhFzVXJkXgF2oKpbdMamVHkTRuGRzmrYFzur2mqWKPI2XMuOdZ79GKK7yFzflXGZEPAY7zw_iwZmAc-grNlHfuwam9kTKz2nPUnsZM0pqkmRvcELsz63tk4uo6FLnsFkN7XHMj5AvHO92sIspQenw1s1vHgoESw");
stompHeaders.set("Authorization",auth);
StompSessionHandlerAdapter sessionHandler = new StompSessionHandlerAdapter() {
@Override

@ -1 +1 @@
Subproject commit edc9973662bc4f02198f72919de9408fa9ea9043
Subproject commit e9ebd34921652f48c2d84ac531e392ce32d17bb5