| | |
| | | import com.zy.common.service.CommonService; |
| | | import com.zy.common.utils.*; |
| | | import com.zy.core.News; |
| | | import com.zy.core.action.LiftAction; |
| | | import com.zy.core.action.ShuttleAction; |
| | | import com.zy.core.cache.MessageQueue; |
| | | import com.zy.core.cache.SlaveConnection; |
| | |
| | | import com.zy.core.model.LiftSlave; |
| | | import com.zy.core.model.ShuttleSlave; |
| | | import com.zy.core.model.Task; |
| | | import com.zy.core.model.command.LiftAssignCommand; |
| | | import com.zy.core.model.command.LiftCommand; |
| | | import com.zy.core.model.command.ShuttleAssignCommand; |
| | | import com.zy.core.model.command.ShuttleCommand; |
| | | import com.zy.core.model.protocol.*; |
| | | import com.zy.core.properties.SlaveProperties; |
| | | import com.zy.core.thread.*; |
| | | import com.zy.core.thread.impl.FyDevpThread; |
| | | import com.zy.system.entity.Config; |
| | | import com.zy.system.service.ConfigService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 立体仓库WCS系统主流程业务 |
| | |
| | | private NoLiftInServiceImpl noLiftInService; |
| | | @Autowired |
| | | private NoLiftOutServiceImpl noLiftOutService; |
| | | @Autowired |
| | | private LiftAction liftAction; |
| | | |
| | | |
| | | public static List<Integer> staNosIn = new ArrayList<Integer>() {{ |
| | |
| | | } |
| | | |
| | | if (wrkMast.getShuttleNo() == null) {//没有绑定小车,进行调度 |
| | | boolean result = shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), liftSta.getLocNo());//调度小车到货物所在输送站点进行取货 |
| | | boolean result = shuttleDispatchUtils.searchDispatchShuttle(wrkMast.getWrkNo(), null, liftSta.getLocNo(), null);//调度小车到货物所在输送站点进行取货 |
| | | News.taskInfo(wrkMast.getWrkNo(), "{}任务,调度小车{}系统等待中", wrkMast.getWrkNo(), result ? "成功" : "失败"); |
| | | return false; |
| | | } |
| | |
| | | return false; |
| | | } |
| | | } |
| | | boolean result = shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo());//调度小车到货物所在库位进行取货 |
| | | boolean result = shuttleDispatchUtils.searchDispatchShuttle(wrkMast.getWrkNo(), null, wrkMast.getSourceLocNo(), null);//调度小车到货物所在库位进行取货 |
| | | News.taskInfo(wrkMast.getWrkNo(), "{}任务,调度小车{}系统等待中。", wrkMast.getWrkNo(), result ? "成功" : "失败"); |
| | | return false; |
| | | } |
| | |
| | | } |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | public synchronized void liftInExecute() { |
| | | try { |
| | | List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>() |
| | | .in("wrk_sts", WrkStsType.NEW_INBOUND.sts, WrkStsType.INBOUND_DEVICE_RUN.sts, WrkStsType.INBOUND_LIFT_RUN_COMPLETE.sts) |
| | | .in("source_sta_no", 1012, 1022) |
| | | ); |
| | | for (WrkMast wrkMast : wrkMasts) { |
| | | boolean step0 = this.liftInExecuteStep0(wrkMast);//设备上走 |
| | | if (!step0) { |
| | | return; |
| | | } |
| | | |
| | | boolean step1 = this.liftInExecuteStep1(wrkMast);//提升机搬运 |
| | | if (!step1) { |
| | | return; |
| | | } |
| | | |
| | | boolean step2 = this.liftInExecuteStep2(wrkMast);//触发搬运任务 |
| | | if (!step2) { |
| | | return; |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | private boolean liftInExecuteStep0(WrkMast wrkMast) { |
| | | Date now = new Date(); |
| | | if (wrkMast.getWrkSts() == WrkStsType.NEW_INBOUND.sts) { |
| | | FyDevpThread devpThread = (FyDevpThread) SlaveConnection.get(SlaveType.Devp, 1); |
| | | if(devpThread == null) { |
| | | return false; |
| | | } |
| | | |
| | | Map<Integer, StaProtocol> station = devpThread.getStation(); |
| | | StaProtocol staProtocol = station.get(wrkMast.getSourceStaNo()); |
| | | if (staProtocol == null) { |
| | | return false; |
| | | } |
| | | |
| | | if (!staProtocol.isAutoing()) { |
| | | News.info("{}任务,{}站点,不在自动状态", wrkMast.getWrkNo(), staProtocol.getSiteId()); |
| | | return false; |
| | | } |
| | | |
| | | if (!staProtocol.isLoading()) { |
| | | News.info("{}任务,{}站点,无托盘", wrkMast.getWrkNo(), staProtocol.getSiteId()); |
| | | return false; |
| | | } |
| | | |
| | | if (!staProtocol.getBarcode().equals(wrkMast.getBarcode())) { |
| | | News.info("{}任务,{}站点,托盘码不匹配,站点托盘码:{},任务托盘码:{}", wrkMast.getWrkNo(), staProtocol.getSiteId(), staProtocol.getBarcode(), wrkMast.getBarcode()); |
| | | return false; |
| | | } |
| | | |
| | | short staNo = 1012; |
| | | if (wrkMast.getSourceStaNo() == 1022) { |
| | | staNo = 1023; |
| | | } |
| | | |
| | | staProtocol = staProtocol.clone(); |
| | | staProtocol.setStaNo(staNo); |
| | | staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue()); |
| | | boolean result = MessageQueue.offer(SlaveType.Devp, 1, new Task(2, staProtocol)); |
| | | |
| | | wrkMast.setWrkSts(WrkStsType.INBOUND_DEVICE_RUN.sts); |
| | | wrkMast.setSystemMsg("");//清空消息 |
| | | wrkMast.setModiTime(now); |
| | | if (wrkMastService.updateById(wrkMast)) { |
| | | return false; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | private boolean liftInExecuteStep1(WrkMast wrkMast) { |
| | | Date now = new Date(); |
| | | if (wrkMast.getWrkSts() == WrkStsType.INBOUND_DEVICE_RUN.sts) { |
| | | //获取提升机信息 |
| | | LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, 1); |
| | | if (liftThread == null) { |
| | | return false; |
| | | } |
| | | |
| | | LiftProtocol liftProtocol = liftThread.getStatus(); |
| | | if (liftProtocol == null) { |
| | | return false; |
| | | } |
| | | |
| | | if (!liftThread.isIdle()) { |
| | | return false; |
| | | } |
| | | |
| | | //判断提升机是否有其他任务(该任务需要换层必须提前独占提升机) |
| | | WrkMast liftWrkMast = wrkMastService.selectLiftWrkMast(liftProtocol.getLiftNo()); |
| | | if (liftWrkMast != null) { |
| | | News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}号提升机,提升机存在未完成任务,禁止派发", wrkMast.getWrkNo(), liftProtocol.getLiftNo()); |
| | | return false;//当前提升机存在未完成任务,等待下一次轮询 |
| | | } |
| | | |
| | | //判断提升机内是否有小车 |
| | | if (liftProtocol.getHasCar()) { |
| | | News.info("{}任务,{}号提升机,提升机内有小车,禁止派发", wrkMast.getWrkNo(), liftProtocol.getLiftNo()); |
| | | return false; |
| | | } |
| | | |
| | | //判断提升机内是否有托盘 |
| | | if (liftProtocol.getHasTray()) { |
| | | News.info("{}任务,{}号提升机,提升机内有托盘,禁止派发", wrkMast.getWrkNo(), liftProtocol.getLiftNo()); |
| | | return false; |
| | | } |
| | | |
| | | FyDevpThread devpThread = (FyDevpThread) SlaveConnection.get(SlaveType.Devp, 1); |
| | | if(devpThread == null) { |
| | | return false; |
| | | } |
| | | |
| | | Map<Integer, StaProtocol> station = devpThread.getStation(); |
| | | |
| | | Integer sourceStaNo = wrkMast.getSourceStaNo(); |
| | | if (wrkMast.getSourceStaNo() == 1022) { |
| | | sourceStaNo = 1023; |
| | | } |
| | | |
| | | StaProtocol staProtocol = station.get(sourceStaNo); |
| | | if (staProtocol == null) { |
| | | return false; |
| | | } |
| | | |
| | | if (!staProtocol.isAutoing()) { |
| | | News.info("{}任务,{}站点,不在自动状态", wrkMast.getWrkNo(), staProtocol.getSiteId()); |
| | | return false; |
| | | } |
| | | |
| | | if (!staProtocol.isLoading()) { |
| | | News.info("{}任务,{}站点,无托盘", wrkMast.getWrkNo(), staProtocol.getSiteId()); |
| | | return false; |
| | | } |
| | | |
| | | if (staProtocol.getWorkNo().intValue() != wrkMast.getWrkNo()) { |
| | | News.info("{}任务,{}站点,任务号不一致", wrkMast.getWrkNo(), staProtocol.getSiteId()); |
| | | return false; |
| | | } |
| | | |
| | | if (!staProtocol.getBarcode().equals(wrkMast.getBarcode())) { |
| | | News.info("{}任务,{}站点,托盘码不匹配,站点托盘码:{},任务托盘码:{}", wrkMast.getWrkNo(), staProtocol.getSiteId(), staProtocol.getBarcode(), wrkMast.getBarcode()); |
| | | return false; |
| | | } |
| | | |
| | | //获取提升机命令 |
| | | List<LiftCommand> liftCommands = liftThread.getPalletInCommand(wrkMast.getWrkNo(), wrkMast.getSourceStaNo(), 101); |
| | | LiftCommand liftCommand = liftCommands.get(0); |
| | | |
| | | int deviceWrk = commonService.getWorkNo(8);//生成提升机设备工作号 |
| | | liftCommand.setTaskNo(deviceWrk);//更换随机任务号 |
| | | |
| | | ArrayList<LiftCommand> commands = new ArrayList<>(); |
| | | commands.add(liftCommand); |
| | | |
| | | //提交到线程去工作 |
| | | LiftAssignCommand assignCommand = new LiftAssignCommand(); |
| | | assignCommand.setCommands(commands); |
| | | assignCommand.setLiftNo(liftProtocol.getLiftNo().shortValue()); |
| | | assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); |
| | | assignCommand.setTaskMode(LiftCommandModeType.PALLET_IN.id.shortValue()); |
| | | |
| | | wrkMast.setWrkSts(WrkStsType.INBOUND_LIFT_RUN.sts); |
| | | wrkMast.setLiftNo(liftProtocol.getLiftNo());//提前锁定提升机 |
| | | wrkMast.setSystemMsg("");//清空消息 |
| | | wrkMast.setModiTime(now); |
| | | if (wrkMastService.updateById(wrkMast)) { |
| | | //下发任务 |
| | | liftAction.assignWork(wrkMast.getLiftNo(), assignCommand); |
| | | return false; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | private boolean liftInExecuteStep2(WrkMast wrkMast) { |
| | | Date now = new Date(); |
| | | if (wrkMast.getWrkSts() == WrkStsType.INBOUND_LIFT_RUN_COMPLETE.sts) { |
| | | //获取提升机信息 |
| | | LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, 1); |
| | | if (liftThread == null) { |
| | | return false; |
| | | } |
| | | |
| | | LiftProtocol liftProtocol = liftThread.getStatus(); |
| | | if (liftProtocol == null) { |
| | | return false; |
| | | } |
| | | |
| | | if (!liftThread.isIdle()) { |
| | | return false; |
| | | } |
| | | |
| | | //判断提升机内是否有小车 |
| | | if (liftProtocol.getHasCar()) { |
| | | News.info("{}任务,{}号提升机,提升机内有小车,禁止派发", wrkMast.getWrkNo(), liftProtocol.getLiftNo()); |
| | | return false; |
| | | } |
| | | |
| | | //判断提升机内是否有托盘 |
| | | if (!liftProtocol.getHasTray()) { |
| | | News.info("{}任务,{}号提升机,提升机内无托盘,禁止派发", wrkMast.getWrkNo(), liftProtocol.getLiftNo()); |
| | | return false; |
| | | } |
| | | |
| | | boolean dispatchShuttle = shuttleDispatchUtils.searchDispatchShuttle(wrkMast.getWrkNo(), "0200301", wrkMast.getLocNo(), "TRANSPORT_LIFT"); |
| | | if(!dispatchShuttle) { |
| | | News.info("{}任务,调度小车失败", wrkMast.getWrkNo()); |
| | | return false; |
| | | } |
| | | |
| | | wrkMast.setWrkSts(WrkStsType.INBOUND_SHUTTLE_RUN.sts); |
| | | wrkMast.setLiftNo(null); |
| | | wrkMast.setSystemMsg("");//清空消息 |
| | | wrkMast.setModiTime(now); |
| | | if (wrkMastService.updateById(wrkMast)) { |
| | | return false; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | public synchronized void liftOutExecute() { |
| | | try { |
| | | List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>() |
| | | .in("wrk_sts", WrkStsType.NEW_OUTBOUND.sts, WrkStsType.OUTBOUND_SHUTTLE_RUN_COMPLETE.sts) |
| | | .in("sta_no", 1011, 1021) |
| | | ); |
| | | for (WrkMast wrkMast : wrkMasts) { |
| | | boolean step1 = this.liftOutExecuteStep1(wrkMast);//触发搬运任务 |
| | | if (!step1) { |
| | | return; |
| | | } |
| | | |
| | | boolean step2 = this.liftOutExecuteStep2(wrkMast);//提升机搬运 |
| | | if (!step2) { |
| | | return; |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | private boolean liftOutExecuteStep1(WrkMast wrkMast) { |
| | | Date now = new Date(); |
| | | if (wrkMast.getWrkSts() == WrkStsType.NEW_OUTBOUND.sts) { |
| | | FyDevpThread devpThread = (FyDevpThread) SlaveConnection.get(SlaveType.Devp, 1); |
| | | if(devpThread == null) { |
| | | return false; |
| | | } |
| | | |
| | | Map<Integer, StaProtocol> station = devpThread.getStation(); |
| | | StaProtocol staProtocol = station.get(wrkMast.getStaNo()); |
| | | if (staProtocol == null) { |
| | | return false; |
| | | } |
| | | |
| | | if (!staProtocol.isAutoing()) { |
| | | News.info("{}任务,{}站点,不在自动状态", wrkMast.getWrkNo(), staProtocol.getSiteId()); |
| | | return false; |
| | | } |
| | | |
| | | if (!staProtocol.isOutEnable()) { |
| | | News.info("{}任务,{}站点,没有可出信号", wrkMast.getWrkNo(), staProtocol.getSiteId()); |
| | | return false; |
| | | } |
| | | |
| | | |
| | | boolean dispatchShuttle = shuttleDispatchUtils.searchDispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), "0200301", "TRANSPORT_LIFT"); |
| | | if(!dispatchShuttle) { |
| | | News.info("{}任务,调度小车失败", wrkMast.getWrkNo()); |
| | | return false; |
| | | } |
| | | |
| | | wrkMast.setWrkSts(WrkStsType.OUTBOUND_SHUTTLE_RUN.sts); |
| | | wrkMast.setSystemMsg("");//清空消息 |
| | | wrkMast.setModiTime(now); |
| | | if (wrkMastService.updateById(wrkMast)) { |
| | | return false; |
| | | } |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | private boolean liftOutExecuteStep2(WrkMast wrkMast) { |
| | | Date now = new Date(); |
| | | if (wrkMast.getWrkSts() == WrkStsType.OUTBOUND_SHUTTLE_RUN_COMPLETE.sts) { |
| | | //获取提升机信息 |
| | | LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, 1); |
| | | if (liftThread == null) { |
| | | return false; |
| | | } |
| | | |
| | | LiftProtocol liftProtocol = liftThread.getStatus(); |
| | | if (liftProtocol == null) { |
| | | return false; |
| | | } |
| | | |
| | | if (!liftThread.isIdle()) { |
| | | return false; |
| | | } |
| | | |
| | | //判断提升机是否有其他任务(该任务需要换层必须提前独占提升机) |
| | | WrkMast liftWrkMast = wrkMastService.selectLiftWrkMast(liftProtocol.getLiftNo()); |
| | | if (liftWrkMast != null) { |
| | | News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}号提升机,提升机存在未完成任务,禁止派发", wrkMast.getWrkNo(), liftProtocol.getLiftNo()); |
| | | return false;//当前提升机存在未完成任务,等待下一次轮询 |
| | | } |
| | | |
| | | //判断提升机内是否有小车 |
| | | if (liftProtocol.getHasCar()) { |
| | | News.info("{}任务,{}号提升机,提升机内有小车,禁止派发", wrkMast.getWrkNo(), liftProtocol.getLiftNo()); |
| | | return false; |
| | | } |
| | | |
| | | //判断提升机内是否有托盘 |
| | | if (!liftProtocol.getHasTray()) { |
| | | News.info("{}任务,{}号提升机,提升机内无托盘,禁止派发", wrkMast.getWrkNo(), liftProtocol.getLiftNo()); |
| | | return false; |
| | | } |
| | | |
| | | FyDevpThread devpThread = (FyDevpThread) SlaveConnection.get(SlaveType.Devp, 1); |
| | | if(devpThread == null) { |
| | | return false; |
| | | } |
| | | |
| | | Map<Integer, StaProtocol> station = devpThread.getStation(); |
| | | StaProtocol staProtocol = station.get(wrkMast.getStaNo()); |
| | | if (staProtocol == null) { |
| | | return false; |
| | | } |
| | | |
| | | if (!staProtocol.isAutoing()) { |
| | | News.info("{}任务,{}站点,不在自动状态", wrkMast.getWrkNo(), staProtocol.getSiteId()); |
| | | return false; |
| | | } |
| | | |
| | | Integer sourceLev = liftThread.getLevToStaNo(Utils.getLev(wrkMast.getSourceLocNo())); |
| | | |
| | | //获取提升机命令 |
| | | List<LiftCommand> liftCommands = liftThread.getPalletOutCommand(wrkMast.getWrkNo(), sourceLev, wrkMast.getStaNo()); |
| | | LiftCommand liftCommand = liftCommands.get(0); |
| | | |
| | | int deviceWrk = commonService.getWorkNo(8);//生成提升机设备工作号 |
| | | liftCommand.setTaskNo(deviceWrk);//更换随机任务号 |
| | | |
| | | ArrayList<LiftCommand> commands = new ArrayList<>(); |
| | | commands.add(liftCommand); |
| | | |
| | | //提交到线程去工作 |
| | | LiftAssignCommand assignCommand = new LiftAssignCommand(); |
| | | assignCommand.setCommands(commands); |
| | | assignCommand.setLiftNo(liftProtocol.getLiftNo().shortValue()); |
| | | assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); |
| | | assignCommand.setTaskMode(LiftCommandModeType.PALLET_OUT.id.shortValue()); |
| | | |
| | | wrkMast.setWrkSts(WrkStsType.OUTBOUND_LIFT_RUN.sts); |
| | | wrkMast.setLiftNo(liftProtocol.getLiftNo());//提前锁定提升机 |
| | | wrkMast.setSystemMsg("");//清空消息 |
| | | wrkMast.setModiTime(now); |
| | | if (wrkMastService.updateById(wrkMast)) { |
| | | //下发任务 |
| | | liftAction.assignWork(wrkMast.getLiftNo(), assignCommand); |
| | | return false; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | |
| | | //小车移动至站点 501.生成移库任务 ==> 502.小车取货中 |
| | | if (wrkMast.getWrkSts() == WrkStsType.NEW_LOC_MOVE.sts) { |
| | | if (wrkMast.getShuttleNo() == null) {//没有绑定小车,进行调度 |
| | | boolean result = shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo());//调度小车到货物点进行取货 |
| | | boolean result = shuttleDispatchUtils.searchDispatchShuttle(wrkMast.getWrkNo(), null, wrkMast.getSourceLocNo(), null);//调度小车到货物点进行取货 |
| | | News.info("{}任务,调度小车{}系统等待中", wrkMast.getWrkNo(), result ? "成功" : "失败"); |
| | | |
| | | if (result) { |