|  |  |  | 
|---|
|  |  |  | import com.zy.core.action.ForkLiftAction; | 
|---|
|  |  |  | import com.zy.core.action.ShuttleAction; | 
|---|
|  |  |  | import com.zy.core.cache.SlaveConnection; | 
|---|
|  |  |  | import com.zy.core.dispatcher.ForkLiftDispatchUtils; | 
|---|
|  |  |  | import com.zy.core.dispatcher.ShuttleDispatchUtils; | 
|---|
|  |  |  | import com.zy.core.enums.*; | 
|---|
|  |  |  | import com.zy.core.model.command.*; | 
|---|
|  |  |  | import com.zy.core.model.protocol.ForkLiftProtocol; | 
|---|
|  |  |  | import com.zy.core.model.protocol.ForkLiftStaProtocol; | 
|---|
|  |  |  | import com.zy.core.model.protocol.LiftStaProtocol; | 
|---|
|  |  |  | import com.zy.core.model.protocol.ShuttleProtocol; | 
|---|
|  |  |  | import com.zy.core.thread.ForkLiftThread; | 
|---|
|  |  |  | import com.zy.core.thread.ShuttleThread; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 立体仓库WCS系统主流程业务 | 
|---|
|  |  |  | * Created by vincent on 2020/8/6 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Service("forkMainService") | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ConfigService configService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private NavigateMapUtils navigateMapUtils; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private NavigateMapData navigateMapData; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private NavigateUtils navigateUtils; | 
|---|
|  |  |  | 
|---|
|  |  |  | private BasShuttleChargeService basShuttleChargeService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private DeviceConfigService deviceConfigService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ForkLiftDispatchUtils forkLiftDispatchUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 初始化实时地图 | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //检测障碍物车 | 
|---|
|  |  |  | boolean checkObstacle = shuttleOperaUtils.checkObstacle(wrkMast.getLocNo(), new ArrayList<Integer>() {{ | 
|---|
|  |  |  | int checkObstacle = shuttleOperaUtils.checkObstacle(wrkMast.getLocNo(), new ArrayList<Integer>() {{ | 
|---|
|  |  |  | add(shuttleProtocol.getShuttleNo()); | 
|---|
|  |  |  | }}, new ArrayList<>()); | 
|---|
|  |  |  | if (checkObstacle) { | 
|---|
|  |  |  | if (checkObstacle > 0) { | 
|---|
|  |  |  | News.info("{}任务,避障范围有小车,等待障碍小车调离中", wrkMast.getWrkNo()); | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | //判断小车是否到达货物库位 | 
|---|
|  |  |  | if (!shuttleProtocol.getCurrentLocNo().equals(wrkMast.getSourceLocNo())) { | 
|---|
|  |  |  | //检测障碍物车 | 
|---|
|  |  |  | boolean checkObstacle = shuttleOperaUtils.checkObstacle(wrkMast.getSourceLocNo(), new ArrayList<Integer>() {{ | 
|---|
|  |  |  | int checkObstacle = shuttleOperaUtils.checkObstacle(wrkMast.getSourceLocNo(), new ArrayList<Integer>() {{ | 
|---|
|  |  |  | add(shuttleProtocol.getShuttleNo()); | 
|---|
|  |  |  | }}, new ArrayList<>()); | 
|---|
|  |  |  | if (checkObstacle) { | 
|---|
|  |  |  | if (checkObstacle > 0) { | 
|---|
|  |  |  | News.info("{}任务,避障范围有小车,等待障碍小车调离中", wrkMast.getWrkNo()); | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //检测障碍物车 | 
|---|
|  |  |  | boolean checkObstacle = shuttleOperaUtils.checkObstacle(wrkMast.getLocNo(), new ArrayList<Integer>() {{ | 
|---|
|  |  |  | int checkObstacle = shuttleOperaUtils.checkObstacle(wrkMast.getLocNo(), new ArrayList<Integer>() {{ | 
|---|
|  |  |  | add(shuttleProtocol.getShuttleNo()); | 
|---|
|  |  |  | }}, new ArrayList<>()); | 
|---|
|  |  |  | if (checkObstacle) { | 
|---|
|  |  |  | if (checkObstacle > 0) { | 
|---|
|  |  |  | News.info("{}任务,避障范围有小车,等待障碍小车调离中", wrkMast.getWrkNo()); | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | News.error("提升机已确认且任务完成状态,复位失败,但未找到工作档。提升机号={},工作号={}", forkLiftProtocol.getLiftNo(), forkLiftProtocol.getWrkNo()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | boolean checkPreviewDispatchForkLift = commonService.checkWorkNoContainMk(forkLiftProtocol.getWrkNo(), WrkIoType.FORKLIFT_MOVE.id); | 
|---|
|  |  |  | boolean checkPreviewDispatchForkLift = commonService.checkWorkNoContainMk(forkLiftProtocol.getWrkNo(), WrkIoType.PREVIEW_LIFT_MOVE.id); | 
|---|
|  |  |  | if (checkPreviewDispatchForkLift) { | 
|---|
|  |  |  | //属于提升机预调度移动任务 | 
|---|
|  |  |  | //无工作档支撑,直接确认完成 | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //检测障碍物车 | 
|---|
|  |  |  | boolean checkObstacle = shuttleOperaUtils.checkObstacle(basShuttleCharge.getWaitLocNo(), new ArrayList<Integer>() {{ | 
|---|
|  |  |  | int checkObstacle = shuttleOperaUtils.checkObstacle(basShuttleCharge.getWaitLocNo(), new ArrayList<Integer>() {{ | 
|---|
|  |  |  | add(shuttleProtocol.getShuttleNo()); | 
|---|
|  |  |  | }}, new ArrayList<>()); | 
|---|
|  |  |  | if (checkObstacle) { | 
|---|
|  |  |  | if (checkObstacle > 0) { | 
|---|
|  |  |  | News.info("{}任务,避障范围有小车,等待障碍小车调离中", wrkMast.getWrkNo()); | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取源输送站 | 
|---|
|  |  |  | ForkLiftStaProtocol liftSta = ForkLiftUtils.getLiftStaByStaNo(wrkMast.getSourceStaNo()); | 
|---|
|  |  |  | if (liftSta == null) { | 
|---|
|  |  |  | return false;//找不到站点 | 
|---|
|  |  |  | //搜索最近且无故障提升机 | 
|---|
|  |  |  | ForkLiftStaProtocol recentLiftStation = forkLiftDispatchUtils.getRecentLiftStation(shuttleProtocol.getShuttleNo(), Utils.getLev(wrkMast.getLocNo())); | 
|---|
|  |  |  | if(recentLiftStation == null) { | 
|---|
|  |  |  | News.info("{}号小车,{}目标库位,没有可用空闲输送站点", shuttleProtocol.getShuttleNo(), wrkMast.getLocNo()); | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (liftSta.getHasTray()) { | 
|---|
|  |  |  | if (recentLiftStation.getHasTray()) { | 
|---|
|  |  |  | News.taskInfo(wrkMast.getWrkNo(), "{}任务,源站存在托盘", wrkMast.getWrkNo()); | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (liftSta.getHasCar()) { | 
|---|
|  |  |  | if (recentLiftStation.getHasCar()) { | 
|---|
|  |  |  | News.taskInfo(wrkMast.getWrkNo(), "{}任务,源站存在小车", wrkMast.getWrkNo()); | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取目标输送站 | 
|---|
|  |  |  | ForkLiftStaProtocol liftStaTarget = ForkLiftUtils.getLiftStaByStaNo(wrkMast.getStaNo()); | 
|---|
|  |  |  | ForkLiftStaProtocol liftStaTarget = ForkLiftUtils.getLiftStaByLev(recentLiftStation.getLiftNo(), Utils.getLev(wrkMast.getLocNo())); | 
|---|
|  |  |  | if (liftStaTarget == null) { | 
|---|
|  |  |  | return false;//找不到站点 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | assignCommand.setAuto(true);//自动模式 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //计算近点位置 | 
|---|
|  |  |  | String endLocation = navigateUtils.calcEndLocation(shuttleProtocol.getCurrentLocNo(), liftSta.getLocNo(), NavigationMapType.getMapTypes(NavigationMapType.NORMAL), null, null, 1); | 
|---|
|  |  |  | String endLocation = navigateUtils.calcEndLocation(shuttleProtocol.getCurrentLocNo(), recentLiftStation.getLocNo(), NavigationMapType.getMapTypes(NavigationMapType.NORMAL), null, null, 1); | 
|---|
|  |  |  | if (endLocation == null) { | 
|---|
|  |  |  | News.taskInfo(wrkMast.getWrkNo(), "{}任务,小车近点位置计算失败", wrkMast.getWrkNo()); | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | 
|---|
|  |  |  | assignCommand.setCommands(commands); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | wrkMast.setWrkSts(WrkStsType.MOVE_NEARBY.sts);//小车移动到提升机中  301.生成小车移库任务 ==> 302.小车移动至近点中 | 
|---|
|  |  |  | wrkMast.setSourceStaNo(recentLiftStation.getStaNo()); | 
|---|
|  |  |  | wrkMast.setStaNo(liftStaTarget.getStaNo()); | 
|---|
|  |  |  | wrkMast.setModiTime(now); | 
|---|
|  |  |  | wrkMast.setSystemMsg("");//清空消息 | 
|---|
|  |  |  | if (wrkMastService.updateById(wrkMast)) { | 
|---|
|  |  |  | 
|---|
|  |  |  | assignCommand.setAuto(true);//自动模式 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取小车到提升机行走命令 | 
|---|
|  |  |  | List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(shuttleProtocol.getCurrentLocNo(), liftSta.getLocNo(), NavigationMapType.getNormalWithDevice(), assignCommand, shuttleThread); | 
|---|
|  |  |  | List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(shuttleProtocol.getCurrentLocNo(), liftSta.getLocNo(), NavigationMapType.getMapTypes(NavigationMapType.NORMAL), assignCommand, shuttleThread); | 
|---|
|  |  |  | if (commands == null) { | 
|---|
|  |  |  | News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}小车,路径计算失败", wrkMast.getWrkNo(), shuttleProtocol.getShuttleNo()); | 
|---|
|  |  |  | return false;//路径解锁失败 | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //移动 | 
|---|
|  |  |  | int workNo = commonService.getWorkNo(WrkIoType.FORKLIFT_MOVE.id);//获取任务号 | 
|---|
|  |  |  | int workNo = commonService.getWorkNo(WrkIoType.PREVIEW_LIFT_MOVE.id);//获取任务号 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取提升机命令 | 
|---|
|  |  |  | ForkLiftCommand liftCommand = forkLiftThread.getMoveCommand(workNo, forkLiftProtocol.getLev(), Utils.getLev(wrkMast.getSourceLocNo())); | 
|---|