#
zjj
17 小时以前 69ba128c58bfb9f5a79481e4997558aafc6f46c6
src/main/java/com/zy/core/action/ShuttleAction.java
@@ -121,9 +121,9 @@
        News.info("[RCS Debug] Execute check command {},{}", shuttleNo, taskNo);
        //检测命令
        int checked = checkCommand(redisCommand, shuttleNo);
        ShuttleCheckCommandResultType checked = checkCommand(redisCommand, shuttleNo);
        News.info("[RCS Debug] Execute check command complete {},{}", shuttleNo, taskNo);
        if (checked == 0) {
        if (checked.equals(ShuttleCheckCommandResultType.FAIL)) {
            return false;
        }
@@ -140,7 +140,7 @@
        //取出命令
        ShuttleCommand command = null;
        if (checked == 1) {
        if (checked.equals(ShuttleCheckCommandResultType.SUCCESS)) {
            //非连续指令,需要检测上一条指令是否完成
            if (commandStep > 0) {
                ShuttleCommand lastCommand = commands.get(commandStep - 1);
@@ -150,7 +150,7 @@
            }
            command = commands.get(commandStep);
        } else if (checked == 2) {
        } else if (checked.equals(ShuttleCheckCommandResultType.SUCCESS_GO)) {
            //连续指令直接取数据
            command = commands.get(commandStep);
        }
@@ -185,7 +185,7 @@
                return false;//申请失败
            }
            if (checked == 2) {
            if (checked.equals(ShuttleCheckCommandResultType.SUCCESS_GO)) {
                nodes.remove(0);
            }
@@ -240,38 +240,40 @@
     * 检测命令
     * 0:未通过 1:通过 2:通过且可提前下发指令
     */
    private int checkCommand(ShuttleRedisCommand redisCommand, Integer shuttleNo) {
    private ShuttleCheckCommandResultType checkCommand(ShuttleRedisCommand redisCommand, Integer shuttleNo) {
        TrafficControlThread trafficControlThread = (TrafficControlThread) SlaveConnection.get(SlaveType.TrafficControl, 1);
        if(trafficControlThread == null){
            return 0;
            return ShuttleCheckCommandResultType.FAIL;
        }
        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
        if (shuttleThread == null) {
            return 0;
            return ShuttleCheckCommandResultType.FAIL;
        }
        ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
        if (shuttleProtocol == null) {
            return 0;
            return ShuttleCheckCommandResultType.FAIL;
        }
        int commandStep = redisCommand.getCommandStep();
        if (commandStep == 0) {
            return 1;//第一条命令无需检测
            return ShuttleCheckCommandResultType.SUCCESS;//第一条命令无需检测
        }
        ShuttleAssignCommand assignCommand = redisCommand.getAssignCommand();
        List<ShuttleCommand> commands = assignCommand.getCommands();
        if (commands.isEmpty()) {
            return 0;
            return ShuttleCheckCommandResultType.FAIL;
        }
        boolean supportContinuously = false;
        int checkIdx = commandStep - 2;
        if (checkIdx < 0) {
            supportContinuously = true;
            checkIdx = commandStep - 1;
        }
        ShuttleCommand last2Command = commands.get(checkIdx);
        if(last2Command.getComplete()){
            supportContinuously = true;
@@ -289,18 +291,18 @@
                //小车移动连续下发指令
                if (assignCommand.getShuttleMoveCommandsContinuously()) {
                    if (!supportContinuously) {
                        return 0;
                        return ShuttleCheckCommandResultType.FAIL;
                    }
                    //移动指令
                    if(lastCommand.getMode() != ShuttleCommandModeType.MOVE.id) {
                        return 0;
                        return ShuttleCheckCommandResultType.FAIL;
                    }
                    List<NavigateNode> nodes = lastCommand.getNodes();
                    NavigateNode startNode = nodes.get(0);
                    if (!startNode.getLinePartAllowGo()) {//直线段部分,允许直接行走
                        return 0;
                        return ShuttleCheckCommandResultType.FAIL;
                    }
                    //直线段数据标识
@@ -310,23 +312,23 @@
                        //取指令
                        ShuttleCommand currentCommand = commands.get(commandStep);
                        if(currentCommand.getMode() != ShuttleCommandModeType.MOVE.id) {
                            return 0;
                            return ShuttleCheckCommandResultType.FAIL;
                        }
                        List<NavigateNode> currentNodes = currentCommand.getNodes();
                        NavigateNode currentStartNode = currentNodes.get(0);
                        if(!currentStartNode.getLinePartAllowGo()) {//直线段部分,允许直接行走
                            return 0;
                            return ShuttleCheckCommandResultType.FAIL;
                        }
                        if(currentStartNode.getLinePartFlag().equals(linePartFlag)) {
                            //数据标识一致
                            return 2;//允许小车移动连续下发指令
                            return ShuttleCheckCommandResultType.SUCCESS_GO;//允许小车移动连续下发指令
                        }
                    }
                }
                return 0;
                return ShuttleCheckCommandResultType.FAIL;
            }
        }
@@ -369,10 +371,10 @@
            //删除redis
            redisUtil.del(RedisKeyType.SHUTTLE_WORK_FLAG.key + redisCommand.getWrkNo());
            return 0;//禁止再下发命令
            return ShuttleCheckCommandResultType.FAIL;//禁止再下发命令
        }
        return 1;
        return ShuttleCheckCommandResultType.SUCCESS;
    }
    //检测更新命令完成
