Junjie
2023-07-21 8c4a69845aefd4699a7e1f30fa6407763543b48a
库位移转WCS
4个文件已修改
254 ■■■■■ 已修改文件
src/main/java/com/zy/asrs/mapper/WrkMastMapper.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java 233 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/MainProcess.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/WrkMastMapper.xml 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/mapper/WrkMastMapper.java
@@ -60,4 +60,8 @@
    List<WrkMast> selectShuttleWrkByLev(String lev);
    WrkMast selectLiftWrkMast(Integer liftNo);
    List<WrkMast> selectInOutWrkMast();//查询出入库工作档
    List<WrkMast> selectLocToLocWrkMast();//查询库位移转工作档
}
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -1343,12 +1343,15 @@
        //判断其他空闲穿梭车是否离任务最近
        String distLocNo = null;//目标地点,入库=》提升机口,出库=》货物库位号
        if (wrkMast.getIoType() < 101) {
        if (wrkMast.getIoType() == 1) {
            //入库
            distLocNo = Utils.levToOutInStaLocNo(lev);
        }else {
        }else if(wrkMast.getIoType() == 101){
            //出库
            distLocNo = locNo;
        } else if (wrkMast.getIoType() == 11) {
            //库位移转
            distLocNo = wrkMast.getSourceLocNo();
        }
        //判断当前任务所在楼层是否有其他任务已经分配了小车,如有则直接用该小车(一层楼仅分配一台车)
@@ -2013,6 +2016,232 @@
    }
    /**
     * 库位移转
     */
    public synchronized void locToLocExecute() {
        //获取出入库工作档
        List<WrkMast> wrkMasts = wrkMastMapper.selectInOutWrkMast();
        if (wrkMasts.size() > 0) {
            //有出入库任务,必须等待任务执行完毕再执行库位移转
            return;
        }
        //查询库位移转工作档
        List<WrkMast> wrkMasts1 = wrkMastMapper.selectLocToLocWrkMast();
        for (WrkMast wrkMast : wrkMasts1) {
            boolean step1 = this.locToLocExecuteStep1(wrkMast);//绑定小车
            if (!step1) {
                continue;
            }
            boolean step2 = this.locToLocExecuteStep2(wrkMast);//调度小车到目标楼层
            if (!step2) {
                continue;
            }
            boolean step3 = this.locToLocExecuteStep3(wrkMast);//同楼层库位移转
            if (!step3) {
                continue;
            }
        }
    }
    /**
     * 绑定小车并调度车
     * 如需主方法执行continue,请返回false
     * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue
     */
    private boolean locToLocExecuteStep1(WrkMast wrkMast) {
        if (wrkMast.getShuttleNo() == null) {//给库位移转绑定穿梭车号
            //寻找最近且空闲的四向穿梭车
            HashMap<String,Object> searchIdleShuttle = this.searchIdleShuttle(wrkMast);
            ShuttleThread shuttleThread = (ShuttleThread) searchIdleShuttle.get("result");
            if (shuttleThread == null) {
                //没有找到空闲穿梭车
                return false;
            }
            wrkMast.setShuttleNo(shuttleThread.getSlave().getId());//给工作档分配四向穿梭车号
            wrkMastMapper.updateById(wrkMast);
        }
        return true;
    }
    /**
     * 调度小车到目标楼层
     * 如需主方法执行continue,请返回false
     * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue
     */
    private boolean locToLocExecuteStep2(WrkMast wrkMast) {
        if (wrkMast.getWrkSts() == 1 && wrkMast.getShuttleNo() != null) {
            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
            ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
            if (!shuttleProtocol.isIdle(wrkMast.getWrkNo().shortValue())) {
                return false;//小车处于不空闲状态
            }
            String currentLocNo = shuttleProtocol.getCurrentLocNo();//小车当前库位号
            int shuttleLev = Utils.getLev(currentLocNo);//小车所在楼层
            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, 1);
            LiftProtocol liftProtocol = liftThread.getLiftProtocol();
            //判断小车是否再目标楼层
            if (shuttleLev != Utils.getLev(wrkMast.getLocNo())) {
                //小车和目标不在同一楼层
                //提升机口站点库位号
                String liftSiteLocNo = Utils.levToOutInStaLocNo(shuttleLev);
                //创建分配命令
                ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
                assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());//四向穿梭车号
                assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());//任务号
                assignCommand.setTaskMode(ShuttleTaskModeType.PAK_IN.id.shortValue());//入出库模式
                assignCommand.setSourceLocNo(currentLocNo);//源库位(小车当前位置)
                //小车移动到提升机口,计算路径
                List<ShuttleCommand> commands = this.shuttleAssignCommand(shuttleProtocol.getLocNo(), liftSiteLocNo, NavigationMapType.NONE.id, assignCommand, shuttleThread);
                if (commands == null) {
                    return false;//未找到路径
                }
                //获取当前小车所在楼层的站点信息
                BasDevp basDevp = basDevpService.queryByLocNo(liftSiteLocNo);
                Short endStartCode = Short.parseShort(basDevp.getQrCodeValue());//站点二维码
                //增加移动进提升机命令
                ShuttleCommand moveCommand = shuttleThread.getMoveCommand(endStartCode, liftProtocol.getBarcode(), 1600, ShuttleRunDirection.TOP.id, null, null, 500);
                commands.add(moveCommand);
                //分配目标库位
                shuttleProtocol.setLocNo(liftSiteLocNo);
                //目标库位
                assignCommand.setLocNo(liftSiteLocNo);
                assignCommand.setCommands(commands);
                wrkMast.setWrkSts(5L);//小车迁移状态
                if (wrkMastMapper.updateById(wrkMast) > 0) {
                    //下发任务
                    MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
                }
            }
        }
        return true;
    }
    /**
     * 同楼层库位移转
     * 如需主方法执行continue,请返回false
     * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue
     */
    private boolean locToLocExecuteStep3(WrkMast wrkMast) {
        if (wrkMast.getShuttleNo() == null) {
            return false;
        }
        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
        ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
        if (!shuttleProtocol.isIdle(wrkMast.getWrkNo().shortValue())) {
            return false;//小车处于不空闲状态
        }
        LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, 1);
        LiftProtocol liftProtocol = liftThread.getLiftProtocol();
        DevpThread devpThread = null;
        for (DevpSlave devp : slaveProperties.getDevp()){
            // 获取入库站信息
            devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
        }
        //判断小车是否在工作档任务目标楼层
        String currentLocNo = shuttleProtocol.getCurrentLocNo();//小车当前库位号
        int shuttleLev = Utils.getLev(currentLocNo);//小车所在楼层
        if (shuttleLev != Utils.getLev(wrkMast.getLocNo())) {
            return false;//不在同一楼层
        }
        if (wrkMast.getWrkSts() == 1 || wrkMast.getWrkSts() == 8) {
            //调度小车执行同楼层移库任务
            //创建分配命令
            ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
            assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());//四向穿梭车号
            assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());//任务号
            assignCommand.setTaskMode(ShuttleTaskModeType.PAK_IN.id.shortValue());//入出库模式
            assignCommand.setSourceLocNo(currentLocNo);//源库位(小车当前位置)
            List<ShuttleCommand> commands = new ArrayList<>();
            if (wrkMast.getWrkSts() == 8) {//8.提升机迁移小车完成,需要将小车移出提升机
                //判断提升机是否空闲
                if (!liftProtocol.isIdleNoTask()) {
                    return false;//提升机忙
                }
                //判断提升机任务号和当前工作档任务号是否一致
                if (liftProtocol.getTaskNo().intValue() != 0 && liftProtocol.getTaskNo().intValue() != wrkMast.getWrkNo()) {
                    return false;
                }
                //判断提升机楼层是否到位,判断站点是否给出提升机到位信号
                String locNo = wrkMast.getLocNo();
                int lev = Utils.getLev(locNo);//目标二维码所在楼层
                int liftLev = liftProtocol.getLev().intValue();//提升机所在楼层
                if (liftLev != lev) {
                    return false;//提升机不在目标楼层跳过
                }
                Integer staNo = Utils.levToOutInStaNo(lev >= 2 ? lev + 1 : lev);
                //获取目标站信息
                StaProtocol staProtocol1 = devpThread.getStation().get(staNo);
                if (staProtocol1 == null) {
                    return false;//站点信息不存在
                }
                if (!staProtocol1.isLiftArrival()) {
                    return false;//站点提升机到位信号false
                }
                BasDevp basDevp = basDevpService.selectById(staNo);
                short startCode = liftProtocol.getBarcode();//提升机内部二维码
                Short distCode = Short.parseShort(basDevp.getQrCodeValue());//提升机口站点二维码
                Short runDirection = ShuttleRunDirection.BOTTOM.id;//运行方向
                //获取命令
                ShuttleCommand moveCommand = shuttleThread.getMoveCommand(startCode, distCode, 1600, runDirection, null, null, 500);
                commands.add(0, moveCommand);//将该指令添加到队头
                currentLocNo = basDevp.getLocNo();//使用输送站点口作为起点坐标
            }
            //直接计算车到源库位到目标库位路径
            List<ShuttleCommand> commands1 = this.shuttleAssignCommand(currentLocNo, wrkMast.getSourceLocNo(), wrkMast.getLocNo(), assignCommand, shuttleThread);
            if (commands1 == null) {
                return false;//找不到路径等待下一次
            }
            commands.addAll(commands1);
            //分配任务号
            shuttleProtocol.setTaskNo(wrkMast.getWrkNo().shortValue());
            //分配源库位
            shuttleProtocol.setSourceLocNo(wrkMast.getSourceLocNo());
            assignCommand.setCommands(commands);
            //分配目标库位
            shuttleProtocol.setLocNo(wrkMast.getLocNo());
            //目标库位
            assignCommand.setLocNo(wrkMast.getLocNo());
            wrkMast.setWrkSts(9L);//小车入库中
            if (wrkMastMapper.updateById(wrkMast) > 0) {
                //下发任务
                MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
            }
        }
        return true;
    }
    /**
     * 异常信息记录
     */
    public void recErr() {
src/main/java/com/zy/core/MainProcess.java
@@ -65,6 +65,8 @@
                    mainService.liftIoExecute();
                    //提升机任务完成
                    mainService.liftFinished();
                    //库位移转
                    mainService.locToLocExecute();
                    // 异常信息记录
                    mainService.recErr();
                    // 入库  ===>> 空栈板初始化入库,叉车入库站放货
src/main/resources/mapper/WrkMastMapper.xml
@@ -163,4 +163,19 @@
        select top 1 * from asr_wrk_mast
        where lift_no = #{liftNo}
    </select>
    <select id="selectInOutWrkMast" resultMap="BaseResultMap">
        select * from asr_wrk_mast
        where io_type in (1,101)
        and wrk_sts not in (14,15,34,35)
        order by io_pri desc,wrk_sts desc
    </select>
    <select id="selectLocToLocWrkMast" resultMap="BaseResultMap">
        select * from asr_wrk_mast
        where io_type in (11)
        and wrk_sts not in (14,15,34,35)
        order by io_pri desc,wrk_sts desc
    </select>
</mapper>