#
Junjie
2025-07-03 456273f11d75782e676d43763f0f0601ea5c37f8
src/main/java/com/zy/core/Utils/DeviceMsgUtils.java
@@ -23,6 +23,21 @@
    @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()) {
@@ -53,7 +68,17 @@
        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;
@@ -61,6 +86,18 @@
    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<>();
@@ -99,4 +136,5 @@
        }
    }
}