自动化立体仓库 - WMS系统
#
luxiaotao1123
2022-12-08 6559c51b0ddc00a14a7589bc57bbfec4a01a0b2f
src/main/java/com/zy/common/service/CommonService.java
@@ -16,6 +16,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
@@ -25,6 +26,15 @@
@Slf4j
@Service
public class CommonService {
    public static final List<Integer> FIRST_GROUP_ROW_LIST = new ArrayList<Integer>() {{
        add(2);add(3);add(4);add(5);add(6);add(7);add(8);add(9);add(10);
        add(11);add(12);add(13);add(14);add(15);add(16);add(17);
    }};
    public static final List<Integer> SECOND_GROUP_ROW_LIST = new ArrayList<Integer>() {{
        add(18);add(19);add(20);
        add(21);add(22);add(23);add(24);add(25);add(26);add(27);add(28);add(29);add(30);
    }};
    @Autowired
    private WrkMastService wrkMastService;
@@ -57,25 +67,23 @@
        }
        int workNo = 0;
        // 入出库类型
        if (wrkLastno.getWrkMk() == 0) {
            workNo = wrkLastno.getWrkNo();
            int sNo = wrkLastno.getSNo();
            int eNo = wrkLastno.getENo();
        workNo = wrkLastno.getWrkNo();
        int sNo = wrkLastno.getSNo();
        int eNo = wrkLastno.getENo();
            workNo = workNo>=eNo ? sNo : workNo+1;
        workNo = workNo>=eNo ? sNo : workNo+1;
            while (true) {
                WrkMast wrkMast = wrkMastService.selectById(workNo);
                if (null != wrkMast) {
                    workNo = workNo>=eNo ? sNo : workNo+1;
                } else {
                    break;
                }
        while (true) {
            WrkMast wrkMast = wrkMastService.selectById(workNo);
            if (null != wrkMast) {
                workNo = workNo>=eNo ? sNo : workNo+1;
            } else {
                break;
            }
            if (workNo > 0){
                wrkLastno.setWrkNo(workNo);
                wrkLastnoService.updateById(wrkLastno);
            }
        }
        if (workNo > 0){
            wrkLastno.setWrkNo(workNo);
            wrkLastnoService.updateById(wrkLastno);
        }
        if (workNo == 0) {
            throw new CoolException("生成工作号失败,请联系管理员");
@@ -87,9 +95,9 @@
        return workNo;
    }
    public StartupDto getLocNo(Integer whsType, Integer staDescId, Integer sourceStaNo, boolean emptyMk, List<String> matNos, LocTypeDto locTypeDto, int times) {
    public StartupDto getLocNo(Integer whsType, Integer staDescId, Integer sourceStaNo, List<String> matNos, LocTypeDto locTypeDto, int times) {
        LocTypeDto oldLocType = locTypeDto.clone();
        return getLocNo(whsType, staDescId, sourceStaNo, emptyMk, matNos, locTypeDto, oldLocType, times);
        return getLocNo(whsType, staDescId, sourceStaNo, matNos, locTypeDto, oldLocType, times);
    }
    /**
@@ -100,12 +108,24 @@
     * @param matNos 物料号集合
     * @return locNo 检索到的库位号
     */
    public StartupDto getLocNo(Integer whsType, Integer staDescId, Integer sourceStaNo, boolean emptyMk, List<String> matNos, LocTypeDto locTypeDto, LocTypeDto oldLocType, int times) {
    public StartupDto getLocNo(Integer whsType, Integer staDescId, Integer sourceStaNo, List<String> matNos, LocTypeDto locTypeDto, LocTypeDto oldLocType, int times) {
        StartupDto startupDto = new StartupDto();
        if (sourceStaNo == 100) { // 轻货信号
            whsType = 1;    // 1 - 11 左
        } else if (sourceStaNo == 200) { // 重货信号
            whsType = 2;    // 12 - 21 右
        int start = 2;
        int end = 30;
        int dualCrnNo;
        switch (sourceStaNo) {
            case 203:
                whsType = 1;
                dualCrnNo = 2;
                break;
            case 102:
                whsType = 2;
                start = 31;
                end = 32;
                dualCrnNo = 3;
                break;
            default:
                throw new CoolException("数据异常,请联系管理员");
        }
        // 生成工作号
        int workNo = getWorkNo(0);
@@ -117,25 +137,52 @@
        int sRow = rowLastno.getsRow();          // 起始列
        int eRow = rowLastno.geteRow();          // 终止列
        int crn_qty = rowLastno.getCrnQty();     // 堆垛机数量(巷道数量)
        int rowCount = eRow - sRow + 1;          // 库排总数
        int rowCount;
        if (whsType == 1) {
            rowCount = 2;
        } else {
            rowCount = 1;
        }
//        int rowCount = eRow - sRow + 1;          // 库排总数
        // 目标堆垛机号
        int crnNo = 0;
        // 目标库位
        LocMast locMast = null;
        // 靠近摆放规则 --- 同天同规格物料
        if (!Cools.isEmpty(matNos)) {
            List<String> locNos = locDetlService.getSameDetl(matNos.get(0), sRow, eRow);
        if (!Cools.isEmpty(matNos) && matNos.size() == 1) {
            List<String> locNos = locDetlService.getSameDetl(matNos.get(0), start, end);
            for (String locNo : locNos) {
                List<String> groupLoc = Utils.getGroupLoc(locNo);
                locMast = locMastService.findOutMost(groupLoc);
                if (null != locMast) {
                    // 浅库位符合尺寸检测
                    if (VersionUtils.locMoveCheckLocType(locMast, locTypeDto)) {
                        // 浅库位对应堆垛机必须可用且无异常
                        if (basCrnpService.checkSiteError(locMast.getCrnNo(), true)) {
                            crnNo = locMast.getCrnNo();
                            break;
                if (whsType == 1) {
                    LocMast locMast0 = locMastService.findOutMost(locNo);
                    if (null != locMast0) {
                        // 浅库位符合尺寸检测
                        if (VersionUtils.locMoveCheckLocType(locMast0, locTypeDto)) {
                            // 浅库位对应堆垛机必须可用且无异常
                            if (basCrnpService.checkSiteError(dualCrnNo, true)) {
                                crnNo = dualCrnNo;
                                locMast = locMast0;
                                break;
                            }
                        }
                    }
                } else {
                    if (Utils.isShallowLoc(slaveProperties, locNo)) {
                        continue;
                    }
                    String shallowLocNo = Utils.getShallowLoc(slaveProperties, locNo);
                    // 检测目标库位是否为空库位
                    LocMast shallowLoc = locMastService.selectById(shallowLocNo);
                    if (shallowLoc != null && shallowLoc.getLocSts().equals("O")) {
                        if (VersionUtils.locMoveCheckLocType(shallowLoc, locTypeDto)) {
                            // 因库位移转、需预留空库位
                            if (locMastService.checkEmptyCount(shallowLoc)) {
                                if (basCrnpService.checkSiteError(shallowLoc.getCrnNo(), true)) {
                                    locMast = shallowLoc;
                                    crnNo = locMast.getCrnNo();
                                    break;
                                }
                            }
                        }
                    }
                }
@@ -143,19 +190,41 @@
        }
        // 靠近摆放规则 --- 空托
        if (emptyMk) {
            List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>().eq("loc_sts", "D").ge("row1", sRow).le("row1", eRow));
        if (staDescId == 10) {
            List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>()
                    .eq("loc_sts", "D").ge("row1", start).le("row1", end));
            if (locMasts.size() > 0) {
                for (LocMast loc : locMasts) {
                    List<String> groupLoc = Utils.getGroupLoc(loc.getLocNo());
                    locMast = locMastService.findOutMost(groupLoc);
                    if (null != locMast) {
                        // 浅库位符合尺寸检测
                        if (VersionUtils.locMoveCheckLocType(locMast, locTypeDto)) {
                            // 浅库位对应堆垛机必须可用且无异常
                            if (basCrnpService.checkSiteError(locMast.getCrnNo(), true)) {
                                crnNo = locMast.getCrnNo();
                                break;
                    if (whsType == 1) {
                        LocMast locMast0 = locMastService.findOutMost(loc.getLocNo());
                        if (null != locMast0) {
                            // 浅库位符合尺寸检测
                            if (VersionUtils.locMoveCheckLocType(locMast0, locTypeDto)) {
                                // 浅库位对应堆垛机必须可用且无异常
                                if (basCrnpService.checkSiteError(dualCrnNo, true)) {
                                    crnNo = dualCrnNo;
                                    locMast = locMast0;
                                    break;
                                }
                            }
                        }
                    } else {
                        if (Utils.isShallowLoc(slaveProperties, loc.getLocNo())) {
                            continue;
                        }
                        String shallowLocNo = Utils.getShallowLoc(slaveProperties, loc.getLocNo());
                        // 检测目标库位是否为空库位
                        LocMast shallowLoc = locMastService.selectById(shallowLocNo);
                        if (shallowLoc != null && shallowLoc.getLocSts().equals("O")) {
                            if (VersionUtils.locMoveCheckLocType(shallowLoc, locTypeDto)) {
                                // 因库位移转、需预留空库位
                                if (locMastService.checkEmptyCount(shallowLoc)) {
                                    if (basCrnpService.checkSiteError(shallowLoc.getCrnNo(), true)) {
                                        locMast = shallowLoc;
                                        crnNo = locMast.getCrnNo();
                                        break;
                                    }
                                }
                            }
                        }
                    }
@@ -165,63 +234,15 @@
        // 如果没有相近物料,则按规则轮询货架
        if (null == locMast) {
            int t = 0;
            boolean execute = true;
            int crnNo1;
            // 1 - 11排
            if (whsType == 1) {
                while (execute && t < 4) {
                    t++;
                    switch (curRow) {
                        case 3:
                            curRow = 11;
                            crnNo1 = 2;
                            break;
                        case 11:
                            curRow = 4;
                            crnNo1 = 1;
                            break;
                        case 4:
                            curRow = 12;
                            crnNo1 = 2;
                            break;
                        default:
                            curRow = 3;
                            crnNo1 = 1;
                            break;
                    }
                    if (basCrnpService.checkSiteError(crnNo1, true)) {
                        crnNo = crnNo1;
                        execute = false;
                    }
                if (curRow == 2) {
                    curRow = 30;
                } else if (curRow == 30) {
                    curRow = 2;
                }
                // 12 - 21排
            } else {
                while (execute && t < 4) {
                    t++;
                    switch (curRow) {
                        case 11:
                            curRow = 18;
                            crnNo1 = 3;
                            break;
                        case 18:
                            curRow = 12;
                            crnNo1 = 2;
                            break;
                        case 12:
                            curRow = 19;
                            crnNo1 = 3;
                            break;
                        default:
                            curRow = 11;
                            crnNo1 = 2;
                            break;
                    }
                    if (basCrnpService.checkSiteError(crnNo1, true)) {
                        crnNo = crnNo1;
                        execute = false;
                    }
                }
            }
            if (basCrnpService.checkSiteError(dualCrnNo, true)) {
                crnNo = dualCrnNo;
            }
        }
@@ -253,10 +274,63 @@
        // 1.当检索库排为浅库位排时,优先寻找当前库排的深库位排
        if (locMast == null) {
            locMast = locMastService.queryFreeLocMast(curRow, locTypeDto.getLocType1());
            // 因库位移转、需预留空库位
            if (!locMastService.checkEmptyCount(locMast)) {
                locMast = null;
            if (whsType == 1) {
                List<Integer> rows = Utils.getGroupLoc(curRow);
//                Iterator<Integer> iterator = rows.iterator();
//                while (iterator.hasNext()) {
//                    Integer next = iterator.next();
//                    if (next.equals(17) || next.equals(18)) {
//                        iterator.remove();
//                    }
//                }
                List<LocMast> locMasts = locMastService.queryFreeLocMast(rows, rows.size(), locTypeDto.getLocType1());
                if (!Cools.isEmpty(locMasts)) {
                    Integer innermostRow = Utils.getOutLayerRow(locMasts.get(0).getLocNo(), false);
                    for (LocMast one : locMasts) {
                        if (one.getRow1().equals(innermostRow)) {
                            locMast = one;
                            break;
                        }
                    }
                }
                // 因库位移转、需预留空库位 todo:luxiaotao
//            if (!locMastService.checkEmptyCount(locMast)) {
//                locMast = null;
//            }
            } else {
                if (Utils.isShallowLoc(slaveProperties, curRow)) {
                    Integer deepRow = Utils.getDeepRow(slaveProperties, curRow);
                    locMast = locMastService.queryFreeLocMast0(deepRow, locTypeDto.getLocType1());
                    // 因库位移转、需预留空库位
                    if (locMast !=null && !locMastService.checkEmptyCount(locMast)) {
                        locMast = null;
                    }
                }
                if (Cools.isEmpty(locMast)) {
                    locMast = locMastService.queryFreeLocMast0(curRow, locTypeDto.getLocType1());
                    // 因库位移转、需预留空库位
                    if (!locMastService.checkEmptyCount(locMast)) {
                        locMast = null;
                    }
                    // 目标库位 ===>> 浅库位, 则校验其深库位是否为 F D X
                    if (null != locMast && Utils.isShallowLoc(slaveProperties, locMast.getLocNo())) {
                        LocMast deepLoc = locMastService.selectById(Utils.getDeepLoc(slaveProperties, locMast.getLocNo()));
                        if (!deepLoc.getLocSts().equals("F") && !deepLoc.getLocSts().equals("D") && !deepLoc.getLocSts().equals("X")) {
                            locMast = null;
                        }
                    }
                    // 目标库位 ===>> 深库位, 则校验其浅库位是否为 O
                    if (null != locMast && Utils.isDeepLoc(slaveProperties, locMast.getLocNo())) {
                        LocMast shallowLoc = locMastService.selectById(Utils.getShallowLoc(slaveProperties, locMast.getLocNo()));
                        if (!shallowLoc.getLocSts().equals("O")) {
                            locMast = null;
                        }
                    }
                }
            }
        }
@@ -265,13 +339,15 @@
            // 当前巷道无空库位时,递归调整至下一巷道,检索全部巷道无果后,跳出递归
            if (times < rowCount) {
                times = times + 1;
                return getLocNo(whsType, staDescId, sourceStaNo, emptyMk, matNos, locTypeDto, oldLocType, times);
                return getLocNo(whsType, staDescId, sourceStaNo, matNos, locTypeDto, oldLocType, times);
            } else {
                times = 0;
            }
//            // 货物检索低库位仓失败,兼容高库位仓后继续执行
//            if (locTypeDto.getLocType1() == 1) {
//                locTypeDto.setLocType1((short) 2);
//                return getLocNo(1, staDescId, sourceStaNo, emptyMk, matNos, locTypeDto, oldLocType, times);
//            }
            // 货物检索低库位仓失败,兼容高库位仓后继续执行
            if (locTypeDto.getLocType1() == 1) {
                locTypeDto.setLocType1((short) 2);
                return getLocNo(1, staDescId, sourceStaNo, matNos, locTypeDto, oldLocType, times);
            }
            log.error("系统没有空库位!!! 尺寸规格: {}, 轮询次数:{}", JSON.toJSONString(locTypeDto), times);
            throw new CoolException("没有空库位");
        }