#
zzgtfwq
1 天以前 de480b42a379d1cf23e1703977c0169e837fa786
src/main/java/com/zy/asrs/utils/Utils.java
@@ -1,9 +1,12 @@
package com.zy.asrs.utils;
import com.core.common.Arith;
import com.core.common.Cools;
import com.zy.core.properties.SlaveProperties;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
/**
 * Created by vincent on 2020/8/27
@@ -19,4 +22,322 @@
        return (float) Arith.multiplys(2, f, 1);
    }
    public static String zerofill(String msg, Integer count){
        if (msg.length() == count){
            return msg;
        } else if (msg.length() > count){
            return msg.substring(0, 16);
        } else {
            StringBuilder msgBuilder = new StringBuilder(msg);
            for (int i = 0; i<count-msg.length(); i++){
                msgBuilder.insert(0,"0");
            }
            return msgBuilder.toString();
        }
    }
    /**
     * 判断是否为深库位
     */
    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 shallowRow = row;
        if (row==1 || row == 5 || row==11){
            shallowRow = row+1;
        } else if (row==4 || row==8 || row == 14){
            shallowRow = row-1;
        }
//        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;
//        int targetRow = row;
        if (row==2 || row == 6 || row==12){
            targetRow = row-1;
        } else if (row==3 || row==7 || row == 13){
            targetRow = row+1;
        }else {
            throw new RuntimeException(shallowLoc + "不是浅库位,系统繁忙");
        }
