#
Junjie
13 小时以前 bdf43f554f9bc7f0de94e7530e79af9193341334
#
1个文件已添加
2个文件已修改
104 ■■■■ 已修改文件
src/main/java/com/zy/core/network/fake/ZyStationFakeConnect.java 46 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/network/fake/ZyStationFakeSegConnect.java 43 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/sql/20260319_add_fake_run_block_timeout_config.sql 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/network/fake/ZyStationFakeConnect.java
@@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -31,6 +32,7 @@
 * 输送站假连接(模拟)
 */
public class ZyStationFakeConnect implements ZyStationConnectApi {
    private static final long DEFAULT_FAKE_RUN_BLOCK_TIMEOUT_MS = 10000L;
    private static int LOCK_STATION = 0;
    private HashMap<Integer, List<ZyStationStatusEntity>> deviceStatusMap = new HashMap<>();
@@ -346,6 +348,7 @@
        Integer targetStationDeviceNo = null;
        long executeTime = System.currentTimeMillis();
        long runBlockTimeoutMs = getFakeRunBlockTimeoutMs();
        int i = 0;
        while (i < navigateNodes.size()) {
            if (Thread.currentThread().isInterrupted()) {
@@ -372,16 +375,9 @@
            }
            if (!checkTaskNoInArea(taskNo)) {
                boolean fakeAllowCheckBlock = true;
                Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
                if (systemConfigMapObj != null) {
                    HashMap<String, String> systemConfigMap = (HashMap<String, String>) systemConfigMapObj;
                    if (!systemConfigMap.get("fakeAllowCheckBlock").equals("Y")) {
                        fakeAllowCheckBlock = false;
                    }
                }
                boolean fakeAllowCheckBlock = getFakeAllowCheckBlock();
                if (fakeAllowCheckBlock && System.currentTimeMillis() - executeTime > 1000 * 10) {
                if (fakeAllowCheckBlock && System.currentTimeMillis() - executeTime > runBlockTimeoutMs) {
                    //认定堵塞
                    boolean result = runBlockStation(taskNo, currentStationId, currentStationDeviceNo, taskNo, currentStationId);
                    if(!result) {
@@ -687,6 +683,38 @@
        return result;
    }
    private boolean getFakeAllowCheckBlock() {
        boolean fakeAllowCheckBlock = true;
        Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
        if (systemConfigMapObj instanceof Map) {
            Map<?, ?> systemConfigMap = (Map<?, ?>) systemConfigMapObj;
            Object value = systemConfigMap.get("fakeAllowCheckBlock");
            if (value != null && !"Y".equals(String.valueOf(value))) {
                fakeAllowCheckBlock = false;
            }
        }
        return fakeAllowCheckBlock;
    }
    private long getFakeRunBlockTimeoutMs() {
        long timeoutMs = DEFAULT_FAKE_RUN_BLOCK_TIMEOUT_MS;
        Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
        if (systemConfigMapObj instanceof Map) {
            Map<?, ?> systemConfigMap = (Map<?, ?>) systemConfigMapObj;
            Object value = systemConfigMap.get("fakeRunBlockTimeoutMs");
            if (value != null) {
                try {
                    long parsed = Long.parseLong(String.valueOf(value).trim());
                    if (parsed > 0) {
                        timeoutMs = parsed;
                    }
                } catch (Exception ignore) {
                }
            }
        }
        return timeoutMs;
    }
    private boolean checkTaskNoInArea(Integer taskNo) {
        Object fakeTaskNoAreaObj = redisUtil.get(RedisKeyType.FAKE_TASK_NO_AREA.key);
        if (fakeTaskNoAreaObj == null) {
src/main/java/com/zy/core/network/fake/ZyStationFakeSegConnect.java
@@ -27,6 +27,7 @@
import java.util.Arrays;
public class ZyStationFakeSegConnect implements ZyStationConnectApi {
    private static final long DEFAULT_FAKE_RUN_BLOCK_TIMEOUT_MS = 10000L;
    // 站点级锁:每个站点独立一把锁,提升并发性能
    private final Map<Integer, ReentrantLock> stationLocks = new ConcurrentHashMap<>();
@@ -128,6 +129,7 @@
            boolean initialized = false;
            // 上一步执行时间(用于堵塞检测)
            long stepExecuteTime = System.currentTimeMillis();
            long runBlockTimeoutMs = getFakeRunBlockTimeoutMs();
            // 仅在每次到达目标时执行一次到位处理,避免重复生成条码
            boolean arrivalHandled = false;
@@ -145,6 +147,15 @@
                StationCommand command = commandQueue.poll(100, TimeUnit.MILLISECONDS);
                if (command != null) {
                    taskLastUpdateTime.put(taskNo, System.currentTimeMillis());
                    List<Integer> newPath = command.getNavigatePath();
                    Integer lastInQueue = getLastInQueue(pendingPathQueue);
                    int startIndex = getPathAppendStartIndex(newPath, currentStationId, lastInQueue);
                    if (newPath != null && !newPath.isEmpty() && startIndex < 0) {
                        News.info("[WCS Debug] 任务{}忽略无法衔接的旧路径段: {}, 当前位置: {}, 队列尾: {}", taskNo,
                                newPath, currentStationId, lastInQueue);
                        continue;
                    }
                    // 每次接收命令都刷新目标,避免沿用旧目标导致状态抖动
                    Integer commandTargetStationId = command.getTargetStaNo();
@@ -164,12 +175,7 @@
                    }
                    // 将新路径追加到待执行队列
                    List<Integer> newPath = command.getNavigatePath();
                    if (newPath != null && !newPath.isEmpty()) {
                        // 获取队列中最后一个站点(用于衔接点去重)
                        Integer lastInQueue = getLastInQueue(pendingPathQueue);
                        int startIndex = getPathAppendStartIndex(newPath, currentStationId, lastInQueue);
                        for (int i = startIndex; i < newPath.size(); i++) {
                            pendingPathQueue.offer(newPath.get(i));
                        }
@@ -244,7 +250,8 @@
                            if (!checkTaskNoInArea(taskNo)) {
                                boolean fakeAllowCheckBlock = getFakeAllowCheckBlock();
                                if (fakeAllowCheckBlock && System.currentTimeMillis() - stepExecuteTime > 10000) {
                                if (fakeAllowCheckBlock
                                        && System.currentTimeMillis() - stepExecuteTime > runBlockTimeoutMs) {
                                    // 认定堵塞
                                    boolean result = runBlockStation(taskNo, currentStationId, currentDeviceNo, taskNo,
                                            currentStationId);
@@ -330,6 +337,11 @@
            if (idx >= 0) {
                return idx + 1;
            }
            return -1;
        }
        if (lastInQueue != null) {
            return -1;
        }
        return 0;
@@ -387,6 +399,25 @@
        return fakeAllowCheckBlock;
    }
    private long getFakeRunBlockTimeoutMs() {
        long timeoutMs = DEFAULT_FAKE_RUN_BLOCK_TIMEOUT_MS;
        Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
        if (systemConfigMapObj instanceof Map) {
            Map<?, ?> systemConfigMap = (Map<?, ?>) systemConfigMapObj;
            Object value = systemConfigMap.get("fakeRunBlockTimeoutMs");
            if (value != null) {
                try {
                    long parsed = Long.parseLong(String.valueOf(value).trim());
                    if (parsed > 0) {
                        timeoutMs = parsed;
                    }
                } catch (Exception ignore) {
                }
            }
        }
        return timeoutMs;
    }
    @Override
    public CommandResponse sendOriginCommand(String address, short[] data) {
        return new CommandResponse(true, "原始命令已受理(异步执行)");
src/main/resources/sql/20260319_add_fake_run_block_timeout_config.sql
New file
@@ -0,0 +1,15 @@
-- 输送线仿真判定堵塞超时时间,单位毫秒
-- 默认 10000ms,与现有硬编码行为保持一致
INSERT INTO sys_config(name, code, value, type, status, select_type)
SELECT '输送线仿真判定堵塞超时时间(毫秒)', 'fakeRunBlockTimeoutMs', '10000', 1, 1, 'fake'
FROM dual
WHERE NOT EXISTS (
    SELECT 1
    FROM sys_config
    WHERE code = 'fakeRunBlockTimeoutMs'
);
SELECT id, name, code, value, type, status, select_type
FROM sys_config
WHERE code = 'fakeRunBlockTimeoutMs';