#
Junjie
21 小时以前 2c175f2b2c00dfe18c349b92a6f6b1ec55bc3db1
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -302,12 +302,12 @@
            }
            if (liftSta.getHasCar()) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}站点存在小车,禁止派发", wrkMast.getWrkNo(), liftSta.getStaNo());
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}站点存在小车,禁止派发", wrkMast.getWrkNo(), liftSta.getSiteId());
                return false;
            }
            if (liftSta.getHasTray()) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}站点有托盘,禁止派发", wrkMast.getWrkNo(), liftSta.getStaNo());
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}站点有托盘,禁止派发", wrkMast.getWrkNo(), liftSta.getSiteId());
                return false;
            }
@@ -427,7 +427,7 @@
            assignCommand.setCommands(commands);
            wrkMast.setWrkSts(WrkStsType.OUTBOUND_SHUTTLE_RUN.sts);//小车搬运中  101.生成出库任务 ==> 102.小车搬运中
            wrkMast.setSourceStaNo(liftSta.getStaNo());
            wrkMast.setSourceStaNo(liftSta.getSiteId());
            wrkMast.setModiTime(new Date());
            wrkMast.setSystemMsg("");//清空消息
            if (wrkMastService.updateById(wrkMast)) {
@@ -504,6 +504,12 @@
            //判断小车是否到达货物库位
            if (!shuttleProtocol.getCurrentLocNo().equals(wrkMast.getSourceLocNo())) {
                //任务被避障取消
                Object cancelLock = redisUtil.get(RedisKeyType.TRAFFIC_CONTROL_SHUTTLE_OBSTACLE_CANCEL_TASK_LOCK.key + wrkMast.getShuttleNo());
                if(cancelLock != null) {
                    return false;
                }
                //小车未到达取货位置
                shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), wrkMast.getShuttleNo());//调度小车到货物所在库位进行取货
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,小车未到达取货位置", wrkMast.getWrkNo(), wrkMast.getSourceLocNo());
@@ -611,18 +617,13 @@
        //1.生成入库任务 ==> 3.提升机搬运中
        if (wrkMast.getWrkSts() == WrkStsType.NEW_INBOUND.sts) {
            //获取目标输送站
            ForkLiftStaProtocol liftSta = ForkLiftUtils.getLiftStaByStaNo(wrkMast.getStaNo());
            LiftStaProtocol liftSta = LiftUtils.getLiftStaByStaNo(wrkMast.getStaNo());
            if (liftSta == null) {
                return false;//找不到站点
            }
            if (liftSta.getHasTray()) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,目标站存在托盘", wrkMast.getWrkNo());
                return false;
            }
            if (liftSta.getHasCar()) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,目标站存在小车", wrkMast.getWrkNo());
                return false;
            }
@@ -695,7 +696,7 @@
            }
            //获取提升机命令
            LiftCommand liftCommand = liftThread.getPickAndPutCommand(wrkMast.getWrkNo(), wrkMast.getSourceStaNo(), liftSta.getLev());
            LiftCommand liftCommand = liftThread.getPickAndPutCommand(wrkMast.getWrkNo(), wrkMast.getSourceStaNo(), liftSta.getSiteId());
            ArrayList<LiftCommand> commands = new ArrayList<>();
            commands.add(liftCommand);
@@ -768,13 +769,8 @@
                return false;
            }
            if (liftSta.getHasCar()) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}站点存在小车,禁止派发", wrkMast.getWrkNo(), liftSta.getStaNo());
                return false;
            }
            if (!liftSta.getHasTray()) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}站点无托盘,禁止派发", wrkMast.getWrkNo(), liftSta.getStaNo());
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}站点无托盘,禁止派发", wrkMast.getWrkNo(), liftSta.getSiteId());
                return false;
            }
