From 46d68076bfa7b706549e0420dfe09314024e3696 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期五, 22 十一月 2024 21:02:39 +0800
Subject: [PATCH] #读取地图文件优化
---
src/main/java/com/zy/core/thread/NyShuttleThread.java | 181 +++++++++++++++++++++++++++++++-------------
1 files changed, 127 insertions(+), 54 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/NyShuttleThread.java b/src/main/java/com/zy/core/thread/NyShuttleThread.java
index 9ad6f5a..c382847 100644
--- a/src/main/java/com/zy/core/thread/NyShuttleThread.java
+++ b/src/main/java/com/zy/core/thread/NyShuttleThread.java
@@ -10,7 +10,6 @@
import com.zy.asrs.utils.Utils;
import com.zy.common.model.NavigateNode;
-import com.zy.common.model.NyShuttleOperaResult;
import com.zy.common.service.CommonService;
import com.zy.common.utils.*;
import com.zy.core.News;
@@ -29,7 +28,6 @@
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
-import javax.swing.*;
import java.io.IOException;
import java.net.Socket;
import java.text.MessageFormat;
@@ -115,12 +113,6 @@
private void readStatus() {
try {
- if (null == shuttleProtocol) {
- shuttleProtocol = new NyShuttleProtocol();
- shuttleProtocol.setShuttleNo(slave.getId().shortValue());
- shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
- }
-
//----------璇诲彇鍥涘悜绌挎杞︾姸鎬�-----------
NyShuttleHttpCommand readStatusCommand = NyHttpUtils.getReadStatusCommand(slave.getId());
JSONObject jsonObject = NyHttpUtils.requestCommand(socket, readStatusCommand);
@@ -180,6 +172,8 @@
shuttleProtocol.setStatusSum(jsonObject.getObject("statusSum", NyShuttleProtocol.StatusSumClass.class));
//闈炶嚜鍔ㄧ姸鎬佹椂闂磋鏃�
shuttleProtocol.setErrTime(jsonObject.getInteger("errTime"));
+ //鏈�杩戜竴娆″湪绾挎椂闂�
+ shuttleProtocol.setLastOnlineTime(System.currentTimeMillis());
//灏忚溅澶勪簬杩愯涓紝灏嗘爣璁扮疆涓篺alse
if (shuttleProtocol.getFree() == 0) {
@@ -249,6 +243,23 @@
OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
// log.info(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
}
+// log.warn(JSON.toJSONString(shuttleProtocol));//杈撳嚭灏忚溅鐘舵��
+
+ if (System.currentTimeMillis() - shuttleProtocol.getDeviceDataLog() > 1000 * 5) {
+ //閲囬泦鏃堕棿瓒呰繃5s锛屼繚瀛樹竴娆℃暟鎹褰�
+ //淇濆瓨鏁版嵁璁板綍
+ DeviceDataLogService deviceDataLogService = SpringUtils.getBean(DeviceDataLogService.class);
+ DeviceDataLog deviceDataLog = new DeviceDataLog();
+ deviceDataLog.setOriginData(JSON.toJSONString(jsonObject));
+ deviceDataLog.setWcsData(JSON.toJSONString(shuttleProtocol));
+ deviceDataLog.setType("shuttle");
+ deviceDataLog.setDeviceNo(shuttleProtocol.getShuttleNo().intValue());
+ deviceDataLog.setCreateTime(new Date());
+ deviceDataLogService.insert(deviceDataLog);
+
+ //鏇存柊閲囬泦鏃堕棿
+ shuttleProtocol.setDeviceDataLog(System.currentTimeMillis());
+ }
}
} catch (Exception e) {
e.printStackTrace();
@@ -271,6 +282,11 @@
socket.setSoTimeout(60000);
socket.setKeepAlive(true);
this.socket = socket;
+ if (null == shuttleProtocol) {
+ shuttleProtocol = new NyShuttleProtocol();
+ shuttleProtocol.setShuttleNo(slave.getId().shortValue());
+ }
+ shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
log.info(MessageFormat.format("銆恵0}銆戝洓鍚戠┛姊溅Socket閾炬帴鎴愬姛 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
} catch (IOException e) {
OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆戝洓鍚戠┛姊溅Socket閾炬帴澶辫触 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
@@ -344,6 +360,9 @@
if (result == null) {
return false;//璇锋眰澶辫触
}
+
+ shuttleProtocol.setSendTime(System.currentTimeMillis());//鎸囦护涓嬪彂鏃堕棿
+
return true;
}
@@ -358,7 +377,7 @@
shuttleProtocol.setAssignCommand(assignCommand);
shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WORKING);
//浠诲姟鏁版嵁淇濆瓨鍒皉edis
- redisUtil.set("shuttle_wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(redisCommand));
+ redisUtil.set(RedisKeyType.SHUTTLE.key + assignCommand.getTaskNo(), JSON.toJSONString(redisCommand));
//鎵ц涓嬪彂浠诲姟
executeWork(assignCommand.getTaskNo());
}
@@ -370,10 +389,11 @@
return false;
}
+ NavigateMapUtils navigateMapUtils = SpringUtils.getBean(NavigateMapUtils.class);
WrkMastMapper wrkMastMapper = SpringUtils.getBean(WrkMastMapper.class);
WrkMast wrkMast = wrkMastMapper.selectByWorkNo(wrkNo.intValue());
- Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo);
+ Object o = redisUtil.get(RedisKeyType.SHUTTLE.key + wrkNo);
if (o == null) {
return false;
}
@@ -388,8 +408,6 @@
}
checkIOSta(commands, commandStep);//妫�娴嬪皬杞︽槸鍚﹁繘鍑烘彁鍗囨満杈撻�佺珯
-
- NavigateMapData navigateMapData = new NavigateMapData(Utils.getLev(shuttleProtocol.getCurrentLocNo()));
boolean isLock = false;//鏄惁瑙i攣璺緞
//鍙栧嚭鍛戒护
@@ -408,13 +426,21 @@
//涓婁竴鏉℃寚浠ょ殑鐩爣浣嶇疆鍜屽綋鍓嶅皬杞︿綅缃浉鍚岋紝鍒欒瀹氫笂涓�鏉′换鍔″畬鎴�
lastCommand.setComplete(true);
//瑙i攣閿佸畾璺緞锛屼笂涓�鏉¤矾寰�
- List<NavigateNode> nodes = lastCommand.getNodes();
+ List<NavigateNode> nodes = JSON.parseArray(JSON.toJSONString(lastCommand.getNodes()), NavigateNode.class);//杩涜娣卞害copy
// //瑙i攣褰撳墠璺緞
// if (command != null && command.getNodes() != null) {
// nodes.addAll(command.getNodes());
// }
if (nodes != null) {
- navigateMapData.writeNavigateNodeToRedisMap(nodes, false);//瑙i攣璺緞
+ NavigateNode targetNode = assignCommand.getNodes().get(assignCommand.getNodes().size() - 1);//鏈�缁堣妭鐐�
+ NavigateNode node = nodes.get(nodes.size() - 1);
+ if (!(targetNode.getX() == node.getX() && targetNode.getY() == node.getY())) {
+ nodes.remove(nodes.size() - 1);//鍓旈櫎灏捐妭鐐�
+ }
+ boolean result = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(shuttleProtocol.getCurrentLocNo()), shuttleProtocol.getShuttleNo().intValue(), nodes, false);//瑙i攣璺緞
+ if (!result) {
+ return false;//瑙i攣澶辫触
+ }
isLock = true;//瑙i攣杩囪矾寰�
}
}
@@ -422,7 +448,7 @@
lastCommand.setComplete(true);//鍏朵粬鍛戒护榛樿璁や负瀹屾垚
}
//浠诲姟鏁版嵁淇濆瓨鍒皉edis
- redisUtil.set("shuttle_wrk_no_" + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
+ redisUtil.set(RedisKeyType.SHUTTLE.key + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
if (!lastCommand.getComplete()) {
//涓婁竴鏉′换鍔℃湭瀹屾垚锛岀姝笅鍙戝懡浠�
@@ -433,7 +459,7 @@
NyShuttleHttpCommand endCommand = commands.get(commands.size() - 1);
if (endCommand.getComplete()) {
//鍒犻櫎redis
- redisUtil.del("shuttle_wrk_no_" + redisCommand.getWrkNo());
+ redisUtil.del(RedisKeyType.SHUTTLE.key + redisCommand.getWrkNo());
if (!assignCommand.getCharge()) {
//瀵逛富绾跨▼鎶涘嚭绛夊緟纭鐘舵�亀aiting
@@ -471,38 +497,41 @@
return false;
}
- if (command.getRequest().getBody().get("requestType").equals("move")) {
- ArrayList<int[]> whiteList = new ArrayList<>();//璁剧疆鑺傜偣鐨勭櫧鍚嶅崟
- if (wrkMast != null && ((wrkMast.getIoType() > 100 && wrkMast.getIoType() < 200) || wrkMast.getIoType() == 11)) {
- //鍑哄簱浠诲姟锛屼笉妫�娴嬮鑺傜偣
- int[] startArr = NavigatePositionConvert.positionToXY(wrkMast.getSourceLocNo());//寮�濮嬭妭鐐�
- whiteList.add(startArr);
- }
-
- //瑙i攣杩囪矾寰勶紝鍙娴嬩笅涓�娈佃矾寰勬槸鍚﹀彲璧�(褰撳墠璺緞宸茬粡琚攣瀹氭棤闇�鍐嶆娴�)
- if (isLock) {
- //鍙娴嬩笅涓�娈佃矾寰勬槸鍚﹀彲璧�(褰撳墠璺緞宸茬粡琚攣瀹氭棤闇�鍐嶆娴�)
- //妫�娴嬭矾寰勬槸鍚﹀彲琛岃蛋
- if (!checkPath(nextNodes == null ? command.getNodes() : nextNodes, null, whiteList)) {
- return false;
- }
- }else {
- //妫�娴嬪綋鍓嶈矾寰勫拰涓嬩竴娈佃矾寰�
- //妫�娴嬭矾寰勬槸鍚﹀彲琛岃蛋
- if (!checkPath(command.getNodes(), nextNodes, whiteList)) {
- return false;
- }
- }
-
- //閿佸畾璺緞锛岄攣瀹氬綋鍓嶈矾寰勫拰涓嬩竴姝ヨ矾寰�
- List<NavigateNode> nodes = command.getNodes();
- if (nextNodes != null) {
- nodes.addAll(nextNodes);
- }
- if (nodes != null) {
- navigateMapData.writeNavigateNodeToRedisMap(nodes, true);//鎵�浣跨敤鐨勮矾寰勮繘琛岄攣瀹氱鐢�
- }
- }
+// if (command.getRequest().getBody().get("requestType").equals("move")) {
+// ArrayList<int[]> whiteList = new ArrayList<>();//璁剧疆鑺傜偣鐨勭櫧鍚嶅崟
+// if (wrkMast != null && ((wrkMast.getIoType() > 100 && wrkMast.getIoType() < 200) || wrkMast.getIoType() == 11)) {
+// //鍑哄簱浠诲姟锛屼笉妫�娴嬮鑺傜偣
+// int[] startArr = NavigatePositionConvert.positionToXY(wrkMast.getSourceLocNo());//寮�濮嬭妭鐐�
+// whiteList.add(startArr);
+// }
+//
+// //瑙i攣杩囪矾寰勶紝鍙娴嬩笅涓�娈佃矾寰勬槸鍚﹀彲璧�(褰撳墠璺緞宸茬粡琚攣瀹氭棤闇�鍐嶆娴�)
+// if (isLock) {
+// //鍙娴嬩笅涓�娈佃矾寰勬槸鍚﹀彲璧�(褰撳墠璺緞宸茬粡琚攣瀹氭棤闇�鍐嶆娴�)
+// //妫�娴嬭矾寰勬槸鍚﹀彲琛岃蛋
+// if (!checkPath(nextNodes == null ? command.getNodes() : nextNodes, null, whiteList)) {
+// return false;
+// }
+// }else {
+// //妫�娴嬪綋鍓嶈矾寰勫拰涓嬩竴娈佃矾寰�
+// //妫�娴嬭矾寰勬槸鍚﹀彲琛岃蛋
+// if (!checkPath(command.getNodes(), nextNodes, whiteList)) {
+// return false;
+// }
+// }
+//
+// //閿佸畾璺緞锛岄攣瀹氬綋鍓嶈矾寰勫拰涓嬩竴姝ヨ矾寰�
+// List<NavigateNode> nodes = command.getNodes();
+// if (nextNodes != null) {
+// nodes.addAll(nextNodes);
+// }
+// if (nodes != null) {
+// boolean result = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(shuttleProtocol.getCurrentLocNo()), nodes, true);//鎵�浣跨敤鐨勮矾寰勮繘琛岄攣瀹氱鐢�
+// if (!result) {
+// return false;//璺緞閿佸畾澶辫触
+// }
+// }
+// }
//鍙墽琛屽懡浠�
if (!write(command, assignCommand)) {
@@ -524,7 +553,7 @@
//鏇存柊redis鏁版嵁
redisCommand.setCommandStep(commandStep);
//浠诲姟鏁版嵁淇濆瓨鍒皉edis
- redisUtil.set("shuttle_wrk_no_" + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
+ redisUtil.set(RedisKeyType.SHUTTLE.key + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
return true;
}
@@ -536,7 +565,7 @@
return false;
}
- Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo);
+ Object o = redisUtil.get(RedisKeyType.SHUTTLE.key + wrkNo);
if (o == null) {
return false;
}
@@ -620,7 +649,7 @@
return false;
}
- Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo);
+ Object o = redisUtil.get(RedisKeyType.SHUTTLE.key + wrkNo);
if (o == null) {
return false;
}
@@ -706,7 +735,7 @@
// assignCommand.setCommands(commands);
// redisCommand.setAssignCommand(assignCommand);
// //浠诲姟鏁版嵁淇濆瓨鍒皉edis
-// redisUtil.set("shuttle_wrk_no_" + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
+// redisUtil.set(RedisKeyType.SHUTTLE.key + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
// return false;//褰撳墠涓嶅彲琛岃蛋锛岀瓑寰呬笅涓�娆℃墽琛岃蛋鏂拌矾寰�
// }
@@ -773,7 +802,7 @@
}
}
}
- }else {//璺戝簱浣�
+ } else if (shuttleProtocol.getMoveType() == 1) {//璺戝簱浣�
Integer xCurrent = shuttleProtocol.getXCurrent();
if (xCurrent > shuttleProtocol.getXTarget()) {//褰揦鍊煎ぇ浜嶺鐩爣鍊硷紝杩涜褰掗浂涓擸鏂瑰悜+1
shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());
@@ -797,12 +826,56 @@
//璋冨害鍘荤洰鏍囦綅缃�
if (shuttleProtocol.getCurrentLocNo().equals(target.getLocNo())) {
shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);//灏忚溅鍜岀洰鏍囦綅缃竴鑷达紝璺宠繃
- }else {
+ } else {
boolean result = shuttleDispatchUtils.dispatchShuttle(commonService.getWorkNo(3), target.getLocNo());
if (result) {//璋冨害鎴愬姛
shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
}
}
+ } else if (shuttleProtocol.getMoveType() == 2) {//姣嶈建閬撳惊鐜窇
+ Integer xCurrent = shuttleProtocol.getXCurrent();
+ Integer yCurrent = shuttleProtocol.getYCurrent();
+
+ String locNo = Utils.getLocNo(xCurrent, yCurrent, lev);
+ //璋冨害鍘荤洰鏍囦綅缃�
+ if (shuttleProtocol.getCurrentLocNo().equals(locNo)) {
+ if (yCurrent.equals(shuttleProtocol.getYStart())) {
+ shuttleProtocol.setYCurrent(shuttleProtocol.getYTarget());//灏忚溅鍜岀洰鏍囦綅缃竴鑷达紝鍒囨崲搴撲綅
+ }else {
+ shuttleProtocol.setYCurrent(shuttleProtocol.getYStart());//灏忚溅鍜岀洰鏍囦綅缃竴鑷达紝鍒囨崲搴撲綅
+ }
+ } else {
+ boolean result = shuttleDispatchUtils.dispatchShuttle(commonService.getWorkNo(3), locNo);
+ if (result) {//璋冨害鎴愬姛
+ if (yCurrent.equals(shuttleProtocol.getYStart())) {
+ shuttleProtocol.setYCurrent(shuttleProtocol.getYTarget());//鍒囨崲搴撲綅
+ }else {
+ shuttleProtocol.setYCurrent(shuttleProtocol.getYStart());//鍒囨崲搴撲綅
+ }
+ }
+ }
+ } else if (shuttleProtocol.getMoveType() == 3) {//瀛愯建閬撳惊鐜窇
+ Integer xCurrent = shuttleProtocol.getXCurrent();
+ Integer yCurrent = shuttleProtocol.getYCurrent();
+
+ String locNo = Utils.getLocNo(xCurrent, yCurrent, lev);
+ //璋冨害鍘荤洰鏍囦綅缃�
+ if (shuttleProtocol.getCurrentLocNo().equals(locNo)) {
+ if (xCurrent.equals(shuttleProtocol.getXStart())) {
+ shuttleProtocol.setXCurrent(shuttleProtocol.getXTarget());//灏忚溅鍜岀洰鏍囦綅缃竴鑷达紝鍒囨崲搴撲綅
+ }else {
+ shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());//灏忚溅鍜岀洰鏍囦綅缃竴鑷达紝鍒囨崲搴撲綅
+ }
+ } else {
+ boolean result = shuttleDispatchUtils.dispatchShuttle(commonService.getWorkNo(3), locNo);
+ if (result) {//璋冨害鎴愬姛
+ if (xCurrent.equals(shuttleProtocol.getXStart())) {
+ shuttleProtocol.setXCurrent(shuttleProtocol.getXTarget());//鍒囨崲搴撲綅
+ }else {
+ shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());//鍒囨崲搴撲綅
+ }
+ }
+ }
}
}
--
Gitblit v1.9.1