自动化立体仓库 - WMS系统
zwl
4 天以前 a68a6de7f27e035beb2a141d895dd7e44ae9e659
src/main/java/com/zy/common/service/CommonService.java
@@ -538,6 +538,30 @@
        return orderedCrnNos;
    }
    /**
     * 优先按 s_crn_no/e_crn_no 反推真实堆垛机数量。
     *
     * 之前有逻辑错误把 asr_row_lastno.crn_qty 当成轮询游标写回,
     * 导致“堆垛机数量”字段被污染。后续找位不能再直接信任 crn_qty,
     * 否则会少扫堆垛机,表现出来就是任务长期偏向某几台堆垛机。
     */
    private int resolveCrnCount(RowLastno rowLastno) {
        if (rowLastno == null) {
            return 0;
        }
        if (rowLastno.getsCrnNo() != null && rowLastno.geteCrnNo() != null && rowLastno.geteCrnNo() >= rowLastno.getsCrnNo()) {
            return rowLastno.geteCrnNo() - rowLastno.getsCrnNo() + 1;
        }
        if (rowLastno.getCrnQty() != null && rowLastno.getCrnQty() > 0) {
            return rowLastno.getCrnQty();
        }
        Integer rowSpan = getCrnRowSpan(rowLastno.getTypeId());
        if (rowSpan != null && rowSpan > 0 && rowLastno.getsRow() != null && rowLastno.geteRow() != null && rowLastno.geteRow() >= rowLastno.getsRow()) {
            return (rowLastno.geteRow() - rowLastno.getsRow() + 1 + rowSpan - 1) / rowSpan;
        }
        return 0;
    }
    private Integer getCrnStartRow(RowLastno rowLastno, Integer crnNo) {
        if (rowLastno == null || crnNo == null) {
            return null;
@@ -729,6 +753,11 @@
     *
     * 推荐排只对普通物料生效,空托盘已经切换成“按库区轮询堆垛机”的规则,
     * 因此这里会直接跳过空托盘请求,避免 row 参数把空托盘重新带回旧逻辑。
     *
     * 另外,单排推荐不再作为“强绑定单台堆垛机”处理。
     * 现场上游经常只传一个推荐排,例如 row=[1],如果这里直接短路命中,
     * 满板任务就会长期压在同一台堆垛机上。现在只有当推荐排能覆盖多台堆垛机时,
     * 才把它当作真正的优先候选集合。
     */
    private LocMast findRun2RecommendLoc(RowLastno rowLastno, RowLastnoType rowLastnoType, boolean emptyPalletRequest,
                                         List<Integer> recommendRows, LocTypeDto locTypeDto, Integer staDescId,
@@ -738,7 +767,7 @@
            return null;
        }
        List<Integer> recommendCrnNos = mapRowsToCrnNos(rowLastno, recommendRows);
        if (Cools.isEmpty(recommendCrnNos)) {
        if (Cools.isEmpty(recommendCrnNos) || recommendCrnNos.size() <= 1) {
            return null;
        }
        LocMast locMast = findRun2EmptyLocByCrnNos(rowLastno, rowLastnoType, recommendCrnNos, locTypeDto,
@@ -791,11 +820,25 @@
     * 普通物料命中库位后,沿用 run2 原有的全仓轮询游标推进方式。
     */
    private void advanceNormalRun2Cursor(RowLastno rowLastno, int curRow) {
        advanceNormalRun2Cursor(rowLastno, curRow, null, null);
    }
    /**
     * 普通物料游标优先按“本次真正可用的堆垛机集合”推进。
     *
     * 这样即使库区定义里存在不存在的堆垛机,或者路径主数据只覆盖部分堆垛机,
     * 满板任务也会在真实可作业的堆垛机之间轮询,不会因为理论堆垛机号的空洞而长期回落到同一台。
     */
    private void advanceNormalRun2Cursor(RowLastno rowLastno, int curRow, List<Integer> runnableCrnNos, Integer selectedCrnNo) {
        if (rowLastno == null) {
            return;
        }
        int updateCurRow = curRow == 0 ? (rowLastno.getsRow() == null ? 1 : rowLastno.getsRow()) : curRow;
        if (!Cools.isEmpty(runnableCrnNos) && selectedCrnNo != null) {
            updateCurRow = getNextRun2CurrentRow(rowLastno, runnableCrnNos, selectedCrnNo, updateCurRow);
        } else {
        updateCurRow = getNextRun2CurrentRow(rowLastno, updateCurRow);
        }
        rowLastno.setCurrentRow(updateCurRow);
        rowLastnoService.updateById(rowLastno);
    }
@@ -1471,7 +1514,7 @@
        }
        int sRow = rowLastno.getsRow();
        int eRow = rowLastno.geteRow();
        int crnNumber = rowLastno.getCrnQty();
        int crnNumber = resolveCrnCount(rowLastno);
        // ===============>>>> 开始执行
@@ -1691,7 +1734,7 @@
        if (Cools.isEmpty(rowLastnoType)) {
            throw new CoolException("数据异常,请联系管理员===》库位规则类型未知");
        }
        int crnNumber = rowLastno.getCrnQty();
        int crnNumber = resolveCrnCount(rowLastno);
        rowCount = crnNumber;
        curRow = rowLastno.getCurrentRow();
@@ -1701,6 +1744,7 @@
        Run2AreaSearchResult emptyPalletAreaSearchResult = null;
        List<Integer> orderedCrnNos = getOrderedCrnNos(rowLastno, crnNo);
        List<Integer> orderedRunnableCrnNos = getOrderedRunnableRun2CrnNos(rowLastno, staDescId, sourceStaNo, orderedCrnNos);
        List<Integer> triedCrnNos = new ArrayList<>();
        locMast = findRun2RecommendLoc(rowLastno, rowLastnoType, emptyPalletRequest, recommendRows, locTypeDto,
                staDescId, sourceStaNo, startupDto, preferredArea, triedCrnNos);
@@ -1727,7 +1771,7 @@
        if (emptyPalletRequest) {
            advanceEmptyPalletRun2Cursor(emptyPalletAreaSearchResult, locMast);
        } else {
            advanceNormalRun2Cursor(rowLastno, curRow);
            advanceNormalRun2Cursor(rowLastno, curRow, orderedRunnableCrnNos, locMast == null ? null : locMast.getCrnNo());
        }
        if (Cools.isEmpty(locMast) || !locMast.getLocSts().equals("O")) {
@@ -1789,7 +1833,7 @@
        }
        int sRow = rowLastno.getsRow();
        int eRow = rowLastno.geteRow();
        int crnNumber = rowLastno.getCrnQty();
        int crnNumber = resolveCrnCount(rowLastno);
        // ===============>>>> 开始执行
        curRow = rowLastno.getCurrentRow();