package com.zy.core.cache;
|
|
import com.zy.core.model.protocol.CrnErrProtocol;
|
import com.zy.core.model.protocol.RgvErrProtocol;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
/**
|
* Created by IX on 2025/02/21
|
*/
|
public class CrnErrCache {
|
// 本地缓存,键为 currentPosition,值为 DeviceStatus
|
private static final ConcurrentHashMap<Integer, CrnErrProtocol> cache = new ConcurrentHashMap<>();
|
|
/**
|
* 更新设备状态
|
*/
|
public static void updateCrnStatus(CrnErrProtocol status) {
|
try {
|
cache.put(status.getCrnNo(), status);
|
} finally {
|
}
|
}
|
|
|
/**
|
* 更新设备状态
|
*/
|
public static void updateCrnErr(Integer crnNo,String error) {
|
try {
|
CrnErrProtocol crnErrProtocol = cache.get(crnNo);
|
if (crnErrProtocol == null){
|
crnErrProtocol = new CrnErrProtocol();
|
crnErrProtocol.setCrnNo(crnNo);
|
}
|
if (!crnErrProtocol.getError().equals(error)){
|
crnErrProtocol.setError(error);
|
cache.put(crnErrProtocol.getCrnNo(), crnErrProtocol);
|
}
|
} finally {
|
}
|
}
|
|
|
/**
|
* 更新设备状态
|
*/
|
public static void updateCrnErr(Integer crnNo) {
|
try {
|
CrnErrProtocol crnErrProtocol = cache.get(crnNo);
|
if (crnErrProtocol == null){
|
crnErrProtocol = new CrnErrProtocol();
|
crnErrProtocol.setCrnNo(crnNo);
|
}
|
if (!crnErrProtocol.getError().equals("-")){
|
crnErrProtocol.setError("-");
|
cache.put(crnErrProtocol.getCrnNo(), crnErrProtocol);
|
}
|
} finally {
|
}
|
}
|
|
|
|
|
/**
|
* 更新设备状态
|
*/
|
public static String getErrorCrn(Integer crnNo) {
|
try {
|
CrnErrProtocol crnErrProtocol = cache.get(crnNo);
|
if (crnErrProtocol == null){
|
crnErrProtocol = new CrnErrProtocol();
|
crnErrProtocol.setCrnNo(crnNo);
|
}
|
return crnErrProtocol.getError();
|
} finally {
|
}
|
}
|
|
/**
|
* 获取设备状态
|
*/
|
public static CrnErrProtocol getCrnStatus(Integer crnNo) {
|
try {
|
return cache.get(crnNo);
|
} finally {
|
}
|
}
|
|
/**
|
* 获取所有设备状态
|
*/
|
public static ConcurrentHashMap<Integer, CrnErrProtocol> getAllCrnStatus() {
|
try {
|
return new ConcurrentHashMap<>(cache); // 返回副本
|
} finally {
|
}
|
}
|
|
}
|