| | |
| | | } |
| | | |
| | | /** |
| | | * 调度车辆 |
| | | */ |
| | | public boolean searchDispatchShuttleIn(Integer wrkNo, String sourceLocNo, String locNo, String flag, boolean in) { |
| | | ArrayList<ShuttleThread> sameLev = new ArrayList<>();//相同楼层的穿梭车 |
| | | ArrayList<ShuttleThread> diffLev = new ArrayList<>();//不同楼层的穿梭车 |
| | | |
| | | for (ShuttleSlave shuttle : slaveProperties.getShuttle()) { |
| | | //获取四向穿梭车线程 |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId()); |
| | | ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); |
| | | if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) { |
| | | continue; |
| | | } |
| | | |
| | | if (checkChargeWrk(shuttle.getId())) { |
| | | continue;//存在充电任务,过滤小车 |
| | | } |
| | | |
| | | if (!shuttleThread.isIdle()) { |
| | | continue;//小车忙碌中 |
| | | } |
| | | |
| | | BasShuttle basShuttle = basShuttleService.selectOne(new EntityWrapper<BasShuttle>().eq("shuttle_no", shuttle.getId())); |
| | | if (basShuttle != null) { |
| | | if (basShuttle.getStatus() == 0) { |
| | | continue;//小车被禁用 |
| | | } |
| | | } |
| | | |
| | | int currentLev = Utils.getLev(shuttleProtocol.getCurrentLocNo());//小车当前层高 |
| | | String currentLocNo = shuttleProtocol.getCurrentLocNo();//小车当前库位号 |
| | | |
| | | if (currentLocNo.equals(locNo)) { |
| | | //车辆当前位置已经是目标库位,调度该车 |
| | | //给工作档绑定小车号 |
| | | WrkMast wrkMast1 = wrkMastService.selectByWorkNo(wrkNo); |
| | | if (wrkMast1 != null) { |
| | | wrkMast1.setShuttleNo(shuttleProtocol.getShuttleNo()); |
| | | wrkMastService.updateById(wrkMast1); |
| | | return true; |
| | | } |
| | | break; |
| | | } |
| | | // if (in) { |
| | | if (currentLev == Utils.getLev(sourceLocNo)) { |
| | | //工作档楼层相同的穿梭车 |
| | | sameLev.add(shuttleThread); |
| | | } else { |
| | | //工作档不同楼层的穿梭车 |
| | | diffLev.add(shuttleThread); |
| | | } |
| | | // } else { |
| | | // if (currentLev == Utils.getLev(locNo)) { |
| | | // //工作档楼层相同的穿梭车 |
| | | // sameLev.add(shuttleThread); |
| | | // } else { |
| | | // //工作档不同楼层的穿梭车 |
| | | // diffLev.add(shuttleThread); |
| | | // } |
| | | // } |
| | | |
| | | |
| | | } |
| | | |
| | | //优先调度同楼层小车,寻找离任务最近的穿梭车 |
| | | if (!sameLev.isEmpty()) { |
| | | Map<Integer, ShuttleThread> sameShuttles = new TreeMap<>();//自然排序小车Map |
| | | for (ShuttleThread shuttleThread : sameLev) { |
| | | ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); |
| | | Integer shuttleNo = shuttleProtocol.getShuttleNo(); |
| | | //当前穿梭车库位号 |
| | | String currentLocNo = shuttleProtocol.getCurrentLocNo(); |
| | | if (currentLocNo.equals(sourceLocNo)) { |
| | | sameShuttles.put(-1, shuttleThread); |
| | | continue; |
| | | } |
| | | |
| | | //当前穿梭车线程到目标地点距离 |
| | | List<NavigateNode> currentShuttlePath = navigateUtils.calc(currentLocNo, locNo, NavigationMapType.NORMAL.id, Utils.getShuttlePoints(shuttleNo, Utils.getLev(currentLocNo)), null);//搜索空闲穿梭车,使用正常通道地图 |
| | | if (currentShuttlePath == null) { |
| | | continue; |
| | | } |
| | | Integer currentAllDistance = navigateUtils.getOriginPathAllDistance(currentShuttlePath);//计算当前路径行走总距离 |
| | | sameShuttles.put(currentAllDistance, shuttleThread); |
| | | } |
| | | |
| | | //尝试调度同楼层小车 |
| | | for (Map.Entry<Integer, ShuttleThread> entry : sameShuttles.entrySet()) { |
| | | ShuttleThread shuttleThread = entry.getValue(); |
| | | ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); |
| | | Integer shuttleNo = shuttleProtocol.getShuttleNo(); |
| | | //尝试调度小车 |
| | | boolean result = shuttleMoveGenerate(wrkNo, sourceLocNo, locNo, shuttleNo, flag, false); |
| | | if (result) { |
| | | return true;//调度成功 |
| | | } |
| | | } |
| | | } |
| | | |
| | | //执行到此处,同楼层无调度成功小车。需要进行跨楼层调度小车 |
| | | //寻找离任务楼层最近的穿梭车(不考虑跨楼层小车移动距离) |
| | | if (!diffLev.isEmpty()) { |
| | | Map<Integer, ShuttleThread> diffShuttles = new TreeMap<>();//自然排序小车Map |
| | | //获取任务 |
| | | WrkMast wrkMast1 = wrkMastService.selectByWorkNo(wrkNo); |
| | | if (wrkMast1 != null) { |
| | | String targetLoc = wrkMast1.getIoType() < 100 ? wrkMast1.getLocNo() : wrkMast1.getSourceLocNo(); |
| | | int lev = Utils.getLev(targetLoc);//目标楼层 |
| | | |
| | | //检测目标楼层车数量是否小于允许的最大数量 |
| | | boolean checkDispatchMaxNum = checkDispatchMaxNum(lev); |
| | | if (!checkDispatchMaxNum) { |
| | | News.info("{}任务,{}层,已经达到当前楼层调度车辆最大值", wrkMast1.getWrkNo(), lev); |
| | | return false; |
| | | } |
| | | |
| | | for (ShuttleThread shuttleThread : diffLev) { |
| | | ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); |
| | | //当前穿梭车库位号 |
| | | String currentLocNo = shuttleProtocol.getCurrentLocNo(); |
| | | int currentLev = Utils.getLev(currentLocNo); |
| | | List<WrkMast> wrkMasts1 = wrkMastService.selectNoShuttleWrkByLev(currentLev);//判断当前穿梭车楼层是否有待分配车辆的任务,如果有则不分配这辆车 |
| | | int shuttleCount = this.getShuttleCountByLev(currentLev);//获取穿梭车楼层车辆数量 |
| | | if (!wrkMasts1.isEmpty() && shuttleCount <= 1) { |
| | | //存在其他任务且可用小车数量小于等于1,跳过这辆车 |
| | | continue; |
| | | } |
| | | |
| | | //ABS(目标楼层 - 当前楼层) 得到差距,取最小差值 |
| | | int currentValue = Math.abs(lev - currentLev); |
| | | diffShuttles.put(currentValue, shuttleThread); |
| | | } |
| | | |
| | | //尝试调度跨楼层小车 |
| | | for (Map.Entry<Integer, ShuttleThread> entry : diffShuttles.entrySet()) { |
| | | ShuttleThread shuttleThread = entry.getValue(); |
| | | ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); |
| | | Integer shuttleNo = shuttleProtocol.getShuttleNo(); |
| | | //尝试调度小车 |
| | | boolean result = shuttleMoveGenerate(wrkNo, sourceLocNo, locNo, shuttleNo, flag, false); |
| | | if (result) { |
| | | return true;//调度成功 |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | News.info("{}目标库位没有搜索到可用穿梭车", locNo); |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 小车迁移任务生成 |
| | | */ |
| | | @Transactional |