#
Junjie
4 天以前 456273f11d75782e676d43763f0f0601ea5c37f8
#
2个文件已修改
54 ■■■■■ 已修改文件
src/main/java/com/zy/core/Utils/DeviceMsgUtils.java 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/thread/impl/NyShuttleThread.java 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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 @@
        }
    }
}
src/main/java/com/zy/core/thread/impl/NyShuttleThread.java
@@ -41,7 +41,6 @@
import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.text.MessageFormat;
import java.util.*;
@@ -77,7 +76,7 @@
                    listenMessageFromRedis();
                    listenInit();//监听初始化事件
                    read();
                    Thread.sleep(50);
                    Thread.sleep(100);
                } catch (Exception e) {
                    log.error("ShuttleThread Fail", e);
                }
@@ -257,6 +256,15 @@
                InnerSuhttleExtend extend = new InnerSuhttleExtend();
                shuttleProtocol.setExtend(extend);
            }
            //----------读取四向穿梭车状态-----------
            DeviceMsgUtils deviceMsgUtils = SpringUtils.getBean(DeviceMsgUtils.class);
            NyShuttleHttpCommand readStatusCommand = getReadStatusCommand(slave.getId());
            //指令超过五条,不再下发任务状态请求
            TreeSet<String> deviceCommandMsgListKey = deviceMsgUtils.getDeviceCommandMsgListKey(SlaveType.Shuttle, slave.getId());
            if (deviceCommandMsgListKey.size() < 5) {
                requestCommand(readStatusCommand);//请求状态
            }
            if (this.socketReadResults.isEmpty()) {
@@ -1090,7 +1098,7 @@
            JSONObject data = JSON.parseObject(JSON.toJSONString(httpCommand));
            data.remove("nodes");
            String key = deviceMsgUtils.sendCommand(SlaveType.Shuttle, slave.getId(), data);
            String key = deviceMsgUtils.sendDeviceCommand(SlaveType.Shuttle, slave.getId(), data);
            String requestType = null;
            String taskId = null;