#
Junjie
14 小时以前 6e02d92c3b9c240fa78a343b67ddf0db12d840e6
src/main/java/com/zy/core/action/ShuttleAction.java
@@ -119,8 +119,10 @@
            return false;
        }
        News.info("[RCS Debug] Execute check command {},{}", shuttleNo, taskNo);
        //检测命令
        int checked = checkCommand(redisCommand, shuttleNo);
        News.info("[RCS Debug] Execute check command complete {},{}", shuttleNo, taskNo);
        if (checked == 0) {
            return false;
        }
@@ -165,18 +167,23 @@
            }
            List<NavigateNode> nodes = JSON.parseArray(JSON.toJSONString(command.getNodes()), NavigateNode.class);
            //申请管制
            applyTrafficControl(commands, nodes, shuttleNo, taskNo);
            Object object = redisUtil.get(RedisKeyType.TRAFFIC_CONTROL_LOCK_APPLY.key + shuttleNo);
            if (object == null) {
                //申请管制
                News.info("[RCS Debug] Execute apply control {},{}", shuttleNo, taskNo);
                redisUtil.set(RedisKeyType.TRAFFIC_CONTROL_LOCK_APPLY.key + shuttleNo, "lock", 10);
                applyTrafficControl(commands, nodes, shuttleNo, taskNo);
                News.info("[RCS Debug] Execute apply control complete {},{}", shuttleNo, taskNo);
            }
            News.info("[RCS Debug] Execute query control {},{}", shuttleNo, taskNo);
            //查询管制
            boolean apply = queryTrafficControl(shuttleNo, taskNo);
            News.info("[RCS Debug] Execute query control complete {},{}", shuttleNo, taskNo);
            if(!apply){
                return false;//申请失败
            }
//            //检测路径是否冲突
//            int conflict = searchShuttlePathConflict(nodes, shuttleNo);
//            if(conflict == 2){
//                return false;//检测后有冲突
//            }
            if (checked == 2) {
                nodes.remove(0);
@@ -191,8 +198,10 @@
            }
        }
        News.info("[RCS Debug] Execute send command {},{}", shuttleNo, taskNo);
        // 下发命令
        CommandResponse response = write(command, shuttleNo);
        News.info("[RCS Debug] Execute send command complete {},{}", shuttleNo, taskNo);
        //保存命令日志
        BasShuttleOpt basShuttleOpt = new BasShuttleOpt();
@@ -328,16 +337,24 @@
            // 系统任务
            if (assignCommand.getAuto()) {
                if (!assignCommand.getCharge()) {
                    //对主线程抛出等待确认状态waiting
                    shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.WAITING);
                } else {
                    shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.CHARGING_WAITING);
                if (assignCommand.getTaskMode() == ShuttleTaskModeType.UPDATE_LOCATION.id) {//更新坐标无需等待确认
                    //直接复位空闲状态
                    shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
                    //任务号清零
                    shuttleThread.setSyncTaskNo(0);
                    //标记复位
                    shuttleThread.setPakMk(true);
                    News.info("四向穿梭车更新坐标任务执行完成,穿梭车号={},任务数据={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(endCommand));
                }else {
                    if (!assignCommand.getCharge()) {
                        //对主线程抛出等待确认状态waiting
                        shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.WAITING);
                    } else {
                        shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.CHARGING_WAITING);
                    }
                    News.info("四向穿梭车任务执行下发完成等待执行结束,穿梭车号={},任务数据={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(endCommand));
                }
                News.info("四向穿梭车任务执行下发完成等待执行结束,穿梭车号={},任务数据={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(endCommand));
                // 手动任务
            } else {
            } else {// 手动任务
                //手动模式不抛出等待状态,直接复位空闲状态
                shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
                //任务号清零
@@ -348,7 +365,8 @@
            }
            //申请取消管制
            trafficControlThread.cancelTrafficControl(shuttleNo, shuttleProtocol.getTaskNo());
            cancelTrafficControl(shuttleNo, shuttleProtocol.getTaskNo());
            //删除redis
            redisUtil.del(RedisKeyType.SHUTTLE_WORK_FLAG.key + redisCommand.getWrkNo());
            return 0;//禁止再下发命令
