#
Junjie
16 小时以前 205cb40876114827a2134c29fde159e063e81454
src/main/java/com/zy/core/thread/impl/ZyStationV3Thread.java
@@ -30,6 +30,7 @@
import com.zy.core.network.DeviceConnectPool;
import com.zy.core.network.ZyStationConnectDriver;
import com.zy.core.network.entity.ZyStationStatusEntity;
import com.zy.core.utils.DeviceLogRedisKeyBuilder;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
@@ -169,7 +170,7 @@
            deviceDataLog.setDeviceNo(deviceConfig.getDeviceNo());
            deviceDataLog.setCreateTime(new Date());
            redisUtil.set(RedisKeyType.DEVICE_LOG_KEY.key + System.currentTimeMillis(), deviceDataLog, 60 * 60 * 24);
            redisUtil.set(DeviceLogRedisKeyBuilder.build(deviceDataLog), deviceDataLog, 60 * 60 * 24);
            deviceDataLogTime = System.currentTimeMillis();
        }
    }
@@ -218,6 +219,11 @@
        if (commandType == StationCommandType.MOVE) {
            if (!stationId.equals(targetStationId)) {
                List<Integer> path = calcPathStationIds(stationId, targetStationId);
                if (path == null || path.isEmpty()) {
                    log.warn("输送线命令生成失败,路径为空,taskNo={}, stationId={}, targetStationId={}",
                            taskNo, stationId, targetStationId);
                    return null;
                }
                stationCommand.setNavigatePath(path);
            }
        }
@@ -333,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;
@@ -384,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()) {
                                break;
                            }
                            Thread.sleep(200);
                        if (!sendSegmentWithRetry(nextCmd, original.getTaskNo())) {
                            break;
                        }
                    }
                    Thread.sleep(500);
@@ -437,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) {
        }
    }
}