#ZH
野心家
2025-05-27 1b9f41e12e3ee8ac8bbc388eab7585300bdab75a
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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 {
        }
    }
 
}