| | |
| | | import com.core.common.Cools; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.domain.ShuttleGatherResult; |
| | | import com.zy.asrs.domain.param.ShuttleDemoParam; |
| | | import com.zy.asrs.domain.param.ShuttleGatherParam; |
| | | import com.zy.asrs.entity.BasShuttle; |
| | | import com.zy.asrs.entity.DeviceConfig; |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.service.BasShuttleService; |
| | | import com.zy.asrs.service.DeviceConfigService; |
| | | import com.zy.asrs.service.WrkMastService; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.common.model.NavigateNode; |
| | | import com.zy.common.model.enums.NavigationMapType; |
| | | import com.zy.common.service.CommonService; |
| | | import com.zy.common.utils.ForkLiftUtils; |
| | | import com.zy.common.utils.NavigateUtils; |
| | | import com.zy.core.News; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.enums.WrkIoType; |
| | | import com.zy.core.enums.WrkStsType; |
| | | import com.zy.core.model.ForkLiftSlave; |
| | | import com.zy.core.model.ShuttleSlave; |
| | | import com.zy.core.model.protocol.*; |
| | | import com.zy.core.properties.SlaveProperties; |
| | | import com.zy.core.thread.ForkLiftThread; |
| | | import com.zy.core.thread.ShuttleThread; |
| | | import com.zy.system.entity.Config; |
| | | import com.zy.system.service.ConfigService; |
| | |
| | | public class ShuttleDispatchUtils { |
| | | |
| | | @Autowired |
| | | private SlaveProperties slaveProperties; |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | | @Autowired |
| | | private CommonService commonService; |
| | |
| | | private ConfigService configService; |
| | | @Autowired |
| | | private BasShuttleService basShuttleService; |
| | | @Autowired |
| | | private DeviceConfigService deviceConfigService; |
| | | |
| | | /** |
| | | * 调度车辆-调度指定穿梭车 |
| | | */ |
| | | public boolean dispatchShuttle(Integer wrkNo, String locNo, Integer shuttleNo) { |
| | | public synchronized boolean dispatchShuttle(Integer wrkNo, String locNo, Integer shuttleNo) { |
| | | return shuttleMoveGenerate(wrkNo, locNo, shuttleNo); |
| | | } |
| | | |
| | | /** |
| | | * 调度车辆 |
| | | */ |
| | | public boolean dispatchShuttle(Integer wrkNo, String locNo) { |
| | | public synchronized boolean dispatchShuttle(Integer wrkNo, String locNo) { |
| | | ArrayList<ShuttleThread> sameLev = new ArrayList<>();//相同楼层的穿梭车 |
| | | ArrayList<ShuttleThread> diffLev = new ArrayList<>();//不同楼层的穿梭车 |
| | | |
| | | for (ShuttleSlave shuttle : slaveProperties.getShuttle()) { |
| | | List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>() |
| | | .eq("device_type", String.valueOf(SlaveType.Shuttle))); |
| | | for (DeviceConfig device : shuttleList) { |
| | | //获取四向穿梭车线程 |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId()); |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getDeviceNo()); |
| | | ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); |
| | | if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) { |
| | | continue; |
| | | } |
| | | |
| | | if (checkChargeWrk(shuttle.getId())) { |
| | | if (checkChargeWrk(device.getDeviceNo())) { |
| | | continue;//存在充电任务,过滤小车 |
| | | } |
| | | |
| | |
| | | continue;//小车忙碌中 |
| | | } |
| | | |
| | | BasShuttle basShuttle = basShuttleService.selectOne(new EntityWrapper<BasShuttle>().eq("shuttle_no", shuttle.getId())); |
| | | BasShuttle basShuttle = basShuttleService.selectOne(new EntityWrapper<BasShuttle>().eq("shuttle_no", device.getDeviceNo())); |
| | | if (basShuttle != null) { |
| | | if (basShuttle.getStatus() == 0) { |
| | | continue;//小车被禁用 |
| | |
| | | //当前穿梭车库位号 |
| | | String currentLocNo = shuttleProtocol.getCurrentLocNo(); |
| | | //当前穿梭车线程到目标地点距离 |
| | | List<NavigateNode> currentShuttlePath = navigateUtils.calc(currentLocNo, locNo, NavigationMapType.NORMAL.id, Utils.getShuttlePoints(shuttleNo, Utils.getLev(currentLocNo)), null);//搜索空闲穿梭车,使用正常通道地图 |
| | | List<NavigateNode> currentShuttlePath = navigateUtils.calc(currentLocNo, locNo, NavigationMapType.getMapTypes(NavigationMapType.NORMAL), Utils.getShuttlePoints(shuttleNo, Utils.getLev(currentLocNo)), null);//搜索空闲穿梭车,使用正常通道地图 |
| | | if (currentShuttlePath == null) { |
| | | continue; |
| | | } |
| | |
| | | //当前穿梭车库位号 |
| | | String currentLocNo = shuttleProtocol.getCurrentLocNo(); |
| | | int currentLev = Utils.getLev(currentLocNo); |
| | | List<WrkMast> wrkMasts1 = wrkMastService.selectNoShuttleWrkByLev(currentLev);//判断当前穿梭车楼层是否有待分配车辆的任务,如果有则不分配这辆车 |
| | | int shuttleCount = this.getShuttleCountByLev(currentLev);//获取穿梭车楼层车辆数量 |
| | | //判断当前楼层是否有任务,如果有则不分配这辆车 |
| | | List<WrkMast> wrkMasts1 = wrkMastService.selectWrkByLev(currentLev); |
| | | int shuttleCount = this.getShuttleEnableUseCountByLev(currentLev);//获取穿梭车楼层车辆数量 |
| | | if (!wrkMasts1.isEmpty() && shuttleCount <= 1) { |
| | | //存在其他任务且可用小车数量小于等于1,跳过这辆车 |
| | | continue; |
| | |
| | | * 小车迁移任务生成 |
| | | */ |
| | | @Transactional |
| | | public boolean shuttleMoveGenerate(Integer wrkNo, String locNo, Integer shuttleNo) { |
| | | public synchronized boolean shuttleMoveGenerate(Integer wrkNo, String locNo, Integer shuttleNo) { |
| | | Date now = new Date(); |
| | | //获取四向穿梭车线程 |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo); |
| | |
| | | } |
| | | } |
| | | |
| | | Integer sourceStaNo = null;//小车换层源站点 |
| | | Integer staNo = null;//小车换层目标站点 |
| | | if (Utils.getLev(locNo) != Utils.getLev(shuttleProtocol.getCurrentLocNo())) { |
| | | //目标库位和小车库位处于不同一楼层,需要通过提升机调度 |
| | | //获取穿梭车最近且空闲的提升机输送站点 |
| | | ForkLiftStaProtocol liftSta = this.getRecentLiftSta(shuttleNo, Utils.getLev(locNo)); |
| | | if (liftSta == null) { |
| | | News.info("{}号小车,{}目标库位,没有可用空闲输送站点", shuttleNo, locNo); |
| | | return false;//没有可用且空闲的输送站点 |
| | | } |
| | | sourceStaNo = liftSta.getStaNo();//源站点 |
| | | |
| | | ForkLiftStaProtocol targetLiftSta = ForkLiftUtils.getLiftStaByLev(liftSta.getLiftNo(), Utils.getLev(locNo)); |
| | | if (targetLiftSta == null) { |
| | | News.info("{}号小车,{}目标库位,没有目标站点", shuttleNo, locNo); |
| | | return false;//没有找到目标站点 |
| | | } |
| | | //目标站点 |
| | | staNo = targetLiftSta.getStaNo();//目标站 |
| | | } |
| | | |
| | | // 获取工作号 |
| | | int workNo = commonService.getWorkNo(WrkIoType.SHUTTLE_MOVE.id); |
| | | // 保存工作档 |
| | |
| | | wrkMast.setShuttleNo(shuttleNo);//穿梭车号 |
| | | wrkMast.setSourceLocNo(shuttleProtocol.getCurrentLocNo()); // 源库位 => 小车当前库位号 |
| | | wrkMast.setLocNo(locNo); // 目标库位 |
| | | wrkMast.setSourceStaNo(sourceStaNo);//源站 |
| | | wrkMast.setStaNo(staNo);//目标站 |
| | | wrkMast.setAppeTime(now); |
| | | wrkMast.setModiTime(now); |
| | | boolean res = wrkMastService.insert(wrkMast); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 小车演示 |
| | | */ |
| | | public void shuttleDemo(ShuttleDemoParam param) { |
| | | List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>() |
| | | .eq("device_type", String.valueOf(SlaveType.Shuttle)) |
| | | .in("device_no", param.getShuttleNos()) |
| | | ); |
| | | |
| | | for (DeviceConfig device : shuttleList) { |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getDeviceNo()); |
| | | if (shuttleThread == null) { |
| | | continue; |
| | | } |
| | | |
| | | shuttleThread.enableDemo(param.getStatus() == 1); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 检测目标楼层车数量是否小于允许的最大数量 |
| | | * true: 小于最大数量 false: 大于或等于最大数量 |
| | | */ |
| | |
| | | return false; |
| | | } |
| | | |
| | | List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>() |
| | | .eq("device_type", String.valueOf(SlaveType.Shuttle))); |
| | | int levCount = 0;//目标楼层车辆数量 |
| | | for (ShuttleSlave shuttle : slaveProperties.getShuttle()) { |
| | | for (DeviceConfig device : shuttleList) { |
| | | //获取四向穿梭车线程 |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId()); |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getDeviceNo()); |
| | | ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); |
| | | if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) { |
| | | continue; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取穿梭车最近且空闲的提升机输送站点 |
| | | */ |
| | | public ForkLiftStaProtocol getRecentLiftSta(Integer shuttleNo, Integer targetLev) { |
| | | //获取四向穿梭车线程 |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo); |
| | | if (shuttleThread == null) { |
| | | return null; |
| | | } |
| | | ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); |
| | | if (shuttleProtocol == null) { |
| | | return null; |
| | | } |
| | | |
| | | //获取小车同一楼层的站点 |
| | | ArrayList<ForkLiftStaProtocol> list = new ArrayList<>(); |
| | | int lev = Utils.getLev(shuttleProtocol.getCurrentLocNo());//小车楼层 |
| | | for (ForkLiftSlave slave : slaveProperties.getForkLift()) { |
| | | ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, slave.getId()); |
| | | if (forkLiftThread == null) { |
| | | continue; |
| | | } |
| | | ForkLiftProtocol forkLiftProtocol = forkLiftThread.getStatus(); |
| | | if (forkLiftProtocol == null) { |
| | | continue; |
| | | } |
| | | if (!forkLiftThread.isIdle()) { |
| | | continue; |
| | | } |
| | | |
| | | ForkLiftStaProtocol forkLiftStaProtocol = ForkLiftUtils.getLiftStaByLev(slave.getId(), lev); |
| | | if (forkLiftStaProtocol == null) { |
| | | continue; |
| | | } |
| | | |
| | | //判断当前层是否无托盘 |
| | | if (forkLiftStaProtocol.getHasTray()) { |
| | | continue; |
| | | } |
| | | |
| | | if (forkLiftStaProtocol.getHasCar()) { |
| | | continue; |
| | | } |
| | | |
| | | //判断目标楼层站点是否无托盘 |
| | | ForkLiftStaProtocol targetLiftStaProtocol = ForkLiftUtils.getLiftStaByLev(slave.getId(), targetLev); |
| | | if (targetLiftStaProtocol == null) { |
| | | continue; |
| | | } |
| | | |
| | | if (targetLiftStaProtocol.getHasTray()) { |
| | | continue;//有托盘跳过 |
| | | } |
| | | |
| | | if (targetLiftStaProtocol.getHasCar()) { |
| | | continue; |
| | | } |
| | | |
| | | list.add(forkLiftStaProtocol); |
| | | } |
| | | |
| | | if (list.isEmpty()) { |
| | | return null; |
| | | } |
| | | |
| | | String currentLocNo = shuttleProtocol.getCurrentLocNo();//小车位置 |
| | | Integer recentAllDistance = 9999999; |
| | | ForkLiftStaProtocol recentSta = null;//最近站点 |
| | | //搜索距离小车最近的站点 |
| | | for (ForkLiftStaProtocol forkLiftStaProtocol : list) { |
| | | Integer staNo = forkLiftStaProtocol.getStaNo();//站点号 |
| | | String locNo = forkLiftStaProtocol.getLocNo();//站点库位号 |
| | | |
| | | //当前穿梭车线程到目标地点距离 |
| | | 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);//计算当前路径行走总距离 |
| | | if (currentAllDistance < recentAllDistance) { |
| | | //如果当前楼层的车路径更小,则更新最近站点 |
| | | recentSta = forkLiftStaProtocol; |
| | | recentAllDistance = currentAllDistance; |
| | | } |
| | | } |
| | | |
| | | return recentSta; |
| | | } |
| | | |
| | | /** |
| | | * 检测是否穿梭车是否有充电任务 |
| | | */ |
| | | public boolean checkChargeWrk(int shuttleNo) { |
| | |
| | | /** |
| | | * 获取楼层可用小车数量 |
| | | */ |
| | | public int getShuttleCountByLev(int lev) { |
| | | public int getShuttleEnableUseCountByLev(int lev) { |
| | | List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>() |
| | | .eq("device_type", String.valueOf(SlaveType.Shuttle))); |
| | | int count = 0; |
| | | for (ShuttleSlave slave : slaveProperties.getShuttle()) { |
| | | for (DeviceConfig device : shuttleList) { |
| | | //获取四向穿梭车线程 |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, slave.getId()); |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getDeviceNo()); |
| | | if (shuttleThread == null) { |
| | | continue; |
| | | } |
| | |
| | | continue; |
| | | } |
| | | |
| | | if (checkChargeWrk(slave.getId())) { |
| | | if (checkChargeWrk(device.getDeviceNo())) { |
| | | continue;//存在充电任务,过滤小车 |
| | | } |
| | | |
| | |
| | | return count; |
| | | } |
| | | |
| | | /** |
| | | * 获取楼层小车数量 |
| | | */ |
| | | public int getShuttleCountByLev(int lev) { |
| | | List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>() |
| | | .eq("device_type", String.valueOf(SlaveType.Shuttle))); |
| | | int count = 0; |
| | | for (DeviceConfig device : shuttleList) { |
| | | //获取四向穿梭车线程 |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getDeviceNo()); |
| | | if (shuttleThread == null) { |
| | | continue; |
| | | } |
| | | |
| | | ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); |
| | | if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) { |
| | | continue; |
| | | } |
| | | |
| | | if (shuttleProtocol.getCurrentLocNo() == null) { |
| | | continue; |
| | | } |
| | | |
| | | if (Utils.getLev(shuttleProtocol.getCurrentLocNo()) == lev) { |
| | | //同一楼层可用小车 |
| | | count++; |
| | | continue; |
| | | } |
| | | } |
| | | return count; |
| | | } |
| | | |
| | | } |