@@ -1382,6 +1378,11 @@
                return false;
            }
            Object limitObj = redisUtil.get(RedisKeyType.TASK_RUN_LIMIT.key + wrkMast.getWrkNo());
            if (limitObj != null) {
                return false;
            }
            //小车已经在充电桩位置,下发停止充电命令
            ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
            assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());//四向穿梭车号
@@ -1394,6 +1395,7 @@
            //下发任务
            shuttleAction.assignWork(shuttleProtocol.getShuttleNo(), assignCommand);
            redisUtil.set(RedisKeyType.TASK_RUN_LIMIT.key + wrkMast.getWrkNo(), "limit", 10);
            return false;
        }
        return true;
@@ -1540,8 +1542,8 @@
            //小车已在近点位置无需前往
            if (shuttleProtocol.getCurrentLocNo().equals(endLocation)) {
                wrkMast.setWrkSts(WrkStsType.MOVE_NEARBY_COMPLETE.sts);//小车移动到提升机中  301.生成小车移库任务 ==> 303.小车移动至近点完成
                wrkMast.setSourceStaNo(recentLiftStation.getStaNo());
                wrkMast.setStaNo(targetLiftSta.getStaNo());
                wrkMast.setSourceStaNo(recentLiftStation.getSiteId());
                wrkMast.setStaNo(targetLiftSta.getSiteId());
                wrkMast.setModiTime(now);
                wrkMast.setSystemMsg("");//清空消息
                wrkMastService.updateById(wrkMast);
@@ -1566,8 +1568,8 @@
            assignCommand.setCommands(commands);
            wrkMast.setWrkSts(WrkStsType.MOVE_NEARBY.sts);//小车移动到提升机中  301.生成小车移库任务 ==> 302.小车移动至近点中
            wrkMast.setSourceStaNo(recentLiftStation.getStaNo());
            wrkMast.setStaNo(targetLiftSta.getStaNo());
            wrkMast.setSourceStaNo(recentLiftStation.getSiteId());
            wrkMast.setStaNo(targetLiftSta.getSiteId());
            wrkMast.setModiTime(now);
            wrkMast.setSystemMsg("");//清空消息
            if (wrkMastService.updateById(wrkMast)) {
@@ -1660,7 +1662,13 @@
            int targetLev = Utils.getLev(shuttleProtocol.getCurrentLocNo());
            if (object == null || liftProtocol.getLev() != targetLev) {
                //获取提升机命令
                LiftCommand liftCommand = liftThread.getMoveCommand(wrkMast.getWrkNo(), liftProtocol.getLev(), targetLev);
                LiftStaProtocol startSta = LiftUtils.getLiftStaByLev(liftProtocol.getLiftNo(), liftProtocol.getLev());
                LiftStaProtocol targetSta = LiftUtils.getLiftStaByLev(liftProtocol.getLiftNo(), targetLev);
                if (startSta == null || targetSta == null) {
                    News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}号提升机,站点数据不存在", wrkMast.getWrkNo(), wrkMast.getLiftNo());
                    return false;
                }
                LiftCommand liftCommand = liftThread.getMoveCommand(commonService.getWorkNo(WrkIoType.PREVIEW_LIFT_MOVE.id), startSta.getSiteId(), targetSta.getSiteId());
                ArrayList<LiftCommand> commands = new ArrayList<>();
                commands.add(liftCommand);
@@ -1674,6 +1682,12 @@
                liftAction.assignWork(wrkMast.getLiftNo(), assignCommand);
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}号提升机在{}层,提升机不在小车层,调度移动中", wrkMast.getWrkNo(), liftProtocol.getLev(), wrkMast.getLiftNo());
                redisUtil.set(RedisKeyType.LIFT_MOVE_TO_SHUTTLE_LIMIT.key + wrkMast.getWrkNo(), "lift_moving", 60 * 3);
                redisUtil.set(RedisKeyType.TASK_RUN_LIMIT.key + wrkMast.getWrkNo(), "lock", 8);
                return false;
            }
            Object limitObj = redisUtil.get(RedisKeyType.TASK_RUN_LIMIT.key + wrkMast.getWrkNo());
            if (limitObj != null) {
                return false;
            }
