|  |  | 
 |  |  | import java.time.temporal.ChronoUnit; | 
 |  |  | import java.util.ArrayList; | 
 |  |  | import java.util.List; | 
 |  |  | import java.util.Optional; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * 货架核心功能 | 
 |  |  | 
 |  |  |         return null; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     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; | 
 |  |  | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  | //        // 靠近摆放规则 --- 空托  //分离版 | 
 |  |  | //        if (staDescId == 10 && Utils.BooleanWhsTypeStaIoType(whsType)) { | 
 |  |  | //            List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>().eq("row1", nearRow).eq("loc_sts", "O")); | 
 |  |  | //            for (LocMast locMast1:locMasts){ | 
 |  |  | //                if (VersionUtils.locMoveCheckLocTypeComplete(locMast1, locTypeDto)) { | 
 |  |  | //                    continue; | 
 |  |  | //                } | 
 |  |  | //                String shallowLoc = Utils.getDeepLoc(slaveProperties,locMast1.getLocNo()); | 
 |  |  | //                LocMast locMast2 = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no",shallowLoc)); | 
 |  |  | //                if (!Cools.isEmpty(locMast2) && locMast2.getLocSts().equals("D")){ | 
 |  |  | //                    locMast = locMast1; | 
 |  |  | //                    break; | 
 |  |  | //                } | 
 |  |  | //            } | 
 |  |  | //        } | 
 |  |  |  | 
 |  |  |         // 靠近摆放规则 --- 空托 //互通版 | 
 |  |  |         if (staDescId == 10 && Utils.BooleanWhsTypeStaIoType(rowLastno)) { | 
 |  |  | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // 开始查找库位 ==============================>> | 
 |  |  |         if (staDescId == 10 && 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()) | 
 |  |  |                     .orderBy("lev1", false).orderBy("bay1", true)); | 
 |  |  |             for (LocMast locMast1 : locMasts) { | 
 |  |  |                 if (!VersionUtils.locMoveCheckLocTypeComplete(locMast1, locTypeDto)) { | 
 |  |  |                     continue; | 
 |  |  |                 } | 
 |  |  |                 if (Utils.BooleanWhsTypeStaIoType(rowLastno)) { | 
 |  |  |                     String shallowLoc = Utils.getDeepLoc(slaveProperties, locMast1.getLocNo()); | 
 |  |  |                     LocMast locMast2 = locMastService.selectOne(new EntityWrapper<LocMast>() | 
 |  |  |                             .eq("loc_no", shallowLoc).eq("loc_sts", "O").eq("whs_type", rowLastnoType.getType().longValue())); | 
 |  |  |                     if (!Cools.isEmpty(locMast2)) { | 
 |  |  |                         locMast = locMast2; | 
 |  |  |                         break; | 
 |  |  |                     } | 
 |  |  |                 } else { | 
 |  |  |                     if (!Cools.isEmpty(locMast1)) { | 
 |  |  |                         locMast = locMast1; | 
 |  |  |                         break; | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             if (Cools.isEmpty(locMast) && Utils.BooleanWhsTypeStaIoType(rowLastno)) { | 
 |  |  |                 for (LocMast locMast1 : locMasts) { | 
 |  |  |                     if (!VersionUtils.locMoveCheckLocTypeComplete(locMast1, locTypeDto)) { | 
 |  |  |                         continue; | 
 |  |  |                     } | 
 |  |  |                     if (Utils.BooleanWhsTypeStaIoType(rowLastno)) { | 
 |  |  |                         String shallowLoc = Utils.getDeepLoc(slaveProperties, locMast1.getLocNo()); | 
 |  |  |                         LocMast locMast2 = locMastService.selectOne(new EntityWrapper<LocMast>() | 
 |  |  |                                 .eq("loc_no", shallowLoc).eq("loc_sts", "O").eq("whs_type", rowLastnoType.getType().longValue())); | 
 |  |  |                         if (!Cools.isEmpty(locMast2)) { | 
 |  |  |                             locMast = locMast2; | 
 |  |  |                             break; | 
 |  |  |                         } else { | 
 |  |  |                             locMast2 = locMastService.selectOne(new EntityWrapper<LocMast>() | 
 |  |  |                                     .eq("loc_no", shallowLoc).eq("loc_sts", "F").eq("whs_type", rowLastnoType.getType().longValue())); | 
 |  |  |                             if (!Cools.isEmpty(locMast2)) { | 
 |  |  |                                 locMast = locMast1; | 
 |  |  |                                 break; | 
 |  |  |                             } else { | 
 |  |  |                                 locMast2 = locMastService.selectOne(new EntityWrapper<LocMast>() | 
 |  |  |                                         .eq("loc_no", shallowLoc).eq("loc_sts", "D").eq("whs_type", rowLastnoType.getType().longValue())); | 
 |  |  |                                 if (!Cools.isEmpty(locMast2)) { | 
 |  |  |                                     locMast = locMast1; | 
 |  |  |                                     break; | 
 |  |  |                                 } | 
 |  |  |                             } | 
 |  |  |                         } | 
 |  |  |                     } else { | 
 |  |  |                         if (!Cools.isEmpty(locMast1)) { | 
 |  |  |                             locMast = locMast1; | 
 |  |  |                             break; | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         // 1.按规则查找库位 | 
 |  |  |         if (Cools.isEmpty(locMast) && crnNo != 0) { |