#
Junjie
2023-10-12 a71d0a6a0d5e31f0e93feaf0444d93bc603fdd90
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -698,38 +698,6 @@
                continue;
            }
        }
        // 根据输送线plc遍历
        for (DevpSlave devp : slaveProperties.getDevp()) {
            // 遍历入库站
            for (DevpSlave.StaRack staRack : devp.getRackInStn()) {
                // 获取入库站信息
                DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                StaProtocol staProtocol = devpThread.getStation().get(staRack.getStaNo());
                if (staProtocol == null) {
                    continue;
                } else {
                    staProtocol = staProtocol.clone();
                }
                Short workNo = staProtocol.getWorkNo();
                BasDevp basDevp = basDevpService.selectById(staProtocol.getSiteId());
                if (basDevp == null) {
                    continue;//站点信息不存在
                }
                // 判断是否满足入库条件,自动、有物、四向穿梭车可取信号
                if (!(staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isShuttleTakeEnable())) {
                    continue;
                }
            }
        }
    }
//    /**
@@ -1176,6 +1144,12 @@
            //获取提升机命令
            NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_TRAY.id, startSta, targetSta, wrkMast.getWrkNo());
            if (wrkMast.getIoType() == 53) {
                //拣料再回库,重新分配设备工作号
                Random random = new Random();
                int deviceWrk = Math.abs((liftCommand.getTaskNo().intValue() + random.nextInt(9999)));//获取设备工作号
                liftCommand.setTaskNo((short) deviceWrk);
            }
            ArrayList<NyLiftCommand> commands = new ArrayList<>();
            commands.add(liftCommand);
@@ -1216,10 +1190,14 @@
                return false;
            }
            //调度小车避让
            boolean result = Utils.searchEmptyGroupToMoveShuttle(Utils.getLev(wrkMast.getSourceLocNo()), wrkMast.getShuttleNo(), shuttleThread);
            if (!result) {
                return false;
            NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
            if (shuttleProtocol.getCurrentLocNo().equals(wrkMast.getSourceLocNo())) {
                //小车还在输送站点
                //调度小车避让
                boolean result = Utils.searchEmptyGroupToMoveShuttle(Utils.getLev(wrkMast.getSourceLocNo()), wrkMast.getShuttleNo(), shuttleThread);
                if (!result) {
                    return false;
                }
            }
            //获取出库站点(目标站)
@@ -1403,7 +1381,7 @@
                    continue;
                }
                boolean step4 = this.locToLocExecuteStep4(wrkMast);//调度车辆取货并运送到出库口
                boolean step4 = this.locToLocExecuteStep4(wrkMast);//调度车辆取货并运送到目标库位
                if (!step4) {
                    continue;
                }
