自动化立体仓库 - WCS系统
Junjie
2023-05-10 baed29d667be08051c36c31997117a1ba292d5bc
src/main/java/com/zy/core/thread/ShuttleThread.java
@@ -16,11 +16,9 @@
import com.zy.asrs.service.BasShuttleOptService;
import com.zy.asrs.service.BasShuttleService;
import com.zy.asrs.service.LocMastService;
import com.zy.asrs.utils.Utils;
import com.zy.common.model.NavigateNode;
import com.zy.common.utils.CommonUtils;
import com.zy.common.utils.NavigatePositionConvert;
import com.zy.common.utils.NavigateUtils;
import com.zy.common.utils.RedisUtil;
import com.zy.common.utils.*;
import com.zy.core.News;
import com.zy.core.ThreadHandler;
import com.zy.core.cache.MessageQueue;
@@ -178,7 +176,7 @@
                if (shuttleProtocol.getErrorCode() != 0 && shuttleProtocol.getProtocolStatusType() == ShuttleProtocolStatusType.WORKING) {
                    //出现错误
                    reset(shuttleProtocol.getTaskNo());
                    resetAndTryFix(shuttleProtocol.getTaskNo());
                }
                if(shuttleProtocol.getProtocolStatusType() == ShuttleProtocolStatusType.FIXING
@@ -200,7 +198,7 @@
                //检测是否有提升机锁定标记,有则检测提升机是否到位,是否能走下一步命令
                if (shuttleProtocol.getBusyStatusType() == ShuttleStatusType.IDLE
                        && shuttleProtocol.getTaskNo() != 0) {
                    Object o = redisUtil.get("wrk_no_" + shuttleProtocol.getTaskNo());
                    Object o = redisUtil.get("shuttle_wrk_no_" + shuttleProtocol.getTaskNo());
                    if (o != null) {
                        ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class);
                        if (redisCommand.getLiftSecurityMk()) {
@@ -394,9 +392,11 @@
    //分配任务
    private void assignWork(ShuttleAssignCommand assignCommand) {
        if (!assignCommand.getAuto()) {
            List<NavigateNode> allNode = new ArrayList<>();
            List<ShuttleCommand> commands = new ArrayList<>();
            ShuttleCommand command = new ShuttleCommand();
            LocMastService locMastService = SpringUtils.getBean(LocMastService.class);
            NavigateMapData navigateMapData;
            switch (assignCommand.getTaskMode()) {
                case 1://入库
                case 2://出库
@@ -404,7 +404,12 @@
                    //计算小车起点到中点所需命令
                    LocMast currentLocMast = locMastService.queryByQrCode(shuttleProtocol.getCurrentCode().toString());
                    List<NavigateNode> firstMastResult = NavigateUtils.calc(currentLocMast.getLocNo(), assignCommand.getSourceLocNo(), ShuttleTaskModeType.PAK_IN.id);
                    //所使用的路径进行锁定禁用
                    navigateMapData = new NavigateMapData(Utils.getLev(currentLocMast.getLocNo()));
                    navigateMapData.writeNavigateNodeToRedisMap(firstMastResult, true);////所使用的路径进行锁定禁用
                    if (firstMastResult != null) {
                        allNode.addAll(firstMastResult);//将节点进行保存
                        //获取分段路径
                        ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(firstMastResult);
                        //将每一段路径分成command指令
@@ -466,7 +471,10 @@
                    //计算中点到终点路径
                    List<NavigateNode> secMastResult = NavigateUtils.calc(assignCommand.getSourceLocNo(), assignCommand.getLocNo(), ShuttleTaskModeType.PAK_IN.id);
                    navigateMapData.writeNavigateNodeToRedisMap(firstMastResult, true);////所使用的路径进行锁定禁用
                    if (secMastResult != null) {
                        allNode.addAll(secMastResult);//将节点进行保存
                        //获取分段路径
                        ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(secMastResult);
                        //将每一段路径分成command指令
@@ -590,7 +598,12 @@
                case 14://移动到目标库位
                    LocMast locMast = locMastService.queryByQrCode(shuttleProtocol.getCurrentCode().toString());
                    List<NavigateNode> result = NavigateUtils.calc(locMast.getLocNo(), assignCommand.getLocNo(), ShuttleTaskModeType.PAK_IN.id);
                    //所使用的路径进行锁定禁用
                    navigateMapData = new NavigateMapData(Utils.getLev(locMast.getLocNo()));
                    navigateMapData.writeNavigateNodeToRedisMap(result, true);////所使用的路径进行锁定禁用
                    if (result != null) {
                        allNode.addAll(result);//将节点进行保存
                        //获取分段路径
                        ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(result);
                        //将每一段路径分成command指令
@@ -626,6 +639,7 @@
                default:
            }
            assignCommand.setCommands(commands);
            assignCommand.setNodes(allNode);//当前任务所占用的节点list
        }
        ShuttleRedisCommand redisCommand = new ShuttleRedisCommand();
@@ -638,7 +652,7 @@
        shuttleProtocol.setAssignCommand(assignCommand);
        shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WORKING);
        //任务数据保存到redis
        redisUtil.set("wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(redisCommand));
        redisUtil.set("shuttle_wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(redisCommand));
        //执行下发任务
        executeWork(assignCommand.getTaskNo());
    }
@@ -650,7 +664,7 @@
            return false;
        }
        Object o = redisUtil.get("wrk_no_" + wrkNo);
        Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo);
        if (o == null) {
            return false;
        }
@@ -683,7 +697,7 @@
                    commandStep--;
                    redisCommand.setCommandStep(commandStep);
                    //任务数据保存到redis
                    redisUtil.set("wrk_no_" + wrkNo, JSON.toJSONString(redisCommand));
                    redisUtil.set("shuttle_wrk_no_" + wrkNo, JSON.toJSONString(redisCommand));
                    shuttleProtocol.setPakMk(true);
                    return true;
                }else {
@@ -731,7 +745,7 @@
                errorCommands.remove(0);
                redisCommand.setErrorCommands(errorCommands);
                //任务数据保存到redis
                redisUtil.set("wrk_no_" + wrkNo, JSON.toJSONString(redisCommand));
                redisUtil.set("shuttle_wrk_no_" + wrkNo, JSON.toJSONString(redisCommand));
                return true;
            }
        }
@@ -769,7 +783,7 @@
                commandStep++;
                redisCommand.setCommandStep(commandStep);
                //任务数据保存到redis
                redisUtil.set("wrk_no_" + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
                redisUtil.set("shuttle_wrk_no_" + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
            }else {
                //已执行完成
                //保存数据到数据库做流水
@@ -799,8 +813,13 @@
                    }
                }
                String locNo = shuttleProtocol.getLocNo() == null ? shuttleProtocol.getSourceLocNo() : shuttleProtocol.getLocNo();
                //解除锁定的库位路径
                NavigateMapData navigateMapData = new NavigateMapData(Utils.getLev(locNo));
                navigateMapData.writeNavigateNodeToRedisMap(redisCommand.getAssignCommand().getNodes(), false);
                //删除redis
                redisUtil.del("wrk_no_" + redisCommand.getWrkNo());
                redisUtil.del("shuttle_wrk_no_" + redisCommand.getWrkNo());
                if (!assignCommand.getAuto()) {
                    //手动模式不抛出等待状态,直接复位
@@ -836,7 +855,7 @@
            return false;
        }
        Object o = redisUtil.get("wrk_no_" + wrkNo);
        Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo);
        if (o == null) {
            return false;
        }
@@ -925,7 +944,7 @@
        liftProtocol.setSecurityMk(true);//标记置为true,防止其他任务占用当前提升机
        redisCommand.setLiftSecurityMk(true);//标记置为true,防止其他任务占用当前提升机
        //任务数据保存到redis
        redisUtil.set("wrk_no_" + wrkNo, JSON.toJSONString(redisCommand));
        redisUtil.set("shuttle_wrk_no_" + wrkNo, JSON.toJSONString(redisCommand));
        //命令list
        ArrayList<LiftCommand> liftCommands = new ArrayList<>();
@@ -950,13 +969,13 @@
    /**
     * 复位并尝试修复错误
     */
    private boolean reset(Short wrkNo) {
    private boolean resetAndTryFix(Short wrkNo) {
        //读取redis数据
        if (wrkNo == null) {
            return false;
        }
        Object o = redisUtil.get("wrk_no_" + wrkNo);
        Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo);
        if (o == null) {
            return false;
        }
@@ -1027,7 +1046,7 @@
        redisCommand.setErrorCommands(list);
        //任务数据保存到redis
        redisUtil.set("wrk_no_" + wrkNo, JSON.toJSONString(redisCommand));
        redisUtil.set("shuttle_wrk_no_" + wrkNo, JSON.toJSONString(redisCommand));
        shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.FIXING);
        return true;
    }