#
Junjie
3 天以前 6cf4a3e2ba925e75b60f13bb8ebc5e92d37809b2
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -17,10 +17,8 @@
import com.zy.core.cache.SlaveConnection;
import com.zy.core.dispatcher.ShuttleDispatchUtils;
import com.zy.core.enums.*;
import com.zy.core.model.*;
import com.zy.core.model.command.*;
import com.zy.core.model.protocol.*;
import com.zy.core.properties.SlaveProperties;
import com.zy.core.thread.*;
import com.zy.system.entity.Config;
import com.zy.system.service.ConfigService;
@@ -38,8 +36,6 @@
@Service("mainService")
public class MainServiceImpl {
    @Autowired
    private SlaveProperties slaveProperties;
    @Autowired
    private WrkMastService wrkMastService;
    @Autowired
@@ -76,6 +72,8 @@
    private NotifyUtils notifyUtils;
    @Autowired
    private BasShuttleChargeService basShuttleChargeService;
    @Autowired
    private DeviceConfigService deviceConfigService;
    /**
     * 初始化实时地图
@@ -89,7 +87,7 @@
                Object data = redisUtil.get(RedisKeyType.MAP.key + lev);
                if (data == null) {//redis地图数据为空
                    //载入地图
                    List<List<MapNode>> lists = navigateMapData.getJsonData(lev, -1, null, null);//获取完整地图(包括入库出库)
                    List<List<MapNode>> lists = navigateMapData.getJsonOriginData(lev, NavigationMapType.getMapTypes(NavigationMapType.NONE), null, null);//获取完整地图(包括入库出库)
                    //存入数据库
                    basMap.setData(JSON.toJSONString(lists));
@@ -198,7 +196,7 @@
            assignCommand.setAuto(true);//自动模式
            //获取小车到输送站点行走命令
            List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(liftSta.getLocNo(), wrkMast.getLocNo(), NavigationMapType.DFX.id, assignCommand, shuttleThread);
            List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(liftSta.getLocNo(), wrkMast.getLocNo(), NavigationMapType.getDfxWithDevice(), assignCommand, shuttleThread);
            if (commands == null) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}小车,路径计算失败", wrkMast.getWrkNo(), shuttleProtocol.getShuttleNo());
                return false;
@@ -309,6 +307,23 @@
                return false;
            }
            List<WrkMast> shuttleMoveList = wrkMastService.selectList(new EntityWrapper<WrkMast>()
                    .eq("io_type", 200)
            );
            for (WrkMast moveWrkMast : shuttleMoveList) {
                if(Utils.getLev(moveWrkMast.getLocNo()) != Utils.getLev(wrkMast.getSourceLocNo())) {
                    continue;
                }
                if(Utils.getLev(moveWrkMast.getLocNo()) == Utils.getLev(moveWrkMast.getSourceLocNo())) {
                    continue;
                }
                //存在换层任务,出库任务暂时不执行
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,存在换层任务,出库任务等待中", wrkMast.getWrkNo());
                return false;
            }
            boolean checkLocPathIsAvailable = navigateUtils.checkLocPathIsAvailable(wrkMast.getSourceLocNo(), liftSta.getLocNo());
            if(!checkLocPathIsAvailable) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,未计算到可执行路径,等待中", wrkMast.getWrkNo());
@@ -319,7 +334,7 @@
                //强制预留一台小车给入库任务
                int lev = Utils.getLev(wrkMast.getSourceLocNo());
                //获取当前楼层有几台可用小车
                int shuttleCount = shuttleDispatchUtils.getShuttleCountByLev(lev);
                int shuttleCount = shuttleDispatchUtils.getShuttleEnableUseCountByLev(lev);
                if (shuttleCount >= 2) {//只有可用小车数量大于2,才进行入库任务预留小车
                    int shuttleWrkInObligateCount = 1;//预留小车数量
                    Config config = configService.selectOne(new EntityWrapper<Config>().eq("code", "shuttleWrkInObligateCount").eq("status", 1));
@@ -378,7 +393,7 @@
            assignCommand.setAuto(true);//自动模式
            //获取小车到输送站点行走命令
            List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(wrkMast.getSourceLocNo(), liftSta.getLocNo(), NavigationMapType.DFX.id, assignCommand, shuttleThread);
            List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(wrkMast.getSourceLocNo(), liftSta.getLocNo(), NavigationMapType.getDfxWithDevice(), assignCommand, shuttleThread);
            if (commands == null) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}小车,路径计算失败", wrkMast.getWrkNo(), shuttleProtocol.getShuttleNo());
                return false;
@@ -414,97 +429,6 @@
            return false;
        }
        return true;
    }
    /**
     * 四向穿梭车任务完成
     */
    public synchronized void shuttleFinished() {
        try {
            for (ShuttleSlave shuttle : slaveProperties.getShuttle()) {
                //获取四向穿梭车信息
                ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId());
                ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
                if (shuttleProtocol == null) {
                    continue;
                }
                //四向穿梭车状态为等待确认、小车处于空闲状态
                if (shuttleProtocol.getProtocolStatus() == ShuttleProtocolStatusType.WAITING.id  //任务完成等待确认
                        && shuttleProtocol.getTaskNo() != 0
                ) {
                    //将任务档标记为完成
                    WrkMast wrkMast = wrkMastService.selectByWorkNo(shuttleProtocol.getTaskNo());
                    if (wrkMast != null) {
                        if (wrkMast.getWrkSts() == WrkStsType.INBOUND_SHUTTLE_RUN.sts) {
                            //5.小车搬运中 ==> 9.入库完成
                            wrkMast.setWrkSts(WrkStsType.COMPLETE_INBOUND.sts);
                            shuttleThread.setSyncTaskNo(0);
                        } else if (wrkMast.getWrkSts() == WrkStsType.OUTBOUND_SHUTTLE_RUN.sts) {
                            //102.小车搬运中 ==> 103.小车搬运完成
                            wrkMast.setWrkSts(WrkStsType.OUTBOUND_SHUTTLE_RUN_COMPLETE.sts);
                            shuttleThread.setSyncTaskNo(0);
                        } else if (wrkMast.getWrkSts() == WrkStsType.MOVE_NEARBY.sts) {
                            //302.小车移动至近点中 ==> 303.小车移动至近点完成
                            wrkMast.setWrkSts(WrkStsType.MOVE_NEARBY_COMPLETE.sts);
                            shuttleThread.setSyncTaskNo(0);
                        } else if (wrkMast.getWrkSts() == WrkStsType.MOVE_IN_LIFT.sts) {
                            //304.小车迁入提升机中 ==> 305.小车迁入提升机完成
                            wrkMast.setWrkSts(WrkStsType.MOVE_IN_LIFT_COMPLETE.sts);
                            shuttleThread.setSyncTaskNo(0);
                        } else if (wrkMast.getWrkSts() == WrkStsType.MOVE_OUT_LIFT.sts) {
                            //308.小车迁出提升机中 ==> 309.小车迁出提升机完成
                            if (Utils.getLev(shuttleProtocol.getCurrentLocNo()) != Utils.getLev(wrkMast.getLocNo())) {
                                continue;//小车未到达目标层
                            }
                            wrkMast.setWrkSts(WrkStsType.MOVE_OUT_LIFT_COMPLETE.sts);
                            shuttleThread.setSyncTaskNo(0);
                        } else if (wrkMast.getWrkSts() == WrkStsType.MOVE_SHUTTLE.sts) {
                            //310.小车移动中 ==> 311.小车移动完成
                            wrkMast.setWrkSts(WrkStsType.COMPLETE_MOVE.sts);
                            shuttleThread.setSyncTaskNo(0);
                            notifyUtils.notify(String.valueOf(SlaveType.Shuttle), shuttleProtocol.getShuttleNo(), String.valueOf(wrkMast.getWrkNo()), wrkMast.getWmsWrkNo(), NotifyMsgType.SHUTTLE_MOVE_COMPLETE);//触发通知
                        } else if (wrkMast.getWrkSts() == WrkStsType.CHARGE_SHUTTLE_WORKING.sts) {
                            //204.小车充电中 ==> 205.小车充电完成
                            wrkMast.setWrkSts(WrkStsType.CHARGE_SHUTTLE_COMPLETE.sts);
                            shuttleThread.setSyncTaskNo(0);
                            notifyUtils.notify(String.valueOf(SlaveType.Shuttle), shuttleProtocol.getShuttleNo(), String.valueOf(wrkMast.getWrkNo()), wrkMast.getWmsWrkNo(), NotifyMsgType.SHUTTLE_POWER_COMPLETE);//触发通知
                        } else if (wrkMast.getWrkSts() == WrkStsType.LOC_MOVE_SHUTTLE_RUN.sts) {
                            //502.小车搬运中 ==> 509.移库完成
                            wrkMast.setWrkSts(WrkStsType.COMPLETE_LOC_MOVE.sts);
                            shuttleThread.setSyncTaskNo(0);
                            notifyUtils.notify(String.valueOf(SlaveType.Shuttle), shuttleProtocol.getShuttleNo(), String.valueOf(wrkMast.getWrkNo()), wrkMast.getWmsWrkNo(), NotifyMsgType.SHUTTLE_DELIVERY);//触发通知
                        } else {
                            continue;
                        }
                        if (wrkMastService.updateById(wrkMast)) {
                            //设置四向穿梭车为空闲状态
                            shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
                            News.info("四向穿梭车已确认且任务完成状态,复位。四向穿梭车号={}", shuttleProtocol.getShuttleNo());
                        } else {
                            News.error("四向穿梭车已确认且任务完成状态,复位失败,但未找到工作档。四向穿梭车号={},工作号={}", shuttleProtocol.getShuttleNo(), shuttleProtocol.getTaskNo());
                        }
                    } else {
                        Object object = redisUtil.get(RedisKeyType.SHUTTLE_WORK_FLAG.key + shuttleProtocol.getTaskNo());
                        if(object != null){
                            ShuttleAssignCommand assignCommand = JSON.parseObject(object.toString(), ShuttleAssignCommand.class);
                            if (!assignCommand.getAuto()) {
                                //手动模式
                                //工作号清零
                                shuttleThread.setTaskNo(0);
                                //设置四向穿梭车为空闲状态
                                shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
                                News.info("四向穿梭车已确认且任务完成状态,复位。四向穿梭车号={}", shuttleProtocol.getShuttleNo());
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
@@ -584,7 +508,7 @@
            assignCommand.setAuto(true);//自动模式
            //获取小车到输送站点行走命令
            List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(wrkMast.getSourceLocNo(), wrkMast.getLocNo(), NavigationMapType.DFX.id, assignCommand, shuttleThread);
            List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(wrkMast.getSourceLocNo(), wrkMast.getLocNo(), NavigationMapType.getDfxWithDevice(), assignCommand, shuttleThread);
            if (commands == null) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}小车,路径计算失败", wrkMast.getWrkNo(), shuttleProtocol.getShuttleNo());
                return false;
@@ -745,9 +669,9 @@
            }
            //获取提升机命令
            List<ForkLiftCommand> liftCommands = forkLiftThread.getPickAndPutCommand(wrkMast.getWrkNo(), wrkMast.getSourceStaNo(), liftSta.getLev());
            ForkLiftCommand liftCommand = forkLiftThread.getPickAndPutCommand(wrkMast.getWrkNo(), wrkMast.getSourceStaNo(), liftSta.getLev());
            ArrayList<ForkLiftCommand> commands = new ArrayList<>();
            commands.addAll(liftCommands);
            commands.add(liftCommand);
            //提交到线程去工作
            LiftAssignCommand assignCommand = new LiftAssignCommand();
@@ -873,9 +797,9 @@
            }
            //获取提升机命令
            List<ForkLiftCommand> liftCommands = forkLiftThread.getPickAndPutCommand(wrkMast.getWrkNo(), liftSta.getLev(), wrkMast.getStaNo());
            ForkLiftCommand liftCommand = forkLiftThread.getPickAndPutCommand(wrkMast.getWrkNo(), liftSta.getLev(), wrkMast.getStaNo());
            ArrayList<ForkLiftCommand> commands = new ArrayList<>();
            commands.addAll(liftCommands);
            commands.add(liftCommand);
            //提交到线程去工作
            LiftAssignCommand assignCommand = new LiftAssignCommand();
@@ -902,9 +826,14 @@
     */
    public synchronized void forkLiftFinished() {
        try {
            for (ForkLiftSlave forkLiftSlave : slaveProperties.getForkLift()) {
            List<DeviceConfig> forkliftList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
                    .eq("device_type", String.valueOf(SlaveType.ForkLift)));
            for (DeviceConfig device : forkliftList) {
                //获取提升机信息
                ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, forkLiftSlave.getId());
                ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, device.getDeviceNo());
                if(forkLiftThread == null) {
                    continue;
                }
                ForkLiftProtocol forkLiftProtocol = forkLiftThread.getStatus();
                if (forkLiftProtocol == null) {
                    continue;
@@ -974,9 +903,11 @@
     */
    private void recShuttleErr() {
        Date now = new Date();
        for (ShuttleSlave shuttleSlave : slaveProperties.getShuttle()) {
        List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
                .eq("device_type", String.valueOf(SlaveType.Shuttle)));
        for (DeviceConfig device : shuttleList) {
            // 获取四向穿梭车信息
            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleSlave.getId());
            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getDeviceNo());
            if (shuttleThread == null) {
                continue;
            }
@@ -987,7 +918,7 @@
            if (shuttleProtocol.getTaskNo() != 0) {
                //有任务
                BasShuttleErrLog latest = basShuttleErrLogService.findLatestByTaskNo(shuttleSlave.getId(), shuttleProtocol.getTaskNo());
                BasShuttleErrLog latest = basShuttleErrLogService.findLatestByTaskNo(device.getDeviceNo(), shuttleProtocol.getTaskNo());
                // 有异常
                if (latest == null) {
                    if (shuttleProtocol.getErrorCode() != null && Integer.parseInt(shuttleProtocol.getErrorCode()) != 0) {
@@ -1005,7 +936,7 @@
                                null,    // 结束时间
                                wrkMast.getWrkSts(),    // 工作状态
                                wrkMast.getIoType(),    // 入出库类型
                                shuttleSlave.getId(),    // 四向穿梭车
                                device.getDeviceNo(),    // 四向穿梭车
                                null,    // plc
                                wrkMast.getLocNo(),    // 目标库位
                                wrkMast.getStaNo(),    // 目标站
@@ -1023,7 +954,7 @@
                                JSON.toJSONString(shuttleProtocol)    // 系统状态数据
                        );
                        if (!basShuttleErrLogService.insert(basShuttleErrLog)) {
                            News.error("四向穿梭车plc异常记录失败 ===>> [id:{}] [error:{}]", shuttleSlave.getId(), errName);
                            News.error("四向穿梭车plc异常记录失败 ===>> [id:{}] [error:{}]", device.getDeviceNo(), errName);
                        }
                    }
                } else {
@@ -1033,7 +964,7 @@
                        latest.setUpdateTime(now);
                        latest.setStatus(2);
                        if (!basShuttleErrLogService.updateById(latest)) {
                            News.error("四向穿梭车plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", shuttleSlave.getId(), latest.getId());
                            News.error("四向穿梭车plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", device.getDeviceNo(), latest.getId());
                        }
                    }
                }
@@ -1046,9 +977,11 @@
     */
    private void recLiftErr() {
        Date now = new Date();
        for (ForkLiftSlave forkLiftSlave : slaveProperties.getForkLift()) {
        List<DeviceConfig> forkliftList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
                .eq("device_type", String.valueOf(SlaveType.ForkLift)));
        for (DeviceConfig device : forkliftList) {
            // 获取提升机信息
            ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, forkLiftSlave.getId());
            ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, device.getDeviceNo());
            if (forkLiftThread == null) {
                continue;
            }
@@ -1059,7 +992,7 @@
            if (forkLiftProtocol.getTaskNo() != 0) {
                //有任务
                BasLiftErrLog latest = basLiftErrLogService.findLatestByTaskNo(forkLiftSlave.getId(), forkLiftProtocol.getTaskNo());
                BasLiftErrLog latest = basLiftErrLogService.findLatestByTaskNo(device.getDeviceNo(), forkLiftProtocol.getTaskNo());
                // 有异常
                if (latest == null) {
                    if (forkLiftProtocol.getErrorCode() != null && forkLiftProtocol.getErrorCode() != 0) {
@@ -1078,7 +1011,7 @@
                                null,    // 结束时间
                                wrkMast.getWrkSts(),    // 工作状态
                                wrkMast.getIoType(),    // 入出库类型
                                forkLiftSlave.getId(),    // 提升机
                                device.getDeviceNo(),    // 提升机
                                null,    // plc
                                wrkMast.getLocNo(),    // 目标库位
                                wrkMast.getStaNo(),    // 目标站
@@ -1096,7 +1029,7 @@
                                JSON.toJSONString(forkLiftProtocol)    // 系统状态数据
                        );
                        if (!basLiftErrLogService.insert(basLiftErrLog)) {
                            News.error("提升机plc异常记录失败 ===>> [id:{}] [error:{}]", forkLiftSlave.getId(), errName);
                            News.error("提升机plc异常记录失败 ===>> [id:{}] [error:{}]", device.getDeviceNo(), errName);
                        }
                    }
                } else {
@@ -1106,7 +1039,7 @@
                        latest.setUpdateTime(now);
                        latest.setStatus(2);
                        if (!basLiftErrLogService.updateById(latest)) {
                            News.error("提升机plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", forkLiftSlave.getId(), latest.getId());
                            News.error("提升机plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", device.getDeviceNo(), latest.getId());
                        }
                    }
                }
@@ -1125,9 +1058,11 @@
                return;//无充电桩
            }
            for (ShuttleSlave shuttle : slaveProperties.getShuttle()) {
            List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
                    .eq("device_type", String.valueOf(SlaveType.Shuttle)));
            for (DeviceConfig device : shuttleList) {
                //获取四向穿梭车线程
                ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId());
                ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getDeviceNo());
                ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
                if (shuttleProtocol == null) {
                    continue;
@@ -1200,15 +1135,15 @@
                wrkMast.setIoType(WrkIoType.SHUTTLE_CHARGE.id);//300.充电
                wrkMast.setIoPri((double) 999);
                wrkMast.setLocNo(chargeLocNo);
                wrkMast.setShuttleNo(shuttle.getId());
                wrkMast.setShuttleNo(device.getDeviceNo());
                wrkMast.setMemo("charge");
                wrkMast.setAppeTime(new Date());
                if (!wrkMastService.insert(wrkMast)) {
                    News.error("保存{}号四向穿梭车充电任务失败!!!", shuttle.getId());
                    News.error("保存{}号四向穿梭车充电任务失败!!!", device.getDeviceNo());
                    continue;
                }
                News.info("保存{}号四向穿梭车充电任务成功!!!", shuttle.getId());
                News.info("保存{}号四向穿梭车充电任务成功!!!", device.getDeviceNo());
            }
        } catch (Exception e) {
            e.printStackTrace();
@@ -1221,8 +1156,10 @@
    public synchronized void executeShuttleCharge() {
        try {
            //查询小车充电任务
            for (ShuttleSlave shuttle : slaveProperties.getShuttle()) {
                WrkMast wrkMast = wrkMastService.selectChargeWorking(shuttle.getId());
            List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
                    .eq("device_type", String.valueOf(SlaveType.Shuttle)));
            for (DeviceConfig device : shuttleList) {
                WrkMast wrkMast = wrkMastService.selectChargeWorking(device.getDeviceNo());
                if(wrkMast == null) {
                    continue;
                }
@@ -1271,7 +1208,7 @@
                return false;
            }
            if (shuttleProtocol.getCurrentLocNo().equals(wrkMast.getLocNo())) {
            if (wrkMast.getLocNo().equals(shuttleProtocol.getCurrentLocNo())) {
                //小车在充电桩位置
                wrkMast.setWrkSts(WrkStsType.CHARGE_SHUTTLE_RUN_COMPLETE.sts);
                wrkMast.setModiTime(new Date());
@@ -1343,7 +1280,7 @@
            ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
            assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());//四向穿梭车号
            assignCommand.setTaskNo(wrkMast.getWrkNo());//任务号
            assignCommand.setTaskMode(ShuttleTaskModeType.CHARGE.id);//出库模式
            assignCommand.setTaskMode(ShuttleTaskModeType.CHARGE_ON.id);//充电开
            assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//源库位(小车当前位置)
            List<ShuttleCommand> commands = shuttleOperaUtils.getShuttleChargeCommand(assignCommand, shuttleThread, true);
@@ -1384,7 +1321,7 @@
            ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
            assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());//四向穿梭车号
            assignCommand.setTaskNo(wrkMast.getWrkNo());//任务号
            assignCommand.setTaskMode(ShuttleTaskModeType.CHARGE.id);//出库模式
            assignCommand.setTaskMode(ShuttleTaskModeType.CHARGE_OFF.id);//充电关
            assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//源库位(小车当前位置)
            List<ShuttleCommand> commands = shuttleOperaUtils.getShuttleChargeCommand(assignCommand, shuttleThread, false);
@@ -1555,7 +1492,7 @@
            assignCommand.setAuto(true);//自动模式
            //计算近点位置
            String endLocation = navigateUtils.calcEndLocation(shuttleProtocol.getCurrentLocNo(), liftSta.getLocNo(), NavigationMapType.NORMAL.id, null, null, 1);
            String endLocation = navigateUtils.calcEndLocation(shuttleProtocol.getCurrentLocNo(), liftSta.getLocNo(), NavigationMapType.getMapTypes(NavigationMapType.NORMAL, NavigationMapType.PATH_LOCK), null, null, 1);
            if (endLocation == null) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,小车近点位置计算失败", wrkMast.getWrkNo());
                return false;
@@ -1566,11 +1503,12 @@
                wrkMast.setWrkSts(WrkStsType.MOVE_NEARBY_COMPLETE.sts);//小车移动到提升机中  301.生成小车移库任务 ==> 303.小车移动至近点完成
                wrkMast.setModiTime(now);
                wrkMast.setSystemMsg("");//清空消息
                wrkMastService.updateById(wrkMast);
                return true;
            }
            //获取小车到近点行走命令
            List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(shuttleProtocol.getCurrentLocNo(), endLocation, NavigationMapType.NORMAL.id, assignCommand, shuttleThread);
            List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(shuttleProtocol.getCurrentLocNo(), endLocation, NavigationMapType.getMapTypes(NavigationMapType.NORMAL, NavigationMapType.SHUTTLE), assignCommand, shuttleThread);
            if (commands == null) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}小车,路径计算失败", wrkMast.getWrkNo(), shuttleProtocol.getShuttleNo());
                return false;//路径解锁失败
@@ -1652,6 +1590,22 @@
                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());
                    return false;
                }
            }
            if (wrkMast.getLiftNo() == null) {
                //申请提升机资源(该任务需要换层必须提前独占提升机)
                boolean applyForkLift = forkLiftAction.applyForkLift(liftSta.getLiftNo(), wrkMast.getWrkNo());
@@ -1669,7 +1623,7 @@
            assignCommand.setAuto(true);//自动模式
            //获取小车到提升机行走命令
            List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(shuttleProtocol.getCurrentLocNo(), liftSta.getLocNo(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread);
            List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(shuttleProtocol.getCurrentLocNo(), liftSta.getLocNo(), NavigationMapType.getNormalWithDevice(), assignCommand, shuttleThread);
            if (commands == null) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}小车,路径计算失败", wrkMast.getWrkNo(), shuttleProtocol.getShuttleNo());
                return false;//路径解锁失败
@@ -1731,9 +1685,9 @@
            }
            //获取提升机命令
            List<ForkLiftCommand> liftCommands = forkLiftThread.getShuttleSwitchCommand(wrkMast.getWrkNo(), sourceLiftSta.getLev(), liftSta.getLev());
            ForkLiftCommand liftCommand = forkLiftThread.getShuttleSwitchCommand(wrkMast.getWrkNo(), sourceLiftSta.getLev(), liftSta.getLev());
            ArrayList<ForkLiftCommand> commands = new ArrayList<>();
            commands.addAll(liftCommands);
            commands.add(liftCommand);
            //提交到线程去工作
            LiftAssignCommand assignCommand = new LiftAssignCommand();