//        if (remainder == 2) {
//            targetRow = row - 1;
//        } else if (remainder == 3) {
//            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 == 3) {
//            targetRow = shallowRow + 1;
//        } else {
//            throw new RuntimeException(shallowRow + "不是浅库位排,系统繁忙");
//        }
//        int targetRow = row;
        if (shallowRow==2 || shallowRow == 6 || shallowRow==12){
            targetRow = shallowRow-1;
        } else if (shallowRow==3 || shallowRow==7 || shallowRow == 13){
            targetRow = shallowRow+1;
        }else {
            throw new RuntimeException(shallowRow + "不是浅库位,系统繁忙");
        }
        return targetRow;
    }
    /**
     * 通过库位号获取 排
     */
    public static int getRow(String locNo) {
        if (!Cools.isEmpty(locNo)) {
            return Integer.parseInt(locNo.substring(0, 2));
        }
        throw new RuntimeException("库位解析异常");
    }
    /**
     * 当检索到双深库位的浅库位时,如果深库位无货,则放入对应的深库位
     */
    public static void toDeepIfEmptyByShallow(String shallowLoc) {
        int row = getRow(shallowLoc);
        int remainder = (int) Arith.remainder(row, 4);
        int targetRow = 0;
        if (remainder == 2) {
            targetRow = row - 1;
        } else if (remainder == 3) {
            targetRow = row + 1;
        } else {
            throw new RuntimeException(shallowLoc + "不是浅库位,系统繁忙");
        }
        String targetLoc = zerofill(String.valueOf(targetRow), 2) + shallowLoc.substring(2);
    }
    public static double[] getRgvPosNew(Integer devNo,double a, double b) {
        double[] rgvPosNew = getRgvPosNew(a, b);
        switch (devNo){
            case 101:
            case 102:
            case 103:
            case 104:
            case 105:
            case 106:
            case 107:
            case 108:
            case 109:
            case 110:
            case 111:
                rgvPosNew[0] = rgvPosNew[0] - 70;
                break;
            case 112:
            case 113:
            case 114:
            case 115:
                rgvPosNew[0] = rgvPosNew[0] + 50;
                break;
            case 116:
            case 117:
            case 118:
            case 119:
            case 120:
            case 121:
            case 122:
            case 123:
            case 124:
            case 125:
            case 126:
            case 127:
            case 128:
            case 129:
            case 130:
            case 131:
            case 132:
            case 133:
                rgvPosNew[1] = rgvPosNew[1] + 50;
                break;
            case 134:
                rgvPosNew[1] = rgvPosNew[1] - 70;
                break;
        }
        return rgvPosNew;
    }
    public static double[] getRgvPosNew(double a, double b) {
        Object[][] intervals = {
//                // 弧线区间(拐点116-115),控制点假设为(1125, 882)
//                {680103, 731550, 1115, 882, 1215, 775, 1125, 882},
                // 直线区间(0-134400)
//                {起点, 终点, 类型, x1, y1, x2, y2,
                {0.0, 240000.0, 0, 100.0, 225.0, 1100.0, 225.0},
                {1000000.0, 1240000.0, 0, 100.0, 625.0, 1100.0, 625.0},
//                // 圆弧区间(拐点116-115)新参数:圆心(1115,775)
//                {120000.0, 127500.0, 2, 60.0, 750.0, 10.0, 800.0, 60.0, 800.0}, // 修正终点坐标
//                {127500.0, 134900.0, 2, 10.0, 800.0, 60.0, 850.0, 60.0, 800.0},
//                {134900.0, 680103.0,0, 60.0, 850.0, 1100.0, 850.0},
//                {680103.0, 731550.0, 2, 1100.0, 850.0, 1200.0, 750.0, 1100.0, 750.0},
//                {731550.0, 972950.0,0, 1200.0, 750.0, 1200.0, 100.0},
//                {972950.0, 1016193.0, 2, 1200.0, 100.0, 1150.0, 50.0, 1150.0, 100.0},
//                {1016193.0, 1063563.0, 2, 1150.0, 50.0, 1100.0, 100.0, 1150.0, 100.0},
//                {1063563.0, 1315250.0,0, 1100.0, 100.0, 1100.0, 700.0},
//                {1315250.0, 1322829.0, 2, 1100.0, 700.0, 1050.0, 750.0, 1050.0, 700.0},
//                {1322829.0, 1737000.0,0, 1050.0, 750.0, 390.0, 750.0},
        };
        for (Object[] interval : intervals) {
            double start = (Double) interval[0];
            double end = (Double) interval[1];
            int type = (Integer) interval[2];
            if (b >= start && b <= end) {
                double t = (b - start) / (end - start);
                // 根据不同类型计算坐标
                switch (type) {
                    case 0: // 直线
                        return linearInterpolation(interval, t);
                    case 1: // 贝塞尔曲线
                        return bezierInterpolation(interval, t);
                    case 2: // 圆弧
                        return circularInterpolation(interval, t);
                }
            }
        }
        return new double[]{0, 0};
    }
    // 直线插值
    private static double[] linearInterpolation(Object[] interval, double t) {
        double x1 = (Double) interval[3];
        double y1 = (Double) interval[4];
        double x2 = (Double) interval[5];
        double y2 = (Double) interval[6];
        return new double[]{
                x1 + t * (x2 - x1),
                y1 + t * (y2 - y1)
        };
    }
    // 贝塞尔曲线插值
    private static double[] bezierInterpolation(Object[] interval, double t) {
        double x0 = (Double) interval[3];
        double y0 = (Double) interval[4];
        double x2 = (Double) interval[5];
        double y2 = (Double) interval[6];
        double cx = (Double) interval[7];
        double cy = (Double) interval[8];
        return new double[]{
                Math.pow(1-t, 2)*x0 + 2*(1-t)*t*cx + t*t*x2,
                Math.pow(1-t, 2)*y0 + 2*(1-t)*t*cy + t*t*y2
        };
    }
    // 圆弧插值(新增)
    private static double[] circularInterpolation(Object[] interval, double t) {
        // 参数解析
        double startX = (Double) interval[3];
        double startY = (Double) interval[4];
        double endX = (Double) interval[5];
        double endY = (Double) interval[6];
        double centerX = (Double) interval[7];
        double centerY = (Double) interval[8];
        // 计算起始角度和终止角度
        double startAngle = Math.atan2(startY - centerY, startX - centerX);
        double endAngle = Math.atan2(endY - centerY, endX - centerX);
        // 角度插值
        double currentAngle = startAngle + t * (endAngle - startAngle);
        double radius = Math.hypot(startX - centerX, startY - centerY);
        return new double[]{
                centerX + radius * Math.cos(currentAngle),
                centerY + radius * Math.sin(currentAngle)
        };
    }
    public static void main(String[] args) {
        SlaveProperties slaveProperties = new SlaveProperties();
        slaveProperties.setDoubleDeep(true);
        List<Integer> list = new ArrayList<>();
        list.add(1);list.add(4);list.add(5);list.add(8);list.add(9);list.add(12);
        slaveProperties.setDoubleLocs(list);
        slaveProperties.setGroupCount(4);
        Integer deepRow = getDeepRow(slaveProperties, 6);
        System.out.println(deepRow);
    }
}