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

This commit is contained in:
tiger_zhou 2023-07-05 16:35:29 +08:00
parent c5f5449da9
commit 526d674075
6 changed files with 78 additions and 80 deletions

View File

@ -15,6 +15,7 @@ import lombok.Getter;
import java.util.ArrayList;
import java.util.List;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
/**
* 2.7.13 列车阻塞消息
@ -52,12 +53,9 @@ public class TrainBlockInfoResponse extends MessageResponse {
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());
}
builder.setGroupId(StringUtils.defaultString(train.getGroupId(), ""));
builder.setTrainId(StringUtils.defaultString(train.getTrainId(), ""));
if (Objects.nonNull(train.getDirection())) {
builder.setDirection(train.getDirection().value);
}
@ -74,9 +72,8 @@ public class TrainBlockInfoResponse extends MessageResponse {
DeviceStatusProto.DeviceType dtProto = DeviceStatusProto.DeviceType.forNumber(train.getDevType().getVal());
builder.setDeviceType(dtProto);
}
if (Objects.nonNull(train.getDevName())) {
builder.setDevName(train.getDevName());
}
builder.setDevName(StringUtils.defaultString(train.getDevName(), ""));
if (Objects.nonNull(train.getBlockFlag())) {
builder.setBlockFlag(train.getBlockFlag() ? 1 : 0);
}

View File

@ -19,6 +19,7 @@ import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
/**
* 2.7.9列车信息全体消息
@ -59,37 +60,31 @@ public class TrainIndicationInitResponse extends MessageResponse {
if (trainCell.getRtuId() != null) {
builder.setRtuId(trainCell.getRtuId());
}
NccWindow.Builder window = NccWindow.newBuilder();
if (trainCell.getNccWindow() != null) {
NccWindow.Builder window = NccWindow.newBuilder();
window.setNccWindow(trainCell.getNccWindow());
window.setNccWinOffset(trainCell.getNccWindowOffset());
builder.setWindow(window);
}
if (Objects.nonNull(trainCell.getNccWindowOffset())) {
window.setNccWinOffset(trainCell.getNccWindowOffset());
}
builder.setWindow(window);
if (trainCell.getDevType() != null) {
builder.setDevType(DeviceStatusProto.DeviceType.forNumber(trainCell.getDevType().getVal()));
}
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());
}
builder.setDevName(StringUtils.defaultString(trainCell.getDevName(), ""));
builder.setTrainIndex(StringUtils.defaultString(trainCell.getTrainIndex(), ""));
builder.setGroupId(StringUtils.defaultString(trainCell.getGroupId(), ""));
builder.setTrainId(StringUtils.defaultString(trainCell.getTrainId(), ""));
builder.setGlobalId(StringUtils.defaultString(trainCell.getGlobalId(), ""));
if (trainCell.getDestinationId() != null) {
builder.setDestinationId(trainCell.getDestinationId());
}
builder.setRollingStock(trainCell.getRollingStock());
if (trainCell.getDriverId() != null) {
builder.setDriverId(trainCell.getDriverId());
}
builder.setDriverId(StringUtils.defaultString(trainCell.getDriverId(), ""));
if (trainCell.getOtpTime() != null) {
builder.setOtpTime(trainCell.getOtpTime());
}

View File

@ -12,6 +12,7 @@ import java.util.List;
import java.util.Objects;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
/**
* 2.7.11 列车信息删除消息
@ -95,16 +96,10 @@ public class TrainIndicationRemoveResponse extends MessageResponse {
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);
trainRemove.setDevName(StringUtils.defaultString(this.devName, ""));
trainRemove.setTrainIndex(StringUtils.defaultString(this.trainIndex, ""));
trainRemove.setGroupId(StringUtils.defaultString(this.groupId, ""));
}
return List.of(trainRemove);
}

View File

@ -16,8 +16,11 @@ import io.netty.buffer.ByteBuf;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.List;
import java.util.Objects;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
/**
* 2.7.10 列车信息更新消息[增加/更新]
@ -129,14 +132,20 @@ public class TrainIndicationUpdateResponse extends MessageResponse {
train.setType(this.type);
train.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);
}
train.setWindow(window);
if (Objects.nonNull(this.devType)) {
train.setDevType(DeviceStatusProto.DeviceType.forNumber(this.devType.getVal()));
}
train.setDevName(StringUtils.defaultString(this.devName, ""));
train.setDevType(DeviceStatusProto.DeviceType.forNumber(this.devType.getVal()));
train.setDevName(this.devName);
train.setTrainIndex(this.trainIndex);
train.setTrainIndex(StringUtils.defaultString(this.trainIndex, ""));
train.setRollingStock(this.getRollingStock());
train.setOtpTime(this.optTime);
train.setArriveTime(this.arriveTime.toEpochSecond(ZoneOffset.ofHours(8)));
@ -145,13 +154,21 @@ public class TrainIndicationUpdateResponse extends MessageResponse {
DeviceStatusConvertor.convert(DeviceStatus.TRAIN_MODE.class, this.mode);
train.setMode(trainMode.build());
train.setSpeed(this.speed);
train.setRate(this.rate);
train.setRouteId(this.routeId);
train.setDriverId(this.driverId);
train.setDestinationId(this.destinationId);
train.setGroupId(this.groupId);
train.setGlobalId(this.globalId);
train.setTrainId(this.trainId);
if (Objects.nonNull(this.rate)) {
train.setRate(this.rate);
}
if (Objects.nonNull(this.routeId)) {
train.setRouteId(this.routeId);
}
train.setDriverId(StringUtils.defaultString(this.driverId, ""));
if (Objects.nonNull(this.destinationId)) {
train.setDestinationId(this.destinationId);
}
train.setGroupId(StringUtils.defaultString(this.groupId, ""));
train.setGlobalId(StringUtils.defaultString(this.globalId, ""));
train.setTrainId(StringUtils.defaultString(this.trainId, ""));
return Lists.newArrayList(train);
}

View File

@ -18,6 +18,7 @@ import lombok.Getter;
import java.time.LocalDateTime;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
/**
* 2.7.8列车报点消息
@ -134,18 +135,14 @@ public class TrainRecordResponse extends MessageResponse {
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);
}
builder.setTrainId(StringUtils.defaultString(this.trainId, ""));
builder.setGlobalId(StringUtils.defaultString(this.globalId, ""));
if (Objects.nonNull(this.localSubId)) {
builder.setLocalSubId(this.localSubId);
}
if (Objects.nonNull(this.groupId)) {
builder.setGroupId(this.groupId);
}
builder.setGlobalId(StringUtils.defaultString(this.groupId, ""));
if (this.getDestinationId() != null) {
builder.setDestinationId(this.getDestinationId());
}
@ -161,7 +158,8 @@ public class TrainRecordResponse extends MessageResponse {
if (this.getSideId() != null) {
builder.setSideId(this.getSideId());
}
builder.setTrackName(this.getTrackName());
;
builder.setTrackName(StringUtils.defaultString(this.trackName, ""));
if (this.getRecordType() != null) {
builder.setRecordType(this.getRecordType());
}

View File

@ -97,25 +97,21 @@ public class LineDeviceStatusService {
Executors.newSingleThreadScheduledExecutor()
.scheduleWithFixedDelay(
() -> {
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;
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);
}
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,