@@ -2027,6 +2005,7 @@
                    if (wrkMast.getStaNo() != 303 && wrkMast.getStaNo() != 317) {
                        //覆盖工作档目标站
                        wrkMast.setStaNo(targetSta.intValue());
                        wrkMast.setShuttleNo(null);//释放小车
                        if (wrkMastMapper.updateById(wrkMast) > 0) {
                            //向300站写入目标站
                            staProtocol = staProtocol.clone();
@@ -2047,30 +2026,82 @@
            StaProtocol staProtocol317 = devpThread.getStation().get(317);
            if (staProtocol303.isAutoing() && staProtocol303.isLoading() && staProtocol303.getWorkNo() != 0) {
                //调度机械臂
//                //查询是否有工作档
//                WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol303.getWorkNo().intValue());
//                if (wrkMast == null) {
//                    continue;
//                }
//                WrkDetl wrkDetl = wrkDetlService.selectById(wrkMast.getWrkNo());
//                if (wrkDetl == null) {
//                    continue;
//                }
//                RobotUtils.sendTask(staProtocol303.getWorkNo().toString(), wrkDetl.getAnfme().intValue(), "303");
                RobotUtils.sendTask(staProtocol303.getWorkNo().toString(), -1, "303");
                //查询是否有工作档
                WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol303.getWorkNo().intValue());
                if (wrkMast == null) {
                    continue;
                }
                List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(wrkMast.getWrkNo());
                if (wrkDetls.isEmpty()) {
                    continue;
                }
                if (wrkMast.getInvWh() == null) {
                    wrkMast.setInvWh("Y");//标记已经下发机械臂任务
                    if (wrkMastMapper.updateById(wrkMast) > 0) {
                        RobotUtils.sendTask(staProtocol303.getWorkNo().toString(), wrkDetls.size(), "303");
                    }
                }
            }else if (staProtocol317.isAutoing() && staProtocol317.isLoading() && staProtocol317.getWorkNo() != 0) {
                //调度机械臂
//                //查询是否有工作档
//                WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol317.getWorkNo().intValue());
//                if (wrkMast == null) {
//                    continue;
//                }
//                WrkDetl wrkDetl = wrkDetlService.selectById(wrkMast.getWrkNo());
//                if (wrkDetl == null) {
//                    continue;
//                }
//                RobotUtils.sendTask(staProtocol303.getWorkNo().toString(), wrkDetl.getAnfme().intValue(), "317");
                RobotUtils.sendTask(staProtocol303.getWorkNo().toString(), -1, "317");
                //查询是否有工作档
                WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol317.getWorkNo().intValue());
                if (wrkMast == null) {
                    continue;
                }
                List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(wrkMast.getWrkNo());
                if (wrkDetls.isEmpty()) {
                    continue;
                }
                if (wrkMast.getInvWh() == null) {
                    wrkMast.setInvWh("Y");//标记已经下发机械臂任务
                    if (wrkMastMapper.updateById(wrkMast) > 0) {
                        RobotUtils.sendTask(staProtocol303.getWorkNo().toString(), wrkDetls.size(), "317");
                    }
                }
            }
        }
    }
    // 300站拣料
    public void pick300() {
        //检测300站是否自动、有物、工作号
        for (DevpSlave devp : slaveProperties.getDevp()) {
            // 获取入库站信息
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
            StaProtocol staProtocol = devpThread.getStation().get(300);
            if (staProtocol == null) {
                continue;
            }
            if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.getWorkNo() != 0) {
                //查询是否有工作档
                WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol.getWorkNo().intValue());
                if (wrkMast == null) {
                    continue;
                }
                if (wrkMast.getWrkSts() != 25) {//25.提升机搬运完成
                    continue;
                }
                if (wrkMast.getMk() == null) {
                    Integer sourceStaNo = wrkMast.getSourceStaNo();//源站
                    Integer staNo = wrkMast.getStaNo();//目标站
                    //覆盖工作档目标站
                    wrkMast.setStaNo(sourceStaNo);
                    wrkMast.setSourceStaNo(staNo);
                    if (wrkMastMapper.updateById(wrkMast) > 0) {
                        //向300站写入目标站
                        staProtocol = staProtocol.clone();
                        staProtocol.setStaNo(wrkMast.getStaNo().shortValue());//移动到目标站
                        boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                        try {
                            Thread.sleep(500);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }
@@ -2626,7 +2657,8 @@
                NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_CAR.id, sourceLiftSta.getStaNo(), sourceLiftSta.getStaNo(), wrkMast.getWrkNo());
                Random random = new Random();
                liftCommand.setTaskNo((short) Math.abs((liftCommand.getTaskNo().intValue() + random.nextInt(9999))));//更换随机任务号
                int deviceWrk = Math.abs((liftCommand.getTaskNo().intValue() + random.nextInt(9999)));//获取设备工作号
                liftCommand.setTaskNo((short) deviceWrk);//更换随机任务号
                ArrayList<NyLiftCommand> commands = new ArrayList<>();
                commands.add(liftCommand);
@@ -2948,6 +2980,30 @@
//            NavigateNode liftNode = new NavigateNode(basLift.getPoint$().getX(), basLift.getPoint$().getY());
//            liftNode.setZ(basLift.getPoint$().getZ());
            //小车已经在目标库位,直接认定小车移动任务完成
            if (shuttleProtocol.getCurrentLocNo().equals(wrkMast.getLocNo())) {
                if (shuttleProtocol.getToken().equals(wrkMast.getWrkNo())) {
                    //释放小车令牌
                    shuttleProtocol.setToken(0);
                }
                wrkMast.setWrkSts(111L);//111.小车移动完成
                wrkMast.setLiftNo(null);//释放提升机
                wrkMast.setModiTime(now);
                wrkMastMapper.updateById(wrkMast);
                if (wrkMast.getWrkSts() == 111) {
                    // 保存工作主档历史档
                    if (wrkMastLocMapper.save(wrkMast.getWrkNo()) <= 0) {
                        log.info("保存工作历史档[workNo={0}]失败", wrkMast.getWrkNo());
                    }
                    // 删除工作主档
                    if (!wrkMastService.deleteById(wrkMast)) {
                        log.info("删除工作主档[workNo={0}]失败", wrkMast.getWrkNo());
                    }
                }
                return false;
            }
            //获取小车到目标库位命令
            NyShuttleOperaResult result = NyShuttleOperaUtils.getStartToTargetCommands(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), wrkMast.getLocNo(), NavigationMapType.NORMAL.id);
            if (result == null) {