From 6182cc11c3e93610df7fda87611d2ca807c6354c Mon Sep 17 00:00:00 2001
From: qlsxk <qlsxk@qq.com>
Date: 星期四, 16 十月 2025 14:28:30 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/common/utils/ShuttleOperaUtils.java | 729 +++++++++++++++++++++++++++++++++++++-------------------
1 files changed, 482 insertions(+), 247 deletions(-)
diff --git a/src/main/java/com/zy/common/utils/ShuttleOperaUtils.java b/src/main/java/com/zy/common/utils/ShuttleOperaUtils.java
index 9451d91..c4fe002 100644
--- a/src/main/java/com/zy/common/utils/ShuttleOperaUtils.java
+++ b/src/main/java/com/zy/common/utils/ShuttleOperaUtils.java
@@ -1,22 +1,31 @@
package com.zy.common.utils;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
-import com.zy.asrs.entity.BasShuttle;
-import com.zy.asrs.service.BasShuttleService;
+import com.core.common.SpringUtils;
+import com.core.exception.CoolException;
+import com.zy.asrs.entity.DeviceConfig;
+import com.zy.asrs.service.DeviceConfigService;
import com.zy.asrs.utils.Utils;
+import com.zy.common.model.MapNode;
import com.zy.common.model.NavigateNode;
+import com.zy.common.model.enums.NavigationMapType;
import com.zy.core.News;
+import com.zy.core.cache.SlaveConnection;
+import com.zy.core.dispatcher.ShuttleDispatchUtils;
+import com.zy.core.enums.MapNodeType;
+import com.zy.core.enums.RedisKeyType;
import com.zy.core.enums.ShuttleRunDirection;
+import com.zy.core.enums.SlaveType;
import com.zy.core.model.command.ShuttleAssignCommand;
import com.zy.core.model.command.ShuttleCommand;
import com.zy.core.model.protocol.ShuttleProtocol;
import com.zy.core.thread.ShuttleThread;
+import com.zy.system.entity.Config;
+import com.zy.system.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
+import java.util.*;
/**
* 鍥涘悜杞︽搷浣滃伐鍏风被
@@ -26,30 +35,62 @@
public class ShuttleOperaUtils {
@Autowired
- private BasShuttleService basShuttleService;
- @Autowired
private NavigateUtils navigateUtils;
@Autowired
- private NavigateMapUtils navigateMapUtils;
+ private NavigateMapData navigateMapData;
+ @Autowired
+ private ConfigService configService;
+ @Autowired
+ private ShuttleDispatchUtils shuttleDispatchUtils;
+ @Autowired
+ private DeviceConfigService deviceConfigService;
+ @Autowired
+ private RedisUtil redisUtil;
- public synchronized List<ShuttleCommand> getStartToTargetCommands(String startLocNo, String endLocNo, Integer mapType, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread) {
- return getStartToTargetCommands(startLocNo, endLocNo, mapType, null, assignCommand, shuttleThread);
+ public synchronized List<ShuttleCommand> getStartToTargetCommands(String startLocNo, String endLocNo, List<NavigationMapType> mapTypes, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread) {
+ return getStartToTargetCommands(startLocNo, endLocNo, mapTypes, null, assignCommand, shuttleThread, "move");
}
- public synchronized List<ShuttleCommand> getStartToTargetCommands(String startLocNo, String endLocNo, Integer mapType, List<int[]> whites, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread) {
+ public synchronized List<ShuttleCommand> getStartToTargetCommands(String startLocNo, String endLocNo, List<NavigationMapType> mapTypes, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread, String moveType) {
+ return getStartToTargetCommands(startLocNo, endLocNo, mapTypes, null, assignCommand, shuttleThread, moveType);
+ }
+
+ public synchronized List<ShuttleCommand> getStartToTargetCommands(String startLocNo, String endLocNo, List<NavigationMapType> mapTypes, List<int[]> whites, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread, String moveType) {
ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
if (shuttleProtocol == null) {
return null;
}
Integer shuttleNo = shuttleProtocol.getShuttleNo();
//鑾峰彇灏忚溅绉诲姩閫熷害
- Integer runSpeed = Optional.ofNullable(basShuttleService.selectOne(new EntityWrapper<BasShuttle>().eq("shuttle_no", shuttleNo)).getRunSpeed()).orElse(1000);
- List<NavigateNode> nodeList = navigateUtils.calc(startLocNo, endLocNo, mapType, Utils.getShuttlePoints(shuttleNo, Utils.getLev(startLocNo)), whites);
+ Integer runSpeed = 1000;
+ Object speedObj = redisUtil.get(RedisKeyType.SHUTTLE_SPEED_MAP.key);
+ if (speedObj != null) {
+ HashMap<Integer, Integer> shuttleSpeedMap = (HashMap<Integer, Integer>) speedObj;
+ Integer speed = shuttleSpeedMap.get(shuttleNo);
+ if (speed != null) {
+ runSpeed = speed;
+ }
+ }
+
+ Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
+
+ //灏忚溅(x,y)鍛戒护杩愯鏂瑰悜棰犲��
+ boolean shuttleDirectionReverse = false;
+ if (systemConfigMapObj != null) {
+ HashMap<String, String> systemConfigMap = (HashMap<String, String>) systemConfigMapObj;
+ if (systemConfigMap.get("shuttleDirectionReverse").equals("Y")) {
+ shuttleDirectionReverse = true;
+ }
+ }
+
+ long calcStartTime = System.currentTimeMillis();
+ List<NavigateNode> nodeList = navigateUtils.calc(startLocNo, endLocNo, mapTypes, Utils.getShuttlePoints(shuttleNo, Utils.getLev(startLocNo)), whites);
if (nodeList == null) {
News.error("{} dash {} can't find navigate path!", startLocNo, endLocNo);
shuttleThread.offerSystemMsg("{} dash {} can't find navigate path!", startLocNo, endLocNo);
return null;
}
+ News.info("[RCS Debug] Calc path time:{}", (System.currentTimeMillis() - calcStartTime));
List<NavigateNode> allNode = new ArrayList<>();
List<NavigateNode> lockNode = new ArrayList<>();
@@ -59,7 +100,7 @@
if (whites != null) {
boolean flag = false;
for (int[] white : whites) {
- if(white[0] == node.getX() && white[1] == node.getY()) {
+ if (white[0] == node.getX() && white[1] == node.getY()) {
flag = true;
break;
}
@@ -72,96 +113,70 @@
lockNode.add(node.clone());
}
+ long startTime = System.currentTimeMillis();
List<ShuttleCommand> commands = new ArrayList<>();
//鑾峰彇鍒嗘璺緞
- ArrayList<ArrayList<NavigateNode>> data = navigateUtils.getSectionPath(nodeList);
+ List<List<NavigateNode>> data = navigateUtils.getSectionPath(nodeList);
+ long endTime = System.currentTimeMillis();
+ News.info("[RCS Debug] getSection path time:{}", (endTime - startTime));
+
+ long startGetSectionCommandTime = System.currentTimeMillis();
//灏嗘瘡涓�娈佃矾寰勫垎鎴恈ommand鎸囦护
- for (ArrayList<NavigateNode> nodes : data) {
+ for (int i = 0; i < data.size(); i++) {
+ long startGetStartAndEndPathTime = System.currentTimeMillis();
+ List<NavigateNode> nodes = data.get(i);
//寮�濮嬭矾寰�
NavigateNode startPath = nodes.get(0);
-
//鐩爣璺緞
NavigateNode endPath = nodes.get(nodes.size() - 1);
+ News.info("[RCS Debug] getStartAndEndPath idx:{} time:{}", i, (System.currentTimeMillis() - startGetStartAndEndPathTime));
+
+ long startAllDistanceTime = System.currentTimeMillis();
Integer allDistance = navigateUtils.getCurrentPathAllDistance(nodes);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
+ News.info("[RCS Debug] getAllDistance idx:{} time:{}", i, (System.currentTimeMillis() - startAllDistanceTime));
+
+ long startGetPosition = System.currentTimeMillis();
//閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮�
String startCodeNum = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), startPath.getZ());
//閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮�
String distCodeNum = NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), endPath.getZ());
+ News.info("[RCS Debug] xyToPosition idx:{} time:{}", i, (System.currentTimeMillis() - startGetPosition));
+
+ long startGetMoveCommandTime = System.currentTimeMillis();
//鑾峰彇绉诲姩鍛戒护
- ShuttleCommand command = shuttleThread.getMoveCommand(assignCommand.getDeviceTaskNo(), startCodeNum, distCodeNum, allDistance, ShuttleRunDirection.get(startPath.getDirection()).id.intValue(), runSpeed, nodes);
+ ShuttleCommand command = shuttleThread.getMoveCommand(assignCommand.getDeviceTaskNo(), startCodeNum, distCodeNum, allDistance, ShuttleRunDirection.get(startPath.getDirection()).id.intValue(), runSpeed, nodes, shuttleDirectionReverse);
+ News.info("[RCS Debug] getMoveCommand idx:{} time:{}", i, (System.currentTimeMillis() - startGetMoveCommandTime));
+
+ if (i + 1 == data.size()) {
+ long startGetInOutLiftTime = System.currentTimeMillis();
+ if (moveType.equals("inLift")) {
+ command = shuttleThread.getMoveLiftCommand(assignCommand.getDeviceTaskNo(), startCodeNum, distCodeNum, allDistance, ShuttleRunDirection.get(startPath.getDirection()).id.intValue(), runSpeed, nodes, true, shuttleDirectionReverse);
+ }else if (moveType.equals("outLift")) {
+ command = shuttleThread.getMoveLiftCommand(assignCommand.getDeviceTaskNo(), startCodeNum, distCodeNum, allDistance, ShuttleRunDirection.get(startPath.getDirection()).id.intValue(), runSpeed, nodes, false, shuttleDirectionReverse);
+ }
+ News.info("[RCS Debug] getInOutLiftTime idx:{} time:{}", i, (System.currentTimeMillis() - startGetInOutLiftTime));
+ }
+
command.setNodes(nodes);//灏嗚璧拌妭鐐规坊鍔犲埌姣忎竴姝ュ懡浠や腑
commands.add(command);
}
+ News.info("[RCS Debug] getSectionCommand path time:{}", (System.currentTimeMillis() - startGetSectionCommandTime));
assignCommand.setNodes(allNode);//褰撳墠浠诲姟鎵�鍗犵敤鐨勮妭鐐筶ist
+ assignCommand.setMapTypes(mapTypes);
- boolean result = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(startLocNo), shuttleNo, lockNode, true);//閿佸畾璺緞
- if (!result) {
- News.error("{} dash {} can't lock path!", startLocNo, endLocNo);
- shuttleThread.offerSystemMsg("{} dash {} can't lock path!", startLocNo, endLocNo);
- return null;//璺緞閿佸畾澶辫触
+ //灏忚溅绉诲姩杩炵画涓嬪彂鎸囦护
+ boolean shuttleMoveCommandsContinuously = false;
+ if (systemConfigMapObj != null) {
+ HashMap<String, String> systemConfigMap = (HashMap<String, String>) systemConfigMapObj;
+ String shuttleMoveCommandsContinuouslyConfig = systemConfigMap.get("shuttleMoveCommandsContinuously");
+ if (shuttleMoveCommandsContinuouslyConfig != null && shuttleMoveCommandsContinuouslyConfig.equals("Y")) {
+ shuttleMoveCommandsContinuously = true;
+ }
}
- return commands;
- }
+ assignCommand.setShuttleMoveCommandsContinuously(shuttleMoveCommandsContinuously);
- public synchronized List<ShuttleCommand> shuttleInOutLiftCommand(String startLocNo, String endLocNo, Integer mapType, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread) {
- NavigateNode startNode = NavigatePositionConvert.locNoToNode(startLocNo);
- NavigateNode endNode = NavigatePositionConvert.locNoToNode(endLocNo);
- List<NavigateNode> unlockPath = new ArrayList<>();
- unlockPath.add(startNode);
- unlockPath.add(endNode);
-
- ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
- if (shuttleProtocol == null) {
- return null;
- }
-
- Integer shuttleNo = shuttleProtocol.getShuttleNo();
- //鎵�浣跨敤鐨勮矾寰勮繘琛岄攣瀹�/瑙i攣
- boolean lockResult = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(endLocNo), shuttleProtocol.getShuttleNo(), unlockPath, false);//鎵�浣跨敤鐨勮矾寰勮繘琛岃В閿�
- if (!lockResult) {
- News.error("{} dash {} can't find unlock path!", startLocNo, endLocNo);
- shuttleThread.offerSystemMsg("{} dash {} can't find unlock path!", startLocNo, endLocNo);
- return null;//瑙i攣澶辫触
- }
-
- //鑾峰彇灏忚溅绉诲姩閫熷害
- Integer runSpeed = Optional.ofNullable(basShuttleService.selectOne(new EntityWrapper<BasShuttle>().eq("shuttle_no", shuttleNo)).getRunSpeed()).orElse(1000);
- List<NavigateNode> nodeList = navigateUtils.calc(startLocNo, endLocNo, mapType, Utils.getShuttlePoints(shuttleNo, Utils.getLev(startLocNo)), null);
- if (nodeList == null) {
- News.error("{} dash {} can't find navigate path!", startLocNo, endLocNo);
- shuttleThread.offerSystemMsg("{} dash {} can't find navigate path!", startLocNo, endLocNo);
- return null;
- }
-
- List<NavigateNode> allNode = new ArrayList<>();
- for (NavigateNode node : nodeList) {
- allNode.add(node.clone());
- }
-
- List<ShuttleCommand> commands = new ArrayList<>();
- //鑾峰彇鍒嗘璺緞
- ArrayList<ArrayList<NavigateNode>> data = navigateUtils.getSectionPath(nodeList);
- //灏嗘瘡涓�娈佃矾寰勫垎鎴恈ommand鎸囦护
- for (ArrayList<NavigateNode> nodes : data) {
- //寮�濮嬭矾寰�
- NavigateNode startPath = nodes.get(0);
-
- //鐩爣璺緞
- NavigateNode endPath = nodes.get(nodes.size() - 1);
- Integer allDistance = navigateUtils.getCurrentPathAllDistance(nodes);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
- //閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮�
- String startCodeNum = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), startPath.getZ());
- //閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮�
- String distCodeNum = NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), endPath.getZ());
- //鑾峰彇绉诲姩鍛戒护
- ShuttleCommand command = shuttleThread.getMoveCommand(assignCommand.getDeviceTaskNo(), startCodeNum, distCodeNum, allDistance, ShuttleRunDirection.get(startPath.getDirection()).id.intValue(), runSpeed, nodes);
- command.setNodes(nodes);//灏嗚璧拌妭鐐规坊鍔犲埌姣忎竴姝ュ懡浠や腑
- commands.add(command);
- }
-
- assignCommand.setNodes(allNode);//褰撳墠浠诲姟鎵�鍗犵敤鐨勮妭鐐筶ist
-
+ News.info("{}浠诲姟锛寋}灏忚溅锛寋} - {} 璺緞鍛戒护鍖呰绠楁垚鍔燂紝鑰楁椂:{}ms", assignCommand.getTaskNo(), shuttleProtocol.getShuttleNo(), startLocNo, endLocNo, System.currentTimeMillis() - startTime);
return commands;
}
@@ -187,6 +202,390 @@
ShuttleCommand command = shuttleThread.getLiftCommand(assignCommand.getDeviceTaskNo(), lift);
commands.add(command);
return commands;
+ }
+
+ /**
+ * 妫�娴嬮殰纰嶇墿杞�
+ * @return 0:鏃犻殰纰� 1:鏈夐殰纰嶈皟搴︽垚鍔� 2:鏈夐殰纰嶈皟搴﹀け璐�
+ */
+ public synchronized int checkObstacle(String locNo, List<Integer> whiteShuttles, List<NavigateNode> whiteNodes) {
+ int innerCircle = 0;
+ int outerCircle = 3;
+ Config avoidInnerCircleConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "avoidInnerCircle"));
+ if (avoidInnerCircleConfig != null) {
+ innerCircle = Integer.parseInt(avoidInnerCircleConfig.getValue());
+ }
+
+ Config avoidOuterCircleConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "avoidOuterCircle"));
+ if (avoidOuterCircleConfig != null) {
+ outerCircle = Integer.parseInt(avoidOuterCircleConfig.getValue());
+ }
+
+ ArrayList<int[]> whiteShuttlePointList = new ArrayList<>();
+ for (Integer shuttle : whiteShuttles) {
+ //鑾峰彇鍥涘悜绌挎杞︾嚎绋�
+ ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle);
+ if (shuttleThread == null) {
+ continue;
+ }
+ ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+ if (shuttleProtocol == null) {
+ continue;
+ }
+ String currentLocNo = shuttleProtocol.getCurrentLocNo();
+ int[] shuttleArr = NavigatePositionConvert.positionToXY(currentLocNo);
+ whiteShuttlePointList.add(shuttleArr);
+ }
+
+ //鑾峰彇鍐呭湀鑺傜偣
+ List<NavigateNode> innerNodes = getInnerNodes(locNo, innerCircle, whiteShuttlePointList);
+ List<Integer> nodesCar = findNodesCar(innerNodes);
+ if (nodesCar.isEmpty()) {
+ return 0;//鍐呭湀涓棤杞�
+ }
+
+ //鑾峰彇澶栧湀鑺傜偣
+ List<NavigateNode> outerNodes = getOuterNodes(locNo, outerCircle, whiteShuttlePointList, innerNodes, whiteNodes);
+
+ //灏嗗唴鍦堣妭鐐逛腑闅滅灏忚溅璋冪
+ for (Integer shuttleNo : nodesCar) {
+ ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
+ if (shuttleThread == null) {
+ continue;
+ }
+ ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+ if (shuttleProtocol == null) {
+ continue;
+ }
+ if (!shuttleThread.isIdle()) {
+ continue;
+ }
+
+ String targetLocNo = null;
+ for (NavigateNode node : outerNodes) {
+ String dispatchLocNo = NavigatePositionConvert.nodeToLocNo(node);
+ //鑾峰彇鍐呭湀鑺傜偣
+ List<NavigateNode> avoidInnerNodes = getInnerNodes(dispatchLocNo, innerCircle, new ArrayList<>());
+ //璁$畻鍐呭湀鏄惁鏈夊皬杞�
+ List<Integer> avoidNodesCar = findNodesCar(avoidInnerNodes);
+ if (!avoidNodesCar.isEmpty()) {
+ continue;
+ }
+ targetLocNo = dispatchLocNo;
+ break;
+ }
+
+ if (targetLocNo == null) {
+ continue;
+ }
+ boolean dispatched = shuttleDispatchUtils.dispatchShuttle(null, targetLocNo, shuttleNo);
+ return dispatched ? 1 : 2;
+ }
+
+ return 2;//鍐呭湀涓湁杞�
+ }
+
+ private HashMap<String, Integer> findCarMap() {
+ HashMap<String, Integer> carMap = new HashMap<>();
+
+ List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+ .eq("device_type", String.valueOf(SlaveType.Shuttle)));
+ for (DeviceConfig device : shuttleList) {
+ ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getDeviceNo());
+ if (shuttleThread == null) {
+ continue;
+ }
+ ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+ if (shuttleProtocol == null) {
+ continue;
+ }
+ String currentLocNo = shuttleProtocol.getCurrentLocNo();
+ if (currentLocNo == null) {
+ continue;
+ }
+
+ carMap.put(currentLocNo, device.getDeviceNo());
+ }
+ return carMap;
+ }
+
+ //鎼滅储鑺傜偣鍐呯殑灏忚溅缂栧彿
+ private List<Integer> findNodesCar(List<NavigateNode> nodes) {
+ List<Integer> list = new ArrayList<>();
+ HashMap<String, Integer> carMap = findCarMap();
+ for (NavigateNode node : nodes) {
+ String locNo = NavigatePositionConvert.nodeToLocNo(node);
+ if (carMap.containsKey(locNo)) {
+ list.add(carMap.get(locNo));
+ }
+ }
+
+ return list;
+ }
+
+ private List<NavigateNode> getOuterNodes(String locNo, int outerCircle, List<int[]> whiteShuttlePointList, List<NavigateNode> innerNodes, List<NavigateNode> whiteNodes) {
+ List<NavigateNode> outerNodes = new ArrayList<>();
+ List<NavigateNode> outerNodesTmp = new ArrayList<>();
+ int lev = Utils.getLev(locNo);
+ int[] pointArr = NavigatePositionConvert.positionToXY(locNo);
+ NavigateNode currentNode = new NavigateNode(pointArr[0], pointArr[1]);
+ currentNode.setZ(lev);
+
+ List<List<MapNode>> lists = navigateMapData.getJsonData(lev, NavigationMapType.getMapTypes(NavigationMapType.NONE), null, null);//鑾峰彇瀹屾暣鍦板浘
+ int[][] map = navigateMapData.parseJsonDataArr(lists);
+ int nodeValue = map[pointArr[0]][pointArr[1]];
+ currentNode.setNodeValue(nodeValue);
+
+ for (int i = 0; i < outerCircle; i++) {
+ int idx = i + 1;
+ List<NavigateNode> list = extend_outer_nodes(map, currentNode, idx);
+ if (list.isEmpty()) {
+ continue;
+ }
+ outerNodesTmp.addAll(list);
+ }
+
+ for (NavigateNode node : outerNodesTmp) {
+ boolean flag = false;
+ for (NavigateNode innerNode : innerNodes) {
+ if (node.getX() == innerNode.getX() && node.getY() == innerNode.getY()) {
+ flag = true;
+ break;
+ }
+ }
+
+ if (flag) {
+ continue;
+ }
+
+ for (NavigateNode whiteNode : whiteNodes) {
+ if (node.getX() == whiteNode.getX() && node.getY() == whiteNode.getY()) {
+ flag = true;
+ break;
+ }
+ }
+
+ if (flag) {
+ continue;
+ }
+
+ outerNodes.add(node);
+ }
+
+ return outerNodes;
+ }
+
+ private List<NavigateNode> getInnerNodes(String locNo, int innerCircle, List<int[]> whiteShuttlePointList) {
+ List<NavigateNode> innerNodes = new ArrayList<>();
+ int lev = Utils.getLev(locNo);
+ int[] pointArr = NavigatePositionConvert.positionToXY(locNo);
+ NavigateNode currentNode = new NavigateNode(pointArr[0], pointArr[1]);
+ currentNode.setZ(lev);
+
+ boolean addCurrentNode = true;
+ for (int[] shuttlePoint : whiteShuttlePointList) {
+ if(currentNode.getX() == shuttlePoint[0] && currentNode.getY() == shuttlePoint[1]) {
+ addCurrentNode = false;
+ break;
+ }
+ }
+ if (addCurrentNode) {
+ innerNodes.add(currentNode);
+ }
+
+ List<List<MapNode>> lists = navigateMapData.getJsonData(lev, NavigationMapType.getMapTypes(NavigationMapType.NONE), null, null);//鑾峰彇瀹屾暣鍦板浘
+ int[][] map = navigateMapData.parseJsonDataArr(lists);
+ int nodeValue = map[pointArr[0]][pointArr[1]];
+ currentNode.setNodeValue(nodeValue);
+
+ for (int i = 0; i < innerCircle; i++) {
+ int idx = i + 1;
+ List<NavigateNode> list = extend_inner_nodes(map, currentNode, idx);
+ if (list.isEmpty()) {
+ continue;
+ }
+
+ for (NavigateNode node : list) {
+ boolean flag = false;
+ for (int[] shuttlePoint : whiteShuttlePointList) {
+ if(node.getX() == shuttlePoint[0] && node.getY() == shuttlePoint[1]) {
+ flag = true;
+ break;
+ }
+ }
+ if(flag) {
+ continue;
+ }
+ innerNodes.add(node);
+ }
+ }
+
+ return innerNodes;
+ }
+
+ private List<NavigateNode> extend_inner_nodes(int[][] map, NavigateNode startNode, int innerCircleIdx) {
+ //榛樿鍦板浘姣嶈建鏂瑰悜x
+ String mapDirection = "x";
+ ConfigService configService = SpringUtils.getBean(ConfigService.class);
+ if (configService != null) {
+ Config config = configService.selectOne(new EntityWrapper<Config>()
+ .eq("code", "direction_map")
+ .eq("status", 1));
+ if (config != null) {
+ mapDirection = config.getValue();
+ }
+ }
+
+ ArrayList<NavigateNode> nodes = new ArrayList<>();
+ int x = startNode.getX();
+ int y = startNode.getY();
+ int z = startNode.getZ();
+
+ if (mapDirection.equals("x")) {//姣嶈建x鏂瑰悜
+ if (map[x][y] == MapNodeType.MAIN_PATH.id) {
+ //姣嶈建鎵嶈兘杩涜涓婁笅绉诲姩
+ if (is_valid(map, x + innerCircleIdx, y)) {
+ NavigateNode node = new NavigateNode(x + innerCircleIdx, y);
+ node.setNodeValue(map[x + innerCircleIdx][y]);
+ node.setZ(z);
+ if (node.getNodeValue().equals(startNode.getNodeValue())) {
+ nodes.add(node);
+ }
+ }
+ if (is_valid(map, x - innerCircleIdx, y)) {
+ NavigateNode node = new NavigateNode(x - innerCircleIdx, y);
+ node.setNodeValue(map[x - innerCircleIdx][y]);
+ node.setZ(z);
+ if (node.getNodeValue().equals(startNode.getNodeValue())) {
+ nodes.add(node);
+ }
+ }
+ }
+
+ if (map[x][y] == MapNodeType.NORMAL_PATH.id || map[x][y] == MapNodeType.MAIN_PATH.id || map[x][y] == MapNodeType.CONVEYOR_CAR_GO.id || map[x][y] == MapNodeType.CHARGE.id || map[x][y] == MapNodeType.LIFT.id) {
+ //瀛愯建鍜屾瘝杞ㄣ�佸皬杞﹀彲璧拌緭閫佺嚎銆佸厖鐢垫々銆佹彁鍗囨満鎵嶈兘杩涜宸﹀彸绉诲姩
+ if (is_valid(map, x, y + innerCircleIdx)) {
+ NavigateNode node = new NavigateNode(x, y + innerCircleIdx);
+ node.setNodeValue(map[x][y + innerCircleIdx]);
+ node.setZ(z);
+ if (node.getNodeValue().equals(startNode.getNodeValue())) {
+ nodes.add(node);
+ }
+ }
+
+ if (is_valid(map, x, y - innerCircleIdx)) {
+ NavigateNode node = new NavigateNode(x, y - innerCircleIdx);
+ node.setNodeValue(map[x][y - innerCircleIdx]);
+ node.setZ(z);
+ if (node.getNodeValue().equals(startNode.getNodeValue())) {
+ nodes.add(node);
+ }
+ }
+ }
+ }else if (mapDirection.equals("y")) {//姣嶈建y鏂瑰悜
+ if (map[x][y] == MapNodeType.MAIN_PATH.id) {
+ //姣嶈建鎵嶈兘杩涜宸﹀彸绉诲姩
+ if (is_valid(map, x, y + innerCircleIdx)) {
+ NavigateNode node = new NavigateNode(x, y + innerCircleIdx);
+ node.setNodeValue(map[x][y + innerCircleIdx]);
+ node.setZ(z);
+ if (node.getNodeValue().equals(startNode.getNodeValue())) {
+ nodes.add(node);
+ }
+ }
+
+ if (is_valid(map, x, y - innerCircleIdx)) {
+ NavigateNode node = new NavigateNode(x, y - innerCircleIdx);
+ node.setNodeValue(map[x][y - innerCircleIdx]);
+ node.setZ(z);
+ if (node.getNodeValue().equals(startNode.getNodeValue())) {
+ nodes.add(node);
+ }
+ }
+ }
+
+ if (map[x][y] == MapNodeType.NORMAL_PATH.id || map[x][y] == MapNodeType.MAIN_PATH.id || map[x][y] == MapNodeType.CONVEYOR_CAR_GO.id || map[x][y] == MapNodeType.CHARGE.id || map[x][y] == MapNodeType.LIFT.id) {
+ //瀛愯建鍜屾瘝杞ㄣ�佸皬杞﹀彲璧拌緭閫佺嚎銆佸厖鐢垫々銆佹彁鍗囨満鎵嶈兘杩涜涓婁笅绉诲姩
+ if (is_valid(map, x + innerCircleIdx, y)) {
+ NavigateNode node = new NavigateNode(x + innerCircleIdx, y);
+ node.setNodeValue(map[x + innerCircleIdx][y]);
+ node.setZ(z);
+ if (node.getNodeValue().equals(startNode.getNodeValue())) {
+ nodes.add(node);
+ }
+ }
+ if (is_valid(map, x - innerCircleIdx, y)) {
+ NavigateNode node = new NavigateNode(x - innerCircleIdx, y);
+ node.setNodeValue(map[x - innerCircleIdx][y]);
+ node.setZ(z);
+ if (node.getNodeValue().equals(startNode.getNodeValue())) {
+ nodes.add(node);
+ }
+ }
+ }
+ }else {
+ throw new CoolException("寮傚父鍦板浘鏂瑰悜");
+ }
+
+ return nodes;
+ }
+
+ private List<NavigateNode> extend_outer_nodes(int[][] map, NavigateNode startNode, int innerCircleIdx) {
+ ArrayList<NavigateNode> nodes = new ArrayList<>();
+ int x = startNode.getX();
+ int y = startNode.getY();
+ int z = startNode.getZ();
+
+ if (is_valid(map, x + innerCircleIdx, y)) {
+ NavigateNode node = new NavigateNode(x + innerCircleIdx, y);
+ node.setNodeValue(map[x + innerCircleIdx][y]);
+ node.setZ(z);
+ if (node.getNodeValue().equals(startNode.getNodeValue())) {
+ nodes.add(node);
+ }
+ }
+
+ if (is_valid(map, x - innerCircleIdx, y)) {
+ NavigateNode node = new NavigateNode(x - innerCircleIdx, y);
+ node.setNodeValue(map[x - innerCircleIdx][y]);
+ node.setZ(z);
+ if (node.getNodeValue().equals(startNode.getNodeValue())) {
+ nodes.add(node);
+ }
+ }
+
+ if (is_valid(map, x, y + innerCircleIdx)) {
+ NavigateNode node = new NavigateNode(x, y + innerCircleIdx);
+ node.setNodeValue(map[x][y + innerCircleIdx]);
+ node.setZ(z);
+ if (node.getNodeValue().equals(startNode.getNodeValue())) {
+ nodes.add(node);
+ }
+ }
+
+ if (is_valid(map, x, y - innerCircleIdx)) {
+ NavigateNode node = new NavigateNode(x, y - innerCircleIdx);
+ node.setNodeValue(map[x][y - innerCircleIdx]);
+ node.setZ(z);
+ if (node.getNodeValue().equals(startNode.getNodeValue())) {
+ nodes.add(node);
+ }
+ }
+ return nodes;
+ }
+
+ private boolean is_valid(int[][] map, int x, int y) {
+ if (x < 0 || x >= map.length
+ || y < 0 || y >= map[1].length) {
+ return false;
+ }
+ // 濡傛灉缁撶偣鐨勪綅缃皬浜�0锛屽垯涓嶅悎娉�
+ if (map[x][y] < 0) {
+ return false;
+ }
+
+ //浠ヤ笂鎯呭喌閮芥病鏈夊垯鍚堟硶
+ return true;
}
// private boolean checkSimilarityPath(Motion motion, ShuttleAssignCommand assignCommand) {
@@ -235,170 +634,6 @@
// }
//
// return true;
-// }
-
-// /**
-// * 璁$畻骞惰幏鍙栧皬杞︿粠璧风偣鈥斺�斾腑闂寸偣鈥斺�旂洰鏍囩偣涔嬮棿鎼繍璐х墿鍔ㄤ綔鍛戒护
-// * @param shuttleNo 灏忚溅鍙�
-// * @param wrkNo 宸ヤ綔鍙�
-// * @param startPoint 璧风偣锛堝皬杞﹀綋鍓嶄綅缃級
-// * @param targetPoint 鐩爣鐐癸紙璐х墿鐩爣浣嶇疆锛�
-// */
-// public static synchronized ShuttleOperaResult getShuttleTransportCommands(Integer shuttleNo, Integer wrkNo, String startPoint, String targetPoint) {
-// //琛岃蛋璺緞
-// ArrayList<NavigateNode> nodes = new ArrayList<>();
-// //鍛戒护闆嗗悎
-// ArrayList<NyShuttleHttpCommand> commands = new ArrayList<>();
-//
-// //璁$畻璧风偣鍒扮洰鏍囩偣鍛戒护
-// ShuttleOperaResult result = getStartToTargetCommands(shuttleNo, wrkNo, startPoint, targetPoint, NavigationMapType.DFX.id);
-// if (result == null) {
-// //璁$畻缁撴灉蹇呴』涓嶄负绌猴紝鍚﹀垯璁$畻澶辫触
-// return null;
-// }
-// nodes.addAll(result.getNodes());
-// //璧风偣浣嶇疆涓嬪彂涓�鏉¢《鍗囧懡浠ゅ皢璐х墿杩涜鎼繍
-// commands.add(NyHttpUtils.getPalletLiftCommand(shuttleNo, wrkNo, true));
-// commands.addAll(result.getCommands());//璧风偣鍒扮洰鏍囩偣绉诲姩鍛戒护
-// //褰撳皬杞﹁璧板埌鐩爣鐐瑰悗锛岄渶瑕佷笅鍙戜竴鏉′笅闄嶅懡浠ゅ皢璐х墿鏀剧疆
-// commands.add(NyHttpUtils.getPalletLiftCommand(shuttleNo, wrkNo, false));
-// return result(commands, nodes);
-// }
-//
-// /**
-// * 璁$畻骞惰幏鍙栧皬杞︿粠璧风偣鈥斺�斾腑闂寸偣鈥斺�旂洰鏍囩偣涔嬮棿鎼繍璐х墿鍔ㄤ綔鍛戒护
-// * @param shuttleNo 灏忚溅鍙�
-// * @param wrkNo 宸ヤ綔鍙�
-// * @param startPoint 璧风偣锛堝皬杞﹀綋鍓嶄綅缃級
-// * @param middlePoint 涓棿鐐癸紙璐х墿浣嶇疆锛�
-// * @param targetPoint 鐩爣鐐癸紙璐х墿鐩爣浣嶇疆锛�
-// */
-// public static synchronized ShuttleOperaResult getShuttleTransportCommands(Integer shuttleNo, Integer wrkNo, String startPoint, String middlePoint, String targetPoint) {
-// //琛岃蛋璺緞
-// ArrayList<NavigateNode> nodes = new ArrayList<>();
-// //鍛戒护闆嗗悎
-// ArrayList<NyShuttleHttpCommand> commands = new ArrayList<>();
-//
-// if (!startPoint.equals(middlePoint)) {//璧风偣鍜屼腑闂寸偣涓嶄竴鑷达紝闇�瑕佽绠楄捣鐐瑰埌涓棿鐐硅矾寰�
-// //璁$畻璧风偣鍒颁腑闂寸偣鍛戒护
-// ShuttleOperaResult result1 = getStartToTargetCommands(shuttleNo, wrkNo, startPoint, middlePoint, NavigationMapType.NORMAL.id);
-// if (result1 == null) {
-// //璁$畻缁撴灉蹇呴』涓嶄负绌猴紝鍚﹀垯璁$畻澶辫触
-// return null;
-// }
-// nodes.addAll(result1.getNodes());
-// commands.addAll(result1.getCommands());
-// }
-//
-// //璁$畻涓棿鐐瑰埌鐩爣鐐瑰懡浠�
-// ShuttleOperaResult result2 = getStartToTargetCommands(shuttleNo, wrkNo, middlePoint, targetPoint, NavigationMapType.DFX.id);
-// if (result2 == null) {
-// //璁$畻缁撴灉蹇呴』涓嶄负绌猴紝鍚﹀垯璁$畻澶辫触
-// return null;
-// }
-// nodes.addAll(result2.getNodes());
-// //褰撳皬杞﹁璧板埌涓棿鐐瑰悗锛岄渶瑕佷笅鍙戜竴鏉¢《鍗囧懡浠ゅ皢璐х墿杩涜鎼繍
-// commands.add(NyHttpUtils.getPalletLiftCommand(shuttleNo, wrkNo, true));
-// commands.addAll(result2.getCommands());//涓棿鐐瑰埌鐩爣鐐圭Щ鍔ㄥ懡浠�
-// //褰撳皬杞﹁璧板埌鐩爣鐐瑰悗锛岄渶瑕佷笅鍙戜竴鏉′笅闄嶅懡浠ゅ皢璐х墿鏀剧疆
-// commands.add(NyHttpUtils.getPalletLiftCommand(shuttleNo, wrkNo, false));
-// return result(commands, nodes);
-// }
-//
-// /**
-// * 鑾峰彇璧风偣鍒扮洰鏍囩偣琛岃蛋鍛戒护
-// */
-// public synchronized ShuttleOperaResult getStartToTargetCommands(Integer shuttleNo, Integer wrkNo, String startPoint, String targetPoint, Integer mapType) {
-// NavigateMapUtils navigateMapUtils = SpringUtils.getBean(NavigateMapUtils.class);
-// //璁$畻璧风偣鍒扮洰鏍囩偣琛岃蛋鑺傜偣
-// List<NavigateNode> calc = NavigateUtils.calc(startPoint, targetPoint, mapType, Utils.getShuttlePoints(shuttleNo, Utils.getLev(startPoint)), null);
-// if (calc == null) {
-// return null;
-// }
-//
-// //鍛戒护闆嗗悎
-// ArrayList<NyShuttleHttpCommand> commands = new ArrayList<>();
-// List<NavigateNode> allNode = new ArrayList<>();
-//
-// //鑾峰彇鍒嗘璺緞
-// ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(calc);
-// //灏嗘瘡涓�娈佃矾寰勫垎鎴恈ommand鎸囦护
-// for (ArrayList<NavigateNode> nodes : data) {
-// //寮�濮嬭矾寰�
-// NavigateNode startPath = nodes.get(0);
-// //鐩爣璺緞
-// NavigateNode targetPath = nodes.get(nodes.size() - 1);
-// //鑾峰彇绉诲姩鍛戒护
-// NyShuttleHttpCommand moveCommand = NyHttpUtils.getMoveCommand(shuttleNo, wrkNo, startPath, targetPath);
-// moveCommand.setNodes(nodes);//灏嗚璧拌妭鐐规坊鍔犲埌姣忎竴姝ュ懡浠や腑
-// commands.add(moveCommand);
-//
-// allNode.addAll(nodes);
-// }
-//
-// boolean result = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(startPoint), shuttleNo, allNode, true);//閿佸畾璺緞
-// if (!result) {
-// return null;//璺緞閿佸畾澶辫触
-// }
-// return result(commands, calc);
-// }
-//
-// /**
-// * 鑾峰彇璧风偣鍒扮洰鏍囩偣琛岃蛋鍛戒护(鍙紶鐧藉悕鍗�)
-// */
-// public static synchronized ShuttleOperaResult getStartToTargetCommandsByWhites(Integer shuttleNo, Integer wrkNo, String startPoint, String targetPoint, Integer mapType, List<int[]> whites) {
-// NavigateMapUtils navigateMapUtils = SpringUtils.getBean(NavigateMapUtils.class);
-// //璁$畻璧风偣鍒扮洰鏍囩偣琛岃蛋鑺傜偣
-// List<NavigateNode> calc = NavigateUtils.calc(startPoint, targetPoint, mapType, Utils.getShuttlePoints(shuttleNo, Utils.getLev(startPoint)), whites);
-// if (calc == null) {
-// return null;
-// }
-//
-// //鍛戒护闆嗗悎
-// ArrayList<NyShuttleHttpCommand> commands = new ArrayList<>();
-// List<NavigateNode> allNode = new ArrayList<>();
-//
-// //鑾峰彇鍒嗘璺緞
-// ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(calc);
-// //灏嗘瘡涓�娈佃矾寰勫垎鎴恈ommand鎸囦护
-// for (ArrayList<NavigateNode> nodes : data) {
-// //寮�濮嬭矾寰�
-// NavigateNode startPath = nodes.get(0);
-// //鐩爣璺緞
-// NavigateNode targetPath = nodes.get(nodes.size() - 1);
-// //鑾峰彇绉诲姩鍛戒护
-// NyShuttleHttpCommand moveCommand = NyHttpUtils.getMoveCommand(shuttleNo, wrkNo, startPath, targetPath);
-// moveCommand.setNodes(nodes);//灏嗚璧拌妭鐐规坊鍔犲埌姣忎竴姝ュ懡浠や腑
-// commands.add(moveCommand);
-//
-// allNode.addAll(nodes);
-// }
-//
-// //閿佸畾璺緞鏃跺墧闄ょ櫧鍚嶅崟鑺傜偣
-// ArrayList<NavigateNode> nodes = new ArrayList<>();
-// for (NavigateNode node : allNode) {
-// boolean flag = false;
-// for (int[] white : whites) {
-// if (node.getX() == white[0] && node.getY() == white[1]) {
-// flag = true;//瀛樺湪鐧藉悕鍗曡妭鐐�
-// break;//璺宠繃鐧藉悕鍗曡妭鐐�
-// }
-// }
-//
-// if (!flag) {
-// nodes.add(node);
-// }
-// }
-// boolean result = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(startPoint), shuttleNo, nodes, true);//閿佸畾璺緞
-// if (!result) {
-// return null;//璺緞閿佸畾澶辫触
-// }
-// return result(commands, calc);
-// }
-//
-// //杩斿洖缁撴灉闆�
-// public static ShuttleOperaResult result(List<NyShuttleHttpCommand> commands, List<NavigateNode> nodes) {
-// return new ShuttleOperaResult(commands, nodes);
// }
}
--
Gitblit v1.9.1