#
Junjie
8 天以前 6daf900a09adcca981f620744bf89851654d88e0
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -12,7 +12,7 @@
import com.zy.common.service.CommonService;
import com.zy.common.utils.*;
import com.zy.core.News;
import com.zy.core.action.ForkLiftAction;
import com.zy.core.action.LiftAction;
import com.zy.core.action.ShuttleAction;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.dispatcher.ShuttleDispatchUtils;
@@ -67,7 +67,7 @@
    @Autowired
    private ShuttleAction shuttleAction;
    @Autowired
    private ForkLiftAction forkLiftAction;
    private LiftAction liftAction;
    @Autowired
    private NotifyUtils notifyUtils;
    @Autowired
@@ -649,65 +649,65 @@
            if (liftNo == null) {
                //未分配提升机
                Integer staNo = wrkMast.getSourceStaNo();
                liftNo = ForkLiftUtils.getConveyorBindLiftNo(staNo);
                liftNo = LiftUtils.getConveyorBindLiftNo(staNo);
                if(liftNo == null) {
                    News.taskInfo(wrkMast.getWrkNo(), "{}任务,未找到匹配的提升机", wrkMast.getWrkNo());
                    return false;
                }
                //申请提升机资源
                boolean applyForkLift = forkLiftAction.applyForkLift(liftNo, wrkMast.getWrkNo());
                if(!applyForkLift) {
                boolean applyLift = liftAction.applyLift(liftNo, wrkMast.getWrkNo());
                if(!applyLift) {
                    News.taskInfo(wrkMast.getWrkNo(), "{}任务,申请提升机资源失败,禁止入库", wrkMast.getWrkNo());
                    return false;
                }
                return false;
            }
            ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, liftNo);
            if (forkLiftThread == null) {
            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, liftNo);
            if (liftThread == null) {
                return false;
            }
            ForkLiftProtocol forkLiftProtocol = forkLiftThread.getStatus();
            if (forkLiftProtocol == null) {
            LiftProtocol liftProtocol = liftThread.getStatus();
            if (liftProtocol == null) {
                return false;
            }
            if (!forkLiftThread.isIdle()) {
            if (!liftThread.isIdle()) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}号提升机,忙碌中", wrkMast.getWrkNo(), liftSta.getLiftNo());
                return false;
            }
            //判断提升机是否处于入库模式
            if (!forkLiftProtocol.getIOModeType().equals(ForkLiftIoModeType.IN)) {
            if (!liftProtocol.getIOModeType().equals(LiftIoModeType.IN)) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,提升机不处于入库模式,禁止入库", wrkMast.getWrkNo());
                return false;
            }
            //请求上级系统,是否允许入库
            boolean inMission = ForkLiftUtils.queryInMission(wrkMast.getSourceStaNo(), liftSta.getLiftNo(), wrkMast.getWmsWrkNo());
            boolean inMission = LiftUtils.queryInMission(wrkMast.getSourceStaNo(), liftSta.getLiftNo(), wrkMast.getWmsWrkNo());
            if (!inMission) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,上级系统不允许入库", wrkMast.getWrkNo());
                return false;
            }
            //获取提升机命令
            ForkLiftCommand liftCommand = forkLiftThread.getPickAndPutCommand(wrkMast.getWrkNo(), wrkMast.getSourceStaNo(), liftSta.getLev());
            ArrayList<ForkLiftCommand> commands = new ArrayList<>();
            LiftCommand liftCommand = liftThread.getPickAndPutCommand(wrkMast.getWrkNo(), wrkMast.getSourceStaNo(), liftSta.getLev());
            ArrayList<LiftCommand> commands = new ArrayList<>();
            commands.add(liftCommand);
            //提交到线程去工作
            LiftAssignCommand assignCommand = new LiftAssignCommand();
            assignCommand.setCommands(commands);
            assignCommand.setLiftNo(liftNo.shortValue());
            assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());
            assignCommand.setTaskMode(ForkLiftTaskModeType.PICK_PUT.id.shortValue());
            assignCommand.setLiftNo(liftNo);
            assignCommand.setTaskNo(wrkMast.getWrkNo());
            assignCommand.setTaskMode(ForkLiftTaskModeType.PICK_PUT.id);
            wrkMast.setWrkSts(WrkStsType.INBOUND_LIFT_RUN.sts);//提升机搬运中  1.生成入库任务 ==> 3.提升机搬运中
            wrkMast.setSystemMsg("");//清空消息
            wrkMast.setModiTime(now);
            if (wrkMastService.updateById(wrkMast)) {
                //下发任务
                forkLiftAction.assignWork(wrkMast.getLiftNo(), assignCommand);
                liftAction.assignWork(wrkMast.getLiftNo(), assignCommand);
            }
            return false;
        }
