From 60edff747d52eb42aadb036e3fbd580252de4c05 Mon Sep 17 00:00:00 2001
From: zhang <zc857179121@qq.com>
Date: 星期四, 28 八月 2025 08:15:54 +0800
Subject: [PATCH] 1
---
zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/LaneService.java | 117 +++++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 94 insertions(+), 23 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 9eb7351..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
@@ -1,19 +1,25 @@
package com.zy.acs.manager.core.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.zy.acs.common.constant.RedisConstant;
import com.zy.acs.common.utils.GsonUtils;
+import com.zy.acs.common.utils.RedisSupport;
import com.zy.acs.framework.common.Cools;
import com.zy.acs.framework.common.SnowflakeIdWorker;
import com.zy.acs.manager.core.domain.Lane;
+import com.zy.acs.manager.core.service.astart.MapDataDispatcher;
import com.zy.acs.manager.manager.entity.Code;
+import com.zy.acs.manager.manager.enums.StatusType;
import com.zy.acs.manager.manager.service.CodeService;
import com.zy.acs.manager.manager.service.RouteService;
import com.zy.acs.manager.system.service.ConfigService;
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.*;
@@ -26,11 +32,17 @@
@Service
public class LaneService {
- private boolean initialized = Boolean.FALSE;
+ private final RedisSupport redis = RedisSupport.defaultRedisSupport;
- private final List<Lane> lanes = new ArrayList<>();
+ private List<Lane> lanes = new ArrayList<>();
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;
@Autowired
private CodeService codeService;
@@ -40,27 +52,70 @@
private SnowflakeIdWorker snowflakeIdWorker;
@Autowired
private ConfigService configService;
+ @Autowired
+ private MapDataDispatcher mapDataDispatcher;
+
+ // service -------------------------------------------------------
public Boolean isInitialized() {
return this.initialized;
}
- public List<String> getLanePoints(String codeData) {
+ public Lane search(String codeData) {
if (Cools.isEmpty(codeData) || !this.initialized) {
return null;
}
- for (Lane lane : this.lanes) {
- if (lane.getCodes().contains(codeData)) {
- return lane.getCodes();
- }
- }
- return null;
+// if (result == null) {
+// for (Lane lane : this.lanes) {
+// if (lane.getCodes().contains(codeData)) {
+// return lane;
+// }
+// }
+// }
+ return this.codeLaneMap.get(codeData);
}
- @PostConstruct
- public synchronized void init() {
+ public List<int[]> getLaneCodeIdxList(String codeData) {
+ if (Cools.isEmpty(codeData)) {
+ return new ArrayList<>();
+ }
+ List<int[]> list = this.laneCodeIdxMap.get(codeData);
+ if (null == list) {
+ return new ArrayList<>();
+ }
+ return list;
+ }
+
+ // launcher -------------------------------------------------------
+
+ @EventListener(ApplicationReadyEvent.class)
+ public void init() {
+ Integer lev = MapDataDispatcher.MAP_DEFAULT_LEV;
+ String laneDataStr = redis.getValue(RedisConstant.MAP_LANE_DATA, String.valueOf(lev));
+ if (!Cools.isEmpty(laneDataStr)) {
+ this.lanes = GsonUtils.fromJsonToList(laneDataStr, Lane.class);
+ } else {
+
+ StopWatch stopWatch = new StopWatch();
+ stopWatch.start();
+
+ this.initLaneData();
+
+ stopWatch.stop();
+ log.info("the rcs system calculated lane data which has spend {} millisecond......", stopWatch.getTime());
+
+ redis.setValue(RedisConstant.MAP_LANE_DATA, String.valueOf(lev), GsonUtils.toJson(this.lanes));
+ }
+
+ this.generateLaneCodeIdx(null);
+ this.initialized = Boolean.TRUE;
+// System.out.println(GsonUtils.toJson(this.lanes));
+ }
+
+ private void initLaneData() {
log.info("the rcs system is starting to initialize lane data...");
- List<Code> codeList = codeService.list(new LambdaQueryWrapper<Code>().eq(Code::getStatus, 1));
+
+ List<Code> codeList = codeService.list(new LambdaQueryWrapper<Code>().eq(Code::getStatus, StatusType.ENABLE.val));
this.fillAdjacencyCodeMap(codeList);
@@ -68,23 +123,20 @@
this.mergeDeadEndLane();
- this.deadInteractionPoint();
+ this.deleteInteractionPoint();
this.filterLanesWithFewPoints();
this.generateLaneHash();
- this.initialized = Boolean.TRUE;
log.info("the lane data initialization has been completed in rcs system.");
-
- System.out.println(GsonUtils.toJson(this.lanes));
}
private void fillAdjacencyCodeMap(List<Code> codeList) {
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()));
}
}
@@ -96,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); // 鍖呭惈璧风偣
@@ -180,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);
@@ -244,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());
@@ -262,7 +318,7 @@
}
}
- private void deadInteractionPoint() {
+ private void deleteInteractionPoint() {
for (Lane lane : this.lanes) {
lane.removeInteraction(this.adjacencyCodeMap);
}
@@ -299,4 +355,19 @@
return sb.toString();
}
+ public void generateLaneCodeIdx(Integer lev) {
+ log.info("There is initializing Lane CodeIdxMap......");
+ if (Cools.isEmpty(this.lanes)) {
+ return;
+ }
+ for (Lane lane : this.lanes) {
+ List<int[]> codeIdxList = new ArrayList<>();
+ for (String code : lane.getCodes()) {
+ int[] codeMatrixIdx = mapDataDispatcher.getCodeMatrixIdx(lev, code);
+ codeIdxList.add(codeMatrixIdx);
+ this.laneCodeIdxMap.put(code, codeIdxList);
+ this.codeLaneMap.put(code, lane);
+ }
+ }
+ }
}
--
Gitblit v1.9.1