This commit is contained in:
xzb 2023-06-20 15:55:04 +08:00
commit 6f80cb25bc
10 changed files with 275 additions and 524 deletions

View File

@ -1,119 +0,0 @@
package club.joylink.xiannccda.ats.message.collect;
import com.google.protobuf.Descriptors.FieldDescriptor.Type;
import com.google.protobuf.GeneratedMessageV3.Builder;
import com.google.protobuf.Message;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.function.BiFunction;
import org.springframework.util.CollectionUtils;
/** 收集状态方法 */
public abstract class DeviceStatusCollect {
/**
* 返回全量设备状态信息
*
* @param builder 返回的消息类型
* @param lineDataList 要处理的线路数据列表
* @return 状态消息
*/
public static Message collectAllStatus(Builder builder, List<DeviceStatusData> lineDataList) {
return commonCollectFunction(
builder,
(data, fieldType) -> {
Map<String, Map<String, Builder>> allDevice = data.getAllDeviceMap();
Map<String, Builder> deviceMap = allDevice.get(fieldType);
if (!CollectionUtils.isEmpty(deviceMap)) { // 如果存在该类型状态则全部放入
return deviceMap.values().stream().map(Builder::build).toList();
}
return List.of();
},
lineDataList);
}
/**
* 返回增量设备状态信息
*
* @param lineDataList 线路数据列表
* @return 状态信息
*/
public static Message collectIncrementStatus(
Builder builder, List<DeviceStatusData> lineDataList) {
return commonCollectFunction(
builder,
(data, fieldType) -> {
Map<String, Map<String, Builder>> allDevice = data.getAllDeviceMap();
Map<String, Map<String, Builder>> statusDevice = data.getStatusVOMap();
Map<String, Builder> deviceMap = allDevice.get(fieldType);
if (!CollectionUtils.isEmpty(deviceMap)) { // 如果存在该类型状态则全部放入
// 获取当前存储的状态
Map<String, Builder> statusMap =
statusDevice.computeIfAbsent(fieldType, key -> new HashMap<>(deviceMap.size()));
return compare(statusMap, deviceMap);
}
return List.of();
},
lineDataList);
}
/**
* 对比获取设备变化了的状态信息并更新状态信息
*
* @param curMap 原有的状态信息
* @param newMap 采集到状态信息
* @return 发生变化的状态信息
*/
public static List<Message> compare(Map<String, Builder> curMap, Map<String, Builder> newMap) {
List<Message> messageList = new LinkedList<>();
if (newMap != null) {
newMap.forEach(
(k, v) -> {
if (curMap.containsKey(k)) { // 包含状态对比状态是否一致
Message message = v.build();
if (!curMap.get(k).build().equals(message)) {
curMap.get(k).mergeFrom(message);
messageList.add(message);
}
} else { // 不包含直接添加状态
curMap.put(k, v.clone());
messageList.add(curMap.get(k).build());
}
});
}
return messageList;
}
/**
* 公共处理部分
*
* @param builder 返回的builder对象
* @param compareFun 额外的处理逻辑
* @param lineDataList 线路数据
* @return 消息内容
*/
private static Message commonCollectFunction(
Builder builder,
BiFunction<DeviceStatusData, String, List<Message>> compareFun,
List<DeviceStatusData> lineDataList) {
if (lineDataList == null || lineDataList.size() == 0) {
return builder.build();
}
// 消息体字段列表
builder.getDescriptorForType().getFields().stream()
.filter(f -> f.getType().equals(Type.MESSAGE))
.forEach(
field -> {
String fieldType = field.getMessageType().getName(); // 字段类型
List<Message> allDeviceList = new LinkedList<>();
for (DeviceStatusData data : lineDataList) { // 循环传入的线路数据
allDeviceList.addAll(compareFun.apply(data, fieldType));
}
if (!CollectionUtils.isEmpty(allDeviceList)) {
builder.setField(field, allDeviceList);
}
});
return builder.build();
}
}

View File