@@ -724,7 +724,7 @@
        //103.小车搬运完成 ==> 104.提升机搬运中
        if (wrkMast.getWrkSts() == WrkStsType.OUTBOUND_SHUTTLE_RUN_COMPLETE.sts) {
            //获取源站
            ForkLiftStaProtocol liftSta = ForkLiftUtils.getLiftStaByStaNo(wrkMast.getSourceStaNo());
            LiftStaProtocol liftSta = LiftUtils.getLiftStaByStaNo(wrkMast.getSourceStaNo());
            if (liftSta == null) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,找不到站点,禁止派发", wrkMast.getWrkNo());
                return false;//找不到站点
@@ -784,51 +784,51 @@
                    return false;
                }
                //申请提升机资源
                boolean applyForkLift = forkLiftAction.applyForkLift(liftSta.getLiftNo(), wrkMast.getWrkNo());
                if(!applyForkLift) {
                boolean applyLift = liftAction.applyLift(liftSta.getLiftNo(), wrkMast.getWrkNo());
                if(!applyLift) {
                    News.taskInfo(wrkMast.getWrkNo(), "{}任务,申请提升机资源失败,禁止执行出库", wrkMast.getWrkNo());
                    return false;
                }
                return false;
            }
            ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, liftNo);
            if (forkLiftThread == null) {
            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, liftNo);
            if (liftThread == null) {
                return false;
            }
            ForkLiftProtocol forkLiftProtocol = forkLiftThread.getStatus();
            if (forkLiftProtocol == null) {
            LiftProtocol liftProtocol = liftThread.getStatus();
            if (liftProtocol == null) {
                return false;
            }
            if (!forkLiftThread.isIdle()) {
            if (!liftThread.isIdle()) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}号提升机,忙碌中", wrkMast.getWrkNo(), liftSta.getLiftNo());
                return false;
            }
            //判断提升机是否处于出库模式
            if (!forkLiftProtocol.getIOModeType().equals(ForkLiftIoModeType.OUT)) {
            if (!liftProtocol.getIOModeType().equals(LiftIoModeType.OUT)) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,提升机不处于出库模式,禁止出库", wrkMast.getWrkNo());
                return false;
            }
            //请求上级系统,是否允许出库
            boolean outMission = ForkLiftUtils.queryOutMission(wrkMast.getStaNo());
            boolean outMission = LiftUtils.queryOutMission(wrkMast.getStaNo());
            if (!outMission) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,上级系统不允许出库", wrkMast.getWrkNo());
                return false;
            }
            //获取提升机命令
            ForkLiftCommand liftCommand = forkLiftThread.getPickAndPutCommand(wrkMast.getWrkNo(), liftSta.getLev(), wrkMast.getStaNo());
            ArrayList<ForkLiftCommand> commands = new ArrayList<>();
            LiftCommand liftCommand = liftThread.getPickAndPutCommand(wrkMast.getWrkNo(), liftSta.getLev(), wrkMast.getStaNo());
            ArrayList<LiftCommand> commands = new ArrayList<>();
            commands.add(liftCommand);
            //提交到线程去工作
            LiftAssignCommand assignCommand = new LiftAssignCommand();
            assignCommand.setCommands(commands);
            assignCommand.setLiftNo(liftNo.shortValue());
            assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());
            assignCommand.setTaskMode(ForkLiftTaskModeType.PICK_PUT.id.shortValue());
            assignCommand.setLiftNo(liftNo);
            assignCommand.setTaskNo(wrkMast.getWrkNo());
            assignCommand.setTaskMode(ForkLiftTaskModeType.PICK_PUT.id);
            wrkMast.setWrkSts(WrkStsType.OUTBOUND_LIFT_RUN.sts);//提升机搬运中  103.生成入库任务 ==> 104.提升机搬运中
            wrkMast.setShuttleNo(null);//释放小车
@@ -836,7 +836,7 @@
            wrkMast.setModiTime(new Date());
            if (wrkMastService.updateById(wrkMast)) {
                //下发任务
                forkLiftAction.assignWork(wrkMast.getLiftNo(), assignCommand);
                liftAction.assignWork(wrkMast.getLiftNo(), assignCommand);
            }
            return false;
        }
