#
Junjie
13 小时以前 efbd157c0d810c39d04cd86752e769a3f3a1a1fc
src/main/java/com/zy/core/thread/impl/NyShuttleThread.java
@@ -5,7 +5,6 @@
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.DateUtils;
import com.core.common.SpringUtils;
import com.core.exception.CoolException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zy.asrs.entity.BasShuttle;
import com.zy.asrs.entity.DeviceConfig;
@@ -52,6 +51,7 @@
    private DeviceConfig deviceConfig;
    private RedisUtil redisUtil;
    private ShuttleProtocol shuttleProtocol;
    private ShuttleAction shuttleAction = null;
    private static final boolean DEBUG = false;//调试模式
@@ -92,14 +92,11 @@
//        Thread executeThread = new Thread(() -> {
//            while (true) {
//                try {
//                    ShuttleAction shuttleAction = null;
//                    try {
//                        shuttleAction = SpringUtils.getBean(ShuttleAction.class);
//                    }catch (Exception e){
//                        continue;
//                    }
//
//                    if (shuttleAction == null) {
//                        try {
//                            shuttleAction = SpringUtils.getBean(ShuttleAction.class);
//                        }catch (Exception e){
//                        }
//                        continue;
//                    }
//
@@ -580,7 +577,7 @@
    }
    @Override
    public boolean isRequireCharge() {
    public ShuttleRequireChargeType isRequireCharge() {
        if (this.shuttleProtocol.getDeviceStatus() == null
                || this.shuttleProtocol.getPakMk() == null
                || this.shuttleProtocol.getErrorCode() == null
@@ -588,7 +585,7 @@
                || this.shuttleProtocol.getMode() == null
                || this.shuttleProtocol.getExtend() == null
        ) {
            return false;
            return ShuttleRequireChargeType.NONE;
        }
        InnerSuhttleExtend extend = (InnerSuhttleExtend) this.shuttleProtocol.getExtend();
@@ -601,25 +598,43 @@
                && extend.getSuspendState() == 0
                ;
        if (!res) {
            return res;
            return ShuttleRequireChargeType.NONE;
        } else {
            // 电量小于阈值需要进行充电
            try {
                BasShuttleService shuttleService = SpringUtils.getBean(BasShuttleService.class);
                if (shuttleService == null) {
                    return false;
                    return ShuttleRequireChargeType.NONE;
                }
                BasShuttle basShuttle = shuttleService.selectOne(new EntityWrapper<BasShuttle>().eq("shuttle_no", deviceConfig.getDeviceNo()));
                if (basShuttle == null) {
                    return false;
                    return ShuttleRequireChargeType.NONE;
                }
                Integer chargeLine = basShuttle.getChargeLine();
                if (chargeLine == null) {
                    return false;
                    return ShuttleRequireChargeType.NONE;
                }
                return Integer.valueOf(this.shuttleProtocol.getBatteryPower()) < chargeLine;
                boolean chargeResult = Integer.valueOf(this.shuttleProtocol.getBatteryPower()) < chargeLine;
                if (chargeResult) {
                    return ShuttleRequireChargeType.FORCE_CHARGE;//需要强制充电
                }
                Integer suggestChargeLine = basShuttle.getSuggestChargeLine();
                if (suggestChargeLine == null) {
                    return ShuttleRequireChargeType.NONE;
                }
                boolean suggestChargeResult = Integer.valueOf(this.shuttleProtocol.getBatteryPower()) < suggestChargeLine;
                if (suggestChargeResult) {
                    return ShuttleRequireChargeType.SUGGEST_CHARGE;//建议充电
                }
                return ShuttleRequireChargeType.NONE;
            } catch (Exception e) {
                return false;
                return ShuttleRequireChargeType.NONE;
            }
        }
    }
@@ -764,13 +779,15 @@
    @Override
    public synchronized boolean setTaskNo(Integer taskNo) {
        redisUtil.set(RedisKeyType.SHUTTLE_FLAG.key + shuttleProtocol.getShuttleNo(), taskNo);
        this.shuttleProtocol.setTaskNo(taskNo);
        return true;
    }
    @Override
    public synchronized boolean setSyncTaskNo(Integer taskNo) {
        this.shuttleProtocol.setSyncTaskNo(taskNo);
        redisUtil.setSync(RedisKeyType.SHUTTLE_FLAG.key + shuttleProtocol.getShuttleNo(), taskNo);
        this.shuttleProtocol.setTaskNo(taskNo);
        return true;
    }
@@ -929,8 +946,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;
        }
