jiazx0107@163.com
2023-12-02 5bb3ad3944ff229baff1d8bb92caf55d816ee68b
src/main/java/com/fzzy/gateway/GatewayUtils.java
@@ -1,7 +1,10 @@
package com.fzzy.gateway;
import com.fzzy.api.Constant;
import com.fzzy.api.data.ApiCommonDevice;
import com.fzzy.api.data.GatewayDeviceType;
import com.fzzy.gateway.entity.GatewayDevice;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import java.util.*;
@@ -11,13 +14,6 @@
 */
@Component
public class GatewayUtils {
    /**
     * 设备在线标记,针对WEBSocket请求,控制设备是否在线,key = deviceId,Value=Y/N
     */
    public static Map<String, String> contextOnlineMap = new HashMap<>();
    /**
     * 设备缓存
@@ -74,22 +70,21 @@
        cacheMapDeviceSn.remove(data.getDeviceSn());
    }
    public static void updateOnline(String deviceId) {
        contextOnlineMap.put(deviceId, "Y");
    public static String getStatus(String sn) {
        ApiCommonDevice device = Constant.getCommonDeviceCache(sn);
        if (null == device) return Constant.YN_N;
        return device.getStatus();
    }
    public static void updateOffOnline(String deviceId) {
        contextOnlineMap.put(deviceId, "N");
    }
    public static boolean isOnline(String deviceId) {
        String value = contextOnlineMap.get(deviceId);
        if (null == value || "N".equals(value)) return false;
        GatewayDevice device = getCacheByDeviceId(deviceId);
        if (null == device.getStatus() || Constant.YN_N.equals(device.getStatus())) return false;
        return true;
    }
    public static Collection<GatewayDevice> listDeviceWeight(){
    public static Collection<GatewayDevice> listDeviceWeight() {
        return cacheMapDeviceWeight.values();
    }
}