From 3a49654f51096d4f9f95f4a5e8198e168e38a0c5 Mon Sep 17 00:00:00 2001 From: zhang <zc857179121@qq.com> Date: 星期六, 16 八月 2025 08:34:13 +0800 Subject: [PATCH] 1 --- zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/LaneService.java | 37 +++++++++++++++++++++++-------------- 1 files changed, 23 insertions(+), 14 deletions(-) diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/LaneService.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/LaneService.java index cbfedb2..018eb05 100644 --- a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/LaneService.java +++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/LaneService.java @@ -16,9 +16,10 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.time.StopWatch; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.event.EventListener; import org.springframework.stereotype.Service; -import javax.annotation.PostConstruct; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.*; @@ -38,6 +39,8 @@ private final Map<String, List<String>> adjacencyCodeMap = new HashMap<>(); private final Map<String, List<int[]>> laneCodeIdxMap = new HashMap<>(); + + private final Map<String, Lane> codeLaneMap = new HashMap<>(); private boolean initialized = Boolean.FALSE; @@ -62,12 +65,14 @@ if (Cools.isEmpty(codeData) || !this.initialized) { return null; } - for (Lane lane : this.lanes) { - if (lane.getCodes().contains(codeData)) { - return lane; - } - } - return null; +// if (result == null) { +// for (Lane lane : this.lanes) { +// if (lane.getCodes().contains(codeData)) { +// return lane; +// } +// } +// } + return this.codeLaneMap.get(codeData); } public List<int[]> getLaneCodeIdxList(String codeData) { @@ -83,7 +88,7 @@ // launcher ------------------------------------------------------- - @PostConstruct + @EventListener(ApplicationReadyEvent.class) public void init() { Integer lev = MapDataDispatcher.MAP_DEFAULT_LEV; String laneDataStr = redis.getValue(RedisConstant.MAP_LANE_DATA, String.valueOf(lev)); @@ -131,7 +136,7 @@ for (Code code : codeList) { List<Long> adjacencyNode = routeService.getAdjacencyNode(code.getId()); this.adjacencyCodeMap.put(code.getData(), adjacencyNode.stream().map(node -> ( - codeService.getById(node).getData() + codeService.getCacheById(node).getData() )).collect(Collectors.toList())); } } @@ -143,6 +148,10 @@ if (this.adjacencyCodeMap.get(codeData).size() != 2) { List<String> neighbors = this.adjacencyCodeMap.get(codeData); for (String neighbor : neighbors) { + if (this.adjacencyCodeMap.get(neighbor) == null) { + log.info("cunzai"); + continue; + } if (this.adjacencyCodeMap.get(neighbor).size() == 2 && !visited.contains(neighbor)) { Lane lane = new Lane(String.valueOf(snowflakeIdWorker.nextId()).substring(3)); lane.getCodes().add(codeData); // 鍖呭惈璧风偣 @@ -227,9 +236,9 @@ return true; } - Code parentCode = codeService.selectByData(parent); - Code currentCode = codeService.selectByData(current); - Code neighborCode = codeService.selectByData(neighbor); + Code parentCode = codeService.getCacheByData(parent); + Code currentCode = codeService.getCacheByData(current); + Code neighborCode = codeService.getCacheByData(neighbor); double direction1 = this.calculateDirection(parentCode, currentCode); double direction2 = this.calculateDirection(currentCode, neighborCode); @@ -291,7 +300,7 @@ for (String anotherPointNear : anotherPointNears) { if (!lane.getCodes().contains(anotherPointNear) && this.adjacencyCodeMap.get(anotherPointNear).size() == 2) { - for (Lane lane0 : lanes) { + for (Lane lane0 : new ArrayList<>(lanes)) { if (lane0.getCodes().contains(anotherPointNear)) { lane0.getCodes().addAll(lane.getCodes()); @@ -348,7 +357,6 @@ public void generateLaneCodeIdx(Integer lev) { log.info("There is initializing Lane CodeIdxMap......"); - long l = System.currentTimeMillis(); if (Cools.isEmpty(this.lanes)) { return; } @@ -358,6 +366,7 @@ int[] codeMatrixIdx = mapDataDispatcher.getCodeMatrixIdx(lev, code); codeIdxList.add(codeMatrixIdx); this.laneCodeIdxMap.put(code, codeIdxList); + this.codeLaneMap.put(code, lane); } } } -- Gitblit v1.9.1