模拟设备状态变更接口调整

This commit is contained in:
tiger_zhou 2023-07-05 16:00:44 +08:00
parent d042470c8f
commit c5f5449da9
8 changed files with 124 additions and 37 deletions

View File

@ -3,7 +3,13 @@ package club.joylink.xiannccda.ats.message.line3.rep;
import club.joylink.xiannccda.ats.message.MessageResponse;
import club.joylink.xiannccda.ats.message.line3.MessageCons;
import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto;
import club.joylink.xiannccda.dto.protos.TrainProto.TrainBlock;
import com.google.common.collect.Lists;
import com.google.protobuf.GeneratedMessageV3;
import com.google.protobuf.GeneratedMessageV3.Builder;
import io.netty.buffer.ByteBuf;
import java.util.Objects;
import lombok.Getter;
import java.util.ArrayList;
@ -40,6 +46,45 @@ public class TrainBlockInfoResponse extends MessageResponse {
}
}
@Override
public List<Builder> generateProto() {
List<GeneratedMessageV3.Builder> builders = Lists.newArrayList();
for (TrainCell train : this.trains) {
TrainBlock.Builder builder = TrainBlock.newBuilder();
builder.setLineId(this.getLineId());
if (Objects.nonNull(train.getGroupId())) {
builder.setGroupId(train.getGroupId());
}
if (Objects.nonNull(train.getTrainId())) {
builder.setTrainId(train.getTrainId());
}
if (Objects.nonNull(train.getDirection())) {
builder.setDirection(train.getDirection().value);
}
if (Objects.nonNull(train.getStationIdInUpSide())) {
builder.setStationIDInUpSide(train.getStationIdInUpSide());
}
if (Objects.nonNull(train.getStationIdInDownSide())) {
builder.setStationIDInUpSide(train.getStationIdInDownSide());
}
if (Objects.nonNull(train.getRtuId())) {
builder.setRtuId(train.getRtuId());
}
if (Objects.nonNull(train.getDevType())) {
DeviceStatusProto.DeviceType dtProto = DeviceStatusProto.DeviceType.forNumber(train.getDevType().getVal());
builder.setDeviceType(dtProto);
}
if (Objects.nonNull(train.getDevName())) {
builder.setDevName(train.getDevName());
}
if (Objects.nonNull(train.getBlockFlag())) {
builder.setBlockFlag(train.getBlockFlag() ? 1 : 0);
}
builders.add(builder);
}
return builders;
}
@Getter
@Setter
public static class TrainCell {
@ -129,9 +174,9 @@ public class TrainBlockInfoResponse extends MessageResponse {
public static DirectionEnum of(final int value) {
for (final DirectionEnum direction : values()) {
if (direction.value == value) {
return direction;
}
if (direction.value == value) {
return direction;
}
}
return DirectionEnum.Unknown;
}

View File

@ -12,6 +12,7 @@ import club.joylink.xiannccda.dto.protos.TrainProto.TrainInfo;
import com.google.common.collect.Lists;
import com.google.protobuf.GeneratedMessageV3.Builder;
import io.netty.buffer.ByteBuf;
import java.util.Objects;
import lombok.Getter;
import java.time.LocalDateTime;
@ -67,10 +68,18 @@ public class TrainIndicationInitResponse extends MessageResponse {
if (trainCell.getDevType() != null) {
builder.setDevType(DeviceStatusProto.DeviceType.forNumber(trainCell.getDevType().getVal()));
}
builder.setDevName(trainCell.getDevName());
builder.setTrainIndex(trainCell.getTrainIndex());
builder.setGroupId(trainCell.getGroupId());
builder.setTrainId(trainCell.getTrainId());
if (Objects.nonNull(trainCell.getDevName())) {
builder.setDevName(trainCell.getDevName());
}
if (Objects.nonNull(trainCell.getTrainIndex())) {
builder.setTrainIndex(trainCell.getTrainIndex());
}
if (Objects.nonNull(trainCell.getGroupId())) {
builder.setGroupId(trainCell.getGroupId());
}
if (Objects.nonNull(trainCell.getTrainId())) {
builder.setTrainId(trainCell.getTrainId());
}
if (trainCell.getGlobalId() != null) {
builder.setGlobalId(trainCell.getGlobalId());
}

View File

@ -9,6 +9,7 @@ import club.joylink.xiannccda.dto.protos.TrainProto.TrainRemove;
import com.google.protobuf.GeneratedMessageV3.Builder;
import io.netty.buffer.ByteBuf;
import java.util.List;
import java.util.Objects;
import lombok.Getter;
import lombok.Setter;
@ -77,16 +78,33 @@ public class TrainIndicationRemoveResponse extends MessageResponse {
@Override
public List<Builder> generateProto() {
TrainRemove.Builder trainRemove = TrainRemove.newBuilder();
trainRemove.setLineId(this.lineId);
trainRemove.setRtuId(this.rtuId);
if (Objects.nonNull(this.lineId)) {
trainRemove.setLineId(this.lineId);
}
if (Objects.nonNull(this.rtuId)) {
trainRemove.setRtuId(this.rtuId);
}
NccWindow.Builder window = NccWindow.newBuilder();
window.setNccWindow(this.nccWindow);
window.setNccWinOffset(this.nccWindowOffset);
if (Objects.nonNull(this.nccWindow)) {
window.setNccWindow(this.nccWindow);
}
if (Objects.nonNull(this.nccWindowOffset)) {
window.setNccWinOffset(this.nccWindowOffset);
}
trainRemove.setWindow(window);
trainRemove.setDeviceType(DeviceStatusProto.DeviceType.forNumber(this.devType.getVal()));
trainRemove.setDevName(this.devName);
trainRemove.setTrainIndex(this.trainIndex);
trainRemove.setGroupId(this.groupId);
if (Objects.nonNull(this.devType)) {
trainRemove.setDeviceType(DeviceStatusProto.DeviceType.forNumber(this.devType.getVal()));
}
if (Objects.nonNull(this.devName)) {
trainRemove.setDevName(this.devName);
}
if (Objects.nonNull(this.trainIndex)) {
trainRemove.setTrainIndex(this.trainIndex);
}
if (Objects.nonNull(this.groupId)) {
trainRemove.setGroupId(this.groupId);
}
return List.of(trainRemove);
}

View File

@ -125,7 +125,6 @@ public class TrainIndicationUpdateResponse extends MessageResponse {
@Override
public List<Builder> generateProto() {
TrainProto.TrainInfo.Builder train = TrainInfo.newBuilder();
train.setLineId(this.lineId);
train.setType(this.type);
train.setRtuId(this.rtuId);

View File

@ -13,6 +13,7 @@ import com.google.protobuf.GeneratedMessageV3.Builder;
import io.netty.buffer.ByteBuf;
import java.time.ZoneOffset;
import java.util.List;
import java.util.Objects;
import lombok.Getter;
import java.time.LocalDateTime;
@ -130,11 +131,21 @@ public class TrainRecordResponse extends MessageResponse {
@Override
public List<Builder> generateProto() {
TrainRecord.Builder builder = TrainRecord.newBuilder();
builder.setLineId(this.getLineId());
builder.setTrainId(this.getTrainId());
builder.setGlobalId(this.getGlobalId());
builder.setLocalSubId(this.getLocalSubId());
builder.setGroupId(this.getGroupId());
if (Objects.nonNull(this.lineId)) {
builder.setLineId(this.getLineId());
}
if (Objects.nonNull(this.trainId)) {
builder.setTrainId(this.trainId);
}
if (Objects.nonNull(this.globalId)) {
builder.setGlobalId(this.globalId);
}
if (Objects.nonNull(this.localSubId)) {
builder.setLocalSubId(this.localSubId);
}
if (Objects.nonNull(this.groupId)) {
builder.setGroupId(this.groupId);
}
if (this.getDestinationId() != null) {
builder.setDestinationId(this.getDestinationId());
}

View File

@ -156,6 +156,7 @@ public class MockDeviceController {
Object v = jo2.get(s1);
this.setVal(cloneBuilder, s1, v);
}
this.setVal(builder, s, cloneBuilder.build());
}
}
DeviceDataRepository.add(lineId, List.of(builder), dataType);

View File

@ -177,7 +177,7 @@ public class Status {
String groupId;
NccWindow window;
TrainMode trainMode;
TrainMode mode;
@Schema(description = "设备类型 DEVICE_TYPE_UNKNOW;\n"
+ " DEVICE_TYPE_RTU;\n"
+ " DEVICE_TYPE_STATION;\n"

View File

@ -52,7 +52,7 @@ public class LineDeviceStatusService {
@PostConstruct
public void deviceStatusRefresh() {
// this.createDataConvertor();
this.createDataConvertor();
// 设备状态数据集合
DeviceStatusData deviceStatusData = DeviceStatusDataRepository.getDeviceStatusData(DATA_KEY);
// 添加初始化转换方法
@ -97,21 +97,25 @@ public class LineDeviceStatusService {
Executors.newSingleThreadScheduledExecutor()
.scheduleWithFixedDelay(
() -> {
boolean isEmpty = true;
if (resetTimes.get() == stopTime) { // 代表还没有停顿不相等说明已经进入空循环
int count = (int) (Math.random() * 12);
List<MessageData> updateMockData =
nccMockDataService.loadUpdateData(id, MessageId.TRAIN_RECORD.name(), count);
DeviceStatusConvertorManager.doConvertor(updateMockData);
isEmpty = updateMockData.size() == 0;
}
if (isEmpty) { // 假数据已经用完了开始重复使用中间停顿30000ms
if (resetTimes.get() <= 0) {
id.set(0);
resetTimes.set(stopTime);
} else {
resetTimes.set(resetTimes.get() - frequency);
try {
boolean isEmpty = true;
if (resetTimes.get() == stopTime) { // 代表还没有停顿不相等说明已经进入空循环
int count = (int) (Math.random() * 12);
List<MessageData> updateMockData =
nccMockDataService.loadUpdateData(id, MessageId.TRAIN_RECORD.name(), count);
DeviceStatusConvertorManager.doConvertor(updateMockData);
isEmpty = updateMockData.size() == 0;
}
if (isEmpty) { // 假数据已经用完了开始重复使用中间停顿30000ms
if (resetTimes.get() <= 0) {
id.set(0);
resetTimes.set(stopTime);
} else {
resetTimes.set(resetTimes.get() - frequency);
}
}
} catch (Exception e) {
e.printStackTrace();
}
},
frequency,