@@ -563,7 +565,7 @@
            return;
        }
        if (shuttleThread.isRequireCharge()) {
        if (!shuttleThread.isRequireCharge().equals(ShuttleRequireChargeType.NONE)) {
            return;
        }
@@ -705,378 +707,60 @@
        }
    }
    public synchronized void demoModeRunLoc(Integer shuttleNo) {
        Config demoModeRunLocConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "demoModeRunLoc"));
        if (demoModeRunLocConfig == null) {
            return;
        }
        if (!demoModeRunLocConfig.getValue().equals("Y")) {
            return;
        }
        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
        if (shuttleThread == null) {
            return;
        }
        ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
        if (shuttleProtocol == null) {
            return;
        }
        if (!shuttleThread.isIdle()) {
            return;
        }
        LocMast targetLoc = null;
        EntityWrapper<LocMast> wrapper = new EntityWrapper<>();
        wrapper.eq("lev1", Utils.getLev(shuttleProtocol.getCurrentLocNo()));
        wrapper.notIn("loc_sts", "X");
        wrapper.isNull("loc_type");
        wrapper.last("ORDER BY RAND() LIMIT 1");
        for (int i = 0; i < 3; i++) {
            LocMast locMast = locMastService.selectOne(wrapper);
            if(locMast == null) {
                continue;
            }
            targetLoc = locMast;
            break;
        }
        if(targetLoc == null) {
            return;
        }
        boolean result = shuttleDispatchUtils.dispatchShuttle(null, targetLoc.getLocNo(), shuttleProtocol.getShuttleNo());
        if (result) {
            targetLoc.setLocType("Y");
            locMastService.updateById(targetLoc);
        }
    }
    public synchronized boolean clearPath(Integer shuttleNo) {
        return navigateMapUtils.clearPath(shuttleNo);
    }