@@ -1486,14 +1486,9 @@
            }
            //获取源输送站
            ForkLiftStaProtocol liftSta = ForkLiftUtils.getLiftStaByStaNo(wrkMast.getSourceStaNo());
            LiftStaProtocol liftSta = LiftUtils.getLiftStaByStaNo(wrkMast.getSourceStaNo());
            if (liftSta == null) {
                return false;//找不到站点
            }
            if (liftSta.getHasTray()) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,源站存在托盘", wrkMast.getWrkNo());
                return false;
            }
            if (liftSta.getHasCar()) {
@@ -1502,14 +1497,9 @@
            }
            //获取目标输送站
            ForkLiftStaProtocol liftStaTarget = ForkLiftUtils.getLiftStaByStaNo(wrkMast.getStaNo());
            LiftStaProtocol liftStaTarget = LiftUtils.getLiftStaByStaNo(wrkMast.getStaNo());
            if (liftStaTarget == null) {
                return false;//找不到站点
            }
            if (liftStaTarget.getHasTray()) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,目标站存在托盘", wrkMast.getWrkNo());
                return false;
            }
            if (liftStaTarget.getHasCar()) {
@@ -1524,7 +1514,7 @@
            assignCommand.setAuto(true);//自动模式
            //计算近点位置
            String endLocation = navigateUtils.calcEndLocation(shuttleProtocol.getCurrentLocNo(), liftSta.getLocNo(), NavigationMapType.getMapTypes(NavigationMapType.NORMAL, NavigationMapType.PATH_LOCK), null, null, 1);
            String endLocation = navigateUtils.calcEndLocation(shuttleProtocol.getCurrentLocNo(), liftSta.getLocNo(), NavigationMapType.getMapTypes(NavigationMapType.NORMAL), null, null, 1);
            if (endLocation == null) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,小车近点位置计算失败", wrkMast.getWrkNo());
                return false;
@@ -1591,14 +1581,9 @@
            }
            //获取源输送站
            ForkLiftStaProtocol liftSta = ForkLiftUtils.getLiftStaByStaNo(wrkMast.getSourceStaNo());
            LiftStaProtocol liftSta = LiftUtils.getLiftStaByStaNo(wrkMast.getSourceStaNo());
            if (liftSta == null) {
                return false;//找不到站点
            }
            if (liftSta.getHasTray()) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,源站存在托盘", wrkMast.getWrkNo());
                return false;
            }
            if (liftSta.getHasCar()) {
@@ -1607,14 +1592,9 @@
            }
            //获取目标输送站
            ForkLiftStaProtocol liftStaTarget = ForkLiftUtils.getLiftStaByStaNo(wrkMast.getStaNo());
            LiftStaProtocol liftStaTarget = LiftUtils.getLiftStaByStaNo(wrkMast.getStaNo());
            if (liftStaTarget == null) {
                return false;//找不到站点
            }
            if (liftStaTarget.getHasTray()) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,目标站存在托盘", wrkMast.getWrkNo());
                return false;
            }
            if (liftStaTarget.getHasCar()) {
@@ -1622,29 +1602,47 @@
                return false;
            }
            List<WrkMast> outWrkMastList = wrkMastService.selectList(new EntityWrapper<WrkMast>()
                    .eq("io_type", 101)
                    .in("wrk_sts"
                            , WrkStsType.OUTBOUND_SHUTTLE_RUN.sts
                            , WrkStsType.OUTBOUND_SHUTTLE_RUN_COMPLETE.sts
                            , WrkStsType.OUTBOUND_LIFT_RUN.sts
                            , WrkStsType.OUTBOUND_LIFT_RUN_COMPLETE.sts
                    )
            );
            for (WrkMast outWrkMast : outWrkMastList) {
                if(Utils.getLev(outWrkMast.getSourceLocNo()) == Utils.getLev(wrkMast.getLocNo())) {
                    News.taskInfo(wrkMast.getWrkNo(), "{}任务,存在正在执行的小车出库任务,禁止移动至站点", wrkMast.getWrkNo());
            if (wrkMast.getLiftNo() == null) {
                //申请提升机资源
                boolean applyLift = liftAction.applyLift(liftSta.getLiftNo(), wrkMast.getWrkNo());
                if(!applyLift) {
                    News.taskInfo(wrkMast.getWrkNo(), "{}任务,申请提升机资源失败,禁止移动", wrkMast.getWrkNo());
                    return false;
                }
                return false;
            }
            if (wrkMast.getLiftNo() == null) {
                //申请提升机资源(该任务需要换层必须提前独占提升机)
                boolean applyForkLift = forkLiftAction.applyForkLift(liftSta.getLiftNo(), wrkMast.getWrkNo());
                if(!applyForkLift) {
                    News.taskInfo(wrkMast.getWrkNo(), "{}任务,申请提升机资源失败,禁止移动至站点", wrkMast.getWrkNo());
                    return false;
                }
            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, wrkMast.getLiftNo());
            if (liftThread == null) {
                return false;
            }
            LiftProtocol liftProtocol = liftThread.getStatus();
            if (liftProtocol == null) {
                return false;
            }
            if (!liftThread.isIdle()) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}号提升机,提升机忙碌中,禁止派发", wrkMast.getWrkNo(), wrkMast.getLiftNo());
                return false;
            }
            int targetLev = Utils.getLev(wrkMast.getLocNo());
            if (liftProtocol.getLev() != targetLev) {
                //获取提升机命令
                LiftCommand liftCommand = liftThread.getMoveCommand(wrkMast.getWrkNo(), liftProtocol.getLev(), targetLev);
                ArrayList<LiftCommand> commands = new ArrayList<>();
                commands.add(liftCommand);
                //提交到线程去工作
                LiftAssignCommand assignCommand = new LiftAssignCommand();
                assignCommand.setCommands(commands);
                assignCommand.setLiftNo(wrkMast.getLiftNo());
                assignCommand.setTaskNo(wrkMast.getWrkNo());
                assignCommand.setTaskMode(ForkLiftTaskModeType.MOVE.id);
                //下发任务
                liftAction.assignWork(wrkMast.getLiftNo(), assignCommand);
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}号提升机在{}层,提升机不在小车层,调度移动中", wrkMast.getWrkNo(), liftProtocol.getLev(), wrkMast.getLiftNo());
                return false;
            }
