| | |
| | | package com.zy.core.utils; |
| | | |
| | | import com.core.exception.CoolException; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.zy.common.exception.CoolException; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.enums.RedisKeyType; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.model.DeviceCommandMsgModel; |
| | | import com.zy.core.model.DeviceMsgModel; |
| | | import com.zy.core.properties.DeviceConfig; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | |
| | | @Value("${deviceMsgConfig.destroyAfterReading}") |
| | | private boolean destroyAfterReading; |
| | | |
| | | @Value("${deviceMsgConfig.gatewayId}") |
| | | private Integer gatewayId; |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | |
| | | public List<DeviceConfig> getDeviceConfig() { |
| | | List<DeviceConfig> list = new ArrayList<>(); |
| | | Object obj = redisUtil.get(RedisKeyType.DEVICE_CONFIG.key); |
| | | if(null == obj){ |
| | | return list; |
| | | } |
| | | |
| | | List<DeviceConfig> deviceConfigs = JSON.parseArray(obj.toString(), DeviceConfig.class); |
| | | for (DeviceConfig deviceConfig : deviceConfigs) { |
| | | if(deviceConfig.getGatewayId().equals(gatewayId)){ |
| | | list.add(deviceConfig); |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | public DeviceCommandMsgModel getDeviceCommandMsg(SlaveType deviceType, Integer deviceId) { |
| | | TreeSet<String> listKey = getDeviceCommandMsgListKey(deviceType, deviceId); |
| | |
| | | return key; |
| | | } |
| | | |
| | | public void sendDeviceConfig(String allDevices) { |
| | | redisUtil.set(RedisKeyType.DEVICE_CONFIG.key, allDevices); |
| | | } |
| | | |
| | | public TreeSet<String> getDeviceMsgListKey(SlaveType deviceType, Integer deviceId) { |
| | | String listKey = parseDeviceMsgKey(deviceType, deviceId); |
| | | Set<String> keys = redisUtil.searchKeys(listKey); |