Junjie
2025-08-13 5bd42df0ef1bcdbc3911381274b4f3f267d0203b
src/main/java/com/zy/core/thread/impl/NyShuttleThread.java
@@ -89,35 +89,35 @@
        });
        readThread.start();
        //设备执行
        Thread executeThread = new Thread(() -> {
            while (true) {
                try {
                    if (shuttleAction == null) {
                        try {
                            shuttleAction = SpringUtils.getBean(ShuttleAction.class);
                        }catch (Exception e){
                        }
                        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 executeThread = new Thread(() -> {
//            while (true) {
//                try {
//                    if (shuttleAction == null) {
//                        try {
//                            shuttleAction = SpringUtils.getBean(ShuttleAction.class);
//                        }catch (Exception e){
//                        }
//                        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();
    }
    private void listenMessageFromRedis() {
@@ -927,8 +927,11 @@
            return false;
        }
        List<NavigationMapType> restartCalcMapTypes = new ArrayList<>(mapTypes);
        restartCalcMapTypes.add(NavigationMapType.SHUTTLE);
        String currentLocNo = shuttleProtocol.getCurrentLocNo();
        List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(currentLocNo, locNo, mapTypes, assignCommand, this);
        List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(currentLocNo, locNo, restartCalcMapTypes, assignCommand, this);
        if (commands == null) {
            return false;
        }
@@ -974,8 +977,64 @@
        HashMap<String, Object> body = new HashMap<>();
        body.put("requestType", "move");//移动命令
        body.put("taskId", taskId);//TaskID需要随机
//        body.put("start", navigateNodeToNyPointNode(NavigatePositionConvert.codeToNode(startCodeNum, device.getHostId())));//起点
//        body.put("target", navigateNodeToNyPointNode(NavigatePositionConvert.codeToNode(distCodeNum, device.getHostId())));//终点
        body.put("path", path);
        request.setBody(body);
        NavigateNode startNode = nodes.get(0);
        for (NavigateNode node : nodes) {
            HashMap<String, Object> data = new HashMap<>();
            String codeNum = NavigatePositionConvert.xyToPosition(node.getX(), node.getY(), node.getZ());
            Map<String, Object> nyNode = navigateNodeToNyPointNode(NavigatePositionConvert.codeToNode(codeNum));
            int xp = Integer.parseInt(String.valueOf(nyNode.get("y")));
            int yp = Integer.parseInt(String.valueOf(nyNode.get("x")));
            int z = Integer.parseInt(String.valueOf(nyNode.get("z")));
            List<List<MapNode>> mapData = navigateMapData.getJsonData(startNode.getZ(), NavigationMapType.getMapTypes(NavigationMapType.NONE), null, null);
            List<MapNode> mapNodes = mapData.get(node.getX());
            MapNode mapNode = mapNodes.get(node.getY());
            data.put("xp", xp);
            data.put("yp", yp);
            data.put("z", z);
            data.put("x", mapNode.getXBase());
            data.put("y", mapNode.getYBase());
            path.add(data);
        }
        httpStandard.setRequest(request);
        LocMastService locMastService = SpringUtils.getBean(LocMastService.class);
        LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
                .eq("qr_code_value", distCodeNum));
        if (locMast == null) {
            throw new CoolException("库位信息不存在");
        }
        ShuttleCommand command = new ShuttleCommand();
        command.setShuttleNo(deviceConfig.getDeviceNo());
        command.setBody(JSON.toJSONString(httpStandard));
        command.setMode(ShuttleCommandModeType.MOVE.id);
        command.setTargetLocNo(locMast.getLocNo());
        command.setTaskNo(taskId);
        return command;
    }
    @Override
    public ShuttleCommand getMoveLiftCommand(Integer taskNo, String startCodeNum, String distCodeNum, Integer allDistance, Integer runDirection, Integer runSpeed, List<NavigateNode> nodes, Boolean moveIn) {
        NavigateMapData navigateMapData = SpringUtils.getBean(NavigateMapData.class);
        NyShuttleHttpCommand httpStandard = getHttpStandard(deviceConfig.getDeviceNo(), taskNo);
        NyShuttleHttpCommand.NyRequest request = httpStandard.getRequest();
        ArrayList<HashMap<String, Object>> path = new ArrayList<>();
        Integer taskId = getTaskId();
        HashMap<String, Object> body = new HashMap<>();
        if (moveIn) {
            body.put("requestType", "intoLift");//进提升机
        }else {
            body.put("requestType", "outLift");//出提升机
        }
        body.put("taskId", taskId);//TaskID需要随机
        body.put("path", path);
        request.setBody(body);