#
Junjie
2 天以前 73ce8bebcc5d14f3fb62a19ee677abfcdfc776b4
src/main/java/com/zy/core/thread/impl/NyShuttleThread.java
@@ -9,10 +9,8 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zy.asrs.entity.BasShuttle;
import com.zy.asrs.entity.DeviceConfig;
import com.zy.asrs.entity.DeviceDataLog;
import com.zy.asrs.entity.LocMast;
import com.zy.asrs.service.BasShuttleService;
import com.zy.asrs.service.DeviceDataLogService;
import com.zy.asrs.service.LocMastService;
import com.zy.asrs.utils.Utils;
import com.zy.common.ExecuteSupport;
@@ -25,7 +23,6 @@
import com.zy.core.News;
import com.zy.core.model.DeviceCommandMsgModel;
import com.zy.core.utils.DeviceMsgUtils;
import com.zy.core.action.ShuttleAction;
import com.zy.core.cache.OutputQueue;
import com.zy.core.enums.*;
import com.zy.core.model.CommandResponse;
@@ -88,78 +85,38 @@
        });
        readThread.start();
        //设备执行
        Thread executeThread = new Thread(() -> {
            while (true) {
                try {
                    ShuttleAction shuttleAction = null;
                    try {
                        shuttleAction = SpringUtils.getBean(ShuttleAction.class);
                    }catch (Exception e){
                        continue;
                    }
                    if (shuttleAction == null) {
                        continue;
                    }
                    Object object = redisUtil.get(RedisKeyType.SHUTTLE_FLAG.key + deviceConfig.getDeviceNo());
                    if (object == null) {
                        continue;
                    }
                    Integer taskNo = Integer.valueOf(String.valueOf(object));
                    if (taskNo != 0) {
                        //存在任务需要执行
                        boolean result = shuttleAction.executeWork(deviceConfig.getDeviceNo(), taskNo);
                    }
                    Thread.sleep(100);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        executeThread.start();
//        //其他任务
//        Thread otherThread = new Thread(() -> {
//        //设备执行
//        Thread executeThread = new Thread(() -> {
//            while (true) {
//                try {
//                    saveLog();//保存数据
//                    ShuttleAction shuttleAction = null;
//                    try {
//                        shuttleAction = SpringUtils.getBean(ShuttleAction.class);
//                    }catch (Exception e){
//                        continue;
//                    }
//
//                    if (shuttleAction == null) {
//                        continue;
//                    }
//
//                    Object object = redisUtil.get(RedisKeyType.SHUTTLE_FLAG.key + deviceConfig.getDeviceNo());
//                    if (object == null) {
//                        continue;
//                    }
//
//                    Integer taskNo = Integer.valueOf(String.valueOf(object));
//                    if (taskNo != 0) {
//                        //存在任务需要执行
//                        boolean result = shuttleAction.executeWork(deviceConfig.getDeviceNo(), taskNo);
//                    }
//                    Thread.sleep(100);
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
//        });
//        otherThread.start();
    }
    private void saveLog() {
        if (shuttleProtocol == null) {
            return;
        }
        if (System.currentTimeMillis() - shuttleProtocol.getDeviceDataLog() > 1000 * 5) {
            if (this.originDeviceData != null) {
                //采集时间超过5s,保存一次数据记录
                //保存数据记录
                DeviceDataLogService deviceDataLogService = SpringUtils.getBean(DeviceDataLogService.class);
                if (deviceDataLogService == null) {
                    return;
                }
                DeviceDataLog deviceDataLog = new DeviceDataLog();
                deviceDataLog.setOriginData(JSON.toJSONString(this.originDeviceData));
                deviceDataLog.setWcsData(JSON.toJSONString(shuttleProtocol));
                deviceDataLog.setType(String.valueOf(SlaveType.Shuttle));
                deviceDataLog.setDeviceNo(deviceConfig.getDeviceNo());
                deviceDataLog.setCreateTime(new Date());
                deviceDataLogService.insert(deviceDataLog);
                //更新采集时间
                shuttleProtocol.setDeviceDataLog(System.currentTimeMillis());
                OutputQueue.SHUTTLE.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), deviceConfig.getDeviceNo()));
            }
        }
//        executeThread.start();
    }
    private void listenMessageFromRedis() {
@@ -775,7 +732,7 @@
                //将路径锁与小车路径进行匹配
                ArrayList<NavigateNode> tmp = new ArrayList<>();
                //检测路径是否被锁定
                int[][] map = navigateMapData.getDataFromRedis(lev, NavigationMapType.DFX.id, null, null);
                int[][] map = navigateMapData.getDataFromRedis(lev, NavigationMapType.getDfxWithDevice(), null, null);
                for (NavigateNode node : path) {
                    if(map[node.getX()][node.getY()] == -999) {
                        tmp.add(node);
@@ -861,6 +818,11 @@
        String msg = News.replace(format, arguments);
        shuttleProtocol.setSystemMsg(msg);
        return true;
    }
    @Override
    public void updateDeviceDataLogTime(long time) {
        shuttleProtocol.setDeviceDataLog(time);
    }
    @Override
@@ -1195,6 +1157,11 @@
        return new int[]{data.getInteger("y"), data.getInteger("x"), z};
    }
    @Override
    public Object getOriginDeviceData() {
        return this.originDeviceData;
    }
    @Data
    private class InnerSuhttleExtend {