| | |
| | | package com.zy.common.utils; |
| | | |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.BasDevp; |
| | | import com.zy.asrs.entity.WrkCharge; |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.mapper.WrkChargeMapper; |
| | | import com.zy.asrs.mapper.WrkMastMapper; |
| | | import com.zy.asrs.service.BasDevpService; |
| | | import com.zy.asrs.service.WrkMastService; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.common.model.NavigateNode; |
| | |
| | | import com.zy.common.service.CommonService; |
| | | import com.zy.core.News; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.ShuttleChargeType; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.model.LiftSlave; |
| | | import com.zy.core.model.ShuttleSlave; |
| | | import com.zy.core.model.protocol.LiftProtocol; |
| | | import com.zy.core.model.protocol.LiftStaProtocol; |
| | | import com.zy.core.model.protocol.NyShuttleProtocol; |
| | | import com.zy.core.properties.SlaveProperties; |
| | | import com.zy.core.thread.LiftThread; |
| | | import com.zy.core.thread.NyShuttleThread; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | private WrkChargeMapper wrkChargeMapper; |
| | | @Autowired |
| | | private CommonService commonService; |
| | | @Autowired |
| | | private BasDevpService basDevpService; |
| | | |
| | | /** |
| | | * 调度车辆-调度指定穿梭车 |
| | |
| | | |
| | | if (currentLocNo.equals(locNo)) { |
| | | //车辆当前位置已经是目标库位,调度该车 |
| | | shuttleMoveGenerate(wrkNo, locNo, shuttleProtocol.getShuttleNo().intValue()); |
| | | //给工作档绑定小车号 |
| | | WrkMast wrkMast1 = wrkMastMapper.selectByWorkNo(wrkNo); |
| | | if (wrkMast1 != null) { |
| | | wrkMast1.setShuttleNo(shuttleProtocol.getShuttleNo().intValue()); |
| | | wrkMastMapper.updateById(wrkMast1); |
| | | return true; |
| | | } |
| | | break; |
| | | } |
| | | |
| | |
| | | if (currentAllDistance < recentAllDistance) { |
| | | //如果当前楼层的车路径更小,则更新最近穿梭车 |
| | | recentShuttle = shuttleThread; |
| | | recentAllDistance = currentAllDistance; |
| | | } |
| | | } |
| | | }else { |
| | | //同一楼层,没有空闲穿梭车,只能从其他楼层调度 |
| | | //寻找离任务最近的穿梭车 |
| | | for (NyShuttleThread shuttleThread : diffLev) { |
| | | //寻找离任务楼层最近的穿梭车(不考虑跨楼层小车移动距离) |
| | | |
| | | //当前穿梭车库位号 |
| | | String currentLocNo = shuttleThread.getShuttleProtocol().getCurrentLocNo(); |
| | | int currentLev = Utils.getLev(currentLocNo); |
| | | List<WrkMast> wrkMasts1 = wrkMastService.selectNoShuttleWrkByLev(currentLev);//判断当前穿梭车楼层是否有待分配车辆的任务,如果有则不分配这辆车 |
| | | if (wrkMasts1.size() > 0) { |
| | | //存在其他任务,跳过这辆车 |
| | | continue; |
| | | } |
| | | //获取任务 |
| | | WrkMast wrkMast1 = wrkMastMapper.selectByWorkNo(wrkNo); |
| | | |
| | | //当前穿梭车线程到当前车子所在楼层的提升机口距离 |
| | | List<NavigateNode> currentShuttlePath = NavigateUtils.calc(currentLocNo, Utils.levToOutInStaLocNo(currentLev), NavigationMapType.NORMAL.id, Utils.getShuttlePoints(shuttleThread.getSlave().getId(), currentLev));//搜索空闲穿梭车,使用正常通道地图 |
| | | if (currentShuttlePath == null) { |
| | | continue; |
| | | } |
| | | if (wrkMast1 != null) { |
| | | int lev = Utils.getLev(wrkMast1.getLocNo());//目标楼层 |
| | | int recentValue = 99999;//最小差值 |
| | | for (NyShuttleThread shuttleThread : diffLev) { |
| | | //当前穿梭车库位号 |
| | | String currentLocNo = shuttleThread.getShuttleProtocol().getCurrentLocNo(); |
| | | int currentLev = Utils.getLev(currentLocNo); |
| | | List<WrkMast> wrkMasts1 = wrkMastService.selectNoShuttleWrkByLev(currentLev);//判断当前穿梭车楼层是否有待分配车辆的任务,如果有则不分配这辆车 |
| | | if (wrkMasts1.size() > 0) { |
| | | //存在其他任务,跳过这辆车 |
| | | continue; |
| | | } |
| | | |
| | | Integer currentAllDistance = NavigateUtils.getOriginPathAllDistance(currentShuttlePath);//计算当前路径行走总距离 |
| | | if (currentAllDistance < recentAllDistance) { |
| | | //如果当前楼层的车路径更小,则更新最近穿梭车 |
| | | recentShuttle = shuttleThread; |
| | | //ABS(目标楼层 - 当前楼层) 得到差距,取最小差值 |
| | | int currentValue = Math.abs(lev - currentLev); |
| | | if (currentValue < recentValue) { |
| | | //如果当前楼层的车路径更小,则更新最近穿梭车 |
| | | recentShuttle = shuttleThread; |
| | | recentValue = currentValue; |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | * 小车迁移任务生成 |
| | | */ |
| | | @Transactional |
| | | private boolean shuttleMoveGenerate(Integer wrkNo, String locNo, Integer shuttleNo) { |
| | | public boolean shuttleMoveGenerate(Integer wrkNo, String locNo, Integer shuttleNo) { |
| | | Date now = new Date(); |
| | | //获取四向穿梭车线程 |
| | | NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo); |
| | |
| | | //判断是否有充电任务正在使用穿梭车 |
| | | WrkCharge wrkCharge = wrkChargeMapper.selectWorking(shuttleNo); |
| | | if (wrkCharge != null) {//小车存在充电任务,等待执行完成后再生成新的任务 |
| | | return false; |
| | | //判断目标点是否为充电桩,如果是去充电则放行 |
| | | boolean toCharge = false;//去充电目标 |
| | | for (ShuttleChargeType chargeType : ShuttleChargeType.values()) { |
| | | if (chargeType.locNo.equals(locNo)) { |
| | | toCharge = true;//去充电桩 |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (wrkCharge.getWrkSts() == 53) { |
| | | toCharge = true;//充电结束,允许生成移库任务 |
| | | } |
| | | |
| | | if (!toCharge) { |
| | | //不是去充电桩且存在充电任务,禁止生成新的移动任务 |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | Integer sourceStaNo = null;//小车换层源站点 |
| | | Integer staNo = null;//小车换层目标站点 |
| | | if (Utils.getLev(locNo) != shuttleProtocol.getPoint().getZ()) { |
| | | //目标库位和小车库位处于不同一楼层,需要通过提升机调度 |
| | | //获取穿梭车最近且空闲的提升机输送站点 |
| | | LiftStaProtocol liftSta = this.getRecentLiftSta(shuttleNo); |
| | | if (liftSta == null) { |
| | | return false;//没有可用且空闲的输送站点 |
| | | } |
| | | sourceStaNo = liftSta.getStaNo();//源站点 |
| | | //提升机号*100+目标楼层=目标站点 |
| | | staNo = liftSta.getLiftNo() * 100 + Utils.getLev(locNo);//目标站 |
| | | } |
| | | |
| | | // 获取工作号 |
| | |
| | | wrkMast.setShuttleNo(shuttleNo);//穿梭车号 |
| | | wrkMast.setSourceLocNo(shuttleProtocol.getCurrentLocNo()); // 源库位 => 小车当前库位号 |
| | | wrkMast.setLocNo(locNo); // 目标库位 |
| | | wrkMast.setSourceStaNo(sourceStaNo);//源站 |
| | | wrkMast.setStaNo(staNo);//目标站 |
| | | wrkMast.setPicking("N"); // 拣料 |
| | | wrkMast.setExitMk("N"); // 退出 |
| | | wrkMast.setLinkMis("N"); |
| | |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 获取穿梭车最近且空闲的提升机输送站点 |
| | | */ |
| | | public LiftStaProtocol getRecentLiftSta(Integer shuttleNo) { |
| | | //获取四向穿梭车线程 |
| | | NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo); |
| | | if (shuttleThread == null) { |
| | | return null; |
| | | } |
| | | NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); |
| | | if (shuttleProtocol == null) { |
| | | return null; |
| | | } |
| | | |
| | | //获取小车同一楼层的站点 |
| | | ArrayList<LiftStaProtocol> list = new ArrayList<>(); |
| | | int lev = Utils.getLev(shuttleProtocol.getCurrentLocNo());//小车楼层 |
| | | for (LiftSlave slave : slaveProperties.getLift()) { |
| | | LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, slave.getId()); |
| | | if (liftThread == null) { |
| | | continue; |
| | | } |
| | | LiftProtocol liftProtocol = liftThread.getLiftProtocol(); |
| | | if (liftProtocol == null) { |
| | | continue; |
| | | } |
| | | if (!liftProtocol.isIdle()) { |
| | | continue; |
| | | } |
| | | |
| | | LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(slave.getId(), lev); |
| | | if (liftStaProtocol == null) { |
| | | continue; |
| | | } |
| | | |
| | | list.add(liftStaProtocol); |
| | | } |
| | | |
| | | if (list.isEmpty()) { |
| | | return null; |
| | | } |
| | | |
| | | String currentLocNo = shuttleProtocol.getCurrentLocNo();//小车位置 |
| | | Integer recentAllDistance = 9999999; |
| | | LiftStaProtocol recentSta = null;//最近站点 |
| | | //搜索距离小车最近的站点 |
| | | for (LiftStaProtocol liftStaProtocol : list) { |
| | | Integer staNo = liftStaProtocol.getStaNo();//站点号 |
| | | String locNo = liftStaProtocol.getLocNo();//站点库位号 |
| | | |
| | | //当前穿梭车线程到目标地点距离 |
| | | List<NavigateNode> currentShuttlePath = NavigateUtils.calc(currentLocNo, locNo, NavigationMapType.NORMAL.id, Utils.getShuttlePoints(shuttleNo, Utils.getLev(currentLocNo)));//使用正常通道地图 |
| | | if (currentShuttlePath == null) { |
| | | continue; |
| | | } |
| | | Integer currentAllDistance = NavigateUtils.getOriginPathAllDistance(currentShuttlePath);//计算当前路径行走总距离 |
| | | if (currentAllDistance < recentAllDistance) { |
| | | //如果当前楼层的车路径更小,则更新最近站点 |
| | | recentSta = liftStaProtocol; |
| | | recentAllDistance = currentAllDistance; |
| | | } |
| | | } |
| | | |
| | | return recentSta; |
| | | } |
| | | |
| | | } |