Junjie
2023-04-03 6ffc119998de63d0c6c6c356612b555a5da8ab4e
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -23,10 +23,7 @@
import com.zy.core.enums.*;
import com.zy.core.model.*;
import com.zy.core.model.command.*;
import com.zy.core.model.protocol.CrnProtocol;
import com.zy.core.model.protocol.ShuttleProtocol;
import com.zy.core.model.protocol.StaProtocol;
import com.zy.core.model.protocol.SteProtocol;
import com.zy.core.model.protocol.*;
import com.zy.core.properties.SlaveProperties;
import com.zy.core.thread.*;
import lombok.extern.slf4j.Slf4j;
@@ -673,9 +670,8 @@
                            //入出库模式
                            assignCommand.setTaskMode(ShuttleTaskModeType.PAK_IN.id.shortValue());
                            //源库位(小车当前位置)
                            Short currentCode = shuttleProtocol.getCurrentCode();
                            LocMast currentLocMast = locMastService.queryByQrCode(currentCode.toString());
                            assignCommand.setSourceLocNo(currentLocMast.getLocNo());
                            String currentLocNo = shuttleProtocol.getCurrentLocNo();
                            assignCommand.setSourceLocNo(currentLocNo);
                            if (wrkMast.getWrkSts() == 8 || Boolean.parseBoolean(searchIdleShuttle.get("sameLay").toString())) {
                                //同一层
@@ -688,7 +684,6 @@
                                //不同层,将目标库位分配成提升机库位号
                                //小车当前层高
                                String currentLocNo = currentLocMast.getLocNo();
                                Integer currentLev = Integer.parseInt(currentLocNo.substring(currentLocNo.length() - 2, currentLocNo.length()));
                                //获取提升机
@@ -736,9 +731,7 @@
                continue;
            }
            Short currentCode = shuttleProtocol.getCurrentCode();//四向穿梭车当前位置二维码
            LocMast shuttleLocMast = locMastService.queryByQrCode(currentCode.toString());//找到二维码对应的库位记录
            String shuttleLocNo = shuttleLocMast.getLocNo();//二维码对应库位号
            String shuttleLocNo = shuttleProtocol.getCurrentLocNo();//二维码对应库位号
            String shuttleLocNoLay = shuttleLocNo.substring(shuttleLocNo.length() - 2, shuttleLocNo.length());//库位号对应层高
            if (lay.equals(shuttleLocNoLay)) {
                //当前四向穿梭车和工作档任务在同一层,则调配该车辆
@@ -752,9 +745,7 @@
                recentShuttle = shuttleThread;
            }else {
                ShuttleProtocol recentShuttleProtocol = recentShuttle.getShuttleProtocol();//目前最近穿梭车
                Short recentShuttleCurrentCode = recentShuttleProtocol.getCurrentCode();//目前最近穿梭车位置二维码
                LocMast recentShuttleLocMast = locMastService.queryByQrCode(recentShuttleCurrentCode.toString());//找到二维码对应的库位记录
                String recentShuttleLocNo = recentShuttleLocMast.getLocNo();//二维码对应库位号
                String recentShuttleLocNo = recentShuttleProtocol.getCurrentLocNo();//二维码对应库位号
                String recentShuttleLocNoLay = recentShuttleLocNo.substring(recentShuttleLocNo.length() - 2, recentShuttleLocNo.length());//库位号对应层高
                int recentShuttleLocNoLayInt = Integer.parseInt(recentShuttleLocNoLay);
@@ -838,7 +829,9 @@
                        shuttleProtocol.setLocNo(null);
                        //标记复位
                        shuttleProtocol.setPakMk(true);
                        News.info("四向穿梭车已确认且任务完成状态,复位。堆垛机号={}", shuttleProtocol.getShuttleNo());
                        //任务指令清零
                        shuttleProtocol.setAssignCommand(null);
                        News.info("四向穿梭车已确认且任务完成状态,复位。四向穿梭车号={}", shuttleProtocol.getShuttleNo());
                    } else {
                        News.error("四向穿梭车已确认且任务完成状态,复位失败,但未找到工作档。四向穿梭车号={},工作号={}", shuttleProtocol.getShuttleNo(), shuttleProtocol.getTaskNo());
                    }
