| | |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.ArrayList; |
| | | import java.util.Comparator; |
| | | import java.util.HashMap; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.LinkedHashSet; |
| | | import java.util.List; |
| | | import java.util.Locale; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.Optional; |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * 检索库位号 |
| | | * 入库找库位统一入口。 |
| | | * |
| | | * 空托盘入库也从这里进入,先由 {@link #normalizeLocTypeDto(Integer, FindLocNoAttributeVo, LocTypeDto)} |
| | | * 统一识别空托盘和整理库位规格,再按 row_lastno_type 分流到不同库型的找位实现。 |
| | | * |
| | | * @param staDescId 路径ID |
| | | * @param sourceStaNo 源站 |
| | |
| | | Integer whsType = Utils.GetWhsType(sourceStaNo); |
| | | RowLastno rowLastno = rowLastnoService.selectById(whsType); |
| | | RowLastnoType rowLastnoType = rowLastnoTypeService.selectById(rowLastno.getTypeId()); |
| | | List<Integer> stationAreas = Utils.getStationStorageAreas(sourceStaNo); |
| | | findLocNoAttributeVo.setOutAreas(stationAreas); |
| | | Integer preferredArea = resolvePreferredArea(sourceStaNo, findLocNoAttributeVo); |
| | | if (preferredArea != null) { |
| | | findLocNoAttributeVo.setOutArea(preferredArea); |
| | |
| | | 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: |
| | |
| | | log.error("站点={} 查找库位异常", sourceStaNo, e); |
| | | throw new CoolException("站点=" + sourceStaNo + " 查找库位失败"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 供 6.15 重分配接口复用:按外部指定的堆垛机顺序,在指定库区内找新的入库位。 |
| | | * |
| | | * 这里不推进 row_lastno 游标,只负责一次性的路径校验 + 设备校验 + 空库位搜索。 |
| | | */ |
| | | public StartupDto findRun2InboundLocByCandidateCrnNos(Integer sourceStaNo, Integer staDescId, Integer preferredArea, |
| | | List<Integer> candidateCrnNos, LocTypeDto locTypeDto) { |
| | | if (sourceStaNo == null) { |
| | | throw new CoolException("源站不能为空"); |
| | | } |
| | | if (Cools.isEmpty(candidateCrnNos)) { |
| | | return null; |
| | | } |
| | | Integer whsType = Utils.GetWhsType(sourceStaNo); |
| | | RowLastno defaultRowLastno = rowLastnoService.selectById(whsType); |
| | | if (Cools.isEmpty(defaultRowLastno)) { |
| | | throw new CoolException("站点=" + sourceStaNo + " 未查询到对应的库位规则"); |
| | | } |
| | | RowLastno searchRowLastno = defaultRowLastno; |
| | | if (preferredArea != null && preferredArea > 0) { |
| | | RowLastno areaRowLastno = rowLastnoService.selectById(preferredArea); |
| | | if (Cools.isEmpty(areaRowLastno)) { |
| | | throw new CoolException("未找到库区轮询规则"); |
| | | } |
| | | searchRowLastno = areaRowLastno; |
| | | } |
| | | RowLastnoType rowLastnoType = rowLastnoTypeService.selectById(searchRowLastno.getTypeId()); |
| | | 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"); |
| | | if (Cools.isEmpty(locMast) || !"O".equals(locMast.getLocSts())) { |
| | | return null; |
| | | } |
| | | startupDto.setSourceStaNo(sourceStaNo); |
| | | startupDto.setCrnNo(locMast.getCrnNo()); |
| | | startupDto.setLocNo(locMast.getLocNo()); |
| | | return startupDto; |
| | | } |
| | | |
| | | /** |
| | |
| | | * 统一整理入库规格,避免不同入口传入的 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. 严格高度 + any locType2 |
| | | * 3. 向上兼容高度 + narrow |
| | | * 4. 向上兼容高度 + any locType2 |
| | | * 2. 向上兼容高度 + narrow |
| | | * 3. loc_type1=3 + open |
| | | */ |
| | | private List<LocTypeDto> buildEmptyPalletSearchLocTypes(LocTypeDto locTypeDto) { |
| | | LinkedHashSet<LocTypeDto> searchLocTypes = new LinkedHashSet<LocTypeDto>(); |
| | | LocTypeDto narrowStrictLocType = copyLocTypeDto(locTypeDto == null ? new LocTypeDto() : locTypeDto); |
| | | if (narrowStrictLocType != null) { |
| | | narrowStrictLocType.setLocType2((short) 1); |
| | | searchLocTypes.add(narrowStrictLocType); |
| | | LocTypeDto openStrictLocType = copyLocTypeDto(narrowStrictLocType); |
| | | openStrictLocType.setLocType2(null); |
| | | searchLocTypes.add(openStrictLocType); |
| | | |
| | | LocTypeDto narrowCompatibleLocType = buildUpwardCompatibleLocTypeDto(narrowStrictLocType); |
| | | if (narrowCompatibleLocType != null) { |
| | | narrowCompatibleLocType.setLocType2((short) 1); |
| | | searchLocTypes.add(narrowCompatibleLocType); |
| | | LocTypeDto openCompatibleLocType = copyLocTypeDto(narrowCompatibleLocType); |
| | | openCompatibleLocType.setLocType2(null); |
| | | searchLocTypes.add(openCompatibleLocType); |
| | | } |
| | | List<LocTypeDto> searchLocTypes = new ArrayList<LocTypeDto>(); |
| | | LocTypeDto baseLocTypeDto = copyLocTypeDto(locTypeDto == null ? new LocTypeDto() : locTypeDto); |
| | | if (baseLocTypeDto == null) { |
| | | return searchLocTypes; |
| | | } |
| | | return new ArrayList<LocTypeDto>(searchLocTypes); |
| | | |
| | | LocTypeDto narrowStrictLocType = copyLocTypeDto(baseLocTypeDto); |
| | | narrowStrictLocType.setLocType2((short) 1); |
| | | searchLocTypes.add(narrowStrictLocType); |
| | | |
| | | LocTypeDto narrowCompatibleLocType = buildUpwardCompatibleLocTypeDto(narrowStrictLocType); |
| | | if (narrowCompatibleLocType != null) { |
| | | narrowCompatibleLocType.setLocType2((short) 1); |
| | | searchLocTypes.add(narrowCompatibleLocType); |
| | | } |
| | | |
| | | 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) { |
| | |
| | | * 解析本次找位应优先使用的库区,站点绑定优先于接口传参。 |
| | | */ |
| | | private Integer resolvePreferredArea(Integer sourceStaNo, FindLocNoAttributeVo findLocNoAttributeVo) { |
| | | BasDevp sourceStation = basDevpService.selectById(sourceStaNo); |
| | | Integer stationArea = parseArea(sourceStation == null ? null : sourceStation.getArea()); |
| | | Integer stationArea = Utils.getStationStorageArea(sourceStaNo); |
| | | if (stationArea != null) { |
| | | return stationArea; |
| | | } |
| | | Integer requestArea = findLocNoAttributeVo.getOutArea(); |
| | | if (requestArea != null && requestArea >= 1 && requestArea <= 3) { |
| | | if (isValidArea(requestArea)) { |
| | | return requestArea; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 把站点维护的库区值统一解析成 1/2/3。 |
| | | */ |
| | | private Integer parseArea(String area) { |
| | | if (Cools.isEmpty(area)) { |
| | | return null; |
| | | } |
| | | String normalized = area.trim(); |
| | | if (normalized.isEmpty()) { |
| | | return null; |
| | | } |
| | | try { |
| | | int areaNo = Integer.parseInt(normalized); |
| | | return areaNo >= 1 && areaNo <= 3 ? areaNo : null; |
| | | } catch (NumberFormatException ignored) { |
| | | } |
| | | String upper = normalized.toUpperCase(Locale.ROOT); |
| | | if ("A".equals(upper) || "A区".equals(upper) || "A库".equals(upper) || "A库区".equals(upper)) { |
| | | return 1; |
| | | } |
| | | if ("B".equals(upper) || "B区".equals(upper) || "B库".equals(upper) || "B库区".equals(upper)) { |
| | | return 2; |
| | | } |
| | | if ("C".equals(upper) || "C区".equals(upper) || "C库".equals(upper) || "C库区".equals(upper)) { |
| | | return 3; |
| | | } |
| | | return null; |
| | | private boolean isValidArea(Integer area) { |
| | | return area != null && area >= 1 && area <= 3; |
| | | } |
| | | |
| | | /** |
| | |
| | | private LocMast findAgvLocByRows(RowLastno rowLastno, RowLastnoType rowLastnoType, List<Integer> rows, |
| | | int startBay, int endBay, int curRow, int nearRow, |
| | | LocTypeDto locTypeDto, boolean useDeepCheck) { |
| | | return findAgvLocByRows(rowLastno, rowLastnoType, rows, startBay, endBay, curRow, nearRow, locTypeDto, null, useDeepCheck); |
| | | } |
| | | |
| | | private LocMast findAgvLocByRows(RowLastno rowLastno, RowLastnoType rowLastnoType, List<Integer> rows, |
| | | int startBay, int endBay, int curRow, int nearRow, |
| | | LocTypeDto locTypeDto, FindLocNoAttributeVo findLocNoAttributeVo, boolean useDeepCheck) { |
| | | for (Integer row : rows) { |
| | | if (row == null) { |
| | | continue; |
| | |
| | | applyLocTypeFilters(wrapper, locTypeDto, true); |
| | | wrapper.orderBy("lev1", true).orderBy("bay1", true); |
| | | List<LocMast> locMasts = locMastService.selectList(wrapper); |
| | | for (LocMast candidate : locMasts) { |
| | | List<LocMast> sortedLocMasts = sortLocCandidates(locMasts, findLocNoAttributeVo); |
| | | for (LocMast candidate : sortedLocMasts) { |
| | | if (!VersionUtils.locMoveCheckLocTypeComplete(candidate, locTypeDto)) { |
| | | continue; |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 构造空托盘跨库区搜索顺序: |
| | | * 先当前库区,再依次补足其它库区,避免重复。 |
| | | * 读取站点配置的优先池堆垛机号并做去重。 |
| | | */ |
| | | private List<Integer> buildAreaSearchOrder(Integer preferredArea) { |
| | | private List<Integer> loadPriorityCrnNos(String csv) { |
| | | return Utils.distinctCrnNos(csv); |
| | | } |
| | | |
| | | /** |
| | | * 从候选堆垛机池中移除已经出现在排除列表里的堆垛机,保持原始顺序不变。 |
| | | */ |
| | | private List<Integer> excludePriorityCrnNos(List<Integer> crnNos, List<Integer> excludedCrnNos) { |
| | | List<Integer> result = new ArrayList<Integer>(); |
| | | if (Cools.isEmpty(crnNos)) { |
| | | return result; |
| | | } |
| | | LinkedHashSet<Integer> excludedCrnNoSet = new LinkedHashSet<Integer>(Utils.distinctCrnNos(excludedCrnNos)); |
| | | for (Integer crnNo : Utils.distinctCrnNos(crnNos)) { |
| | | if (crnNo == null || excludedCrnNoSet.contains(crnNo)) { |
| | | continue; |
| | | } |
| | | result.add(crnNo); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 从当前游标的下一台堆垛机开始轮转。 |
| | | */ |
| | | private List<Integer> rotatePriorityCrnNos(List<Integer> crnNos, Integer currentCrnNo) { |
| | | List<Integer> orderedCrnNos = Utils.distinctCrnNos(crnNos); |
| | | if (Cools.isEmpty(orderedCrnNos) || currentCrnNo == null) { |
| | | return orderedCrnNos; |
| | | } |
| | | int currentIndex = orderedCrnNos.indexOf(currentCrnNo); |
| | | if (currentIndex < 0) { |
| | | return orderedCrnNos; |
| | | } |
| | | List<Integer> rotatedCrnNos = new ArrayList<>(); |
| | | for (int index = currentIndex + 1; index < orderedCrnNos.size(); index++) { |
| | | rotatedCrnNos.add(orderedCrnNos.get(index)); |
| | | } |
| | | for (int index = 0; index <= currentIndex; index++) { |
| | | rotatedCrnNos.add(orderedCrnNos.get(index)); |
| | | } |
| | | return rotatedCrnNos; |
| | | } |
| | | |
| | | /** |
| | | * run2 站点优先池找位入口。 |
| | | * |
| | | * 空托盘规则: |
| | | * 1. 先找站点第一优先池,再找第二优先池;第二池会排除第一池已配置的堆垛机。 |
| | | * 2. 每个优先池内先找窄库位,再做高度向上兼容,最后把 loc_type1 改为 3 兜底。 |
| | | * 3. 只有命中库位的池会推进自己的 currentNo 游标,未命中的池不改变轮询状态。 |
| | | */ |
| | | private LocMast findRun2PriorityLocInPools(BasDevp station, RowLastno rowLastno, RowLastnoType rowLastnoType, |
| | | Integer staDescId, Integer sourceStaNo, FindLocNoAttributeVo findLocNoAttributeVo, |
| | | LocTypeDto locTypeDto, StartupDto startupDto, boolean emptyPalletRequest) { |
| | | if (station == null) { |
| | | return null; |
| | | } |
| | | List<Integer> firstPoolCrnNos = loadPriorityCrnNos(station.getInFirstCrnCsv()); |
| | | List<Integer> secondPoolCrnNos = excludePriorityCrnNos(loadPriorityCrnNos(station.getInSecondCrnCsv()), firstPoolCrnNos); |
| | | if (Cools.isEmpty(firstPoolCrnNos) && Cools.isEmpty(secondPoolCrnNos)) { |
| | | throw new CoolException("站点=" + station.getDevNo() + " 未配置入库优先堆垛机"); |
| | | } |
| | | |
| | | if (emptyPalletRequest) { |
| | | for (int poolNo = 1; poolNo <= 2; poolNo++) { |
| | | List<Integer> poolCrnNos = poolNo == 1 ? firstPoolCrnNos : secondPoolCrnNos; |
| | | Integer currentCrnNo = poolNo == 1 ? station.getInFirstCrnCurrentNo() : station.getInSecondCrnCurrentNo(); |
| | | for (LocTypeDto searchLocTypeDto : buildEmptyPalletSearchLocTypes(locTypeDto)) { |
| | | LocMast locMast = findRun2PriorityLocInPool(rowLastno, rowLastnoType, station, poolCrnNos, currentCrnNo, |
| | | poolNo, searchLocTypeDto, staDescId, sourceStaNo, findLocNoAttributeVo, startupDto, true); |
| | | if (locMast != null) { |
| | | return locMast; |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | LocMast locMast = findRun2PriorityLocInPoolWithCompatibility(rowLastno, rowLastnoType, station, firstPoolCrnNos, |
| | | station.getInFirstCrnCurrentNo(), 1, locTypeDto, staDescId, sourceStaNo, findLocNoAttributeVo, startupDto, false); |
| | | if (locMast != null) { |
| | | return locMast; |
| | | } |
| | | return findRun2PriorityLocInPoolWithCompatibility(rowLastno, rowLastnoType, station, secondPoolCrnNos, |
| | | station.getInSecondCrnCurrentNo(), 2, locTypeDto, staDescId, sourceStaNo, findLocNoAttributeVo, startupDto, false); |
| | | } |
| | | |
| | | /** |
| | | * 在单个优先池内按轮转顺序找位。 |
| | | * |
| | | * 池内规则: |
| | | * 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, |
| | | Integer staDescId, Integer sourceStaNo, FindLocNoAttributeVo findLocNoAttributeVo, |
| | | StartupDto startupDto) { |
| | | return findRun2PriorityLocInPool(rowLastno, rowLastnoType, station, crnNos, currentCrnNo, poolNo, locTypeDto, |
| | | staDescId, sourceStaNo, findLocNoAttributeVo, startupDto, false); |
| | | } |
| | | |
| | | private LocMast findRun2PriorityLocInPool(RowLastno rowLastno, RowLastnoType rowLastnoType, BasDevp station, |
| | | List<Integer> crnNos, Integer currentCrnNo, int poolNo, LocTypeDto locTypeDto, |
| | | Integer staDescId, Integer sourceStaNo, FindLocNoAttributeVo findLocNoAttributeVo, |
| | | StartupDto startupDto, boolean ignoreFreqType) { |
| | | if (Cools.isEmpty(crnNos)) { |
| | | return null; |
| | | } |
| | | List<Integer> rotatedCrnNos = rotatePriorityCrnNos(crnNos, currentCrnNo); |
| | | if (Cools.isEmpty(rotatedCrnNos)) { |
| | | return null; |
| | | } |
| | | for (Integer candidateCrnNo : rotatedCrnNos) { |
| | | if (candidateCrnNo == null || !basCrnpService.checkSiteError(candidateCrnNo, true)) { |
| | | continue; |
| | | } |
| | | Integer targetStaNo = resolveTargetStaNo(rowLastno, staDescId, sourceStaNo, candidateCrnNo); |
| | | if (Utils.BooleanWhsTypeSta(rowLastno, staDescId) && targetStaNo == null) { |
| | | continue; |
| | | } |
| | | Integer preferredNearRow = getCrnStartRow(rowLastno, candidateCrnNo); |
| | | LocMast candidateLoc = findConfiguredEmptyLocForCrn(rowLastno, rowLastnoType, candidateCrnNo, |
| | | preferredNearRow, locTypeDto, findLocNoAttributeVo, ignoreFreqType); |
| | | if (Cools.isEmpty(candidateLoc)) { |
| | | continue; |
| | | } |
| | | if (!updatePriorityCursor(station, poolNo, currentCrnNo, candidateCrnNo)) { |
| | | throw new CoolException("站点=" + station.getDevNo() + " 优先池轮转更新失败,请重试"); |
| | | } |
| | | if (targetStaNo != null) { |
| | | startupDto.setStaNo(targetStaNo); |
| | | } |
| | | return candidateLoc; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 普通托盘的优先池规格兼容入口。 |
| | | * |
| | | * 空托盘不走这个方法,因为空托盘已经在 {@link #buildEmptyPalletSearchLocTypes(LocTypeDto)} |
| | | * 中固定展开了“窄库位优先 + 高度向上兼容 + loc_type1=3 兜底”的顺序。 |
| | | */ |
| | | private LocMast findRun2PriorityLocInPoolWithCompatibility(RowLastno rowLastno, RowLastnoType rowLastnoType, |
| | | BasDevp station, List<Integer> crnNos, Integer currentCrnNo, |
| | | int poolNo, LocTypeDto locTypeDto, Integer staDescId, |
| | | Integer sourceStaNo, FindLocNoAttributeVo findLocNoAttributeVo, |
| | | StartupDto startupDto, boolean ignoreFreqType) { |
| | | LocMast locMast = findRun2PriorityLocInPool(rowLastno, rowLastnoType, station, crnNos, currentCrnNo, poolNo, |
| | | locTypeDto, staDescId, sourceStaNo, findLocNoAttributeVo, startupDto, ignoreFreqType); |
| | | if (locMast != null) { |
| | | return locMast; |
| | | } |
| | | LocTypeDto compatibleLocTypeDto = buildRetryCompatibleLocTypeDto(staDescId, findLocNoAttributeVo, locTypeDto); |
| | | if (compatibleLocTypeDto == null) { |
| | | return null; |
| | | } |
| | | return findRun2PriorityLocInPool(rowLastno, rowLastnoType, station, crnNos, currentCrnNo, poolNo, |
| | | compatibleLocTypeDto, staDescId, sourceStaNo, findLocNoAttributeVo, startupDto, ignoreFreqType); |
| | | } |
| | | |
| | | /** |
| | | * 以乐观方式回写优先池游标。 |
| | | */ |
| | | private boolean updatePriorityCursor(BasDevp station, int poolNo, Integer expectedCurrentNo, Integer selectedCrnNo) { |
| | | if (station == null || station.getDevNo() == null || selectedCrnNo == null) { |
| | | return false; |
| | | } |
| | | BasDevp updateStation = new BasDevp(); |
| | | String cursorColumn; |
| | | if (poolNo == 1) { |
| | | updateStation.setInFirstCrnCurrentNo(selectedCrnNo); |
| | | cursorColumn = "in_first_crn_current_no"; |
| | | } else { |
| | | updateStation.setInSecondCrnCurrentNo(selectedCrnNo); |
| | | cursorColumn = "in_second_crn_current_no"; |
| | | } |
| | | EntityWrapper<BasDevp> wrapper = new EntityWrapper<>(); |
| | | wrapper.eq("dev_no", station.getDevNo()); |
| | | if (expectedCurrentNo == null) { |
| | | wrapper.isNull(cursorColumn); |
| | | } else { |
| | | wrapper.eq(cursorColumn, expectedCurrentNo); |
| | | } |
| | | if (basDevpService.update(updateStation, wrapper)) { |
| | | return true; |
| | | } |
| | | BasDevp latestStation = basDevpService.selectById(station.getDevNo()); |
| | | if (latestStation == null) { |
| | | return false; |
| | | } |
| | | Integer latestCurrentNo = poolNo == 1 ? latestStation.getInFirstCrnCurrentNo() : latestStation.getInSecondCrnCurrentNo(); |
| | | return Objects.equals(latestCurrentNo, selectedCrnNo); |
| | | } |
| | | |
| | | /** |
| | | * 组装优先池预览数据。 |
| | | */ |
| | | private Map<String, Object> buildPriorityPoolPreview(RowLastno rowLastno, RowLastnoType rowLastnoType, int poolNo, |
| | | List<Integer> crnNos, Integer currentCrnNo, Integer staDescId, |
| | | Integer sourceStaNo, LocTypeDto locTypeDto, |
| | | FindLocNoAttributeVo findLocNoAttributeVo) { |
| | | return buildPriorityPoolPreview(rowLastno, rowLastnoType, poolNo, crnNos, currentCrnNo, staDescId, sourceStaNo, |
| | | locTypeDto, findLocNoAttributeVo, false); |
| | | } |
| | | |
| | | private Map<String, Object> buildPriorityPoolPreview(RowLastno rowLastno, RowLastnoType rowLastnoType, int poolNo, |
| | | List<Integer> crnNos, Integer currentCrnNo, Integer staDescId, |
| | | Integer sourceStaNo, LocTypeDto locTypeDto, |
| | | FindLocNoAttributeVo findLocNoAttributeVo, boolean ignoreFreqType) { |
| | | Map<String, Object> item = new HashMap<String, Object>(); |
| | | List<Integer> configuredCrnNos = Utils.distinctCrnNos(crnNos); |
| | | List<Integer> rotatedCrnNos = rotatePriorityCrnNos(configuredCrnNos, currentCrnNo); |
| | | item.put("poolNo", poolNo); |
| | | item.put("currentCrnNo", currentCrnNo); |
| | | item.put("configuredCrnNos", configuredCrnNos); |
| | | item.put("rotatedCrnNos", rotatedCrnNos); |
| | | item.put("runnableCrnNos", getOrderedRunnableRun2CrnNos(rowLastno, staDescId, sourceStaNo, rotatedCrnNos)); |
| | | item.put("profiles", buildRun2ProfilePreview(rowLastno, rowLastnoType, rotatedCrnNos, staDescId, sourceStaNo, |
| | | locTypeDto, findLocNoAttributeVo, ignoreFreqType)); |
| | | return item; |
| | | } |
| | | |
| | | /** |
| | | * 构造空托盘跨库区搜索顺序: |
| | | * 先站点绑定库区,再补请求库区,最后回退全仓库区,避免重复。 |
| | | */ |
| | | private List<Integer> buildAreaSearchOrder(List<Integer> preferredAreas, Integer requestArea) { |
| | | LinkedHashSet<Integer> areaOrder = new LinkedHashSet<>(); |
| | | if (preferredArea != null && preferredArea >= 1 && preferredArea <= 3) { |
| | | areaOrder.add(preferredArea); |
| | | if (!Cools.isEmpty(preferredAreas)) { |
| | | for (Integer area : preferredAreas) { |
| | | if (isValidArea(area)) { |
| | | areaOrder.add(area); |
| | | } |
| | | } |
| | | } |
| | | if (isValidArea(requestArea)) { |
| | | areaOrder.add(requestArea); |
| | | } |
| | | for (int area = 1; area <= 3; area++) { |
| | | areaOrder.add(area); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 预览 run2 当前会参与的库区、堆垛机顺序和深浅排画像,不落任务档。 |
| | | * 预览 run2 当前会参与的优先池、堆垛机顺序和深浅排画像,不落任务档。 |
| | | */ |
| | | public Map<String, Object> previewRun2Allocation(BasCrnDepthRuleRuntimePreviewParam param) { |
| | | if (param == null || param.getStaDescId() == null || param.getSourceStaNo() == null) { |
| | |
| | | FindLocNoAttributeVo findLocNoAttributeVo = new FindLocNoAttributeVo(); |
| | | findLocNoAttributeVo.setMatnr(param.getMatnr()); |
| | | findLocNoAttributeVo.setOutArea(param.getOutArea()); |
| | | findLocNoAttributeVo.setFreqType(param.getFreqType()); |
| | | |
| | | LocTypeDto locTypeDto = new LocTypeDto(); |
| | | locTypeDto.setLocType1(param.getLocType1()); |
| | |
| | | throw new CoolException("未找到仓库轮询规则"); |
| | | } |
| | | RowLastnoType rowLastnoType = rowLastnoTypeService.selectById(rowLastno.getTypeId()); |
| | | Integer preferredArea = resolvePreferredArea(param.getSourceStaNo(), findLocNoAttributeVo); |
| | | List<Integer> stationAreas = Utils.getStationStorageAreas(param.getSourceStaNo()); |
| | | boolean emptyPalletRequest = isEmptyPalletRequest(param.getStaDescId(), findLocNoAttributeVo); |
| | | BasDevp station = basDevpService.selectById(param.getSourceStaNo()); |
| | | if (Cools.isEmpty(station)) { |
| | | throw new CoolException("站点=" + param.getSourceStaNo() + " 未配置入库优先堆垛机"); |
| | | } |
| | | List<Integer> firstPoolCrnNos = loadPriorityCrnNos(station.getInFirstCrnCsv()); |
| | | List<Integer> secondPoolCrnNos = excludePriorityCrnNos(loadPriorityCrnNos(station.getInSecondCrnCsv()), firstPoolCrnNos); |
| | | |
| | | Map<String, Object> result = new HashMap<String, Object>(); |
| | | result.put("whsType", whsType); |
| | | result.put("preferredArea", preferredArea); |
| | | result.put("preferredArea", findLocNoAttributeVo.getOutArea()); |
| | | result.put("preferredAreas", stationAreas); |
| | | result.put("emptyPallet", emptyPalletRequest); |
| | | result.put("locType", locTypeDto); |
| | | result.put("stationPriorityEntries", Utils.getStationStorageAreaName( |
| | | param.getSourceStaNo(), |
| | | locTypeDto == null || locTypeDto.getLocType1() == null ? null : locTypeDto.getLocType1().intValue(), |
| | | findLocNoAttributeVo.getMatnr())); |
| | | result.put("firstPriorityCrnNos", firstPoolCrnNos); |
| | | result.put("secondPriorityCrnNos", secondPoolCrnNos); |
| | | result.put("firstPriorityCurrentNo", station.getInFirstCrnCurrentNo()); |
| | | result.put("secondPriorityCurrentNo", station.getInSecondCrnCurrentNo()); |
| | | result.put("firstPriorityRotatedCrnNos", rotatePriorityCrnNos(firstPoolCrnNos, station.getInFirstCrnCurrentNo())); |
| | | result.put("secondPriorityRotatedCrnNos", rotatePriorityCrnNos(secondPoolCrnNos, station.getInSecondCrnCurrentNo())); |
| | | |
| | | List<Integer> orderedCrnNos = getOrderedCrnNos(rowLastno, resolveRun2CrnNo(rowLastno)); |
| | | List<Integer> runnableCrnNos = getOrderedRunnableRun2CrnNos(rowLastno, param.getStaDescId(), param.getSourceStaNo(), orderedCrnNos); |
| | | result.put("orderedCrnNos", orderedCrnNos); |
| | | result.put("runnableCrnNos", runnableCrnNos); |
| | | List<Map<String, Object>> poolPreviews = new ArrayList<Map<String, Object>>(); |
| | | |
| | | if (emptyPalletRequest) { |
| | | List<Integer> areaSearchOrder = buildAreaSearchOrder(preferredArea); |
| | | List<Map<String, Object>> searchStages = new ArrayList<Map<String, Object>>(); |
| | | for (LocTypeDto stageLocTypeDto : buildEmptyPalletSearchLocTypes(locTypeDto)) { |
| | | List<Map<String, Object>> areaPreviews = new ArrayList<Map<String, Object>>(); |
| | | for (Integer area : areaSearchOrder) { |
| | | RowLastno areaRowLastno = getAreaRowLastno(area, rowLastno); |
| | | RowLastnoType areaRowLastnoType = rowLastnoTypeService.selectById(areaRowLastno.getTypeId()); |
| | | List<Integer> areaOrderedCrnNos = getOrderedCrnNos(areaRowLastno, resolveRun2CrnNo(areaRowLastno)); |
| | | List<Integer> areaRunnableCrnNos = getOrderedRunnableRun2CrnNos(areaRowLastno, param.getStaDescId(), |
| | | param.getSourceStaNo(), areaOrderedCrnNos, false); |
| | | Map<String, Object> areaItem = new HashMap<String, Object>(); |
| | | areaItem.put("area", area); |
| | | areaItem.put("orderedCrnNos", areaOrderedCrnNos); |
| | | areaItem.put("runnableCrnNos", areaRunnableCrnNos); |
| | | areaItem.put("profiles", buildRun2ProfilePreview(areaRowLastno, areaRowLastnoType, areaOrderedCrnNos, |
| | | param.getStaDescId(), param.getSourceStaNo(), stageLocTypeDto)); |
| | | areaPreviews.add(areaItem); |
| | | for (int poolNo = 1; poolNo <= 2; poolNo++) { |
| | | List<Integer> poolCrnNos = poolNo == 1 ? firstPoolCrnNos : secondPoolCrnNos; |
| | | Integer currentCrnNo = poolNo == 1 ? station.getInFirstCrnCurrentNo() : station.getInSecondCrnCurrentNo(); |
| | | Map<String, Object> poolPreview = buildPriorityPoolPreview(rowLastno, rowLastnoType, poolNo, poolCrnNos, |
| | | currentCrnNo, param.getStaDescId(), param.getSourceStaNo(), locTypeDto, findLocNoAttributeVo, true); |
| | | List<Map<String, Object>> stagePreviews = new ArrayList<Map<String, Object>>(); |
| | | for (LocTypeDto stageLocTypeDto : buildEmptyPalletSearchLocTypes(locTypeDto)) { |
| | | Map<String, Object> stagePreview = buildPriorityPoolPreview(rowLastno, rowLastnoType, poolNo, poolCrnNos, |
| | | currentCrnNo, param.getStaDescId(), param.getSourceStaNo(), stageLocTypeDto, findLocNoAttributeVo, true); |
| | | stagePreview.put("stageCode", buildEmptyPalletStageCode(locTypeDto, stageLocTypeDto)); |
| | | stagePreview.put("locType", stageLocTypeDto); |
| | | stagePreviews.add(stagePreview); |
| | | } |
| | | Map<String, Object> stageItem = new HashMap<String, Object>(); |
| | | stageItem.put("stageCode", buildEmptyPalletStageCode(locTypeDto, stageLocTypeDto)); |
| | | stageItem.put("locType", stageLocTypeDto); |
| | | stageItem.put("areaSearchOrder", areaSearchOrder); |
| | | stageItem.put("areaPreviews", areaPreviews); |
| | | searchStages.add(stageItem); |
| | | poolPreview.put("stagePreviews", stagePreviews); |
| | | poolPreviews.add(poolPreview); |
| | | } |
| | | result.put("areaSearchOrder", areaSearchOrder); |
| | | result.put("searchStages", searchStages); |
| | | result.put("poolPreviews", poolPreviews); |
| | | return result; |
| | | } |
| | | |
| | | if (preferredArea != null) { |
| | | List<Integer> preferredCrnNos = filterCrnNosByRows(rowLastno, orderedCrnNos, getRun2AreaRows(preferredArea, rowLastno)); |
| | | result.put("candidateCrnNos", preferredCrnNos); |
| | | result.put("profiles", buildRun2ProfilePreview(rowLastno, rowLastnoType, preferredCrnNos, |
| | | param.getStaDescId(), param.getSourceStaNo(), locTypeDto)); |
| | | result.put("areaMode", "preferred-area-only"); |
| | | return result; |
| | | } |
| | | |
| | | result.put("candidateCrnNos", orderedCrnNos); |
| | | result.put("profiles", buildRun2ProfilePreview(rowLastno, rowLastnoType, orderedCrnNos, |
| | | param.getStaDescId(), param.getSourceStaNo(), locTypeDto)); |
| | | result.put("areaMode", "warehouse-round-robin"); |
| | | poolPreviews.add(buildPriorityPoolPreview(rowLastno, rowLastnoType, 1, firstPoolCrnNos, |
| | | station.getInFirstCrnCurrentNo(), param.getStaDescId(), param.getSourceStaNo(), locTypeDto, |
| | | findLocNoAttributeVo)); |
| | | poolPreviews.add(buildPriorityPoolPreview(rowLastno, rowLastnoType, 2, secondPoolCrnNos, |
| | | station.getInSecondCrnCurrentNo(), param.getStaDescId(), param.getSourceStaNo(), locTypeDto, |
| | | findLocNoAttributeVo)); |
| | | result.put("poolPreviews", poolPreviews); |
| | | return result; |
| | | } |
| | | |
| | |
| | | * 组装某批堆垛机的运行时画像预览数据。 |
| | | */ |
| | | private List<Map<String, Object>> buildRun2ProfilePreview(RowLastno rowLastno, RowLastnoType rowLastnoType, List<Integer> crnNos, |
| | | Integer staDescId, Integer sourceStaNo, LocTypeDto locTypeDto) { |
| | | Integer staDescId, Integer sourceStaNo, LocTypeDto locTypeDto, |
| | | FindLocNoAttributeVo findLocNoAttributeVo) { |
| | | return buildRun2ProfilePreview(rowLastno, rowLastnoType, crnNos, staDescId, sourceStaNo, locTypeDto, findLocNoAttributeVo, false); |
| | | } |
| | | |
| | | private List<Map<String, Object>> buildRun2ProfilePreview(RowLastno rowLastno, RowLastnoType rowLastnoType, List<Integer> crnNos, |
| | | Integer staDescId, Integer sourceStaNo, LocTypeDto locTypeDto, |
| | | FindLocNoAttributeVo findLocNoAttributeVo, boolean ignoreFreqType) { |
| | | List<Map<String, Object>> profiles = new ArrayList<Map<String, Object>>(); |
| | | if (Cools.isEmpty(crnNos)) { |
| | | return profiles; |
| | |
| | | item.put("shallowRows", profile == null ? null : profile.getShallowRows()); |
| | | item.put("deepRows", profile == null ? null : profile.getDeepRows()); |
| | | LocMast firstMatchLoc = findConfiguredEmptyLocForCrn(rowLastno, rowLastnoType, crnNo, |
| | | getCrnStartRow(rowLastno, crnNo), locTypeDto); |
| | | getCrnStartRow(rowLastno, crnNo), locTypeDto, findLocNoAttributeVo, ignoreFreqType); |
| | | item.put("firstMatchLocNo", firstMatchLoc == null ? null : firstMatchLoc.getLocNo()); |
| | | item.put("assignableLocCount", countAssignableLocForCrn(rowLastno, rowLastnoType, crnNo, |
| | | getCrnStartRow(rowLastno, crnNo) == null ? 0 : getCrnStartRow(rowLastno, crnNo), locTypeDto)); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 空托盘 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 做轮询均分。 |
| | | * |
| | |
| | | * 因为空托盘的业务口径已经切换成“按库区找堆垛机”,不是按推荐排找巷道。 |
| | | */ |
| | | private Run2AreaSearchResult findEmptyPalletRun2Loc(RowLastno defaultRowLastno, Integer staDescId, Integer sourceStaNo, |
| | | StartupDto startupDto, Integer preferredArea, LocTypeDto locTypeDto) { |
| | | StartupDto startupDto, FindLocNoAttributeVo findLocNoAttributeVo, |
| | | LocTypeDto locTypeDto) { |
| | | for (LocTypeDto stageLocTypeDto : buildEmptyPalletSearchLocTypes(locTypeDto)) { |
| | | String stageCode = buildEmptyPalletStageCode(locTypeDto, stageLocTypeDto); |
| | | Run2AreaSearchResult searchResult = findEmptyPalletRun2AreaLoc(defaultRowLastno, staDescId, sourceStaNo, |
| | | startupDto, preferredArea, stageLocTypeDto, stageCode); |
| | | startupDto, findLocNoAttributeVo, stageLocTypeDto, stageCode); |
| | | if (!Cools.isEmpty(searchResult) && !Cools.isEmpty(searchResult.locMast)) { |
| | | return searchResult; |
| | | } |
| | |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 保留链路:在某个空托盘规格阶段内按库区顺序搜索。 |
| | | * |
| | | * 库区顺序由 {@link #buildAreaSearchOrder(List, Integer)} 生成:站点绑定库区优先,其次接口请求库区, |
| | | * 最后补齐 1/2/3 全库区。每个库区使用自己的 row_lastno 游标,并且跨库区时不强制 sta_desc 路径校验。 |
| | | */ |
| | | private Run2AreaSearchResult findEmptyPalletRun2AreaLoc(RowLastno defaultRowLastno, Integer staDescId, Integer sourceStaNo, |
| | | StartupDto startupDto, Integer preferredArea, LocTypeDto locTypeDto, |
| | | StartupDto startupDto, FindLocNoAttributeVo findLocNoAttributeVo, LocTypeDto locTypeDto, |
| | | String stageCode) { |
| | | for (Integer area : buildAreaSearchOrder(preferredArea)) { |
| | | List<Integer> areaSearchOrder = buildAreaSearchOrder( |
| | | findLocNoAttributeVo == null ? null : findLocNoAttributeVo.getOutAreas(), |
| | | findLocNoAttributeVo == null ? null : findLocNoAttributeVo.getOutArea()); |
| | | for (Integer area : areaSearchOrder) { |
| | | RowLastno areaRowLastno = getAreaRowLastno(area, defaultRowLastno); |
| | | if (Cools.isEmpty(areaRowLastno)) { |
| | | continue; |
| | |
| | | continue; |
| | | } |
| | | LocMast locMast = findRun2EmptyLocByCrnNos(areaRowLastno, areaRowLastnoType, runnableAreaCrnNos, locTypeDto, |
| | | staDescId, sourceStaNo, startupDto, area, stageCode + "-area-" + area, false); |
| | | staDescId, sourceStaNo, startupDto, area, findLocNoAttributeVo, stageCode + "-area-" + area, false); |
| | | if (!Cools.isEmpty(locMast)) { |
| | | return new Run2AreaSearchResult(locMast, areaRowLastno, runnableAreaCrnNos); |
| | | } |
| | |
| | | // 站点优先级只是“优先尝试”,没有命中时必须继续走默认/库区回退, |
| | | // 否则会把“优先候选无位”误判成“整仓无位”。 |
| | | LocMast locMast = findRun2EmptyLocByCrnLocTypeEntries(rowLastno, rowLastnoType, stationCrnLocTypes, |
| | | locTypeDto, staDescId, sourceStaNo, startupDto, preferredArea, "station-priority"); |
| | | locTypeDto, staDescId, sourceStaNo, startupDto, preferredArea, "station-priority", findLocNoAttributeVo); |
| | | if (!Cools.isEmpty(locMast)) { |
| | | return new Run2SearchResult(locMast, rowLastno, |
| | | getOrderedRunnableRun2CrnNos(rowLastno, staDescId, sourceStaNo, extractCrnNos(stationCrnLocTypes))); |
| | |
| | | } |
| | | List<Integer> runnableCrnNos = getOrderedRunnableRun2CrnNos(rowLastno, staDescId, sourceStaNo, candidateCrnNos); |
| | | LocMast locMast = findRun2EmptyLocByCrnNos(rowLastno, rowLastnoType, candidateCrnNos, locTypeDto, |
| | | staDescId, sourceStaNo, startupDto, preferredArea, preferredArea == null ? "default" : "preferred-area"); |
| | | staDescId, sourceStaNo, startupDto, preferredArea, findLocNoAttributeVo, |
| | | preferredArea == null ? "default" : "preferred-area"); |
| | | return new Run2SearchResult(locMast, rowLastno, runnableCrnNos); |
| | | } |
| | | |
| | |
| | | .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()); |
| | |
| | | LocTypeDto locTypeDto, Integer staDescId, Integer sourceStaNo, StartupDto startupDto, |
| | | Integer preferredArea, String stage) { |
| | | return findRun2EmptyLocByCrnNos(rowLastno, rowLastnoType, candidateCrnNos, locTypeDto, |
| | | staDescId, sourceStaNo, startupDto, preferredArea, stage, true); |
| | | staDescId, sourceStaNo, startupDto, preferredArea, null, stage, true); |
| | | } |
| | | |
| | | private LocMast findRun2EmptyLocByCrnNos(RowLastno rowLastno, RowLastnoType rowLastnoType, List<Integer> candidateCrnNos, |
| | | LocTypeDto locTypeDto, Integer staDescId, Integer sourceStaNo, StartupDto startupDto, |
| | | Integer preferredArea, String stage, boolean routeRequired) { |
| | | Integer preferredArea, FindLocNoAttributeVo findLocNoAttributeVo, String stage) { |
| | | return findRun2EmptyLocByCrnNos(rowLastno, rowLastnoType, candidateCrnNos, locTypeDto, |
| | | staDescId, sourceStaNo, startupDto, preferredArea, findLocNoAttributeVo, stage, true); |
| | | } |
| | | |
| | | 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) { |
| | | if (Cools.isEmpty(candidateCrnNos)) { |
| | | log.warn("run2 skip empty candidate list. stage={}, sourceStaNo={}, preferredArea={}, spec={}", |
| | | stage, sourceStaNo, preferredArea, JSON.toJSONString(locTypeDto)); |
| | |
| | | List<Integer> noEmptyCrns = new ArrayList<>(); |
| | | List<Integer> locTypeBlockedCrns = new ArrayList<>(); |
| | | return findRun2EmptyLocByCrnNosRecursively(rowLastno, rowLastnoType, candidateCrnNos, locTypeDto, |
| | | staDescId, sourceStaNo, startupDto, preferredArea, stage, routeRequired, 0, |
| | | staDescId, sourceStaNo, startupDto, preferredArea, findLocNoAttributeVo, stage, routeRequired, 0, |
| | | crnErrorCrns, routeBlockedCrns, noEmptyCrns, locTypeBlockedCrns); |
| | | } |
| | | |
| | | private LocMast findRun2EmptyLocByCrnNosRecursively(RowLastno rowLastno, RowLastnoType rowLastnoType, |
| | | List<Integer> candidateCrnNos, LocTypeDto locTypeDto, |
| | | Integer staDescId, Integer sourceStaNo, StartupDto startupDto, |
| | | Integer preferredArea, String stage, boolean routeRequired, int index, |
| | | Integer preferredArea, FindLocNoAttributeVo findLocNoAttributeVo, |
| | | String stage, boolean routeRequired, int index, |
| | | List<Integer> crnErrorCrns, List<Integer> routeBlockedCrns, |
| | | List<Integer> noEmptyCrns, List<Integer> locTypeBlockedCrns) { |
| | | if (index >= candidateCrnNos.size()) { |
| | |
| | | if (!isCrnActive(candidateCrnNo)) { |
| | | crnErrorCrns.add(candidateCrnNo); |
| | | return findRun2EmptyLocByCrnNosRecursively(rowLastno, rowLastnoType, candidateCrnNos, locTypeDto, |
| | | staDescId, sourceStaNo, startupDto, preferredArea, stage, routeRequired, index + 1, |
| | | staDescId, sourceStaNo, startupDto, preferredArea, findLocNoAttributeVo, stage, routeRequired, index + 1, |
| | | crnErrorCrns, routeBlockedCrns, noEmptyCrns, locTypeBlockedCrns); |
| | | } |
| | | 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, stage, routeRequired, index + 1, |
| | | staDescId, sourceStaNo, startupDto, preferredArea, findLocNoAttributeVo, stage, routeRequired, index + 1, |
| | | crnErrorCrns, routeBlockedCrns, noEmptyCrns, locTypeBlockedCrns); |
| | | } |
| | | Integer preferredNearRow = getCrnStartRow(rowLastno, candidateCrnNo); |
| | | LocMast candidateLoc = findConfiguredEmptyLocForCrn(rowLastno, rowLastnoType, candidateCrnNo, |
| | | preferredNearRow, locTypeDto); |
| | | preferredNearRow, locTypeDto, findLocNoAttributeVo); |
| | | if (Cools.isEmpty(candidateLoc)) { |
| | | int availableLocCount = countAssignableLocForCrn(rowLastno, rowLastnoType, candidateCrnNo, |
| | | preferredNearRow == null ? 0 : preferredNearRow, locTypeDto); |
| | |
| | | locTypeBlockedCrns.add(candidateCrnNo); |
| | | } |
| | | return findRun2EmptyLocByCrnNosRecursively(rowLastno, rowLastnoType, candidateCrnNos, locTypeDto, |
| | | staDescId, sourceStaNo, startupDto, preferredArea, stage, routeRequired, index + 1, |
| | | staDescId, sourceStaNo, startupDto, preferredArea, findLocNoAttributeVo, stage, routeRequired, index + 1, |
| | | crnErrorCrns, routeBlockedCrns, noEmptyCrns, locTypeBlockedCrns); |
| | | } |
| | | if (targetStaNo != null) { |
| | |
| | | private LocMast findRun2EmptyLocByCrnLocTypeEntries(RowLastno rowLastno, RowLastnoType rowLastnoType, |
| | | List<Map<String, Integer>> crnLocTypeEntries, LocTypeDto locTypeDto, |
| | | Integer staDescId, Integer sourceStaNo, StartupDto startupDto, |
| | | Integer preferredArea, String stage) { |
| | | Integer preferredArea, String stage, FindLocNoAttributeVo findLocNoAttributeVo) { |
| | | if (Cools.isEmpty(crnLocTypeEntries)) { |
| | | log.warn("run2 skip empty crn-locType list. stage={}, sourceStaNo={}, preferredArea={}, spec={}", |
| | | stage, sourceStaNo, preferredArea, JSON.toJSONString(locTypeDto)); |
| | |
| | | List<Integer> noEmptyCrns = new ArrayList<>(); |
| | | List<Integer> locTypeBlockedCrns = new ArrayList<>(); |
| | | return findRun2EmptyLocByCrnLocTypeEntriesRecursively(rowLastno, rowLastnoType, crnLocTypeEntries, locTypeDto, |
| | | staDescId, sourceStaNo, startupDto, preferredArea, stage, 0, candidateCrnNos, |
| | | staDescId, sourceStaNo, startupDto, preferredArea, stage, findLocNoAttributeVo, 0, candidateCrnNos, |
| | | crnErrorCrns, routeBlockedCrns, noEmptyCrns, locTypeBlockedCrns); |
| | | } |
| | | |
| | | private LocMast findRun2EmptyLocByCrnLocTypeEntriesRecursively(RowLastno rowLastno, RowLastnoType rowLastnoType, |
| | | List<Map<String, Integer>> crnLocTypeEntries, LocTypeDto locTypeDto, |
| | | Integer staDescId, Integer sourceStaNo, StartupDto startupDto, |
| | | Integer preferredArea, String stage, int index, |
| | | Integer preferredArea, String stage, FindLocNoAttributeVo findLocNoAttributeVo, int index, |
| | | List<Integer> candidateCrnNos, List<Integer> crnErrorCrns, |
| | | List<Integer> routeBlockedCrns, List<Integer> noEmptyCrns, |
| | | List<Integer> locTypeBlockedCrns) { |
| | |
| | | if (!isCrnActive(candidateCrnNo)) { |
| | | crnErrorCrns.add(candidateCrnNo); |
| | | return findRun2EmptyLocByCrnLocTypeEntriesRecursively(rowLastno, rowLastnoType, crnLocTypeEntries, locTypeDto, |
| | | staDescId, sourceStaNo, startupDto, preferredArea, stage, index + 1, candidateCrnNos, |
| | | staDescId, sourceStaNo, startupDto, preferredArea, stage, findLocNoAttributeVo, index + 1, candidateCrnNos, |
| | | crnErrorCrns, routeBlockedCrns, noEmptyCrns, locTypeBlockedCrns); |
| | | } |
| | | Integer targetStaNo = resolveTargetStaNo(rowLastno, staDescId, sourceStaNo, candidateCrnNo); |
| | | if (Utils.BooleanWhsTypeSta(rowLastno, staDescId) && targetStaNo == null) { |
| | | routeBlockedCrns.add(candidateCrnNo); |
| | | return findRun2EmptyLocByCrnLocTypeEntriesRecursively(rowLastno, rowLastnoType, crnLocTypeEntries, locTypeDto, |
| | | staDescId, sourceStaNo, startupDto, preferredArea, stage, index + 1, candidateCrnNos, |
| | | staDescId, sourceStaNo, startupDto, preferredArea, stage, findLocNoAttributeVo, index + 1, candidateCrnNos, |
| | | crnErrorCrns, routeBlockedCrns, noEmptyCrns, locTypeBlockedCrns); |
| | | } |
| | | LocTypeDto searchLocTypeDto = buildRun2SearchLocTypeDto(locTypeDto, candidateLocType1); |
| | | Integer preferredNearRow = getCrnStartRow(rowLastno, candidateCrnNo); |
| | | LocMast candidateLoc = findConfiguredEmptyLocForCrn(rowLastno, rowLastnoType, candidateCrnNo, |
| | | preferredNearRow, searchLocTypeDto); |
| | | preferredNearRow, searchLocTypeDto, findLocNoAttributeVo); |
| | | if (Cools.isEmpty(candidateLoc)) { |
| | | int availableLocCount = countAssignableLocForCrn(rowLastno, rowLastnoType, candidateCrnNo, |
| | | preferredNearRow == null ? 0 : preferredNearRow, searchLocTypeDto); |
| | |
| | | locTypeBlockedCrns.add(candidateCrnNo); |
| | | } |
| | | return findRun2EmptyLocByCrnLocTypeEntriesRecursively(rowLastno, rowLastnoType, crnLocTypeEntries, locTypeDto, |
| | | staDescId, sourceStaNo, startupDto, preferredArea, stage, index + 1, candidateCrnNos, |
| | | staDescId, sourceStaNo, startupDto, preferredArea, stage, findLocNoAttributeVo, index + 1, candidateCrnNos, |
| | | crnErrorCrns, routeBlockedCrns, noEmptyCrns, locTypeBlockedCrns); |
| | | } |
| | | if (targetStaNo != null) { |
| | |
| | | */ |
| | | private LocMast findRun2OrderedEmptyLocByCrnLocType(RowLastnoType rowLastnoType, Integer candidateCrnNo, |
| | | Short candidateLocType1, LocTypeDto locTypeDto) { |
| | | return findRun2OrderedEmptyLocByCrnLocType(rowLastnoType, candidateCrnNo, candidateLocType1, locTypeDto, null); |
| | | } |
| | | |
| | | private LocMast findRun2OrderedEmptyLocByCrnLocType(RowLastnoType rowLastnoType, Integer candidateCrnNo, |
| | | Short candidateLocType1, LocTypeDto locTypeDto, |
| | | FindLocNoAttributeVo findLocNoAttributeVo) { |
| | | if (candidateCrnNo == null) { |
| | | return null; |
| | | } |
| | |
| | | wrapper.eq("loc_type1", candidateLocType1); |
| | | } |
| | | applyLocTypeFilters(wrapper, locTypeDto, false); |
| | | // 单伸堆垛机按层、列递增顺序找第一个空库位。 |
| | | if (rowLastnoType != null && rowLastnoType.getType() != null && (rowLastnoType.getType() == 1 || rowLastnoType.getType() == 2)) { |
| | | wrapper.orderBy("lev1", true).orderBy("bay1", true); |
| | | } else { |
| | | wrapper.orderBy("lev1", true).orderBy("bay1", true); |
| | | List<LocMast> locMasts = locMastService.selectList(wrapper); |
| | | List<LocMast> sortedLocMasts = sortLocCandidates(locMasts, findLocNoAttributeVo); |
| | | for (LocMast candidateLoc : sortedLocMasts) { |
| | | if (candidateLoc == null) { |
| | | continue; |
| | | } |
| | | if (locTypeDto != null && !VersionUtils.locMoveCheckLocTypeComplete(candidateLoc, locTypeDto)) { |
| | | continue; |
| | | } |
| | | return candidateLoc; |
| | | } |
| | | LocMast candidateLoc = locMastService.selectOne(wrapper); |
| | | if (Cools.isEmpty(candidateLoc)) { |
| | | return null; |
| | | } |
| | | if (locTypeDto != null && !VersionUtils.locMoveCheckLocTypeComplete(candidateLoc, locTypeDto)) { |
| | | return null; |
| | | } |
| | | return candidateLoc; |
| | | return null; |
| | | } |
| | | |
| | | private Optional<CrnRowInfo> findAvailableCrnAndNearRow(RowLastno rowLastno, int curRow, int crnNumber, int times, |
| | |
| | | } |
| | | |
| | | /** |
| | | * 查询某一排上的所有空库位,并按单伸/双伸策略排序。 |
| | | * 查询某一排上的所有空库位,并按单伸/双伸策略与频次排序。 |
| | | */ |
| | | private List<LocMast> findOpenLocsByRow(RowLastno rowLastno, RowLastnoType rowLastnoType, Integer row, |
| | | Integer crnNo, LocTypeDto locTypeDto, boolean singleExtension) { |
| | | return findOpenLocsByRow(rowLastno, rowLastnoType, row, crnNo, locTypeDto, null, singleExtension, false); |
| | | } |
| | | |
| | | private List<LocMast> findOpenLocsByRow(RowLastno rowLastno, RowLastnoType rowLastnoType, Integer row, |
| | | Integer crnNo, LocTypeDto locTypeDto, FindLocNoAttributeVo findLocNoAttributeVo, |
| | | boolean singleExtension) { |
| | | return findOpenLocsByRow(rowLastno, rowLastnoType, row, crnNo, locTypeDto, findLocNoAttributeVo, singleExtension, false); |
| | | } |
| | | |
| | | private List<LocMast> findOpenLocsByRow(RowLastno rowLastno, RowLastnoType rowLastnoType, Integer row, |
| | | Integer crnNo, LocTypeDto locTypeDto, FindLocNoAttributeVo findLocNoAttributeVo, |
| | | boolean singleExtension, boolean ignoreFreqType) { |
| | | List<LocMast> result = new ArrayList<LocMast>(); |
| | | if (row == null) { |
| | | return result; |
| | | } |
| | | Wrapper<LocMast> wrapper = new EntityWrapper<LocMast>() |
| | | // .eq("row1", row) |
| | | .eq("loc_sts", "O"); |
| | | if (crnNo != null) { |
| | | wrapper.eq("crn_no", crnNo); |
| | | } |
| | | applyLocTypeFilters(wrapper, locTypeDto, true); |
| | | if (singleExtension) { |
| | | wrapper.orderBy("lev1", true).orderBy("bay1", true); |
| | | } else { |
| | | wrapper.orderBy("lev1", true).orderBy("bay1", true); |
| | | } |
| | | List<LocMast> locMasts = locMastService.selectList(wrapper); |
| | | for (LocMast locMast : locMasts) { |
| | | List<LocMast> sortedLocMasts = sortLocCandidates(locMasts, findLocNoAttributeVo, ignoreFreqType); |
| | | for (LocMast locMast : sortedLocMasts) { |
| | | if (matchesLocType(locMast, locTypeDto)) { |
| | | result.add(locMast); |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private List<LocMast> sortLocCandidates(List<LocMast> locMasts, FindLocNoAttributeVo findLocNoAttributeVo) { |
| | | return sortLocCandidates(locMasts, findLocNoAttributeVo, false); |
| | | } |
| | | |
| | | private List<LocMast> sortLocCandidates(List<LocMast> locMasts, FindLocNoAttributeVo findLocNoAttributeVo, boolean ignoreFreqType) { |
| | | Integer freqType = ignoreFreqType ? null : (findLocNoAttributeVo == null ? null : findLocNoAttributeVo.getFreqType()); |
| | | return sortLocCandidates(locMasts, freqType, getHighFreqFrontBayCount()); |
| | | } |
| | | |
| | | private List<LocMast> sortLocCandidates(List<LocMast> locMasts, Integer freqType, Integer frontBayCount) { |
| | | List<LocMast> result = new ArrayList<LocMast>(); |
| | | if (Cools.isEmpty(locMasts)) { |
| | | return result; |
| | | } |
| | | result.addAll(locMasts); |
| | | |
| | | Integer normalizedFreqType = normalizeFreqType(freqType); |
| | | if (normalizedFreqType == null) { |
| | | result.sort(Comparator |
| | | .comparing(LocMast::getLev1, Comparator.nullsLast(Integer::compareTo)) |
| | | .thenComparing(LocMast::getBay1, Comparator.nullsLast(Integer::compareTo)) |
| | | .thenComparing(LocMast::getLocNo, Comparator.nullsLast(String::compareTo))); |
| | | return result; |
| | | } |
| | | |
| | | if (Objects.equals(normalizedFreqType, 2)) { |
| | | result.sort(Comparator |
| | | .comparing(LocMast::getLev1, Comparator.nullsLast(Integer::compareTo)) |
| | | .thenComparing(LocMast::getBay1, Comparator.nullsLast(Comparator.reverseOrder())) |
| | | .thenComparing(LocMast::getLocNo, Comparator.nullsLast(String::compareTo))); |
| | | return result; |
| | | } |
| | | |
| | | int normalizedFrontBayCount = frontBayCount == null ? 0 : frontBayCount; |
| | | if (normalizedFrontBayCount > 0) { |
| | | result.sort(Comparator |
| | | .comparingInt((LocMast loc) -> resolveFrontBayGroup(loc, normalizedFrontBayCount)) |
| | | .thenComparing(LocMast::getBay1, Comparator.nullsLast(Integer::compareTo)) |
| | | .thenComparing(LocMast::getLev1, Comparator.nullsLast(Integer::compareTo)) |
| | | .thenComparing(LocMast::getLocNo, Comparator.nullsLast(String::compareTo))); |
| | | } else { |
| | | result.sort(Comparator |
| | | .comparing(LocMast::getBay1, Comparator.nullsLast(Integer::compareTo)) |
| | | .thenComparing(LocMast::getLev1, Comparator.nullsLast(Integer::compareTo)) |
| | | .thenComparing(LocMast::getLocNo, Comparator.nullsLast(String::compareTo))); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private int resolveFrontBayGroup(LocMast locMast, int frontBayCount) { |
| | | if (locMast == null || locMast.getBay1() == null || locMast.getBay1() <= 0) { |
| | | return 1; |
| | | } |
| | | return locMast.getBay1() <= frontBayCount ? 0 : 1; |
| | | } |
| | | |
| | | private Integer normalizeFreqType(Integer freqType) { |
| | | if (freqType == null || (freqType != 1 && freqType != 2)) { |
| | | return null; |
| | | } |
| | | return freqType; |
| | | } |
| | | |
| | | private int getHighFreqFrontBayCount() { |
| | | Parameter parameter = Parameter.get(); |
| | | if (parameter == null || Cools.isEmpty(parameter.getHighFreqFrontBayCount())) { |
| | | return 0; |
| | | } |
| | | Integer parsedCount = safeParseInt(parameter.getHighFreqFrontBayCount()); |
| | | if (parsedCount == null || parsedCount <= 0) { |
| | | return 0; |
| | | } |
| | | return parsedCount; |
| | | } |
| | | |
| | | /** |
| | |
| | | if (crnNo != null) { |
| | | wrapper.eq("crn_no", crnNo); |
| | | } |
| | | Long whsType = resolveLocWhsType(rowLastno, rowLastnoType); |
| | | if (whsType != null) { |
| | | wrapper.eq("whs_type", whsType); |
| | | } |
| | | if (statuses != null && statuses.length > 0) { |
| | | if (statuses.length == 1) { |
| | | wrapper.eq("loc_sts", statuses[0]); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 双伸堆垛机同货优先: |
| | | * 先找深库位中 standby1 相同且状态为 F 的货位,再检查其对应浅库位是否为空。 |
| | | */ |
| | | private LocMast findDoubleExtensionSameGoodsPreferredLoc(RowLastno rowLastno, RowLastnoType rowLastnoType, |
| | | Integer crnNo, CrnDepthRuleProfile profile, |
| | | LocTypeDto locTypeDto, FindLocNoAttributeVo findLocNoAttributeVo) { |
| | | if (profile == null || !profile.isDoubleExtension() || findLocNoAttributeVo == null |
| | | || Cools.isEmpty(findLocNoAttributeVo.getStandby1())) { |
| | | return null; |
| | | } |
| | | String standby1 = findLocNoAttributeVo.getStandby1(); |
| | | LinkedHashSet<Integer> processedDeepRows = new LinkedHashSet<Integer>(); |
| | | for (Integer searchRow : profile.getSearchRows()) { |
| | | if (searchRow == null || !profile.isDeepRow(searchRow) || !processedDeepRows.add(searchRow)) { |
| | | continue; |
| | | } |
| | | Integer shallowRow = profile.getPairedShallowRow(searchRow); |
| | | if (shallowRow == null) { |
| | | continue; |
| | | } |
| | | List<LocMast> deepLocs = findOccupiedLocsByRow(searchRow, 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; |
| | | } |
| | | List<LocDetl> sameGoodsLocDetls = locDetlService.selectList(new EntityWrapper<LocDetl>() |
| | | .eq("standby1", standby1) |
| | | .in("loc_no", deepLocNos)); |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | | * 查询某一排上状态为 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) { |
| | | List<LocMast> shallowOpenLocs = findOpenLocsByRow(rowLastno, rowLastnoType, shallowRow, crnNo, locTypeDto, false); |
| | | return findPairAssignableLoc(rowLastno, rowLastnoType, crnNo, shallowRow, deepRow, locTypeDto, null); |
| | | } |
| | | |
| | | 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); |
| | | 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) { |
| | | Integer preferredNearRow, LocTypeDto locTypeDto) { |
| | | return findConfiguredEmptyLocForCrn(rowLastno, rowLastnoType, crnNo, preferredNearRow, locTypeDto, null, false); |
| | | } |
| | | |
| | | private LocMast findConfiguredEmptyLocForCrn(RowLastno rowLastno, RowLastnoType rowLastnoType, Integer crnNo, |
| | | Integer preferredNearRow, LocTypeDto locTypeDto, FindLocNoAttributeVo findLocNoAttributeVo) { |
| | | return findConfiguredEmptyLocForCrn(rowLastno, rowLastnoType, crnNo, preferredNearRow, locTypeDto, findLocNoAttributeVo, false); |
| | | } |
| | | |
| | | private LocMast findConfiguredEmptyLocForCrn(RowLastno rowLastno, RowLastnoType rowLastnoType, Integer crnNo, |
| | | Integer preferredNearRow, LocTypeDto locTypeDto, FindLocNoAttributeVo findLocNoAttributeVo, |
| | | boolean ignoreFreqType) { |
| | | if (rowLastno == null || crnNo == null) { |
| | | return null; |
| | | } |
| | | CrnDepthRuleProfile profile = basCrnDepthRuleService.resolveProfile(rowLastno, crnNo, preferredNearRow); |
| | | if (profile == null || Cools.isEmpty(profile.getSearchRows())) { |
| | | return null; |
| | | } |
| | | LocMast sameGoodsPreferredLoc = findDoubleExtensionSameGoodsPreferredLoc(rowLastno, rowLastnoType, crnNo, |
| | | profile, locTypeDto, findLocNoAttributeVo); |
| | | if (!Cools.isEmpty(sameGoodsPreferredLoc)) { |
| | | return sameGoodsPreferredLoc; |
| | | } |
| | | LinkedHashSet<Integer> processedShallowRows = new LinkedHashSet<Integer>(); |
| | | boolean singleExtension = profile.isSingleExtension(); |
| | |
| | | continue; |
| | | } |
| | | LocMast candidateLoc = findPairAssignableLoc(rowLastno, rowLastnoType, crnNo, searchRow, |
| | | profile.getPairedDeepRow(searchRow), locTypeDto); |
| | | profile.getPairedDeepRow(searchRow), locTypeDto, findLocNoAttributeVo); |
| | | if (!Cools.isEmpty(candidateLoc)) { |
| | | return candidateLoc; |
| | | } |
| | |
| | | continue; |
| | | } |
| | | LocMast candidateLoc = findPairAssignableLoc(rowLastno, rowLastnoType, crnNo, shallowRow, |
| | | searchRow, locTypeDto); |
| | | searchRow, locTypeDto, findLocNoAttributeVo); |
| | | if (!Cools.isEmpty(candidateLoc)) { |
| | | return candidateLoc; |
| | | } |
| | |
| | | } |
| | | } |
| | | } |
| | | List<LocMast> locMasts = findOpenLocsByRow(rowLastno, rowLastnoType, searchRow, crnNo, locTypeDto, singleExtension); |
| | | List<LocMast> locMasts = findOpenLocsByRow(rowLastno, rowLastnoType, searchRow, crnNo, locTypeDto, findLocNoAttributeVo, singleExtension, ignoreFreqType); |
| | | 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++; |
| | | } |
| | | } |
| | |
| | | * run/run2 标准堆垛机统一的空库位查询入口。 |
| | | */ |
| | | private LocMast findStandardEmptyLoc(RowLastno rowLastno, RowLastnoType rowLastnoType, int crnNo, int nearRow, LocTypeDto locTypeDto) { |
| | | return findConfiguredEmptyLocForCrn(rowLastno, rowLastnoType, crnNo, nearRow, locTypeDto); |
| | | return findStandardEmptyLoc(rowLastno, rowLastnoType, crnNo, nearRow, locTypeDto, null); |
| | | } |
| | | |
| | | private LocMast findStandardEmptyLoc(RowLastno rowLastno, RowLastnoType rowLastnoType, int crnNo, int nearRow, |
| | | LocTypeDto locTypeDto, FindLocNoAttributeVo findLocNoAttributeVo) { |
| | | return findConfiguredEmptyLocForCrn(rowLastno, rowLastnoType, crnNo, nearRow, locTypeDto, findLocNoAttributeVo); |
| | | } |
| | | |
| | | /** |
| | |
| | | if (signRule1) { |
| | | if (nearRow != curRow) { |
| | | List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>() |
| | | .eq("row1", nearRow).eq("loc_sts", "O").eq("whs_type", rowLastnoType.getType().longValue())); |
| | | .eq("row1", nearRow).eq("loc_sts", "O")); |
| | | for (LocMast locMast1 : locMasts) { |
| | | //获取巷道 |
| | | // List<String> groupOutsideLocCrn = Utils.getGroupOutLocCrn(curRow,nearRow,locMast1.getLocNo(), curRow>nearRow); |
| | |
| | | // 靠近摆放规则 --- 空托 //互通版 |
| | | if (staDescId == 10 && Utils.BooleanWhsTypeStaIoType(rowLastno)) { |
| | | List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>() |
| | | .eq("loc_sts", "D").ge("row1", sRow).le("row1", eRow).eq("whs_type", rowLastnoType.getType().longValue())); |
| | | .eq("loc_sts", "D").ge("row1", sRow).le("row1", eRow)); |
| | | if (!locMasts.isEmpty()) { |
| | | for (LocMast loc : locMasts) { |
| | | if (Utils.isShallowLoc(slaveProperties, loc.getLocNo())) { |
| | |
| | | |
| | | // Search empty location ==============================>> |
| | | if (staDescId == 10 && Cools.isEmpty(locMast) && crnNo != 0) { |
| | | locMast = findStandardEmptyLoc(rowLastno, rowLastnoType, crnNo, nearRow, locTypeDto); |
| | | locMast = findStandardEmptyLoc(rowLastno, rowLastnoType, crnNo, nearRow, locTypeDto, findLocNoAttributeVo); |
| | | } |
| | | |
| | | |
| | | |
| | | if (Cools.isEmpty(locMast) && crnNo != 0) { |
| | | locMast = findStandardEmptyLoc(rowLastno, rowLastnoType, crnNo, nearRow, locTypeDto); |
| | | locMast = findStandardEmptyLoc(rowLastno, rowLastnoType, crnNo, nearRow, locTypeDto, findLocNoAttributeVo); |
| | | } |
| | | |
| | | if (!Cools.isEmpty(locMast) && !basCrnpService.checkSiteError(crnNo, true)) { |
| | |
| | | * run2 入库找位主流程。 |
| | | * |
| | | * 当前方法只保留“组织流程”和“统一收口”的职责,具体策略拆成独立方法: |
| | | * 1. 普通物料:按 row_lastno 自身轮询顺序 -> 站点优先库区/堆垛机 -> 其它库区。 |
| | | * 2. 空托盘:优先库区 loc_type2=1 -> 其它库区 loc_type2=1 -> loc_type1=2 兼容。 |
| | | * 3. 命中库位后分别回写普通物料游标或空托盘库区游标。 |
| | | * |
| | | * WCS 传入的推荐排不再参与 run2 选位,避免上游 row 参数把任务重新绑回固定堆垛机。 |
| | | * 1. 先按站点第一优先池找位,再找第二优先池。 |
| | | * 2. 池内按 current_no 轮转,从下一台堆垛机开始平均分配。 |
| | | * 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) { |
| | | |
| | | int crnNo = 0; |
| | | int nearRow = 0; |
| | | LocMast locMast = null; |
| | | |
| | | StartupDto startupDto = new StartupDto(); |
| | | RowLastno rowLastno = rowLastnoService.selectById(whsType); |
| | | |
| | | if (Cools.isEmpty(rowLastno)) { |
| | | throw new CoolException("数据异常,请联系管理员===>库位规则未知"); |
| | | } |
| | |
| | | if (Cools.isEmpty(rowLastnoType)) { |
| | | throw new CoolException("数据异常,请联系管理员===》库位规则类型未知"); |
| | | } |
| | | int curRow = rowLastno.getCurrentRow() == null ? 0 : rowLastno.getCurrentRow(); |
| | | crnNo = resolveRun2CrnNo(rowLastno); |
| | | Integer preferredArea = findLocNoAttributeVo.getOutArea(); |
| | | BasDevp station = basDevpService.selectById(sourceStaNo); |
| | | if (Cools.isEmpty(station)) { |
| | | throw new CoolException("站点=" + sourceStaNo + " 未配置入库优先堆垛机"); |
| | | } |
| | | List<Integer> firstPoolCrnNos = loadPriorityCrnNos(station.getInFirstCrnCsv()); |
| | | List<Integer> secondPoolCrnNos = loadPriorityCrnNos(station.getInSecondCrnCsv()); |
| | | if (Cools.isEmpty(firstPoolCrnNos) && Cools.isEmpty(secondPoolCrnNos)) { |
| | | throw new CoolException("站点=" + sourceStaNo + " 未配置入库优先堆垛机"); |
| | | } |
| | | boolean emptyPalletRequest = isEmptyPalletRequest(staDescId, findLocNoAttributeVo); |
| | | Run2AreaSearchResult emptyPalletAreaSearchResult = null; |
| | | Run2SearchResult normalRun2SearchResult = null; |
| | | |
| | | List<Integer> orderedCrnNos = getOrderedCrnNos(rowLastno, crnNo); |
| | | List<Integer> orderedRunnableCrnNos = getOrderedRunnableRun2CrnNos(rowLastno, staDescId, sourceStaNo, orderedCrnNos); |
| | | if (emptyPalletRequest) { |
| | | emptyPalletAreaSearchResult = findEmptyPalletRun2Loc(rowLastno, staDescId, sourceStaNo, startupDto, preferredArea, locTypeDto); |
| | | if (!Cools.isEmpty(emptyPalletAreaSearchResult)) { |
| | | locMast = emptyPalletAreaSearchResult.locMast; |
| | | } |
| | | } else { |
| | | normalRun2SearchResult = findNormalRun2Loc(rowLastno, rowLastnoType, sourceStaNo, staDescId, findLocNoAttributeVo, |
| | | locTypeDto, startupDto, preferredArea, orderedCrnNos); |
| | | if (normalRun2SearchResult != null) { |
| | | locMast = normalRun2SearchResult.locMast; |
| | | } |
| | | } |
| | | |
| | | if (!Cools.isEmpty(locMast)) { |
| | | crnNo = locMast.getCrnNo(); |
| | | nearRow = locMast.getRow1(); |
| | | } |
| | | if (emptyPalletRequest) { |
| | | advanceEmptyPalletRun2Cursor(emptyPalletAreaSearchResult, locMast); |
| | | } else if (!Cools.isEmpty(locMast)) { |
| | | List<Integer> cursorCrnNos = normalRun2SearchResult == null || Cools.isEmpty(normalRun2SearchResult.runnableCrnNos) |
| | | ? orderedRunnableCrnNos |
| | | : normalRun2SearchResult.runnableCrnNos; |
| | | advanceNormalRun2Cursor(rowLastno, curRow, cursorCrnNos, locMast.getCrnNo()); |
| | | } |
| | | |
| | | LocMast locMast = findRun2PriorityLocInPools(station, rowLastno, rowLastnoType, staDescId, sourceStaNo, |
| | | findLocNoAttributeVo, locTypeDto, startupDto, emptyPalletRequest); |
| | | if (Cools.isEmpty(locMast) || !locMast.getLocSts().equals("O")) { |
| | | if (emptyPalletRequest) { |
| | | log.error("No empty location found. spec={}, preferredArea={}, nearRow={}", |
| | | JSON.toJSONString(locTypeDto), preferredArea, nearRow); |
| | | log.error("No empty location found. spec={}, station={}, firstPool={}, secondPool={}", |
| | | JSON.toJSONString(locTypeDto), sourceStaNo, JSON.toJSONString(firstPoolCrnNos), |
| | | JSON.toJSONString(secondPoolCrnNos)); |
| | | throw new CoolException("没有空库位"); |
| | | } |
| | | LocTypeDto compatibleLocTypeDto = buildRetryCompatibleLocTypeDto(staDescId, findLocNoAttributeVo, locTypeDto); |
| | | if (compatibleLocTypeDto != null) { |
| | | log.warn("locType compatibility retry. source={}, target={}", JSON.toJSONString(locTypeDto), JSON.toJSONString(compatibleLocTypeDto)); |
| | | return getLocNoRun2(whsType, staDescId, sourceStaNo, findLocNoAttributeVo, moveCrnNo, compatibleLocTypeDto, recommendRows, 0); |
| | | } |
| | | log.error("No empty location found. spec={}, preferredArea={}, nearRow={}", JSON.toJSONString(locTypeDto), preferredArea, nearRow); |
| | | log.error("No empty location found. spec={}, station={}, firstPool={}, secondPool={}", |
| | | JSON.toJSONString(locTypeDto), sourceStaNo, JSON.toJSONString(firstPoolCrnNos), JSON.toJSONString(secondPoolCrnNos)); |
| | | throw new CoolException("没有空库位"); |
| | | } |
| | | |
| | | int workNo = getWorkNo(0); |
| | | startupDto.setWorkNo(workNo); |
| | | startupDto.setCrnNo(crnNo); |
| | | startupDto.setCrnNo(locMast.getCrnNo()); |
| | | startupDto.setSourceStaNo(sourceStaNo); |
| | | startupDto.setLocNo(locMast.getLocNo()); |
| | | return startupDto; |
| | |
| | | * 单伸堆垛机复用统一画像算法查询空库位。 |
| | | */ |
| | | private LocMast findSingleExtensionEmptyLoc(RowLastno rowLastno, int crnNo, int nearRow, RowLastnoType rowLastnoType, LocTypeDto locTypeDto) { |
| | | return findConfiguredEmptyLocForCrn(rowLastno, rowLastnoType, crnNo, nearRow, locTypeDto); |
| | | return findSingleExtensionEmptyLoc(rowLastno, crnNo, nearRow, rowLastnoType, locTypeDto, null); |
| | | } |
| | | |
| | | private LocMast findSingleExtensionEmptyLoc(RowLastno rowLastno, int crnNo, int nearRow, RowLastnoType rowLastnoType, |
| | | LocTypeDto locTypeDto, FindLocNoAttributeVo findLocNoAttributeVo) { |
| | | return findConfiguredEmptyLocForCrn(rowLastno, rowLastnoType, crnNo, nearRow, locTypeDto, findLocNoAttributeVo); |
| | | } |
| | | |
| | | public StartupDto getLocNoRun4(Integer whsType, Integer staDescId, Integer sourceStaNo, FindLocNoAttributeVo findLocNoAttributeVo, Integer moveCrnNo, LocTypeDto locTypeDto, int times) { |
| | |
| | | crnNo = locNecessaryParameters[2]; |
| | | nearRow = locNecessaryParameters[3]; |
| | | List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>() |
| | | .eq("crn_no", crnNo).eq("loc_sts", "O").eq("whs_type", rowLastnoType.getType().longValue())); |
| | | .eq("crn_no", crnNo).eq("loc_sts", "O")); |
| | | if (locMasts.size() <= 5) { |
| | | nearRow = 0; |
| | | times++; |
| | |
| | | if (signRule1) { |
| | | if (nearRow != curRow) { |
| | | List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>() |
| | | .eq("row1", nearRow).eq("loc_sts", "O").eq("whs_type", rowLastnoType.getType().longValue())); |
| | | .eq("row1", nearRow).eq("loc_sts", "O")); |
| | | for (LocMast locMast1 : locMasts) { |
| | | //获取巷道 |
| | | // List<String> groupOutsideLocCrn = Utils.getGroupOutLocCrn(curRow,nearRow,locMast1.getLocNo(), curRow>nearRow); |
| | |
| | | if (Cools.isEmpty(locMast) && crnNo != 0) { |
| | | List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>() |
| | | .eq("row1", nearRow) |
| | | .eq("loc_sts", "O").eq("whs_type", rowLastnoType.getType().longValue()) |
| | | .eq("loc_sts", "O") |
| | | .orderBy("lev1", true).orderBy("bay1", true));//最浅库位 |
| | | for (LocMast locMast1 : locMasts) { |
| | | if (!VersionUtils.locMoveCheckLocTypeComplete(locMast1, locTypeDto)) { |
| | |
| | | |
| | | // 开始查找库位 ==============================>> |
| | | |
| | | Integer preferredArea = findLocNoAttributeVo.getOutArea(); |
| | | Integer preferredArea = findLocNoAttributeVo == null ? null : findLocNoAttributeVo.getOutArea(); |
| | | List<Integer> areaSearchOrder = buildAreaSearchOrder(findLocNoAttributeVo == null ? null : findLocNoAttributeVo.getOutAreas(), preferredArea); |
| | | |
| | | if (Cools.isEmpty(locMast) && preferredArea == null) { |
| | | List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>() |
| | | .eq("row1", nearRow) |
| | | .eq("loc_sts", "O").eq("whs_type", rowLastnoType.getType().longValue()) |
| | | .orderBy("lev1", true).orderBy("bay1", true)); // 最浅库位 |
| | | for (LocMast locMast1 : locMasts) { |
| | | if (!VersionUtils.locMoveCheckLocTypeComplete(locMast1, locTypeDto)) { |
| | | if (Cools.isEmpty(locMast)) { |
| | | for (Integer area : areaSearchOrder) { |
| | | int[] bayRange = getAgvAreaBayRange(area); |
| | | List<Integer> areaRows = getAgvAreaRows(area, rowLastno); |
| | | if (Cools.isEmpty(areaRows)) { |
| | | continue; |
| | | } |
| | | if (Utils.BooleanWhsTypeStaIoType(rowLastno)) { |
| | | // 获取目标库位所在巷道最深空库位 |
| | | LocMast locMast2 = locMastService.selectLocByLocStsPakInO(curRow, nearRow, locMast1, rowLastnoType.getType().longValue()); |
| | | if (!Cools.isEmpty(locMast2) && locMast2.getRow1() == curRow) { |
| | | locMast = locMast2; |
| | | break; |
| | | } |
| | | locMast = findAgvLocByRows(rowLastno, rowLastnoType, areaRows, |
| | | bayRange[0], bayRange[1], curRow, nearRow, locTypeDto, findLocNoAttributeVo, false); |
| | | if (!Cools.isEmpty(locMast)) { |
| | | crnNo = locMast.getCrnNo(); |
| | | preferredArea = area; |
| | | break; |
| | | } |
| | | } |
| | | } else if (Cools.isEmpty(locMast)) { |
| | | int[] bayRange = getAgvAreaBayRange(preferredArea); |
| | | locMast = findAgvLocByRows(rowLastno, rowLastnoType, getAgvAreaRows(preferredArea, rowLastno), |
| | | bayRange[0], bayRange[1], curRow, nearRow, locTypeDto, false); |
| | | if (!Cools.isEmpty(locMast)) { |
| | | crnNo = locMast.getCrnNo(); |
| | | } |
| | | if (Cools.isEmpty(locMast)) { |
| | | locMast = findAgvLocByRows(rowLastno, rowLastnoType, getAgvFallbackRows(rowLastno), |
| | | 1, 19, curRow, nearRow, locTypeDto, true); |
| | | 1, 19, curRow, nearRow, locTypeDto, findLocNoAttributeVo, true); |
| | | if (!Cools.isEmpty(locMast)) { |
| | | crnNo = locMast.getCrnNo(); |
| | | } |