@@ -1853,7 +1807,7 @@
            assignCommand.setLocNo(wrkMast.getLocNo());//目标库位
            //获取小车到目标库位命令
            List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(shuttleProtocol.getCurrentLocNo(), wrkMast.getLocNo(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread);
            List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(shuttleProtocol.getCurrentLocNo(), wrkMast.getLocNo(), NavigationMapType.getNormalWithDevice(), assignCommand, shuttleThread);
            if (commands == null) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}小车,路径计算失败", wrkMast.getWrkNo(), shuttleProtocol.getShuttleNo());
                return false;//路径计算失败
@@ -1875,71 +1829,73 @@
    //自动切换出入库模式
    public void autoSwitchForkLiftIOMode() {
        for (ForkLiftSlave forkLiftSlave : slaveProperties.getForkLift()) {
            Integer liftNo = forkLiftSlave.getId();
            ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, liftNo);
            if (forkLiftThread == null) {
                continue;
            }
            ForkLiftProtocol forkLiftProtocol = forkLiftThread.getStatus();
            if (forkLiftProtocol == null) {
                continue;
            }
            List<Integer> liftAllStaNo = ForkLiftUtils.getLiftAllStaNo(liftNo);
            if (liftAllStaNo.isEmpty()) {
                continue;
            }
            List<Integer> conveyorBindLiftAllStaNo = ForkLiftUtils.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 (forkLiftProtocol.getIOModeType().equals(ForkLiftIoModeType.NONE)) {
                //未知模式
                if (!inWrkMasts.isEmpty()) {
                    forkLiftThread.switchIOMode(ForkLiftIoModeType.IN);
                } else if (!outWrkMasts.isEmpty()) {
                    forkLiftThread.switchIOMode(ForkLiftIoModeType.OUT);
                }else {
                    forkLiftThread.switchIOMode(ForkLiftIoModeType.IN);
                }
            } else if (forkLiftProtocol.getIOModeType().equals(ForkLiftIoModeType.IN)) {
                //入库模式
                if (inWrkMasts.isEmpty() && !outWrkMasts.isEmpty()) {
                    forkLiftThread.switchIOMode(ForkLiftIoModeType.OUT);
                }
            } else if (forkLiftProtocol.getIOModeType().equals(ForkLiftIoModeType.OUT)) {
                //出库模式
                if (outWrkMasts.isEmpty() && !inWrkMasts.isEmpty()) {
                    forkLiftThread.switchIOMode(ForkLiftIoModeType.IN);
                }
            }
        }
