From 26419bf11ec888de7af9141a0ac1874065775e61 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期六, 04 十一月 2023 13:59:51 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/NyShuttleThread.java | 279 ++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 222 insertions(+), 57 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/NyShuttleThread.java b/src/main/java/com/zy/core/thread/NyShuttleThread.java
index f2602a8..255604a 100644
--- a/src/main/java/com/zy/core/thread/NyShuttleThread.java
+++ b/src/main/java/com/zy/core/thread/NyShuttleThread.java
@@ -11,6 +11,7 @@
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;
import com.zy.core.ThreadHandler;
@@ -28,11 +29,13 @@
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
+import javax.swing.*;
import java.io.IOException;
import java.net.Socket;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Date;
+import java.util.HashMap;
import java.util.List;
/**
@@ -98,6 +101,11 @@
&& !shuttleProtocol.getPakMk()) {
//鎵ц涓嬩竴姝ユ寚浠�
executeWork(shuttleProtocol.getTaskNo().shortValue());
+ }
+
+ //灏忚溅绌洪棽涓旀湁璺戝簱绋嬪簭
+ if (shuttleProtocol.isIdle() && shuttleProtocol.getMoveLoc()) {
+ moveLoc();
}
} catch (Exception e) {
e.printStackTrace();
@@ -329,6 +337,7 @@
);
opt.setSend(1);//宸蹭笅鍙�
opt.setResponse(JSON.toJSONString(result));//璇锋眰鍝嶅簲
+ opt.setDeviceWrk(command.getWrkNo().toString());//璁惧宸ヤ綔鍙�
shuttleOptService.insert(opt);
}
@@ -361,7 +370,9 @@
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);
if (o == null) {
@@ -377,8 +388,9 @@
return false;
}
- NavigateMapData navigateMapData = new NavigateMapData(Utils.getLev(shuttleProtocol.getCurrentLocNo()));
+ checkIOSta(commands, commandStep);//妫�娴嬪皬杞︽槸鍚﹁繘鍑烘彁鍗囨満杈撻�佺珯
+ boolean isLock = false;//鏄惁瑙i攣璺緞
//鍙栧嚭鍛戒护
NyShuttleHttpCommand command = null;
if (commandStep < commands.size()) {
@@ -394,13 +406,23 @@
if (shuttleProtocol.getPoint().equals(target)) {
//涓婁竴鏉℃寚浠ょ殑鐩爣浣嶇疆鍜屽綋鍓嶅皬杞︿綅缃浉鍚岋紝鍒欒瀹氫笂涓�鏉′换鍔″畬鎴�
lastCommand.setComplete(true);
- //瑙i攣閿佸畾璺緞锛屼笂涓�鏉¤矾寰勫拰褰撳墠璺緞
+ //瑙i攣閿佸畾璺緞锛屼笂涓�鏉¤矾寰�
List<NavigateNode> nodes = lastCommand.getNodes();
- if (command != null && command.getNodes() != null) {
- nodes.addAll(command.getNodes());
- }
+// //瑙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()), nodes, false);//瑙i攣璺緞
+ if (!result) {
+ return false;//瑙i攣澶辫触
+ }
+ isLock = true;//瑙i攣杩囪矾寰�
}
}
}else {
@@ -439,8 +461,9 @@
}
if (shuttleProtocol.getFree() == ShuttleStatusType.BUSY.id) {
- //鍋滄鍏呯數
- if(!(command.getRequest().getBody().get("requestType").equals("stopCharge") && shuttleProtocol.getChargState() == 1)){
+ String requestType = command.getRequest().getBody().get("requestType").toString();
+ //鍋滄鍏呯數 绠″埗鍛戒护
+ if(!(requestType.equals("stopCharge") && shuttleProtocol.getChargState() == 1) && !requestType.equals("resume")){
return false;//灏忚溅鐘舵�佸繖锛岀姝㈡墽琛屽懡浠�
}
}
@@ -455,21 +478,41 @@
return false;
}
- if (command.getRequest().getBody().get("requestType").equals("move")) {
- //妫�娴嬭矾寰勬槸鍚﹀彲琛岃蛋
- if (!checkPath(command.getNodes(), nextNodes, redisCommand)) {
- 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)) {
@@ -492,37 +535,6 @@
redisCommand.setCommandStep(commandStep);
//浠诲姟鏁版嵁淇濆瓨鍒皉edis
redisUtil.set("shuttle_wrk_no_" + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
-
-// //鍒ゆ柇鏁版嵁鏄惁鎵ц瀹屾垚
-// if (commandStep < commands.size() - 1) {
-// commandStep++;
-// //鏇存柊redis鏁版嵁
-// redisCommand.setCommandStep(commandStep);
-// //浠诲姟鏁版嵁淇濆瓨鍒皉edis
-// redisUtil.set("shuttle_wrk_no_" + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
-// }else {
-// //宸叉墽琛屽畬鎴�
-//
-// commandStep = commands.size();
-// //鏇存柊redis鏁版嵁
-// redisCommand.setCommandStep(commandStep);
-// //浠诲姟鏁版嵁淇濆瓨鍒皉edis
-// redisUtil.set("shuttle_wrk_no_" + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
-//// //鏈�鍚庝竴娈靛懡浠や负绉诲姩鍛戒护锛屽垯鏆傜紦鍒犻櫎redis绛夊緟娓呴櫎璺緞鏃朵竴娆℃�у垹闄�
-//// //鏈�鍚庝竴娈靛懡浠や负涓嶆槸绉诲姩鍛戒护锛屽垯鍒犻櫎redis
-//// if (!command.getRequest().getBody().get("requestType").equals("move")) {
-//// //鍒犻櫎redis
-//// redisUtil.del("shuttle_wrk_no_" + redisCommand.getWrkNo());
-//// }
-////
-//// if (!assignCommand.getCharge()) {
-//// //瀵逛富绾跨▼鎶涘嚭绛夊緟纭鐘舵�亀aiting
-//// shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WAITING);
-//// }else {
-//// shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.CHARGING_WAITING);
-//// }
-//// News.info("鍥涘悜绌挎杞︿换鍔℃墽琛屼笅鍙戝畬鎴愮瓑寰呮墽琛岀粨鏉燂紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
-// }
return true;
}
@@ -658,17 +670,17 @@
* 妫�娴嬭矾寰勬槸鍚﹀彲琛岃蛋
* 濡傛灉璺緞涓虹洰鏍囧簱浣嶏紝浣嗕笉鍙璧帮紝绯荤粺灏嗗皾璇曢噸鏂拌绠楄矾寰�
*/
- private boolean checkPath(List<NavigateNode> currentNodes, List<NavigateNode> nextNodes, ShuttleRedisCommand redisCommand) {
+ private boolean checkPath(List<NavigateNode> currentNodes, List<NavigateNode> nextNodes, List<int[]> whitePoints) {
//妫�娴嬭矾寰勬槸鍚﹀彲琛岃蛋(妫�鏌ヨ矾寰勯攣瀹氱姸鎬侊紝妫�娴嬭矾寰勬槸鍚︽湁鍏朵粬灏忚溅)
//妫�娴嬪綋鍓嶈璧拌矾寰勶紝鍜屼笅涓�姝ヨ矾寰�
- boolean checkPathIsAvailable = NavigateUtils.checkPathIsAvailable(currentNodes, shuttleProtocol.getShuttleNo().intValue(), Utils.getLev(shuttleProtocol.getCurrentLocNo()));
+ boolean checkPathIsAvailable = NavigateUtils.checkPathIsAvailable(currentNodes, shuttleProtocol.getShuttleNo().intValue(), Utils.getLev(shuttleProtocol.getCurrentLocNo()), whitePoints);
if (nextNodes == null) {
if (checkPathIsAvailable) {
return true;//鍙璧�
}
return false;
}else {
- boolean checkPathIsAvailable2 = NavigateUtils.checkPathIsAvailable(nextNodes, shuttleProtocol.getShuttleNo().intValue(), Utils.getLev(shuttleProtocol.getCurrentLocNo()));
+ boolean checkPathIsAvailable2 = NavigateUtils.checkPathIsAvailable(nextNodes, shuttleProtocol.getShuttleNo().intValue(), Utils.getLev(shuttleProtocol.getCurrentLocNo()), whitePoints);
if (checkPathIsAvailable && checkPathIsAvailable2) {
return true;//鍙璧�
}
@@ -711,4 +723,157 @@
return false;//涓嶅彲琛岃蛋
}
+ /**
+ * 璺戝簱绋嬪簭
+ */
+ private void moveLoc() {
+ LocMastService locMastService = SpringUtils.getBean(LocMastService.class);
+ ShuttleDispatchUtils shuttleDispatchUtils = SpringUtils.getBean(ShuttleDispatchUtils.class);
+ CommonService commonService = SpringUtils.getBean(CommonService.class);
+ WrkMastMapper wrkMastMapper = SpringUtils.getBean(WrkMastMapper.class);
+ int lev = Utils.getLev(shuttleProtocol.getCurrentLocNo());//灏忚溅褰撳墠妤煎眰
+ if (!shuttleProtocol.isIdle()) {
+ return;
+ }
+
+ WrkMast wrkMast = wrkMastMapper.selectShuttleHasMoveWorking(shuttleProtocol.getShuttleNo().intValue());
+ if (wrkMast != null) {
+ return;
+ }
+
+ if (shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) {
+ //璺戝簱缁撴潫
+ shuttleProtocol.setMoveLoc(false);
+ shuttleProtocol.setMoveType(0);
+ shuttleProtocol.setXStart(0);
+ shuttleProtocol.setXTarget(0);
+ shuttleProtocol.setXCurrent(0);
+ shuttleProtocol.setYStart(0);
+ shuttleProtocol.setYTarget(0);
+ shuttleProtocol.setYCurrent(0);
+ return;
+ }
+
+ if (shuttleProtocol.getMoveType() == 0) {//璺戣建閬�
+ ArrayList<String> locs = new ArrayList<>();
+ for (int i = shuttleProtocol.getXCurrent(); i <= shuttleProtocol.getXTarget(); i++) {
+ String locNo = Utils.getLocNo(i, shuttleProtocol.getYCurrent(), lev);
+ locs.add(locNo);
+ }
+ List<LocMast> locMasts = locMastService.selectEmptyLocNos(locs);
+ if (locMasts.isEmpty()) {
+ //绌哄簱浣�
+ shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);
+ return;
+ }
+
+ LocMast start = locMasts.get(0);
+ LocMast target = locMasts.get(locMasts.size() - 1);
+ //鍒ゆ柇灏忚溅鏄惁鍦ㄨ捣鐐逛綅缃�
+ if (!shuttleProtocol.getCurrentLocNo().equals(start.getLocNo())) {//涓嶅湪璧风偣浣嶇疆锛岃皟搴﹀幓璧风偣浣嶇疆
+ shuttleDispatchUtils.dispatchShuttle(commonService.getWorkNo(3), start.getLocNo());
+ }else {
+ //鍦ㄨ捣鐐逛綅缃紝璋冨害鍘荤洰鏍囦綅缃�
+ if (shuttleProtocol.getCurrentLocNo().equals(target.getLocNo())) {
+ shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);//灏忚溅鍜岀洰鏍囦綅缃竴鑷达紝璺宠繃
+ }else {
+ boolean result = shuttleDispatchUtils.dispatchShuttle(commonService.getWorkNo(3), target.getLocNo());
+ if (result) {//璋冨害鎴愬姛
+ shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);
+ }
+ }
+ }
+ }else {//璺戝簱浣�
+ Integer xCurrent = shuttleProtocol.getXCurrent();
+ if (xCurrent > shuttleProtocol.getXTarget()) {//褰揦鍊煎ぇ浜嶺鐩爣鍊硷紝杩涜褰掗浂涓擸鏂瑰悜+1
+ shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());
+ shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);
+ return;
+ }
+
+ Integer yCurrent = shuttleProtocol.getYCurrent();
+ String locNo = Utils.getLocNo(xCurrent, yCurrent, lev);
+ LocMast target = locMastService.selectById(locNo);
+ if (target == null) {
+ shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
+ return;
+ }
+
+ if (!target.getLocSts().equals("O")) {
+ shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
+ return;
+ }
+
+ //璋冨害鍘荤洰鏍囦綅缃�
+ if (shuttleProtocol.getCurrentLocNo().equals(target.getLocNo())) {
+ shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);//灏忚溅鍜岀洰鏍囦綅缃竴鑷达紝璺宠繃
+ }else {
+ boolean result = shuttleDispatchUtils.dispatchShuttle(commonService.getWorkNo(3), target.getLocNo());
+ if (result) {//璋冨害鎴愬姛
+ shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
+ }
+ }
+ }
+ }
+
+ //妫�娴嬪皬杞︽槸鍚﹁繘鍑烘彁鍗囨満杈撻�佺珯
+ public void checkIOSta(List<NyShuttleHttpCommand> commands, int commandStep) {
+ if (commandStep != 0) {
+ NyShuttleHttpCommand lastCommand = commands.get(commandStep - 1);//涓婁竴姝ュ懡浠�
+ if (lastCommand.getRequest().getBody().get("requestType").equals("move")) {
+ //妫�娴嬭捣鐐规槸鍚︿负鎻愬崌鏈鸿緭閫佺珯鐐�
+ NyShuttleProtocol.NyShuttlePointClass start = JSON.parseObject(lastCommand.getRequest().getBody().get("start").toString(), NyShuttleProtocol.NyShuttlePointClass.class);
+ int[] startPoint = NavigatePositionConvert.NyXyzToWCSXyz(start.getX(), start.getY(), start.getZ());
+ if (startPoint[0] == 13 && (startPoint[1] == 22 || startPoint[1] == 38 || startPoint[1] == 57)) {
+ //杈撻�佺珯鐐逛綅缃�
+
+ int liftNo;
+ if (startPoint[1] == 22) {
+ liftNo = 1;
+ } else if (startPoint[1] == 38) {
+ liftNo = 2;
+ } else {
+ liftNo = 3;
+ }
+
+ HashMap<String, Object> data = new HashMap<>();
+ data.put("lev", startPoint[2]);
+ data.put("status", false);//鍑鸿緭閫佺珯
+
+ //涓嬪彂浠诲姟
+ MessageQueue.offer(SlaveType.Lift, liftNo, new Task(4, data));
+ }
+ }
+ }
+
+ if (commands.size() == commandStep) {
+ return;
+ }
+ NyShuttleHttpCommand command = commands.get(commandStep);//褰撳墠鍛戒护
+ if (command.getRequest().getBody().get("requestType").equals("move")) {
+ NyShuttleProtocol.NyShuttlePointClass target = JSON.parseObject(command.getRequest().getBody().get("target").toString(), NyShuttleProtocol.NyShuttlePointClass.class);
+ int[] targetPoint = NavigatePositionConvert.NyXyzToWCSXyz(target.getX(), target.getY(), target.getZ());
+ //妫�娴嬬洰鏍囦綅缃槸鍚︿负鎻愬崌鏈鸿緭閫佺珯鐐�
+ if (targetPoint[0] == 13 && (targetPoint[1] == 22 || targetPoint[1] == 38 || targetPoint[1] == 57)) {
+ //杈撻�佺珯鐐逛綅缃�
+
+ int liftNo;
+ if (targetPoint[1] == 22) {
+ liftNo = 1;
+ } else if (targetPoint[1] == 38) {
+ liftNo = 2;
+ } else {
+ liftNo = 3;
+ }
+
+ HashMap<String, Object> data = new HashMap<>();
+ data.put("lev", targetPoint[2]);
+ data.put("status", true);//杩涜緭閫佺珯
+
+ //涓嬪彂浠诲姟
+ MessageQueue.offer(SlaveType.Lift, liftNo, new Task(4, data));
+ }
+ }
+ }
+
}
--
Gitblit v1.9.1