| | |
| | | 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; |
| | |
| | | * 输送站假连接(模拟) |
| | | */ |
| | | 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<>(); |
| | |
| | | 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; |
| | | } |
| | | |
| | |
| | | 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; |
| | | } |
| | |
| | | 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; |
| | | } |
| | | } |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | if (navigateNodes == null || targetNavigateNodes == null) { |
| | | if (navigateNodes.isEmpty() || targetNavigateNodes.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | |
| | | Integer targetStationDeviceNo = null; |
| | | |
| | | long executeTime = System.currentTimeMillis(); |
| | | long runBlockTimeoutMs = getFakeRunBlockTimeoutMs(); |
| | | int i = 0; |
| | | while (i < navigateNodes.size()) { |
| | | if (Thread.currentThread().isInterrupted()) { |
| | |
| | | } |
| | | |
| | | 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) { |
| | |
| | | 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) { |