//        List<DeviceConfig> forkliftList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
//                .eq("device_type", String.valueOf(SlaveType.ForkLift)));
//        for (DeviceConfig device : forkliftList) {
//            Integer liftNo = device.getDeviceNo();
//            ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, liftNo);
//            if (forkLiftThread == null) {
//                continue;
//            }
//            ForkLiftProtocol forkLiftProtocol = forkLiftThread.getStatus();
//            if (forkLiftProtocol == null) {
//                continue;
//            }
//
//            List<Integer> liftAllStaNo = ForkLiftUtils.getLiftAllStaNo(liftNo);
//            if (liftAllStaNo.isEmpty()) {
//                continue;
//            }
//
//            List<Integer> conveyorBindLiftAllStaNo = ForkLiftUtils.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 (forkLiftProtocol.getIOModeType().equals(ForkLiftIoModeType.NONE)) {
//                //未知模式
//                if (!inWrkMasts.isEmpty()) {
//                    forkLiftThread.switchIOMode(ForkLiftIoModeType.IN);
//                } else if (!outWrkMasts.isEmpty()) {
//                    forkLiftThread.switchIOMode(ForkLiftIoModeType.OUT);
//                }else {
//                    forkLiftThread.switchIOMode(ForkLiftIoModeType.IN);
//                }
//            } else if (forkLiftProtocol.getIOModeType().equals(ForkLiftIoModeType.IN)) {
//                //入库模式
//                if (inWrkMasts.isEmpty() && !outWrkMasts.isEmpty()) {
//                    forkLiftThread.switchIOMode(ForkLiftIoModeType.OUT);
//                }
//            } else if (forkLiftProtocol.getIOModeType().equals(ForkLiftIoModeType.OUT)) {
//                //出库模式
//                if (outWrkMasts.isEmpty() && !inWrkMasts.isEmpty()) {
//                    forkLiftThread.switchIOMode(ForkLiftIoModeType.IN);
//                }
//            }
//        }
    }
    //出库任务预调度提升机
@@ -2010,9 +1966,9 @@
            int workNo = commonService.getWorkNo(WrkIoType.FORKLIFT_MOVE.id);//获取任务号
            //获取提升机命令
            List<ForkLiftCommand> liftCommand = forkLiftThread.getMoveCommand(workNo, forkLiftProtocol.getLev(), Utils.getLev(wrkMast.getSourceLocNo()));
            ForkLiftCommand liftCommand = forkLiftThread.getMoveCommand(workNo, forkLiftProtocol.getLev(), Utils.getLev(wrkMast.getSourceLocNo()));
            ArrayList<ForkLiftCommand> commands = new ArrayList<>();
            commands.addAll(liftCommand);
            commands.add(liftCommand);
            //提交到线程去工作
            LiftAssignCommand assignCommand = new LiftAssignCommand();