| | |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | |
| | | |
| | | public Object getDeviceCommandMsg(SlaveType deviceType, Integer deviceId) { |
| | | TreeSet<String> listKey = getDeviceCommandMsgListKey(deviceType, deviceId); |
| | | if (listKey.isEmpty()) { |
| | | return null; |
| | | } |
| | | |
| | | String firstKey = listKey.first(); |
| | | Object data = redisUtil.get(firstKey); |
| | | if (destroyAfterReading) { |
| | | redisUtil.del(firstKey); |
| | | } |
| | | return data; |
| | | } |
| | | |
| | | public DeviceMsgModel getDeviceMsg(SlaveType deviceType, Integer deviceId) { |
| | | TreeSet<String> listKey = getDeviceMsgListKey(deviceType, deviceId); |
| | | if (listKey.isEmpty()) { |
| | |
| | | redisUtil.set(key, msgModel, 60 * 60); |
| | | } |
| | | |
| | | public String sendCommand(SlaveType deviceType, Integer deviceId, Object command) { |
| | | public String sendDeviceMsg(SlaveType deviceType, Integer deviceId, Object command) { |
| | | String key = parseDeviceMsgKey(deviceType, deviceId) + System.currentTimeMillis(); |
| | | |
| | | DeviceMsgModel deviceMsgModel = new DeviceMsgModel(); |
| | | deviceMsgModel.setDeviceId(deviceId); |
| | | deviceMsgModel.setDeviceMsg(command); |
| | | redisUtil.set(key, deviceMsgModel, 60 * 60 * 24); |
| | | return key; |
| | | } |
| | | |
| | | public String sendDeviceCommand(SlaveType deviceType, Integer deviceId, Object command) { |
| | | String key = parseDeviceCommandMsgKey(deviceType, deviceId) + System.currentTimeMillis(); |
| | | redisUtil.set(key, command, 60 * 60 * 24); |
| | | return key; |
| | |
| | | |
| | | public TreeSet<String> getDeviceMsgListKey(SlaveType deviceType, Integer deviceId) { |
| | | String listKey = parseDeviceMsgKey(deviceType, deviceId); |
| | | Set<String> keys = redisUtil.searchKeys(listKey); |
| | | |
| | | TreeSet<String> treeSet = new TreeSet<>(); |
| | | for (String key : keys) { |
| | | treeSet.add(key); |
| | | } |
| | | |
| | | return treeSet; |
| | | } |
| | | |
| | | public TreeSet<String> getDeviceCommandMsgListKey(SlaveType deviceType, Integer deviceId) { |
| | | String listKey = parseDeviceCommandMsgKey(deviceType, deviceId); |
| | | Set<String> keys = redisUtil.searchKeys(listKey); |
| | | |
| | | TreeSet<String> treeSet = new TreeSet<>(); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | } |