| | |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.common.model.Shelves; |
| | | import com.zy.common.model.StartupDto; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | * 货架核心功能 |
| | | * Created by vincent on 2020/6/11 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class CommonService { |
| | | |
| | |
| | | * @param matNos 产品号集合 |
| | | * @return locNo 检索到的库位号 |
| | | */ |
| | | public StartupDto getLocNo(Integer whsType, Integer staDescId, Integer sourceStaNo, List<String> matNos) { |
| | | public StartupDto getLocNo(Integer whsType, Integer staDescId, Integer sourceStaNo, List<String> matNos, int times) { |
| | | if (sourceStaNo == 3) { |
| | | whsType = 1; |
| | | } else if (sourceStaNo == 7) { |
| | | whsType = 2; |
| | | } else if (sourceStaNo == 19) { |
| | | whsType = 3; |
| | | } else { |
| | | throw new CoolException("无效入库站"); |
| | | } |
| | |
| | | if (Cools.isEmpty(rowLastno)) { |
| | | throw new CoolException("数据异常,请联系管理员"); |
| | | } |
| | | if (whsType == 1 || whsType == 2){ |
| | | int curRow = rowLastno.getCurrentRow(); |
| | | int sRow = rowLastno.getsRow(); |
| | | int eRow = rowLastno.geteRow(); |
| | | int crn_qty = rowLastno.getCrnQty(); |
| | | int rowCount = eRow - sRow + 1; |
| | | // 目标堆垛机号 |
| | | int crnNo = 0; |
| | | // 目标库位 |
| | | LocMast locMast = null; |
| | | int curRow = rowLastno.getCurrentRow(); |
| | | int sRow = rowLastno.getsRow(); |
| | | int eRow = rowLastno.geteRow(); |
| | | int crn_qty = rowLastno.getCrnQty(); |
| | | int rowCount = eRow - sRow + 1; |
| | | // 目标堆垛机号 |
| | | int crnNo = 0; |
| | | // 目标库位 |
| | | LocMast locMast = null; |
| | | |
| | | // 同一天同规格货物靠近摆法规则 todo:luxiaotao |
| | | // if (!Cools.isEmpty(matNos)) { |
| | | // List<String> locNos = locDetlService.getSameDetlToday(matNos.get(0)); |
| | | // for (String locNo : locNos) { |
| | | // // 获取排 |
| | | // int row = Integer.parseInt(locNo.substring(0, 2)); |
| | | // // 判断是否为深库位 |
| | | // double remainder = Arith.remainder(row, rowCount / crn_qty); |
| | | // int targetRow; |
| | | // if (remainder == 1) { |
| | | // // 得到当前库位的外围库位 |
| | | // targetRow = row + 1; |
| | | // } else if (remainder == 0) { |
| | | // // 得到当前库位的内围库位 |
| | | // targetRow = row - 1; |
| | | // } else { |
| | | // continue; |
| | | // } |
| | | // String targetLocNo = zerofill(String.valueOf(targetRow), 2)+locNo.substring(2); |
| | | // // 检测目标库位是否为空库位 |
| | | // LocMast targetLocMast = locMastService.selectById(targetLocNo); |
| | | // if (targetLocMast != null && targetLocMast.getLocSts().equals("O")) { |
| | | // locMast = targetLocMast; |
| | | // crnNo = locMast.getCrnNo(); |
| | | // break; |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | // 如果没有相近产品,则按规则轮询货架 |
| | | if (null == locMast) { |
| | | // 获取目标站所在货架排号 todo:luxiaotao |
| | | if (curRow == sRow) { |
| | | curRow = eRow; |
| | | } else { |
| | | curRow = sRow; |
| | | } |
| | | crnNo = whsType; |
| | | // Shelves shelves = new Shelves(rowCount, crn_qty); |
| | | // curRow = shelves.start(curRow); |
| | | // if (curRow < 0) { |
| | | // throw new CoolException("检索库位失败,请联系管理员"); |
| | | // } |
| | | // for (List<Integer> node : shelves.nodes){ |
| | | // if (node.contains(curRow)) { |
| | | // crnNo = shelves.nodes.indexOf(node) + 1; |
| | | // break; |
| | | // } |
| | | // } |
| | | } |
| | | |
| | | basCrnpService.checkSiteStatus(crnNo); |
| | | // 获取目标站 |
| | | Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>() |
| | | .eq("type_no", staDescId) |
| | | .eq("stn_no", sourceStaNo) |
| | | .eq("crn_no", crnNo); |
| | | StaDesc staDesc = staDescService.selectOne(wrapper); |
| | | if (Cools.isEmpty(staDesc)) { |
| | | throw new CoolException("入库路径不存在"); |
| | | } |
| | | BasDevp staNo = basDevpService.selectById(staDesc.getCrnStn()); |
| | | int inQty = staNo.getInQty()==null?0:staNo.getInQty(); |
| | | if (staNo.getAutoing().equals("Y") && inQty<2) { |
| | | // 查找库位 |
| | | if (locMast == null) { |
| | | locMast = locMastService.queryFreeLocMast(curRow); |
| | | } |
| | | if (Cools.isEmpty(locMast)) { |
| | | throw new CoolException("没有空库位"); |
| | | } |
| | | String locNo = locMast.getLocNo(); |
| | | |
| | | // 更新库位排号 |
| | | rowLastno.setCurrentRow(curRow); |
| | | rowLastnoService.updateById(rowLastno); |
| | | |
| | | // 返回dto |
| | | startupDto.setCrnNo(crnNo); |
| | | startupDto.setSourceStaNo(sourceStaNo); |
| | | startupDto.setStaNo(staNo.getDevNo()); |
| | | startupDto.setLocNo(locNo); |
| | | // 按规则轮询货架 |
| | | if (whsType == 1 || whsType == 2) { |
| | | if (curRow == sRow) { |
| | | curRow = eRow; |
| | | } else { |
| | | throw new CoolException("目标站"+staDesc.getCrnStn()+"不可用"); |
| | | curRow = sRow; |
| | | } |
| | | crnNo = whsType; |
| | | basCrnpService.checkSiteStatus(crnNo, true); |
| | | } else { |
| | | throw new CoolException(rowLastno.getWhsType()+"号库位排号分配规则不可用"); |
| | | Shelves shelves = new Shelves(rowCount, crn_qty); |
| | | curRow = curRow - 4; |
| | | for (int i = 0; i < shelves.group; i ++) { |
| | | curRow = shelves.start(curRow); |
| | | if (curRow < 0) { |
| | | throw new CoolException("检索库位失败,请联系管理员"); |
| | | } |
| | | Integer crnNo1 = shelves.getCrnNo(curRow); |
| | | if (basCrnpService.checkSiteError(crnNo1 + 2, true)) { |
| | | // 偏移量补偿 |
| | | curRow = curRow + 4; |
| | | crnNo = crnNo1 + 2; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (crnNo == 0) { |
| | | throw new CoolException("没有可用的堆垛机"); |
| | | } |
| | | |
| | | // 获取目标站 |
| | | Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>() |
| | | .eq("type_no", staDescId) |
| | | .eq("stn_no", sourceStaNo) |
| | | .eq("crn_no", crnNo); |
| | | StaDesc staDesc = staDescService.selectOne(wrapper); |
| | | if (Cools.isEmpty(staDesc)) { |
| | | log.error("入库路径不存在, staDescId={}, sourceStaNo={}, crnNo={}", staDescId, sourceStaNo, crnNo); |
| | | throw new CoolException("入库路径不存在"); |
| | | } |
| | | // 检测目标站 |
| | | BasDevp staNo = basDevpService.selectById(staDesc.getCrnStn()); |
| | | if (!staNo.getAutoing().equals("Y")) { |
| | | throw new CoolException("目标站"+staDesc.getCrnStn()+"不可用"); |
| | | } |
| | | |
| | | // 更新库位排号 |
| | | rowLastno.setCurrentRow(curRow); |
| | | rowLastnoService.updateById(rowLastno); |
| | | |
| | | // 开始查找库位 ==============================>> |
| | | |
| | | // 查找库位 |
| | | locMast = locMastService.queryFreeLocMast(curRow); |
| | | |
| | | if (Cools.isEmpty(locMast)) { |
| | | // 当前巷道无空库位时,递归调整至下一巷道,检索全部巷道无果后,跳出递归 |
| | | if (times >= rowCount) { |
| | | log.error("系统没有空库位!!!"); |
| | | throw new CoolException("没有空库位"); |
| | | } |
| | | times = times + 1; |
| | | return getLocNo(1, staDescId, sourceStaNo, matNos, times); |
| | | } |
| | | String locNo = locMast.getLocNo(); |
| | | |
| | | // 返回dto |
| | | startupDto.setCrnNo(crnNo); |
| | | startupDto.setSourceStaNo(sourceStaNo); |
| | | startupDto.setStaNo(staNo.getDevNo()); |
| | | startupDto.setLocNo(locNo); |
| | | return startupDto; |
| | | } |
| | | |