#
Junjie
3 天以前 6cf4a3e2ba925e75b60f13bb8ebc5e92d37809b2
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -87,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));
@@ -196,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;
@@ -334,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));
@@ -393,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;
@@ -429,99 +429,6 @@
            return false;
        }
        return true;
    }
    /**
     * 四向穿梭车任务完成
     */
    public synchronized void shuttleFinished() {
        try {
            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, device.getDeviceNo());
                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();
        }
    }
    /**
@@ -601,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;
@@ -762,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();
@@ -890,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();
@@ -924,6 +831,9 @@
            for (DeviceConfig device : forkliftList) {
                //获取提升机信息
                ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, device.getDeviceNo());
                if(forkLiftThread == null) {
                    continue;
                }
                ForkLiftProtocol forkLiftProtocol = forkLiftThread.getStatus();
                if (forkLiftProtocol == null) {
                    continue;
@@ -1298,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());
@@ -1582,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;
@@ -1598,7 +1508,7 @@
            }
            //获取小车到近点行走命令
            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;//路径解锁失败
@@ -1713,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;//路径解锁失败
@@ -1775,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();
@@ -1897,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;//路径计算失败
@@ -1919,73 +1829,73 @@
    //自动切换出入库模式
    public void autoSwitchForkLiftIOMode() {
        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);
                }
            }
        }
//        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);
//                }
//            }
//        }
    }
    //出库任务预调度提升机
@@ -2056,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();