@@ -1750,7 +1764,7 @@
            }
            //获取提升机命令
            LiftCommand liftCommand = liftThread.getShuttleSwitchCommand(wrkMast.getWrkNo(), sourceLiftSta.getLev(), liftSta.getLev());
            LiftCommand liftCommand = liftThread.getShuttleSwitchCommand(wrkMast.getWrkNo(), sourceLiftSta.getSiteId(), liftSta.getSiteId());
            ArrayList<LiftCommand> commands = new ArrayList<>();
            commands.add(liftCommand);
@@ -1931,4 +1945,75 @@
        return true;
    }
    //自动切换出入库模式
    public void autoSwitchLiftIOMode() {
        List<DeviceConfig> liftList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
                .eq("device_type", String.valueOf(SlaveType.Lift)));
        for (DeviceConfig device : liftList) {
            Integer liftNo = device.getDeviceNo();
            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, liftNo);
            if (liftThread == null) {
                continue;
            }
            LiftProtocol liftProtocol = liftThread.getStatus();
            if (liftProtocol == null) {
                continue;
            }
            List<Integer> liftAllStaNo = LiftUtils.getLiftAllStaNo(liftNo);
            if (liftAllStaNo.isEmpty()) {
                continue;
            }
            List<Integer> conveyorBindLiftAllStaNo = LiftUtils.getConveyorBindLiftAllStaNo(liftNo);
            if (conveyorBindLiftAllStaNo.isEmpty()) {
                continue;
            }
            //获取入库任务
            List<WrkMast> inWrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>()
                    .in("sta_no", liftAllStaNo)
                    .in("wrk_sts"
                            , WrkStsType.NEW_INBOUND.sts
                            , WrkStsType.INBOUND_DEVICE_RUN.sts
                            , WrkStsType.INBOUND_LIFT_RUN.sts
                            , WrkStsType.INBOUND_LIFT_RUN_COMPLETE.sts
                            , WrkStsType.INBOUND_SHUTTLE_RUN.sts
                            , WrkStsType.INBOUND_SHUTTLE_RUN_COMPLETE.sts
                    ));
            //获取出库任务
            List<WrkMast> outWrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>()
                    .in("sta_no", conveyorBindLiftAllStaNo)
                    .in("wrk_sts"
                            , WrkStsType.NEW_OUTBOUND.sts
                            , WrkStsType.OUTBOUND_SHUTTLE_RUN.sts
                            , WrkStsType.OUTBOUND_SHUTTLE_RUN_COMPLETE.sts
                            , WrkStsType.OUTBOUND_LIFT_RUN.sts
                            , WrkStsType.OUTBOUND_LIFT_RUN_COMPLETE.sts
                    ));
            if (liftProtocol.getIOModeType().equals(LiftIoModeType.NONE)) {
                //未知模式
                if (!inWrkMasts.isEmpty()) {
                    liftThread.switchIOMode(LiftIoModeType.IN);
                } else if (!outWrkMasts.isEmpty()) {
                    liftThread.switchIOMode(LiftIoModeType.OUT);
                }else {
                    liftThread.switchIOMode(LiftIoModeType.IN);
                }
            } else if (liftProtocol.getIOModeType().equals(LiftIoModeType.IN)) {
                //入库模式
                if (inWrkMasts.isEmpty() && !outWrkMasts.isEmpty()) {
                    liftThread.switchIOMode(LiftIoModeType.OUT);
                }
            } else if (liftProtocol.getIOModeType().equals(LiftIoModeType.OUT)) {
                //出库模式
                if (outWrkMasts.isEmpty() && !inWrkMasts.isEmpty()) {
                    liftThread.switchIOMode(LiftIoModeType.IN);
                }
            }
        }
    }
}