#
zwl
2025-04-17 f53a21bd8bf2dec64175ea833d05bc8b49b9a8e6
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -120,6 +120,7 @@
                    ));
            for (WrkMast wrkMast : wrkMasts) {
                boolean step1 = this.shuttleInExecuteStep1(wrkMast);//小车搬入库中
                Thread.sleep(100);
                if (!step1) {
                    continue;
                }
@@ -134,7 +135,7 @@
     * 如需主方法执行continue,请返回false
     * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue
     */
    public boolean shuttleInExecuteStep1(WrkMast wrkMast) {
    public synchronized boolean shuttleInExecuteStep1(WrkMast wrkMast) {
        if (wrkMast.getWrkSts() == WrkStsType.INBOUND_LIFT_RUN_COMPLETE.sts) {
            //获取目标站
            ForkLiftStaProtocol liftSta = ForkLiftUtils.getLiftStaByStaNo(wrkMast.getStaNo());
@@ -233,6 +234,7 @@
                    ));
            for (WrkMast wrkMast : wrkMasts) {
                boolean step1 = this.shuttleOutExecuteStep1(wrkMast);//小车搬出库中
                Thread.sleep(100);
                if (!step1) {
                    continue;
                }
@@ -247,7 +249,7 @@
     * 如需主方法执行continue,请返回false
     * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue
     */
    public boolean shuttleOutExecuteStep1(WrkMast wrkMast) {
    public synchronized boolean shuttleOutExecuteStep1(WrkMast wrkMast) {
        //101.生成出库任务 => 102.小车搬运中
        if (wrkMast.getWrkSts() == WrkStsType.NEW_OUTBOUND.sts) {
            Integer liftNo = wrkMast.getLiftNo();
@@ -271,7 +273,6 @@
                wrkMast.setLiftNo(liftNo);
                wrkMast.setModiTime(new Date());
                wrkMastService.updateById(wrkMast);
                return false;
            }
            ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, liftNo);
@@ -593,59 +594,6 @@
            }
            for (WrkMast wrkMast : wrkMasts) {
                Integer liftNo = wrkMast.getLiftNo();
                if (liftNo == null) {
                    //未分配提升机
                    Integer staNo = wrkMast.getIoType() == WrkIoType.IN.id ? wrkMast.getSourceStaNo() : wrkMast.getStaNo();
                    liftNo = ForkLiftUtils.getConveyorBindLiftNo(staNo);
                    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;
                    }
                    if (!forkLiftThread.isIdle()) {
                        News.info("{}号提升机,忙碌中", liftNo);
                        continue;
                    }
                    //判断提升机是否有其他任务
                    WrkMast liftWrkMast = wrkMastService.selectLiftWrkMast(wrkMast.getLiftNo());
                    if (liftWrkMast != null) {
                        if (!liftWrkMast.getWrkNo().equals(wrkMast.getWrkNo())) {//提升机任务和当前任务不相同
                            News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}号提升机,提升机存在未完成任务,禁止派发", wrkMast.getWrkNo(), wrkMast.getLiftNo());
                            continue;//当前提升机存在未完成任务,等待下一次轮询
                        }
                    }
                    wrkMast.setLiftNo(liftNo);
                    wrkMast.setModiTime(new Date());
                    wrkMastService.updateById(wrkMast);
                    continue;
                }
                ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, liftNo);
                if (forkLiftThread == null) {
                    continue;
                }
                ForkLiftProtocol forkLiftProtocol = forkLiftThread.getStatus();
                if (forkLiftProtocol == null) {
                    continue;
                }
                if (!forkLiftThread.isIdle()) {
                    News.info("{}号提升机,忙碌中", liftNo);
                    continue;
                }
                boolean stepIn = this.liftIoExecuteStepIn(wrkMast);//提升机入库
                if (!stepIn) {
                    continue;
@@ -688,7 +636,18 @@
                return false;
            }
            ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, liftSta.getLiftNo());
            Integer liftNo = wrkMast.getLiftNo();
            if (liftNo == null) {
                //未分配提升机
                Integer staNo = wrkMast.getSourceStaNo();
                liftNo = ForkLiftUtils.getConveyorBindLiftNo(staNo);
                if(liftNo == null) {
                    News.taskInfo(wrkMast.getWrkNo(), "{}任务,未找到匹配的提升机", wrkMast.getWrkNo());
                    return false;
                }
            }
            ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, liftNo);
            if (forkLiftThread == null) {
                return false;
            }
