| | |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Comparator; |
| | | import java.util.HashMap; |
| | | import java.util.LinkedHashMap; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 检索库位号 |
| | | * 入库找库位统一入口。 |
| | | * |
| | | * 空托盘入库也从这里进入,先由 {@link #normalizeLocTypeDto(Integer, FindLocNoAttributeVo, LocTypeDto)} |
| | | * 统一识别空托盘和整理库位规格,再按 row_lastno_type 分流到不同库型的找位实现。 |
| | | * |
| | | * @param staDescId 路径ID |
| | | * @param sourceStaNo 源站 |
| | |
| | | switch (rowLastnoType.getType()) { |
| | | case 1: |
| | | case 2: |
| | | return getLocNoRun2(whsType, staDescId, sourceStaNo, findLocNoAttributeVo, 0, locTypeDto, recommendRows, 0); |
| | | case 3: |
| | | return getLocNoRun(whsType, staDescId, sourceStaNo, findLocNoAttributeVo, 0, locTypeDto, 0); |
| | | return getLocNoRun2(whsType, staDescId, sourceStaNo, findLocNoAttributeVo, 0, locTypeDto, recommendRows, 0); |
| | | |
| | | case 4: |
| | | return getLocNoRun4(whsType, staDescId, sourceStaNo, findLocNoAttributeVo, 4, locTypeDto, 0); |
| | | case 5: |
| | |
| | | } |
| | | |
| | | /** |
| | | * 供 6.15 重分配接口复用:按外部指定的堆垛机顺序,在指定库区内找新的入库位。 |
| | | * 供重分配接口复用:按外部指定的堆垛机顺序找新的入库位。 |
| | | * |
| | | * 这里不推进 row_lastno 游标,只负责一次性的路径校验 + 设备校验 + 空库位搜索。 |
| | | */ |
| | | public StartupDto findRun2InboundLocByCandidateCrnNos(Integer sourceStaNo, Integer staDescId, |
| | | List<Integer> candidateCrnNos, LocTypeDto locTypeDto) { |
| | | return findRun2InboundLocByCandidateCrnNos(sourceStaNo, staDescId, null, candidateCrnNos, locTypeDto, null); |
| | | } |
| | | |
| | | public StartupDto findRun2InboundLocByCandidateCrnNos(Integer sourceStaNo, Integer staDescId, |
| | | List<Integer> candidateCrnNos, LocTypeDto locTypeDto, |
| | | Integer targetLev) { |
| | | return findRun2InboundLocByCandidateCrnNos(sourceStaNo, staDescId, null, candidateCrnNos, locTypeDto, targetLev); |
| | | } |
| | | |
| | | /** |
| | | * 兼容旧调用:按外部指定的堆垛机顺序,在指定库区内找新的入库位。 |
| | | */ |
| | | public StartupDto findRun2InboundLocByCandidateCrnNos(Integer sourceStaNo, Integer staDescId, Integer preferredArea, |
| | | List<Integer> candidateCrnNos, LocTypeDto locTypeDto) { |
| | | return findRun2InboundLocByCandidateCrnNos(sourceStaNo, staDescId, preferredArea, candidateCrnNos, locTypeDto, null); |
| | | } |
| | | |
| | | private StartupDto findRun2InboundLocByCandidateCrnNos(Integer sourceStaNo, Integer staDescId, Integer preferredArea, |
| | | List<Integer> candidateCrnNos, LocTypeDto locTypeDto, |
| | | Integer targetLev) { |
| | | if (sourceStaNo == null) { |
| | | throw new CoolException("源站不能为空"); |
| | | } |
| | |
| | | if (Cools.isEmpty(rowLastnoType)) { |
| | | throw new CoolException("数据异常,请联系管理员===》库位规则类型未知"); |
| | | } |
| | | if (rowLastnoType.getType() != 1 && rowLastnoType.getType() != 2) { |
| | | throw new CoolException("当前仓库不支持重新分配入库位"); |
| | | } |
| | | StartupDto startupDto = new StartupDto(); |
| | | LocMast locMast = findRun2EmptyLocByCrnNos(searchRowLastno, rowLastnoType, candidateCrnNos, locTypeDto, |
| | | staDescId, sourceStaNo, startupDto, preferredArea, null, "reassign-inbound"); |
| | | staDescId, sourceStaNo, startupDto, preferredArea, null, "reassign-inbound", targetLev); |
| | | if (Cools.isEmpty(locMast) || !"O".equals(locMast.getLocSts())) { |
| | | return null; |
| | | } |
| | |
| | | * 统一整理入库规格,避免不同入口传入的 locType 不一致。 |
| | | * |
| | | * 空托盘的库位策略有两段: |
| | | * 1. 首轮只限制 loc_type2=1,表示优先找窄库位。 |
| | | * 2. loc_type1 高度信息必须保留,后续再按低位向高位兼容。 |
| | | * 1. 先限制 loc_type2=1,表示优先找窄库位,并保留 loc_type1 高度兼容。 |
| | | * 2. 窄库位没有结果后,把 loc_type1 改为 3 再找库位。 |
| | | * |
| | | * 非空托盘只保留 loc_type1,满托找位不再使用 loc_type2/loc_type3 过滤。 |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * 空托盘固定按 4 段式找位: |
| | | * 空托盘固定按窄库位优先找位: |
| | | * 1. 严格高度 + narrow |
| | | * 2. 向上兼容高度 + narrow |
| | | * 3. 严格高度 + open |
| | | * 4. 向上兼容高度 + open |
| | | * 3. loc_type1=3 + open |
| | | */ |
| | | private List<LocTypeDto> buildEmptyPalletSearchLocTypes(LocTypeDto locTypeDto) { |
| | | List<LocTypeDto> searchLocTypes = new ArrayList<LocTypeDto>(); |
| | |
| | | searchLocTypes.add(narrowCompatibleLocType); |
| | | } |
| | | |
| | | LocTypeDto openStrictLocType = copyLocTypeDto(baseLocTypeDto); |
| | | openStrictLocType.setLocType2((short) 0); |
| | | searchLocTypes.add(openStrictLocType); |
| | | |
| | | LocTypeDto openCompatibleLocType = buildUpwardCompatibleLocTypeDto(openStrictLocType); |
| | | if (openCompatibleLocType != null) { |
| | | openCompatibleLocType.setLocType2((short) 0); |
| | | searchLocTypes.add(openCompatibleLocType); |
| | | } |
| | | LocTypeDto emptyPalletFallbackLocType = copyLocTypeDto(baseLocTypeDto); |
| | | emptyPalletFallbackLocType.setLocType1((short) 3); |
| | | emptyPalletFallbackLocType.setLocType2((short) 0); |
| | | searchLocTypes.add(emptyPalletFallbackLocType); |
| | | return searchLocTypes; |
| | | } |
| | | |
| | | /** |
| | | * 给空托盘找位阶段生成日志标识,便于排查到底卡在窄库位、高度兼容还是 loc_type1=3 兜底阶段。 |
| | | */ |
| | | private String buildEmptyPalletStageCode(LocTypeDto baseLocTypeDto, LocTypeDto stageLocTypeDto) { |
| | | boolean emptyPalletType3Fallback = stageLocTypeDto != null |
| | | && stageLocTypeDto.getLocType1() != null |
| | | && stageLocTypeDto.getLocType1() == 3; |
| | | if (emptyPalletType3Fallback) { |
| | | return "empty-pallet-locType1-3"; |
| | | } |
| | | boolean compatibleHeight = baseLocTypeDto != null |
| | | && baseLocTypeDto.getLocType1() != null |
| | | && stageLocTypeDto != null |
| | |
| | | |
| | | /** |
| | | * 把 locType 条件追加到库位查询条件里。 |
| | | * |
| | | * 空托盘会显式传 loc_type2:第一轮 loc_type2=1 优先窄库位,兜底阶段 loc_type2=0 表示不再限制宽窄。 |
| | | * 满托盘整理后没有 loc_type2/loc_type3,此处会排除 loc_type2=1,避免满托占用空托盘窄库位。 |
| | | */ |
| | | private Wrapper<LocMast> applyLocTypeFilters(Wrapper<LocMast> wrapper, LocTypeDto locTypeDto, boolean includeLocType1) { |
| | | if (wrapper == null || locTypeDto == null) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 按第一优先池 -> 第二优先池的顺序查找可用库位。 |
| | | * run2 站点优先池找位入口。 |
| | | * |
| | | * 空托盘规则: |
| | | * 1. 先找站点第一优先池,再找第二优先池;第二池会排除第一池已配置的堆垛机。 |
| | | * 2. 每个优先池内先找窄库位,再做高度向上兼容,最后把 loc_type1 改为 3 兜底。 |
| | | * 3. 只有命中库位的池会推进自己的 currentNo 游标,未命中的池不改变轮询状态。 |
| | | */ |
| | | private LocMast findRun2PriorityLocInPools(BasDevp station, RowLastno rowLastno, RowLastnoType rowLastnoType, |
| | | Integer staDescId, Integer sourceStaNo, FindLocNoAttributeVo findLocNoAttributeVo, |
| | |
| | | |
| | | /** |
| | | * 在单个优先池内按轮转顺序找位。 |
| | | * |
| | | * 池内规则: |
| | | * 1. 从 currentNo 的下一台堆垛机开始轮转,保证同一优先池内均分。 |
| | | * 2. 跳过不可入、故障或源站到目标堆垛机无入库路径的堆垛机。 |
| | | * 3. 每台堆垛机内部交给 {@link #findConfiguredEmptyLocForCrn(RowLastno, RowLastnoType, Integer, Integer, LocTypeDto, FindLocNoAttributeVo, boolean)} |
| | | * 按深浅排画像选择第一个可分配库位。 |
| | | * 4. 命中后回写该优先池游标,并把目标站写入 startupDto。 |
| | | */ |
| | | private LocMast findRun2PriorityLocInPool(RowLastno rowLastno, RowLastnoType rowLastnoType, BasDevp station, |
| | | List<Integer> crnNos, Integer currentCrnNo, int poolNo, LocTypeDto locTypeDto, |
| | |
| | | } |
| | | |
| | | /** |
| | | * 在单个优先池内先按当前规格找位,失败后再做一次 locType1 向上兼容。 |
| | | * 普通托盘的优先池规格兼容入口。 |
| | | * |
| | | * 空托盘不走这个方法,因为空托盘已经在 {@link #buildEmptyPalletSearchLocTypes(LocTypeDto)} |
| | | * 中固定展开了“窄库位优先 + 高度向上兼容 + loc_type1=3 兜底”的顺序。 |
| | | */ |
| | | private LocMast findRun2PriorityLocInPoolWithCompatibility(RowLastno rowLastno, RowLastnoType rowLastnoType, |
| | | BasDevp station, List<Integer> crnNos, Integer currentCrnNo, |
| | |
| | | } |
| | | |
| | | /** |
| | | * 空托盘 run2 专用搜索链路。 |
| | | * 保留的空托盘 run2 按库区轮询搜索链路。 |
| | | * |
| | | * 当前 getLocNoRun2 的空托盘实际入口走 {@link #findRun2PriorityLocInPools(BasDevp, RowLastno, RowLastnoType, Integer, Integer, FindLocNoAttributeVo, LocTypeDto, StartupDto, boolean)} |
| | | * 的站点优先池规则;如果后续需要恢复“当前库区 -> 其它库区”的兜底,可以从这里接回。 |
| | | * |
| | | * 执行顺序: |
| | | * 1. 先按固定规格阶段构造 4 段式 locType 回退顺序。 |
| | | * 1. 先按固定规格阶段构造“窄库位优先 + loc_type1=3 兜底”的 locType 回退顺序。 |
| | | * 2. 每个规格阶段都按“当前库区 -> 其它库区”的顺序搜索。 |
| | | * 3. 每个库区内部都按该库区自己的 rowLastno/currentRow 做轮询均分。 |
| | | * |
| | |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 保留链路:在某个空托盘规格阶段内按库区顺序搜索。 |
| | | * |
| | | * 库区顺序由 {@link #buildAreaSearchOrder(List, Integer)} 生成:站点绑定库区优先,其次接口请求库区, |
| | | * 最后补齐 1/2/3 全库区。每个库区使用自己的 row_lastno 游标,并且跨库区时不强制 sta_desc 路径校验。 |
| | | */ |
| | | private Run2AreaSearchResult findEmptyPalletRun2AreaLoc(RowLastno defaultRowLastno, Integer staDescId, Integer sourceStaNo, |
| | | StartupDto startupDto, FindLocNoAttributeVo findLocNoAttributeVo, LocTypeDto locTypeDto, |
| | | String stageCode) { |
| | |
| | | .eq("stn_no", sourceStaNo) |
| | | .eq("crn_no", crnNo)); |
| | | if (Cools.isEmpty(staDesc)) { |
| | | log.error("type_no={},stn_no={},crn_no={}", staDescId, sourceStaNo, crnNo); |
| | | log.error("没有入库路径type_no={},stn_no={},crn_no={}", staDescId, sourceStaNo, crnNo); |
| | | return null; |
| | | } |
| | | BasDevp staNo = basDevpService.selectById(staDesc.getCrnStn()); |
| | |
| | | private LocMast findRun2EmptyLocByCrnNos(RowLastno rowLastno, RowLastnoType rowLastnoType, List<Integer> candidateCrnNos, |
| | | LocTypeDto locTypeDto, Integer staDescId, Integer sourceStaNo, StartupDto startupDto, |
| | | Integer preferredArea, FindLocNoAttributeVo findLocNoAttributeVo, String stage, boolean routeRequired) { |
| | | return findRun2EmptyLocByCrnNos(rowLastno, rowLastnoType, candidateCrnNos, locTypeDto, |
| | | staDescId, sourceStaNo, startupDto, preferredArea, findLocNoAttributeVo, stage, routeRequired, null); |
| | | } |
| | | |
| | | private LocMast findRun2EmptyLocByCrnNos(RowLastno rowLastno, RowLastnoType rowLastnoType, List<Integer> candidateCrnNos, |
| | | LocTypeDto locTypeDto, Integer staDescId, Integer sourceStaNo, StartupDto startupDto, |
| | | Integer preferredArea, FindLocNoAttributeVo findLocNoAttributeVo, String stage, |
| | | Integer targetLev) { |
| | | return findRun2EmptyLocByCrnNos(rowLastno, rowLastnoType, candidateCrnNos, locTypeDto, |
| | | staDescId, sourceStaNo, startupDto, preferredArea, findLocNoAttributeVo, stage, true, targetLev); |
| | | } |
| | | |
| | | private LocMast findRun2EmptyLocByCrnNos(RowLastno rowLastno, RowLastnoType rowLastnoType, List<Integer> candidateCrnNos, |
| | | LocTypeDto locTypeDto, Integer staDescId, Integer sourceStaNo, StartupDto startupDto, |
| | | Integer preferredArea, FindLocNoAttributeVo findLocNoAttributeVo, String stage, |
| | | boolean routeRequired, Integer targetLev) { |
| | | if (Cools.isEmpty(candidateCrnNos)) { |
| | | log.warn("run2 skip empty candidate list. stage={}, sourceStaNo={}, preferredArea={}, spec={}", |
| | | stage, sourceStaNo, preferredArea, JSON.toJSONString(locTypeDto)); |
| | |
| | | List<Integer> locTypeBlockedCrns = new ArrayList<>(); |
| | | return findRun2EmptyLocByCrnNosRecursively(rowLastno, rowLastnoType, candidateCrnNos, locTypeDto, |
| | | staDescId, sourceStaNo, startupDto, preferredArea, findLocNoAttributeVo, stage, routeRequired, 0, |
| | | crnErrorCrns, routeBlockedCrns, noEmptyCrns, locTypeBlockedCrns); |
| | | crnErrorCrns, routeBlockedCrns, noEmptyCrns, locTypeBlockedCrns, targetLev); |
| | | } |
| | | |
| | | private LocMast findRun2EmptyLocByCrnNosRecursively(RowLastno rowLastno, RowLastnoType rowLastnoType, |
| | |
| | | Integer preferredArea, FindLocNoAttributeVo findLocNoAttributeVo, |
| | | String stage, boolean routeRequired, int index, |
| | | List<Integer> crnErrorCrns, List<Integer> routeBlockedCrns, |
| | | List<Integer> noEmptyCrns, List<Integer> locTypeBlockedCrns) { |
| | | List<Integer> noEmptyCrns, List<Integer> locTypeBlockedCrns, |
| | | Integer targetLev) { |
| | | if (index >= candidateCrnNos.size()) { |
| | | logRun2NoMatch(stage, sourceStaNo, preferredArea, candidateCrnNos, locTypeDto, |
| | | crnErrorCrns, routeBlockedCrns, noEmptyCrns, locTypeBlockedCrns); |
| | |
| | | crnErrorCrns.add(candidateCrnNo); |
| | | return findRun2EmptyLocByCrnNosRecursively(rowLastno, rowLastnoType, candidateCrnNos, locTypeDto, |
| | | staDescId, sourceStaNo, startupDto, preferredArea, findLocNoAttributeVo, stage, routeRequired, index + 1, |
| | | crnErrorCrns, routeBlockedCrns, noEmptyCrns, locTypeBlockedCrns); |
| | | crnErrorCrns, routeBlockedCrns, noEmptyCrns, locTypeBlockedCrns, targetLev); |
| | | } |
| | | Integer targetStaNo = routeRequired ? resolveTargetStaNo(rowLastno, staDescId, sourceStaNo, candidateCrnNo) : null; |
| | | if (routeRequired && Utils.BooleanWhsTypeSta(rowLastno, staDescId) && targetStaNo == null) { |
| | | routeBlockedCrns.add(candidateCrnNo); |
| | | return findRun2EmptyLocByCrnNosRecursively(rowLastno, rowLastnoType, candidateCrnNos, locTypeDto, |
| | | staDescId, sourceStaNo, startupDto, preferredArea, findLocNoAttributeVo, stage, routeRequired, index + 1, |
| | | crnErrorCrns, routeBlockedCrns, noEmptyCrns, locTypeBlockedCrns); |
| | | crnErrorCrns, routeBlockedCrns, noEmptyCrns, locTypeBlockedCrns, targetLev); |
| | | } |
| | | Integer preferredNearRow = getCrnStartRow(rowLastno, candidateCrnNo); |
| | | LocMast candidateLoc = findConfiguredEmptyLocForCrn(rowLastno, rowLastnoType, candidateCrnNo, |
| | | preferredNearRow, locTypeDto, findLocNoAttributeVo); |
| | | preferredNearRow, locTypeDto, findLocNoAttributeVo, targetLev); |
| | | if (Cools.isEmpty(candidateLoc)) { |
| | | int availableLocCount = countAssignableLocForCrn(rowLastno, rowLastnoType, candidateCrnNo, |
| | | preferredNearRow == null ? 0 : preferredNearRow, locTypeDto); |
| | |
| | | } |
| | | return findRun2EmptyLocByCrnNosRecursively(rowLastno, rowLastnoType, candidateCrnNos, locTypeDto, |
| | | staDescId, sourceStaNo, startupDto, preferredArea, findLocNoAttributeVo, stage, routeRequired, index + 1, |
| | | crnErrorCrns, routeBlockedCrns, noEmptyCrns, locTypeBlockedCrns); |
| | | crnErrorCrns, routeBlockedCrns, noEmptyCrns, locTypeBlockedCrns, targetLev); |
| | | } |
| | | if (targetStaNo != null) { |
| | | startupDto.setStaNo(targetStaNo); |
| | |
| | | return locTypeDto == null || VersionUtils.locMoveCheckLocTypeComplete(locMast, locTypeDto); |
| | | } |
| | | |
| | | private boolean matchesTargetLev(LocMast locMast, Integer targetLev) { |
| | | return targetLev == null || targetLev <= 0 || (locMast != null && Objects.equals(locMast.getLev1(), targetLev)); |
| | | } |
| | | |
| | | /** |
| | | * 查询某一排上的所有空库位,并按单伸/双伸策略与频次排序。 |
| | | */ |
| | |
| | | private List<LocMast> findOpenLocsByRow(RowLastno rowLastno, RowLastnoType rowLastnoType, Integer row, |
| | | Integer crnNo, LocTypeDto locTypeDto, FindLocNoAttributeVo findLocNoAttributeVo, |
| | | boolean singleExtension, boolean ignoreFreqType) { |
| | | return findOpenLocsByRow(rowLastno, rowLastnoType, row, crnNo, locTypeDto, findLocNoAttributeVo, |
| | | singleExtension, ignoreFreqType, null); |
| | | } |
| | | |
| | | private List<LocMast> findOpenLocsByRow(RowLastno rowLastno, RowLastnoType rowLastnoType, Integer row, |
| | | Integer crnNo, LocTypeDto locTypeDto, FindLocNoAttributeVo findLocNoAttributeVo, |
| | | boolean singleExtension, boolean ignoreFreqType, Integer targetLev) { |
| | | List<LocMast> result = new ArrayList<LocMast>(); |
| | | if (row == null) { |
| | | return result; |
| | |
| | | if (crnNo != null) { |
| | | wrapper.eq("crn_no", crnNo); |
| | | } |
| | | if (targetLev != null && targetLev > 0) { |
| | | wrapper.eq("lev1", targetLev); |
| | | } |
| | | applyLocTypeFilters(wrapper, locTypeDto, true); |
| | | List<LocMast> locMasts = locMastService.selectList(wrapper); |
| | | List<LocMast> sortedLocMasts = sortLocCandidates(locMasts, findLocNoAttributeVo, ignoreFreqType); |
| | | for (LocMast locMast : sortedLocMasts) { |
| | | if (matchesLocType(locMast, locTypeDto)) { |
| | | if (matchesLocType(locMast, locTypeDto) && matchesTargetLev(locMast, targetLev)) { |
| | | result.add(locMast); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 双伸堆垛机同货优先: |
| | | * 先找深库位中同货且状态为 F 的货位,再检查其对应浅库位是否为空。 |
| | | * 空托盘请求则按 matnr=emptyPallet 识别,深位已有空托盘时优先返回对应浅位。 |
| | | */ |
| | | private LocMast findDoubleExtensionSameGoodsPreferredLoc(RowLastno rowLastno, RowLastnoType rowLastnoType, |
| | | Integer crnNo, CrnDepthRuleProfile profile, |
| | | LocTypeDto locTypeDto, FindLocNoAttributeVo findLocNoAttributeVo) { |
| | | if (profile == null || !profile.isDoubleExtension() || findLocNoAttributeVo == null) { |
| | | return null; |
| | | } |
| | | boolean emptyPalletRequest = "emptyPallet".equalsIgnoreCase(findLocNoAttributeVo.getMatnr()); |
| | | String standby1 = findLocNoAttributeVo.getStandby1(); |
| | | if (!emptyPalletRequest && Cools.isEmpty(standby1)) { |
| | | return null; |
| | | } |
| | | List<Integer> orderedShallowRows = orderDoubleExtensionShallowRows(rowLastno, rowLastnoType, crnNo, profile); |
| | | for (Integer shallowRow : orderedShallowRows) { |
| | | Integer deepRow = profile.getPairedDeepRow(shallowRow); |
| | | if (deepRow == null) { |
| | | continue; |
| | | } |
| | | List<LocMast> deepLocs = findOccupiedLocsByRow(deepRow, crnNo, findLocNoAttributeVo); |
| | | if (Cools.isEmpty(deepLocs)) { |
| | | continue; |
| | | } |
| | | List<String> deepLocNos = new ArrayList<String>(); |
| | | for (LocMast deepLoc : deepLocs) { |
| | | if (deepLoc == null || Cools.isEmpty(deepLoc.getLocNo())) { |
| | | continue; |
| | | } |
| | | deepLocNos.add(deepLoc.getLocNo()); |
| | | } |
| | | if (Cools.isEmpty(deepLocNos)) { |
| | | continue; |
| | | } |
| | | EntityWrapper<LocDetl> detlWrapper = new EntityWrapper<LocDetl>(); |
| | | detlWrapper.in("loc_no", deepLocNos); |
| | | if (emptyPalletRequest) { |
| | | detlWrapper.eq("matnr", findLocNoAttributeVo.getMatnr()); |
| | | } else { |
| | | detlWrapper.eq("standby1", standby1); |
| | | } |
| | | List<LocDetl> sameGoodsLocDetls = locDetlService.selectList(detlWrapper); |
| | | if (Cools.isEmpty(sameGoodsLocDetls)) { |
| | | continue; |
| | | } |
| | | LinkedHashSet<String> sameGoodsLocNos = new LinkedHashSet<String>(); |
| | | for (LocDetl locDetl : sameGoodsLocDetls) { |
| | | if (locDetl == null || Cools.isEmpty(locDetl.getLocNo())) { |
| | | continue; |
| | | } |
| | | sameGoodsLocNos.add(locDetl.getLocNo()); |
| | | } |
| | | if (Cools.isEmpty(sameGoodsLocNos)) { |
| | | continue; |
| | | } |
| | | for (LocMast deepLoc : deepLocs) { |
| | | if (deepLoc == null || !sameGoodsLocNos.contains(deepLoc.getLocNo())) { |
| | | continue; |
| | | } |
| | | LocMast shallowLoc = findLocByPosition(rowLastno, rowLastnoType, crnNo, shallowRow, |
| | | deepLoc.getBay1(), deepLoc.getLev1(), "O"); |
| | | if (!Cools.isEmpty(shallowLoc) && matchesLocType(shallowLoc, locTypeDto)) { |
| | | return shallowLoc; |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 双伸堆垛机按当前两侧负载排序浅位搜索顺序。 |
| | | * |
| | | * 负载越低的浅/深配对越优先,避免长期只命中同一侧。 |
| | | */ |
| | | private List<Integer> orderDoubleExtensionShallowRows(RowLastno rowLastno, RowLastnoType rowLastnoType, |
| | | Integer crnNo, CrnDepthRuleProfile profile) { |
| | | List<Integer> orderedShallowRows = new ArrayList<Integer>(); |
| | | if (profile == null || !profile.isDoubleExtension() || Cools.isEmpty(profile.getShallowRows())) { |
| | | return orderedShallowRows; |
| | | } |
| | | orderedShallowRows.addAll(profile.getShallowRows()); |
| | | final Map<Integer, Integer> originalOrder = new HashMap<Integer, Integer>(); |
| | | for (int index = 0; index < orderedShallowRows.size(); index++) { |
| | | originalOrder.put(orderedShallowRows.get(index), index); |
| | | } |
| | | final Map<Integer, Integer> pairLoadCache = new HashMap<Integer, Integer>(); |
| | | for (Integer shallowRow : orderedShallowRows) { |
| | | pairLoadCache.put(shallowRow, countDoubleExtensionPairLoad(rowLastno, rowLastnoType, crnNo, profile, shallowRow)); |
| | | } |
| | | orderedShallowRows.sort(Comparator |
| | | .comparingInt((Integer row) -> pairLoadCache.getOrDefault(row, Integer.MAX_VALUE)) |
| | | .thenComparingInt(row -> originalOrder.getOrDefault(row, Integer.MAX_VALUE))); |
| | | return rotateEqualLoadGroupsByCurrentRow(orderedShallowRows, rowLastno, pairLoadCache); |
| | | } |
| | | |
| | | /** |
| | | * 等载时,按当前排游标旋转组内顺序,避免长期固定命中同一侧深库位。 |
| | | */ |
| | | private List<Integer> rotateEqualLoadGroupsByCurrentRow(List<Integer> orderedRows, RowLastno rowLastno, |
| | | Map<Integer, Integer> pairLoadCache) { |
| | | if (Cools.isEmpty(orderedRows) || rowLastno == null) { |
| | | return orderedRows; |
| | | } |
| | | Integer currentRow = rowLastno.getCurrentRow(); |
| | | if (currentRow == null || currentRow <= 0) { |
| | | return orderedRows; |
| | | } |
| | | List<Integer> rotatedRows = new ArrayList<Integer>(orderedRows.size()); |
| | | int index = 0; |
| | | while (index < orderedRows.size()) { |
| | | Integer currentLoad = pairLoadCache.get(orderedRows.get(index)); |
| | | int groupStart = index; |
| | | while (index < orderedRows.size() && Objects.equals(pairLoadCache.get(orderedRows.get(index)), currentLoad)) { |
| | | index++; |
| | | } |
| | | List<Integer> sameLoadRows = new ArrayList<Integer>(orderedRows.subList(groupStart, index)); |
| | | rotateShallowRowsByCurrentRow(sameLoadRows, currentRow); |
| | | rotatedRows.addAll(sameLoadRows); |
| | | } |
| | | return rotatedRows; |
| | | } |
| | | |
| | | private void rotateShallowRowsByCurrentRow(List<Integer> shallowRows, Integer currentRow) { |
| | | if (Cools.isEmpty(shallowRows) || shallowRows.size() <= 1 || currentRow == null) { |
| | | return; |
| | | } |
| | | int pivotIndex = -1; |
| | | for (int i = 0; i < shallowRows.size(); i++) { |
| | | Integer row = shallowRows.get(i); |
| | | if (row != null && row > currentRow) { |
| | | pivotIndex = i; |
| | | break; |
| | | } |
| | | } |
| | | if (pivotIndex <= 0) { |
| | | return; |
| | | } |
| | | List<Integer> rotated = new ArrayList<Integer>(shallowRows.size()); |
| | | rotated.addAll(shallowRows.subList(pivotIndex, shallowRows.size())); |
| | | rotated.addAll(shallowRows.subList(0, pivotIndex)); |
| | | shallowRows.clear(); |
| | | shallowRows.addAll(rotated); |
| | | } |
| | | |
| | | /** |
| | | * 统计双伸浅/深配对的当前已占用库位数量。 |
| | | */ |
| | | private int countDoubleExtensionPairLoad(RowLastno rowLastno, RowLastnoType rowLastnoType, Integer crnNo, |
| | | CrnDepthRuleProfile profile, Integer shallowRow) { |
| | | if (profile == null || shallowRow == null) { |
| | | return Integer.MAX_VALUE; |
| | | } |
| | | int count = countOccupiedLocsByRow(rowLastno, rowLastnoType, shallowRow, crnNo); |
| | | Integer deepRow = profile.getPairedDeepRow(shallowRow); |
| | | if (deepRow != null) { |
| | | count += countOccupiedLocsByRow(rowLastno, rowLastnoType, deepRow, crnNo); |
| | | } |
| | | return count; |
| | | } |
| | | |
| | | /** |
| | | * 统计某一排当前已占用/预约的库存数量。 |
| | | * |
| | | * 这里把 S/R/P/Q/D/X 都算作负载,避免批量入库时只看 F 导致刚预约出去的库位不参与均衡。 |
| | | */ |
| | | private int countOccupiedLocsByRow(RowLastno rowLastno, RowLastnoType rowLastnoType, Integer row, Integer crnNo) { |
| | | if (row == null) { |
| | | return Integer.MAX_VALUE; |
| | | } |
| | | Wrapper<LocMast> wrapper = new EntityWrapper<LocMast>() |
| | | .eq("row1", row) |
| | | .in("loc_sts", Arrays.asList("F", "S", "R", "P", "Q", "D", "X")); |
| | | if (crnNo != null) { |
| | | wrapper.eq("crn_no", crnNo); |
| | | } |
| | | return locMastService.selectCount(wrapper); |
| | | } |
| | | |
| | | /** |
| | | * 查询某一排上状态为 F 的库位,并按当前频次/前几列策略排序。 |
| | | */ |
| | | private List<LocMast> findOccupiedLocsByRow(Integer row, Integer crnNo, FindLocNoAttributeVo findLocNoAttributeVo) { |
| | | List<LocMast> result = new ArrayList<LocMast>(); |
| | | if (row == null) { |
| | | return result; |
| | | } |
| | | Wrapper<LocMast> wrapper = new EntityWrapper<LocMast>() |
| | | .eq("row1", row) |
| | | .eq("loc_sts", "F"); |
| | | if (crnNo != null) { |
| | | wrapper.eq("crn_no", crnNo); |
| | | } |
| | | List<LocMast> locMasts = locMastService.selectList(wrapper); |
| | | return sortLocCandidates(locMasts, findLocNoAttributeVo, false); |
| | | } |
| | | |
| | | /** |
| | | * 在一对浅排/深排之间选择真正可投放的目标库位。 |
| | | * |
| | | * 双伸位规则: |
| | | * 1. 浅位和深位同列同层都为空时,优先返回深位,避免浅位先占住后挡住深位。 |
| | | * 2. 深位已有货时,允许返回对应浅位。 |
| | | * 3. 深位为空但规格不匹配时,不把浅位作为可投放结果,继续找下一组同列同层位置。 |
| | | */ |
| | | private LocMast findPairAssignableLoc(RowLastno rowLastno, RowLastnoType rowLastnoType, Integer crnNo, |
| | | Integer shallowRow, Integer deepRow, LocTypeDto locTypeDto) { |
| | |
| | | private LocMast findPairAssignableLoc(RowLastno rowLastno, RowLastnoType rowLastnoType, Integer crnNo, |
| | | Integer shallowRow, Integer deepRow, LocTypeDto locTypeDto, |
| | | FindLocNoAttributeVo findLocNoAttributeVo) { |
| | | List<LocMast> shallowOpenLocs = findOpenLocsByRow(rowLastno, rowLastnoType, shallowRow, crnNo, locTypeDto, findLocNoAttributeVo, false); |
| | | return findPairAssignableLoc(rowLastno, rowLastnoType, crnNo, shallowRow, deepRow, locTypeDto, findLocNoAttributeVo, null); |
| | | } |
| | | |
| | | private LocMast findPairAssignableLoc(RowLastno rowLastno, RowLastnoType rowLastnoType, Integer crnNo, |
| | | Integer shallowRow, Integer deepRow, LocTypeDto locTypeDto, |
| | | FindLocNoAttributeVo findLocNoAttributeVo, Integer targetLev) { |
| | | List<LocMast> shallowOpenLocs = findOpenLocsByRow(rowLastno, rowLastnoType, shallowRow, crnNo, locTypeDto, findLocNoAttributeVo, false, false, targetLev); |
| | | if (Cools.isEmpty(shallowOpenLocs)) { |
| | | return null; |
| | | } |
| | |
| | | } |
| | | } |
| | | for (LocMast shallowLoc : shallowOpenLocs) { |
| | | LocMast deepBlockingLoc = findLocByPosition(rowLastno, rowLastnoType, crnNo, deepRow, shallowLoc.getBay1(), shallowLoc.getLev1(), "F", "D"); |
| | | if (!Cools.isEmpty(deepBlockingLoc)) { |
| | | return shallowLoc; |
| | | } |
| | | if (findLocByPosition(rowLastno, rowLastnoType, crnNo, deepRow, shallowLoc.getBay1(), shallowLoc.getLev1()) == null) { |
| | | LocMast deepInStockLoc = findLocByPosition(rowLastno, rowLastnoType, crnNo, deepRow, shallowLoc.getBay1(), shallowLoc.getLev1(), "F"); |
| | | if (!Cools.isEmpty(deepInStockLoc)) { |
| | | return shallowLoc; |
| | | } |
| | | } |
| | |
| | | |
| | | /** |
| | | * 按某台堆垛机的深浅排画像搜索第一个可分配空库位。 |
| | | * |
| | | * 这是空托盘最终落库位的核心选择方法: |
| | | * 1. 先读取堆垛机深浅库位规则画像,得到该堆垛机本次应扫描的排顺序。 |
| | | * 2. 双伸堆垛机先尝试同货优先规则,再按浅排/深排成对判断可投放位置。 |
| | | * 3. 单伸堆垛机直接按排内排序后的空库位返回第一个匹配项。 |
| | | * 4. 排内排序会继续受频次、前几列策略和 locType 过滤影响。 |
| | | */ |
| | | private LocMast findConfiguredEmptyLocForCrn(RowLastno rowLastno, RowLastnoType rowLastnoType, Integer crnNo, |
| | | Integer preferredNearRow, LocTypeDto locTypeDto) { |
| | |
| | | |
| | | private LocMast findConfiguredEmptyLocForCrn(RowLastno rowLastno, RowLastnoType rowLastnoType, Integer crnNo, |
| | | Integer preferredNearRow, LocTypeDto locTypeDto, FindLocNoAttributeVo findLocNoAttributeVo, |
| | | Integer targetLev) { |
| | | return findConfiguredEmptyLocForCrn(rowLastno, rowLastnoType, crnNo, preferredNearRow, locTypeDto, findLocNoAttributeVo, |
| | | false, targetLev); |
| | | } |
| | | |
| | | private LocMast findConfiguredEmptyLocForCrn(RowLastno rowLastno, RowLastnoType rowLastnoType, Integer crnNo, |
| | | Integer preferredNearRow, LocTypeDto locTypeDto, FindLocNoAttributeVo findLocNoAttributeVo, |
| | | boolean ignoreFreqType) { |
| | | return findConfiguredEmptyLocForCrn(rowLastno, rowLastnoType, crnNo, preferredNearRow, locTypeDto, findLocNoAttributeVo, |
| | | ignoreFreqType, null); |
| | | } |
| | | |
| | | private LocMast findConfiguredEmptyLocForCrn(RowLastno rowLastno, RowLastnoType rowLastnoType, Integer crnNo, |
| | | Integer preferredNearRow, LocTypeDto locTypeDto, FindLocNoAttributeVo findLocNoAttributeVo, |
| | | boolean ignoreFreqType, Integer targetLev) { |
| | | if (rowLastno == null || crnNo == null) { |
| | | return null; |
| | | } |
| | |
| | | if (profile == null || Cools.isEmpty(profile.getSearchRows())) { |
| | | return null; |
| | | } |
| | | LinkedHashSet<Integer> processedShallowRows = new LinkedHashSet<Integer>(); |
| | | LocMast sameGoodsPreferredLoc = findDoubleExtensionSameGoodsPreferredLoc(rowLastno, rowLastnoType, crnNo, |
| | | profile, locTypeDto, findLocNoAttributeVo); |
| | | if (!Cools.isEmpty(sameGoodsPreferredLoc) && matchesTargetLev(sameGoodsPreferredLoc, targetLev)) { |
| | | return sameGoodsPreferredLoc; |
| | | } |
| | | boolean singleExtension = profile.isSingleExtension(); |
| | | if (!singleExtension) { |
| | | List<Integer> orderedShallowRows = orderDoubleExtensionShallowRows(rowLastno, rowLastnoType, crnNo, profile); |
| | | for (Integer shallowRow : orderedShallowRows) { |
| | | if (shallowRow == null) { |
| | | continue; |
| | | } |
| | | LocMast candidateLoc = findPairAssignableLoc(rowLastno, rowLastnoType, crnNo, shallowRow, |
| | | profile.getPairedDeepRow(shallowRow), locTypeDto, findLocNoAttributeVo, targetLev); |
| | | if (!Cools.isEmpty(candidateLoc)) { |
| | | return candidateLoc; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | LinkedHashSet<Integer> processedShallowRows = new LinkedHashSet<Integer>(); |
| | | for (Integer searchRow : profile.getSearchRows()) { |
| | | if (searchRow == null) { |
| | | continue; |
| | | } |
| | | if (!singleExtension) { |
| | | if (profile.isShallowRow(searchRow)) { |
| | | if (!processedShallowRows.add(searchRow)) { |
| | | if (profile.isShallowRow(searchRow)) { |
| | | if (!processedShallowRows.add(searchRow)) { |
| | | continue; |
| | | } |
| | | LocMast candidateLoc = findPairAssignableLoc(rowLastno, rowLastnoType, crnNo, searchRow, |
| | | profile.getPairedDeepRow(searchRow), locTypeDto, findLocNoAttributeVo, targetLev); |
| | | if (!Cools.isEmpty(candidateLoc)) { |
| | | return candidateLoc; |
| | | } |
| | | continue; |
| | | } |
| | | if (profile.isDeepRow(searchRow)) { |
| | | Integer shallowRow = profile.getPairedShallowRow(searchRow); |
| | | if (shallowRow != null) { |
| | | if (!processedShallowRows.add(shallowRow)) { |
| | | continue; |
| | | } |
| | | LocMast candidateLoc = findPairAssignableLoc(rowLastno, rowLastnoType, crnNo, searchRow, |
| | | profile.getPairedDeepRow(searchRow), locTypeDto, findLocNoAttributeVo); |
| | | LocMast candidateLoc = findPairAssignableLoc(rowLastno, rowLastnoType, crnNo, shallowRow, |
| | | searchRow, locTypeDto, findLocNoAttributeVo, targetLev); |
| | | if (!Cools.isEmpty(candidateLoc)) { |
| | | return candidateLoc; |
| | | } |
| | | continue; |
| | | } |
| | | if (profile.isDeepRow(searchRow)) { |
| | | Integer shallowRow = profile.getPairedShallowRow(searchRow); |
| | | if (shallowRow != null) { |
| | | if (!processedShallowRows.add(shallowRow)) { |
| | | continue; |
| | | } |
| | | LocMast candidateLoc = findPairAssignableLoc(rowLastno, rowLastnoType, crnNo, shallowRow, |
| | | searchRow, locTypeDto, findLocNoAttributeVo); |
| | | if (!Cools.isEmpty(candidateLoc)) { |
| | | return candidateLoc; |
| | | } |
| | | continue; |
| | | } |
| | | } |
| | | } |
| | | List<LocMast> locMasts = findOpenLocsByRow(rowLastno, rowLastnoType, searchRow, crnNo, locTypeDto, findLocNoAttributeVo, singleExtension, ignoreFreqType); |
| | | List<LocMast> locMasts = findOpenLocsByRow(rowLastno, rowLastnoType, searchRow, crnNo, locTypeDto, findLocNoAttributeVo, singleExtension, ignoreFreqType, targetLev); |
| | | if (!Cools.isEmpty(locMasts)) { |
| | | return locMasts.get(0); |
| | | } |
| | |
| | | count++; |
| | | continue; |
| | | } |
| | | LocMast deepBlockingLoc = findLocByPosition(rowLastno, rowLastnoType, crnNo, deepRow, shallowLoc.getBay1(), shallowLoc.getLev1(), "F", "D"); |
| | | if (!Cools.isEmpty(deepBlockingLoc) || |
| | | findLocByPosition(rowLastno, rowLastnoType, crnNo, deepRow, shallowLoc.getBay1(), shallowLoc.getLev1()) == null) { |
| | | LocMast deepInStockLoc = findLocByPosition(rowLastno, rowLastnoType, crnNo, deepRow, shallowLoc.getBay1(), shallowLoc.getLev1(), "F"); |
| | | if (!Cools.isEmpty(deepInStockLoc)) { |
| | | count++; |
| | | } |
| | | } |
| | |
| | | * 当前方法只保留“组织流程”和“统一收口”的职责,具体策略拆成独立方法: |
| | | * 1. 先按站点第一优先池找位,再找第二优先池。 |
| | | * 2. 池内按 current_no 轮转,从下一台堆垛机开始平均分配。 |
| | | * 3. 空托盘先按 loc_type2=1 搜索,同池无结果再允许其它库位。 |
| | | * 4. 低库位可向上兼容,兼容重试仍保持两层优先池顺序。 |
| | | * 3. 空托盘由 matnr=emptyPallet 或 staDescId=10 识别,先找窄库位,失败后用 loc_type1=3 兜底。 |
| | | * 4. 普通托盘只做 loc_type1 向上兼容,并排除空托盘专用窄库位。 |
| | | */ |
| | | @Transactional |
| | | public StartupDto getLocNoRun2(Integer whsType, Integer staDescId, Integer sourceStaNo, FindLocNoAttributeVo findLocNoAttributeVo, Integer moveCrnNo, LocTypeDto locTypeDto, List<Integer> recommendRows, int times) { |