@@ -942,7 +962,7 @@
            }
            ShuttleCommand firstCommand = originCommands.get(0);
            ShuttleCommand endCommand = originCommands.get(commands.size() - 1);
            ShuttleCommand endCommand = originCommands.get(originCommands.size() - 1);
            if (firstCommand.getMode() != ShuttleCommandModeType.PALLET_LIFT.id) {
                return false;
@@ -976,12 +996,11 @@
        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);
        List<List<MapNode>> mapData = navigateMapData.getJsonData(startNode.getZ(), NavigationMapType.getMapTypes(NavigationMapType.NONE), null, null);
        for (NavigateNode node : nodes) {
            HashMap<String, Object> data = new HashMap<>();
            String codeNum = NavigatePositionConvert.xyToPosition(node.getX(), node.getY(), node.getZ());
@@ -990,7 +1009,6 @@
            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());
@@ -1004,18 +1022,70 @@
        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("库位信息不存在");
        }
        Object object = redisUtil.get(RedisKeyType.LOC_MAP.key);
        HashMap<String, String> locMap = (HashMap<String, String>) object;
        String targetLocNo = locMap.get(distCodeNum);
        ShuttleCommand command = new ShuttleCommand();
        command.setShuttleNo(deviceConfig.getDeviceNo());
        command.setBody(JSON.toJSONString(httpStandard));
        command.setMode(ShuttleCommandModeType.MOVE.id);
        command.setTargetLocNo(locMast.getLocNo());
        command.setTargetLocNo(targetLocNo);
        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);
        NavigateNode startNode = nodes.get(0);
        List<List<MapNode>> mapData = navigateMapData.getJsonData(startNode.getZ(), NavigationMapType.getMapTypes(NavigationMapType.NONE), null, null);
        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<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);
        Object object = redisUtil.get(RedisKeyType.LOC_MAP.key);
        HashMap<String, String> locMap = (HashMap<String, String>) object;
        String targetLocNo = locMap.get(distCodeNum);
        ShuttleCommand command = new ShuttleCommand();
        command.setShuttleNo(deviceConfig.getDeviceNo());
        command.setBody(JSON.toJSONString(httpStandard));
        command.setMode(ShuttleCommandModeType.MOVE.id);
        command.setTargetLocNo(targetLocNo);
        command.setTaskNo(taskId);
        return command;
    }
@@ -1084,7 +1154,6 @@
    //获取小车复位响应命令
    public ShuttleCommand getInitCommand(Integer taskNo, Integer code) {
        LocMastService locMastService = SpringUtils.getBean(LocMastService.class);
        NavigateMapData navigateMapData = SpringUtils.getBean(NavigateMapData.class);
        NyShuttleHttpCommand httpStandard = getHttpStandard(deviceConfig.getDeviceNo(), taskNo);
        NyShuttleHttpCommand.NyRequest request = httpStandard.getRequest();
@@ -1100,15 +1169,14 @@
        map.put("z", lev);
        String mapStr = JSON.toJSONString(map);
        LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
                .eq("qr_code_value", mapStr));
        if (locMast == null) {
            throw new CoolException("地址码不存在");
        }
        Object object = redisUtil.get(RedisKeyType.LOC_MAP.key);
        HashMap<String, String> locMap = (HashMap<String, String>) object;
        String targetLocNo = locMap.get(mapStr);
        List<List<MapNode>> mapData = navigateMapData.getJsonData(lev, NavigationMapType.getMapTypes(NavigationMapType.NONE), null, null);
        List<MapNode> mapNodes = mapData.get(locMast.getRow1());
        MapNode mapNode = mapNodes.get(locMast.getBay1());
        List<MapNode> mapNodes = mapData.get(Utils.getRow(targetLocNo));
        MapNode mapNode = mapNodes.get(Utils.getBay(targetLocNo));
        HashMap<String, Object> location = new HashMap<>();
        location.put("xp", row);
@@ -1214,16 +1282,16 @@
    private JSONObject queryCommandStatus(String resultKey) {
        // 获取服务器响应
        // 尝试50次
        JSONObject result = null;
        for (int i = 0; i < 50; i++) {
        long startTime = System.currentTimeMillis();
        while (true) {
            if((System.currentTimeMillis() - startTime) > 1000 * 10) {
                break;
            }
            result = getRequestBody(resultKey);
            if (result == null) {
                try {
                    Thread.sleep(500);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                continue;
            }else {
                break;
            }