@@ -849,6 +842,152 @@
    }
    /**
     * 提升机任务
     */
    public synchronized void liftIoExecute() {
        for (LiftSlave liftSlave : slaveProperties.getLift()) {
            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, liftSlave.getId());
            if (liftThread == null) {
                continue;
            }
            LiftProtocol liftProtocol = liftThread.getLiftProtocol();
            if (liftProtocol == null) {
                continue;
            }
            //判断提升机是否处于空闲状态
            if (!liftProtocol.isIdle()) {
                continue;
            }
            //搜索是否有待处理的任务
            WrkMast wrkMast = wrkMastMapper.selectLiftStep6();
            if (wrkMast == null) {
                continue;
            }
            //给提升机分配任务
            liftProtocol.setLiftLock(true);//锁定提升机
            liftProtocol.setTaskNo(wrkMast.getWrkNo().shortValue());//设置任务号
            liftProtocol.setShuttleNo(wrkMast.getShuttleNo().shortValue());//设置四向穿梭车号
            liftProtocol.setProtocolStatus(LiftProtocolStatusType.WORKING);//设置提升机状态为工作中
            //找到四向穿梭车的线程
            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, liftProtocol.getShuttleNo().intValue());
            if (shuttleThread == null) {
                continue;
            }
            ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
            if (shuttleProtocol == null) {
                continue;
            }
            //命令list
            ArrayList<LiftCommand> commands = new ArrayList<>();
            //当前穿梭车库位号
            String currentLocNo = shuttleProtocol.getCurrentLocNo();
            //当前穿梭车楼层
            int currentLocNoLey = Integer.parseInt(currentLocNo.substring(currentLocNo.length() - 2, currentLocNo.length()));
            //工作档目标库位号
            String wrkMastLocNo = wrkMast.getLocNo();
            //工作档目标库位楼层
            int wrkMastLocNoLey = Integer.parseInt(wrkMastLocNo.substring(wrkMastLocNo.length() - 2, wrkMastLocNo.length()));
            //提升机当前楼层
            int liftLev = liftProtocol.getLev().intValue();
            if (liftLev != currentLocNoLey) {
                //不同楼层
                LiftCommand command1 = new LiftCommand();
                command1.setLiftNo(liftProtocol.getLiftNo());//提升机号
                command1.setTaskNo(liftProtocol.getTaskNo());//任务号
                command1.setRun((short) 1);//升降
                command1.setDistPosition((short) currentLocNoLey);//目标楼层(穿梭车所在楼层)
                command1.setLiftLock(true);//锁定提升机
                commands.add(command1);//将命令添加进list
            }
            //输送线将四向穿梭车移动进来
            LiftCommand command2 = new LiftCommand();
            command2.setLiftNo(liftProtocol.getLiftNo());//提升机号
            command2.setTaskNo(liftProtocol.getTaskNo());//任务号
            command2.setRun((short) 6);//输送线运作
            command2.setLiftLock(true);//锁定提升机
            commands.add(command2);//将命令添加进list
            //提升机搬运四向穿梭车
            LiftCommand command3 = new LiftCommand();
            command3.setLiftNo(liftProtocol.getLiftNo());//提升机号
            command3.setTaskNo(liftProtocol.getTaskNo());//任务号
            command3.setRun((short) 1);//升降
            command3.setDistPosition((short) wrkMastLocNoLey);//工作档目标楼层
            command3.setLiftLock(true);//锁定提升机
            commands.add(command3);//将命令添加进list
            //提升机到达指定楼层,输送线将四向穿梭车移出去
            //输送线将四向穿梭车移动进来
            LiftCommand command4 = new LiftCommand();
            command4.setLiftNo(liftProtocol.getLiftNo());//提升机号
            command4.setTaskNo(liftProtocol.getTaskNo());//任务号
            command4.setRun((short) 3);//输送线运作
            command4.setLiftLock(true);//锁定提升机
            commands.add(command4);//将命令添加进list
            wrkMast.setWrkSts(7L);//移动任务
            //所需命令组合完毕,更新数据库,提交到线程去工作
            LiftAssignCommand assignCommand = new LiftAssignCommand();
            assignCommand.setCommands(commands);
            assignCommand.setLiftNo(liftProtocol.getLiftNo());
            assignCommand.setTaskNo(liftProtocol.getTaskNo());
            if (wrkMastMapper.updateById(wrkMast) > 0) {
                //下发任务
                MessageQueue.offer(SlaveType.Lift, liftProtocol.getLiftNo().intValue(), new Task(3, assignCommand));
            }
        }
    }
    /**
     * 提升机任务完成
     */
    public synchronized void liftFinished() {
        for (LiftSlave liftSlave : slaveProperties.getLift()) {
            //获取提升机信息
            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, liftSlave.getId());
            LiftProtocol liftProtocol = liftThread.getLiftProtocol();
            if (liftProtocol == null) {
                continue;
            }
            //提升机为等待确认
            if (liftProtocol.getProtocolStatus() == LiftProtocolStatusType.WAITING.id && liftProtocol.getTaskNo() != 0) {
                //将任务档标记为完成
                WrkMast wrkMast = wrkMastMapper.selectByWorkNo7(liftProtocol.getTaskNo().intValue());
                if (wrkMast != null) {
                    wrkMast.setWrkSts(8L);
                    if (wrkMastMapper.updateById(wrkMast) > 0) {
                        //设置提升机为空闲状态
                        liftProtocol.setProtocolStatus(LiftProtocolStatusType.IDLE);
                        //任务号清零
                        liftProtocol.setTaskNo((short) 0);
                        //标记复位
                        liftProtocol.setPakMk(true);
                        //任务指令清零
                        liftProtocol.setAssignCommand(null);
                        News.info("提升机已确认且任务完成状态,复位。提升机号={}", liftProtocol.getLiftNo());
                    } else {
                        News.error("提升机已确认且任务完成状态,复位失败,但未找到工作档。提升机号={},工作号={}", liftProtocol.getLiftNo(), liftProtocol.getTaskNo());
                    }
                }
            }
        }
    }
    /**
     * 入出库  ===>>  堆垛机入出库作业下发
     */
    public synchronized void crnIoExecute(){