pang.jiabao
2025-09-17 77ee4fbf68b83bf2ff0577d6751bbfbe85312f9f
堆垛机空闲10秒有入库任务回原点,空闲两分钟回原点
2个文件已修改
66 ■■■■■ 已修改文件
src/main/java/com/zy/core/MainProcess.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/service/impl/MainServiceImpl.java 63 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/MainProcess.java
@@ -72,6 +72,9 @@
                    mainService.outOfDevp(11);
                    // 堆垛机回原点
                    mainService.originGo();
                } catch (Exception e) {
                    e.printStackTrace();
                }
src/main/java/com/zy/service/impl/MainServiceImpl.java
@@ -1594,4 +1594,67 @@
//        News.infoNoLog(""+mark+" - 0"+" - outOfDevp执行完成");
    }
    /**
     * 堆垛机回原点
     */
    public synchronized void originGo() throws InterruptedException {
        for (CrnSlave crn : slaveProperties.getCrn()) {
            // 获取堆垛机信息
            CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId());
            CrnProtocol crnProtocol = crnThread.getCrnProtocol();
            if(crnProtocol == null) {
                continue;
            }
            if (crnProtocol.getStatusType() == CrnStatusType.IDLE && crnProtocol.getTaskNo() == 0 && crnProtocol.getModeType() == CrnModeType.AUTO
                    && crnProtocol.getLoaded() == 0 && crnProtocol.getForkPos() == 0) {
                // 判断是不是已在原点
                if(crnProtocol.getBay() == 0 && crnProtocol.getLevel() == 1) {
                    continue;
                }
                // 判断是不是空闲三分钟
                BasCrnp basCrnp = basCrnpService.selectById(crn.getId());
                if (basCrnp.getWrkNo() != 0) {
                    continue;
                }
                Date now = new Date();
                Date modiTime = basCrnp.getModiTime();
                long diffInMillis = now.getTime()-modiTime.getTime();
                if(diffInMillis < 10 * 1000) { // 空闲小于10秒则跳过
                    continue;
                } else {  // 有入库任务或大于2分钟,回原点
                    int count = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("io_type", 1).eq("crn_no", crn.getId()).in("wrk_sts", 2, 9, 10));
                    if(count == 0 && diffInMillis < 2 * 60 * 1000) {
                        continue;
                    }
                }
                // 有吊车入库或吊车出库任务
                int count = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("crn_no", crnProtocol.getCrnNo()).in("wrk_sts", 3, 12));
                if(count != 0) {
                    continue;
                }
                CrnCommand crnCommand = new CrnCommand();
                crnCommand.setCrnNo(crn.getId()); // 堆垛机编号
                crnCommand.setTaskNo((short) 9999); // 工作号
                crnCommand.setTaskMode(CrnTaskModeType.GO_ORIGIN); // 任务模式:  回原点
                crnCommand.setSourcePosX((short) (crn.getId() == 1 ? 4 : crn.getId() == 2 ? 6 : crn.getId() == 3 ? 7 : 11));     // 源库位排
                crnCommand.setSourcePosY((short) 0);     // 源库位列
                crnCommand.setSourcePosZ((short) 1);     // 源库位层
                crnCommand.setDestinationPosX((short) 0);     // 目标库位排
                crnCommand.setDestinationPosY((short) 0);     // 目标库位列
                crnCommand.setDestinationPosZ((short) 0);     // 目标库位层
                if (!MessageQueue.offer(SlaveType.Crn, crn.getId(), new Task(2, crnCommand))) {
                    News.error("回原点任务下发失败", crn.getId(), JSON.toJSON(crnCommand));
                } else {
                    basCrnp.setModiTime(new Date());
                    basCrnpService.updateById(basCrnp); // 设置更新时间,避免重复下发回原点
                    log.info("{}号堆垛机回原点任务下发成功:{}", crn.getId(), JSON.toJSON(crnCommand));
                }
                Thread.sleep(3000);
            }
        }
    }
}