| | |
| | | */ |
| | | switch (rowLastnoType.getType()) { |
| | | case 4: |
| | | return getLocNoRun4(whsType, staDescId, sourceStaNo, matnr, batch, grade, 4, locTypeDto, 0); |
| | | return getLocNoRun4(whsType, staDescId, sourceStaNo, matnr, batch, grade, 4, locTypeDto, 2); |
| | | } |
| | | } catch (CoolException ex) { |
| | | log.error("入库失败,错误信息: {}", ex.getMessage(), ex); |
| | |
| | | RowLastno rowLastno = rowLastnoService.selectById(4); |
| | | LocMast locMast = null; // 目标库位 |
| | | StartupDto startupDto = new StartupDto(); |
| | | int MaxBay = rowLastno.getCurrentRow(); |
| | | int curRow = rowLastno.getCurrentRow(); |
| | | int sRow = rowLastno.getsRow(); |
| | | int eRow = rowLastno.geteRow(); |
| | | //满版空板入库规则 |
| | | switch (staDescId){ |
| | | //全板 |
| | | case 1: |
| | | // 从第 3 列开始 轮询每一列 |
| | | int currentBay = 1; |
| | | while (currentBay <= MaxBay) { // |
| | | locMast = locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .ge("row1", sRow) // 排范围:起始到结束 |
| | | .le("row1", eRow) |
| | | .ne("row1", 8) // 排除第8排 |
| | | .eq("loc_sts", "O") // 空库位 |
| | | .eq("bay1", currentBay) // 当前列 |
| | | .eq("loc_type1", locTypeDto.getLocType1()) |
| | | .orderBy("row1 ASC, lev1 ASC")); // 按排和层排序 |
| | | |
| | | if (!Cools.isEmpty(locMast)) { |
| | | // 检查是否符合商品编号和批号规则 |
| | | LocDetl locDetl = locDetlService.selectOne(new EntityWrapper<LocDetl>() |
| | | .eq("loc_no", locMast.getLocNo()) |
| | | .andNew() |
| | | .eq("matnr", matnr) |
| | | .eq("batch", batch)); |
| | | |
| | | if (Cools.isEmpty(locDetl) || (matnr.equals(locDetl.getMatnr()) && batch.equals(locDetl.getBatch()))) { |
| | | // 找到符合条件的库位,跳出循环 |
| | | break; |
| | | } |
| | | } |
| | | |
| | | // 当前列无空位,检查下一列 |
| | | currentBay++; |
| | | int nearRow = 8;//特殊单排 |
| | | int orbit = 7;//轨道 |
| | | // 相似工作档案 --- 同天同规格物料 |
| | | if (!Cools.isEmpty(matnr) && (staDescId == 1 || staDescId == 11 || staDescId == 111) ) { |
| | | //查询相似工作档案 |
| | | List<WrkMast> wrkMasts = wrkMastService.selectWrkMastWrkDetlMatnrBatch(1, matnr, batch,null, crnNo); |
| | | for (WrkMast wrkMast:wrkMasts){ |
| | | if (Cools.isEmpty(wrkMast.getLocNo())){ |
| | | continue; |
| | | } |
| | | // ③ 如果第一排全满,检索第8排 |
| | | if (Cools.isEmpty(locMast)) { |
| | | for (int bay = 1; bay <= MaxBay; bay++) { |
| | | locMast = locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("row1", 8) // 第8排 |
| | | .eq("loc_sts", "O") // 空库位状态 |
| | | .eq("bay1", bay) // 当前列 |
| | | .orderBy("lev1 ASC")); // 按层排序 |
| | | |
| | | if (!Cools.isEmpty(locMast)) { |
| | | break; // 找到符合条件的库位,退出循环 |
| | | } |
| | | } |
| | | //目标排为轨道外排 |
| | | if (Utils.getRow(wrkMast.getLocNo()) == orbit || Utils.getRow(wrkMast.getLocNo()) == nearRow){ |
| | | continue; |
| | | } |
| | | |
| | | // 如果没有找到符合条件的库位 |
| | | if (Cools.isEmpty(locMast)) { |
| | | log.error("系统没有空库位!!! 尺寸规格: {},", JSON.toJSONString(locTypeDto)); |
| | | throw new CoolException("没有空库位"); |
| | | //查找此库位的浅库位是否为空 |
| | | int value = Integer.valueOf(wrkMast.getLocNo().substring(0, 2)) + 1; |
| | | String loc="0"+value+wrkMast.getLocNo().substring(2); |
| | | LocMast locMast1=locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("loc_no",loc) |
| | | .eq("loc_sts","O") |
| | | .eq("loc_type1", locTypeDto.getLocType1()) |
| | | ); |
| | | if(Cools.isEmpty(locMast1)){ |
| | | continue; |
| | | } |
| | | locMast=locMast1; |
| | | break; |
| | | // 空板规则 |
| | | case 10: |
| | | // ① 优先检索第1排所有列状态为 "D" 的库位 |
| | | // 标签,用于跳出外层循环 |
| | | outerLoop: |
| | | for (int bay = 1; bay <= MaxBay; bay++) { |
| | | locMast = locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("row1", sRow) // 第一排 |
| | | .eq("loc_sts", "D") // 空板状态 |
| | | .eq("bay1", bay) // 当前列 |
| | | .ne("row1", 8) // 排除第8排 |
| | | .orderBy("lev1 ASC")); // 按层排序 |
| | | |
| | | if (!Cools.isEmpty(locMast)) { |
| | | // 从当前列找到状态为 "D" 的库位后,向外依次检索排 |
| | | for (int row = sRow + 1; row <= eRow; row++) { // 从第二排开始 |
| | | LocMast potentialLoc = locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("row1", row) // 当前排 |
| | | .eq("loc_sts", "O") // 空库位状态 |
| | | .eq("bay1", bay) // 当前列 |
| | | .ne("row1", 8) // 排除第8排 |
| | | .eq("lev1",locMast.getLev1())); //当前层 |
| | | |
| | | if (!Cools.isEmpty(potentialLoc)) { |
| | | locMast = potentialLoc; // 更新为找到的空库位 |
| | | break outerLoop; // 找到符合条件的库位,跳出外层循环 |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // ② 如果第1排没有找到 "D",检索状态为 "O" 的库位 |
| | | if (Cools.isEmpty(locMast)) { |
| | | for (int bay = 1; bay <= MaxBay; bay++) { |
| | | locMast = locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("row1", sRow) // 第一排 |
| | | .eq("loc_sts", "O") // 空库位状态 |
| | | .eq("bay1", bay) // 当前列 |
| | | .orderBy("lev1 ASC")); // 按层排序 |
| | | |
| | | if (!Cools.isEmpty(locMast)) { |
| | | break; // 找到符合条件的库位,退出循环 |
| | | } |
| | | } |
| | | } |
| | | |
| | | // ③ 如果第一排全满,检索第8排 |
| | | if (Cools.isEmpty(locMast)) { |
| | | for (int bay = 1; bay <= MaxBay; bay++) { |
| | | locMast = locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("row1", 8) // 第8排 |
| | | .eq("loc_sts", "O") // 空库位状态 |
| | | .eq("bay1", bay) // 当前列 |
| | | .orderBy("lev1 ASC")); // 按层排序 |
| | | |
| | | if (!Cools.isEmpty(locMast)) { |
| | | break; // 找到符合条件的库位,退出循环 |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 如果仍然没有找到符合条件的库位 |
| | | if (Cools.isEmpty(locMast)) { |
| | | log.error("系统没有空库位!!! 尺寸规格: {},", JSON.toJSONString(locTypeDto)); |
| | | throw new CoolException("没有空库位"); |
| | | } |
| | | break; |
| | | |
| | | default: |
| | | throw new CoolException("不支持的库位规则类型: " + staDescId); |
| | | } |
| | | |
| | | } |
| | | |
| | | // 返回找到的库位 |
| | | // 靠近摆放规则 --- 同天同规格物料 |
| | | if (Cools.isEmpty(locMast)) { |
| | | List<LocDetl> locNos = locDetlService.getSameDetlToday(matnr, batch,sRow, eRow); |
| | | for (LocDetl locNo : locNos) { |
| | | //目标排为最外层排 |
| | | if (Utils.getRow(locNo.getLocNo()) == nearRow || Utils.getRow(locNo.getLocNo()) == orbit){ |
| | | continue; |
| | | } |
| | | LocMast locMast2=locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("loc_no",locNo.getLocNo()) |
| | | .eq("loc_sts","F")); |
| | | if(Cools.isEmpty(locMast2)){ |
| | | continue; |
| | | } |
| | | int value = Integer.valueOf(locNo.getLocNo().substring(0, 2)) + 1; |
| | | String loc="0"+value+locNo.getLocNo().substring(2); |
| | | LocMast locMast1=locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("loc_no",loc) |
| | | .eq("loc_sts","O") |
| | | .eq("loc_type1", locTypeDto.getLocType1()) |
| | | ); |
| | | if(Cools.isEmpty(locMast1)){ |
| | | continue; |
| | | } |
| | | locMast=locMast1; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | // 靠近摆放规则 --- 空托 |
| | | if (staDescId == 10) { |
| | | List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>().eq("loc_sts", "D").ge("row1", sRow).le("row1", eRow)); |
| | | if (locMasts.size() > 0) { |
| | | for (LocMast loc : locMasts) { |
| | | if (Utils.isShallowLoc(slaveProperties, loc.getLocNo())) { |
| | | continue; |
| | | } |
| | | String shallowLocNo = Utils.getShallowLoc(slaveProperties, loc.getLocNo()); |
| | | // 检测目标库位是否为空库位 |
| | | LocMast shallowLoc = locMastService.selectById(shallowLocNo); |
| | | if (shallowLoc != null && shallowLoc.getLocSts().equals("O")) { |
| | | if (shallowLoc.getLocType1()<locTypeDto.getLocType1()){ |
| | | continue; |
| | | } |
| | | if (basCrnpService.checkSiteError(shallowLoc.getCrnNo(), true)) { |
| | | locMast = shallowLoc; |
| | | crnNo = locMast.getCrnNo(); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 获取目标站 |
| | | Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>() |
| | | .eq("type_no", staDescId) |
| | | .eq("stn_no", sourceStaNo) |
| | | .eq("crn_no", 1); |
| | | StaDesc staDesc = staDescService.selectOne(wrapper); |
| | | if (Cools.isEmpty(staDesc)) { |
| | | log.error("type_no={},stn_no={},crn_no={}", staDescId, sourceStaNo, crnNo); |
| | | throw new CoolException("入库路径不存在"); |
| | | } |
| | | BasDevp staNo = basDevpService.selectById(staDesc.getStnNo()); |
| | | if (!staNo.getAutoing().equals("Y")) { |
| | | throw new CoolException("目标站"+staDesc.getCrnStn()+"不可用"); |
| | | } |
| | | |
| | | // 如果没有相近物料,则按规则轮询货架 |
| | | if (null == locMast) { |
| | | LocMast locMast1 = new LocMast(); |
| | | if(times != 0){ |
| | | locMast1=locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("row1", 1) |
| | | .eq("loc_sts","O") |
| | | .eq("loc_type1", locTypeDto.getLocType1()) |
| | | .orderBy("lev1,bay1 ASC")); |
| | | } else { |
| | | locMast1=locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("row1", 8) |
| | | .eq("loc_sts","O") |
| | | .eq("loc_type1", locTypeDto.getLocType1()) |
| | | .orderBy("lev1,bay1 ASC")); |
| | | } |
| | | if(!Cools.isEmpty(locMast1)){ |
| | | locMast=locMast1; |
| | | } |
| | | } |
| | | // 更新库位排号 |
| | | rowLastno.setCurrentRow(curRow); |
| | | rowLastnoService.updateById(rowLastno); |
| | | |
| | | // 2.库位当前所属尺寸无空库位时,调整尺寸参数,向上兼容检索库位 |
| | | if (Cools.isEmpty(locMast)) { |
| | | times = times - 1; |
| | | if (times >= 0) { |
| | | return getLocNoRun4(whsType,staDescId, sourceStaNo, matnr, batch, grade,moveCrnNo,locTypeDto,times); |
| | | } |
| | | log.error("系统没有空库位!!! 尺寸规格: {},", JSON.toJSONString(locTypeDto)); |
| | | throw new CoolException("没有空库位"); |
| | | } |
| | | String locNo = locMast.getLocNo(); |
| | | // 返回找到的库位 |
| | | int workNo = getWorkNo(0); |
| | | startupDto.setWorkNo(workNo); |
| | | startupDto.setCrnNo(locMast.getCrnNo()); |
| | |
| | | return startupDto; |
| | | } |
| | | |
| | | public StartupDto getLocNoRunPick(Integer whsType, Integer staDescId, Integer sourceStaNo, String matnr, String batch, String grade, Integer moveCrnNo, LocTypeDto locTypeDto, int times) { |
| | | int crnNo = 1;//小车编号备用 |
| | | RowLastno rowLastno = rowLastnoService.selectById(4); |
| | | LocMast locMast = null; // 目标库位 |
| | | StartupDto startupDto = new StartupDto(); |
| | | int curRow = rowLastno.getCurrentRow(); |
| | | int sRow = rowLastno.getsRow(); |
| | | int eRow = rowLastno.geteRow(); |
| | | int nearRow = 8;//特殊单排 |
| | | int orbit = 7;//轨道 |
| | | // 相似工作档案 --- 同天同规格物料 |
| | | if (!Cools.isEmpty(matnr) && (staDescId == 1 || staDescId == 11 || staDescId == 111) ) { |
| | | //查询相似工作档案 |
| | | List<WrkMast> wrkMasts = wrkMastService.selectWrkMastWrkDetlMatnrBatch(1, matnr, batch,null, crnNo); |
| | | for (WrkMast wrkMast:wrkMasts){ |
| | | if (Cools.isEmpty(wrkMast.getLocNo())){ |
| | | continue; |
| | | } |
| | | //目标排为轨道外排 |
| | | if (Utils.getRow(wrkMast.getLocNo()) == orbit || Utils.getRow(wrkMast.getLocNo()) == nearRow){ |
| | | continue; |
| | | } |
| | | //查找此库位的浅库位是否为空 |
| | | int value = Integer.valueOf(wrkMast.getLocNo().substring(0, 2)) + 1; |
| | | String loc="0"+value+wrkMast.getLocNo().substring(2); |
| | | LocMast locMast1=locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("loc_no",loc) |
| | | .eq("loc_sts","O") |
| | | .eq("loc_type1", locTypeDto.getLocType1()) |
| | | ); |
| | | if(Cools.isEmpty(locMast1)){ |
| | | continue; |
| | | } |
| | | locMast=locMast1; |
| | | break; |
| | | } |
| | | |
| | | } |
| | | |
| | | // 靠近摆放规则 --- 同天同规格物料 |
| | | if (Cools.isEmpty(locMast)) { |
| | | List<LocDetl> locNos = locDetlService.getSameDetlToday(matnr, batch,sRow, eRow); |
| | | for (LocDetl locNo : locNos) { |
| | | //目标排为最外层排 |
| | | if (Utils.getRow(locNo.getLocNo()) == nearRow || Utils.getRow(locNo.getLocNo()) == orbit){ |
| | | continue; |
| | | } |
| | | LocMast locMast2=locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("loc_no",locNo.getLocNo()) |
| | | .eq("loc_sts","F")); |
| | | if(Cools.isEmpty(locMast2)){ |
| | | continue; |
| | | } |
| | | int value = Integer.valueOf(locNo.getLocNo().substring(0, 2)) + 1; |
| | | String loc="0"+value+locNo.getLocNo().substring(2); |
| | | LocMast locMast1=locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("loc_no",loc) |
| | | .eq("loc_sts","O") |
| | | .eq("loc_type1", locTypeDto.getLocType1()) |
| | | ); |
| | | if(Cools.isEmpty(locMast1)){ |
| | | continue; |
| | | } |
| | | locMast=locMast1; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | // 靠近摆放规则 --- 空托 |
| | | if (staDescId == 10) { |
| | | List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>().eq("loc_sts", "D").ge("row1", sRow).le("row1", eRow)); |
| | | if (locMasts.size() > 0) { |
| | | for (LocMast loc : locMasts) { |
| | | if (Utils.isShallowLoc(slaveProperties, loc.getLocNo())) { |
| | | continue; |
| | | } |
| | | String shallowLocNo = Utils.getShallowLoc(slaveProperties, loc.getLocNo()); |
| | | // 检测目标库位是否为空库位 |
| | | LocMast shallowLoc = locMastService.selectById(shallowLocNo); |
| | | if (shallowLoc != null && shallowLoc.getLocSts().equals("O")) { |
| | | if (shallowLoc.getLocType1()<locTypeDto.getLocType1()){ |
| | | continue; |
| | | } |
| | | if (basCrnpService.checkSiteError(shallowLoc.getCrnNo(), true)) { |
| | | locMast = shallowLoc; |
| | | crnNo = locMast.getCrnNo(); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 获取目标站 |
| | | Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>() |
| | | .eq("type_no", staDescId) |
| | | .eq("stn_no", sourceStaNo) |
| | | .eq("crn_no", 1); |
| | | StaDesc staDesc = staDescService.selectOne(wrapper); |
| | | if (Cools.isEmpty(staDesc)) { |
| | | log.error("type_no={},stn_no={},crn_no={}", staDescId, sourceStaNo, crnNo); |
| | | throw new CoolException("入库路径不存在"); |
| | | } |
| | | BasDevp staNo = basDevpService.selectById(staDesc.getStnNo()); |
| | | if (!staNo.getAutoing().equals("Y")) { |
| | | throw new CoolException("目标站"+staDesc.getCrnStn()+"不可用"); |
| | | } |
| | | |
| | | // 如果没有相近物料,则按规则轮询货架 |
| | | if (null == locMast) { |
| | | LocMast locMast1 = new LocMast(); |
| | | if(times != 0){ |
| | | locMast1=locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("row1", 1) |
| | | .eq("loc_sts","O") |
| | | .eq("loc_type1", locTypeDto.getLocType1()) |
| | | .orderBy("lev1,bay1 ASC")); |
| | | } else { |
| | | locMast1=locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("row1", 8) |
| | | .eq("loc_sts","O") |
| | | .eq("loc_type1", locTypeDto.getLocType1()) |
| | | .orderBy("lev1,bay1 ASC")); |
| | | } |
| | | if(!Cools.isEmpty(locMast1)){ |
| | | locMast=locMast1; |
| | | } |
| | | } |
| | | // 更新库位排号 |
| | | rowLastno.setCurrentRow(curRow); |
| | | rowLastnoService.updateById(rowLastno); |
| | | |
| | | // 2.库位当前所属尺寸无空库位时,调整尺寸参数,向上兼容检索库位 |
| | | if (Cools.isEmpty(locMast)) { |
| | | times = times - 1; |
| | | if (times >= 0) { |
| | | return getLocNoRun4(whsType,staDescId, sourceStaNo, matnr, batch, grade,moveCrnNo,locTypeDto,times); |
| | | } |
| | | log.error("系统没有空库位!!! 尺寸规格: {},", JSON.toJSONString(locTypeDto)); |
| | | throw new CoolException("没有空库位"); |
| | | } |
| | | String locNo = locMast.getLocNo(); |
| | | // 返回找到的库位 |
| | | startupDto.setWorkNo(0); |
| | | startupDto.setCrnNo(locMast.getCrnNo()); |
| | | startupDto.setSourceStaNo(sourceStaNo); |
| | | startupDto.setLocNo(locNo); |
| | | |
| | | return startupDto; |
| | | } |
| | | |
| | | public StartupDto getLocNoRun5(Integer whsType, Integer staDescId, Integer sourceStaNo, String matnr, String batch, String grade, Integer moveCrnNo, LocTypeDto locTypeDto, int times) { |
| | | if (Cools.isEmpty(matnr)) { //物料号 |
| | | matnr = ""; |