@@ -1655,7 +1653,7 @@
            assignCommand.setAuto(true);//自动模式
            //获取小车到提升机行走命令
            List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(shuttleProtocol.getCurrentLocNo(), liftSta.getLocNo(), NavigationMapType.getNormalWithDevice(), assignCommand, shuttleThread);
            List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(shuttleProtocol.getCurrentLocNo(), liftThread.getCurrentLocNo(), NavigationMapType.getNormalWithDevice(), assignCommand, shuttleThread);
            if (commands == null) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}小车,路径计算失败", wrkMast.getWrkNo(), shuttleProtocol.getShuttleNo());
                return false;//路径解锁失败
@@ -1689,23 +1687,23 @@
        //提升机搬运中  305.小车迁入提升机完成 ==> 306.提升机搬运中
        if (wrkMast.getWrkSts() == WrkStsType.MOVE_IN_LIFT_COMPLETE.sts) {
            ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, wrkMast.getLiftNo());
            if (forkLiftThread == null) {
            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, wrkMast.getLiftNo());
            if (liftThread == null) {
                return false;
            }
            ForkLiftProtocol forkLiftProtocol = forkLiftThread.getStatus();
            if (forkLiftProtocol == null) {
            LiftProtocol liftProtocol = liftThread.getStatus();
            if (liftProtocol == null) {
                return false;
            }
            if (!forkLiftThread.isIdle()) {
            if (!liftThread.isIdle()) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}号提升机,提升机忙碌中,禁止派发", wrkMast.getWrkNo(), wrkMast.getLiftNo());
                return false;
            }
            //获取源站
            ForkLiftStaProtocol sourceLiftSta = ForkLiftUtils.getLiftStaByStaNo(wrkMast.getSourceStaNo());
            LiftStaProtocol sourceLiftSta = LiftUtils.getLiftStaByStaNo(wrkMast.getSourceStaNo());
            //获取目标站
            ForkLiftStaProtocol liftSta = ForkLiftUtils.getLiftStaByStaNo(wrkMast.getStaNo());
            LiftStaProtocol liftSta = LiftUtils.getLiftStaByStaNo(wrkMast.getStaNo());
            if (sourceLiftSta == null || liftSta == null) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,缺少站点信息,禁止派发", wrkMast.getWrkNo());
                return false;//缺少站点信息
