自动化立体仓库 - WMS系统
Junjie
2023-05-12 fd1bfa1163d438ec6cabfdd6e01e632d31189c80
src/main/java/com/zy/asrs/utils/Utils.java
@@ -1,11 +1,15 @@
package com.zy.asrs.utils;
import com.alibaba.fastjson.JSON;
import com.core.common.Arith;
import com.core.common.Cools;
import com.zy.common.properties.SlaveProperties;
import com.zy.common.service.CommonService;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
@@ -144,6 +148,26 @@
    }
    /**
     * 通过库位号获取 列
     */
    public static int getBay(String locNo) {
        if (!Cools.isEmpty(locNo)) {
            return Integer.parseInt(locNo.substring(2, 5));
        }
        throw new RuntimeException("库位解析异常");
    }
    /**
     * 通过库位号获取 层
     */
    public static int getLev(String locNo) {
        if (!Cools.isEmpty(locNo)) {
            return Integer.parseInt(locNo.substring(5, 7));
        }
        throw new RuntimeException("库位解析异常");
    }
    /**
     * 当检索到双深库位的浅库位时,如果深库位无货,则放入对应的深库位
     */
    public static void toDeepIfEmptyByShallow(String shallowLoc) {
@@ -161,113 +185,272 @@
    }
    public static Integer getGroupRow(String locNo, Boolean pakin){
        int row = getRow(locNo);
        switch (row) {
            case 1:
            case 2:
            case 3:
                return 3;
            case 4:
            case 5:
            case 6:
            case 7:
                return 4;
            case 8:
            case 9:
            case 10:
            case 11:
                return 11;
            case 12:
            case 13:
            case 14:
                return 12;
            case 15:
            case 16:
            case 17:
            case 18:
                return 18;
            case 19:
            case 20:
            case 21:
                return 19;
            default:
                throw new RuntimeException("库位解析异常");
        }
    public static String getLocNo(Number row, Number bay, Number lev) {
        return zerofill(String.valueOf(row), 2) + zerofill(String.valueOf(bay), 3) + zerofill(String.valueOf(lev), 2);
    }
    public static List<String> getGroupLoc(String locNo){
        int row = getRow(locNo);
        switch (row) {
            case 1:
            case 2:
            case 3:
                return new ArrayList<String>() {{
                    add(zerofill(String.valueOf(1), 2) + locNo.substring(2));
                    add(zerofill(String.valueOf(2), 2) + locNo.substring(2));
                    add(zerofill(String.valueOf(3), 2) + locNo.substring(2));
                }};
            case 4:
            case 5:
            case 6:
            case 7:
                return new ArrayList<String>() {{
                    add(zerofill(String.valueOf(4), 2) + locNo.substring(2));
                    add(zerofill(String.valueOf(5), 2) + locNo.substring(2));
                    add(zerofill(String.valueOf(6), 2) + locNo.substring(2));
                    add(zerofill(String.valueOf(7), 2) + locNo.substring(2));
                }};
            case 8:
            case 9:
            case 10:
            case 11:
                return new ArrayList<String>() {{
                    add(zerofill(String.valueOf(8), 2) + locNo.substring(2));
                    add(zerofill(String.valueOf(9), 2) + locNo.substring(2));
                    add(zerofill(String.valueOf(10), 2) + locNo.substring(2));
                    add(zerofill(String.valueOf(11), 2) + locNo.substring(2));
                }};
            case 12:
            case 13:
            case 14:
                return new ArrayList<String>() {{
                    add(zerofill(String.valueOf(12), 2) + locNo.substring(2));
                    add(zerofill(String.valueOf(13), 2) + locNo.substring(2));
                    add(zerofill(String.valueOf(14), 2) + locNo.substring(2));
                }};
            case 15:
            case 16:
            case 17:
            case 18:
                return new ArrayList<String>() {{
                    add(zerofill(String.valueOf(15), 2) + locNo.substring(2));
                    add(zerofill(String.valueOf(16), 2) + locNo.substring(2));
                    add(zerofill(String.valueOf(17), 2) + locNo.substring(2));
                    add(zerofill(String.valueOf(18), 2) + locNo.substring(2));
                }};
            case 19:
            case 20:
            case 21:
                return new ArrayList<String>() {{
                    add(zerofill(String.valueOf(19), 2) + locNo.substring(2));
                    add(zerofill(String.valueOf(20), 2) + locNo.substring(2));
                    add(zerofill(String.valueOf(21), 2) + locNo.substring(2));
                }};
            default:
                throw new RuntimeException("库位解析异常");
        if (CommonService.FIRST_GROUP_ROW_LIST.contains(row)) {
            List<String> result = new ArrayList<>();
            for (Integer row0 : CommonService.FIRST_GROUP_ROW_LIST) {
                result.add(zerofill(String.valueOf(row0), 2) + locNo.substring(2));
            }
            return result;
        }
        if (CommonService.SECOND_GROUP_ROW_LIST.contains(row)) {
            List<String> result = new ArrayList<>();
            for (Integer row0 : CommonService.SECOND_GROUP_ROW_LIST) {
                result.add(zerofill(String.valueOf(row0), 2) + locNo.substring(2));
            }
            return result;
        }
        if (CommonService.FIRST_GROUP_ROW_LIST_SHORT.contains(row)) {
            List<String> result = new ArrayList<>();
            for (Integer row0 : CommonService.FIRST_GROUP_ROW_LIST_SHORT) {
                result.add(zerofill(String.valueOf(row0), 2) + locNo.substring(2));
            }
            return result;
        }
        if (CommonService.THIRD_GROUP_ROW_LIST.contains(row)) {
            List<String> result = new ArrayList<>();
            for (Integer row0 : CommonService.THIRD_GROUP_ROW_LIST) {
                result.add(zerofill(String.valueOf(row0), 2) + locNo.substring(2));
            }
            return result;
        }
        throw new RuntimeException("库位解析异常");
    }
    public static Integer getOutLayerRow(String locNo, Boolean pakin){
        int row = getRow(locNo);
        if (CommonService.FIRST_GROUP_ROW_LIST.contains(row)) {
            return 4;
        } else if (CommonService.SECOND_GROUP_ROW_LIST.contains(row)) {
            return 5;
        } else {
            return -1;
        }
    }
    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);
    public static List<Integer> getGroupLoc(Integer row){
        if (CommonService.FIRST_GROUP_ROW_LIST.contains(row)) {
            return CommonService.FIRST_GROUP_ROW_LIST;
        } else if (CommonService.FIRST_GROUP_ROW_LIST_SHORT.contains(row)) {
            return CommonService.FIRST_GROUP_ROW_LIST_SHORT;
        } else if (CommonService.SECOND_GROUP_ROW_LIST.contains(row)) {
            return CommonService.SECOND_GROUP_ROW_LIST;
        } else if (CommonService.THIRD_GROUP_ROW_LIST.contains(row)) {
            return CommonService.THIRD_GROUP_ROW_LIST;
        } else {
            throw new RuntimeException("库位解析异常");
        }
    }
    // 外侧方向的货位  优先入库方向/优先出库方向
    public static List<String> getGroupOuterLoc(String locNo){
        int row = getRow(locNo);
        List<String> result = new ArrayList<>();
        if (CommonService.FIRST_GROUP_ROW_LIST.contains(row)) {
            List<Integer> clone = Arrays.asList(new Integer[CommonService.FIRST_GROUP_ROW_LIST.size()]);
            Collections.copy(clone, CommonService.FIRST_GROUP_ROW_LIST);
            Collections.reverse(clone);
            for (Integer integer : clone) {
                if (integer > row) {
                    result.add(zerofill(String.valueOf(integer), 2) + locNo.substring(2));
                } else {
                    break;
                }
            }
        } else if (CommonService.FIRST_GROUP_ROW_LIST_SHORT.contains(row)){
            List<Integer> clone = Arrays.asList(new Integer[CommonService.FIRST_GROUP_ROW_LIST_SHORT.size()]);
            Collections.copy(clone, CommonService.FIRST_GROUP_ROW_LIST_SHORT);
            Collections.reverse(clone);
            for (Integer integer : clone) {
                if (integer > row) {
                    result.add(zerofill(String.valueOf(integer), 2) + locNo.substring(2));
                } else {
                    break;
                }
            }
        } else if (CommonService.SECOND_GROUP_ROW_LIST.contains(row)){
            List<Integer> clone = Arrays.asList(new Integer[CommonService.SECOND_GROUP_ROW_LIST.size()]);
            Collections.copy(clone, CommonService.SECOND_GROUP_ROW_LIST);
            Collections.reverse(clone);
            for (Integer integer : clone) {
                if (integer > row) {
                    result.add(zerofill(String.valueOf(integer), 2) + locNo.substring(2));
                } else {
                    break;
                }
            }
        } else if (CommonService.THIRD_GROUP_ROW_LIST.contains(row)){
            for (Integer integer : CommonService.THIRD_GROUP_ROW_LIST) {
                if (integer < row) {
                    result.add(zerofill(String.valueOf(integer), 2) + locNo.substring(2));
                } else {
                    break;
                }
            }
        }
        return result;
    }
    // 外侧方向的货位  优先入库方向/优先出库方向
    public static List<String> getGroupOuterLocIoPri(String locNo){
        int row = getRow(locNo);
        List<String> result = new ArrayList<>();
        if (CommonService.FIRST_GROUP_ROW_LIST.contains(row)) {
            for (Integer integer : CommonService.FIRST_GROUP_ROW_LIST) {
                if (integer < row) {
                    result.add(zerofill(String.valueOf(integer), 2) + locNo.substring(2));
                } else {
                    break;
                }
            }
        } else if (CommonService.FIRST_GROUP_ROW_LIST_SHORT.contains(row)){
            for (Integer integer : CommonService.FIRST_GROUP_ROW_LIST_SHORT) {
                if (integer < row) {
                    result.add(zerofill(String.valueOf(integer), 2) + locNo.substring(2));
                } else {
                    break;
                }
            }
        } else if (CommonService.SECOND_GROUP_ROW_LIST.contains(row)){
            for (Integer integer : CommonService.SECOND_GROUP_ROW_LIST) {
                if (integer < row) {
                    result.add(zerofill(String.valueOf(integer), 2) + locNo.substring(2));
                } else {
                    break;
                }
            }
        } else if (CommonService.THIRD_GROUP_ROW_LIST.contains(row)){
            List<Integer> clone = Arrays.asList(new Integer[CommonService.THIRD_GROUP_ROW_LIST.size()]);
            Collections.copy(clone, CommonService.THIRD_GROUP_ROW_LIST);
            Collections.reverse(clone);
            for (Integer integer : clone) {
                if (integer > row) {
                    result.add(zerofill(String.valueOf(integer), 2) + locNo.substring(2));
                } else {
                    break;
                }
            }
        }
        return result;
    }
    public static void main(String[] args) {
        System.out.println(JSON.toJSONString(getGroupOuterLoc("0200101")));
    }
    // 内侧方向的货位  优先入库方向/优先出库方向 ===>> 反之
    public static List<String> getGroupInsideLoc(String locNo){
        int row = getRow(locNo);
        List<String> result = new ArrayList<>();
        if (CommonService.FIRST_GROUP_ROW_LIST.contains(row)) {
            List<Integer> clone = Arrays.asList(new Integer[CommonService.FIRST_GROUP_ROW_LIST.size()]);
            Collections.copy(clone, CommonService.FIRST_GROUP_ROW_LIST);
            Collections.reverse(clone);
            for (Integer integer : clone) {
                if (integer > row) {
                    result.add(zerofill(String.valueOf(integer), 2) + locNo.substring(2));
                } else {
                    break;
                }
            }
        } else if (CommonService.FIRST_GROUP_ROW_LIST_SHORT.contains(row)) {
            List<Integer> clone = Arrays.asList(new Integer[CommonService.FIRST_GROUP_ROW_LIST_SHORT.size()]);
            Collections.copy(clone, CommonService.FIRST_GROUP_ROW_LIST_SHORT);
            Collections.reverse(clone);
            for (Integer integer : clone) {
                if (integer > row) {
                    result.add(zerofill(String.valueOf(integer), 2) + locNo.substring(2));
                } else {
                    break;
                }
            }
        } else if (CommonService.SECOND_GROUP_ROW_LIST.contains(row)) {
            List<Integer> clone = Arrays.asList(new Integer[CommonService.SECOND_GROUP_ROW_LIST.size()]);
            Collections.copy(clone, CommonService.SECOND_GROUP_ROW_LIST);
            Collections.reverse(clone);
            for (Integer integer : clone) {
                if (integer > row) {
                    result.add(zerofill(String.valueOf(integer), 2) + locNo.substring(2));
                } else {
                    break;
                }
            }
        } else if (CommonService.THIRD_GROUP_ROW_LIST.contains(row)) {
            for (Integer integer : CommonService.THIRD_GROUP_ROW_LIST) {
                if (integer < row) {
                    result.add(zerofill(String.valueOf(integer), 2) + locNo.substring(2));
                } else {
                    break;
                }
            }
        } else {
//            throw new RuntimeException("库位解析异常");
        }
        if (!Cools.isEmpty(result)) {
            Collections.reverse(result);
        }
        return result;
    }
    // 外侧方向的货位  优先入库方向/优先出库方向 ===>> 反之
    public static List<String> getGroupOutsideLoc(String locNo){
        int row = getRow(locNo);
        List<String> result = new ArrayList<>();
        if (CommonService.THIRD_GROUP_ROW_LIST.contains(row)) {
            for (Integer integer : CommonService.THIRD_GROUP_ROW_LIST) {
                if (integer < row) {
                    result.add(zerofill(String.valueOf(integer), 2) + locNo.substring(2));
                } else {
                    break;
                }
            }
        } else if (CommonService.FIRST_GROUP_ROW_LIST.contains(row)) {
            List<Integer> clone = Arrays.asList(new Integer[CommonService.FIRST_GROUP_ROW_LIST.size()]);
            Collections.copy(clone, CommonService.FIRST_GROUP_ROW_LIST);
            Collections.reverse(clone);
            for (Integer integer : clone) {
                if (integer > row) {
                    result.add(zerofill(String.valueOf(integer), 2) + locNo.substring(2));
                } else {
                    break;
                }
            }
        } else if (CommonService.FIRST_GROUP_ROW_LIST_SHORT.contains(row)) {
            List<Integer> clone = Arrays.asList(new Integer[CommonService.FIRST_GROUP_ROW_LIST_SHORT.size()]);
            Collections.copy(clone, CommonService.FIRST_GROUP_ROW_LIST_SHORT);
            Collections.reverse(clone);
            for (Integer integer : clone) {
                if (integer > row) {
                    result.add(zerofill(String.valueOf(integer), 2) + locNo.substring(2));
                } else {
                    break;
                }
            }
        } else if (CommonService.SECOND_GROUP_ROW_LIST.contains(row)) {
            List<Integer> clone = Arrays.asList(new Integer[CommonService.SECOND_GROUP_ROW_LIST.size()]);
            Collections.copy(clone, CommonService.SECOND_GROUP_ROW_LIST);
            Collections.reverse(clone);
            for (Integer integer : clone) {
                if (integer > row) {
                    result.add(zerofill(String.valueOf(integer), 2) + locNo.substring(2));
                } else {
                    break;
                }
            }
        } else {
//            throw new RuntimeException("库位解析异常");
        }
        if (!Cools.isEmpty(result)) {
            Collections.reverse(result);
        }
        return result;
    }
}