From 9fb7c7678174c0fea9bf7c96dca8c24b165d0a48 Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@163.com> Date: 星期六, 04 一月 2025 13:20:57 +0800 Subject: [PATCH] # --- zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/astart/MapDataDispatcher.java | 72 +++++++++++++++++++++--------------- 1 files changed, 42 insertions(+), 30 deletions(-) diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/astart/MapDataDispatcher.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/astart/MapDataDispatcher.java index 20fedf8..59c694b 100644 --- a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/astart/MapDataDispatcher.java +++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/astart/MapDataDispatcher.java @@ -3,6 +3,7 @@ import com.alibaba.fastjson.JSON; 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.exception.CoolException; @@ -17,7 +18,9 @@ import lombok.extern.slf4j.Slf4j; import java.util.*; +import java.util.concurrent.ConcurrentLinkedQueue; import java.util.stream.Collectors; +import java.util.stream.IntStream; /** * Created by vincent on 6/6/2024 @@ -28,6 +31,9 @@ public static final Integer MAP_DEFAULT_LEV = 1; private final RedisSupport redis = RedisSupport.defaultRedisSupport; + + List<Double> xIdxList; + List<Double> yIdxList; private String[][] codeMatrix; @@ -193,7 +199,6 @@ } public String[][] initWaveMatrix(Integer lev) { - log.info("There is initializing Wave Matrix......"); lev = Optional.ofNullable(lev).orElse(MAP_DEFAULT_LEV); String[][] codeMatrix = getCodeMatrix(lev); @@ -236,13 +241,20 @@ log.info("There is initializing Cda Matrix......"); lev = Optional.ofNullable(lev).orElse(MAP_DEFAULT_LEV); + if (Cools.isEmpty(xIdxList, yIdxList)) { + this.initCodeMatrix(lev); + } + String[][] codeMatrix = getCodeMatrix(lev); String[][] cdaMatrix = new String[codeMatrix.length][codeMatrix[0].length]; for (int i = 0; i < codeMatrix.length; i++) { for (int j = 0; j < codeMatrix[i].length; j++) { if (CodeNodeType.NONE.val.equals(codeMatrix[i][j])) { - cdaMatrix[i][j] = CdaNodeType.DISABLE.val; + List<Double> cdaArr = new ArrayList<>(); + cdaArr.add(xIdxList.get(j)); + cdaArr.add(yIdxList.get(i)); + cdaMatrix[i][j] = JSON.toJSONString(cdaArr); } else { Code currCode = codeService.selectByData(codeMatrix[i][j]); if (null != currCode) { @@ -373,6 +385,7 @@ continue; } redis.setMap(RedisConstant.AGV_MAP_ROUTE_CDA_HASH_FLAG, routeCdaKey, Boolean.TRUE); + this.routeCdaMap.put(routeCdaKey, Boolean.TRUE); } } @@ -384,13 +397,9 @@ .orderByAsc(Code::getY) .orderByAsc(Code::getX) ); -// int xCount = codeService.selectDistinctCountFromX(); -// int yCount = codeService.selectDistinctCountFromY(); -// // [][] 绗竴涓槸鎺掔殑鏁伴噺 绗簩涓槸鍒楃殑鏁伴噺 -// String[][] codeMatrix = new String[yCount][xCount]; - List<Double> xIdxList = new ArrayList<>(); - List<Double> yIdxList = new ArrayList<>(); + xIdxList = new ArrayList<>(); + yIdxList = new ArrayList<>(); for (Code code : codeList) { Double x = code.getX(); Double y = code.getY(); @@ -408,24 +417,9 @@ // [][] 绗竴涓槸鎺掔殑鏁伴噺 绗簩涓槸鍒楃殑鏁伴噺 String[][] codeMatrix = new String[yIdxList.size()][xIdxList.size()]; - int idxX = -1; - int idxY = -1; - double lastX = -1; - double lastY = -1; for (Code code : codeList) { Double x = code.getX(); Double y = code.getY(); -// if (y != lastY) { -// idxY ++; -// idxX = 0; -// lastY = y; -// lastX = x; -// } -// if (x != lastX) { -// idxX++; -// lastX = x; -// } -// codeMatrix[idxY][idxX] = code.getData(); codeMatrix[yIdxList.indexOf(y)][xIdxList.indexOf(x)] = code.getData(); } @@ -466,19 +460,37 @@ } lev = Optional.ofNullable(lev).orElse(MAP_DEFAULT_LEV); - List<SortCodeDto> codeList = new ArrayList<>(); DynamicNode[][] dynamicMatrix = getDynamicMatrix(lev); String[][] codeMatrix = this.getCodeMatrix(lev); - for (int i = 0; i < codeMatrix.length; i++) { + + ConcurrentLinkedQueue<SortCodeDto> codeList = new ConcurrentLinkedQueue<>(); + + IntStream.range(0, codeMatrix.length).parallel().forEach(i -> { for (int j = 0; j < codeMatrix[i].length; j++) { DynamicNode dynamicNode = dynamicMatrix[i][j]; if (nodeType.equals(dynamicNode.getVehicle())) { codeList.add(new SortCodeDto(codeMatrix[i][j], dynamicNode.getSerial())); } } - } - codeList.sort(Comparator.comparingInt(SortCodeDto::getSerial)); - return codeList.stream().map(SortCodeDto::getCode).collect(Collectors.toList()); + }); + + return codeList.stream() + .sorted(Comparator.comparingInt(SortCodeDto::getSerial)) + .map(SortCodeDto::getCode) + .collect(Collectors.toList()); + +// List<SortCodeDto> codeList = new ArrayList<>(); + +// for (int i = 0; i < codeMatrix.length; i++) { +// for (int j = 0; j < codeMatrix[i].length; j++) { +// DynamicNode dynamicNode = dynamicMatrix[i][j]; +// if (nodeType.equals(dynamicNode.getVehicle())) { +// codeList.add(new SortCodeDto(codeMatrix[i][j], dynamicNode.getSerial())); +// } +// } +// } +// codeList.sort(Comparator.comparingInt(SortCodeDto::getSerial)); +// return codeList.stream().map(SortCodeDto::getCode).collect(Collectors.toList()); } public void modifyDynamicMatrix(Integer lev, List<String> codeList, String vehicle) { @@ -493,11 +505,11 @@ if (Cools.isEmpty(codeList, vehicle)) { return; } - long time = System.currentTimeMillis() / 1000; +// long time = System.currentTimeMillis() / 1000; int serial = 1; for (String code : codeList) { int[] node = getCodeMatrixIdx(lev, code); - dynamicMatrix[node[0]][node[1]] = new DynamicNode(vehicle, serial, time); + dynamicMatrix[node[0]][node[1]] = new DynamicNode(vehicle, serial); serial++; } } else { -- Gitblit v1.9.1