| | |
| | | public class CommonService { |
| | | private static final int MIN_SPARE_LOC_COUNT = 2; |
| | | |
| | | private static class Run2AreaSearchResult { |
| | | private final LocMast locMast; |
| | | private final RowLastno rowLastno; |
| | | private final List<Integer> runnableCrnNos; |
| | | |
| | | /** |
| | | * @param locMast 命中的空库位 |
| | | * @param rowLastno 命中库区对应的轮询游标记录 |
| | | * @param runnableCrnNos 当前库区可参与轮询的堆垛机顺序 |
| | | */ |
| | | private Run2AreaSearchResult(LocMast locMast, RowLastno rowLastno, List<Integer> runnableCrnNos) { |
| | | this.locMast = locMast; |
| | | this.rowLastno = rowLastno; |
| | | this.runnableCrnNos = runnableCrnNos; |
| | | } |
| | | } |
| | | |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | | @Autowired |
| | |
| | | @Transactional |
| | | public StartupDto getLocNo(Integer staDescId, Integer sourceStaNo, FindLocNoAttributeVo findLocNoAttributeVo, LocTypeDto locTypeDto, List<Integer> recommendRows) { |
| | | try { |
| | | locTypeDto = normalizeLocTypeDto(staDescId, findLocNoAttributeVo, locTypeDto); |
| | | Integer whsType = Utils.GetWhsType(sourceStaNo); |
| | | RowLastno rowLastno = rowLastnoService.selectById(whsType); |
| | | RowLastnoType rowLastnoType = rowLastnoTypeService.selectById(rowLastno.getTypeId()); |
| | |
| | | log.error("站点={} 查找库位异常", sourceStaNo, e); |
| | | throw new CoolException("站点=" + sourceStaNo + " 查找库位失败"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 空托盘识别规则: |
| | | * 1. 以组托档物料编码 matnr=emptyPallet 为主,不再依赖 ioType=10。 |
| | | * 2. 保留 staDescId=10 的兼容判断,避免旧链路还未切换时行为突变。 |
| | | */ |
| | | private boolean isEmptyPalletRequest(Integer staDescId, FindLocNoAttributeVo findLocNoAttributeVo) { |
| | | if (findLocNoAttributeVo != null && "emptyPallet".equalsIgnoreCase(findLocNoAttributeVo.getMatnr())) { |
| | | return true; |
| | | } |
| | | return staDescId != null && staDescId == 10; |
| | | } |
| | | |
| | | /** |
| | | * 统一整理入库规格,避免不同入口传入的 locType 不一致。 |
| | | * |
| | | * 空托盘的库位策略有两段: |
| | | * 1. 首轮只限制 loc_type2=1,表示优先找窄库位。 |
| | | * 2. 首轮不限制 loc_type1,高低位都允许参与搜索。 |
| | | * |
| | | * 这样做的原因是现场口径已经改成“先找窄库位”,而不是“先找低位窄库位”。 |
| | | * 因此这里会主动清空 locType1,防止被站点默认值带成低位优先。 |
| | | */ |
| | | private LocTypeDto normalizeLocTypeDto(Integer staDescId, FindLocNoAttributeVo findLocNoAttributeVo, LocTypeDto locTypeDto) { |
| | | if (!isEmptyPalletRequest(staDescId, findLocNoAttributeVo)) { |
| | | return locTypeDto; |
| | | } |
| | | if (findLocNoAttributeVo != null && Cools.isEmpty(findLocNoAttributeVo.getMatnr())) { |
| | | findLocNoAttributeVo.setMatnr("emptyPallet"); |
| | | } |
| | | LocTypeDto normalizedLocTypeDto = locTypeDto == null ? new LocTypeDto() : locTypeDto; |
| | | // 空托盘首轮不限制高低位,只保留“窄库位优先”的约束。 |
| | | normalizedLocTypeDto.setLocType1(null); |
| | | normalizedLocTypeDto.setLocType2((short) 1); |
| | | return normalizedLocTypeDto; |
| | | } |
| | | |
| | | private Wrapper<LocMast> applyLocTypeFilters(Wrapper<LocMast> wrapper, LocTypeDto locTypeDto, boolean includeLocType1) { |
| | | if (wrapper == null || locTypeDto == null) { |
| | | return wrapper; |
| | | } |
| | | if (includeLocType1 && locTypeDto.getLocType1() != null && locTypeDto.getLocType1() > 0) { |
| | | wrapper.eq("loc_type1", locTypeDto.getLocType1()); |
| | | } |
| | | if (locTypeDto.getLocType2() != null && locTypeDto.getLocType2() > 0) { |
| | | wrapper.eq("loc_type2", locTypeDto.getLocType2()); |
| | | } |
| | | if (locTypeDto.getLocType3() != null && locTypeDto.getLocType3() > 0) { |
| | | wrapper.eq("loc_type3", locTypeDto.getLocType3()); |
| | | } |
| | | return wrapper; |
| | | } |
| | | |
| | | private Integer resolvePreferredArea(Integer sourceStaNo, FindLocNoAttributeVo findLocNoAttributeVo) { |
| | |
| | | if (row == null) { |
| | | continue; |
| | | } |
| | | List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>() |
| | | Wrapper<LocMast> wrapper = new EntityWrapper<LocMast>() |
| | | .eq("row1", row) |
| | | .ge("bay1", startBay) |
| | | .le("bay1", endBay) |
| | | .eq("loc_sts", "O") |
| | | .eq("loc_type1", locTypeDto.getLocType1()) |
| | | .orderBy("lev1", true) |
| | | .orderBy("bay1", true)); |
| | | .eq("loc_sts", "O"); |
| | | applyLocTypeFilters(wrapper, locTypeDto, true); |
| | | wrapper.orderBy("lev1", true).orderBy("bay1", true); |
| | | List<LocMast> locMasts = locMastService.selectList(wrapper); |
| | | for (LocMast candidate : locMasts) { |
| | | if (!VersionUtils.locMoveCheckLocTypeComplete(candidate, locTypeDto)) { |
| | | continue; |
| | |
| | | return orderedCrnNos; |
| | | } |
| | | |
| | | private Integer getCrnStartRow(RowLastno rowLastno, Integer crnNo) { |
| | | if (rowLastno == null || crnNo == null) { |
| | | return null; |
| | | } |
| | | Integer rowSpan = getCrnRowSpan(rowLastno.getTypeId()); |
| | | if (rowSpan == null || rowSpan <= 0) { |
| | | return null; |
| | | } |
| | | int startCrnNo = rowLastno.getsCrnNo() == null ? 1 : rowLastno.getsCrnNo(); |
| | | int startRow = rowLastno.getsRow() == null ? 1 : rowLastno.getsRow(); |
| | | if (crnNo < startCrnNo) { |
| | | return null; |
| | | } |
| | | return startRow + (crnNo - startCrnNo) * rowSpan; |
| | | } |
| | | |
| | | /** |
| | | * 判断某台堆垛机是否可以参与 run2 入库找位。 |
| | | * |
| | | * routeRequired=true: |
| | | * 普通入库必须同时满足设备可入、设备无故障、并且当前源站到该堆垛机存在有效目标站路径。 |
| | | * |
| | | * routeRequired=false: |
| | | * 空托盘跨库区找位时,只校验设备主档、故障和可入状态,不把 sta_desc 路径当成拦截条件。 |
| | | * 这样做是为了先满足“能找到库位”,目标站路径由后续主数据补齐。 |
| | | */ |
| | | private boolean canRun2CrnAcceptPakin(RowLastno rowLastno, Integer staDescId, Integer sourceStaNo, Integer crnNo) { |
| | | return canRun2CrnAcceptPakin(rowLastno, staDescId, sourceStaNo, crnNo, true); |
| | | } |
| | | |
| | | private boolean canRun2CrnAcceptPakin(RowLastno rowLastno, Integer staDescId, Integer sourceStaNo, Integer crnNo, boolean routeRequired) { |
| | | if (crnNo == null) { |
| | | return false; |
| | | } |
| | | BasCrnp basCrnp = basCrnpService.selectById(crnNo); |
| | | if (Cools.isEmpty(basCrnp)) { |
| | | return false; |
| | | } |
| | | if (!"Y".equals(basCrnp.getInEnable())) { |
| | | return false; |
| | | } |
| | | if (basCrnp.getCrnSts() != null && basCrnp.getCrnSts() != 3) { |
| | | return false; |
| | | } |
| | | if (basCrnp.getCrnErr() != null && basCrnp.getCrnErr() != 0) { |
| | | return false; |
| | | } |
| | | if (!routeRequired) { |
| | | return true; |
| | | } |
| | | if (!Utils.BooleanWhsTypeSta(rowLastno, staDescId)) { |
| | | return true; |
| | | } |
| | | StaDesc staDesc = staDescService.selectOne(new EntityWrapper<StaDesc>() |
| | | .eq("type_no", staDescId) |
| | | .eq("stn_no", sourceStaNo) |
| | | .eq("crn_no", crnNo)); |
| | | if (Cools.isEmpty(staDesc)) { |
| | | return false; |
| | | } |
| | | BasDevp targetSta = basDevpService.selectById(staDesc.getCrnStn()); |
| | | return !Cools.isEmpty(targetSta) && "Y".equals(targetSta.getAutoing()); |
| | | } |
| | | |
| | | /** |
| | | * 按既定轮询顺序过滤出真正可参与本次找位的堆垛机列表。 |
| | | */ |
| | | private List<Integer> getOrderedRunnableRun2CrnNos(RowLastno rowLastno, Integer staDescId, Integer sourceStaNo, List<Integer> orderedCrnNos) { |
| | | return getOrderedRunnableRun2CrnNos(rowLastno, staDescId, sourceStaNo, orderedCrnNos, true); |
| | | } |
| | | |
| | | private List<Integer> getOrderedRunnableRun2CrnNos(RowLastno rowLastno, Integer staDescId, Integer sourceStaNo, List<Integer> orderedCrnNos, boolean routeRequired) { |
| | | List<Integer> runnableCrnNos = new ArrayList<>(); |
| | | if (Cools.isEmpty(orderedCrnNos)) { |
| | | return runnableCrnNos; |
| | | } |
| | | for (Integer candidateCrnNo : orderedCrnNos) { |
| | | if (canRun2CrnAcceptPakin(rowLastno, staDescId, sourceStaNo, candidateCrnNo, routeRequired)) { |
| | | runnableCrnNos.add(candidateCrnNo); |
| | | } |
| | | } |
| | | return runnableCrnNos; |
| | | } |
| | | |
| | | /** |
| | | * 根据本次命中的堆垛机,把轮询游标推进到下一台可参与轮询的堆垛机。 |
| | | */ |
| | | private int getNextRun2CurrentRow(RowLastno rowLastno, List<Integer> runnableCrnNos, Integer selectedCrnNo, int currentRow) { |
| | | if (Cools.isEmpty(runnableCrnNos) || selectedCrnNo == null) { |
| | | return getNextRun2CurrentRow(rowLastno, currentRow); |
| | | } |
| | | int index = runnableCrnNos.indexOf(selectedCrnNo); |
| | | if (index < 0) { |
| | | return getNextRun2CurrentRow(rowLastno, currentRow); |
| | | } |
| | | Integer nextCrnNo = runnableCrnNos.get((index + 1) % runnableCrnNos.size()); |
| | | Integer nextRow = getCrnStartRow(rowLastno, nextCrnNo); |
| | | return nextRow == null ? getNextRun2CurrentRow(rowLastno, currentRow) : nextRow; |
| | | } |
| | | |
| | | /** |
| | | * 构造空托盘跨库区搜索顺序: |
| | | * 先当前库区,再依次补足其它库区,避免重复。 |
| | | */ |
| | | private List<Integer> buildAreaSearchOrder(Integer preferredArea) { |
| | | LinkedHashSet<Integer> areaOrder = new LinkedHashSet<>(); |
| | | if (preferredArea != null && preferredArea >= 1 && preferredArea <= 3) { |
| | | areaOrder.add(preferredArea); |
| | | } |
| | | for (int area = 1; area <= 3; area++) { |
| | | areaOrder.add(area); |
| | | } |
| | | return new ArrayList<>(areaOrder); |
| | | } |
| | | |
| | | /** |
| | | * 根据库区取该库区对应的轮询记录。 |
| | | * 当前库里 1/2/3 库区正好复用了 asr_row_lastno 的 whs_type 主键,因此这里直接按 area 取。 |
| | | * 如果缺主数据,就回退到当前源站所在仓的 rowLastno,避免直接空指针。 |
| | | */ |
| | | private RowLastno getAreaRowLastno(Integer area, RowLastno defaultRowLastno) { |
| | | if (area != null && area > 0) { |
| | | RowLastno areaRowLastno = rowLastnoService.selectById(area); |
| | | if (!Cools.isEmpty(areaRowLastno)) { |
| | | return areaRowLastno; |
| | | } |
| | | } |
| | | return defaultRowLastno; |
| | | } |
| | | |
| | | /** |
| | | * 空托盘 run2 专用搜索链路。 |
| | | * |
| | | * 执行顺序: |
| | | * 1. 先按站点绑定库区找 loc_type2=1。 |
| | | * 2. 当前库区没有,再按其它库区继续找 loc_type2=1。 |
| | | * 3. 每个库区内部都按该库区自己的 rowLastno/currentRow 做轮询均分。 |
| | | * |
| | | * 这里故意不复用普通 run2 的“推荐排 -> 当前库区排 -> 其它排”逻辑, |
| | | * 因为空托盘的业务口径已经切换成“按库区找堆垛机”,不是按推荐排找巷道。 |
| | | */ |
| | | private Run2AreaSearchResult findEmptyPalletRun2AreaLoc(RowLastno defaultRowLastno, Integer staDescId, Integer sourceStaNo, |
| | | StartupDto startupDto, Integer preferredArea, LocTypeDto locTypeDto) { |
| | | for (Integer area : buildAreaSearchOrder(preferredArea)) { |
| | | RowLastno areaRowLastno = getAreaRowLastno(area, defaultRowLastno); |
| | | if (Cools.isEmpty(areaRowLastno)) { |
| | | continue; |
| | | } |
| | | RowLastnoType areaRowLastnoType = rowLastnoTypeService.selectById(areaRowLastno.getTypeId()); |
| | | if (Cools.isEmpty(areaRowLastnoType)) { |
| | | continue; |
| | | } |
| | | Integer areaStartCrnNo = resolveRun2CrnNo(areaRowLastno); |
| | | List<Integer> orderedAreaCrnNos = getOrderedCrnNos(areaRowLastno, areaStartCrnNo); |
| | | // 空托盘跨库区时只筛设备主档和故障状态,不强依赖 sta_desc。 |
| | | List<Integer> runnableAreaCrnNos = getOrderedRunnableRun2CrnNos(areaRowLastno, staDescId, sourceStaNo, orderedAreaCrnNos, false); |
| | | List<Integer> candidateCrnNos = Cools.isEmpty(runnableAreaCrnNos) ? orderedAreaCrnNos : runnableAreaCrnNos; |
| | | if (Cools.isEmpty(candidateCrnNos)) { |
| | | continue; |
| | | } |
| | | LocMast locMast = findRun2EmptyLocByCrnNos(areaRowLastno, areaRowLastnoType, candidateCrnNos, locTypeDto, |
| | | staDescId, sourceStaNo, startupDto, area, "empty-pallet-area-" + area, false); |
| | | if (!Cools.isEmpty(locMast)) { |
| | | return new Run2AreaSearchResult(locMast, areaRowLastno, candidateCrnNos); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 空托盘命中库位后,按命中库区回写该库区自己的轮询游标。 |
| | | * 这样 A/B/C 三个库区会分别维护各自的“下一台堆垛机”,不会互相覆盖。 |
| | | */ |
| | | private void advanceEmptyPalletRun2Cursor(Run2AreaSearchResult searchResult, LocMast locMast) { |
| | | if (searchResult == null || searchResult.rowLastno == null || locMast == null) { |
| | | return; |
| | | } |
| | | RowLastno updateRowLastno = searchResult.rowLastno; |
| | | int updateCurRow = updateRowLastno.getCurrentRow() == null || updateRowLastno.getCurrentRow() == 0 |
| | | ? (updateRowLastno.getsRow() == null ? 1 : updateRowLastno.getsRow()) |
| | | : updateRowLastno.getCurrentRow(); |
| | | updateCurRow = getNextRun2CurrentRow(updateRowLastno, searchResult.runnableCrnNos, locMast.getCrnNo(), updateCurRow); |
| | | updateRowLastno.setCurrentRow(updateCurRow); |
| | | rowLastnoService.updateById(updateRowLastno); |
| | | } |
| | | |
| | | /** |
| | | * 普通 run2 的推荐排优先阶段。 |
| | | * |
| | | * 推荐排只对普通物料生效,空托盘已经切换成“按库区轮询堆垛机”的规则, |
| | | * 因此这里会直接跳过空托盘请求,避免 row 参数把空托盘重新带回旧逻辑。 |
| | | */ |
| | | private LocMast findRun2RecommendLoc(RowLastno rowLastno, RowLastnoType rowLastnoType, boolean emptyPalletRequest, |
| | | List<Integer> recommendRows, LocTypeDto locTypeDto, Integer staDescId, |
| | | Integer sourceStaNo, StartupDto startupDto, Integer preferredArea, |
| | | List<Integer> triedCrnNos) { |
| | | if (emptyPalletRequest) { |
| | | return null; |
| | | } |
| | | List<Integer> recommendCrnNos = mapRowsToCrnNos(rowLastno, recommendRows); |
| | | if (Cools.isEmpty(recommendCrnNos)) { |
| | | return null; |
| | | } |
| | | LocMast locMast = findRun2EmptyLocByCrnNos(rowLastno, rowLastnoType, recommendCrnNos, locTypeDto, |
| | | staDescId, sourceStaNo, startupDto, preferredArea, "recommend"); |
| | | triedCrnNos.addAll(recommendCrnNos); |
| | | return locMast; |
| | | } |
| | | |
| | | /** |
| | | * 普通物料 run2 找位主流程。 |
| | | * |
| | | * 执行顺序: |
| | | * 1. 先看站点是否配置了“堆垛机 + 库位类型”优先级。 |
| | | * 2. 没配库区时,直接按当前 run2 轮询顺序找位。 |
| | | * 3. 配了库区时,先在当前库区找,再回退到其它库区。 |
| | | */ |
| | | private LocMast findNormalRun2Loc(RowLastno rowLastno, RowLastnoType rowLastnoType, Integer sourceStaNo, |
| | | Integer staDescId, FindLocNoAttributeVo findLocNoAttributeVo, LocTypeDto locTypeDto, |
| | | StartupDto startupDto, Integer preferredArea, List<Integer> orderedCrnNos, |
| | | List<Integer> triedCrnNos) { |
| | | List<Map<String, Integer>> stationCrnLocTypes = Utils.getStationStorageAreaName( |
| | | sourceStaNo, |
| | | locTypeDto == null || locTypeDto.getLocType1() == null ? null : locTypeDto.getLocType1().intValue(), |
| | | findLocNoAttributeVo == null ? null : findLocNoAttributeVo.getMatnr()); |
| | | if (!Cools.isEmpty(stationCrnLocTypes)) { |
| | | return findRun2EmptyLocByCrnLocTypeEntries(rowLastno, rowLastnoType, stationCrnLocTypes, |
| | | locTypeDto, staDescId, sourceStaNo, startupDto, preferredArea, "station-priority"); |
| | | } |
| | | if (preferredArea == null) { |
| | | List<Integer> defaultCrnNos = new ArrayList<>(orderedCrnNos); |
| | | defaultCrnNos.removeAll(triedCrnNos); |
| | | return findRun2EmptyLocByCrnNos(rowLastno, rowLastnoType, defaultCrnNos, locTypeDto, |
| | | staDescId, sourceStaNo, startupDto, preferredArea, "default"); |
| | | } |
| | | List<Integer> preferredCrnNos = filterCrnNosByRows(rowLastno, orderedCrnNos, getRun2AreaRows(preferredArea, rowLastno)); |
| | | preferredCrnNos.removeAll(triedCrnNos); |
| | | LocMast locMast = findRun2EmptyLocByCrnNos(rowLastno, rowLastnoType, preferredCrnNos, locTypeDto, |
| | | staDescId, sourceStaNo, startupDto, preferredArea, "preferred-area"); |
| | | if (!Cools.isEmpty(locMast)) { |
| | | return locMast; |
| | | } |
| | | List<Integer> fallbackCrnNos = filterCrnNosByRows(rowLastno, orderedCrnNos, getRun2FallbackRows(rowLastno)); |
| | | fallbackCrnNos.removeAll(triedCrnNos); |
| | | fallbackCrnNos.removeAll(preferredCrnNos); |
| | | return findRun2EmptyLocByCrnNos(rowLastno, rowLastnoType, fallbackCrnNos, locTypeDto, |
| | | staDescId, sourceStaNo, startupDto, preferredArea, "fallback-area"); |
| | | } |
| | | |
| | | /** |
| | | * 普通物料命中库位后,沿用 run2 原有的全仓轮询游标推进方式。 |
| | | */ |
| | | private void advanceNormalRun2Cursor(RowLastno rowLastno, int curRow) { |
| | | if (rowLastno == null) { |
| | | return; |
| | | } |
| | | int updateCurRow = curRow == 0 ? (rowLastno.getsRow() == null ? 1 : rowLastno.getsRow()) : curRow; |
| | | updateCurRow = getNextRun2CurrentRow(rowLastno, updateCurRow); |
| | | rowLastno.setCurrentRow(updateCurRow); |
| | | rowLastnoService.updateById(rowLastno); |
| | | } |
| | | |
| | | private List<Integer> filterCrnNosByRows(RowLastno rowLastno, List<Integer> orderedCrnNos, List<Integer> rows) { |
| | | if (Cools.isEmpty(rows)) { |
| | | return new ArrayList<>(orderedCrnNos); |
| | |
| | | JSON.toJSONString(locTypeDto)); |
| | | } |
| | | |
| | | /** |
| | | * 按给定堆垛机顺序依次找空库位。 |
| | | * |
| | | * 这里同时承担三类过滤: |
| | | * 1. 设备侧过滤:堆垛机故障或不存在时直接跳过。 |
| | | * 2. 路径侧过滤:当前源站到该堆垛机目标站无路径时跳过。 |
| | | * 3. 库位侧过滤:无空库位或库位规格不匹配时跳过。 |
| | | * |
| | | * 对空托盘来说,candidateCrnNos 由 run2 的轮询顺序生成,因此天然具备“均分到每个堆垛机”的效果。 |
| | | */ |
| | | private LocMast findRun2EmptyLocByCrnNos(RowLastno rowLastno, RowLastnoType rowLastnoType, List<Integer> candidateCrnNos, |
| | | LocTypeDto locTypeDto, Integer staDescId, Integer sourceStaNo, StartupDto startupDto, |
| | | Integer preferredArea, String stage) { |
| | | return findRun2EmptyLocByCrnNos(rowLastno, rowLastnoType, candidateCrnNos, locTypeDto, |
| | | staDescId, sourceStaNo, startupDto, preferredArea, 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) { |
| | | if (Cools.isEmpty(candidateCrnNos)) { |
| | | log.warn("run2 skip empty candidate list. stage={}, sourceStaNo={}, preferredArea={}, spec={}", |
| | | stage, sourceStaNo, preferredArea, JSON.toJSONString(locTypeDto)); |
| | |
| | | continue; |
| | | } |
| | | Integer targetStaNo = resolveTargetStaNo(rowLastno, staDescId, sourceStaNo, candidateCrnNo); |
| | | if (Utils.BooleanWhsTypeSta(rowLastno, staDescId) && targetStaNo == null) { |
| | | if (routeRequired && Utils.BooleanWhsTypeSta(rowLastno, staDescId) && targetStaNo == null) { |
| | | routeBlockedCrns.add(candidateCrnNo); |
| | | continue; |
| | | } |
| | | Wrapper<LocMast> openWrapper = new EntityWrapper<LocMast>() |
| | | .eq("crn_no", candidateCrnNo) |
| | | .eq("loc_sts", "O") |
| | | .eq("loc_type1", locTypeDto.getLocType1()) |
| | | .orderBy("lev1") |
| | | .orderBy("bay1"); |
| | | .eq("loc_sts", "O"); |
| | | applyLocTypeFilters(openWrapper, locTypeDto, true); |
| | | openWrapper.orderBy("lev1").orderBy("bay1"); |
| | | LocMast anyOpenLoc = locMastService.selectOne(openWrapper); |
| | | if (Cools.isEmpty(anyOpenLoc)) { |
| | | noEmptyCrns.add(candidateCrnNo); |
| | |
| | | } |
| | | Wrapper<LocMast> wrapper = new EntityWrapper<LocMast>() |
| | | .eq("crn_no", candidateCrnNo) |
| | | .eq("loc_sts", "O") |
| | | .eq("loc_type1", locTypeDto.getLocType1()) |
| | | .orderBy("lev1") |
| | | .orderBy("bay1"); |
| | | if (locTypeDto != null && locTypeDto.getLocType1() != null) { |
| | | wrapper.eq("loc_type1", locTypeDto.getLocType1()); |
| | | } |
| | | .eq("loc_sts", "O"); |
| | | applyLocTypeFilters(wrapper, locTypeDto, true); |
| | | wrapper.orderBy("lev1").orderBy("bay1"); |
| | | LocMast candidateLoc = locMastService.selectOne(wrapper); |
| | | if (Cools.isEmpty(candidateLoc) || (locTypeDto != null && !VersionUtils.locMoveCheckLocTypeComplete(candidateLoc, locTypeDto))) { |
| | | locTypeBlockedCrns.add(candidateCrnNo); |
| | |
| | | if (candidateLocType1 != 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); |
| | |
| | | } |
| | | Wrapper<LocMast> wrapper = new EntityWrapper<LocMast>() |
| | | .in("row1", searchRows) |
| | | .eq("loc_sts", "O") |
| | | .eq("whs_type", rowLastnoType.getType().longValue()); |
| | | if (locTypeDto != null && locTypeDto.getLocType1() != null) { |
| | | wrapper.eq("loc_type1", locTypeDto.getLocType1()); |
| | | } |
| | | .eq("loc_sts", "O"); |
| | | applyLocTypeFilters(wrapper, locTypeDto, true); |
| | | return locMastService.selectCount(wrapper); |
| | | } |
| | | |
| | |
| | | compatibleLocTypeDto.setLocType3(locTypeDto.getLocType3()); |
| | | compatibleLocTypeDto.setSiteId(locTypeDto.getSiteId()); |
| | | return compatibleLocTypeDto; |
| | | } |
| | | |
| | | /** |
| | | * 空托盘兼容回退规则: |
| | | * 当首轮 loc_type2=1 没有命中空库位时,允许退化到高位空库位 loc_type1=2。 |
| | | * |
| | | * 注意这里不会继续保留 locType2=1。 |
| | | * 也就是说第二轮是“高位优先兜底”,而不是“高位窄库位兜底”。 |
| | | * 这是按照现场最新口径实现的:窄库位优先,窄库位没有时再找高位空库位。 |
| | | */ |
| | | private LocTypeDto buildEmptyPalletCompatibleLocTypeDto(LocTypeDto locTypeDto) { |
| | | if (locTypeDto == null || locTypeDto.getLocType2() == null || locTypeDto.getLocType2() != 1) { |
| | | return null; |
| | | } |
| | | LocTypeDto compatibleLocTypeDto = new LocTypeDto(); |
| | | compatibleLocTypeDto.setLocType1((short) 2); |
| | | compatibleLocTypeDto.setLocType3(locTypeDto.getLocType3()); |
| | | compatibleLocTypeDto.setSiteId(locTypeDto.getSiteId()); |
| | | return compatibleLocTypeDto; |
| | | } |
| | | |
| | | /** |
| | | * 统一封装找库位失败后的兼容重试顺序。 |
| | | * |
| | | * 空托盘: |
| | | * 先按 loc_type2=1 查找,失败后退到 loc_type1=2。 |
| | | * |
| | | * 非空托盘: |
| | | * 维持原规则,低位失败后再向高位兼容。 |
| | | */ |
| | | private LocTypeDto buildRetryCompatibleLocTypeDto(Integer staDescId, FindLocNoAttributeVo findLocNoAttributeVo, LocTypeDto locTypeDto) { |
| | | if (isEmptyPalletRequest(staDescId, findLocNoAttributeVo)) { |
| | | LocTypeDto emptyPalletCompatibleLocTypeDto = buildEmptyPalletCompatibleLocTypeDto(locTypeDto); |
| | | if (emptyPalletCompatibleLocTypeDto != null) { |
| | | return emptyPalletCompatibleLocTypeDto; |
| | | } |
| | | } |
| | | return buildUpwardCompatibleLocTypeDto(locTypeDto); |
| | | } |
| | | |
| | | |
| | |
| | | times = times + 1; |
| | | return getLocNoRun(whsType, staDescId, sourceStaNo, findLocNoAttributeVo, moveCrnNo, locTypeDto, times); |
| | | } |
| | | LocTypeDto compatibleLocTypeDto = buildUpwardCompatibleLocTypeDto(locTypeDto); |
| | | LocTypeDto compatibleLocTypeDto = buildRetryCompatibleLocTypeDto(staDescId, findLocNoAttributeVo, locTypeDto); |
| | | if (compatibleLocTypeDto != null) { |
| | | log.warn("locType1 upward compatibility retry. source={}, target={}", JSON.toJSONString(locTypeDto), JSON.toJSONString(compatibleLocTypeDto)); |
| | | log.warn("locType compatibility retry. source={}, target={}", JSON.toJSONString(locTypeDto), JSON.toJSONString(compatibleLocTypeDto)); |
| | | return getLocNoRun(whsType, staDescId, sourceStaNo, findLocNoAttributeVo, moveCrnNo, compatibleLocTypeDto, 0); |
| | | } |
| | | log.error("No empty location found. spec={}, times={}", JSON.toJSONString(locTypeDto), times); |
| | |
| | | return getLocNoRun2(whsType, staDescId, sourceStaNo, findLocNoAttributeVo, moveCrnNo, locTypeDto, null, times); |
| | | } |
| | | |
| | | /** |
| | | * run2 入库找位主流程。 |
| | | * |
| | | * 当前方法只保留“组织流程”和“统一收口”的职责,具体策略拆成独立方法: |
| | | * 1. 普通物料:推荐排优先 -> 站点优先库区/堆垛机 -> 其它库区。 |
| | | * 2. 空托盘:优先库区 loc_type2=1 -> 其它库区 loc_type2=1 -> loc_type1=2 兼容。 |
| | | * 3. 命中库位后分别回写普通物料游标或空托盘库区游标。 |
| | | */ |
| | | public StartupDto getLocNoRun2(Integer whsType, Integer staDescId, Integer sourceStaNo, FindLocNoAttributeVo findLocNoAttributeVo, Integer moveCrnNo, LocTypeDto locTypeDto, List<Integer> recommendRows, int times) { |
| | | |
| | | int crnNo = 0; |
| | |
| | | curRow = rowLastno.getCurrentRow(); |
| | | crnNo = resolveRun2CrnNo(rowLastno); |
| | | Integer preferredArea = findLocNoAttributeVo.getOutArea(); |
| | | boolean emptyPalletRequest = isEmptyPalletRequest(staDescId, findLocNoAttributeVo); |
| | | Run2AreaSearchResult emptyPalletAreaSearchResult = null; |
| | | |
| | | List<Integer> orderedCrnNos = getOrderedCrnNos(rowLastno, crnNo); |
| | | List<Integer> triedCrnNos = new ArrayList<>(); |
| | | List<Integer> recommendCrnNos = mapRowsToCrnNos(rowLastno, recommendRows); |
| | | if (!Cools.isEmpty(recommendCrnNos)) { |
| | | locMast = findRun2EmptyLocByCrnNos(rowLastno, rowLastnoType, recommendCrnNos, locTypeDto, staDescId, sourceStaNo, startupDto, preferredArea, "recommend"); |
| | | triedCrnNos.addAll(recommendCrnNos); |
| | | } |
| | | locMast = findRun2RecommendLoc(rowLastno, rowLastnoType, emptyPalletRequest, recommendRows, locTypeDto, |
| | | staDescId, sourceStaNo, startupDto, preferredArea, triedCrnNos); |
| | | if (Cools.isEmpty(locMast)) { |
| | | List<Map<String, Integer>> stationCrnLocTypes = Utils.getStationStorageAreaName( |
| | | sourceStaNo, |
| | | locTypeDto == null || locTypeDto.getLocType1() == null ? null : locTypeDto.getLocType1().intValue(), |
| | | findLocNoAttributeVo == null ? null : findLocNoAttributeVo.getMatnr()); |
| | | if (!Cools.isEmpty(stationCrnLocTypes)) { |
| | | locMast = findRun2EmptyLocByCrnLocTypeEntries(rowLastno, rowLastnoType, stationCrnLocTypes, |
| | | locTypeDto, staDescId, sourceStaNo, startupDto, preferredArea, "station-priority"); |
| | | } else if (preferredArea == null) { |
| | | List<Integer> defaultCrnNos = new ArrayList<>(orderedCrnNos); |
| | | defaultCrnNos.removeAll(triedCrnNos); |
| | | locMast = findRun2EmptyLocByCrnNos(rowLastno, rowLastnoType, defaultCrnNos, locTypeDto, staDescId, sourceStaNo, startupDto, preferredArea, "default"); |
| | | } else { |
| | | List<Integer> preferredCrnNos = filterCrnNosByRows(rowLastno, orderedCrnNos, getRun2AreaRows(preferredArea, rowLastno)); |
| | | preferredCrnNos.removeAll(triedCrnNos); |
| | | locMast = findRun2EmptyLocByCrnNos(rowLastno, rowLastnoType, preferredCrnNos, locTypeDto, staDescId, sourceStaNo, startupDto, preferredArea, "preferred-area"); |
| | | if (Cools.isEmpty(locMast)) { |
| | | List<Integer> fallbackCrnNos = filterCrnNosByRows(rowLastno, orderedCrnNos, getRun2FallbackRows(rowLastno)); |
| | | fallbackCrnNos.removeAll(triedCrnNos); |
| | | fallbackCrnNos.removeAll(preferredCrnNos); |
| | | locMast = findRun2EmptyLocByCrnNos(rowLastno, rowLastnoType, fallbackCrnNos, locTypeDto, staDescId, sourceStaNo, startupDto, preferredArea, "fallback-area"); |
| | | if (emptyPalletRequest) { |
| | | // 空托盘单独按库区轮询: |
| | | // 1. 当前库区先找 loc_type2=1 |
| | | // 2. 当前库区没有,再找其他库区 loc_type2=1 |
| | | // 3. 全部 narrow 都没有时,再退到 loc_type1=2 |
| | | emptyPalletAreaSearchResult = findEmptyPalletRun2AreaLoc(rowLastno, staDescId, sourceStaNo, startupDto, preferredArea, locTypeDto); |
| | | if (!Cools.isEmpty(emptyPalletAreaSearchResult)) { |
| | | locMast = emptyPalletAreaSearchResult.locMast; |
| | | } |
| | | } else { |
| | | locMast = findNormalRun2Loc(rowLastno, rowLastnoType, sourceStaNo, staDescId, findLocNoAttributeVo, |
| | | locTypeDto, startupDto, preferredArea, orderedCrnNos, triedCrnNos); |
| | | } |
| | | } |
| | | |
| | |
| | | crnNo = locMast.getCrnNo(); |
| | | nearRow = locMast.getRow1(); |
| | | } |
| | | if (curRow == 0) { |
| | | curRow = rowLastno.getsRow() == null ? 1 : rowLastno.getsRow(); |
| | | if (emptyPalletRequest) { |
| | | advanceEmptyPalletRun2Cursor(emptyPalletAreaSearchResult, locMast); |
| | | } else { |
| | | advanceNormalRun2Cursor(rowLastno, curRow); |
| | | } |
| | | curRow = getNextRun2CurrentRow(rowLastno, curRow); |
| | | rowLastno.setCurrentRow(curRow); |
| | | rowLastnoService.updateById(rowLastno); |
| | | |
| | | if (Cools.isEmpty(locMast) || !locMast.getLocSts().equals("O")) { |
| | | if (times < rowCount * 2) { |
| | | if (!emptyPalletRequest && times < rowCount * 2) { |
| | | times = times + 1; |
| | | return getLocNoRun2(whsType, staDescId, sourceStaNo, findLocNoAttributeVo, moveCrnNo, locTypeDto, recommendRows, times); |
| | | } |
| | | LocTypeDto compatibleLocTypeDto = buildUpwardCompatibleLocTypeDto(locTypeDto); |
| | | LocTypeDto compatibleLocTypeDto = buildRetryCompatibleLocTypeDto(staDescId, findLocNoAttributeVo, locTypeDto); |
| | | if (compatibleLocTypeDto != null) { |
| | | log.warn("locType1 upward compatibility retry. source={}, target={}", JSON.toJSONString(locTypeDto), JSON.toJSONString(compatibleLocTypeDto)); |
| | | // 第一轮全部堆垛机都没找到时,再进入规格兼容重试,不在单个堆垛机内局部退化。 |
| | | 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={}, times={}, preferredArea={}, nearRow={}", JSON.toJSONString(locTypeDto), times, preferredArea, nearRow); |
| | |
| | | times = times + 1; |
| | | return getLocNoRun4(whsType, staDescId, sourceStaNo, findLocNoAttributeVo, moveCrnNo, locTypeDto, times); |
| | | } |
| | | LocTypeDto compatibleLocTypeDto = buildUpwardCompatibleLocTypeDto(locTypeDto); |
| | | LocTypeDto compatibleLocTypeDto = buildRetryCompatibleLocTypeDto(staDescId, findLocNoAttributeVo, locTypeDto); |
| | | if (compatibleLocTypeDto != null) { |
| | | log.warn("locType1 upward compatibility retry. source={}, target={}", JSON.toJSONString(locTypeDto), JSON.toJSONString(compatibleLocTypeDto)); |
| | | log.warn("locType compatibility retry. source={}, target={}", JSON.toJSONString(locTypeDto), JSON.toJSONString(compatibleLocTypeDto)); |
| | | return getLocNoRun4(whsType, staDescId, sourceStaNo, findLocNoAttributeVo, moveCrnNo, compatibleLocTypeDto, 0); |
| | | } |
| | | log.error("No empty location found. spec={}, times={}", JSON.toJSONString(locTypeDto), times); |
| | |
| | | times = times + 1; |
| | | return getLocNoRun5(whsType, staDescId, sourceStaNo, findLocNoAttributeVo, moveCrnNo, locTypeDto, recommendRows, times); |
| | | } |
| | | LocTypeDto compatibleLocTypeDto = buildUpwardCompatibleLocTypeDto(locTypeDto); |
| | | LocTypeDto compatibleLocTypeDto = buildRetryCompatibleLocTypeDto(staDescId, findLocNoAttributeVo, locTypeDto); |
| | | if (compatibleLocTypeDto != null) { |
| | | log.warn("locType1 upward compatibility retry. source={}, target={}", JSON.toJSONString(locTypeDto), JSON.toJSONString(compatibleLocTypeDto)); |
| | | log.warn("locType compatibility retry. source={}, target={}", JSON.toJSONString(locTypeDto), JSON.toJSONString(compatibleLocTypeDto)); |
| | | return getLocNoRun5(whsType, staDescId, sourceStaNo, findLocNoAttributeVo, moveCrnNo, compatibleLocTypeDto, recommendRows, 0); |
| | | } |
| | | log.error("No empty location found. spec={}, times={}", JSON.toJSONString(locTypeDto), times); |