#
Junjie
21 小时以前 bdf43f554f9bc7f0de94e7530e79af9193341334
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<>();
@@ -129,6 +131,10 @@
        }
        if(commandType == StationCommandType.WRITE_INFO){
            if (command.getBarcode() != null) {
                updateStationBarcode(deviceNo, stationId, command.getBarcode());
                return;
            }
            if (taskNo == 9998 && targetStationId == 0) {
                //生成出库站点仿真数据
                generateFakeOutStationData(deviceNo, stationId);
@@ -199,6 +205,23 @@
        }
    }
    private void updateStationBarcode(Integer deviceNo, Integer stationId, String barcode) {
        List<ZyStationStatusEntity> statusList = deviceStatusMap.get(deviceNo);
        if (statusList == null) {
            return;
        }
        ZyStationStatusEntity status = statusList.stream()
                .filter(item -> item.getStationId().equals(stationId)).findFirst().orElse(null);
        if (status == null) {
            return;
        }
        synchronized (status) {
            status.setBarcode(barcode);
        }
    }
    private void currentLevCommand(StationCommand command, boolean generateBarcode) {
        NavigateUtils navigateUtils = SpringUtils.getBean(NavigateUtils.class);
        if (navigateUtils == null) {
@@ -209,14 +232,14 @@
        Integer stationId = command.getStationId();
        Integer targetStationId = command.getTargetStaNo();
        List<NavigateNode> navigateNodes = null;
        List<NavigateNode> navigateNodes = new ArrayList<>();
        try {
            navigateNodes = navigateUtils.calcByStationId(stationId, targetStationId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (navigateNodes == null) {
        if (navigateNodes.isEmpty()) {
            return;
        }
@@ -237,16 +260,16 @@
        Integer stationId = command.getStationId();
        Integer targetStationId = command.getTargetStaNo();
        List<NavigateNode> navigateNodes = null;
        List<NavigateNode> targetNavigateNodes = null;
        List<NavigateNode> navigateNodes = new ArrayList<>();
        List<NavigateNode> targetNavigateNodes = new ArrayList<>();
        try {
            BasStation startStation = basStationService.selectById(stationId);
            BasStation startStation = basStationService.getById(stationId);
            if (startStation == null) {
                return;
            }
            BasStation targetStation = basStationService.selectById(targetStationId);
            BasStation targetStation = basStationService.getById(targetStationId);
            if (targetStation == null) {
                return;
            }
@@ -287,14 +310,22 @@
                    continue;
                }
                navigateNodes = navigateUtils.calcByStationId(stationId, liftStationId);
                if(navigateNodes == null){
                try {
                    navigateNodes = navigateUtils.calcByStationId(stationId, liftStationId);
                } catch (Exception e) {
                }
                if(navigateNodes.isEmpty()){
                    continue;
                }
                //计算提升机到目标站的路径
                targetNavigateNodes = navigateUtils.calcByStationId(targetLiftStationId, targetStationId);
                if(targetNavigateNodes == null) {
                try {
                    //计算提升机到目标站的路径
                    targetNavigateNodes = navigateUtils.calcByStationId(targetLiftStationId, targetStationId);
                } catch (Exception e) {
                }
                if(targetNavigateNodes.isEmpty()) {
                    continue;
                }
            }
@@ -302,7 +333,7 @@
            e.printStackTrace();
        }
        if (navigateNodes == null || targetNavigateNodes == null) {
        if (navigateNodes.isEmpty() || targetNavigateNodes.isEmpty()) {
            return;
        }
@@ -317,6 +348,7 @@
        Integer targetStationDeviceNo = null;
        long executeTime = System.currentTimeMillis();
        long runBlockTimeoutMs = getFakeRunBlockTimeoutMs();
        int i = 0;
        while (i < navigateNodes.size()) {
            if (Thread.currentThread().isInterrupted()) {
@@ -343,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) {
@@ -658,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) {