From d9505e143cdf452c3a33752b380ee1b3a410601d Mon Sep 17 00:00:00 2001
From: Junjie <xjj@123>
Date: 星期四, 16 十月 2025 14:48:52 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/action/ShuttleAction.java | 1058 ++++++++++++++++++++++++++++++----------------------------
1 files changed, 551 insertions(+), 507 deletions(-)
diff --git a/src/main/java/com/zy/core/action/ShuttleAction.java b/src/main/java/com/zy/core/action/ShuttleAction.java
index 67e1a26..42e4a3f 100644
--- a/src/main/java/com/zy/core/action/ShuttleAction.java
+++ b/src/main/java/com/zy/core/action/ShuttleAction.java
@@ -5,37 +5,37 @@
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.zy.asrs.domain.param.CreateLocMoveTaskParam;
import com.zy.asrs.entity.BasShuttleOpt;
import com.zy.asrs.entity.LocMast;
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.service.BasShuttleOptService;
-import com.zy.asrs.service.BasShuttleService;
import com.zy.asrs.service.LocMastService;
import com.zy.asrs.service.WrkMastService;
import com.zy.asrs.utils.Utils;
-import com.zy.common.ExecuteSupport;
import com.zy.common.model.NavigateNode;
+import com.zy.common.service.CommonService;
import com.zy.common.utils.NavigateMapUtils;
import com.zy.common.utils.RedisUtil;
-import com.zy.common.utils.ShuttleOperaUtils;
import com.zy.core.News;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.dispatcher.ShuttleDispatchUtils;
import com.zy.core.enums.*;
import com.zy.core.model.CommandResponse;
+import com.zy.core.model.TrafficControlDataModel;
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.protocol.ShuttleProtocol;
import com.zy.core.thread.ShuttleThread;
+import com.zy.core.thread.TrafficControlThread;
+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.io.IOException;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
@Component
public class ShuttleAction {
@@ -44,8 +44,6 @@
private RedisUtil redisUtil;
@Autowired
private NavigateMapUtils navigateMapUtils;
- @Autowired
- private BasShuttleService basShuttleService;
@Autowired
private LocMastService locMastService;
@Autowired
@@ -58,12 +56,22 @@
private WrkMastService wrkMastService;
@Autowired
private ShuttleDispatchUtils shuttleDispatchUtils;
+ @Autowired
+ private CommonService commonService;
public synchronized boolean assignWork(Integer shuttleNo, ShuttleAssignCommand assignCommand) {
ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
if (shuttleThread == null) {
return false;
}
+
+ TrafficControlThread trafficControlThread = (TrafficControlThread) SlaveConnection.get(SlaveType.TrafficControl, 1);
+ if(trafficControlThread == null){
+ return false;
+ }
+
+ //Clear Traffic Control
+ trafficControlThread.forceCancelTrafficControl(shuttleNo);
ShuttleRedisCommand redisCommand = new ShuttleRedisCommand();
@@ -79,7 +87,7 @@
return false;
}
- public synchronized boolean executeWork(Integer shuttleNo, Integer taskNo) {
+ public boolean executeWork(Integer shuttleNo, Integer taskNo) {
Object obj = redisUtil.get(RedisKeyType.SHUTTLE_WORK_FLAG.key + taskNo);
if (obj == null) {
return false;
@@ -111,142 +119,89 @@
return false;
}
- List<ShuttleCommand> commands = redisCommand.getAssignCommand().getCommands();
- if (commands.isEmpty()) {
+ News.info("[RCS Debug] Execute check command {},{}", shuttleNo, taskNo);
+ //妫�娴嬪懡浠�
+ ShuttleCheckCommandResultType checked = checkCommand(redisCommand, shuttleNo);
+ News.info("[RCS Debug] Execute check command complete {},{}", shuttleNo, taskNo);
+ if (checked.equals(ShuttleCheckCommandResultType.FAIL)) {
return false;
}
ShuttleAssignCommand assignCommand = redisCommand.getAssignCommand();
- int commandStep = redisCommand.getCommandStep();
-
- Integer mode = -1;
- if(commandStep < commands.size()) {
- //鍙栧嚭鍛戒护
- ShuttleCommand currentCommand = commands.get(commandStep);
- mode = currentCommand.getMode();
- }
-
- //鍒ゆ柇璁惧鏄惁绌洪棽
- Integer finalMode = mode;
- if (!shuttleThread.isDeviceIdle(new ExecuteSupport() {
- @Override
- public Boolean judgement() {
- if (ShuttleCommandModeType.CHARGE_CLOSE.id.equals(finalMode)) {//鍏抽棴鍏呯數
- return false;//涓嶉渶瑕佸垽鏂姸鎬�
- }
- return true;//闇�瑕佸垽鏂姸鎬�
- }
- })) {
+ List<ShuttleCommand> commands = assignCommand.getCommands();
+ if (commands.isEmpty()) {
return false;
}
- // 瀹岀粨涓婁竴鏉″懡浠�
- boolean updateCommand = false;
- if (commandStep != 0) {
- ShuttleCommand command = commands.get(commandStep - 1);
- if (command.getMode() == ShuttleCommandModeType.MOVE.id) {
- // 姝e父绉诲姩
- if (command.getTargetLocNo().equals(shuttleProtocol.getCurrentLocNo())) {
- command.setComplete(true);
- updateCommand = true;
- //瑙i攣閿佸畾璺緞锛屼笂涓�鏉¤矾寰�
- List<NavigateNode> nodes = null;
- try {
- String nodesStr = objectMapper.writeValueAsString(command.getNodes());
- nodes = objectMapper.readValue(nodesStr, new TypeReference<List<NavigateNode>>() {
- });
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
-
- if (nodes != null) {
- 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(), nodes, false);//瑙i攣璺緞
- if (!result) {
- return false;//瑙i攣澶辫触
- }
- }
- }
- } else if (command.getMode() == ShuttleCommandModeType.PALLET_LIFT.id) {
- // 鎵樼洏椤跺崌
- //鍒ゆ柇鏄惁椤跺崌鍒颁綅
- if (shuttleProtocol.getHasLift()) {
- command.setComplete(true);
- updateCommand = true;
-// //鍒ゆ柇鏄惁鏈夌墿
-// if (shuttleProtocol.getHasPallet()) {
-// command.setComplete(true);
-// }
- }
- } else if (command.getMode() == ShuttleCommandModeType.PALLET_DOWN.id) {
- // 鎵樼洏涓嬮檷鍛戒护
- // 鍒ゆ柇鏄惁涓嬮檷鍒颁綅
- if (!shuttleProtocol.getHasLift()) {
- command.setComplete(true);
- updateCommand = true;
- }
- } else if (command.getMode() == ShuttleCommandModeType.CHARGE_OPEN.id) {
- // 鍏呯數寮�
- //鍒ゆ柇灏忚溅鍏呯數鐘舵��
- if (shuttleProtocol.getHasCharge()) {
- command.setComplete(true);
- updateCommand = true;
- }
- }else {
- command.setComplete(true);//鍏朵粬鍛戒护榛樿璁や负瀹屾垚
- updateCommand = true;
- }
-
- if(updateCommand) {
- // 鏇存柊redis鏁版嵁
- redisUtil.set(RedisKeyType.SHUTTLE_WORK_FLAG.key + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand, SerializerFeature.DisableCircularReferenceDetect));
- }
-
- if (!command.getComplete()) {
- return false;
- }
-
- //鍒ゆ柇鏄惁涓烘渶鍚庝竴鏉″懡浠や笖鍛戒护鎵ц瀹屾垚锛屾姏鍑虹瓑寰呯‘璁ょ姸鎬�
- ShuttleCommand endCommand = commands.get(commands.size() - 1);
- if (endCommand.getComplete()) {
- News.info("鍥涘悜绌挎杞︿换鍔℃墽琛屼笅鍙戝畬鎴愮瓑寰呮墽琛岀粨鏉燂紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(commands));
-
- // 绯荤粺浠诲姟
- if (assignCommand.getAuto()) {
- if (!assignCommand.getCharge()) {
- //瀵逛富绾跨▼鎶涘嚭绛夊緟纭鐘舵�亀aiting
- shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.WAITING);
- }else {
- shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.CHARGING_WAITING);
- }
- News.info("鍥涘悜绌挎杞︿换鍔℃墽琛屼笅鍙戝畬鎴愮瓑寰呮墽琛岀粨鏉燂紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
-
- // 鎵嬪姩浠诲姟
- } else {
- //鎵嬪姩妯″紡涓嶆姏鍑虹瓑寰呯姸鎬侊紝鐩存帴澶嶄綅绌洪棽鐘舵��
- shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
- //浠诲姟鍙锋竻闆�
- shuttleThread.setSyncTaskNo(0);
- //鏍囪澶嶄綅
- shuttleThread.setPakMk(true);
- News.info("鍥涘悜绌挎杞︽墜鍔ㄤ换鍔℃墽琛屽畬鎴愶紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
- }
-
- //鍒犻櫎redis
- redisUtil.del(RedisKeyType.SHUTTLE_WORK_FLAG.key + redisCommand.getWrkNo());
- return false;//绂佹鍐嶄笅鍙戝懡浠�
- }
+ int commandStep = redisCommand.getCommandStep();
+ if(commandStep >= commands.size()){
+ return false;
}
//鍙栧嚭鍛戒护
- ShuttleCommand command = commands.get(commandStep);
+ ShuttleCommand command = null;
+ if (checked.equals(ShuttleCheckCommandResultType.SUCCESS)) {
+ //闈炶繛缁寚浠わ紝闇�瑕佹娴嬩笂涓�鏉℃寚浠ゆ槸鍚﹀畬鎴�
+ if (commandStep > 0) {
+ ShuttleCommand lastCommand = commands.get(commandStep - 1);
+ if (!lastCommand.getComplete()) {
+ return false;//鎸囦护鏈畬鎴�
+ }
+ }
+ command = commands.get(commandStep);
+ } else if (checked.equals(ShuttleCheckCommandResultType.SUCCESS_GO)) {
+ //杩炵画鎸囦护鐩存帴鍙栨暟鎹�
+ command = commands.get(commandStep);
+ }
+
+ if(command == null){
+ return false;
+ }
+
+ //绉诲姩鍛戒护锛岄攣瀹氳矾寰�
+ if (command.getMode() == ShuttleCommandModeType.MOVE.id) {
+ TrafficControlThread trafficControlThread = (TrafficControlThread) SlaveConnection.get(SlaveType.TrafficControl, 1);
+ if (trafficControlThread == null) {
+ return false;
+ }
+
+ List<NavigateNode> nodes = JSON.parseArray(JSON.toJSONString(command.getNodes()), NavigateNode.class);
+
+ Object object = redisUtil.get(RedisKeyType.TRAFFIC_CONTROL_LOCK_APPLY.key + shuttleNo);
+ if (object == null) {
+ //鐢宠绠″埗
+ News.info("[RCS Debug] Execute apply control {},{}", shuttleNo, taskNo);
+ redisUtil.set(RedisKeyType.TRAFFIC_CONTROL_LOCK_APPLY.key + shuttleNo, "lock", 4);
+ applyTrafficControl(commands, nodes, shuttleNo, taskNo);
+ News.info("[RCS Debug] Execute apply control complete {},{}", shuttleNo, taskNo);
+ }
+
+ News.info("[RCS Debug] Execute query control {},{}", shuttleNo, taskNo);
+ //鏌ヨ绠″埗
+ boolean apply = queryTrafficControl(shuttleNo, taskNo);
+ News.info("[RCS Debug] Execute query control complete {},{}", shuttleNo, taskNo);
+ if(!apply){
+ return false;//鐢宠澶辫触
+ }
+
+ if (checked.equals(ShuttleCheckCommandResultType.SUCCESS_GO)) {
+ nodes.remove(0);
+ }
+
+ boolean result = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(command.getTargetLocNo()), shuttleNo, nodes, true);//閿佸畾璺緞
+ if (!result) {
+ News.error("{} device can't lock path!", shuttleNo);
+ shuttleThread.offerSystemMsg("{} device can't lock path!", shuttleNo);
+ trafficControlThread.trafficReportError(shuttleNo, taskNo);
+ return false;//璺緞閿佸畾澶辫触
+ }
+ }
+
+ News.info("[RCS Debug] Execute send command {},{}", shuttleNo, taskNo);
// 涓嬪彂鍛戒护
CommandResponse response = write(command, shuttleNo);
+ News.info("[RCS Debug] Execute send command complete {},{}", shuttleNo, taskNo);
//淇濆瓨鍛戒护鏃ュ織
BasShuttleOpt basShuttleOpt = new BasShuttleOpt();
@@ -271,11 +226,311 @@
}
shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.WORKING);
- commandStep++;
+
+ commandStep += 1;
//鏇存柊redis鏁版嵁
redisCommand.setCommandStep(commandStep);
+
//浠诲姟鏁版嵁淇濆瓨鍒皉edis
redisUtil.set(RedisKeyType.SHUTTLE_WORK_FLAG.key + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
+ return true;
+ }
+
+ /**
+ * 妫�娴嬪懡浠�
+ * 0:鏈�氳繃 1:閫氳繃 2:閫氳繃涓斿彲鎻愬墠涓嬪彂鎸囦护
+ */
+ private ShuttleCheckCommandResultType checkCommand(ShuttleRedisCommand redisCommand, Integer shuttleNo) {
+ TrafficControlThread trafficControlThread = (TrafficControlThread) SlaveConnection.get(SlaveType.TrafficControl, 1);
+ if(trafficControlThread == null){
+ return ShuttleCheckCommandResultType.FAIL;
+ }
+
+ ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
+ if (shuttleThread == null) {
+ return ShuttleCheckCommandResultType.FAIL;
+ }
+
+ ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+ if (shuttleProtocol == null) {
+ return ShuttleCheckCommandResultType.FAIL;
+ }
+
+ int commandStep = redisCommand.getCommandStep();
+ if (commandStep == 0) {
+ return ShuttleCheckCommandResultType.SUCCESS;//绗竴鏉″懡浠ゆ棤闇�妫�娴�
+ }
+
+ ShuttleAssignCommand assignCommand = redisCommand.getAssignCommand();
+ List<ShuttleCommand> commands = assignCommand.getCommands();
+ if (commands.isEmpty()) {
+ return ShuttleCheckCommandResultType.FAIL;
+ }
+
+ boolean supportContinuously = false;
+ int checkIdx = commandStep - 2;
+ if (checkIdx < 0) {
+ supportContinuously = true;
+ checkIdx = commandStep - 1;
+ }
+
+ ShuttleCommand last2Command = commands.get(checkIdx);
+ if(last2Command.getComplete()){
+ supportContinuously = true;
+ checkIdx = commandStep - 1;
+ }
+
+ ShuttleCommand lastCommand = commands.get(checkIdx);
+ if (!lastCommand.getComplete()) {
+ //妫�娴嬫洿鏂板懡浠ゅ畬鎴�
+ boolean checked = updateCommandComplete(checkIdx, commands, shuttleNo);
+ if (checked) {
+ // 鏇存柊redis鏁版嵁
+ redisUtil.set(RedisKeyType.SHUTTLE_WORK_FLAG.key + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand, SerializerFeature.DisableCircularReferenceDetect));
+ }else {
+ //灏忚溅绉诲姩杩炵画涓嬪彂鎸囦护
+ if (assignCommand.getShuttleMoveCommandsContinuously()) {
+ if (!supportContinuously) {
+ return ShuttleCheckCommandResultType.FAIL;
+ }
+
+ //绉诲姩鎸囦护
+ if(lastCommand.getMode() != ShuttleCommandModeType.MOVE.id) {
+ return ShuttleCheckCommandResultType.FAIL;
+ }
+
+ List<NavigateNode> nodes = lastCommand.getNodes();
+ NavigateNode startNode = nodes.get(0);
+ if (!startNode.getLinePartAllowGo()) {//鐩寸嚎娈甸儴鍒嗭紝鍏佽鐩存帴琛岃蛋
+ return ShuttleCheckCommandResultType.FAIL;
+ }
+
+ //鐩寸嚎娈垫暟鎹爣璇�
+ Long linePartFlag = startNode.getLinePartFlag();
+
+ if(commandStep < commands.size()){
+ //鍙栨寚浠�
+ ShuttleCommand currentCommand = commands.get(commandStep);
+ if(currentCommand.getMode() != ShuttleCommandModeType.MOVE.id) {
+ return ShuttleCheckCommandResultType.FAIL;
+ }
+
+ List<NavigateNode> currentNodes = currentCommand.getNodes();
+ NavigateNode currentStartNode = currentNodes.get(0);
+ if(!currentStartNode.getLinePartAllowGo()) {//鐩寸嚎娈甸儴鍒嗭紝鍏佽鐩存帴琛岃蛋
+ return ShuttleCheckCommandResultType.FAIL;
+ }
+
+ if(currentStartNode.getLinePartFlag().equals(linePartFlag)) {
+ //鏁版嵁鏍囪瘑涓�鑷�
+ return ShuttleCheckCommandResultType.SUCCESS_GO;//鍏佽灏忚溅绉诲姩杩炵画涓嬪彂鎸囦护
+ }
+ }
+ }
+
+ return ShuttleCheckCommandResultType.FAIL;
+ }
+ }
+
+ //鍒ゆ柇鏄惁涓烘渶鍚庝竴鏉″懡浠や笖鍛戒护鎵ц瀹屾垚锛屾姏鍑虹瓑寰呯‘璁ょ姸鎬�
+ ShuttleCommand endCommand = commands.get(commands.size() - 1);
+ if (endCommand.getComplete()) {
+ News.info("鍥涘悜绌挎杞︿换鍔℃墽琛屼笅鍙戝畬鎴愮瓑寰呮墽琛岀粨鏉燂紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(commands));
+
+ // 绯荤粺浠诲姟
+ if (assignCommand.getAuto()) {
+ if (assignCommand.getTaskMode() == ShuttleTaskModeType.UPDATE_LOCATION.id) {//鏇存柊鍧愭爣鏃犻渶绛夊緟纭
+ //鐩存帴澶嶄綅绌洪棽鐘舵��
+ shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
+ //浠诲姟鍙锋竻闆�
+ shuttleThread.setSyncTaskNo(0);
+ //鏍囪澶嶄綅
+ shuttleThread.setPakMk(true);
+ News.info("鍥涘悜绌挎杞︽洿鏂板潗鏍囦换鍔℃墽琛屽畬鎴愶紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(endCommand));
+ }else {
+ if (!assignCommand.getCharge()) {
+ //瀵逛富绾跨▼鎶涘嚭绛夊緟纭鐘舵�亀aiting
+ shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.WAITING);
+ } else {
+ shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.CHARGING_WAITING);
+ }
+ News.info("鍥涘悜绌挎杞︿换鍔℃墽琛屼笅鍙戝畬鎴愮瓑寰呮墽琛岀粨鏉燂紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(endCommand));
+ }
+ } else {// 鎵嬪姩浠诲姟
+ //鎵嬪姩妯″紡涓嶆姏鍑虹瓑寰呯姸鎬侊紝鐩存帴澶嶄綅绌洪棽鐘舵��
+ shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
+ //浠诲姟鍙锋竻闆�
+ shuttleThread.setSyncTaskNo(0);
+ //鏍囪澶嶄綅
+ shuttleThread.setPakMk(true);
+ News.info("鍥涘悜绌挎杞︽墜鍔ㄤ换鍔℃墽琛屽畬鎴愶紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(endCommand));
+ }
+
+ //鐢宠鍙栨秷绠″埗
+ cancelTrafficControl(shuttleNo, shuttleProtocol.getTaskNo());
+
+ //鍒犻櫎redis
+ redisUtil.del(RedisKeyType.SHUTTLE_WORK_FLAG.key + redisCommand.getWrkNo());
+ return ShuttleCheckCommandResultType.FAIL;//绂佹鍐嶄笅鍙戝懡浠�
+ }
+
+ return ShuttleCheckCommandResultType.SUCCESS;
+ }
+
+ //妫�娴嬫洿鏂板懡浠ゅ畬鎴�
+ private boolean updateCommandComplete(Integer commandIdx, List<ShuttleCommand> commands, Integer shuttleNo) {
+ ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
+ if (shuttleThread == null) {
+ return false;
+ }
+
+ ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+ if (shuttleProtocol == null) {
+ return false;
+ }
+
+ //鍒ゆ柇璁惧鏄惁绌洪棽
+ boolean deviceIdle = shuttleThread.isDeviceIdle();
+
+ ShuttleCommand command = commands.get(commandIdx);
+ if (command.getMode() == ShuttleCommandModeType.MOVE.id) {
+ // 姝e父绉诲姩
+ List<String> targetPoints = new ArrayList<>();
+
+ //瑙i攣閿佸畾璺緞锛屼笂涓�鏉¤矾寰�
+ List<NavigateNode> nodes = null;
+ try {
+ String nodesStr = objectMapper.writeValueAsString(command.getNodes());
+ nodes = objectMapper.readValue(nodesStr, new TypeReference<List<NavigateNode>>() {
+ });
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
+ NavigateNode startNode = nodes.get(0);
+ Long linePartFlag = startNode.getLinePartFlag();
+
+ NavigateNode targetNode = nodes.get(nodes.size() - 1);
+ targetPoints.add(targetNode.getX() + "-" + targetNode.getY());
+
+ for (int i = commandIdx + 1; i < commands.size(); i++) {
+ ShuttleCommand nextCommand = commands.get(i);
+ if (nextCommand.getMode() == ShuttleCommandModeType.MOVE.id) {
+ List<NavigateNode> nextCommandNodes = nextCommand.getNodes();
+ NavigateNode nextStartNode = nextCommandNodes.get(0);
+ Long nextLinePartFlag = nextStartNode.getLinePartFlag();
+ if(nextLinePartFlag.equals(linePartFlag)) {
+ for (NavigateNode node : nextCommandNodes) {
+ String key = node.getX() + "-" + node.getY();
+ if(!targetPoints.contains(key)) {
+ targetPoints.add(key);
+ }
+ }
+ }
+ }
+ }
+
+ TrafficControlThread trafficControlThread = (TrafficControlThread) SlaveConnection.get(SlaveType.TrafficControl, 1);
+ if (trafficControlThread == null) {
+ return false;
+ }
+ //涓婃姤浜ょ
+ News.info("[RCS Debug] Execute check command report traffic {},{}", shuttleNo, shuttleProtocol.getTaskNo());
+ trafficControlThread.trafficReport(command.getNodesDeepCopy(), shuttleNo, shuttleProtocol.getTaskNo());
+ News.info("[RCS Debug] Execute check command report traffic complete {},{}", shuttleNo, shuttleProtocol.getTaskNo());
+
+ String currentLocNo = shuttleProtocol.getCurrentLocNo();
+ if (currentLocNo == null) {
+ return false;
+ }
+ if (targetPoints.contains(Utils.getRow(currentLocNo) + "-" + Utils.getBay(currentLocNo))) {
+ boolean result = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(shuttleProtocol.getCurrentLocNo()), shuttleProtocol.getShuttleNo(), nodes, false);//瑙i攣璺緞
+ if (!result) {
+ return false;//瑙i攣澶辫触
+ }
+ command.setComplete(true);
+ }else {
+ return false;
+ }
+ } else if (command.getMode() == ShuttleCommandModeType.PALLET_LIFT.id) {
+ // 鎵樼洏椤跺崌
+ if (!deviceIdle) {
+ return false;//璁惧涓嶇┖闂�
+ }
+
+ //鍒ゆ柇鏄惁椤跺崌鍒颁綅
+ if (shuttleProtocol.getHasLift()) {
+ command.setComplete(true);
+// //鍒ゆ柇鏄惁鏈夌墿
+// if (shuttleProtocol.getHasPallet()) {
+// command.setComplete(true);
+// }
+ }else {
+ return false;
+ }
+ } else if (command.getMode() == ShuttleCommandModeType.PALLET_DOWN.id) {
+ // 鎵樼洏涓嬮檷鍛戒护
+ if (!deviceIdle) {
+ return false;//璁惧涓嶇┖闂�
+ }
+
+ // 鍒ゆ柇鏄惁涓嬮檷鍒颁綅
+ if (!shuttleProtocol.getHasLift()) {
+ command.setComplete(true);
+ }else {
+ return false;
+ }
+ } else if (command.getMode() == ShuttleCommandModeType.CHARGE_OPEN.id) {
+ // 鍏呯數寮�
+ //鍒ゆ柇灏忚溅鍏呯數鐘舵��
+ if (shuttleProtocol.getHasCharge()) {
+ command.setComplete(true);
+ }else {
+ return false;
+ }
+ } else if (command.getMode() == ShuttleCommandModeType.CHARGE_CLOSE.id) {
+ //鍏抽棴鍏呯數
+ command.setComplete(true);
+ } else {
+ command.setComplete(true);//鍏朵粬鍛戒护榛樿璁や负瀹屾垚
+ }
+
+ return true;
+ }
+
+ //鐢宠绠″埗
+ public boolean applyTrafficControl(List<ShuttleCommand> commands, List<NavigateNode> nodeList, Integer shuttleNo, Integer taskNo) {
+ TrafficControlThread trafficControlThread = (TrafficControlThread) SlaveConnection.get(SlaveType.TrafficControl, 1);
+ if (trafficControlThread == null) {
+ return false;
+ }
+
+ List<NavigateNode> totalNodeList = new ArrayList<>();
+ for (ShuttleCommand command : commands) {
+ if (command.getMode() == ShuttleCommandModeType.MOVE.id) {
+ List<NavigateNode> deepCopy = command.getNodesDeepCopy();
+ if (deepCopy != null) {
+ totalNodeList.addAll(deepCopy);
+ }
+ }
+ }
+ return trafficControlThread.applyTrafficControl(totalNodeList, nodeList, shuttleNo, taskNo);
+ }
+
+ //鏌ヨ鏄惁鐢宠绠″埗鎴愬姛
+ public boolean queryTrafficControl(Integer shuttleNo, Integer taskNo) {
+ Object object = redisUtil.get(RedisKeyType.TRAFFIC_CONTROL_SUCCESS_APPLY.key + shuttleNo + "_" + taskNo);
+ if (object == null) {
+ return false;
+ }
+ return true;
+ }
+
+ public boolean cancelTrafficControl(Integer shuttleNo, Integer taskNo) {
+ TrafficControlDataModel model = new TrafficControlDataModel();
+ model.setShuttleNo(shuttleNo);
+ model.setTaskNo(taskNo);
+ redisUtil.set(RedisKeyType.TRAFFIC_CONTROL_CANCEL_LIST.key + shuttleNo + "_" + taskNo, model);
return true;
}
@@ -310,7 +565,7 @@
return;
}
- if (shuttleThread.isRequireCharge()) {
+ if (!shuttleThread.isRequireCharge().equals(ShuttleRequireChargeType.NONE)) {
return;
}
@@ -318,12 +573,29 @@
return;
}
- String currentLocNo = shuttleProtocol.getCurrentLocNo();
- int lev = Utils.getLev(currentLocNo);
+ boolean demoSwitchLev = false;
+ Config demoSwitchLevConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "demoSwitchLev"));
+ if (demoSwitchLevConfig != null) {
+ if (demoSwitchLevConfig.getValue().equals("Y")) {
+ demoSwitchLev = true;
+ }
+ }
+
+ Config demoRunLevConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "demoRunLev"));
+ if (demoRunLevConfig == null) {
+ return;
+ }
+ List<Integer> levList = JSON.parseArray(demoRunLevConfig.getValue(), Integer.class);
+
+ if (!demoSwitchLev) {
+ String currentLocNo = shuttleProtocol.getCurrentLocNo();
+ levList = new ArrayList<>();
+ levList.add(Utils.getLev(currentLocNo));
+ }
LocMast targetLoc = null;
EntityWrapper<LocMast> wrapper = new EntityWrapper<>();
- wrapper.eq("lev1", lev);
+ wrapper.in("lev1", levList);
wrapper.eq("loc_sts", "O");
wrapper.last("ORDER BY RAND() LIMIT 1");
for (int i = 0; i < 3; i++) {
@@ -340,385 +612,157 @@
}
targetLoc = locMast;
+ break;
}
if(targetLoc == null) {
return;
}
- shuttleDispatchUtils.dispatchShuttle(null, targetLoc.getLocNo(), shuttleNo);
+ shuttleDispatchUtils.dispatchShuttle(null, targetLoc.getLocNo(), shuttleProtocol.getShuttleNo());
}
-// //璺戝簱绋嬪簭
-// public synchronized void moveLoc(Integer shuttleNo) {
-// ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
-// if (shuttleThread == null) {
-// return;
-// }
-// ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(false);
-// if (shuttleProtocol == null) {
-// return;
-// }
-//
-// //灏忚溅寮�鍚窇搴撴ā寮�
-// if (!shuttleProtocol.getMoveLoc()) {
-// return;
-// }
-//
-// //灏忚溅绌洪棽
-// if (!shuttleThread.isIdle()) {
-// return;
-// }
-//
-// int lev = Utils.getLev(shuttleProtocol.getCurrentLocNo());//灏忚溅褰撳墠妤煎眰
-//
-// if (shuttleProtocol.getMoveType() == 0) {//璺戣建閬�
-// //鏍规嵁鍦板浘鏂瑰悜鍐冲畾璺憍鎴杫
-// Config config = configService.selectOne(new EntityWrapper<Config>()
-// .eq("code", "direction_map")
-// .eq("status", 1));
-// if (config == null) {
-// //璺戝簱缁撴潫
-// 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;
-// }
-// String direction = config.getValue();
-//
-// if (direction.equals("y")) {//璺憍杞存柟鍚戯紝璺戝畬x杞村啀鍒囨崲y杞�
-// 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> locList = locMastService.selectList(new EntityWrapper<LocMast>()
-// .eq("loc_sts", LocStsType.O.toString())
-// .in("loc_no", locs));
-// if (locList.isEmpty()) {
-// //绌哄簱浣�
-// shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);
-// return;
-// }
-//
-// LocMast start = locList.get(0);
-// LocMast target = locList.get(locList.size() - 1);
-// //鍒ゆ柇灏忚溅鏄惁鍦ㄨ捣鐐逛綅缃�
-// if (!shuttleProtocol.getCurrentLocNo().equals(start.getLocNo())) {//涓嶅湪璧风偣浣嶇疆锛岃皟搴﹀幓璧风偣浣嶇疆
-// shuttleDispatcher.generateMoveTask(device, start.getLocNo());
-// }else {
-// //鍦ㄨ捣鐐逛綅缃紝璋冨害鍘荤洰鏍囦綅缃�
-// Task task = shuttleDispatcher.generateMoveTask(device, target.getLocNo());
-// if (task != null) {
-// shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);//鍒囨崲y杞�
-// }
-//
-// if(shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) {
-// //y杞翠篃璺戝畬浜嗭紝缁撴潫璺戝簱
-// 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;
-// }
-// }
-// }else {//璺憏杞存柟鍚戯紝璺戝畬y杞村啀鍒囨崲x杞�
-// ArrayList<String> locs = new ArrayList<>();
-// for (int i = shuttleProtocol.getYCurrent(); i <= shuttleProtocol.getYTarget(); i++) {
-// String locNo = Utils.getLocNo(shuttleProtocol.getXCurrent(), i, lev);
-// locs.add(locNo);
-// }
-//
-// List<Loc> locList = locService.list(new LambdaQueryWrapper<Loc>()
-// .eq(Loc::getLocSts, LocStsType.O.val())
-// .in(Loc::getLocNo, locs));
-// if (locList.isEmpty()) {
-// //绌哄簱浣�
-// shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
-// return;
-// }
-//
-// Loc start = locList.get(0);
-// Loc target = locList.get(locList.size() - 1);
-// //鍒ゆ柇灏忚溅鏄惁鍦ㄨ捣鐐逛綅缃�
-// if (!shuttleProtocol.getCurrentLocNo().equals(start.getLocNo())) {//涓嶅湪璧风偣浣嶇疆锛岃皟搴﹀幓璧风偣浣嶇疆
-// shuttleDispatcher.generateMoveTask(device, start.getLocNo());
-// }else {
-// //鍦ㄨ捣鐐逛綅缃紝璋冨害鍘荤洰鏍囦綅缃�
-// Task task = shuttleDispatcher.generateMoveTask(device, target.getLocNo());
-// if (task != null) {
-// shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);//鍒囨崲x杞�
-// }
-//
-// if(shuttleProtocol.getXCurrent() > shuttleProtocol.getXTarget()) {
-// //y杞翠篃璺戝畬浜嗭紝缁撴潫璺戝簱
-// 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;
-// }
-// }
-// }
-//
-// } else if (shuttleProtocol.getMoveType() == 1) {//璺戝簱浣�
-// //鏍规嵁鍦板浘鏂瑰悜鍐冲畾璺憍鎴杫
-// Dict dict = dictService.getOne(new LambdaQueryWrapper<Dict>()
-// .eq(Dict::getFlag, "direction_map")
-// .eq(Dict::getStatus, 1));
-// if (dict == null) {
-// //璺戝簱缁撴潫
-// 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;
-// }
-// String direction = dict.getValue();
-//
-// if (direction.equals("y")) {//璺憍杞存柟鍚戯紝璺戝畬x杞村啀鍒囨崲y杞�
-// Integer xCurrent = shuttleProtocol.getXCurrent();
-//
-// //鑾峰彇寰呰窇搴撲綅鍙�
-// String locNo = Utils.getLocNo(xCurrent, shuttleProtocol.getYCurrent(), lev);
-// Loc target = locService.getOne(new LambdaQueryWrapper<Loc>()
-// .eq(Loc::getLocNo, locNo)
-// .eq(Loc::getLocSts, LocStsType.O.val())
-// .eq(Loc::getHostId, device.getHostId()));
-// if (target == null || shuttleProtocol.getCurrentLocNo().equals(locNo)) {//搴撲綅涓嶅瓨鍦ㄦ垨灏忚溅宸插湪褰撳墠浣嶇疆
-// shuttleProtocol.setXCurrent(xCurrent + 1);
-// if (shuttleProtocol.getXCurrent() > shuttleProtocol.getXTarget()) {
-// //x杞磋窇瀹岋紝鍒囨崲y杞�
-// shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());
-// shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);
-//
-// if(shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) {
-// //y杞翠篃璺戝畬浜嗭紝缁撴潫璺戝簱
-// 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;
-// }
-// }
-// return;
-// }
-//
-// //璋冨害鍘诲簱浣�
-// Task task = shuttleDispatcher.generateMoveTask(device, locNo);
-// if (task == null) {
-// return;//璋冨害澶辫触
-// }
-//
-// shuttleProtocol.setXCurrent(xCurrent + 1);
-// if (shuttleProtocol.getXCurrent() > shuttleProtocol.getXTarget()) {
-// //x杞磋窇瀹岋紝鍒囨崲y杞�
-// shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());
-// shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);
-//
-// if(shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) {
-// //y杞翠篃璺戝畬浜嗭紝缁撴潫璺戝簱
-// 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;
-// }
-// }
-//
-// }else {//璺憏杞存柟鍚戯紝璺戝畬y杞村啀鍒囨崲x杞�
-// Integer yCurrent = shuttleProtocol.getYCurrent();
-//
-// //鑾峰彇寰呰窇搴撲綅鍙�
-// String locNo = Utils.getLocNo(shuttleProtocol.getXCurrent(), yCurrent, lev);
-// Loc target = locService.getOne(new LambdaQueryWrapper<Loc>()
-// .eq(Loc::getLocNo, locNo)
-// .eq(Loc::getLocSts, LocStsType.O.val())
-// .eq(Loc::getHostId, device.getHostId()));
-// if (target == null || shuttleProtocol.getCurrentLocNo().equals(locNo)) {//搴撲綅涓嶅瓨鍦ㄦ垨灏忚溅宸插湪褰撳墠浣嶇疆
-// shuttleProtocol.setYCurrent(yCurrent + 1);
-// if (shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) {
-// //y杞磋窇瀹岋紝鍒囨崲x杞�
-// shuttleProtocol.setYCurrent(shuttleProtocol.getYStart());
-// shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
-//
-// if(shuttleProtocol.getXCurrent() > shuttleProtocol.getXTarget()) {
-// //x杞翠篃璺戝畬浜嗭紝缁撴潫璺戝簱
-// 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;
-// }
-// }
-// return;
-// }
-//
-// //璋冨害鍘诲簱浣�
-// Task task = shuttleDispatcher.generateMoveTask(device, locNo);
-// if (task == null) {
-// return;//璋冨害澶辫触
-// }
-//
-// shuttleProtocol.setYCurrent(yCurrent + 1);
-// if (shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) {
-// //y杞磋窇瀹岋紝鍒囨崲x杞�
-// shuttleProtocol.setYCurrent(shuttleProtocol.getYStart());
-// shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
-//
-// if(shuttleProtocol.getXCurrent() > shuttleProtocol.getXTarget()) {
-// //x杞翠篃璺戝畬浜嗭紝缁撴潫璺戝簱
-// 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;
-// }
-// }
-//
-// }
-// } 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 {
-// Task result = shuttleDispatcher.generateMoveTask(device, locNo);
-// if (result != null) {//璋冨害鎴愬姛
-// 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 {
-// Task result = shuttleDispatcher.generateMoveTask(device, locNo);
-// if (result != null) {//璋冨害鎴愬姛
-// if (xCurrent.equals(shuttleProtocol.getXStart())) {
-// shuttleProtocol.setXCurrent(shuttleProtocol.getXTarget());//鍒囨崲搴撲綅
-// } else {
-// shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());//鍒囨崲搴撲綅
-// }
-// }
-// }
-// } else if (shuttleProtocol.getMoveType() == 4) {//鍙栨斁璐�
-// Integer xCurrent = shuttleProtocol.getXCurrent();
-// if (xCurrent > shuttleProtocol.getXTarget()) {//褰揦鍊煎ぇ浜嶺鐩爣鍊�
-// shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());
-// shuttleProtocol.setYCurrent(shuttleProtocol.getYStart());
-// return;
-// }
-//
-// //鍒ゆ柇x杞磋揣浣嶆槸鍚︽斁婊�
-// boolean flag = true;
-// for (Loc loc : locService.list(new LambdaQueryWrapper<Loc>()
-// .eq(Loc::getHostId, device.getHostId())
-// .eq(Loc::getRow, xCurrent)
-// .ge(Loc::getBay, shuttleProtocol.getYStart())
-// .le(Loc::getBay, shuttleProtocol.getYTarget()))) {
-// if (loc.getLocSts() != LocStsType.F.val()) {
-// flag = false;//鏈弧
-// break;
-// }
-// }
-// if (flag) {
-// shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
-// return;
-// }
-//
-// //鎼滅储鏈夎揣搴撲綅
-// List<Loc> list = locService.list(new LambdaQueryWrapper<Loc>()
-// .eq(Loc::getLocSts, LocStsType.F.val())
-// .eq(Loc::getHostId, device.getHostId())
-// .notIn(Loc::getRow, xCurrent)
-// .eq(Loc::getStatus, 1));
-// if (list.isEmpty()) {
-// return;
-// }
-//
-// Loc start = list.get(0);
-//
-// List<Loc> locList = locService.list(new LambdaQueryWrapper<Loc>()
-// .eq(Loc::getHostId, device.getHostId())
-// .eq(Loc::getStatus, 1)
-// .eq(Loc::getLocSts, LocStsType.O.val())
-// .eq(Loc::getRow, xCurrent)
-// .orderByDesc(Loc::getBay)
-// .orderByAsc(Loc::getRow));
-// if (locList.isEmpty()) {
-// return;
-// }
-//
-// Loc target = locList.get(0);
-// if (target == null) {
-// return;
-// }
-//
-// //璋冨害鍘荤洰鏍囦綅缃�
-// if (!shuttleProtocol.getCurrentLocNo().equals(target.getLocNo())) {
-// Task task = shuttleDispatcher.generateManuaTakeMoveTask(device, start.getLocNo(), target.getLocNo());
-//// if(task != null) {//璋冨害鎴愬姛
-//// shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
-//// }
-// }
-// }
-// }
+ public synchronized void demoModeCargoMove() {
+ Config demoCargoMoveConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "demoCargoMove"));
+ if (demoCargoMoveConfig == null) {
+ return;
+ }
- private synchronized CommandResponse write(ShuttleCommand command, Integer shuttleNo) {
+ if (!demoCargoMoveConfig.getValue().equals("Y")) {
+ return;
+ }
+
+
+ Config demoRunLevConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "demoRunLev"));
+ if (demoRunLevConfig == null) {
+ return;
+ }
+ List<Integer> levList = JSON.parseArray(demoRunLevConfig.getValue(), Integer.class);
+ Random random = new Random();
+ int index = random.nextInt(levList.size());
+ Integer lev = levList.get(index);
+
+ //鑾峰彇妤煎眰灏忚溅鏁伴噺
+ int shuttleCountByLev = shuttleDispatchUtils.getShuttleCountByLev(lev);
+ //鑾峰彇妤煎眰璐х墿鎼繍浠诲姟
+ int currentLevTask = 0;
+ for (WrkMast wrkMast : wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("io_type", WrkIoType.LOC_MOVE.id))) {
+ if (Utils.getLev(wrkMast.getLocNo()) == lev) {
+ currentLevTask += 1;
+ }
+ }
+
+ //鎼繍浠诲姟鏁伴噺瓒呰繃灏忚溅鏁伴噺锛屾殏鏃朵笉鐢熸垚鏂颁换鍔�
+ if (currentLevTask > shuttleCountByLev) {
+ return;
+ }
+
+ LocMast sourceLoc = null;
+ EntityWrapper<LocMast> wrapper = new EntityWrapper<>();
+ wrapper.eq("lev1", lev);
+ wrapper.eq("loc_sts", "F");
+ wrapper.last("ORDER BY RAND() LIMIT 1");
+ for (int i = 0; i < 3; i++) {
+ LocMast locMast = locMastService.selectOne(wrapper);
+ if(locMast == null) {
+ continue;
+ }
+
+ sourceLoc = locMast;
+ break;
+ }
+
+ if(sourceLoc == null) {
+ return;
+ }
+
+ LocMast targetLoc = null;
+ EntityWrapper<LocMast> targetWrapper = new EntityWrapper<>();
+ targetWrapper.eq("lev1", lev);
+ targetWrapper.eq("loc_sts", "O");
+ targetWrapper.last("ORDER BY RAND() LIMIT 1");
+ for (int i = 0; i < 3; i++) {
+ LocMast locMast = locMastService.selectOne(targetWrapper);
+ if(locMast == null) {
+ continue;
+ }
+
+ targetLoc = locMast;
+ break;
+ }
+
+ if(targetLoc == null) {
+ return;
+ }
+
+ try {
+ CreateLocMoveTaskParam param = new CreateLocMoveTaskParam();
+ param.setSourceLocNo(sourceLoc.getLocNo());
+ param.setLocNo(targetLoc.getLocNo());
+ param.setTaskPri(13);
+
+ boolean result = commonService.createLocMoveTask(param);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public synchronized void demoModeRunLoc(Integer shuttleNo) {
+ Config demoModeRunLocConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "demoModeRunLoc"));
+ if (demoModeRunLocConfig == null) {
+ return;
+ }
+
+ if (!demoModeRunLocConfig.getValue().equals("Y")) {
+ return;
+ }
+
+ ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
+ if (shuttleThread == null) {
+ return;
+ }
+
+ ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+ if (shuttleProtocol == null) {
+ return;
+ }
+
+ if (!shuttleThread.isIdle()) {
+ return;
+ }
+
+ LocMast targetLoc = null;
+ EntityWrapper<LocMast> wrapper = new EntityWrapper<>();
+ wrapper.eq("lev1", Utils.getLev(shuttleProtocol.getCurrentLocNo()));
+ wrapper.notIn("loc_sts", "X");
+ wrapper.isNull("loc_type");
+ wrapper.last("ORDER BY RAND() LIMIT 1");
+ for (int i = 0; i < 3; i++) {
+ LocMast locMast = locMastService.selectOne(wrapper);
+ if(locMast == null) {
+ continue;
+ }
+
+ targetLoc = locMast;
+ break;
+ }
+
+ if(targetLoc == null) {
+ return;
+ }
+
+ boolean result = shuttleDispatchUtils.dispatchShuttle(null, targetLoc.getLocNo(), shuttleProtocol.getShuttleNo());
+ if (result) {
+ targetLoc.setLocType("Y");
+ locMastService.updateById(targetLoc);
+ }
+ }
+
+ public synchronized boolean clearPath(Integer shuttleNo) {
+ return navigateMapUtils.clearPath(shuttleNo);
+ }
+
+ private CommandResponse write(ShuttleCommand command, Integer shuttleNo) {
CommandResponse response = new CommandResponse(false);
if (null == command) {
News.error("鍥涘悜绌挎杞﹀啓鍏ュ懡浠や负绌�");
--
Gitblit v1.9.1