package com.zy.core.cache;
|
|
import com.zy.core.model.protocol.RgvProtocol;
|
|
import java.util.Collection;
|
import java.util.concurrent.ConcurrentHashMap;
|
|
/**
|
* Created by IX on 2025/02/21
|
*/
|
public class RgvStatusCache {
|
// 本地缓存,键为 currentPosition,值为 DeviceStatus
|
private static final ConcurrentHashMap<Integer, RgvProtocol> cache = new ConcurrentHashMap<>();
|
|
/**
|
* 更新设备状态
|
*/
|
public static void updateRgvStatus(RgvProtocol status) {
|
try {
|
if (status.getRgvNo()!=1 && status.getRgvNo() != 2){
|
return;
|
}
|
cache.put(status.getRgvNo(), status);
|
} finally {
|
}
|
}
|
|
/**
|
* 获取设备状态
|
*/
|
public static RgvProtocol getRgvStatus(Integer RgvNo) {
|
try {
|
return cache.get(RgvNo);
|
} finally {
|
}
|
}
|
|
/**
|
* 获取所有设备状态
|
*/
|
public static ConcurrentHashMap<Integer, RgvProtocol> getAllRgvStatus() {
|
try {
|
return new ConcurrentHashMap<>(cache); // 返回副本
|
} finally {
|
}
|
}
|
|
/**
|
* 获取所有设备状态
|
*/
|
public static void removeAll() {
|
try {
|
ConcurrentHashMap<Integer, RgvProtocol> integerRgvProtocolConcurrentHashMap = new ConcurrentHashMap<>(cache);
|
if (integerRgvProtocolConcurrentHashMap.values().size()>2){
|
for (RgvProtocol rgvProtocol : integerRgvProtocolConcurrentHashMap.values()){
|
cache.remove(rgvProtocol.getRgvNo());
|
}
|
}
|
} finally {
|
}
|
}
|
|
}
|