From 77401b95f2fc410ecc6d6f9f0052ca56ccc4910f Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期四, 10 八月 2023 12:49:30 +0800
Subject: [PATCH] 地图增加站点
---
src/main/java/com/zy/core/thread/NyShuttleThread.java | 142 +++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 131 insertions(+), 11 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/NyShuttleThread.java b/src/main/java/com/zy/core/thread/NyShuttleThread.java
index 7fc995a..1ab039c 100644
--- a/src/main/java/com/zy/core/thread/NyShuttleThread.java
+++ b/src/main/java/com/zy/core/thread/NyShuttleThread.java
@@ -10,6 +10,7 @@
import com.zy.asrs.utils.Utils;
import com.zy.common.model.NavigateNode;
+import com.zy.common.model.NyShuttleOperaResult;
import com.zy.common.utils.*;
import com.zy.core.News;
import com.zy.core.ThreadHandler;
@@ -17,14 +18,13 @@
import com.zy.core.cache.OutputQueue;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.*;
+import com.zy.core.model.LiftSlave;
import com.zy.core.model.ShuttleSlave;
import com.zy.core.model.Task;
-import com.zy.core.model.command.NyShuttleHttpCommand;
-import com.zy.core.model.command.ShuttleAssignCommand;
-import com.zy.core.model.command.ShuttleCommand;
-import com.zy.core.model.command.ShuttleRedisCommand;
+import com.zy.core.model.command.*;
import com.zy.core.model.protocol.LiftProtocol;
import com.zy.core.model.protocol.NyShuttleProtocol;
+import com.zy.core.properties.SlaveProperties;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
@@ -299,15 +299,16 @@
return false;
}
- WrkMastService wrkMastService = SpringUtils.getBean(WrkMastService.class);
+ WrkMastMapper wrkMastMapper = SpringUtils.getBean(WrkMastMapper.class);
Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo);
if (o == null) {
return false;
}
+
ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class);
- List<NyShuttleHttpCommand> commands = redisCommand.getAssignCommand().getCommands();
ShuttleAssignCommand assignCommand = redisCommand.getAssignCommand();
+ List<NyShuttleHttpCommand> commands = redisCommand.getAssignCommand().getCommands();
//褰撳墠姝ュ簭
int commandStep = redisCommand.getCommandStep();
if (commands.size() == 0) {
@@ -359,13 +360,16 @@
return false;
}
- //妫�鏌ヨ矾寰勬槸鍚﹀彲琛岃蛋(妫�鏌ヨ矾寰勯攣瀹氱姸鎬侊紝妫�娴嬭矾寰勬槸鍚︽湁鍏朵粬灏忚溅)
- //妫�娴嬪綋鍓嶈璧拌矾寰勶紝鍜屼笅涓�姝ヨ矾寰�
- boolean checkPathIsAvailable = NavigateUtils.checkPathIsAvailable(command.getNodes(), shuttleProtocol.getShuttleNo().intValue(), Utils.getLev(shuttleProtocol.getCurrentLocNo()));
- boolean checkPathIsAvailable2 = NavigateUtils.checkPathIsAvailable(nextNodes, shuttleProtocol.getShuttleNo().intValue(), Utils.getLev(shuttleProtocol.getCurrentLocNo()));
- if (!checkPathIsAvailable && !checkPathIsAvailable2) {
+ //妫�娴嬬┛姊溅鏄惁鍦ㄦ彁鍗囨満鍐�
+ if (!checkShuttleInTheLift(wrkNo)) {
return false;
}
+
+ //妫�娴嬭矾寰勬槸鍚﹀彲琛岃蛋
+ if (!checkPath(command.getNodes(), nextNodes, redisCommand)) {
+ return false;
+ }
+
//閿佸畾璺緞锛岄攣瀹氬綋鍓嶈矾寰勫拰涓嬩竴姝ヨ矾寰�
List<NavigateNode> nodes = command.getNodes();
nodes.addAll(nextNodes);
@@ -438,6 +442,8 @@
return false;
}
+ WrkMastMapper wrkMastMapper = SpringUtils.getBean(WrkMastMapper.class);
+
ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class);
//褰撳墠姝ュ簭
int commandStep = redisCommand.getCommandStep();
@@ -480,7 +486,121 @@
return true;//鎻愬崌鏈鸿揪鍒板皬杞︽ゼ灞傦紝鏀捐
}
+ //鎼滅储鏄惁鏈夊叾浠栦换鍔″崰鐢ㄤ簡鎻愬崌鏈猴紝濡傛灉鍗犵敤鎻愬崌鏈虹殑浠诲姟鍜屽綋鍓嶄换鍔$浉鍚岋紝鍒欒繍琛屾墽琛�
+ WrkMast wrkMast1 = wrkMastMapper.selectLiftWrkMast(liftProtocol.getLiftNo().intValue());
+ if (wrkMast1 != null && wrkMast1.getWrkNo() != wrkNo.intValue()) {
+ return false;
+ }
+
+ //鎻愬崌鏈烘湭鍒拌揪灏忚溅妤煎眰锛屽懠鍙彁鍗囨満
+ //鑾峰彇鎻愬崌鏈哄懡浠�
+ NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_CAR.id, null, basDevp.getDevNo(), wrkNo.intValue());
+ ArrayList<NyLiftCommand> liftCommands = new ArrayList<>();
+ liftCommands.add(liftCommand);
+
+ //鎻愪氦鍒扮嚎绋嬪幓宸ヤ綔
+ LiftAssignCommand assignCommand = new LiftAssignCommand();
+ assignCommand.setCommands(liftCommands);
+ assignCommand.setLiftNo(liftProtocol.getLiftNo());
+ assignCommand.setTaskNo(wrkNo);
+ assignCommand.setTaskMode(NyLiftTaskModelType.MOVE_CAR.id.shortValue());
+
+ //涓嬪彂浠诲姟
+ MessageQueue.offer(SlaveType.Lift, liftProtocol.getLiftNo().intValue(), new Task(3, assignCommand));
+
return false;//榛樿涓嶆斁琛�
}
+ /**
+ * 妫�娴嬬┛姊溅鏄惁鍦ㄦ彁鍗囨満鍐�
+ * 濡傜┛姊溅鍦ㄦ彁鍗囨満鍐咃紝蹇呴』绛夊緟鎻愬崌鏈虹┖闂叉墠鍙墽琛岀┛姊溅鍛戒护
+ */
+ private boolean checkShuttleInTheLift(Short wrkNo) {
+ //璇诲彇redis鏁版嵁
+ if (wrkNo == null) {
+ return false;
+ }
+
+ Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo);
+ if (o == null) {
+ return false;
+ }
+
+ SlaveProperties slaveProperties = SpringUtils.getBean(SlaveProperties.class);
+ BasLiftService liftService = SpringUtils.getBean(BasLiftService.class);
+ for (LiftSlave liftSlave : slaveProperties.getLift()) {
+ BasLift basLift = liftService.selectById(liftSlave.getId());
+ if (basLift == null) {
+ continue;
+ }
+ if (basLift.getPoint().equals(shuttleProtocol.getPoint())) {
+ //灏忚溅鍦ㄦ彁鍗囨満鍐�
+ //鍒ゆ柇鎻愬崌鏈烘槸鍚︾┖闂�
+ LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, liftSlave.getId());
+ if (liftThread == null) {
+ return false;
+ }
+ LiftProtocol liftProtocol = liftThread.getLiftProtocol();
+ if (liftProtocol == null) {
+ return false;
+ }
+ if (liftProtocol.isIdle()) {
+ //鎻愬崌鏈哄浜庣┖闂诧紝鏀捐
+ return true;
+ }
+ }
+ }
+ return false;//榛樿涓嶆斁琛�
+ }
+
+ /**
+ * 妫�娴嬭矾寰勬槸鍚﹀彲琛岃蛋
+ * 濡傛灉璺緞涓虹洰鏍囧簱浣嶏紝浣嗕笉鍙璧帮紝绯荤粺灏嗗皾璇曢噸鏂拌绠楄矾寰�
+ */
+ private boolean checkPath(List<NavigateNode> currentNodes, List<NavigateNode> nextNodes, ShuttleRedisCommand redisCommand) {
+ //妫�娴嬭矾寰勬槸鍚﹀彲琛岃蛋(妫�鏌ヨ矾寰勯攣瀹氱姸鎬侊紝妫�娴嬭矾寰勬槸鍚︽湁鍏朵粬灏忚溅)
+ //妫�娴嬪綋鍓嶈璧拌矾寰勶紝鍜屼笅涓�姝ヨ矾寰�
+ boolean checkPathIsAvailable = NavigateUtils.checkPathIsAvailable(currentNodes, shuttleProtocol.getShuttleNo().intValue(), Utils.getLev(shuttleProtocol.getCurrentLocNo()));
+ boolean checkPathIsAvailable2 = NavigateUtils.checkPathIsAvailable(nextNodes, shuttleProtocol.getShuttleNo().intValue(), Utils.getLev(shuttleProtocol.getCurrentLocNo()));
+ if (checkPathIsAvailable && checkPathIsAvailable2) {
+ return true;//鍙璧�
+ }
+
+ ShuttleAssignCommand assignCommand = redisCommand.getAssignCommand();
+ NavigateNode currentTarget = currentNodes.get(currentNodes.size() - 1);
+ String currentLocNo = NavigatePositionConvert.nodeToLocNo(currentTarget);
+ NavigateNode nextTarget = nextNodes.get(nextNodes.size() - 1);
+ String nextLocNo = NavigatePositionConvert.nodeToLocNo(nextTarget);
+ if (assignCommand.getLocNo().equals(currentLocNo) || assignCommand.getLocNo().equals(nextLocNo)) {
+ //褰撳墠璺緞鏈�鍚庝竴涓妭鐐规槸鐩爣搴撲綅锛岃繘琛岃矾寰勬娴嬶紝濡傛灉涓嶅彲琛岃蛋锛岄噸鏂拌绠楄矾寰�
+ //涓嶅彲琛岃蛋锛岄噸鏂拌绠楄矾寰�
+ NyShuttleOperaResult result = NyShuttleOperaUtils.getStartToTargetCommands(shuttleProtocol.getShuttleNo().intValue(), shuttleProtocol.getTaskNo(), shuttleProtocol.getCurrentLocNo(), assignCommand.getLocNo());
+ if (result == null) {
+ return false;//璺緞璁$畻澶辫触锛屼笉鍙璧�
+ }
+
+ List<NyShuttleHttpCommand> newCommands = result.getCommands();//鏂拌矾寰�
+
+ //褰撳墠姝ュ簭
+ int commandStep = redisCommand.getCommandStep();
+ List<NyShuttleHttpCommand> commands = assignCommand.getCommands();
+
+ commands.remove(commandStep);//绉婚櫎褰撳墠姝ュ簭鎸囦护
+ if (assignCommand.getLocNo().equals(currentLocNo)) {
+ //褰撳墠璺緞锛岄渶瑕佸啀澶氱Щ闄や笅涓�姝ユ寚浠�
+ commands.remove(commandStep + 1);
+ }
+
+ //灏嗘柊璺緞娣诲姞杩涙寚浠ら泦鍚�
+ commands.addAll(commandStep, newCommands);
+ assignCommand.setCommands(commands);
+ redisCommand.setAssignCommand(assignCommand);
+ //浠诲姟鏁版嵁淇濆瓨鍒皉edis
+ redisUtil.set("shuttle_wrk_no_" + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
+ return false;//褰撳墠涓嶅彲琛岃蛋锛岀瓑寰呬笅涓�娆℃墽琛岃蛋鏂拌矾寰�
+ }
+
+ return false;//涓嶅彲琛岃蛋
+ }
+
}
--
Gitblit v1.9.1