From 2cfa8856fb1fd1ad7f642fd998d1644879abcdb5 Mon Sep 17 00:00:00 2001
From: Junjie <540245094@qq.com>
Date: 星期四, 25 七月 2024 10:02:24 +0800
Subject: [PATCH] #
---
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/NavigateMapUtils.java | 105 +++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 90 insertions(+), 15 deletions(-)
diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/NavigateMapUtils.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/NavigateMapUtils.java
index 00a447e..fb4052f 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/NavigateMapUtils.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/NavigateMapUtils.java
@@ -1,12 +1,17 @@
package com.zy.asrs.wcs.core.utils;
import com.alibaba.fastjson.JSON;
-import com.zy.asrs.common.wms.entity.BasMap;
-import com.zy.asrs.framework.common.SpringUtils;
+import com.alibaba.fastjson.serializer.SerializerFeature;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.zy.asrs.wcs.core.domain.dto.RedisMapDto;
import com.zy.asrs.wcs.core.model.MapNode;
import com.zy.asrs.wcs.core.model.NavigateNode;
+import com.zy.asrs.wcs.core.model.enums.MapNodeType;
import com.zy.asrs.wcs.core.model.enums.NavigationMapType;
import com.zy.asrs.wcs.rcs.constant.DeviceRedisConstant;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
@@ -16,19 +21,24 @@
@Component
public class NavigateMapUtils {
+ @Autowired
+ private NavigateMapData navigateMapData;
+ @Autowired
+ private RedisUtil redisUtil;
+ @Autowired
+ private ObjectMapper objectMapper;
+
/**
* 鍐欏叆璺緞鑺傜偣鏁版嵁鍒皉edis鍦板浘涓�
* lock涓簍rue 绂佺敤搴撲綅锛宭ock涓篺alse鎭㈠搴撲綅
*/
public synchronized boolean writeNavigateNodeToRedisMap(Integer lev, Integer shuttleNo, List<NavigateNode> nodes, boolean lock) {
- RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class);
try {
if (nodes.isEmpty()) {
return true;
}
- NavigateMapData navigateMapData = new NavigateMapData(lev);
-
+ navigateMapData.setLev(lev);
Object o = redisUtil.get(DeviceRedisConstant.MAP + lev);
if (o == null) {
return false;
@@ -37,8 +47,8 @@
//鑾峰彇灏忚溅鑺傜偣
List<int[]> shuttlePoints = Utils.getShuttlePoints(shuttleNo, lev);
- BasMap basMap = JSON.parseObject(o.toString(), BasMap.class);
- ArrayList arrayList = JSON.parseObject(basMap.getData(), ArrayList.class);
+ RedisMapDto redisMap = JSON.parseObject(o.toString(), RedisMapDto.class);
+ ArrayList arrayList = JSON.parseObject(redisMap.getData(), ArrayList.class);
//甯﹀皬杞﹀湴鍥�
List<List<MapNode>> listsHasShuttle = navigateMapData.filterMap(NavigationMapType.NONE.id, arrayList, lev, null, shuttlePoints);//鑾峰彇甯﹀皬杞﹀湴鍥炬暟鎹�
List<List<MapNode>> lists = navigateMapData.filterMap(NavigationMapType.NONE.id, arrayList, lev, null, null);//鑾峰彇鍏ㄩ儴鍦板浘鏁版嵁
@@ -48,18 +58,18 @@
for (NavigateNode node : nodes) {
List<MapNode> listX = listsHasShuttle.get(node.getX());
MapNode mapNode = listX.get(node.getY());
- if (mapNode.getValue() == -999) {
+ if (mapNode.getValue() == MapNodeType.LOCK.id) {
return false;//璺緞琚攣瀹氳繃锛岀姝㈠啀娆¢攣瀹�
}
- if (mapNode.getValue() == 66) {
+ if (mapNode.getValue() == MapNodeType.CAR.id) {
return false;//璺緞瀛樺湪灏忚溅锛岀姝㈤攣瀹�
}
}
}
//灏濊瘯閿佸畾/瑙i攣璺緞
- NavigateMapData mapData = new NavigateMapData(nodes.get(0).getZ());
- List<List<MapNode>> realMap = mapData.getJsonData(-1, null, null);//鑾峰彇瀹屾暣鍦板浘(鍖呮嫭鍏ュ簱鍑哄簱)
+ navigateMapData.setLev(nodes.get(0).getZ());
+ List<List<MapNode>> realMap = navigateMapData.getJsonDataFromDict(-1, null, null);//鑾峰彇瀹屾暣鍦板浘(鍖呮嫭鍏ュ簱鍑哄簱)
for (NavigateNode node : nodes) {
if (node.getZ() != lev) {
continue;
@@ -68,7 +78,7 @@
List<MapNode> listX = lists.get(node.getX());
MapNode mapNode = listX.get(node.getY());
if (lock) {
- mapNode.setValue(-999);//绂佺敤搴撲綅
+ mapNode.setValue(MapNodeType.LOCK.id);//绂佺敤搴撲綅
} else {
//鑾峰彇鍘熷鑺傜偣鏁版嵁
List<MapNode> rows = realMap.get(node.getX());
@@ -79,10 +89,13 @@
listX.set(node.getY(), mapNode);
lists.set(node.getX(), listX);
}
- basMap.setData(JSON.toJSONString(lists));
- basMap.setUpdateTime(new Date());
+ redisMap.setData(JSON.toJSONString(lists));
+ redisMap.setUpdateTime(new Date());
//灏嗘暟鎹簱鍦板浘鏁版嵁瀛樺叆redis
- redisUtil.set(DeviceRedisConstant.MAP + lev, JSON.toJSONString(basMap));
+ redisUtil.set(DeviceRedisConstant.MAP + lev, JSON.toJSONString(redisMap, SerializerFeature.DisableCircularReferenceDetect));
+
+ //淇濆瓨璺緞閿佽妭鐐�
+ saveLockPath(lev, nodes, lock);
return true;
} catch (Exception e) {
e.printStackTrace();
@@ -90,4 +103,66 @@
return false;
}
+ //淇濆瓨璺緞閿佽妭鐐�
+ public void saveLockPath(Integer lev, List<NavigateNode> nodes, boolean lock) {
+ Object o = redisUtil.get(DeviceRedisConstant.LOCK_PATH + lev);
+ List<NavigateNode> navigateNodes = new ArrayList<>();
+ if (o != null) {
+ try {
+ navigateNodes = objectMapper.readValue(o.toString(), new TypeReference<List<NavigateNode>>() {});
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ String nodeStr = null;
+ if (lock) {
+ navigateNodes.addAll(nodes);
+ try {
+ nodeStr = objectMapper.writeValueAsString(navigateNodes);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ redisUtil.set(DeviceRedisConstant.LOCK_PATH + lev, nodeStr);
+ }else {
+ List<NavigateNode> tmp = new ArrayList<>();
+ for (NavigateNode navigateNode : navigateNodes) {
+ boolean flag = true;
+ for (NavigateNode node : nodes) {
+ if (navigateNode.getX() == node.getX()
+ && navigateNode.getY() == node.getY()
+ && navigateNode.getZ() == node.getZ()) {
+ flag = false;
+ break;
+ }
+ }
+
+ if (flag) {
+ tmp.add(navigateNode);
+ }
+ }
+
+ try {
+ nodeStr = objectMapper.writeValueAsString(tmp);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ redisUtil.set(DeviceRedisConstant.LOCK_PATH + lev, nodeStr);
+ }
+ }
+
+ //鑾峰彇璺緞閿佽妭鐐�
+ public List<NavigateNode> getLockPath(Integer lev) {
+ Object obj = redisUtil.get(DeviceRedisConstant.LOCK_PATH + lev);
+ List<NavigateNode> navigateNodes = new ArrayList<>();
+ if (obj != null) {
+ try {
+ navigateNodes = objectMapper.readValue(obj.toString(), new TypeReference<List<NavigateNode>>() {});
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ return navigateNodes;
+ }
+
}
--
Gitblit v1.9.1