#
Junjie
21 小时以前 205cb40876114827a2134c29fde159e063e81454
#
4个文件已修改
223 ■■■■ 已修改文件
src/main/java/com/zy/core/thread/impl/ZyStationV3Thread.java 48 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/thread/impl/ZyStationV4Thread.java 60 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/thread/impl/v5/StationV5SegmentExecutor.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/utils/StationOperateProcessUtils.java 104 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/thread/impl/ZyStationV3Thread.java
@@ -339,7 +339,9 @@
            segCmd.setCommandType(original.getCommandType());
            segCmd.setPalletSize(original.getPalletSize());
            segCmd.setNavigatePath(new ArrayList<>(path.subList(0, currentEndIdx + 1)));
            sendCommand(segCmd);
            if (!sendSegmentWithRetry(segCmd, original.getTaskNo())) {
                return;
            }
            long runTime = System.currentTimeMillis();
            boolean firstRun = true;
@@ -390,18 +392,8 @@
                        nextCmd.setPalletSize(original.getPalletSize());
                        nextCmd.setNavigatePath(new ArrayList<>(path.subList(currentStartIdx, currentEndIdx + 1)));
                        nextCmd.setOriginalNavigatePath(path);
                        while (true) {
                            CommandResponse commandResponse = sendCommand(nextCmd);
                            if (commandResponse == null) {
                                Thread.sleep(200);
                                continue;
                            }
                            if (commandResponse.getResult()) {
                        if (!sendSegmentWithRetry(nextCmd, original.getTaskNo())) {
                                break;
                            }
                            Thread.sleep(200);
                        }
                    }
                    Thread.sleep(500);
