| | |
| | | package com.fzzy.gateway; |
| | | |
| | | import com.fzzy.api.data.GatewayDeviceType; |
| | | import com.fzzy.gateway.entity.GatewayDevice; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 常量 |
| | | */ |
| | | @Component |
| | | public class GatewayUtils { |
| | | |
| | | |
| | |
| | | */ |
| | | public static Map<String, GatewayDevice> cacheMapDeviceSn = new HashMap<>(); |
| | | |
| | | /** |
| | | * 设备缓存-只针对 |
| | | */ |
| | | public static Map<String, GatewayDevice> cacheMapDeviceWeight = new HashMap<>(); |
| | | |
| | | |
| | | public static void add2Cache(GatewayDevice device) { |
| | | cacheMapDeviceId.put(device.getDeviceId(), device); |
| | | cacheMapDeviceSn.put(device.getDeviceSn(), device); |
| | | |
| | | //保存地磅 |
| | | if (GatewayDeviceType.TYPE_01.getCode().equals(device.getType())) { |
| | | cacheMapDeviceWeight.put(device.getDeviceId(), device); |
| | | } |
| | | } |
| | | |
| | | public static GatewayDevice getCacheByDeviceId(String deviceId) { |
| | |
| | | |
| | | public static GatewayDevice getCacheByDeviceSn(String deviceSn) { |
| | | return cacheMapDeviceSn.get(deviceSn); |
| | | } |
| | | |
| | | public static List<GatewayDevice> getCacheByDeviceType(String deviceType) { |
| | | List<GatewayDevice> result = new ArrayList<>(); |
| | | for (GatewayDevice device : cacheMapDeviceId.values()) { |
| | | if (deviceType.equals(device.getType())) result.add(device); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | public static GatewayDevice getCacheByDeviceTypeOne(String deviceType) { |
| | | for (GatewayDevice device : cacheMapDeviceId.values()) { |
| | | if (deviceType.equals(device.getType())) return device; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | |
| | | if (null == value || "N".equals(value)) return false; |
| | | return true; |
| | | } |
| | | |
| | | |
| | | public static Collection<GatewayDevice> listDeviceWeight(){ |
| | | return cacheMapDeviceWeight.values(); |
| | | } |
| | | } |