#
Junjie
15 小时以前 2c175f2b2c00dfe18c349b92a6f6b1ec55bc3db1
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -2,6 +2,7 @@
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.SpringUtils;
import com.zy.asrs.domain.enums.NotifyMsgType;
import com.zy.asrs.entity.*;
import com.zy.asrs.service.*;
@@ -75,6 +76,8 @@
    private DeviceConfigService deviceConfigService;
    @Autowired
    private LiftDispatchUtils liftDispatchUtils;
    @Autowired
    private BasShuttleService basShuttleService;
    /**
     * 初始化实时地图
@@ -99,7 +102,7 @@
                    }
                    //将数据库地图数据存入redis
                    redisUtil.set(RedisKeyType.MAP.key + lev, JSON.toJSONString(basMap));
                    redisUtil.set(RedisKeyType.MAP.key + lev, lists);
                }
            }
@@ -299,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;
            }
@@ -424,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)) {
@@ -501,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());
@@ -608,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;
            }
@@ -692,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);
@@ -765,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;
            }
@@ -1094,8 +1093,26 @@
                }
                //判断当前小车是否满足需要充电要求
                if (!shuttleThread.isRequireCharge()) {
                    continue;
                if (shuttleThread.isRequireCharge().equals(ShuttleRequireChargeType.NONE)) {
                    continue;//无需充电
                }
                boolean forceCharge = true;
                if (shuttleThread.isRequireCharge().equals(ShuttleRequireChargeType.SUGGEST_CHARGE)) {
                    BasShuttle basShuttle = basShuttleService.selectOne(new EntityWrapper<BasShuttle>().eq("shuttle_no", device.getDeviceNo()));
                    if (basShuttle != null) {
                        Integer suggestChargeLine = basShuttle.getSuggestChargeLine();
                        boolean chargeSuggestResult = Integer.parseInt(shuttleProtocol.getBatteryPower()) < suggestChargeLine;
                        if (chargeSuggestResult) {
                            //检测系统是否有任务
                            List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().in("io_type", 1, 101, 201));
                            if (wrkMasts.isEmpty()) {
                                forceCharge = false;
                            }else {
                                continue;
                            }
                        }
                    }
                }
                WrkMast wrkMast1 = wrkMastService.selectShuttleWorking(shuttleProtocol.getShuttleNo());
@@ -1171,7 +1188,7 @@
                wrkMast.setIoPri((double) 999);
                wrkMast.setLocNo(chargeLocNo);
                wrkMast.setShuttleNo(device.getDeviceNo());
                wrkMast.setMemo("charge");
                wrkMast.setMemo(forceCharge ? "forceCharge" : "suggestCharge");
                wrkMast.setAppeTime(new Date());
                if (!wrkMastService.insert(wrkMast)) {
                    News.error("保存{}号四向穿梭车充电任务失败!!!", device.getDeviceNo());
@@ -1321,7 +1338,7 @@
            List<ShuttleCommand> commands = shuttleOperaUtils.getShuttleChargeCommand(assignCommand, shuttleThread, true);
            assignCommand.setCommands(commands);//运行命令
            wrkMast.setWrkSts(WrkStsType.CHARGE_SHUTTLE_WORKING.sts);
            wrkMast.setWrkSts(WrkStsType.CHARGE_SHUTTLE_START_CHARGING.sts);
            wrkMast.setModiTime(new Date());
            if (!wrkMastService.updateById(wrkMast)) {
                return false;
@@ -1338,7 +1355,7 @@
    //小车停止充电
    private synchronized boolean executeShuttleChargeStepStopCharge(WrkMast wrkMast) {
        if (wrkMast.getWrkSts() == WrkStsType.CHARGE_SHUTTLE_WORKING.sts) {
        if (wrkMast.getWrkSts() == WrkStsType.CHARGE_SHUTTLE_CHARGING.sts) {
            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
            if (shuttleThread == null) {
                return false;
@@ -1348,7 +1365,21 @@
                return false;
            }
            if (!shuttleThread.isChargingCompleted()) {
            boolean stopCharge = false;
            if (wrkMast.getMemo().equals("suggestChargeTaskStop")) {
                stopCharge = true;
            }else {
                if (shuttleThread.isChargingCompleted()) {
                    stopCharge = true;
                }
            }
            if (!stopCharge) {
                return false;
            }
            Object limitObj = redisUtil.get(RedisKeyType.TASK_RUN_LIMIT.key + wrkMast.getWrkNo());
            if (limitObj != null) {
                return false;
            }
@@ -1364,6 +1395,7 @@
            //下发任务
            shuttleAction.assignWork(shuttleProtocol.getShuttleNo(), assignCommand);
            redisUtil.set(RedisKeyType.TASK_RUN_LIMIT.key + wrkMast.getWrkNo(), "limit", 10);
            return false;
        }
        return true;
@@ -1371,7 +1403,7 @@
    //小车离开充电桩
    private synchronized boolean executeShuttleChargeStepLeaveCharge(WrkMast wrkMast) {
        if (wrkMast.getWrkSts() == WrkStsType.CHARGE_SHUTTLE_COMPLETE.sts) {
        if (wrkMast.getWrkSts() == WrkStsType.CHARGE_SHUTTLE_CHARGING_COMPLETE.sts) {
            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
            if (shuttleThread == null) {
                return false;
@@ -1510,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);
@@ -1536,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)) {
@@ -1630,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);
@@ -1644,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;
            }
@@ -1658,7 +1702,7 @@
            assignCommand.setAuto(true);//自动模式
            //获取小车到提升机行走命令
            List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(shuttleProtocol.getCurrentLocNo(), liftLocNo, NavigationMapType.getNormalWithDevice(), assignCommand, shuttleThread, "inLift");
            List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(shuttleProtocol.getCurrentLocNo(), liftLocNo, NavigationMapType.getMapTypes(NavigationMapType.NORMAL), assignCommand, shuttleThread, "inLift");
            if (commands == null) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}小车,路径计算失败", wrkMast.getWrkNo(), shuttleProtocol.getShuttleNo());
                return false;//路径解锁失败
@@ -1720,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);
@@ -1795,7 +1839,14 @@
                return false;
            }
            String targetLocNo = navigateUtils.calcFirstLocation(shuttleProtocol.getCurrentLocNo(), wrkMast.getLocNo(), NavigationMapType.getMapTypes(NavigationMapType.NORMAL), null, null, 5);
            //小车出提升机近点距离
            int shuttleOutLiftLocationDistance = 2;
            Config shuttleOutLiftLocationDistanceConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "shuttleOutLiftLocationDistance"));
            if (shuttleOutLiftLocationDistanceConfig != null) {
                shuttleOutLiftLocationDistance = Integer.parseInt(shuttleOutLiftLocationDistanceConfig.getValue());
            }
            String targetLocNo = navigateUtils.calcFirstLocation(shuttleProtocol.getCurrentLocNo(), wrkMast.getLocNo(), NavigationMapType.getMapTypes(NavigationMapType.NORMAL), null, null, shuttleOutLiftLocationDistance);
            if (targetLocNo == null) {//出提升机近点计算失败
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}小车,出提升机近点计算失败", wrkMast.getWrkNo(), shuttleProtocol.getShuttleNo());
                return false;
@@ -1894,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);
                }
            }
        }
    }
}