@@ -443,4 +435,36 @@
        }
        return null;
    }
    private boolean sendSegmentWithRetry(StationCommand command, Integer taskNo) {
        while (true) {
            if (isTaskMoveReset(taskNo)) {
                return false;
            }
            CommandResponse commandResponse = sendCommand(command);
            if (commandResponse == null) {
                sleepQuietly(200L);
                continue;
            }
            if (commandResponse.getResult()) {
                return true;
            }
            sleepQuietly(200L);
        }
    }
    private boolean isTaskMoveReset(Integer taskNo) {
        if (taskNo == null || redisUtil == null) {
            return false;
        }
        Object cancel = redisUtil.get(RedisKeyType.DEVICE_STATION_MOVE_RESET.key + taskNo);
        return cancel != null;
    }
    private void sleepQuietly(long millis) {
        try {
            Thread.sleep(millis);
        } catch (Exception ignore) {
        }
    }
}
src/main/java/com/zy/core/thread/impl/ZyStationV4Thread.java
@@ -383,20 +383,8 @@
            }
            int segCursor = 0;
            while (true) {
                CommandResponse commandResponse = sendCommand(segmentCommands.get(segCursor));
                if (commandResponse == null) {
                    try {
                        Thread.sleep(200);
                    } catch (Exception ignore) {}
                    continue;
                }
                if (commandResponse.getResult()) {
                    break;
                }
                try {
                    Thread.sleep(200);
                } catch (Exception ignore) {}
            if (!sendSegmentWithRetry(segmentCommands.get(segCursor), original.getTaskNo())) {
                return;
            }
            long runTime = System.currentTimeMillis();
@@ -437,18 +425,8 @@
                    int thresholdSegment = (int) Math.ceil(segLen * segmentAdvanceRatio);
                    if (remainingSegment <= thresholdSegment && segCursor < segmentCommands.size() - 1) {
                        segCursor++;
                        while (true) {
                            CommandResponse commandResponse = sendCommand(segmentCommands.get(segCursor));
                            if (commandResponse == null) {
                                Thread.sleep(200);
                                continue;
                            }
                            if (commandResponse.getResult()) {
                        if (!sendSegmentWithRetry(segmentCommands.get(segCursor), original.getTaskNo())) {
                                break;
                            }
                            Thread.sleep(200);
                        }
                    }
                    Thread.sleep(500);
@@ -535,4 +513,36 @@
        }
        return null;
    }
    private boolean sendSegmentWithRetry(StationCommand command, Integer taskNo) {
        while (true) {
            if (isTaskMoveReset(taskNo)) {
                return false;
            }
            CommandResponse commandResponse = sendCommand(command);
            if (commandResponse == null) {
                sleepQuietly(200L);
                continue;
            }
            if (commandResponse.getResult()) {
                return true;
            }
            sleepQuietly(200L);
        }
    }
    private boolean isTaskMoveReset(Integer taskNo) {
        if (taskNo == null || redisUtil == null) {
            return false;
        }
        Object cancel = redisUtil.get(RedisKeyType.DEVICE_STATION_MOVE_RESET.key + taskNo);
        return cancel != null;
    }
    private void sleepQuietly(long millis) {
        try {
            Thread.sleep(millis);
        } catch (Exception ignore) {
        }
    }
}
src/main/java/com/zy/core/thread/impl/v5/StationV5SegmentExecutor.java
@@ -167,6 +167,9 @@
    private boolean sendSegmentWithRetry(StationCommand command) {
        while (true) {
            if (isTaskMoveReset(command == null ? null : command.getTaskNo())) {
                return false;
            }
            CommandResponse commandResponse = commandSender.apply(command);
            if (commandResponse == null) {
                sleepQuietly(200L);
@@ -179,6 +182,14 @@
        }
    }
    private boolean isTaskMoveReset(Integer taskNo) {
        if (taskNo == null || redisUtil == null) {
            return false;
        }
        Object cancel = redisUtil.get(RedisKeyType.DEVICE_STATION_MOVE_RESET.key + taskNo);
        return cancel != null;
    }
    private double loadSegmentAdvanceRatio() {
        try {
            ConfigService configService = SpringUtils.getBean(ConfigService.class);
src/main/java/com/zy/core/utils/StationOperateProcessUtils.java
@@ -40,6 +40,8 @@
    private static final int STATION_IDLE_RECOVER_SECONDS = 10;
    private static final int STATION_IDLE_RECOVER_LIMIT_SECONDS = 10;
    private static final int STATION_IDLE_TRACK_EXPIRE_SECONDS = 60 * 60;
    private static final long STATION_MOVE_RESET_WAIT_MS = 1000L;
    private static final String IDLE_RECOVER_CLEARED_MEMO = "idleRecoverRerouteCleared";
    @Autowired
    private BasDevpService basDevpService;
@@ -958,10 +960,6 @@
            return;
        }
        if (hasFollowUpMoveCommandAfterStay(idleTrack, stationProtocol.getTaskNo(), stationProtocol.getStationId())) {
            return;
        }
        OutOrderDispatchDecision dispatchDecision = null;
        Integer moveStaNo;
        if (Objects.equals(wrkMast.getWrkSts(), WrkStsType.STATION_RUN.sts)) {
@@ -975,6 +973,8 @@
        }
        redisUtil.set(RedisKeyType.CHECK_STATION_IDLE_RECOVER_LIMIT_.key + stationProtocol.getTaskNo(), "lock", STATION_IDLE_RECOVER_LIMIT_SECONDS);
        resetSegmentMoveCommandsBeforeReroute(stationProtocol.getTaskNo());
        int clearedCommandCount = clearIssuedMoveCommandsDuringIdleStay(idleTrack, stationProtocol.getTaskNo(), stationProtocol.getStationId());
        StationCommand command = stationThread.getCommand(
                StationCommandType.MOVE,
@@ -991,8 +991,8 @@
        MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command));
        syncOutOrderWatchState(wrkMast, stationProtocol.getStationId(), outOrderList, dispatchDecision, command);
        saveStationTaskIdleTrack(new StationTaskIdleTrack(wrkMast.getWrkNo(), stationProtocol.getStationId(), System.currentTimeMillis()));
        News.info("输送站点任务停留{}秒未运行,已重新计算路径并重启运行,站点号={},目标站={},工作号={},命令数据={}",
                STATION_IDLE_RECOVER_SECONDS, stationProtocol.getStationId(), moveStaNo, wrkMast.getWrkNo(), JSON.toJSONString(command));
        News.info("输送站点任务停留{}秒未运行,已重新计算路径并重启运行,站点号={},目标站={},工作号={},清理旧分段命令数={},命令数据={}",
                STATION_IDLE_RECOVER_SECONDS, stationProtocol.getStationId(), moveStaNo, wrkMast.getWrkNo(), clearedCommandCount, JSON.toJSONString(command));
    }
    private boolean canRecoverIdleStationTask(WrkMast wrkMast, Integer currentStationId) {
@@ -1006,41 +1006,91 @@
                || Objects.equals(wrkMast.getWrkSts(), WrkStsType.STATION_RUN.sts);
    }
    private boolean hasFollowUpMoveCommandAfterStay(StationTaskIdleTrack idleTrack,
                                                    Integer taskNo,
                                                    Integer stationId) {
        if (idleTrack == null || taskNo == null || stationId == null || idleTrack.firstSeenTime == null) {
            return false;
    private void resetSegmentMoveCommandsBeforeReroute(Integer taskNo) {
        if (redisUtil == null || taskNo == null || taskNo <= 0) {
            return;
        }
        if (basStationOptService == null) {
            return false;
        String key = RedisKeyType.DEVICE_STATION_MOVE_RESET.key + taskNo;
        redisUtil.set(key, "cancel", 3);
        try {
            Thread.sleep(STATION_MOVE_RESET_WAIT_MS);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        } catch (Exception ignore) {
        }
        redisUtil.del(key);
        }
    private int clearIssuedMoveCommandsDuringIdleStay(StationTaskIdleTrack idleTrack,
                                                      Integer taskNo,
                                                      Integer stationId) {
        if (basStationOptService == null) {
            return 0;
        }
        List<BasStationOpt> optList;
        try {
            optList = basStationOptService.list(new QueryWrapper<BasStationOpt>()
                    .select("id", "target_station_id")
            optList = listIssuedMoveCommandsDuringIdleStay(idleTrack, taskNo);
        } catch (Exception e) {
            return 0;
        }
        if (optList == null || optList.isEmpty()) {
            return 0;
        }
        Date now = new Date();
        String cleanupMemo = buildIdleRecoverClearedMemo(stationId);
        int clearedCount = 0;
        for (BasStationOpt opt : optList) {
            if (opt == null || opt.getId() == null) {
                continue;
            }
            opt.setSend(0);
            opt.setUpdateTime(now);
            opt.setMemo(appendCleanupMemo(opt.getMemo(), cleanupMemo));
            clearedCount++;
        }
        if (clearedCount > 0) {
            basStationOptService.updateBatchById(optList);
        }
        return clearedCount;
    }
    private List<BasStationOpt> listIssuedMoveCommandsDuringIdleStay(StationTaskIdleTrack idleTrack,
                                                                     Integer taskNo) {
        if (idleTrack == null || taskNo == null || taskNo <= 0 || idleTrack.firstSeenTime == null || basStationOptService == null) {
            return Collections.emptyList();
        }
        List<BasStationOpt> optList = basStationOptService.list(new QueryWrapper<BasStationOpt>()
                .select("id", "task_no", "send_time", "target_station_id", "memo", "send")
                    .eq("task_no", taskNo)
                    .eq("source_station_id", stationId)
                    .eq("mode", String.valueOf(StationCommandType.MOVE))
                    .eq("send", 1)
                    .ge("send_time", new Date(idleTrack.firstSeenTime))
                    .orderByDesc("send_time")
                    .last("limit 3"));
        } catch (Exception e) {
            return false;
        }
                .orderByAsc("send_time"));
        if (optList == null || optList.isEmpty()) {
            return false;
            return Collections.emptyList();
        }
        return optList;
        }
        for (BasStationOpt opt : optList) {
            if (opt != null && opt.getTargetStationId() != null && !Objects.equals(opt.getTargetStationId(), stationId)) {
                return true;
    private String buildIdleRecoverClearedMemo(Integer stationId) {
        if (stationId == null) {
            return IDLE_RECOVER_CLEARED_MEMO;
            }
        return IDLE_RECOVER_CLEARED_MEMO + "(stationId=" + stationId + ")";
        }
        return false;
    private String appendCleanupMemo(String memo, String cleanupMemo) {
        if (Cools.isEmpty(cleanupMemo)) {
            return memo;
        }
        if (Cools.isEmpty(memo)) {
            return cleanupMemo;
        }
        if (memo.contains(cleanupMemo)) {
            return memo;
        }
        return memo + " | " + cleanupMemo;
    }
    private StationTaskIdleTrack touchStationTaskIdleTrack(Integer taskNo, Integer stationId) {