@@ -415,7 +433,9 @@
                return false;
            }
            //上报交管
            News.info("[RCS Debug] Execute check command report traffic {},{}", shuttleNo, shuttleProtocol.getTaskNo());
            trafficControlThread.trafficReport(command.getNodesDeepCopy(), shuttleNo, shuttleProtocol.getTaskNo());
            News.info("[RCS Debug] Execute check command report traffic complete {},{}", shuttleNo, shuttleProtocol.getTaskNo());
            String currentLocNo = shuttleProtocol.getCurrentLocNo();
            if (currentLocNo == null) {
@@ -497,103 +517,20 @@
    //查询是否申请管制成功
    public boolean queryTrafficControl(Integer shuttleNo, Integer taskNo) {
        TrafficControlThread trafficControlThread = (TrafficControlThread) SlaveConnection.get(SlaveType.TrafficControl, 1);
        if (trafficControlThread == null) {
        Object object = redisUtil.get(RedisKeyType.TRAFFIC_CONTROL_SUCCESS_APPLY.key + shuttleNo + "_" + taskNo);
        if (object == null) {
            return false;
        }
        TrafficControlDataModel trafficControlDataModel = trafficControlThread.queryTrafficControl(shuttleNo, taskNo);
        if (trafficControlDataModel == null) {
            return false;
        }
        return true;
    }
//    /**
//     * 搜索小车路径是否存在冲突
//     * 0:未检测 1:检测无冲突 2:检测有冲突
//     */
//    public int searchShuttlePathConflict(List<NavigateNode> nodeList, Integer shuttleNo) {
//        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
//        if (shuttleThread == null) {
//            return 0;
//        }
//
//        ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
//        if (shuttleProtocol == null) {
//            return 0;
//        }
//
//        int lev = Utils.getLev(shuttleProtocol.getCurrentLocNo());
//
//        TrafficControlThread trafficControlThread = (TrafficControlThread) SlaveConnection.get(SlaveType.TrafficControl, 1);
//        if (trafficControlThread == null) {
//            return 2;
//        }
//        HashMap<String, List<Integer>> nodeMap = trafficControlThread.getNodesMapByLev(lev);
//        if (nodeMap == null || nodeMap.isEmpty()) {
//            return 2;
//        }
//
//        List<String> conflictLocList = new ArrayList<>();
//        for (NavigateNode node : nodeList) {
//            String locNo = Utils.getLocNo(node.getX(), node.getY(), lev);
//            if(!nodeMap.containsKey(locNo)) {
//                return 2;
//            }
//
//            List<Integer> shuttleNos = nodeMap.get(locNo);
//            if (shuttleNos.size() > 1) {
//                //路径存在多车,冲突
//                conflictLocList.add(locNo);
//            }
//        }
//
//        if (conflictLocList.isEmpty()) {
//            //无冲突,解除交通管制
//            shuttleThread.setTrafficControl(false, null);
//            return 1;//检测后无冲突
//        }
//
//        //路径存在冲突,检测可执行车辆是否为当前小车
//        //上报小车状态-交通管制中
//        shuttleThread.setTrafficControl(true, nodeList);
//
//        HashMap<String, Integer> deviceMap = trafficControlThread.getDeviceMap();
//        if(deviceMap == null) {
//            return 2;
//        }
//
//        boolean detected = false;
////            for (Map.Entry<String, Integer> entry : deviceMap.entrySet()) {
////                List<String> mainList = JSON.parseArray(entry.getKey(), String.class);
////                Integer device = entry.getValue();
////                if(result) {
////                    //判断管制车辆是否匹配
////                    if(shuttleNo.equals(device)) {
////                        detected = true;
////                        break;
////                    }
////                }
////            }
//
//        for (Map.Entry<String, Integer> entry : deviceMap.entrySet()) {
//            String key = entry.getKey();
//            Integer value = entry.getValue();
//            if(shuttleNo.equals(value)) {
//                //判断管制车辆是否匹配
//                detected = true;
//                break;
//            }
//        }
//
//        if (detected) {
//            return 1;//检测后无冲突,交通管制已允许此小车运行
//        }
//
//        return 2;//检测后有冲突
//    }
    public boolean cancelTrafficControl(Integer shuttleNo, Integer taskNo) {
        TrafficControlDataModel model = new TrafficControlDataModel();
        model.setShuttleNo(shuttleNo);
        model.setTaskNo(taskNo);
        redisUtil.set(RedisKeyType.TRAFFIC_CONTROL_CANCEL_LIST.key + shuttleNo + "_" + taskNo, model);
        return true;
    }
    //演示模式
    public synchronized void demo(Integer shuttleNo) {
@@ -766,6 +703,10 @@
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public synchronized boolean clearPath(Integer shuttleNo) {
        return navigateMapUtils.clearPath(shuttleNo);
    }
//    //跑库程序
@@ -1137,7 +1078,7 @@
//        }
//    }
    private synchronized CommandResponse write(ShuttleCommand command, Integer shuttleNo) {
    private CommandResponse write(ShuttleCommand command, Integer shuttleNo) {
        CommandResponse response = new CommandResponse(false);
        if (null == command) {
            News.error("四向穿梭车写入命令为空");