| | |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.entity.result.FindLocNoAttributeVo; |
| | | import com.zy.asrs.entity.result.KeyValueVo; |
| | | import com.zy.asrs.mapper.LocDetlMapper; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.asrs.utils.VersionUtils; |
| | |
| | | private LocMastService locMastService; |
| | | @Autowired |
| | | private LocDetlService locDetlService; |
| | | @Autowired |
| | | private LocDetlMapper locDetlMapper; |
| | | @Autowired |
| | | private SlaveProperties slaveProperties; |
| | | @Autowired |
| | |
| | | */ |
| | | switch (rowLastnoType.getType()) { |
| | | case 1: |
| | | return getLocNoRun(whsType, staDescId, sourceStaNo, findLocNoAttributeVo, 0, locTypeDto, 0); |
| | | return getLocNoRunV3(whsType, staDescId, sourceStaNo, findLocNoAttributeVo, 0, locTypeDto, 0); |
| | | case 2: |
| | | return getLocNoRun(whsType, staDescId, sourceStaNo, findLocNoAttributeVo, 0, locTypeDto, 0); |
| | | return getLocNoRunV3(whsType, staDescId, sourceStaNo, findLocNoAttributeVo, 0, locTypeDto, 0); |
| | | case 3: |
| | | log.error("站点={} 未查询到对应的规则", sourceStaNo); |
| | | break; |
| | |
| | | return null; |
| | | } |
| | | |
| | | |
| | | @Transactional |
| | | public StartupDto getLocNoV2(Integer staDescId, Integer sourceStaNo, WrkMast wrkMast, LocTypeDto locTypeDto) { |
| | | try { |
| | | Integer whsType = 1; |
| | | RowLastno rowLastno = rowLastnoService.selectById(whsType); |
| | | RowLastnoType rowLastnoType = rowLastnoTypeService.selectById(rowLastno.getTypeId()); |
| | | /** |
| | | * 库型 1: 标准堆垛机库 2: 同巷道找库位 |
| | | */ |
| | | switch (rowLastnoType.getType()) { |
| | | case 1: |
| | | return getLocNoRunV2(whsType, staDescId, sourceStaNo, wrkMast, 0, locTypeDto, 0); |
| | | case 2: |
| | | return getLocNoRunV2(whsType, staDescId, sourceStaNo, wrkMast, 0, locTypeDto, 0); |
| | | default: |
| | | log.error("站点={} 未查询到对应的规则", sourceStaNo); |
| | | break; |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | log.error("站点={} 未查询到对应的规则", sourceStaNo); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 检索库位号 |
| | | */ |
| | |
| | | public StartupDto getLocNo1(Integer crnNo) { |
| | | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("crn_no", crnNo) |
| | | .eq("loc_sts","O") |
| | | .eq("whs_type",1) |
| | | .eq("loc_sts", "O") |
| | | .eq("whs_type", 1) |
| | | .orderBy("lev1,bay1")); |
| | | if (Cools.isEmpty(locMast)) { |
| | | return null; |
| | |
| | | */ |
| | | @Transactional |
| | | public StartupDto getLocNoRun(Integer whsType, Integer staDescId, Integer sourceStaNo, FindLocNoAttributeVo findLocNoAttributeVo, Integer moveCrnNo, LocTypeDto locTypeDto, int times) { |
| | | StartupDto startupDto = new StartupDto(); |
| | | |
| | | // 初始化参数 |
| | | int crnNo = 0; //堆垛机号 |
| | | int nearRow = 0; //最浅库位排 |
| | | int curRow = 0; //最深库位排 |
| | | int rowCount = 0; //轮询轮次 |
| | | LocMast locMast = null; // 目标库位 |
| | | |
| | | StartupDto startupDto = new StartupDto(); |
| | | RowLastno rowLastno = rowLastnoService.selectById(whsType); |
| | | if (Cools.isEmpty(rowLastno)) { |
| | | throw new CoolException("数据异常,请联系管理员===>库位规则未知"); |
| | | } |
| | | RowLastnoType rowLastnoType = rowLastnoTypeService.selectById(rowLastno.getTypeId()); |
| | | if (Cools.isEmpty(rowLastnoType)) { |
| | | throw new CoolException("数据异常,请联系管理员===》库位规则类型未知"); |
| | | } |
| | | int sRow = rowLastno.getsRow(); |
| | | int eRow = rowLastno.geteRow(); |
| | | int crnNumber = rowLastno.getCrnQty(); |
| | | |
| | | |
| | | // ===============>>>> 开始执行 |
| | | curRow = rowLastno.getCurrentRow(); |
| | | |
| | | if (!Cools.isEmpty(moveCrnNo) && moveCrnNo != 0) { |
| | | crnNumber = moveCrnNo; |
| | | if (times == 0) { |
| | | curRow = moveCrnNo * 4 - 1; |
| | | } else { |
| | | curRow = moveCrnNo * 4 - 2; |
| | | } |
| | | } |
| | | |
| | | //此程序用于优化堆垛机异常时的运行时间 |
| | | for (int i = times; i < crnNumber * 2; i++) { |
| | | int[] locNecessaryParameters = Utils.LocNecessaryParameters(rowLastno, curRow, crnNumber); |
| | | crnNo = locNecessaryParameters[2]; |
| | | if (basCrnpService.checkSiteError(crnNo, true)) { |
| | | nearRow = locNecessaryParameters[3]; |
| | | List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>() |
| | | .eq("row1", nearRow) |
| | | .eq("loc_sts", "O") |
| | | .eq("frozen", 0) |
| | | .eq("deleted", 0) |
| | | .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) { |
| | | if(curRow+2==7){ |
| | | |
| | | } |
| | | log.error(crnNo + "号堆垛机没有空库位!!! 尺寸规格: {}, 轮询次数:{}", JSON.toJSONString(locTypeDto), times); |
| | | nearRow = 0; |
| | | times++; |
| | | continue; |
| | | RowLastno whsType1 = rowLastnoService.selectOne(new EntityWrapper<RowLastno>().eq("whs_type", 2)); |
| | | crnNo = whsType1.getCrnQty(); |
| | | if (basCrnpService.checkSiteError(crnNo, true)) { |
| | | BasCrnp basCrnp = basCrnpService.selectById(crnNo); |
| | | List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>() |
| | | .eq("crn_no", basCrnp.getCrnNo()) |
| | | .eq("loc_sts", "O") |
| | | .eq("frozen", 0) |
| | | .eq("deleted", 0) |
| | | .eq("whs_type", 1) |
| | | .orderBy("lev1,bay1")); |
| | | if (!Cools.isEmpty(locMasts)) { |
| | | if (locMasts.size() > 15) { |
| | | locMast = locMasts.get(0); |
| | | } |
| | | break; |
| | | } else { |
| | | times++; |
| | | } |
| | | } |
| | | if (nearRow == 0) { |
| | | throw new CoolException("无可用堆垛机"); |
| | | int crnNo1 = crnNo + 1; |
| | | if (crnNo1> whsType1.geteCrnNo()) { |
| | | crnNo1 = whsType1.getsCrnNo(); |
| | | } |
| | | whsType1.setCrnQty(crnNo1); |
| | | rowLastnoService.updateById(whsType1); |
| | | |
| | | Wrapper<StaDesc> wrapper = null; |
| | | StaDesc staDesc = null; |
| | | BasDevp staNo = null; |
| | | |
| | | if (Utils.BooleanWhsTypeSta(rowLastno, staDescId)) { |
| | | // 获取目标站 |
| | | wrapper = new EntityWrapper<StaDesc>() |
| | | .eq("type_no", staDescId) |
| | | .eq("stn_no", sourceStaNo) |
| | | .eq("crn_no", crnNo); |
| | | staDesc = staDescService.selectOne(wrapper); |
| | | if (Cools.isEmpty(staDesc)) { |
| | | log.error("type_no={},stn_no={},crn_no={}", staDescId, sourceStaNo, crnNo); |
| | | // throw new CoolException("入库路径不存在"); |
| | | crnNo = 0; |
| | | } else { |
| | | staNo = basDevpService.selectById(staDesc.getCrnStn()); |
| | | if (!staNo.getAutoing().equals("Y")) { |
| | | log.error("目标站" + staDesc.getCrnStn() + "不可用"); |
| | | // throw new CoolException("目标站"+staDesc.getCrnStn()+"不可用"); |
| | | crnNo = 0; |
| | | } |
| | | startupDto.setStaNo(staNo.getDevNo()); |
| | | } |
| | | // 更新库位排号 |
| | | if (Cools.isEmpty(locMast)) { |
| | | rowLastno.setCurrentRow(curRow); |
| | | rowLastnoService.updateById(rowLastno); |
| | | } |
| | | // 获取目标站 |
| | | wrapper = new EntityWrapper<StaDesc>() |
| | | .eq("type_no", staDescId) |
| | | .eq("stn_no", sourceStaNo) |
| | | .eq("crn_no", crnNo); |
| | | staDesc = staDescService.selectOne(wrapper); |
| | | if (Cools.isEmpty(staDesc)) { |
| | | log.error("入库路径不存在type_no={},stn_no={},crn_no={}", staDescId, sourceStaNo, crnNo); |
| | | } |
| | | |
| | | // 开始查找库位 ==============================>> |
| | | |
| | | // 1.按规则查找库位 |
| | | if (Cools.isEmpty(locMast) && crnNo != 0) { |
| | | List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>().eq("loc_sts", "O").eq("crn_no", crnNo).eq("whs_type", rowLastnoType.getType().longValue()).orderBy("lev1").orderBy("bay1")); |
| | | if (!locMasts.isEmpty()) { |
| | | for (LocMast locMast1 : locMasts) { |
| | | if (basCrnpService.checkSiteError(crnNo, true)) { |
| | | locMast = locMast1; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | if (!Cools.isEmpty(locMast) && !basCrnpService.checkSiteError(crnNo, true)) { |
| | | locMast = null; |
| | | } |
| | | |
| | | // 递归查询 |
| | | if (Cools.isEmpty(locMast) || !locMast.getLocSts().equals("O")) { |
| | | // 当前巷道无空库位时,递归调整至下一巷道,检索全部巷道无果后,跳出递归 |
| | | if (times < rowCount * 2) { |
| | | if (times < 5) { |
| | | times = times + 1; |
| | | return getLocNoRun(whsType, staDescId, sourceStaNo, findLocNoAttributeVo, moveCrnNo, locTypeDto, times); |
| | | } |
| | | // // 2.库位当前所属尺寸无空库位时,调整尺寸参数,向上兼容检索库位 |
| | | // if (locTypeDto.getLocType1() < 2) { |
| | | // int i = locTypeDto.getLocType1() + 1; |
| | | // locTypeDto.setLocType1((short)i); |
| | | // return getLocNo(1, staDescId, sourceStaNo, matnr,batch,grade, locTypeDto, 0); |
| | | // } |
| | | log.error("系统没有空库位!!! 尺寸规格: {}, 轮询次数:{}", JSON.toJSONString(locTypeDto), times); |
| | | throw new CoolException("没有空库位"); |
| | | } |
| | |
| | | startupDto.setCrnNo(crnNo); |
| | | startupDto.setSourceStaNo(sourceStaNo); |
| | | startupDto.setLocNo(locNo); |
| | | startupDto.setStaNo(staDesc.getCrnStn()); |
| | | return startupDto; |
| | | } |
| | | |
| | | @Transactional |
| | | public StartupDto getLocNoRunV3(Integer whsType, Integer staDescId, Integer sourceStaNo, FindLocNoAttributeVo findLocNoAttributeVo, Integer moveCrnNo, LocTypeDto locTypeDto, int times) { |
| | | StartupDto startupDto = new StartupDto(); |
| | | |
| | | // 初始化参数 |
| | | int crnNo = 0; //堆垛机号 |
| | | LocMast locMast = null; // 目标库位 |
| | | RowLastno whsType1 = rowLastnoService.selectOne(new EntityWrapper<RowLastno>().eq("whs_type", 2)); |
| | | crnNo = whsType1.getCrnQty(); |
| | | String matnr = findLocNoAttributeVo == null ? null : findLocNoAttributeVo.getMatnr(); |
| | | Integer chosenCrnNo = null; |
| | | Integer chosenCount = null; |
| | | LocMast chosenLocMast = null; |
| | | int sCrnNo = whsType1.getsCrnNo(); |
| | | int eCrnNo = whsType1.geteCrnNo(); |
| | | List<Integer> candidates = new ArrayList<>(); |
| | | for (int i = crnNo; i <= eCrnNo; i++) { |
| | | candidates.add(i); |
| | | } |
| | | for (int i = sCrnNo; i < crnNo; i++) { |
| | | candidates.add(i); |
| | | } |
| | | if(staDescId != 10){ |
| | | for (Integer candidate : candidates) { |
| | | if (!basCrnpService.checkSiteError(candidate, true)) { |
| | | continue; |
| | | } |
| | | StaDesc staDesc = staDescService.selectOne(new EntityWrapper<StaDesc>() |
| | | .eq("type_no", staDescId) |
| | | .eq("stn_no", sourceStaNo) |
| | | .eq("crn_no", candidate)); |
| | | if (Cools.isEmpty(staDesc)) { |
| | | continue; |
| | | } |
| | | List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>() |
| | | .eq("crn_no", candidate) |
| | | .eq("loc_sts", "O") |
| | | .eq("frozen", 0) |
| | | .eq("deleted", 0) |
| | | .eq("whs_type", 1) |
| | | .orderBy("lev1,bay1")); |
| | | if (Cools.isEmpty(locMasts) || locMasts.size() <= 10) { |
| | | continue; |
| | | } |
| | | Integer count = null; |
| | | if (!Cools.isEmpty(matnr)) { |
| | | count = locDetlMapper.countMatnrByCrnNo(candidate, matnr); |
| | | } |
| | | if (count == null) { |
| | | count = 0; |
| | | } |
| | | if (chosenCrnNo == null || count < chosenCount) { |
| | | chosenCrnNo = candidate; |
| | | chosenCount = count; |
| | | chosenLocMast = locMasts.get(0); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (chosenCrnNo != null) { |
| | | crnNo = chosenCrnNo; |
| | | locMast = chosenLocMast; |
| | | } else |
| | | // else if (basCrnpService.checkSiteError(crnNo, true)) |
| | | {//若轮询找不到数量最少的巷道,退回原来方法 |
| | | BasCrnp basCrnp = basCrnpService.selectById(crnNo); |
| | | List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>() |
| | | .eq("crn_no", basCrnp.getCrnNo()) |
| | | .eq("loc_sts", "O") |
| | | .eq("frozen", 0) |
| | | .eq("deleted", 0) |
| | | .eq("whs_type", 1) |
| | | .orderBy("lev1,bay1")); |
| | | if (!Cools.isEmpty(locMasts)) { |
| | | if (locMasts.size() > 10) { |
| | | locMast = locMasts.get(0); |
| | | } |
| | | } |
| | | } |
| | | int crnNo1 = crnNo + 1; |
| | | if (crnNo1> whsType1.geteCrnNo()) { |
| | | crnNo1 = whsType1.getsCrnNo(); |
| | | } |
| | | whsType1.setCrnQty(crnNo1); |
| | | rowLastnoService.updateById(whsType1); |
| | | |
| | | Wrapper<StaDesc> wrapper = null; |
| | | StaDesc staDesc = null; |
| | | // 获取目标站 |
| | | wrapper = new EntityWrapper<StaDesc>() |
| | | .eq("type_no", staDescId) |
| | | .eq("stn_no", sourceStaNo) |
| | | .eq("crn_no", crnNo); |
| | | staDesc = staDescService.selectOne(wrapper); |
| | | if (Cools.isEmpty(staDesc)) { |
| | | log.error("入库路径不存在type_no={},stn_no={},crn_no={}", staDescId, sourceStaNo, crnNo); |
| | | } |
| | | // 递归查询 |
| | | if (Cools.isEmpty(locMast) || !locMast.getLocSts().equals("O")) { |
| | | // 当前巷道无空库位时,递归调整至下一巷道,检索全部巷道无果后,跳出递归 |
| | | if (times < 5) { |
| | | times = times + 1; |
| | | return getLocNoRun(whsType, staDescId, sourceStaNo, findLocNoAttributeVo, moveCrnNo, locTypeDto, times); |
| | | } |
| | | log.error("系统没有空库位!!! 尺寸规格: {}, 轮询次数:{}", JSON.toJSONString(locTypeDto), times); |
| | | throw new CoolException("没有空库位"); |
| | | } |
| | | String locNo = locMast.getLocNo(); |
| | | |
| | | // 生成工作号 |
| | | int workNo = getWorkNo(0); |
| | | // 返回dto |
| | | startupDto.setWorkNo(workNo); |
| | | startupDto.setCrnNo(crnNo); |
| | | startupDto.setSourceStaNo(sourceStaNo); |
| | | startupDto.setLocNo(locNo); |
| | | startupDto.setStaNo(staDesc.getCrnStn()); |
| | | return startupDto; |
| | | } |
| | | |
| | | /** |
| | | * 当回源库位不在本巷道时,重新检索巷道根据1,2巷道之间分配,3,4巷道全局分配规则 |
| | | */ |
| | | @Transactional |
| | | public StartupDto getLocNoRunV2(Integer whsType, Integer staDescId, Integer sourceStaNo, WrkMast wrkMast, Integer moveCrnNo, LocTypeDto locTypeDto, int times) { |
| | | StartupDto startupDto = new StartupDto(); |
| | | List<WrkDetl> wrkDetl = wrkDetlService.selectByWrkNo(wrkMast.getWrkNo()); |
| | | WrkDetl detl = null; |
| | | if(!wrkDetl.isEmpty()){ |
| | | detl = wrkDetl.get(0); |
| | | } |
| | | String matnr = detl == null ? null : detl.getMatnr(); |
| | | Integer sourceCrnNo = null; |
| | | if (moveCrnNo != null && moveCrnNo != 0) { |
| | | sourceCrnNo = moveCrnNo; |
| | | } else if (wrkMast != null && !Cools.isEmpty(wrkMast.getSourceLocNo())) { |
| | | LocMast sourceLoc = locMastService.selectById(wrkMast.getSourceLocNo()); |
| | | if (!Cools.isEmpty(sourceLoc) && sourceLoc.getCrnNo() != null) { |
| | | sourceCrnNo = sourceLoc.getCrnNo(); |
| | | } |
| | | } else if (wrkMast != null && wrkMast.getCrnNo() != null) { |
| | | sourceCrnNo = wrkMast.getCrnNo(); |
| | | } |
| | | int[] candidates = sourceCrnNo != null && sourceCrnNo < 3 ? new int[]{1, 2} : new int[]{1, 2, 3, 4}; |
| | | Integer chosenCrnNo = null; |
| | | Integer chosenCount = null; |
| | | for (int candidate : candidates) { |
| | | if (sourceCrnNo != null && candidate == sourceCrnNo) { |
| | | continue; |
| | | } |
| | | //判断该巷道是否存在空位 |
| | | LocMast candidateLoc = locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("crn_no", candidate) |
| | | .eq("loc_sts", "O") |
| | | .eq("frozen", 0) |
| | | .eq("deleted", 0) |
| | | .eq("whs_type", 1) |
| | | .orderBy("lev1,bay1")); |
| | | if (Cools.isEmpty(candidateLoc)) { |
| | | continue; |
| | | } |
| | | Integer count = null; |
| | | if (!Cools.isEmpty(matnr)) { |
| | | count = locDetlMapper.countMatnrByCrnNo(candidate, matnr); //计算每个巷道的对应物料占多少库位 |
| | | } |
| | | if (count == null) { |
| | | count = 0; |
| | | } |
| | | if (chosenCrnNo == null || count < chosenCount) { |
| | | chosenCrnNo = candidate; |
| | | chosenCount = count; |
| | | } |
| | | } |
| | | LocMast locMast = null; |
| | | if (chosenCrnNo != null) { |
| | | locMast = locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("crn_no", chosenCrnNo) |
| | | .eq("loc_sts", "O") |
| | | .eq("frozen", 0) |
| | | .eq("deleted", 0) |
| | | .eq("whs_type", 1) |
| | | .orderBy("lev1,bay1")); |
| | | } |
| | | if (Cools.isEmpty(locMast)) { |
| | | List<LocMast> anyLocs = locMastService.selectList(new EntityWrapper<LocMast>() |
| | | .eq("loc_sts", "O") |
| | | .eq("frozen", 0) |
| | | .eq("deleted", 0) |
| | | .eq("whs_type", 1) |
| | | .orderBy("lev1,bay1")); |
| | | if (!Cools.isEmpty(anyLocs)) { |
| | | for (LocMast anyLoc : anyLocs) { |
| | | if (anyLoc == null || anyLoc.getCrnNo() == null) { |
| | | continue; |
| | | } |
| | | if (sourceCrnNo != null && sourceCrnNo.equals(anyLoc.getCrnNo())) { |
| | | continue; |
| | | } |
| | | if (!basCrnpService.checkSiteError(anyLoc.getCrnNo(), true)) { |
| | | continue; |
| | | } |
| | | chosenCrnNo = anyLoc.getCrnNo(); |
| | | locMast = anyLoc; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (Cools.isEmpty(locMast)) { |
| | | throw new CoolException("没有空库位"); |
| | | } |
| | | String locNo = locMast.getLocNo(); |
| | | int workNo = getWorkNo(0); |
| | | startupDto.setWorkNo(workNo); |
| | | startupDto.setCrnNo(chosenCrnNo); |
| | | startupDto.setLocNo(locNo); |
| | | return startupDto; |
| | | } |
| | | |