#
Junjie
2024-12-24 0df6e7bb33c9f6a18f026a500776b00cbf2ae62c
src/main/java/com/zy/asrs/utils/Utils.java
@@ -28,6 +28,7 @@
import java.text.DecimalFormat;
import java.util.*;
import java.util.regex.Pattern;
/**
 * Created by vincent on 2020/8/27
@@ -112,121 +113,6 @@
//                return 0;
//            }
//        }
    }
    /**
     * 判断库位是否为穿梭库位
     * @param locNo
     * @return
     */
    public static Boolean isShuttle(String locNo) {
        int row = Utils.getRow(locNo);
        if (row >= 2 && row <= 12) {
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    }
    // -------------------------------------------------------------------------------------------------------------------
    /**
     * 判断是否为深库位
     */
    public static boolean isDeepLoc(SlaveProperties slaveProperties, String locNo){
        if (slaveProperties.isDoubleDeep()) {
            int row = getRow(locNo);
            return slaveProperties.getDoubleLocs().contains(row);
        } else {
            return false;
        }
    }
    /**
     * 判断是否为深库位
     */
    public static boolean isDeepLoc(SlaveProperties slaveProperties, Integer row){
        if (slaveProperties.isDoubleDeep()) {
            return slaveProperties.getDoubleLocs().contains(row);
        } else {
            return false;
        }
    }
    /**
     * 判断是否为浅库位
     */
    public static boolean isShallowLoc(SlaveProperties slaveProperties, String locNo){
        if (slaveProperties.isDoubleDeep()) {
            int row = getRow(locNo);
            return !slaveProperties.getDoubleLocs().contains(row);
        } else {
            return false;
        }
    }
    /**
     * 判断是否为浅库位
     */
    public static boolean isShallowLoc(SlaveProperties slaveProperties, Integer row){
        if (slaveProperties.isDoubleDeep()) {
            return !slaveProperties.getDoubleLocs().contains(row);
        } else {
            return false;
        }
    }
    /**
     * 获取 深库位对应的浅库位号
     */
    public static String getShallowLoc(SlaveProperties slaveProperties, String deepLoc) {
        int row = getRow(deepLoc);
        int remainder = (int) Arith.remainder(row, slaveProperties.getGroupCount());
        int shallowRow = remainder == 1 ? (row + 1) : (row - 1);
        return zerofill(String.valueOf(shallowRow), 2) + deepLoc.substring(2);
    }
    /**
     * 获取 深库位排对应的浅库位排
     */
    public static Integer getShallowRow(SlaveProperties slaveProperties, Integer deepRow) {
        int remainder = (int) Arith.remainder(deepRow, slaveProperties.getGroupCount());
        return remainder == 1 ? (deepRow + 1) : (deepRow - 1);
    }
    /**
     * 获取 浅库位对应的深库位号
     */
    public static String getDeepLoc(SlaveProperties slaveProperties, String shallowLoc) {
        int row = getRow(shallowLoc);
        int remainder = (int) Arith.remainder(row, slaveProperties.getGroupCount());
        int targetRow;
        if (remainder == 2) {
            targetRow = row - 1;
        } else if (remainder == 1) {
            targetRow = row + 1;
        } else {
            throw new RuntimeException(shallowLoc + "不是浅库位,系统繁忙");
        }
        return zerofill(String.valueOf(targetRow), 2) + shallowLoc.substring(2);
    }
    /**
     * 获取 浅库位排对应的深库位排
     */
    public static Integer getDeepRow(SlaveProperties slaveProperties, Integer shallowRow) {
        int remainder = (int) Arith.remainder(shallowRow, slaveProperties.getGroupCount());
        int targetRow;
        if (remainder == 2) {
            targetRow = shallowRow - 1;
        } else if (remainder == 1) {
            targetRow = shallowRow + 1;
        } else {
            throw new RuntimeException(shallowRow + "不是浅库位排,系统繁忙");
        }
        return targetRow;
    }
    /**
@@ -415,10 +301,10 @@
            if (currentLocNo == null) {
                //小车没有库位号数据,从数据库中取
                BasShuttle basShuttle = basShuttleService.selectById(slave.getId());
                if (basShuttle == null || basShuttle.getPoint() == null) {
                if (basShuttle == null) {
                    continue;
                }
                NyShuttleProtocol.NyShuttlePointClass shuttlePoint = JSON.parseObject(basShuttle.getPoint(), NyShuttleProtocol.NyShuttlePointClass.class);
                NyShuttleProtocol.NyShuttlePointClass shuttlePoint = shuttleProtocol.getPoint();
                currentLocNo = NavigatePositionConvert.nyXyzToLocNo(shuttlePoint.getX(), shuttlePoint.getY(), shuttlePoint.getZ());
            }
@@ -441,6 +327,7 @@
        WrkMastService wrkMastService = SpringUtils.getBean(WrkMastService.class);
        CommonService commonService = SpringUtils.getBean(CommonService.class);
        ShuttleDispatchUtils shuttleDispatchUtils = SpringUtils.getBean(ShuttleDispatchUtils.class);
        NavigateMapData navigateMapData = SpringUtils.getBean(NavigateMapData.class);
        if (shuttleThread == null) {
            return false;
@@ -450,15 +337,24 @@
            return false;
        }
        NavigateMapData mapData = new NavigateMapData(z);//获取地图数据
        int[][] data = mapData.getData(-1, null, currentShuttleId == null ? null : Utils.getShuttlePoints(0, z));//载入全部车辆
        int[][] data = navigateMapData.getData(z, -1, null, currentShuttleId == null ? null : Utils.getShuttlePoints(0, z));//载入全部车辆
        int moveBay = 23;//避让起始列
        int bay = Utils.getBay(shuttleProtocol.getCurrentLocNo());//小车当前列
        if (bay > 1 && bay <= 30) {
            moveBay = 23;
        } else if (bay > 30 && bay <= 45) {
            moveBay = 39;
        } else if (bay > 45) {
            moveBay = 50;
        }
        int distY = -1;
        int distX = -1;
        int distZ = -1;
        //获取避让库位
        String distLocNo = null;
        for (int y = 20; y <= 56; y++) {
        for (int y = moveBay; y <= 56; y++) {
            boolean searchFlag = true;
            for (int x = 10; x <= 11; x++) {
                if (data[x][y] < 0 || data[x][y] == 66) {
@@ -478,6 +374,10 @@
                LocMast distLocMast = locMastService.queryByLoc(locNo);
                if (distLocMast == null) {
                    continue;
                }
                if (distLocMast.getLocSts().equals("X")) {
                    continue;//调过禁用库位
                }
                //判断该库位是否存在工作档
@@ -684,5 +584,13 @@
        }
        return null;
    }
    /**
     * 判断字符串是否为JSON格式
     */
    public static boolean isJson(String jsonString) {
        // JSON格式的正则表达式
        String pattern = "^\\{.*\\}$";
        // 使用Pattern类进行正则匹配
        return Pattern.matches(pattern, jsonString);
    }
}