From 6182cc11c3e93610df7fda87611d2ca807c6354c Mon Sep 17 00:00:00 2001
From: qlsxk <qlsxk@qq.com>
Date: 星期四, 16 十月 2025 14:28:30 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/impl/NyShuttleThread.java | 559 ++++++++++++++++++++++++++++++++++---------------------
1 files changed, 347 insertions(+), 212 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/impl/NyShuttleThread.java b/src/main/java/com/zy/core/thread/impl/NyShuttleThread.java
index 166c711..30b6c6c 100644
--- a/src/main/java/com/zy/core/thread/impl/NyShuttleThread.java
+++ b/src/main/java/com/zy/core/thread/impl/NyShuttleThread.java
@@ -5,14 +5,11 @@
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.DateUtils;
import com.core.common.SpringUtils;
-import com.core.exception.CoolException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zy.asrs.entity.BasShuttle;
import com.zy.asrs.entity.DeviceConfig;
-import com.zy.asrs.entity.DeviceDataLog;
import com.zy.asrs.entity.LocMast;
import com.zy.asrs.service.BasShuttleService;
-import com.zy.asrs.service.DeviceDataLogService;
import com.zy.asrs.service.LocMastService;
import com.zy.asrs.utils.Utils;
import com.zy.common.ExecuteSupport;
@@ -22,10 +19,12 @@
import com.zy.common.utils.NavigateMapData;
import com.zy.common.utils.NavigatePositionConvert;
import com.zy.common.utils.RedisUtil;
+import com.zy.common.utils.ShuttleOperaUtils;
import com.zy.core.News;
-import com.zy.core.model.DeviceCommandMsgModel;
-import com.zy.core.utils.DeviceMsgUtils;
import com.zy.core.action.ShuttleAction;
+import com.zy.core.model.DeviceCommandMsgModel;
+import com.zy.core.model.command.ShuttleAssignCommand;
+import com.zy.core.utils.DeviceMsgUtils;
import com.zy.core.cache.OutputQueue;
import com.zy.core.enums.*;
import com.zy.core.model.CommandResponse;
@@ -52,12 +51,14 @@
private DeviceConfig deviceConfig;
private RedisUtil redisUtil;
private ShuttleProtocol shuttleProtocol;
+ private ShuttleAction shuttleAction = null;
private static final boolean DEBUG = false;//璋冭瘯妯″紡
private List<JSONObject> socketReadResults = new ArrayList<>();
- private List<JSONObject> socketResults = new ArrayList<>();
+ private List<DeviceMsgModel> socketResults = new ArrayList<>();
+ private Long requestReadTime = System.currentTimeMillis();
//鍘熷璁惧鏁版嵁
private Object originDeviceData;
@@ -78,6 +79,9 @@
listenInit();//鐩戝惉鍒濆鍖栦簨浠�
readStatus();
Thread.sleep(100);
+
+// //灏忚溅绌洪棽涓旀湁璺戝簱绋嬪簭
+// shuttleAction.moveLoc(deviceConfig.getDeviceNo());
} catch (Exception e) {
log.error("ShuttleThread Fail", e);
}
@@ -85,85 +89,35 @@
});
readThread.start();
- //璁惧鎵ц
- Thread executeThread = new Thread(() -> {
- while (true) {
- try {
- ShuttleAction shuttleAction = null;
- try {
- shuttleAction = SpringUtils.getBean(ShuttleAction.class);
- }catch (Exception e){
- continue;
- }
-
- if (shuttleAction == null) {
- continue;
- }
-
- Object object = redisUtil.get(RedisKeyType.SHUTTLE_FLAG.key + deviceConfig.getDeviceNo());
- if (object == null) {
- continue;
- }
-
- Integer taskNo = Integer.valueOf(String.valueOf(object));
- if (taskNo != 0) {
- //瀛樺湪浠诲姟闇�瑕佹墽琛�
- boolean result = shuttleAction.executeWork(deviceConfig.getDeviceNo(), taskNo);
- }
-
-// //灏忚溅绌洪棽涓旀湁璺戝簱绋嬪簭
-// shuttleAction.moveLoc(deviceConfig.getDeviceNo());
-
- //婕旂ず妯″紡
- shuttleAction.demo(deviceConfig.getDeviceNo());
-
- Thread.sleep(200);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- executeThread.start();
-
- //鍏朵粬浠诲姟
- Thread otherThread = new Thread(() -> {
- while (true) {
- try {
- saveLog();//淇濆瓨鏁版嵁
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- otherThread.start();
- }
-
- private void saveLog() {
- if (shuttleProtocol == null) {
- return;
- }
-
- if (System.currentTimeMillis() - shuttleProtocol.getDeviceDataLog() > 1000 * 5) {
- if (this.originDeviceData != null) {
- //閲囬泦鏃堕棿瓒呰繃5s锛屼繚瀛樹竴娆℃暟鎹褰�
- //淇濆瓨鏁版嵁璁板綍
- DeviceDataLogService deviceDataLogService = SpringUtils.getBean(DeviceDataLogService.class);
- if (deviceDataLogService == null) {
- return;
- }
- DeviceDataLog deviceDataLog = new DeviceDataLog();
- deviceDataLog.setOriginData(JSON.toJSONString(this.originDeviceData));
- deviceDataLog.setWcsData(JSON.toJSONString(shuttleProtocol));
- deviceDataLog.setType(String.valueOf(SlaveType.Shuttle));
- deviceDataLog.setDeviceNo(deviceConfig.getDeviceNo());
- deviceDataLog.setCreateTime(new Date());
- deviceDataLogService.insert(deviceDataLog);
-
- //鏇存柊閲囬泦鏃堕棿
- shuttleProtocol.setDeviceDataLog(System.currentTimeMillis());
- OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), deviceConfig.getDeviceNo()));
- }
- }
+// //璁惧鎵ц
+// Thread executeThread = new Thread(() -> {
+// while (true) {
+// try {
+// if (shuttleAction == null) {
+// try {
+// shuttleAction = SpringUtils.getBean(ShuttleAction.class);
+// }catch (Exception e){
+// }
+// continue;
+// }
+//
+// Object object = redisUtil.get(RedisKeyType.SHUTTLE_FLAG.key + deviceConfig.getDeviceNo());
+// if (object == null) {
+// continue;
+// }
+//
+// Integer taskNo = Integer.valueOf(String.valueOf(object));
+// if (taskNo != 0) {
+// //瀛樺湪浠诲姟闇�瑕佹墽琛�
+// boolean result = shuttleAction.executeWork(deviceConfig.getDeviceNo(), taskNo);
+// }
+// Thread.sleep(100);
+// } catch (Exception e) {
+// e.printStackTrace();
+// }
+// }
+// });
+// executeThread.start();
}
private void listenMessageFromRedis() {
@@ -188,54 +142,32 @@
data.put("originDeviceData", deviceMsg.getDeviceOriginMsg());
socketReadResults.add(data);
} else {
- socketResults.add(data);//娣诲姞鏁版嵁
+ socketResults.add(deviceMsg);//娣诲姞鏁版嵁
}
} catch (Exception e) {
e.printStackTrace();
}
}
- public JSONObject getRequestBody(String type, String taskId) {
+ public JSONObject getRequestBody(String resultKey) {
try {
// 鑾峰彇鏈嶅姟鍣ㄥ搷搴�
JSONObject result = null;
- if (type.equals("readState")) {
- type = "state";
- }
-
+ int idx = -1;
for (int i = 0; i < socketResults.size(); i++) {
- JSONObject socketResult = socketResults.get(i);
- if (!socketResult.get("msgType").equals("responseMsg")) {//涓嶆槸鍝嶅簲鍐呭
- continue;
- }
-
- JSONObject resultResponse = JSON.parseObject(socketResult.get("response").toString());
- JSONObject resultBody = JSON.parseObject(resultResponse.get("body").toString());
- String responseType = resultBody.get("responseType").toString();
- if (DEBUG) {
- result = socketResult;
+ DeviceMsgModel deviceMsgModel = socketResults.get(i);
+ if(deviceMsgModel.getResultKey().equals(resultKey)){
+ idx = i;
+ result = JSON.parseObject(JSON.toJSONString(deviceMsgModel.getDeviceMsg()));
break;
}
-
- if (!responseType.equals(type)) {
- continue;//鍝嶅簲绫诲瀷涓庤姹傜被鍨嬩笉涓�鑷达紝涓嶅湪璋冭瘯妯″紡涓�
- }
-
- if (taskId != null) {
- String responseTaskId = resultBody.get("taskId").toString();
- if (!responseTaskId.equals(taskId)) {
- continue;//鍝嶅簲ID涓庤姹侷D涓嶄竴鑷达紝涓嶅湪璋冭瘯妯″紡涓�
- }
- }
-
- result = socketResult;
- break;
}
if (result == null) {
return null;//鏃犲搷搴旂粨鏋�
}
+ socketResults.remove(idx);
return filterBodyData(result);//杩斿洖Body缁撴灉闆�
} catch (Exception e) {
return null;
@@ -268,7 +200,10 @@
//鎸囦护瓒呰繃2鏉★紝涓嶅啀涓嬪彂浠诲姟鐘舵�佽姹�
TreeSet<String> deviceCommandMsgListKey = deviceMsgUtils.getDeviceCommandMsgListKey(SlaveType.Shuttle, deviceConfig.getDeviceNo());
if (deviceCommandMsgListKey.size() < 2) {
- requestCommand(readStatusCommand);//璇锋眰鐘舵��
+ if ((System.currentTimeMillis() - requestReadTime) > 500) {
+ requestCommand(readStatusCommand);//璇锋眰鐘舵��
+ requestReadTime = System.currentTimeMillis();
+ }
}
if (this.socketReadResults.isEmpty()) {
@@ -359,35 +294,38 @@
// 鑾峰彇鏈嶅姟鍣ㄥ搷搴�
JSONObject result = null;
int removeIdx = -1;
+ JSONObject socketResult = null;
for (int i = 0; i < socketResults.size(); i++) {
- JSONObject socketResult = socketResults.get(i);
- if (socketResult == null) {
+ DeviceMsgModel deviceMsgModel = socketResults.get(i);
+ if (!deviceMsgModel.getDeviceMsgType().equals("shuttleInit")) {
continue;
}
- if (!socketResult.get("msgType").equals("requestMsg")) {//涓嶆槸璇锋眰鍐呭
- continue;
- }
+ removeIdx = i;
+ socketResult = JSON.parseObject(JSON.toJSONString(deviceMsgModel.getDeviceMsg()));
+ break;
+ }
- JSONObject resultResponse = JSON.parseObject(socketResult.get("request").toString());
- JSONObject resultHeader = JSON.parseObject(resultResponse.get("header").toString());
- JSONObject resultBody = JSON.parseObject(resultResponse.get("body").toString());
- String requestType = resultBody.getString("requestType");
- Integer requestId = resultHeader.getInteger("requestId");
- if (requestType.equals("init")) {
- removeIdx = i;//姝ゆ暟鎹凡缁忓鐞嗭紝浠庣粨鏋滈泦涓墧闄�
- socketResults.remove(removeIdx);
+ if (socketResult == null) {
+ return;
+ }
- Integer code = resultBody.getInteger("code");
- //灏忚溅澶嶄綅璇锋眰
- ShuttleCommand initCommand = getInitCommand(requestId, code);
- //鍙戝嚭璇锋眰
- NyShuttleHttpCommand httpCommand = JSON.parseObject(initCommand.getBody(), NyShuttleHttpCommand.class);
- requestCommand(httpCommand);
+ JSONObject resultResponse = JSON.parseObject(socketResult.get("request").toString());
+ JSONObject resultHeader = JSON.parseObject(resultResponse.get("header").toString());
+ JSONObject resultBody = JSON.parseObject(resultResponse.get("body").toString());
+ String requestType = resultBody.getString("requestType");
+ Integer requestId = resultHeader.getInteger("requestId");
+ if (requestType.equals("init")) {
+ socketResults.remove(removeIdx);
- log.info(MessageFormat.format("銆恵0}銆戝洓鍚戣溅澶嶄綅涓婃姤 ===>> [code:{1}] [ip:{2}] [port:{3}]", deviceConfig.getDeviceNo(), code, deviceConfig.getIp(), deviceConfig.getPort()));
- OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆戝洓鍚戣溅澶嶄綅涓婃姤 ===>> [code:{1}] [ip:{2}] [port:{3}]", deviceConfig.getDeviceNo(), code, deviceConfig.getIp(), deviceConfig.getPort()));
- break;
- }
+ Integer code = resultBody.getInteger("code");
+ //灏忚溅澶嶄綅璇锋眰
+ ShuttleCommand initCommand = getInitCommand(requestId, code);
+ //鍙戝嚭璇锋眰
+ NyShuttleHttpCommand httpCommand = JSON.parseObject(initCommand.getBody(), NyShuttleHttpCommand.class);
+ requestCommand(httpCommand);
+
+ log.info(MessageFormat.format("銆恵0}銆戝洓鍚戣溅澶嶄綅涓婃姤 ===>> [code:{1}] [ip:{2}] [port:{3}]", deviceConfig.getDeviceNo(), code, deviceConfig.getIp(), deviceConfig.getPort()));
+ OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆戝洓鍚戣溅澶嶄綅涓婃姤 ===>> [code:{1}] [ip:{2}] [port:{3}]", deviceConfig.getDeviceNo(), code, deviceConfig.getIp(), deviceConfig.getPort()));
}
} catch (Exception e) {
e.printStackTrace();
@@ -479,9 +417,9 @@
try {
//鍙戝嚭璇锋眰
NyShuttleHttpCommand httpCommand = JSON.parseObject(command.getBody(), NyShuttleHttpCommand.class);
- JSONObject requestToken = requestCommand(httpCommand);
+ String resultKey = requestCommand(httpCommand);
//鏌ヨ璇锋眰缁撴灉
- JSONObject result = queryCommandStatus(requestToken.getString("requestType"), requestToken.getString("taskId"));
+ JSONObject result = queryCommandStatus(resultKey);
if (result == null) {
return response;//璇锋眰澶辫触
}
@@ -502,9 +440,9 @@
try {
//鍙戝嚭璇锋眰
NyShuttleHttpCommand httpCommand = JSON.parseObject(command.getBody(), NyShuttleHttpCommand.class);
- JSONObject requestToken = requestCommand(httpCommand);
+ String resultKey = requestCommand(httpCommand);
//鏌ヨ璇锋眰缁撴灉
- JSONObject result = queryCommandStatus(requestToken.getString("requestType"), requestToken.getString("taskId"));
+ JSONObject result = queryCommandStatus(resultKey);
if (result == null) {
return response;//璇锋眰澶辫触
}
@@ -524,9 +462,9 @@
try {
//鍙戝嚭璇锋眰
NyShuttleHttpCommand httpCommand = JSON.parseObject(command.getBody(), NyShuttleHttpCommand.class);
- JSONObject requestToken = requestCommand(httpCommand);
+ String resultKey = requestCommand(httpCommand);
//鏌ヨ璇锋眰缁撴灉
- JSONObject result = queryCommandStatus(requestToken.getString("requestType"), requestToken.getString("taskId"));
+ JSONObject result = queryCommandStatus(resultKey);
if (result == null) {
return response;//璇锋眰澶辫触
}
@@ -554,9 +492,9 @@
try {
//鍙戝嚭璇锋眰
NyShuttleHttpCommand httpCommand = JSON.parseObject(command.getBody(), NyShuttleHttpCommand.class);
- JSONObject requestToken = requestCommand(httpCommand);
+ String resultKey = requestCommand(httpCommand);
//鏌ヨ璇锋眰缁撴灉
- JSONObject result = queryCommandStatus(requestToken.getString("requestType"), requestToken.getString("taskId"));
+ JSONObject result = queryCommandStatus(resultKey);
if (result == null) {
return response;//璇锋眰澶辫触
}
@@ -643,7 +581,7 @@
}
@Override
- public boolean isRequireCharge() {
+ public ShuttleRequireChargeType isRequireCharge() {
if (this.shuttleProtocol.getDeviceStatus() == null
|| this.shuttleProtocol.getPakMk() == null
|| this.shuttleProtocol.getErrorCode() == null
@@ -651,7 +589,7 @@
|| this.shuttleProtocol.getMode() == null
|| this.shuttleProtocol.getExtend() == null
) {
- return false;
+ return ShuttleRequireChargeType.NONE;
}
InnerSuhttleExtend extend = (InnerSuhttleExtend) this.shuttleProtocol.getExtend();
@@ -664,25 +602,43 @@
&& extend.getSuspendState() == 0
;
if (!res) {
- return res;
+ return ShuttleRequireChargeType.NONE;
} else {
// 鐢甸噺灏忎簬闃堝�奸渶瑕佽繘琛屽厖鐢�
try {
BasShuttleService shuttleService = SpringUtils.getBean(BasShuttleService.class);
if (shuttleService == null) {
- return false;
+ return ShuttleRequireChargeType.NONE;
}
+
BasShuttle basShuttle = shuttleService.selectOne(new EntityWrapper<BasShuttle>().eq("shuttle_no", deviceConfig.getDeviceNo()));
if (basShuttle == null) {
- return false;
+ return ShuttleRequireChargeType.NONE;
}
+
Integer chargeLine = basShuttle.getChargeLine();
if (chargeLine == null) {
- return false;
+ return ShuttleRequireChargeType.NONE;
}
- return Integer.valueOf(this.shuttleProtocol.getBatteryPower()) < chargeLine;
+
+ boolean chargeResult = Integer.valueOf(this.shuttleProtocol.getBatteryPower()) < chargeLine;
+ if (chargeResult) {
+ return ShuttleRequireChargeType.FORCE_CHARGE;//闇�瑕佸己鍒跺厖鐢�
+ }
+
+ Integer suggestChargeLine = basShuttle.getSuggestChargeLine();
+ if (suggestChargeLine == null) {
+ return ShuttleRequireChargeType.NONE;
+ }
+
+ boolean suggestChargeResult = Integer.valueOf(this.shuttleProtocol.getBatteryPower()) < suggestChargeLine;
+ if (suggestChargeResult) {
+ return ShuttleRequireChargeType.SUGGEST_CHARGE;//寤鸿鍏呯數
+ }
+
+ return ShuttleRequireChargeType.NONE;
} catch (Exception e) {
- return false;
+ return ShuttleRequireChargeType.NONE;
}
}
}
@@ -798,7 +754,7 @@
//灏嗚矾寰勯攣涓庡皬杞﹁矾寰勮繘琛屽尮閰�
ArrayList<NavigateNode> tmp = new ArrayList<>();
//妫�娴嬭矾寰勬槸鍚﹁閿佸畾
- int[][] map = navigateMapData.getDataFromRedis(lev, NavigationMapType.DFX.id, null, null);
+ int[][] map = navigateMapData.getDataFromRedis(lev, NavigationMapType.getDfxWithDevice(), null, null);
for (NavigateNode node : path) {
if(map[node.getX()][node.getY()] == -999) {
tmp.add(node);
@@ -818,19 +774,24 @@
@Override
public synchronized boolean setProtocolStatus(ShuttleProtocolStatusType status) {
+ if (status.equals(ShuttleProtocolStatusType.IDLE)) {
+ this.shuttleProtocol.setIdleTime(System.currentTimeMillis());
+ }
this.shuttleProtocol.setProtocolStatus(status);
return true;
}
@Override
public synchronized boolean setTaskNo(Integer taskNo) {
+ redisUtil.set(RedisKeyType.SHUTTLE_FLAG.key + shuttleProtocol.getShuttleNo(), taskNo);
this.shuttleProtocol.setTaskNo(taskNo);
return true;
}
@Override
public synchronized boolean setSyncTaskNo(Integer taskNo) {
- this.shuttleProtocol.setSyncTaskNo(taskNo);
+ redisUtil.setSync(RedisKeyType.SHUTTLE_FLAG.key + shuttleProtocol.getShuttleNo(), taskNo);
+ this.shuttleProtocol.setTaskNo(taskNo);
return true;
}
@@ -887,6 +848,18 @@
}
@Override
+ public boolean setTrafficControl(boolean enable, List<NavigateNode> nodeList) {
+ shuttleProtocol.setTrafficControl(enable);
+ shuttleProtocol.setTrafficControlNodes(nodeList);
+ return true;
+ }
+
+ @Override
+ public void updateDeviceDataLogTime(long time) {
+ shuttleProtocol.setDeviceDataLog(time);
+ }
+
+ @Override
public JSONObject parseStatusToMsg(ShuttleProtocol shuttleProtocol) {
JSONObject result = new JSONObject();
result.put("msgType", "responseMsg");
@@ -903,7 +876,124 @@
}
@Override
- public ShuttleCommand getMoveCommand(Integer taskNo, String startCodeNum, String distCodeNum, Integer allDistance, Integer runDirection, Integer runSpeed, List<NavigateNode> nodes) {
+ public boolean restartCalcPath() {
+ ConfigService configService = SpringUtils.getBean(ConfigService.class);
+ if (configService == null) {
+ return false;
+ }
+
+ ShuttleAction shuttleAction = SpringUtils.getBean(ShuttleAction.class);
+ if (shuttleAction == null) {
+ return false;
+ }
+
+ ShuttleOperaUtils shuttleOperaUtils = SpringUtils.getBean(ShuttleOperaUtils.class);
+ if (shuttleOperaUtils == null) {
+ return false;
+ }
+
+ ObjectMapper objectMapper = SpringUtils.getBean(ObjectMapper.class);
+ if (objectMapper == null) {
+ return false;
+ }
+
+ boolean trafficControlRestartCalcPath = false;
+ Config trafficControlRestartCalcPathConfig = configService.selectOne(new EntityWrapper<Config>()
+ .eq("code", "trafficControlRestartCalcPath")
+ );
+ if(trafficControlRestartCalcPathConfig != null) {
+ trafficControlRestartCalcPath = trafficControlRestartCalcPathConfig.getValue().equals("Y") ? true : false;
+ }
+
+ if (!trafficControlRestartCalcPath) {
+ return false;
+ }
+
+ if (shuttleProtocol.getTaskNo() == 0) {
+ return false;
+ }
+
+ if (!this.isDeviceIdle()) {
+ return false;
+ }
+
+ Object object = redisUtil.get(RedisKeyType.SHUTTLE_RESTART_CALC_PATH.key + shuttleProtocol.getShuttleNo());
+ if (object != null) {
+ return false;
+ }
+
+ Integer taskNo = shuttleProtocol.getTaskNo();
+ Object obj = redisUtil.get(RedisKeyType.SHUTTLE_WORK_FLAG.key + taskNo);
+ if (obj == null) {
+ return false;
+ }
+
+ ShuttleRedisCommand redisCommand = null;
+ try {
+ redisCommand = objectMapper.readValue(String.valueOf(obj), ShuttleRedisCommand.class);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
+ if (redisCommand == null) {
+ return false;
+ }
+
+ ShuttleAssignCommand assignCommand = redisCommand.getAssignCommand();
+ String locNo = assignCommand.getLocNo();
+ List<NavigationMapType> mapTypes = assignCommand.getMapTypes();
+ if (locNo == null) {
+ return false;
+ }
+
+ if (mapTypes == null) {
+ return false;
+ }
+
+ List<NavigationMapType> restartCalcMapTypes = new ArrayList<>(mapTypes);
+ restartCalcMapTypes.add(NavigationMapType.SHUTTLE);
+
+ if (assignCommand.getTaskMode() == ShuttleTaskModeType.TRANSPORT.id) {
+ restartCalcMapTypes.add(NavigationMapType.DFX);
+ }
+
+ String currentLocNo = shuttleProtocol.getCurrentLocNo();
+ List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(currentLocNo, locNo, restartCalcMapTypes, assignCommand, this);
+ if (commands == null) {
+ return false;
+ }
+
+ if (assignCommand.getTaskMode() == ShuttleTaskModeType.TRANSPORT.id) {
+ List<ShuttleCommand> originCommands = assignCommand.getCommands();
+ if (originCommands == null) {
+ return false;
+ }
+
+ ShuttleCommand firstCommand = originCommands.get(0);
+ ShuttleCommand endCommand = originCommands.get(originCommands.size() - 1);
+
+ if (firstCommand.getMode() != ShuttleCommandModeType.PALLET_LIFT.id) {
+ return false;
+ }
+
+ if (endCommand.getMode() != ShuttleCommandModeType.PALLET_DOWN.id) {
+ return false;
+ }
+
+ commands.add(0, firstCommand);
+ commands.add(endCommand);
+ }
+
+ assignCommand.setCommands(commands);
+
+ //涓嬪彂浠诲姟
+ shuttleAction.assignWork(shuttleProtocol.getShuttleNo(), assignCommand);
+ redisUtil.set(RedisKeyType.SHUTTLE_RESTART_CALC_PATH.key + shuttleProtocol.getShuttleNo(), true, 60);
+ return true;
+ }
+
+ @Override
+ public ShuttleCommand getMoveCommand(Integer taskNo, String startCodeNum, String distCodeNum, Integer allDistance, Integer runDirection, Integer runSpeed, List<NavigateNode> nodes, Boolean shuttleDirectionReverse) {
NavigateMapData navigateMapData = SpringUtils.getBean(NavigateMapData.class);
NyShuttleHttpCommand httpStandard = getHttpStandard(deviceConfig.getDeviceNo(), taskNo);
NyShuttleHttpCommand.NyRequest request = httpStandard.getRequest();
@@ -914,21 +1004,25 @@
HashMap<String, Object> body = new HashMap<>();
body.put("requestType", "move");//绉诲姩鍛戒护
body.put("taskId", taskId);//TaskID闇�瑕侀殢鏈�
-// body.put("start", navigateNodeToNyPointNode(NavigatePositionConvert.codeToNode(startCodeNum, device.getHostId())));//璧风偣
-// body.put("target", navigateNodeToNyPointNode(NavigatePositionConvert.codeToNode(distCodeNum, device.getHostId())));//缁堢偣
body.put("path", path);
request.setBody(body);
NavigateNode startNode = nodes.get(0);
+ List<List<MapNode>> mapData = navigateMapData.getJsonData(startNode.getZ(), NavigationMapType.getMapTypes(NavigationMapType.NONE), null, null);
for (NavigateNode node : nodes) {
HashMap<String, Object> data = new HashMap<>();
String codeNum = NavigatePositionConvert.xyToPosition(node.getX(), node.getY(), node.getZ());
Map<String, Object> nyNode = navigateNodeToNyPointNode(NavigatePositionConvert.codeToNode(codeNum));
- int xp = Integer.parseInt(String.valueOf(nyNode.get("y")));
- int yp = Integer.parseInt(String.valueOf(nyNode.get("x")));
+
+ int xp = Integer.parseInt(String.valueOf(nyNode.get("x")));
+ int yp = Integer.parseInt(String.valueOf(nyNode.get("y")));
+ if (shuttleDirectionReverse) {
+ xp = Integer.parseInt(String.valueOf(nyNode.get("y")));
+ yp = Integer.parseInt(String.valueOf(nyNode.get("x")));
+ }
+
int z = Integer.parseInt(String.valueOf(nyNode.get("z")));
- List<List<MapNode>> mapData = navigateMapData.getJsonData(startNode.getZ(), NavigationMapType.NONE.id, null, null);
List<MapNode> mapNodes = mapData.get(node.getX());
MapNode mapNode = mapNodes.get(node.getY());
@@ -942,18 +1036,77 @@
httpStandard.setRequest(request);
- LocMastService locMastService = SpringUtils.getBean(LocMastService.class);
- LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
- .eq("qr_code_value", distCodeNum));
- if (locMast == null) {
- throw new CoolException("搴撲綅淇℃伅涓嶅瓨鍦�");
- }
+ Object object = redisUtil.get(RedisKeyType.LOC_MAP.key);
+ HashMap<String, String> locMap = (HashMap<String, String>) object;
+ String targetLocNo = locMap.get(distCodeNum);
ShuttleCommand command = new ShuttleCommand();
command.setShuttleNo(deviceConfig.getDeviceNo());
command.setBody(JSON.toJSONString(httpStandard));
command.setMode(ShuttleCommandModeType.MOVE.id);
- command.setTargetLocNo(locMast.getLocNo());
+ command.setTargetLocNo(targetLocNo);
+ command.setTaskNo(taskId);
+ return command;
+ }
+
+ @Override
+ public ShuttleCommand getMoveLiftCommand(Integer taskNo, String startCodeNum, String distCodeNum, Integer allDistance, Integer runDirection, Integer runSpeed, List<NavigateNode> nodes, Boolean moveIn, Boolean shuttleDirectionReverse) {
+ NavigateMapData navigateMapData = SpringUtils.getBean(NavigateMapData.class);
+ NyShuttleHttpCommand httpStandard = getHttpStandard(deviceConfig.getDeviceNo(), taskNo);
+ NyShuttleHttpCommand.NyRequest request = httpStandard.getRequest();
+
+ ArrayList<HashMap<String, Object>> path = new ArrayList<>();
+
+ Integer taskId = getTaskId();
+ HashMap<String, Object> body = new HashMap<>();
+// if (moveIn) {
+// body.put("requestType", "intoLift");//杩涙彁鍗囨満
+// } else {
+// body.put("requestType", "outLift");//鍑烘彁鍗囨満
+// }
+ body.put("requestType", "move");//绉诲姩鍛戒护
+ body.put("taskId", taskId);//TaskID闇�瑕侀殢鏈�
+ body.put("path", path);
+ request.setBody(body);
+
+ NavigateNode startNode = nodes.get(0);
+ List<List<MapNode>> mapData = navigateMapData.getJsonData(startNode.getZ(), NavigationMapType.getMapTypes(NavigationMapType.NONE), null, null);
+ for (NavigateNode node : nodes) {
+ HashMap<String, Object> data = new HashMap<>();
+ String codeNum = NavigatePositionConvert.xyToPosition(node.getX(), node.getY(), node.getZ());
+ Map<String, Object> nyNode = navigateNodeToNyPointNode(NavigatePositionConvert.codeToNode(codeNum));
+
+ int xp = Integer.parseInt(String.valueOf(nyNode.get("x")));
+ int yp = Integer.parseInt(String.valueOf(nyNode.get("y")));
+ if (shuttleDirectionReverse) {
+ xp = Integer.parseInt(String.valueOf(nyNode.get("y")));
+ yp = Integer.parseInt(String.valueOf(nyNode.get("x")));
+ }
+
+ int z = Integer.parseInt(String.valueOf(nyNode.get("z")));
+
+ List<MapNode> mapNodes = mapData.get(node.getX());
+ MapNode mapNode = mapNodes.get(node.getY());
+
+ data.put("xp", xp);
+ data.put("yp", yp);
+ data.put("z", z);
+ data.put("x", mapNode.getXBase());
+ data.put("y", mapNode.getYBase());
+ path.add(data);
+ }
+
+ httpStandard.setRequest(request);
+
+ Object object = redisUtil.get(RedisKeyType.LOC_MAP.key);
+ HashMap<String, String> locMap = (HashMap<String, String>) object;
+ String targetLocNo = locMap.get(distCodeNum);
+
+ ShuttleCommand command = new ShuttleCommand();
+ command.setShuttleNo(deviceConfig.getDeviceNo());
+ command.setBody(JSON.toJSONString(httpStandard));
+ command.setMode(ShuttleCommandModeType.MOVE.id);
+ command.setTargetLocNo(targetLocNo);
command.setTaskNo(taskId);
return command;
}
@@ -1022,7 +1175,6 @@
//鑾峰彇灏忚溅澶嶄綅鍝嶅簲鍛戒护
public ShuttleCommand getInitCommand(Integer taskNo, Integer code) {
- LocMastService locMastService = SpringUtils.getBean(LocMastService.class);
NavigateMapData navigateMapData = SpringUtils.getBean(NavigateMapData.class);
NyShuttleHttpCommand httpStandard = getHttpStandard(deviceConfig.getDeviceNo(), taskNo);
NyShuttleHttpCommand.NyRequest request = httpStandard.getRequest();
@@ -1038,15 +1190,14 @@
map.put("z", lev);
String mapStr = JSON.toJSONString(map);
- LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
- .eq("qr_code_value", mapStr));
- if (locMast == null) {
- throw new CoolException("鍦板潃鐮佷笉瀛樺湪");
- }
- List<List<MapNode>> mapData = navigateMapData.getJsonData(lev, NavigationMapType.NONE.id, null, null);
- List<MapNode> mapNodes = mapData.get(locMast.getRow1());
- MapNode mapNode = mapNodes.get(locMast.getBay1());
+ Object object = redisUtil.get(RedisKeyType.LOC_MAP.key);
+ HashMap<String, String> locMap = (HashMap<String, String>) object;
+ String targetLocNo = locMap.get(mapStr);
+
+ List<List<MapNode>> mapData = navigateMapData.getJsonData(lev, NavigationMapType.getMapTypes(NavigationMapType.NONE), null, null);
+ List<MapNode> mapNodes = mapData.get(Utils.getRow(targetLocNo));
+ MapNode mapNode = mapNodes.get(Utils.getBay(targetLocNo));
HashMap<String, Object> location = new HashMap<>();
location.put("xp", row);
@@ -1127,7 +1278,7 @@
}
//鍙戝嚭璇锋眰
- private JSONObject requestCommand(NyShuttleHttpCommand httpCommand) throws IOException {
+ private String requestCommand(NyShuttleHttpCommand httpCommand) throws IOException {
try {
DeviceMsgUtils deviceMsgUtils = SpringUtils.getBean(DeviceMsgUtils.class);
if (deviceMsgUtils == null) {
@@ -1143,39 +1294,25 @@
commandMsgModel.setDeviceType(String.valueOf(SlaveType.Shuttle));
commandMsgModel.setCommand(data);
String key = deviceMsgUtils.sendDeviceCommand(SlaveType.Shuttle, deviceConfig.getDeviceNo(), commandMsgModel);
-
- String requestType = null;
- String taskId = null;
- try {
- requestType = httpCommand.getRequest().getBody().get("requestType").toString();
- taskId = httpCommand.getRequest().getBody().get("taskId").toString();
- } catch (Exception e) {
-// return null;
- //taskId鍙兘鍙栫┖锛屼笉鎶ラ敊锛屾甯告儏鍐�
- }
-
- JSONObject result = new JSONObject();
- result.put("requestType", requestType);
- result.put("taskId", taskId);
- return result;
+ return key;
}catch (Exception e) {
e.printStackTrace();
}
return null;
}
- private JSONObject queryCommandStatus(String requestType, String taskId) {
+ private JSONObject queryCommandStatus(String resultKey) {
// 鑾峰彇鏈嶅姟鍣ㄥ搷搴�
- // 灏濊瘯50娆�
JSONObject result = null;
- for (int i = 0; i < 50; i++) {
- result = getRequestBody(requestType, taskId);
+ long startTime = System.currentTimeMillis();
+ while (true) {
+ if((System.currentTimeMillis() - startTime) > 1000 * 10) {
+ break;
+ }
+
+ result = getRequestBody(resultKey);
if (result == null) {
- try {
- Thread.sleep(500);
- } catch (Exception e) {
- e.printStackTrace();
- }
+ continue;
}else {
break;
}
@@ -1210,13 +1347,6 @@
//WCS绯荤粺鍧愭爣杞墰鐪煎潗鏍�
private static int[] WCSXyzToNyXyz(int x, int y, int z) {
-// //WCS绯荤粺Y杞� => 鐗涚溂X杞磋浆鎹㈠叕寮�
-// int x1 = Math.abs(y - 61) + 11;
-// //WCS绯荤粺X杞� => 鐗涚溂Y杞磋浆鎹㈠叕寮�
-// int y1 = x + 10;
-
-// int x1 = x + 10;
-// int y1 = y + 10;
LocMastService locMastService = SpringUtils.getBean(LocMastService.class);
LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
.eq("row1", x)
@@ -1229,7 +1359,12 @@
String qrCodeValue = locMast.getQrCodeValue();
JSONObject data = JSON.parseObject(qrCodeValue);
- return new int[]{data.getInteger("y"), data.getInteger("x"), z};
+ return new int[]{data.getInteger("x"), data.getInteger("y"), z};
+ }
+
+ @Override
+ public Object getOriginDeviceData() {
+ return this.originDeviceData;
}
@Data
--
Gitblit v1.9.1