@ -1,6 +1,8 @@
package club.joylink.xiannccda.ats.message.collect; package club.joylink.xiannccda.ats.message.collect;
import com.google.protobuf.GeneratedMessageV3.Builder; import com.google.protobuf.GeneratedMessageV3.Builder;
import com.google.protobuf.Message;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import lombok.Getter; import lombok.Getter;
@ -15,8 +17,8 @@ public class DeviceStatusData {
/** 所有设备状态信息 <设备类型【这里用的message的类名:Rtu、Signal等】<设备主键,设备信息>> */ /** 所有设备状态信息 <设备类型【这里用的message的类名:Rtu、Signal等】<设备主键,设备信息>> */
private Map<String, Map<String, Builder>> allDeviceMap = new ConcurrentHashMap<>(); private Map<String, Map<String, Builder>> allDeviceMap = new ConcurrentHashMap<>();
/** 当前所有设备状态信息 */ /** 增量的设备更新信息 */
private Map<String, Map<String, Builder>> statusVOMap = new ConcurrentHashMap<>(); private Map<String, List<Message>> statusVOMap = new ConcurrentHashMap<>();
public DeviceStatusData(String lineCode) { public DeviceStatusData(String lineCode) {
this.lineCode = lineCode; this.lineCode = lineCode;

View File

@ -1,10 +1,13 @@
package club.joylink.xiannccda.ats.message.collect; package club.joylink.xiannccda.ats.message.collect;
import com.google.protobuf.GeneratedMessageV3.Builder; import com.google.protobuf.GeneratedMessageV3.Builder;
import com.google.protobuf.Message;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.springframework.util.CollectionUtils;
/** 线路设备操作方法 */ /** 线路设备操作方法 */
public abstract class DeviceStatusDataOperate { public abstract class DeviceStatusDataOperate {
@ -22,7 +25,7 @@ public abstract class DeviceStatusDataOperate {
* @param builder 设备状态信息 * @param builder 设备状态信息
* @return 状态类型 * @return 状态类型
*/ */
public static String findType(Builder builder) { private static String findType(Builder builder) {
return builder.getDefaultInstanceForType().getClass().getSimpleName(); return builder.getDefaultInstanceForType().getClass().getSimpleName();
} }
@ -32,7 +35,7 @@ public abstract class DeviceStatusDataOperate {
* @param protoBuilder 数据信息 * @param protoBuilder 数据信息
* @return 主键 * @return 主键
*/ */
public static String getIdVal(Builder protoBuilder) { private static String getIdVal(Builder protoBuilder) {
String idName = DEVICE_ID_NAME_MAP.getOrDefault(findType(protoBuilder), DEFAULT_ID_NAME); String idName = DEVICE_ID_NAME_MAP.getOrDefault(findType(protoBuilder), DEFAULT_ID_NAME);
return String.valueOf( return String.valueOf(
protoBuilder.getField(protoBuilder.getDescriptorForType().findFieldByName(idName))); protoBuilder.getField(protoBuilder.getDescriptorForType().findFieldByName(idName)));
@ -48,38 +51,27 @@ public abstract class DeviceStatusDataOperate {
if (data == null || builders == null) { if (data == null || builders == null) {
return; return;
} }
Map<String, Map<String, Builder>> map = data.getAllDeviceMap(); // 获取全量数据
Map<String, Map<String, Builder>> allDeviceMap = data.getAllDeviceMap();
// 最后增量数据
Map<String, List<Message>> statusVOMap = new ConcurrentHashMap<>();
builders.stream() builders.stream()
.collect(Collectors.groupingBy(DeviceStatusDataOperate::findType)) .collect(Collectors.groupingBy(DeviceStatusDataOperate::findType))
.forEach( .forEach(
(k, v) -> { (k, v) -> {
// 当前的设备状态
Map<String, Builder> deviceStatusMap = Map<String, Builder> deviceStatusMap =
map.computeIfAbsent(k, key -> new ConcurrentHashMap<>(v.size())); allDeviceMap.computeIfAbsent(k, key -> new ConcurrentHashMap<>(v.size()));
// 新的设备状态
Map<String, Builder> newDeviceMap = Map<String, Builder> newDeviceMap =
v.stream().collect(Collectors.toMap(DeviceStatusDataOperate::getIdVal, b -> b)); v.stream().collect(Collectors.toMap(DeviceStatusDataOperate::getIdVal, b -> b));
deviceStatusMap.putAll(newDeviceMap); // 对比结果
List<Message> compareList = compare(deviceStatusMap, newDeviceMap);
if (!CollectionUtils.isEmpty(compareList)) {
statusVOMap.put(k, compareList);
}
}); });
} data.getStatusVOMap().putAll(statusVOMap);
/**
* 将采集到的设备状态放入内存中
*
* @param builder 设备状态信息
* @param data 线路的设备信息
* @return 包装的设备状态
*/
public static void addDevice(Builder builder, DeviceStatusData data) {
if (data == null || builder == null) {
return;
}
Map<String, Map<String, Builder>> map = data.getAllDeviceMap();
String buildType = findType(builder);
Map<String, Builder> deviceStatusMap = map.get(buildType);
if (deviceStatusMap == null) {
deviceStatusMap = new ConcurrentHashMap<>();
map.put(buildType, deviceStatusMap);
}
deviceStatusMap.put(getIdVal(builder), builder);
} }
/** /**
@ -94,4 +86,31 @@ public abstract class DeviceStatusDataOperate {
data.getAllDeviceMap().clear(); data.getAllDeviceMap().clear();
data.getStatusVOMap().clear(); data.getStatusVOMap().clear();
} }
/**
* 对比获取设备变化了的状态信息并更新状态信息
*
* @param curMap 原有的状态信息
* @param newMap 采集到状态信息
* @return 发生变化的状态信息
*/
public static List<Message> compare(Map<String, Builder> curMap, Map<String, Builder> newMap) {
List<Message> messageList = new LinkedList<>();
if (newMap != null) {
newMap.forEach(
(k, v) -> {
if (curMap.containsKey(k)) { // 包含状态对比状态是否一致
Message message = v.build();
if (!curMap.get(k).build().equals(message)) {
curMap.get(k).mergeFrom(message);
messageList.add(message);
}
} else { // 不包含直接添加状态
curMap.put(k, v.clone());
messageList.add(curMap.get(k).build());
}
});
}
return messageList;
}
} }

View File

@ -1,9 +1,6 @@
package club.joylink.xiannccda.ats.message.collect; package club.joylink.xiannccda.ats.message.collect;
import club.joylink.xiannccda.dto.protos.WsMessageProto.WsLineMessage;
import club.joylink.xiannccda.dto.protos.WsMessageProto.WsLineNetMessage;
import com.google.protobuf.GeneratedMessageV3.Builder; import com.google.protobuf.GeneratedMessageV3.Builder;
import com.google.protobuf.Message;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -16,18 +13,6 @@ public abstract class DeviceStatusDataRepository {
/** 线路设备状态信息集合 */ /** 线路设备状态信息集合 */
private static final Map<String, DeviceStatusData> lineStatusDataMap = new ConcurrentHashMap<>(); private static final Map<String, DeviceStatusData> lineStatusDataMap = new ConcurrentHashMap<>();
/**
* 添加所属线路的设备信息
*
* @param lineCode 线路编号
* @param builders 设备信息
*/
public static void addAllDeviceStatusData(String lineCode, List<Builder> builders) {
DeviceStatusData data = lineStatusDataMap.computeIfAbsent(lineCode, DeviceStatusData::new);
DeviceStatusDataOperate.resetDevice(data);
DeviceStatusDataOperate.addDevices(builders, data);
}
/** /**
* 批量增加 * 批量增加
* *
@ -39,68 +24,6 @@ public abstract class DeviceStatusDataRepository {
DeviceStatusDataOperate.addDevices(builders, data); DeviceStatusDataOperate.addDevices(builders, data);
} }
/**
* 添加单个设备数据
*
* @param lineCode 线路编号
* @param builder 设备消息
*/
public static void addDeviceStatusData(String lineCode, Builder builder) {
DeviceStatusData data = lineStatusDataMap.computeIfAbsent(lineCode, DeviceStatusData::new);
DeviceStatusDataOperate.addDevice(builder, data);
}
/**
* 采集线路状态数据
*
* @param lineCode 线路编码
* @return 消息数据
*/
public static Message collectLineAllMessage(String lineCode) {
return DeviceStatusCollect.collectAllStatus(
WsLineMessage.newBuilder(), List.of(lineStatusDataMap.get(lineCode)));
}
/**
* 采集增量线路数据
*
* @param lineCode 线路编码
* @return 消息数据
*/
public static Message collectLineMessage(String lineCode) {
return DeviceStatusCollect.collectIncrementStatus(
WsLineMessage.newBuilder(), List.of(lineStatusDataMap.get(lineCode)));
}
/**
* 发送线网消息数据
*
* @return 消息数据
*/
public static Message collectLineNetAllMessage() {
return DeviceStatusCollect.collectAllStatus(
WsLineNetMessage.newBuilder(), lineStatusDataMap.values().stream().toList());
}
/**
* 发送线网增量消息数据
*
* @return 消息数据
*/
public static Message collectLineNetMessage() {
return DeviceStatusCollect.collectIncrementStatus(
WsLineNetMessage.newBuilder(), lineStatusDataMap.values().stream().toList());
}
/**
* 获取现在存在的线路编码列表
*
* @return 线路编码列表
*/
public static List<String> getLineCodeList() {
return lineStatusDataMap.keySet().stream().toList();
}
/** /**
* 获取线路总数据 * 获取线路总数据
* *

View File

@ -19201,27 +19201,10 @@ public final class DeviceStatusProto {
* 列车状态 * 列车状态
* </pre> * </pre>
* *
* <code>.state.TrainMode mode = 16;</code> * <code>int32 mode = 16;</code>
* @return Whether the mode field is set.
*/
boolean hasMode();
/**
* <pre>
* 列车状态
* </pre>
*
* <code>.state.TrainMode mode = 16;</code>
* @return The mode. * @return The mode.
*/ */
club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode getMode(); int getMode();
/**
* <pre>
* 列车状态
* </pre>
*
* <code>.state.TrainMode mode = 16;</code>
*/
club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainModeOrBuilder getModeOrBuilder();
/** /**
* <pre> * <pre>
@ -19747,41 +19730,18 @@ public final class DeviceStatusProto {
} }
public static final int MODE_FIELD_NUMBER = 16; public static final int MODE_FIELD_NUMBER = 16;
private club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode mode_; private int mode_ = 0;
/** /**
* <pre> * <pre>
* 列车状态 * 列车状态
* </pre> * </pre>
* *
* <code>.state.TrainMode mode = 16;</code> * <code>int32 mode = 16;</code>
* @return Whether the mode field is set.
*/
@java.lang.Override
public boolean hasMode() {
return mode_ != null;
}
/**
* <pre>
* 列车状态
* </pre>
*
* <code>.state.TrainMode mode = 16;</code>
* @return The mode. * @return The mode.
*/ */
@java.lang.Override @java.lang.Override
public club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode getMode() { public int getMode() {
return mode_ == null ? club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode.getDefaultInstance() : mode_; return mode_;
}
/**
* <pre>
* 列车状态
* </pre>
*
* <code>.state.TrainMode mode = 16;</code>
*/
@java.lang.Override
public club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainModeOrBuilder getModeOrBuilder() {
return mode_ == null ? club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode.getDefaultInstance() : mode_;
} }
public static final int NCCWINDOW_FIELD_NUMBER = 17; public static final int NCCWINDOW_FIELD_NUMBER = 17;
@ -19995,8 +19955,8 @@ public final class DeviceStatusProto {
if (routeId_ != 0) { if (routeId_ != 0) {
output.writeInt32(15, routeId_); output.writeInt32(15, routeId_);
} }
if (mode_ != null) { if (mode_ != 0) {
output.writeMessage(16, getMode()); output.writeInt32(16, mode_);
} }
if (nccWindow_ != 0) { if (nccWindow_ != 0) {
output.writeInt32(17, nccWindow_); output.writeInt32(17, nccWindow_);
@ -20086,9 +20046,9 @@ public final class DeviceStatusProto {
size += com.google.protobuf.CodedOutputStream size += com.google.protobuf.CodedOutputStream
.computeInt32Size(15, routeId_); .computeInt32Size(15, routeId_);
} }
if (mode_ != null) { if (mode_ != 0) {
size += com.google.protobuf.CodedOutputStream size += com.google.protobuf.CodedOutputStream
.computeMessageSize(16, getMode()); .computeInt32Size(16, mode_);
} }
if (nccWindow_ != 0) { if (nccWindow_ != 0) {
size += com.google.protobuf.CodedOutputStream size += com.google.protobuf.CodedOutputStream
@ -20167,11 +20127,8 @@ public final class DeviceStatusProto {
.equals(other.getDriverId())) return false; .equals(other.getDriverId())) return false;
if (getRouteId() if (getRouteId()
!= other.getRouteId()) return false; != other.getRouteId()) return false;
if (hasMode() != other.hasMode()) return false; if (getMode()
if (hasMode()) { != other.getMode()) return false;
if (!getMode()
.equals(other.getMode())) return false;
}
if (getNccWindow() if (getNccWindow()
!= other.getNccWindow()) return false; != other.getNccWindow()) return false;
if (getNccWindowOffset() if (getNccWindowOffset()
@ -20232,10 +20189,8 @@ public final class DeviceStatusProto {
hash = (53 * hash) + getDriverId().hashCode(); hash = (53 * hash) + getDriverId().hashCode();
hash = (37 * hash) + ROUTEID_FIELD_NUMBER; hash = (37 * hash) + ROUTEID_FIELD_NUMBER;
hash = (53 * hash) + getRouteId(); hash = (53 * hash) + getRouteId();
if (hasMode()) {
hash = (37 * hash) + MODE_FIELD_NUMBER; hash = (37 * hash) + MODE_FIELD_NUMBER;
hash = (53 * hash) + getMode().hashCode(); hash = (53 * hash) + getMode();
}
hash = (37 * hash) + NCCWINDOW_FIELD_NUMBER; hash = (37 * hash) + NCCWINDOW_FIELD_NUMBER;
hash = (53 * hash) + getNccWindow(); hash = (53 * hash) + getNccWindow();
hash = (37 * hash) + NCCWINDOWOFFSET_FIELD_NUMBER; hash = (37 * hash) + NCCWINDOWOFFSET_FIELD_NUMBER;
@ -20403,11 +20358,7 @@ public final class DeviceStatusProto {
recordTime_ = 0L; recordTime_ = 0L;
driverId_ = ""; driverId_ = "";
routeId_ = 0; routeId_ = 0;
mode_ = null; mode_ = 0;
if (modeBuilder_ != null) {
modeBuilder_.dispose();
modeBuilder_ = null;
}
nccWindow_ = 0; nccWindow_ = 0;
nccWindowOffset_ = 0; nccWindowOffset_ = 0;
rate_ = 0; rate_ = 0;
@ -20495,9 +20446,7 @@ public final class DeviceStatusProto {
result.routeId_ = routeId_; result.routeId_ = routeId_;
} }
if (((from_bitField0_ & 0x00008000) != 0)) { if (((from_bitField0_ & 0x00008000) != 0)) {
result.mode_ = modeBuilder_ == null result.mode_ = mode_;
? mode_
: modeBuilder_.build();
} }
if (((from_bitField0_ & 0x00010000) != 0)) { if (((from_bitField0_ & 0x00010000) != 0)) {
result.nccWindow_ = nccWindow_; result.nccWindow_ = nccWindow_;
@ -20592,8 +20541,8 @@ public final class DeviceStatusProto {
if (other.getRouteId() != 0) { if (other.getRouteId() != 0) {
setRouteId(other.getRouteId()); setRouteId(other.getRouteId());
} }
if (other.hasMode()) { if (other.getMode() != 0) {
mergeMode(other.getMode()); setMode(other.getMode());
} }
if (other.getNccWindow() != 0) { if (other.getNccWindow() != 0) {
setNccWindow(other.getNccWindow()); setNccWindow(other.getNccWindow());
@ -20722,13 +20671,11 @@ public final class DeviceStatusProto {
bitField0_ |= 0x00004000; bitField0_ |= 0x00004000;
break; break;
} // case 120 } // case 120
case 130: { case 128: {
input.readMessage( mode_ = input.readInt32();
getModeFieldBuilder().getBuilder(),
extensionRegistry);
bitField0_ |= 0x00008000; bitField0_ |= 0x00008000;
break; break;
} // case 130 } // case 128
case 136: { case 136: {
nccWindow_ = input.readInt32(); nccWindow_ = input.readInt32();
bitField0_ |= 0x00010000; bitField0_ |= 0x00010000;
@ -21694,51 +21641,31 @@ public final class DeviceStatusProto {
return this; return this;
} }
private club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode mode_; private int mode_ ;
private com.google.protobuf.SingleFieldBuilderV3<
club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode, club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode.Builder, club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainModeOrBuilder> modeBuilder_;
/** /**
* <pre> * <pre>
* 列车状态 * 列车状态
* </pre> * </pre>
* *
* <code>.state.TrainMode mode = 16;</code> * <code>int32 mode = 16;</code>
* @return Whether the mode field is set.
*/
public boolean hasMode() {
return ((bitField0_ & 0x00008000) != 0);
}
/**
* <pre>
* 列车状态
* </pre>
*
* <code>.state.TrainMode mode = 16;</code>
* @return The mode. * @return The mode.
*/ */
public club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode getMode() { @java.lang.Override
if (modeBuilder_ == null) { public int getMode() {
return mode_ == null ? club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode.getDefaultInstance() : mode_; return mode_;
} else {
return modeBuilder_.getMessage();
}
} }
/** /**
* <pre> * <pre>
* 列车状态 * 列车状态
* </pre> * </pre>
* *
* <code>.state.TrainMode mode = 16;</code> * <code>int32 mode = 16;</code>
* @param value The mode to set.
* @return This builder for chaining.
*/ */
public Builder setMode(club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode value) { public Builder setMode(int value) {
if (modeBuilder_ == null) {
if (value == null) {
throw new NullPointerException();
}
mode_ = value; mode_ = value;
} else {
modeBuilder_.setMessage(value);
}
bitField0_ |= 0x00008000; bitField0_ |= 0x00008000;
onChanged(); onChanged();
return this; return this;
@ -21748,106 +21675,15 @@ public final class DeviceStatusProto {
* 列车状态 * 列车状态
* </pre> * </pre>
* *
* <code>.state.TrainMode mode = 16;</code> * <code>int32 mode = 16;</code>
*/ * @return This builder for chaining.
public Builder setMode(
club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode.Builder builderForValue) {
if (modeBuilder_ == null) {
mode_ = builderForValue.build();
} else {
modeBuilder_.setMessage(builderForValue.build());
}
bitField0_ |= 0x00008000;
onChanged();
return this;
}
/**
* <pre>
* 列车状态
* </pre>
*
* <code>.state.TrainMode mode = 16;</code>
*/
public Builder mergeMode(club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode value) {
if (modeBuilder_ == null) {
if (((bitField0_ & 0x00008000) != 0) &&
mode_ != null &&
mode_ != club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode.getDefaultInstance()) {
getModeBuilder().mergeFrom(value);
} else {
mode_ = value;
}
} else {
modeBuilder_.mergeFrom(value);
}
bitField0_ |= 0x00008000;
onChanged();
return this;
}
/**
* <pre>
* 列车状态
* </pre>
*
* <code>.state.TrainMode mode = 16;</code>
*/ */
public Builder clearMode() { public Builder clearMode() {
bitField0_ = (bitField0_ & ~0x00008000); bitField0_ = (bitField0_ & ~0x00008000);
mode_ = null; mode_ = 0;
if (modeBuilder_ != null) {
modeBuilder_.dispose();
modeBuilder_ = null;
}
onChanged(); onChanged();
return this; return this;
} }
/**
* <pre>
* 列车状态
* </pre>
*
* <code>.state.TrainMode mode = 16;</code>
*/
public club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode.Builder getModeBuilder() {
bitField0_ |= 0x00008000;
onChanged();
return getModeFieldBuilder().getBuilder();
}
/**
* <pre>
* 列车状态
* </pre>
*
* <code>.state.TrainMode mode = 16;</code>
*/
public club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainModeOrBuilder getModeOrBuilder() {
if (modeBuilder_ != null) {
return modeBuilder_.getMessageOrBuilder();
} else {
return mode_ == null ?
club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode.getDefaultInstance() : mode_;
}
}
/**
* <pre>
* 列车状态
* </pre>
*
* <code>.state.TrainMode mode = 16;</code>
*/
private com.google.protobuf.SingleFieldBuilderV3<
club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode, club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode.Builder, club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainModeOrBuilder>
getModeFieldBuilder() {
if (modeBuilder_ == null) {
modeBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode, club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainMode.Builder, club.joylink.xiannccda.dto.protos.DeviceStatusProto.TrainModeOrBuilder>(
getMode(),
getParentForChildren(),
isClean());
mode_ = null;
}
return modeBuilder_;
}
private int nccWindow_ ; private int nccWindow_ ;
/** /**
@ -22508,20 +22344,19 @@ public final class DeviceStatusProto {
"ipModeTrainDriveModeRmr\030! \001(\010\022 \n\030ipModeT" + "ipModeTrainDriveModeRmr\030! \001(\010\022 \n\030ipModeT" +
"rainDriveModeWash\030\" \001(\010\022\n\n\002id\030# \001(\t\".\n\020O" + "rainDriveModeWash\030\" \001(\010\022\n\n\002id\030# \001(\t\".\n\020O" +
"ccNccFepNetwork\022\n\n\002id\030\001 \001(\t\022\016\n\006active\030\002 " + "ccNccFepNetwork\022\n\n\002id\030\001 \001(\t\022\016\n\006active\030\002 " +
"\001(\010\"\311\003\n\005Train\022\017\n\007trainId\030\001 \001(\t\022\020\n\010global" + "\001(\010\"\267\003\n\005Train\022\017\n\007trainId\030\001 \001(\t\022\020\n\010global" +
"Id\030\002 \001(\t\022\017\n\007groupId\030\003 \001(\t\022\022\n\nlocalSubId\030" + "Id\030\002 \001(\t\022\017\n\007groupId\030\003 \001(\t\022\022\n\nlocalSubId\030" +
"\004 \001(\005\022\021\n\ttrainType\030\005 \001(\005\022\r\n\005speed\030\006 \001(\002\022" + "\004 \001(\005\022\021\n\ttrainType\030\005 \001(\005\022\r\n\005speed\030\006 \001(\002\022" +
"\021\n\tdirection\030\007 \001(\005\022\025\n\rdestinationId\030\010 \001(" + "\021\n\tdirection\030\007 \001(\005\022\025\n\rdestinationId\030\010 \001(" +
"\005\022\021\n\tstationId\030\t \001(\005\022\016\n\006sideId\030\n \001(\005\022\021\n\t" + "\005\022\021\n\tstationId\030\t \001(\005\022\016\n\006sideId\030\n \001(\005\022\021\n\t" +
"trackName\030\013 \001(\t\022\022\n\nrecordType\030\014 \001(\010\022\022\n\nr" + "trackName\030\013 \001(\t\022\022\n\nrecordType\030\014 \001(\010\022\022\n\nr" +
"ecordTime\030\r \001(\003\022\020\n\010driverId\030\016 \001(\t\022\017\n\007rou" + "ecordTime\030\r \001(\003\022\020\n\010driverId\030\016 \001(\t\022\017\n\007rou" +
"teId\030\017 \001(\005\022\036\n\004mode\030\020 \001(\0132\020.state.TrainMo" + "teId\030\017 \001(\005\022\014\n\004mode\030\020 \001(\005\022\021\n\tnccWindow\030\021 " +
"de\022\021\n\tnccWindow\030\021 \001(\005\022\027\n\017nccWindowOffset" + "\001(\005\022\027\n\017nccWindowOffset\030\022 \001(\005\022\014\n\004rate\030\023 \001" +
"\030\022 \001(\005\022\014\n\004rate\030\023 \001(\005\022\017\n\007devType\030\024 \001(\005\022\017\n" + "(\005\022\017\n\007devType\030\024 \001(\005\022\017\n\007devName\030\025 \001(\t\022\021\n\t" +
"\007devName\030\025 \001(\t\022\021\n\tblockFlag\030\026 \001(\005\022\014\n\004sho" + "blockFlag\030\026 \001(\005\022\014\n\004show\030\027 \001(\010\022\016\n\006lineId\030" +
"w\030\027 \001(\010\022\016\n\006lineId\030\030 \001(\005B6\n!club.joylink." + "\030 \001(\005B6\n!club.joylink.xiannccda.dto.prot" +
"xiannccda.dto.protosB\021DeviceStatusProtob" + "osB\021DeviceStatusProtob\006proto3"
"\006proto3"
}; };
descriptor = com.google.protobuf.Descriptors.FileDescriptor descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData, .internalBuildGeneratedFileFrom(descriptorData,

View File

@ -1,15 +1,18 @@
package club.joylink.xiannccda.service; package club.joylink.xiannccda.service;
import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataRepository; import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataRepository;
import club.joylink.xiannccda.ws.IMessageServer;
import club.joylink.xiannccda.ws.LineNetMessageServer;
import club.joylink.xiannccda.ws.WsMessageServerManager;
import com.google.protobuf.GeneratedMessageV3.Builder; import com.google.protobuf.GeneratedMessageV3.Builder;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Train; import club.joylink.xiannccda.dto.protos.DeviceStatusProto.Train;
import club.joylink.xiannccda.ats.message.line3.device.DeviceType; import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
import jakarta.annotation.PostConstruct; import jakarta.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@ -21,89 +24,100 @@ import org.springframework.stereotype.Service;
@Service @Service
public class LineDeviceStatusService { public class LineDeviceStatusService {
@PostConstruct private String dataKey = "lineNet";
public void deviceStatusRefresh() {
List<String> rightPathList = private List<String> rightPathList =
List.of( List.of(
"G0105A", "G0105B", "G0105C", "DG0107", "G0109A", "G0109B", "G0109C", "G0109D", "G0105A", "G0105B", "G0105C", "DG0107", "G0109A", "G0109B", "G0109C", "G0109D", "G0109E",
"G0109E", "G0201A", "G0201B", "G0201C", "G0201D", "G0201E", "G0201F", "G0203A", "G0201A", "G0201B", "G0201C", "G0201D", "G0201E", "G0201F", "G0203A", "G0203B", "G0203C",
"G0203B", "G0203C", "G0203D", "G0301A", "G0301B", "G0301C", "G0301D", "G0301E", "G0203D", "G0301A", "G0301B", "G0301C", "G0301D", "G0301E", "DG0303", "G0401A", "G0401B",
"DG0303", "G0401A", "G0401B", "G0401C", "G0401D", "G0401E", "G0401F", "G0401G", "G0401C", "G0401D", "G0401E", "G0401F", "G0401G", "G0401H", "G0403A", "G0403B", "G0403C",
"G0401H", "G0403A", "G0403B", "G0403C", "G0403D", "G0501A", "G0501B", "G0501C", "G0403D", "G0501A", "G0501B", "G0501C", "G0501D", "DG0503", "DG0505", "G0507A", "G0507B",
"G0501D", "DG0503", "DG0505", "G0507A", "G0507B", "G0507C", "G0507D", "G0601A", "G0507C", "G0507D", "G0601A", "G0601B", "G0601C", "G0601D", "G0601E", "G0601F", "G0601G",
"G0601B", "G0601C", "G0601D", "G0601E", "G0601F", "G0601G", "G0601H", "G0603A", "G0601H", "G0603A", "G0603B", "G0603C", "G0603D", "G0701A", "G0701B", "G0701C", "G0701D",
"G0603B", "G0603C", "G0603D", "G0701A", "G0701B", "G0701C", "G0701D", "G0701E", "G0701E", "G0701F", "G0703A", "G0703B", "G0703C", "G0703D", "G0703E", "DG0705", "G0801A",
"G0701F", "G0703A", "G0703B", "G0703C", "G0703D", "G0703E", "DG0705", "G0801A", "G0801B", "G0801C", "G0801D", "G0801E", "G0801F", "G0803A", "G0803B", "G0803C", "G0803D",
"G0801B", "G0801C", "G0801D", "G0801E", "G0801F", "G0803A", "G0803B", "G0803C", "G0901A", "G0901B", "G0901C", "G0901D", "G0901E", "G0901F", "G0903A", "G0903B", "G0903C",
"G0803D", "G0901A", "G0901B", "G0901C", "G0901D", "G0901E", "G0901F", "G0903A", "G0903D", "DG0905", "G1001A", "G1001B", "G1001C", "G1001D", "G1001E", "G1001F", "G1001G",
"G0903B", "G0903C", "G0903D", "DG0905", "G1001A", "G1001B", "G1001C", "G1001D", "G1001H", "G1003A", "G1003B", "G1003C", "G1003D", "G1101A", "G1101B", "G1101C", "G1101D",
"G1001E", "G1001F", "G1001G", "G1001H", "G1003A", "G1003B", "G1003C", "G1003D", "G1101E", "G1101F", "G1101G", "G1101H", "G1101I", "G1103A", "G1103B", "G1103C", "G1103D",
"G1101A", "G1101B", "G1101C", "G1101D", "G1101E", "G1101F", "G1101G", "G1101H", "G1201A", "G1201B", "G1201C", "DG1203", "G1205A", "G1205B", "G1205C", "G1205D", "G1301A",
"G1101I", "G1103A", "G1103B", "G1103C", "G1103D", "G1201A", "G1201B", "G1201C", "G1301B", "G1301C", "G1301D", "G1301E", "G1303A", "G1303B", "G1303C", "G1303D", "G1401A",
"DG1203", "G1205A", "G1205B", "G1205C", "G1205D", "G1301A", "G1301B", "G1301C", "G1401B", "G1401C", "G1401D", "G1403A", "G1403B", "G1403C", "G1403D", "G1501A", "G1501B",
"G1301D", "G1301E", "G1303A", "G1303B", "G1303C", "G1303D", "G1401A", "G1401B", "G1501C", "G1501D", "G1503A", "G1503B", "G1503C", "G1503D", "DG1505", "G1601A", "G1601B",
"G1401C", "G1401D", "G1403A", "G1403B", "G1403C", "G1403D", "G1501A", "G1501B", "G1601C", "G1601D", "G1601E", "G1601F", "G1601G", "G1603A", "G1603B", "G1603C", "G1603D",
"G1501C", "G1501D", "G1503A", "G1503B", "G1503C", "G1503D", "DG1505", "G1601A", "G1701A", "G1701B", "G1701C", "G1701D", "G1701E", "G1701F", "G1701G", "G1703A", "G1703B",
"G1601B", "G1601C", "G1601D", "G1601E", "G1601F", "G1601G", "G1603A", "G1603B", "G1703C", "G1703D", "G1801A", "G1801B", "G1801C", "G1801D", "G1801E", "G1801F", "G1801G",
"G1603C", "G1603D", "G1701A", "G1701B", "G1701C", "G1701D", "G1701E", "G1701F", "G1801H", "G1801I", "DG1803", "G1805A", "G1805B", "G1805C", "G1805D", "G1901A", "G1901B",
"G1701G", "G1703A", "G1703B", "G1703C", "G1703D", "G1801A", "G1801B", "G1801C", "G1901C", "G1901D", "G1901E", "G1901F", "G1901G", "G1901H", "G1901I", "G1903A", "G1903B",
"G1801D", "G1801E", "G1801F", "G1801G", "G1801H", "G1801I", "DG1803", "G1805A", "G1903C", "G1903D", "G2001A", "G2001B", "G2001C", "G2001D", "G2001E", "G2001F", "G2001G",
"G1805B", "G1805C", "G1805D", "G1901A", "G1901B", "G1901C", "G1901D", "G1901E", "G2003A", "G2003B", "G2003C", "G2003D", "G2101A", "G2101B", "G2101C", "G2101D", "G2101E",
"G1901F", "G1901G", "G1901H", "G1901I", "G1903A", "G1903B", "G1903C", "G1903D", "G2101F", "G2101G", "G2103A", "G2103B", "G2103C", "G2103D", "DG2105", "G2107A", "G2107B",
"G2001A", "G2001B", "G2001C", "G2001D", "G2001E", "G2001F", "G2001G", "G2003A", "DG2109", "G2201A", "G2201B", "G2201C", "G2201D", "G2201E", "G2201F", "G2201G", "G2201H",
"G2003B", "G2003C", "G2003D", "G2101A", "G2101B", "G2101C", "G2101D", "G2101E", "G2201I", "G2203A", "G2203B", "G2203C", "G2203D", "G2301A", "G2301B", "G2301C", "G2301D",
"G2101F", "G2101G", "G2103A", "G2103B", "G2103C", "G2103D", "DG2105", "G2107A", "G2301E", "G2301F", "G2301G", "G2301H", "G2301I", "G2301J", "G2301K", "G2303A", "G2303B",
"G2107B", "DG2109", "G2201A", "G2201B", "G2201C", "G2201D", "G2201E", "G2201F", "G2303C", "G2303D", "G2401A", "G2401B", "G2401C", "G2401D", "G2401E", "G2401F", "DG2403",
"G2201G", "G2201H", "G2201I", "G2203A", "G2203B", "G2203C", "G2203D", "G2301A", "G2405A", "G2405B", "G2405C", "G2405D", "G2501A", "G2501B", "G2501C", "G2501D", "G2501E",
"G2301B", "G2301C", "G2301D", "G2301E", "G2301F", "G2301G", "G2301H", "G2301I", "G2503A", "G2503B", "G2503C", "G2503D", "G2601A", "G2601B", "G2601C", "G2601D", "G2601E",
"G2301J", "G2301K", "G2303A", "G2303B", "G2303C", "G2303D", "G2401A", "G2401B", "G2601F", "DG2603", "G2605A", "G2605B", "G2605C", "DG2607", "DG2609", "G2611A", "G2611B",
"G2401C", "G2401D", "G2401E", "G2401F", "DG2403", "G2405A", "G2405B", "G2405C",
"G2405D", "G2501A", "G2501B", "G2501C", "G2501D", "G2501E", "G2503A", "G2503B",
"G2503C", "G2503D", "G2601A", "G2601B", "G2601C", "G2601D", "G2601E", "G2601F",
"DG2603", "G2605A", "G2605B", "G2605C", "DG2607", "DG2609", "G2611A", "G2611B",
"G2611C"); "G2611C");
List<String> leftPathList = private List<String> leftPathList =
List.of( List.of(
"G2610A", "G2610B", "G2610C", "DG2608", "DG2606", "G2604A", "G2604B", "G2604C", "G2610A", "G2610B", "G2610C", "DG2608", "DG2606", "G2604A", "G2604B", "G2604C", "DG2602",
"DG2602", "G2504A", "G2504B", "G2504C", "G2504D", "G2504E", "G2504F", "G2502A", "G2504A", "G2504B", "G2504C", "G2504D", "G2504E", "G2504F", "G2502A", "G2502B", "G2502C",
"G2502B", "G2502C", "G2502D", "G2406A", "G2406B", "G2406C", "G2406D", "G2406E", "G2502D", "G2406A", "G2406B", "G2406C", "G2406D", "G2406E", "G2404A", "G2404B", "G2404C",
"G2404A", "G2404B", "G2404C", "G2404D", "DG2402", "G2304A", "G2304B", "G2304C", "G2404D", "DG2402", "G2304A", "G2304B", "G2304C", "G2304D", "G2304E", "G2304F", "G2304G",
"G2304D", "G2304E", "G2304F", "G2304G", "G2302A", "G2302B", "G2302C", "G2302D", "G2302A", "G2302B", "G2302C", "G2302D", "G2204A", "G2204B", "G2204C", "G2204D", "G2204E",
"G2204A", "G2204B", "G2204C", "G2204D", "G2204E", "G2204F", "G2204G", "G2204H", "G2204F", "G2204G", "G2204H", "G2204I", "G2204J", "G2204K", "G2202A", "G2202B", "G2202C",
"G2204I", "G2204J", "G2204K", "G2202A", "G2202B", "G2202C", "G2202D", "G2110A", "G2202D", "G2110A", "G2110B", "G2110C", "G2110D", "G2110E", "G2110F", "G2110G", "G2110H",
"G2110B", "G2110C", "G2110D", "G2110E", "G2110F", "G2110G", "G2110H", "G2110I", "G2110I", "DG2108", "G2106A", "G2106B", "DG2104", "G2102A", "G2102B", "G2102C", "G2102D",
"DG2108", "G2106A", "G2106B", "DG2104", "G2102A", "G2102B", "G2102C", "G2102D", "G2004A", "G2004B", "G2004C", "G2004D", "G2004E", "G2004F", "G2004G", "G2002A", "G2002B",
"G2004A", "G2004B", "G2004C", "G2004D", "G2004E", "G2004F", "G2004G", "G2002A", "G2002C", "G2002D", "G1904A", "G1904B", "G1904C", "G1904D", "G1904E", "G1904F", "G1904G",
"G2002B", "G2002C", "G2002D", "G1904A", "G1904B", "G1904C", "G1904D", "G1904E", "G1902A", "G1902B", "G1902C", "G1902D", "G1806A", "G1806B", "G1806C", "G1806D", "G1806E",
"G1904F", "G1904G", "G1902A", "G1902B", "G1902C", "G1902D", "G1806A", "G1806B", "G1806F", "G1806G", "G1806H", "G1804A", "G1804B", "G1804C", "G1804D", "DG1802", "G1704A",
"G1806C", "G1806D", "G1806E", "G1806F", "G1806G", "G1806H", "G1804A", "G1804B", "G1704B", "G1704C", "G1704D", "G1704E", "G1704F", "G1704G", "G1704H", "G1704I", "G1704J",
"G1804C", "G1804D", "DG1802", "G1704A", "G1704B", "G1704C", "G1704D", "G1704E", "G1702A", "G1702B", "G1702C", "G1702D", "G1604A", "G1604B", "G1604C", "G1604D", "G1604E",
"G1704F", "G1704G", "G1704H", "G1704I", "G1704J", "G1702A", "G1702B", "G1702C", "G1604F", "G1604G", "G1602A", "G1602B", "G1602C", "G1602D", "G1508A", "G1508B", "G1508C",
"G1702D", "G1604A", "G1604B", "G1604C", "G1604D", "G1604E", "G1604F", "G1604G", "G1508D", "G1508E", "DG1506", "DG1504", "G1502A", "G1502B", "G1502C", "G1502D", "G1404A",
"G1602A", "G1602B", "G1602C", "G1602D", "G1508A", "G1508B", "G1508C", "G1508D", "G1404B", "G1404C", "G1404D", "G1402A", "G1402B", "G1402C", "G1402D", "G1304A", "G1304B",
"G1508E", "DG1506", "DG1504", "G1502A", "G1502B", "G1502C", "G1502D", "G1404A", "G1304C", "G1304D", "G1302A", "G1302B", "G1302C", "G1302D", "G1206A", "G1206B", "G1206C",
"G1404B", "G1404C", "G1404D", "G1402A", "G1402B", "G1402C", "G1402D", "G1304A", "G1206D", "G1206E", "G1204A", "G1204B", "G1204C", "G1204D", "DG1202", "G1104A", "G1104B",
"G1304B", "G1304C", "G1304D", "G1302A", "G1302B", "G1302C", "G1302D", "G1206A", "G1104C", "G1102A", "G1102B", "G1102C", "G1102D", "G1004A", "G1004B", "G1004C", "G1004D",
"G1206B", "G1206C", "G1206D", "G1206E", "G1204A", "G1204B", "G1204C", "G1204D", "G1004E", "G1004F", "G1004G", "G1004H", "G1004I", "G1002A", "G1002B", "G1002C", "G1002D",
"DG1202", "G1104A", "G1104B", "G1104C", "G1102A", "G1102B", "G1102C", "G1102D", "G0908A", "G0908B", "G0908C", "G0908D", "G0908E", "G0908F", "G0908G", "DG0906", "DG0904",
"G1004A", "G1004B", "G1004C", "G1004D", "G1004E", "G1004F", "G1004G", "G1004H", "G0902A", "G0902B", "G0902C", "G0902D", "G0804A", "G0804B", "G0804C", "G0804D", "G0804E",
"G1004I", "G1002A", "G1002B", "G1002C", "G1002D", "G0908A", "G0908B", "G0908C", "G0804F", "G0802A", "G0802B", "G0802C", "G0802D", "G0710A", "G0710B", "G0710C", "G0710D",
"G0908D", "G0908E", "G0908F", "G0908G", "DG0906", "DG0904", "G0902A", "G0902B", "G0710E", "G0710F", "DG0708", "DG0704", "G0702A", "G0702B", "G0702C", "G0702D", "G0604A",
"G0902C", "G0902D", "G0804A", "G0804B", "G0804C", "G0804D", "G0804E", "G0804F", "G0604B", "G0604C", "G0604D", "G0604E", "G0604F", "G0602A", "G0602B", "G0602C", "G0602D",
"G0802A", "G0802B", "G0802C", "G0802D", "G0710A", "G0710B", "G0710C", "G0710D", "G0506A", "G0506B", "G0506C", "G0506D", "G0506E", "G0506F", "G0506G", "G0504A", "G0504B",
"G0710E", "G0710F", "DG0708", "DG0704", "G0702A", "G0702B", "G0702C", "G0702D", "G0504C", "G0504D", "DG0502", "G0404A", "G0404B", "G0404C", "G0404D", "G0404E", "G0404F",
"G0604A", "G0604B", "G0604C", "G0604D", "G0604E", "G0604F", "G0602A", "G0602B", "G0402A", "G0402B", "G0402C", "G0402D", "G0306A", "G0306B", "G0306C", "G0306D", "G0306E",
"G0602C", "G0602D", "G0506A", "G0506B", "G0506C", "G0506D", "G0506E", "G0506F", "G0306F", "G0306G", "G0306H", "G0304A", "G0304B", "G0304C", "G0304D", "DG0302", "G0206A",
"G0506G", "G0504A", "G0504B", "G0504C", "G0504D", "DG0502", "G0404A", "G0404B", "G0206B", "G0206C", "G0206D", "G0206E", "G0204A", "G0204B", "G0204C", "G0204D", "G0202A",
"G0404C", "G0404D", "G0404E", "G0404F", "G0402A", "G0402B", "G0402C", "G0402D", "G0202B", "G0202C", "G0202D", "G0202E", "G0110A", "G0110B", "G0110C", "G0110D", "G0110E",
"G0306A", "G0306B", "G0306C", "G0306D", "G0306E", "G0306F", "G0306G", "G0306H",
"G0304A", "G0304B", "G0304C", "G0304D", "DG0302", "G0206A", "G0206B", "G0206C",
"G0206D", "G0206E", "G0204A", "G0204B", "G0204C", "G0204D", "G0202A", "G0202B",
"G0202C", "G0202D", "G0202E", "G0110A", "G0110B", "G0110C", "G0110D", "G0110E",
"DG0108", "G0106A", "G0106B", "G0106C", "DG0104"); "DG0108", "G0106A", "G0106B", "G0106C", "DG0104");
List<String> trainList =
List.of("301", "302", "303", "304", "305", "306", "307", "308", "309", "310", "311", "312"); private List<String> trainList =
new ArrayList<>(
List.of(
"301", "302", "303", "304", "305", "306", "307", "308", "309", "310", "311", "312"));
private final WsMessageServerManager wsMessageServerManager;
public LineDeviceStatusService(WsMessageServerManager wsMessageServerManager) {
this.wsMessageServerManager = wsMessageServerManager;
}
@PostConstruct
public void deviceStatusRefresh() {
IMessageServer iMessageServer =
new LineNetMessageServer(DeviceStatusDataRepository.getDeviceStatusData(dataKey));
wsMessageServerManager.registerMessageServer(iMessageServer);
refreshTestData();
}
private void refreshTestData() {
Map<String, Integer> offsetMap = new HashMap<>(trainList.size()); // 列车到达位置 Map<String, Integer> offsetMap = new HashMap<>(trainList.size()); // 列车到达位置
Map<String, Train.Builder> trainInfoMap = new HashMap<>(trainList.size()); // 列车信息集合 Map<String, Train.Builder> trainInfoMap = new HashMap<>(trainList.size()); // 列车信息集合
for (int i = 0, len = trainList.size(); i < len; i++) { for (int i = 0, len = trainList.size(); i < len; i++) {
@ -126,12 +140,18 @@ public class LineDeviceStatusService {
offsetMap.put(code, offset); offsetMap.put(code, offset);
trainInfoMap.put(code, builder); trainInfoMap.put(code, builder);
} }
AtomicInteger count = new AtomicInteger(0);
Executors.newSingleThreadScheduledExecutor() Executors.newSingleThreadScheduledExecutor()
.scheduleWithFixedDelay( .scheduleWithFixedDelay(
() -> { () -> {
log.info("数据处理第" + count.incrementAndGet() + "");
List<String> codeList = randomTrainList();
List<Builder> builders = new LinkedList<>(); List<Builder> builders = new LinkedList<>();
trainInfoMap.forEach( trainInfoMap.forEach(
(k, v) -> { (k, v) -> {
if (!codeList.contains(k)) {
return;
}
List<String> path = v.getDirection() % 2 == 0 ? rightPathList : leftPathList; List<String> path = v.getDirection() % 2 == 0 ? rightPathList : leftPathList;
// 如果已经到达目的地 // 如果已经到达目的地
if (offsetMap.get(k) == v.getDestinationId()) { if (offsetMap.get(k) == v.getDestinationId()) {
@ -146,10 +166,28 @@ public class LineDeviceStatusService {
} }
builders.add(v.clone()); builders.add(v.clone());
}); });
DeviceStatusDataRepository.addDeviceStatusDataList("3", builders); DeviceStatusDataRepository.addDeviceStatusDataList(dataKey, builders);
}, },
1500, 1500,
1500, 1500,
TimeUnit.MILLISECONDS); TimeUnit.MILLISECONDS);
} }
public List<String> randomTrainList() {
int num = (int) (Math.random() * trainList.size());
List<String> codeList = new ArrayList<>(num);
try {
for (int i = 0, len = trainList.size(); i < num; i++, len--) {
int index = (int) (Math.random() * len);
String code = trainList.get(index);
trainList.set(index, trainList.get(trainList.size() - 1));
trainList.set(trainList.size() - 1, code);
codeList.add(code);
}
} catch (Exception e) {
log.error("获取列车列表出错", e);
}
return codeList;
}
} }

View File

@ -1,24 +1,45 @@
package club.joylink.xiannccda.ws; package club.joylink.xiannccda.ws;
import club.joylink.xiannccda.ats.message.collect.DeviceStatusDataRepository; import club.joylink.xiannccda.ats.message.collect.DeviceStatusData;
import club.joylink.xiannccda.dto.protos.WsMessageProto.WsLineNetMessage;
import com.google.protobuf.Descriptors.FieldDescriptor.Type;
import com.google.protobuf.Message;
import com.google.protobuf.GeneratedMessageV3.Builder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Function;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
/** 线网图websocket消息服务 */ /** 线网图websocket消息服务 */
@Slf4j @Slf4j
public class LineNetMessageServer implements IMessageServer { public class LineNetMessageServer implements IMessageServer {
final DeviceStatusData dataSource;
public LineNetMessageServer(DeviceStatusData dataSource) {
this.dataSource = dataSource;
}
@Override @Override
public String getDestinationPattern() { public String getDestinationPattern() {
return "/queue/line/all"; return "/queue/lineNet";
} }
@Override @Override
public Object onSubscription(String destination, Map<String, String> paramMap) { public Object onSubscription(String destination, Map<String, String> paramMap) {
log.info("【线网订阅】发布全量数据"); log.info("【线网订阅】发布全量数据");
byte[] bytes = DeviceStatusDataRepository.collectLineNetAllMessage().toByteArray(); WsLineNetMessage message =
commonCollectFunction(
(fieldType) -> {
Map<String, Builder> deviceMap = dataSource.getAllDeviceMap().get(fieldType);
if (!CollectionUtils.isEmpty(deviceMap)) { // 如果存在该类型状态则全部放入
return deviceMap.values().stream().map(Builder::build).toList();
}
return List.of();
});
byte[] bytes = message.toByteArray();
log.info("【线网订阅】全量数据量:" + bytes.length); log.info("【线网订阅】全量数据量:" + bytes.length);
return bytes; return bytes;
} }
@ -31,9 +52,36 @@ public class LineNetMessageServer implements IMessageServer {
@Override @Override
public List<TopicMessage> onTick() { public List<TopicMessage> onTick() {
List<TopicMessage> topicMessages = new ArrayList<>(); List<TopicMessage> topicMessages = new ArrayList<>();
byte[] bytes = DeviceStatusDataRepository.collectLineNetMessage().toByteArray(); WsLineNetMessage message =
commonCollectFunction(
(fieldType) -> dataSource.getStatusVOMap().getOrDefault(fieldType, List.of()));
byte[] bytes = message.toByteArray();
// 清空增量
dataSource.getStatusVOMap().clear();
log.info("【线网订阅】数据状态变化量:" + bytes.length); log.info("【线网订阅】数据状态变化量:" + bytes.length);
topicMessages.add(new TopicMessage(this.getDestinationPattern(), bytes)); topicMessages.add(new TopicMessage(this.getDestinationPattern(), bytes));
return topicMessages; return topicMessages;
} }
/**
* 公共处理部分
*
* @param compareFun 额外的处理逻辑
* @return 消息内容
*/
public WsLineNetMessage commonCollectFunction(Function<String, List<Message>> compareFun) {
WsLineNetMessage.Builder builder = WsLineNetMessage.newBuilder();
// 消息体字段列表
builder.getDescriptorForType().getFields().stream()
.filter(f -> f.getType().equals(Type.MESSAGE))
.forEach(
field -> {
String fieldType = field.getMessageType().getName(); // 字段类型
List<Message> allDeviceList = compareFun.apply(fieldType);
if (!CollectionUtils.isEmpty(allDeviceList)) {
builder.setField(field, allDeviceList);
}
});
return builder.build();
}
} }

View File

@ -29,7 +29,12 @@ public class TestMessageServer implements IMessageServer {
String lineId = paramMap.get(LineIdPathKey); String lineId = paramMap.get(LineIdPathKey);
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotNull(lineId); BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotNull(lineId);
log.info("线路lineId={}订阅,发布全量数据", lineId); log.info("线路lineId={}订阅,发布全量数据", lineId);
byte[] bytes = DeviceStatusDataRepository.collectLineAllMessage(lineId).toByteArray(); Builder builder = WsLineMessage.newBuilder();
builder.addRtu(Rtu.newBuilder().setId("rtu1").setIpRtuStusInCentralCtrl(true).build());
builder.addSignal(
Signal.newBuilder().setId("signal1").setRedOpen(true).setAutoMode(true).build());
byte[] bytes = builder.build().toByteArray();
System.out.println(JSON.toJSONString(bytes)); System.out.println(JSON.toJSONString(bytes));
return bytes; return bytes;
} }

View File

@ -34,7 +34,12 @@ public class TestMessageServer2 implements IMessageServer {
@Override @Override
public Object onSubscription(String destination, Map<String, String> paramMap) { public Object onSubscription(String destination, Map<String, String> paramMap) {
log.info("线路lineId={}订阅,发布全量数据", lineId); log.info("线路lineId={}订阅,发布全量数据", lineId);
byte[] bytes = DeviceStatusDataRepository.collectLineAllMessage(lineId).toByteArray(); Builder builder = WsLineMessage.newBuilder();
builder.addRtu(Rtu.newBuilder().setId("rtu1").setIpRtuStusInCentralCtrl(true).build());
builder.addSignal(
Signal.newBuilder().setId("signal1").setRedOpen(true).setAutoMode(true).build());
byte[] bytes = builder.build().toByteArray();
System.out.println(JSON.toJSONString(bytes)); System.out.println(JSON.toJSONString(bytes));
return bytes; return bytes;
} }

View File

@ -33,11 +33,6 @@ public class WsMessageServerManager {
public WsMessageServerManager(SimpMessagingTemplate smt) { public WsMessageServerManager(SimpMessagingTemplate smt) {
this.smt = smt; this.smt = smt;
// 注册线网消息服务
registerMessageServer(new LineNetMessageServer());
registerMessageServer(
new TestMessageServer2("3", DeviceStatusDataRepository.getDeviceStatusData("3")));
} }
public void registerMessageServer(IMessageServer messageServer) { public void registerMessageServer(IMessageServer messageServer) {