@@ -754,11 +713,12 @@
            //提交到线程去工作
            LiftAssignCommand assignCommand = new LiftAssignCommand();
            assignCommand.setCommands(commands);
            assignCommand.setLiftNo(wrkMast.getLiftNo().shortValue());
            assignCommand.setLiftNo(liftNo.shortValue());
            assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());
            assignCommand.setTaskMode(ForkLiftTaskModeType.PICK_PUT.id.shortValue());
            wrkMast.setWrkSts(WrkStsType.INBOUND_LIFT_RUN.sts);//提升机搬运中  1.生成入库任务 ==> 3.提升机搬运中
            wrkMast.setLiftNo(liftNo);
            wrkMast.setSystemMsg("");//清空消息
            wrkMast.setModiTime(now);
            if (wrkMastService.updateById(wrkMast)) {
@@ -821,7 +781,18 @@
                return false;
            }
            ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, liftSta.getLiftNo());
            Integer liftNo = wrkMast.getLiftNo();
            if (liftNo == null) {
                //未分配提升机
                Integer staNo = wrkMast.getStaNo();
                liftNo = ForkLiftUtils.getConveyorBindLiftNo(staNo);
                if(liftNo == null) {
                    News.taskInfo(wrkMast.getWrkNo(), "{}任务,未找到匹配的提升机", wrkMast.getWrkNo());
                    return false;
                }
            }
            ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, liftNo);
            if (forkLiftThread == null) {
                return false;
            }
@@ -864,11 +835,12 @@
            //提交到线程去工作
            LiftAssignCommand assignCommand = new LiftAssignCommand();
            assignCommand.setCommands(commands);
            assignCommand.setLiftNo(wrkMast.getLiftNo().shortValue());
            assignCommand.setLiftNo(liftNo.shortValue());
            assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());
            assignCommand.setTaskMode(ForkLiftTaskModeType.PICK_PUT.id.shortValue());
            wrkMast.setWrkSts(WrkStsType.OUTBOUND_LIFT_RUN.sts);//提升机搬运中  103.生成入库任务 ==> 104.提升机搬运中
            wrkMast.setLiftNo(liftNo);
            wrkMast.setShuttleNo(null);//释放小车
            wrkMast.setSystemMsg("");//清空消息
            wrkMast.setModiTime(new Date());
@@ -911,12 +883,12 @@
                            wrkMast.setWrkSts(WrkStsType.COMPLETE_OUTBOUND.sts);
                            wrkMast.setLiftNo(null);//释放提升机
                            forkLiftThread.setSyncTaskNo(0);
                            redisUtil.set(RedisKeyType.FORK_LIFT_PUT_COMPLETE.key + forkLiftProtocol.getLiftNo(), wrkMast.getWmsWrkNo(), 60 * 3);
                        } else if (wrkMast.getWrkSts() == WrkStsType.MOVE_LIFT_RUN.sts) {
                            //306.提升机搬运中 ==> 307.提升机搬运完成
                            wrkMast.setWrkSts(WrkStsType.MOVE_LIFT_RUN_COMPLETE.sts);
                            forkLiftThread.setSyncTaskNo(0);
                        }
                        wrkMast.setModiTime(new Date());
                        if (wrkMastService.updateById(wrkMast)) {
                            forkLiftThread.reset();
@@ -1483,6 +1455,32 @@
                return false;//找不到站点
            }
            if (liftSta.getHasTray()) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,源站存在托盘", wrkMast.getWrkNo());
                return false;
            }
            if (liftSta.getHasCar()) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,源站存在小车", wrkMast.getWrkNo());
                return false;
            }
            //获取目标输送站
            ForkLiftStaProtocol liftStaTarget = ForkLiftUtils.getLiftStaByStaNo(wrkMast.getStaNo());
            if (liftStaTarget == null) {
                return false;//找不到站点
            }
            if (liftStaTarget.getHasTray()) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,目标站存在托盘", wrkMast.getWrkNo());
                return false;
            }
            if (liftStaTarget.getHasCar()) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,目标站存在小车", wrkMast.getWrkNo());
                return false;
            }
            if (wrkMast.getLiftNo() == null) {
                //判断提升机是否有其他任务(该任务需要换层必须提前独占提升机)
                WrkMast liftWrkMast = wrkMastService.selectLiftWrkMast(liftSta.getLiftNo());
@@ -1774,9 +1772,14 @@
                continue;
            }
            List<Integer> liftAllStaNo = ForkLiftUtils.getLiftAllStaNo(liftNo);
            if (liftAllStaNo.isEmpty()) {
                continue;
            }
            //获取入库任务
            List<WrkMast> inWrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>()
                    .eq("lift_no", liftNo)
                    .in("sta_no", liftAllStaNo)
                    .in("wrk_sts"
                            , WrkStsType.NEW_INBOUND.sts
                            , WrkStsType.INBOUND_DEVICE_RUN.sts