|  |  | 
 |  |  | import java.time.temporal.ChronoUnit; | 
 |  |  | import java.util.ArrayList; | 
 |  |  | import java.util.List; | 
 |  |  | import java.util.Optional; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * 货架核心功能 | 
 |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     private Optional<CrnRowInfo> findAvailableCrnAndNearRow(RowLastno rowLastno, int curRow, int crnNumber, int times, | 
 |  |  |                                                             FindLocNoAttributeVo findLocNoAttributeVo, LocTypeDto locTypeDto, | 
 |  |  |                                                             RowLastnoType rowLastnoType) { | 
 |  |  |         int attempt = times; | 
 |  |  |         while (attempt < crnNumber * 2) { | 
 |  |  |             int[] params = Utils.LocNecessaryParameters(rowLastno, curRow, crnNumber); | 
 |  |  |             curRow = params[1]; | 
 |  |  |             int crnNo = params[2]; | 
 |  |  |             if (!basCrnpService.checkSiteError(crnNo, true)) { | 
 |  |  |                 attempt++; | 
 |  |  |                 continue; | 
 |  |  |             } | 
 |  |  |             int rowCount = params[0]; | 
 |  |  |             int nearRow = params[3]; | 
 |  |  |  | 
 |  |  |             // 只取数量判断,避免拉整 list | 
 |  |  |             int availableLocCount = locMastService.selectCount(new EntityWrapper<LocMast>() | 
 |  |  |                     .eq("row1", nearRow) | 
 |  |  |                     .eq("loc_sts", "O") | 
 |  |  |                     .eq("whs_type", rowLastnoType.getType().longValue())); | 
 |  |  |             int crnCountO = wrkMastService.selectCount(new EntityWrapper<WrkMast>() | 
 |  |  |                     .eq("crn_no", crnNo).le("io_type", 100)); | 
 |  |  |             if (availableLocCount - crnCountO <= 2) { // 可以提成常量,比如 MIN_SPARE_SLOTS = 2 | 
 |  |  |                 log.error("{}号堆垛机没有空库位!!! 尺寸规格: {}, 轮询次数:{}", crnNo, JSON.toJSONString(locTypeDto), attempt); | 
 |  |  |                 attempt++; | 
 |  |  |                 continue; | 
 |  |  |             } | 
 |  |  |             return Optional.of(new CrnRowInfo(crnNo, nearRow, curRow, rowCount, attempt)); | 
 |  |  |         } | 
 |  |  |         return Optional.empty(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 检索库位号 | 
 |  |  | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         //此程序用于优化堆垛机异常时的运行时间 | 
 |  |  |         for (int i = times; i < crnNumber * 2; i++) { | 
 |  |  |             int[] locNecessaryParameters = Utils.LocNecessaryParameters(rowLastno, curRow, crnNumber); | 
 |  |  |             curRow = locNecessaryParameters[1]; | 
 |  |  |             crnNo = locNecessaryParameters[2]; | 
 |  |  |             if (basCrnpService.checkSiteError(crnNo, true)) { | 
 |  |  |                 rowCount = locNecessaryParameters[0]; | 
 |  |  |                 nearRow = locNecessaryParameters[3]; | 
 |  |  |                 List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>() | 
 |  |  |                         .eq("row1", nearRow).eq("loc_sts", "O").eq("whs_type", rowLastnoType.getType().longValue())); | 
 |  |  |                 int crnCountO = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("crn_no", crnNo).le("io_type", 100)); | 
 |  |  |                 if (locMasts.size() - crnCountO <= 2) { | 
 |  |  |                     log.error(crnNo + "号堆垛机没有空库位!!! 尺寸规格: {}, 轮询次数:{}", JSON.toJSONString(locTypeDto), times); | 
 |  |  |                     nearRow = 0; | 
 |  |  |                     times++; | 
 |  |  |                     continue; | 
 |  |  |                 } | 
 |  |  |                 break; | 
 |  |  |             } else { | 
 |  |  |                 times++; | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         if (nearRow == 0) { | 
 |  |  |         Optional<CrnRowInfo> infoOpt = findAvailableCrnAndNearRow(rowLastno, curRow, crnNumber, times, findLocNoAttributeVo, locTypeDto, rowLastnoType); | 
 |  |  |         if (!infoOpt.isPresent()) { | 
 |  |  |             throw new CoolException("无可用堆垛机"); | 
 |  |  |         } | 
 |  |  |         CrnRowInfo info = infoOpt.get(); | 
 |  |  |         crnNo = info.getCrnNo(); | 
 |  |  |         nearRow = info.getNearRow(); | 
 |  |  |         curRow = info.getCurRow(); | 
 |  |  |         rowCount = info.getRowCount(); | 
 |  |  |         times = info.getTimes(); | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         boolean signRule1 = false; | 
 |  |  |         boolean signRule2 = false; |