#ZH
野心家
2025-05-27 c9d334e61ff33aa2f90b71e34d5a7a0340765bfe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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 {
        }
    }
 
}