//    //跑库程序
//    public synchronized void moveLoc(Integer shuttleNo) {
//        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
//        if (shuttleThread == null) {
//            return;
//        }
//        ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(false);
//        if (shuttleProtocol == null) {
//            return;
//        }
//
//        //小车开启跑库模式
//        if (!shuttleProtocol.getMoveLoc()) {
//            return;
//        }
//
//        //小车空闲
//        if (!shuttleThread.isIdle()) {
//            return;
//        }
//
//        int lev = Utils.getLev(shuttleProtocol.getCurrentLocNo());//小车当前楼层
//
//        if (shuttleProtocol.getMoveType() == 0) {//跑轨道
//            //根据地图方向决定跑x或y
//            Config config = configService.selectOne(new EntityWrapper<Config>()
//                    .eq("code", "direction_map")
//                    .eq("status", 1));
//            if (config == null) {
//                //跑库结束
//                shuttleProtocol.setMoveLoc(false);
//                shuttleProtocol.setMoveType(0);
//                shuttleProtocol.setXStart(0);
//                shuttleProtocol.setXTarget(0);
//                shuttleProtocol.setXCurrent(0);
//                shuttleProtocol.setYStart(0);
//                shuttleProtocol.setYTarget(0);
//                shuttleProtocol.setYCurrent(0);
//                return;
//            }
//            String direction = config.getValue();
//
//            if (direction.equals("y")) {//跑x轴方向,跑完x轴再切换y轴
//                ArrayList<String> locs = new ArrayList<>();
//                for (int i = shuttleProtocol.getXCurrent(); i <= shuttleProtocol.getXTarget(); i++) {
//                    String locNo = Utils.getLocNo(i, shuttleProtocol.getYCurrent(), lev);
//                    locs.add(locNo);
//                }
//
//                List<LocMast> locList = locMastService.selectList(new EntityWrapper<LocMast>()
//                        .eq("loc_sts", LocStsType.O.toString())
//                        .in("loc_no", locs));
//                if (locList.isEmpty()) {
//                    //空库位
//                    shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);
//                    return;
//                }
//
//                LocMast start = locList.get(0);
//                LocMast target = locList.get(locList.size() - 1);
//                //判断小车是否在起点位置
//                if (!shuttleProtocol.getCurrentLocNo().equals(start.getLocNo())) {//不在起点位置,调度去起点位置
//                    shuttleDispatcher.generateMoveTask(device, start.getLocNo());
//                }else {
//                    //在起点位置,调度去目标位置
//                    Task task = shuttleDispatcher.generateMoveTask(device, target.getLocNo());
//                    if (task != null) {
//                        shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);//切换y轴
//                    }
//
//                    if(shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) {
//                        //y轴也跑完了,结束跑库
//                        shuttleProtocol.setMoveLoc(false);
//                        shuttleProtocol.setMoveType(0);
//                        shuttleProtocol.setXStart(0);
//                        shuttleProtocol.setXTarget(0);
//                        shuttleProtocol.setXCurrent(0);
//                        shuttleProtocol.setYStart(0);
//                        shuttleProtocol.setYTarget(0);
//                        shuttleProtocol.setYCurrent(0);
//                        return;
//                    }
//                }
//            }else {//跑y轴方向,跑完y轴再切换x轴
//                ArrayList<String> locs = new ArrayList<>();
//                for (int i = shuttleProtocol.getYCurrent(); i <= shuttleProtocol.getYTarget(); i++) {
//                    String locNo = Utils.getLocNo(shuttleProtocol.getXCurrent(), i, lev);
//                    locs.add(locNo);
//                }
//
//                List<Loc> locList = locService.list(new LambdaQueryWrapper<Loc>()
//                        .eq(Loc::getLocSts, LocStsType.O.val())
//                        .in(Loc::getLocNo, locs));
//                if (locList.isEmpty()) {
//                    //空库位
//                    shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
//                    return;
//                }
//
//                Loc start = locList.get(0);
//                Loc target = locList.get(locList.size() - 1);
//                //判断小车是否在起点位置
//                if (!shuttleProtocol.getCurrentLocNo().equals(start.getLocNo())) {//不在起点位置,调度去起点位置
//                    shuttleDispatcher.generateMoveTask(device, start.getLocNo());
//                }else {
//                    //在起点位置,调度去目标位置
//                    Task task = shuttleDispatcher.generateMoveTask(device, target.getLocNo());
//                    if (task != null) {
//                        shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);//切换x轴
//                    }
//
//                    if(shuttleProtocol.getXCurrent() > shuttleProtocol.getXTarget()) {
//                        //y轴也跑完了,结束跑库
//                        shuttleProtocol.setMoveLoc(false);
//                        shuttleProtocol.setMoveType(0);
//                        shuttleProtocol.setXStart(0);
//                        shuttleProtocol.setXTarget(0);
//                        shuttleProtocol.setXCurrent(0);
//                        shuttleProtocol.setYStart(0);
//                        shuttleProtocol.setYTarget(0);
//                        shuttleProtocol.setYCurrent(0);
//                        return;
//                    }
//                }
//            }
//
//        } else if (shuttleProtocol.getMoveType() == 1) {//跑库位
//            //根据地图方向决定跑x或y
//            Dict dict = dictService.getOne(new LambdaQueryWrapper<Dict>()
//                    .eq(Dict::getFlag, "direction_map")
//                    .eq(Dict::getStatus, 1));
//            if (dict == null) {
//                //跑库结束
//                shuttleProtocol.setMoveLoc(false);
//                shuttleProtocol.setMoveType(0);
//                shuttleProtocol.setXStart(0);
//                shuttleProtocol.setXTarget(0);
//                shuttleProtocol.setXCurrent(0);
//                shuttleProtocol.setYStart(0);
//                shuttleProtocol.setYTarget(0);
//                shuttleProtocol.setYCurrent(0);
//                return;
//            }
//            String direction = dict.getValue();
//
//            if (direction.equals("y")) {//跑x轴方向,跑完x轴再切换y轴
//                Integer xCurrent = shuttleProtocol.getXCurrent();
//
//                //获取待跑库位号
//                String locNo = Utils.getLocNo(xCurrent, shuttleProtocol.getYCurrent(), lev);
//                Loc target = locService.getOne(new LambdaQueryWrapper<Loc>()
//                        .eq(Loc::getLocNo, locNo)
//                        .eq(Loc::getLocSts, LocStsType.O.val())
//                        .eq(Loc::getHostId, device.getHostId()));
//                if (target == null || shuttleProtocol.getCurrentLocNo().equals(locNo)) {//库位不存在或小车已在当前位置
//                    shuttleProtocol.setXCurrent(xCurrent + 1);
//                    if (shuttleProtocol.getXCurrent() > shuttleProtocol.getXTarget()) {
//                        //x轴跑完,切换y轴
//                        shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());
//                        shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);
//
//                        if(shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) {
//                            //y轴也跑完了,结束跑库
//                            shuttleProtocol.setMoveLoc(false);
//                            shuttleProtocol.setMoveType(0);
//                            shuttleProtocol.setXStart(0);
//                            shuttleProtocol.setXTarget(0);
//                            shuttleProtocol.setXCurrent(0);
//                            shuttleProtocol.setYStart(0);
//                            shuttleProtocol.setYTarget(0);
//                            shuttleProtocol.setYCurrent(0);
//                            return;
//                        }
//                    }
//                    return;
//                }
//
//                //调度去库位
//                Task task = shuttleDispatcher.generateMoveTask(device, locNo);
//                if (task == null) {
//                    return;//调度失败
//                }
//
//                shuttleProtocol.setXCurrent(xCurrent + 1);
//                if (shuttleProtocol.getXCurrent() > shuttleProtocol.getXTarget()) {
//                    //x轴跑完,切换y轴
//                    shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());
//                    shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);
//
//                    if(shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) {
//                        //y轴也跑完了,结束跑库
//                        shuttleProtocol.setMoveLoc(false);
//                        shuttleProtocol.setMoveType(0);
//                        shuttleProtocol.setXStart(0);
//                        shuttleProtocol.setXTarget(0);
//                        shuttleProtocol.setXCurrent(0);
//                        shuttleProtocol.setYStart(0);
//                        shuttleProtocol.setYTarget(0);
//                        shuttleProtocol.setYCurrent(0);
//                        return;
//                    }
//                }
//
//            }else {//跑y轴方向,跑完y轴再切换x轴
//                Integer yCurrent = shuttleProtocol.getYCurrent();
//
//                //获取待跑库位号
//                String locNo = Utils.getLocNo(shuttleProtocol.getXCurrent(), yCurrent, lev);
//                Loc target = locService.getOne(new LambdaQueryWrapper<Loc>()
//                        .eq(Loc::getLocNo, locNo)
//                        .eq(Loc::getLocSts, LocStsType.O.val())
//                        .eq(Loc::getHostId, device.getHostId()));
//                if (target == null || shuttleProtocol.getCurrentLocNo().equals(locNo)) {//库位不存在或小车已在当前位置
//                    shuttleProtocol.setYCurrent(yCurrent + 1);
//                    if (shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) {
//                        //y轴跑完,切换x轴
//                        shuttleProtocol.setYCurrent(shuttleProtocol.getYStart());
//                        shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
//
//                        if(shuttleProtocol.getXCurrent() > shuttleProtocol.getXTarget()) {
//                            //x轴也跑完了,结束跑库
//                            shuttleProtocol.setMoveLoc(false);
//                            shuttleProtocol.setMoveType(0);
//                            shuttleProtocol.setXStart(0);
//                            shuttleProtocol.setXTarget(0);
//                            shuttleProtocol.setXCurrent(0);
//                            shuttleProtocol.setYStart(0);
//                            shuttleProtocol.setYTarget(0);
//                            shuttleProtocol.setYCurrent(0);
//                            return;
//                        }
//                    }
//                    return;
//                }
//
//                //调度去库位
//                Task task = shuttleDispatcher.generateMoveTask(device, locNo);
//                if (task == null) {
//                    return;//调度失败
//                }
//
//                shuttleProtocol.setYCurrent(yCurrent + 1);
//                if (shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) {
//                    //y轴跑完,切换x轴
//                    shuttleProtocol.setYCurrent(shuttleProtocol.getYStart());
//                    shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
//
//                    if(shuttleProtocol.getXCurrent() > shuttleProtocol.getXTarget()) {
//                        //x轴也跑完了,结束跑库
//                        shuttleProtocol.setMoveLoc(false);
//                        shuttleProtocol.setMoveType(0);
//                        shuttleProtocol.setXStart(0);
//                        shuttleProtocol.setXTarget(0);
//                        shuttleProtocol.setXCurrent(0);
//                        shuttleProtocol.setYStart(0);
//                        shuttleProtocol.setYTarget(0);
//                        shuttleProtocol.setYCurrent(0);
//                        return;
//                    }
//                }
//
//            }
//        } else if (shuttleProtocol.getMoveType() == 2) {//母轨道循环跑
//            Integer xCurrent = shuttleProtocol.getXCurrent();
//            Integer yCurrent = shuttleProtocol.getYCurrent();
//
//            String locNo = Utils.getLocNo(xCurrent, yCurrent, lev);
//            //调度去目标位置
//            if (shuttleProtocol.getCurrentLocNo().equals(locNo)) {
//                if (yCurrent.equals(shuttleProtocol.getYStart())) {
//                    shuttleProtocol.setYCurrent(shuttleProtocol.getYTarget());//小车和目标位置一致,切换库位
//                } else {
//                    shuttleProtocol.setYCurrent(shuttleProtocol.getYStart());//小车和目标位置一致,切换库位
//                }
//            } else {
//                Task result = shuttleDispatcher.generateMoveTask(device, locNo);
//                if (result != null) {//调度成功
//                    if (yCurrent.equals(shuttleProtocol.getYStart())) {
//                        shuttleProtocol.setYCurrent(shuttleProtocol.getYTarget());//切换库位
//                    } else {
//                        shuttleProtocol.setYCurrent(shuttleProtocol.getYStart());//切换库位
//                    }
//                }
//            }
//        } else if (shuttleProtocol.getMoveType() == 3) {//子轨道循环跑
//            Integer xCurrent = shuttleProtocol.getXCurrent();
//            Integer yCurrent = shuttleProtocol.getYCurrent();
//
//            String locNo = Utils.getLocNo(xCurrent, yCurrent, lev);
//            //调度去目标位置
//            if (shuttleProtocol.getCurrentLocNo().equals(locNo)) {
//                if (xCurrent.equals(shuttleProtocol.getXStart())) {
//                    shuttleProtocol.setXCurrent(shuttleProtocol.getXTarget());//小车和目标位置一致,切换库位
//                } else {
//                    shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());//小车和目标位置一致,切换库位
//                }
//            } else {
//                Task result = shuttleDispatcher.generateMoveTask(device, locNo);
//                if (result != null) {//调度成功
//                    if (xCurrent.equals(shuttleProtocol.getXStart())) {
//                        shuttleProtocol.setXCurrent(shuttleProtocol.getXTarget());//切换库位
//                    } else {
//                        shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());//切换库位
//                    }
//                }
//            }
//        } else if (shuttleProtocol.getMoveType() == 4) {//取放货
//            Integer xCurrent = shuttleProtocol.getXCurrent();
//            if (xCurrent > shuttleProtocol.getXTarget()) {//当X值大于X目标值
//                shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());
//                shuttleProtocol.setYCurrent(shuttleProtocol.getYStart());
//                return;
//            }
//
//            //判断x轴货位是否放满
//            boolean flag = true;
//            for (Loc loc : locService.list(new LambdaQueryWrapper<Loc>()
//                    .eq(Loc::getHostId, device.getHostId())
//                    .eq(Loc::getRow, xCurrent)
//                    .ge(Loc::getBay, shuttleProtocol.getYStart())
//                    .le(Loc::getBay, shuttleProtocol.getYTarget()))) {
//                if (loc.getLocSts() != LocStsType.F.val()) {
//                    flag = false;//未满
//                    break;
//                }
//            }
//            if (flag) {
//                shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
//                return;
//            }
//
//            //搜索有货库位
//            List<Loc> list = locService.list(new LambdaQueryWrapper<Loc>()
//                    .eq(Loc::getLocSts, LocStsType.F.val())
//                    .eq(Loc::getHostId, device.getHostId())
//                    .notIn(Loc::getRow, xCurrent)
//                    .eq(Loc::getStatus, 1));
//            if (list.isEmpty()) {
//                return;
//            }
//
//            Loc start = list.get(0);
//
//            List<Loc> locList = locService.list(new LambdaQueryWrapper<Loc>()
//                    .eq(Loc::getHostId, device.getHostId())
//                    .eq(Loc::getStatus, 1)
//                    .eq(Loc::getLocSts, LocStsType.O.val())
//                    .eq(Loc::getRow, xCurrent)
//                    .orderByDesc(Loc::getBay)
//                    .orderByAsc(Loc::getRow));
//            if (locList.isEmpty()) {
//                return;
//            }
//
//            Loc target = locList.get(0);
//            if (target == null) {
//                return;
//            }
//
//            //调度去目标位置
//            if (!shuttleProtocol.getCurrentLocNo().equals(target.getLocNo())) {
//                Task task = shuttleDispatcher.generateManuaTakeMoveTask(device, start.getLocNo(), target.getLocNo());
////                if(task != null) {//调度成功
////                    shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
////                }
//            }
//        }
//    }
    private CommandResponse write(ShuttleCommand command, Integer shuttleNo) {
        CommandResponse response = new CommandResponse(false);