#
zhou zhou
4 天以前 1cb3797093cd4d5898860a49bb9dd624b482e6ce
src/main/java/com/zy/core/utils/DeviceMsgUtils.java
@@ -1,11 +1,13 @@
package com.zy.core.utils;
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;
@@ -20,16 +22,25 @@
    @Value("${deviceMsgConfig.destroyAfterReading}")
    private boolean destroyAfterReading;
    @Value("${deviceMsgConfig.gatewayId}")
    private Integer gatewayId;
    @Autowired
    private RedisUtil redisUtil;
    public String getDeviceConfig() {
    public List<DeviceConfig> getDeviceConfig() {
        List<DeviceConfig> list = new ArrayList<>();
        Object obj = redisUtil.get(RedisKeyType.DEVICE_CONFIG.key);
        if(null == obj){
            return null;
            return list;
        }
        return obj.toString();
        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) {
@@ -79,13 +90,13 @@
    public String sendDeviceMsg(SlaveType deviceType, Integer deviceId, DeviceMsgModel deviceMsgModel) {
        String key = parseDeviceMsgKey(deviceType, deviceId) + System.currentTimeMillis();
        redisUtil.set(key, deviceMsgModel, 60 * 60 * 24);
        redisUtil.set(key, deviceMsgModel, 60 * 60);
        return key;
    }
    public String sendDeviceCommand(SlaveType deviceType, Integer deviceId, DeviceCommandMsgModel command) {
        String key = parseDeviceCommandMsgKey(deviceType, deviceId) + System.currentTimeMillis();
        redisUtil.set(key, command, 60 * 60 * 24);
        redisUtil.set(key, command, 60 * 60);
        return key;
    }
@@ -126,6 +137,8 @@
            return RedisKeyType.DEVICE_SHUTTLE_MSG_KEY_.key + deviceId + "_";
        } else if (deviceType.equals(SlaveType.ForkLift)) {
            return RedisKeyType.DEVICE_FORK_LIFT_MSG_KEY_.key + deviceId + "_";
        } else if (deviceType.equals(SlaveType.Lift)) {
            return RedisKeyType.DEVICE_LIFT_MSG_KEY_.key + deviceId + "_";
        }else {
            throw new CoolException("设备类型未定义");
        }
@@ -140,6 +153,8 @@
            return RedisKeyType.DEVICE_SHUTTLE_COMMAND_MSG_KEY.key + deviceId + "_";
        } else if (deviceType.equals(SlaveType.ForkLift)) {
            return RedisKeyType.DEVICE_FORK_LIFT_COMMAND_MSG_KEY.key + deviceId + "_";
        } else if (deviceType.equals(SlaveType.Lift)) {
            return RedisKeyType.DEVICE_LIFT_COMMAND_MSG_KEY.key + deviceId + "_";
        }else {
            throw new CoolException("设备类型未定义");
        }