@@ -1717,23 +1715,23 @@
            }
            //获取提升机命令
            ForkLiftCommand liftCommand = forkLiftThread.getShuttleSwitchCommand(wrkMast.getWrkNo(), sourceLiftSta.getLev(), liftSta.getLev());
            ArrayList<ForkLiftCommand> commands = new ArrayList<>();
            LiftCommand liftCommand = liftThread.getShuttleSwitchCommand(wrkMast.getWrkNo(), sourceLiftSta.getLev(), liftSta.getLev());
            ArrayList<LiftCommand> commands = new ArrayList<>();
            commands.add(liftCommand);
            //提交到线程去工作
            LiftAssignCommand assignCommand = new LiftAssignCommand();
            assignCommand.setCommands(commands);
            assignCommand.setLiftNo(wrkMast.getLiftNo().shortValue());
            assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());
            assignCommand.setTaskMode(ForkLiftTaskModeType.SHUTTLE_SWITCH.id.shortValue());
            assignCommand.setLiftNo(wrkMast.getLiftNo());
            assignCommand.setTaskNo(wrkMast.getWrkNo());
            assignCommand.setTaskMode(ForkLiftTaskModeType.SHUTTLE_SWITCH.id);
            wrkMast.setWrkSts(WrkStsType.MOVE_LIFT_RUN.sts);//提升机搬运中  305.小车迁入提升机完成 ==> 306.提升机搬运中
            wrkMast.setSystemMsg("");//清空消息
            wrkMast.setModiTime(now);
            if (wrkMastService.updateById(wrkMast)) {
                //下发任务
                forkLiftAction.assignWork(wrkMast.getLiftNo(), assignCommand);
                liftAction.assignWork(wrkMast.getLiftNo(), assignCommand);
            }
        }
        return true;
@@ -1928,91 +1926,6 @@
//                }
//            }
//        }
    }
    //出库任务预调度提升机
    public void outTaskPreviewDispatchForkLift() {
        List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>()
                .in("wrk_sts"
                        , WrkStsType.OUTBOUND_SHUTTLE_RUN_COMPLETE.sts
                ));
        for (WrkMast wrkMast : wrkMasts) {
            if(wrkMast.getShuttleNo() == null){
                continue;
            }
            //获取四向穿梭车线程
            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
            if (shuttleThread == null) {
                continue;
            }
            ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
            if (shuttleProtocol == null) {
                continue;
            }
            if(shuttleProtocol.getCurrentLocNo() == null){
                continue;
            }
            //通过输送线站号获取提升机号
            Integer liftNo = ForkLiftUtils.getConveyorBindLiftNo(wrkMast.getStaNo());
            if (liftNo == null) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,未找到匹配的提升机", wrkMast.getWrkNo());
                continue;
            }
            ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, liftNo);
            if (forkLiftThread == null) {
                continue;
            }
            ForkLiftProtocol forkLiftProtocol = forkLiftThread.getStatus();
            if (forkLiftProtocol == null) {
                continue;
            }
            //存在调度锁
            Object object = redisUtil.get(RedisKeyType.OUT_TASK_PREVIEW_DISPATCH_FORKLIFT.key + forkLiftProtocol.getLiftNo());
            if (object != null) {
                continue;
            }
            //申请提升机资源
            boolean applyForkLift = forkLiftAction.applyForkLift(liftNo, null);
            if(!applyForkLift) {
                continue;//提升机已被绑定,不再执行预调度任务
            }
            if (!forkLiftThread.isIdle()) {
                continue;
            }
            //提升机不在出库层
            if (forkLiftProtocol.getLev().equals(Utils.getLev(wrkMast.getSourceLocNo()))) {
                continue;
            }
            //移动
            int workNo = commonService.getWorkNo(WrkIoType.FORKLIFT_MOVE.id);//获取任务号
            //获取提升机命令
            ForkLiftCommand liftCommand = forkLiftThread.getMoveCommand(workNo, forkLiftProtocol.getLev(), Utils.getLev(wrkMast.getSourceLocNo()));
            ArrayList<ForkLiftCommand> commands = new ArrayList<>();
            commands.add(liftCommand);
            //提交到线程去工作
            LiftAssignCommand assignCommand = new LiftAssignCommand();
            assignCommand.setCommands(commands);
            assignCommand.setLiftNo(forkLiftProtocol.getLiftNo().shortValue());
            assignCommand.setTaskNo((short) workNo);
            assignCommand.setTaskMode(ForkLiftTaskModeType.MOVE.id.shortValue());
            forkLiftAction.assignWork(forkLiftProtocol.getLiftNo(), assignCommand);
            redisUtil.set(RedisKeyType.OUT_TASK_PREVIEW_DISPATCH_FORKLIFT.key + forkLiftProtocol.getLiftNo(), "lock", 30);//30秒不再调度
        }
    }
}