【设备状态比较逻辑】

This commit is contained in:
weizhihong 2023-06-19 09:08:23 +08:00
parent 484076b249
commit 14a6489396
3 changed files with 12 additions and 14 deletions

View File

@ -11,7 +11,7 @@ import java.util.function.BiFunction;
import org.springframework.util.CollectionUtils;
/** 收集状态方法 */
public class DeviceStatusCollect {
public abstract class DeviceStatusCollect {
/**
* 返回全量设备状态信息
*

View File

@ -1,15 +1,13 @@
package club.joylink.xiannccda.ats.message.collect;
import com.google.protobuf.GeneratedMessageV3.Builder;
import com.google.protobuf.Message;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
/** 线路设备操作方法 */
public class DeviceStatusDataOperate {
public abstract class DeviceStatusDataOperate {
/** 默认的主键名称 */
private static final String DEFAULT_ID_NAME = "id";

View File

@ -8,15 +8,13 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import lombok.Getter;
import org.springframework.stereotype.Component;
/** 状态信息初始化 */
@Getter
@Component
public class StatusDataRepository {
public abstract class DeviceStatusDataRepository {
/** 线路设备状态信息集合 */
private Map<String, DeviceStatusData> lineStatusDataMap = new ConcurrentHashMap<>();
private static Map<String, DeviceStatusData> lineStatusDataMap = new ConcurrentHashMap<>();
/**
* 添加所属线路的设备信息
@ -24,11 +22,13 @@ public class StatusDataRepository {
* @param lineCode 线路编号
* @param builders 设备信息
*/
public void addAllDeviceStatusData(String lineCode, List<Builder> builders) {
public static void addAllDeviceStatusData(String lineCode, List<Builder> builders) {
DeviceStatusData data = lineStatusDataMap.get(lineCode);
if (data == null) {
data = new DeviceStatusData(lineCode);
lineStatusDataMap.put(lineCode, data);
} else {
DeviceStatusDataOperate.resetDevice(data);
}
DeviceStatusDataOperate.addDevices(builders, data);
}
@ -39,7 +39,7 @@ public class StatusDataRepository {
* @param lineCode 线路编号
* @param builder 设备消息
*/
public void addDeviceStatusData(String lineCode, Builder builder) {
public static void addDeviceStatusData(String lineCode, Builder builder) {
DeviceStatusData data = lineStatusDataMap.get(lineCode);
if (data == null) {
data = new DeviceStatusData(lineCode);
@ -54,7 +54,7 @@ public class StatusDataRepository {
* @param lineCode 线路编码
* @return 消息数据
*/
public Message collectLineAllMessage(String lineCode) {
public static Message collectLineAllMessage(String lineCode) {
return DeviceStatusCollect.collectAllStatus(
WsLineMessage.newBuilder(), List.of(lineStatusDataMap.get(lineCode)));
}
@ -65,7 +65,7 @@ public class StatusDataRepository {
* @param lineCode 线路编码
* @return 消息数据
*/
public Message collectLineMessage(String lineCode) {
public static Message collectLineMessage(String lineCode) {
return DeviceStatusCollect.collectIncrementStatus(
WsLineMessage.newBuilder(), List.of(lineStatusDataMap.get(lineCode)));
}
@ -75,7 +75,7 @@ public class StatusDataRepository {
*
* @return 消息数据
*/
public Message collectLineNetAllMessage() {
public static Message collectLineNetAllMessage() {
return DeviceStatusCollect.collectAllStatus(
WsLineNetMessage.newBuilder(), lineStatusDataMap.values().stream().toList());
}
@ -85,7 +85,7 @@ public class StatusDataRepository {
*
* @return 消息数据
*/
public Message collectLineNetMessage() {
public static Message collectLineNetMessage() {
return DeviceStatusCollect.collectIncrementStatus(
WsLineNetMessage.newBuilder(), lineStatusDataMap.values().stream().toList());
}