#
ytfl
2025-07-18 ed66b0b468efc3f1f51c68712d82e234c7bba2bf
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -462,6 +462,7 @@
                        wrkMast.setLocNo(wrkMast.getSourceLocNo()); // 目标库位 = 出库时的源库位
                        wrkMast.setSourceLocNo(""); // 源库位清空
                        wrkMast.setModiTime(now);
                        wrkMast.setUpdMk("");//允许再次移库
                        if (wrkMastMapper.updateById(wrkMast) == 0) {
                            throw new CoolException("更新工作档数据状态失败");
                        }
@@ -643,6 +644,10 @@
     */
    public synchronized void crnMove() {
        for (CrnSlave crn : slaveProperties.getCrn()) {
            if (crn.getId() == 1) {
                continue;
            }
            // 获取堆垛机信息
            CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId());
            CrnProtocol crnProtocol = crnThread.getCrnProtocol();
@@ -661,6 +666,78 @@
                }
                if (System.currentTimeMillis() - crnProtocol.getLastCommandTime() < 1000 * 60 * 2) {
                    continue;
                }
                Object object = redisUtil.get(RedisConstantType.CRN_MOVE_LOCK);
                if (object != null) {
                    continue;
                }
                List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>()
                        .eq("crn_no", crn.getId())
                        .eq("wrk_sts", 2)
                );
                if (!wrkMasts.isEmpty()) {
                    continue;
                }
                CrnSlave.CrnStn crnStn = crn.getCrnInStn().get(0);
                News.info("堆垛机无任务自动回入库口待机==>>" + crnProtocol.getCrnNo() + "号堆垛机");
                // 命令下发区 --------------------------------------------------------------------------
                CrnCommand crnCommand = new CrnCommand();
                crnCommand.setCrnNo(crnProtocol.getCrnNo()); // 堆垛机编号
                crnCommand.setTaskNo((short) 9999); // 工作号
                crnCommand.setAckFinish((short) 0);  // 任务完成确认位
                crnCommand.setTaskMode(CrnTaskModeType.CRN_MOVE); // 任务模式:  堆垛机移动
                crnCommand.setSourcePosX(crnStn.getRow().shortValue());     // 源库位排
                crnCommand.setSourcePosY((short) 1);     // 源库位列
                crnCommand.setSourcePosZ((short) 1);     // 源库位层
                crnCommand.setDestinationPosX((short) 0);     // 目标库位排
                crnCommand.setDestinationPosY((short) 0);     // 目标库位列
                crnCommand.setDestinationPosZ((short) 0);     // 目标库位层
                if (!MessageQueue.offer(SlaveType.Crn, crnProtocol.getCrnNo(), new Task(2, crnCommand))) {
                    News.error("堆垛机移动命令下发失败,堆垛机号={},任务数据={}", crnProtocol.getCrnNo(), JSON.toJSON(crnCommand));
                }
                crnThread.setBackHpFlag(true);
                redisUtil.set(RedisConstantType.CRN_MOVE_LOCK + crn.getId(), "lock", 60);
                try {
                    Thread.sleep(500);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
    /**
     * 堆垛机有入库任务时,回入库口待机
     */
    public synchronized void crnMoveByInTask() {
        for (CrnSlave crn : slaveProperties.getCrn()) {
            if (crn.getId() == 1) {
                continue;
            }
            // 获取堆垛机信息
            CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId());
            CrnProtocol crnProtocol = crnThread.getCrnProtocol();
            if (crnProtocol == null) {
                continue;
            }
            BasCrnp basCrnp = basCrnpService.selectById(crn.getId());
            if (basCrnp == null) {
                log.error("{}号堆垛机尚未在数据库进行维护!", crn.getId());
                continue;
            }
            if (crnProtocol.getStatusType() == CrnStatusType.IDLE && crnProtocol.getTaskNo() == 0 && crnProtocol.getModeType() == CrnModeType.AUTO) {
                if (crnProtocol.getBay() == 1 && crnProtocol.getLevel() == 1) {
                    continue;
                }
                if (System.currentTimeMillis() - crnProtocol.getLastCommandTime() < 1000 * 60) {
                    continue;
                }
@@ -791,12 +868,14 @@
                    if (null == waitWrkMast) {
                        News.error(""+mark+" - 1"+" - 10"+" - {}库位异常,未检索到相应工作档!", shallowLocNo);
                    } else {
                        waitWrkMast.setIoPri(15D);
                        waitWrkMast.setModiTime(new Date());
                        if (wrkMastMapper.updateById(waitWrkMast) == 0) {
                            News.error(""+mark+" - 1"+" - 11"+" - 调整工作档优先级失败!工作号={}", waitWrkMast.getWrkNo());
                        if (waitWrkMast.getWrkSts() != 14 && waitWrkMast.getIoType() > 100) {
                            waitWrkMast.setIoPri(15D);
                            waitWrkMast.setModiTime(new Date());
                            if (wrkMastMapper.updateById(waitWrkMast) == 0) {
                                News.error(""+mark+" - 1"+" - 11"+" - 调整工作档优先级失败!工作号={}", waitWrkMast.getWrkNo());
                            }
                            continue;
                        }
                        continue;
                    }
                } else if (shallowLoc.getLocSts().equals("F") || shallowLoc.getLocSts().equals("D")) {
@@ -962,7 +1041,7 @@
                    if (crnProtocol.getCrnNo() == 1) {
                        //判断堆垛机和当前任务是否处于一个巷道
                        if (Utils.getLaneByLocNo(wrkMast.getLocNo()) != crnProtocol.getCrnLane()) {
                        if (Utils.getLaneByLocNo(wrkMast.getSourceLocNo()) != crnProtocol.getCrnLane()) {
                            //判断堆垛机所在巷道是否存在其他任务,如存在则优先执行
                            List<WrkMast> currentWrkMasts = wrkMastService.selectLaneWrkMast(crnProtocol.getCrnLane(), false);
                            if (!currentWrkMasts.isEmpty()) {
@@ -2206,13 +2285,16 @@
        ArrayList<Integer> list = new ArrayList<Integer>(){{add(2003);add(2002);}};
        for (Integer staNo : list) {
            Integer devpId = null;
            Integer rgvStaNoDevpId = null;
            Integer rgvStaNo = null;
            if (staNo == 2003) {
                devpId = 1;
                rgvStaNo = 2002;
                rgvStaNoDevpId = 2;
            }else {
                devpId = 2;
                rgvStaNo = 2003;
                rgvStaNoDevpId = 1;
            }
            SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devpId);
@@ -2242,6 +2324,43 @@
                    continue;
                }
                SiemensDevpThread devpThread2 = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, rgvStaNoDevpId);
                if (devpThread2 == null) {
                    continue;
                }
                StaProtocol staProtocolRgvStaNo = devpThread2.getStation().get(rgvStaNo);
                if (staProtocolRgvStaNo == null) {
                    continue;
                }
                if (!staProtocolRgvStaNo.isAutoing()) {
                    continue;
                }
                if (staProtocolRgvStaNo.isLoading()) {
                    continue;
                }
                // 获取RGV信息
                RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, 1);
                if (rgvThread == null) {
                    continue;
                }
                RgvProtocol rgvProtocol = rgvThread.getRgvProtocol();
                if (rgvProtocol == null) {
                    continue;
                }
                if (rgvProtocol.statusType1 != RgvStatusType.IDLE && rgvProtocol.getTaskNo1() != 0) {
                    continue;
                }
                Object object = redisUtil.get(RedisConstantType.RGV_MOVE_LOCK + wrkMast.getWrkNo());
                if (object != null) {
                    continue;
                }
                RgvCommand command = new RgvCommand();
                command.setRgvNo(1); // RGV编号
                command.setAckFinish1((short) 0);  // 任务完成确认位
@@ -2259,6 +2378,7 @@
                wrkMast.setWrkSts(201L);//201.RGV搬运中
                wrkMast.setModiTime(new Date());
                wrkMastService.updateById(wrkMast);
                redisUtil.set(RedisConstantType.RGV_MOVE_LOCK + wrkMast.getWrkNo(), "lock", 60 * 60);
            }
        }
    }
@@ -2287,6 +2407,10 @@
                    continue;
                }
                if (wrkMast.getWrkSts() != 201) {
                    continue;
                }
                Integer devpId = null;
                Integer devpStaNo = null;
                String locNo = null;