From 633d680fdaba504255a12f190a8284c0a9e12de6 Mon Sep 17 00:00:00 2001
From: cpT <1@123>
Date: 星期五, 30 一月 2026 16:42:24 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/impl/ZySiemensDualCrnThread.java | 231 ++++++++++++++++++++++++++++++---------------------------
1 files changed, 121 insertions(+), 110 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/impl/ZySiemensDualCrnThread.java b/src/main/java/com/zy/core/thread/impl/ZySiemensDualCrnThread.java
index 5f6a962..c33d25b 100644
--- a/src/main/java/com/zy/core/thread/impl/ZySiemensDualCrnThread.java
+++ b/src/main/java/com/zy/core/thread/impl/ZySiemensDualCrnThread.java
@@ -20,6 +20,7 @@
import com.zy.core.model.StationObjModel;
import com.zy.core.model.Task;
import com.zy.core.model.command.DualCrnCommand;
+import com.zy.core.model.param.SendDualCrnCommandParam;
import com.zy.core.model.protocol.DualCrnProtocol;
import com.zy.core.model.protocol.StationProtocol;
import com.zy.core.network.DeviceConnectPool;
@@ -31,10 +32,8 @@
import lombok.extern.slf4j.Slf4j;
import java.text.MessageFormat;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+
import com.zy.asrs.entity.BasDualCrnpErrLog;
import com.zy.asrs.service.BasDualCrnpErrLogService;
@@ -67,7 +66,7 @@
try {
deviceLogCollectTime = Utils.getDeviceLogCollectTime();
readStatus();
- Thread.sleep(100);
+ Thread.sleep(50);
} catch (Exception e) {
log.error("DualCrnThread Fail", e);
}
@@ -85,14 +84,13 @@
}
if (step == 2) {
- List<DualCrnCommand> commandList = (List<DualCrnCommand>) task.getData();
- DualCrnCommand command = commandList.get(0);
+ List<SendDualCrnCommandParam> commandList = (List<SendDualCrnCommandParam>) task.getData();
+ for (SendDualCrnCommandParam sendDualCrnCommandParam : commandList) {
+ DualCrnCommand dualCrnCommand = sendDualCrnCommandParam.getCommands().get(0);
+ redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_IDX.key + dualCrnCommand.getTaskNo(), sendDualCrnCommandParam.getCommandIdx(), 60 * 60 * 24);
+ }
- HashMap<String, Object> map = new HashMap<>();
- map.put("commands", commandList);
- map.put("idx", 1);
- redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_.key + command.getTaskNo(), JSON.toJSONString(map, SerializerFeature.DisableCircularReferenceDetect), 60 * 60 * 24);
- sendCommand(command);
+ redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_.key + crnProtocol.getCrnNo(), JSON.toJSONString(commandList, SerializerFeature.DisableCircularReferenceDetect), 60 * 60 * 24);
} else if (step == 3) {
sendCommand((DualCrnCommand) task.getData());
}
@@ -116,99 +114,19 @@
continue;
}
- if (crnProtocol.getLoaded() == 1 && crnProtocol.getLoadedTwo() == 1) {
- Object wait = redisUtil.get(RedisKeyType.DUAL_CRN_PICK_WAIT_NEXT_TASK.key + crnProtocol.getCrnNo());
- if (wait != null) {
- redisUtil.del(RedisKeyType.DUAL_CRN_PICK_WAIT_NEXT_TASK.key + crnProtocol.getCrnNo());
- }
+ if (!((crnProtocol.getStatusType().equals(DualCrnStatusType.IDLE) || crnProtocol.getStatusType().equals(DualCrnStatusType.FETCH_COMPLETE))
+ && (crnProtocol.getStatusTypeTwo().equals(DualCrnStatusType.IDLE) || crnProtocol.getStatusTypeTwo().equals(DualCrnStatusType.FETCH_COMPLETE)))
+ ) {
+ continue;
}
- if(crnProtocol.getTaskNo() > 0 && crnProtocol.getStatus() == DualCrnStatusType.IDLE.id) {
- Integer taskNo = crnProtocol.getTaskNo();
- Object commandObj = redisUtil.get(RedisKeyType.DUAL_CRN_COMMAND_.key + taskNo);
- if (commandObj == null) {
- News.error("鍙屽伐浣嶅爢鍨涙満锛屽伐浣�1绌洪棽绛夊緟涓嬪彂鍛戒护锛屼絾鏈壘鍒板懡浠ゃ�傚爢鍨涙満鍙�={}锛屽伐浣滃彿={}", crnProtocol.getCrnNo(), taskNo);
- continue;
- }
-
- JSONObject commandMap = JSON.parseObject(commandObj.toString());
- Integer idx = commandMap.getInteger("idx");
- List<DualCrnCommand> commandList = commandMap.getJSONArray("commands").toJavaList(DualCrnCommand.class);
- if (idx >= commandList.size()) {
- continue;
- }
- DualCrnCommand dualCommand = commandList.get(idx);
-
- if (dualCommand.getTaskMode() == DualCrnTaskModeType.PUT.id.shortValue()) {
- //绛夊緟涓嬩竴涓换鍔�
- Object wait = redisUtil.get(RedisKeyType.DUAL_CRN_PICK_WAIT_NEXT_TASK.key + crnProtocol.getCrnNo());
- if (wait != null) {
- continue;
- }
-
- Object outTaskStationInfoObj = redisUtil.get(RedisKeyType.DUAL_CRN_OUT_TASK_STATION_INFO.key + taskNo);
- if (outTaskStationInfoObj != null) {
- //妫�娴嬪嚭鍙g珯鏄惁鍙墽琛屾斁璐у姩浣�
- StationObjModel stationObjModel = JSON.parseObject(outTaskStationInfoObj.toString(), StationObjModel.class);
- StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo());
- if (stationThread == null) {
- continue;
- }
-
- Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap();
- StationProtocol stationProtocol = statusMap.get(stationObjModel.getStationId());
- if (stationProtocol == null) {
- continue;
- }
-
- if (!stationProtocol.isAutoing()) {
- continue;
- }
-
- if (stationProtocol.isLoading()) {
- continue;
- }
-
- if (stationProtocol.getTaskNo() > 0) {
- continue;
- }
- }
- }
-
- idx++;
- commandMap.put("idx", idx);
- sendCommand(dualCommand);
- redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_.key + taskNo, commandMap.toJSONString(), 60 * 60 * 24);
+ Object commandListObj = redisUtil.get(RedisKeyType.DUAL_CRN_COMMAND_.key + crnProtocol.getCrnNo());
+ if (commandListObj == null) {
+ continue;
}
-
- if(crnProtocol.getTaskNoTwo() > 0 && crnProtocol.getStatusTwo() == DualCrnStatusType.IDLE.id) {
- Integer taskNo = crnProtocol.getTaskNoTwo();
- Object commandObj = redisUtil.get(RedisKeyType.DUAL_CRN_COMMAND_.key + taskNo);
- if (commandObj == null) {
- News.error("鍙屽伐浣嶅爢鍨涙満锛屽伐浣�2绌洪棽绛夊緟涓嬪彂鍛戒护锛屼絾鏈壘鍒板懡浠ゃ�傚爢鍨涙満鍙�={}锛屽伐浣滃彿={}", crnProtocol.getCrnNo(), taskNo);
- continue;
- }
-
- JSONObject commandMap = JSON.parseObject(commandObj.toString());
- Integer idx = commandMap.getInteger("idx");
- List<DualCrnCommand> commandList = commandMap.getJSONArray("commands").toJavaList(DualCrnCommand.class);
- if (idx >= commandList.size()) {
- continue;
- }
- DualCrnCommand dualCommand = commandList.get(idx);
-
- if (dualCommand.getTaskMode() == DualCrnTaskModeType.PUT.id.shortValue()) {
- //绛夊緟涓嬩竴涓换鍔�
- Object wait = redisUtil.get(RedisKeyType.DUAL_CRN_PICK_WAIT_NEXT_TASK.key + crnProtocol.getCrnNo());
- if (wait != null) {
- continue;
- }
- }
-
- idx++;
- commandMap.put("idx", idx);
- sendCommand(dualCommand);
- redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_.key + taskNo, commandMap.toJSONString(), 60 * 60 * 24);
+ List<SendDualCrnCommandParam> commandList = JSON.parseArray(commandListObj.toString(), SendDualCrnCommandParam.class);
+ for (SendDualCrnCommandParam commandParam : commandList) {
+ processStation(commandParam);
}
Thread.sleep(100);
@@ -218,6 +136,90 @@
}
});
commandThread.start();
+ }
+
+ private void processStation(SendDualCrnCommandParam commandParam) {
+ Integer station = commandParam.getStation();
+ List<DualCrnCommand> commandList = commandParam.getCommands();
+ DualCrnCommand firstCommand = commandList.get(0);
+ Object idxObj = redisUtil.get(RedisKeyType.DUAL_CRN_COMMAND_IDX.key + firstCommand.getTaskNo());
+ if(idxObj == null) {
+ return;
+ }
+ Integer idx = (Integer) idxObj;
+ if (idx >= commandList.size()) {
+ return;
+ }
+ DualCrnCommand dualCommand = commandList.get(idx);
+
+ boolean send = false;
+ if (station == 1) {
+ if (crnProtocol.getStatus().equals(DualCrnStatusType.FETCH_COMPLETE.id)
+ || crnProtocol.getStatus().equals(DualCrnStatusType.IDLE.id)
+ ) {
+ send = true;
+ }
+ }else {
+ if (crnProtocol.getStatusTwo().equals(DualCrnStatusType.FETCH_COMPLETE.id)
+ || crnProtocol.getStatusTwo().equals(DualCrnStatusType.IDLE.id)
+ ) {
+ send = true;
+ }
+ }
+
+ if (idx == 0) {
+ if(send) {
+ idx++;
+ redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_IDX.key + firstCommand.getTaskNo(), idx, 60 * 60 * 24);
+ sendCommand(dualCommand);
+ redisUtil.set(RedisKeyType.DUAL_CRN_PICK_WAIT_NEXT_TASK.key + crnProtocol.getCrnNo(), "lock", 5);
+ }
+ return;
+ }else {
+ if (dualCommand.getTaskMode() == DualCrnTaskModeType.PUT.id.shortValue()) {
+ //绛夊緟涓嬩竴涓换鍔�
+ Object wait = redisUtil.get(RedisKeyType.DUAL_CRN_PICK_WAIT_NEXT_TASK.key + crnProtocol.getCrnNo());
+ if (wait != null) {
+ return;
+ }
+
+ Integer taskNo = dualCommand.getTaskNo();
+ Object outTaskStationInfoObj = redisUtil.get(RedisKeyType.DUAL_CRN_OUT_TASK_STATION_INFO.key + taskNo);
+ if (outTaskStationInfoObj != null) {
+ //妫�娴嬪嚭鍙g珯鏄惁鍙墽琛屾斁璐у姩浣�
+ StationObjModel stationObjModel = JSON.parseObject(outTaskStationInfoObj.toString(), StationObjModel.class);
+ StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo());
+ if (stationThread == null) {
+ return;
+ }
+
+ Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap();
+ StationProtocol stationProtocol = statusMap.get(stationObjModel.getStationId());
+ if (stationProtocol == null) {
+ return;
+ }
+
+ if (!stationProtocol.isAutoing()) {
+ return;
+ }
+
+ if (stationProtocol.isLoading()) {
+ return;
+ }
+
+ if (stationProtocol.getTaskNo() > 0) {
+ return;
+ }
+ }
+ }
+
+ if(send) {
+ idx++;
+ redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_IDX.key + firstCommand.getTaskNo(), idx, 60 * 60 * 24);
+ sendCommand(dualCommand);
+ }
+ return;
+ }
}
/**
@@ -251,13 +253,13 @@
crnProtocol.setLiftPosTwo(0);
crnProtocol.setAlarm(0);
- crnProtocol.setXSpeed(0);
- crnProtocol.setYSpeed(0);
- crnProtocol.setZSpeed(0);
- crnProtocol.setXDistance(0);
- crnProtocol.setYDistance(0);
- crnProtocol.setXDuration(0);
- crnProtocol.setYDuration(0);
+ crnProtocol.setXSpeed(0D);
+ crnProtocol.setYSpeed(0D);
+ crnProtocol.setZSpeed(0D);
+ crnProtocol.setXDistance(0D);
+ crnProtocol.setYDistance(0D);
+ crnProtocol.setXDuration(0D);
+ crnProtocol.setYDuration(0D);
BasDualCrnpService basDualCrnpService = null;
try {
@@ -430,6 +432,9 @@
crnCommand.setCrnNo(crnNo); // 鍫嗗灈鏈虹紪鍙�
crnCommand.setTaskNo(taskNo); // 宸ヤ綔鍙�
crnCommand.setTaskMode(DualCrnTaskModeType.PICK.id); // 浠诲姟妯″紡: 鍙栬揣
+ crnCommand.setSourcePosX(Utils.getRow(targetLocNo)); // 鐩爣搴撲綅鎺�
+ crnCommand.setSourcePosY(Utils.getBay(targetLocNo)); // 鐩爣搴撲綅鍒�
+ crnCommand.setSourcePosZ(Utils.getLev(targetLocNo)); // 鐩爣搴撲綅灞�
crnCommand.setDestinationPosX(Utils.getRow(targetLocNo)); // 鐩爣搴撲綅鎺�
crnCommand.setDestinationPosY(Utils.getBay(targetLocNo)); // 鐩爣搴撲綅鍒�
crnCommand.setDestinationPosZ(Utils.getLev(targetLocNo)); // 鐩爣搴撲綅灞�
@@ -444,6 +449,9 @@
crnCommand.setCrnNo(crnNo); // 鍫嗗灈鏈虹紪鍙�
crnCommand.setTaskNo(taskNo); // 宸ヤ綔鍙�
crnCommand.setTaskMode(DualCrnTaskModeType.PUT.id); // 浠诲姟妯″紡: 鏀捐揣
+ crnCommand.setSourcePosX(Utils.getRow(targetLocNo)); // 鐩爣搴撲綅鎺�
+ crnCommand.setSourcePosY(Utils.getBay(targetLocNo)); // 鐩爣搴撲綅鍒�
+ crnCommand.setSourcePosZ(Utils.getLev(targetLocNo)); // 鐩爣搴撲綅灞�
crnCommand.setDestinationPosX(Utils.getRow(targetLocNo)); // 鐩爣搴撲綅鎺�
crnCommand.setDestinationPosY(Utils.getBay(targetLocNo)); // 鐩爣搴撲綅鍒�
crnCommand.setDestinationPosZ(Utils.getLev(targetLocNo)); // 鐩爣搴撲綅灞�
@@ -458,6 +466,9 @@
crnCommand.setCrnNo(crnNo); // 鍫嗗灈鏈虹紪鍙�
crnCommand.setTaskNo(taskNo); // 宸ヤ綔鍙�
crnCommand.setTaskMode(DualCrnTaskModeType.MOVE.id); // 浠诲姟妯″紡: 鍫嗗灈鏈虹Щ鍔�
+ crnCommand.setSourcePosX(Utils.getRow(targetLocNo)); // 鐩爣搴撲綅鎺�
+ crnCommand.setSourcePosY(Utils.getBay(targetLocNo)); // 鐩爣搴撲綅鍒�
+ crnCommand.setSourcePosZ(Utils.getLev(targetLocNo)); // 鐩爣搴撲綅灞�
crnCommand.setDestinationPosX(Utils.getRow(targetLocNo)); // 鐩爣搴撲綅鎺�
crnCommand.setDestinationPosY(Utils.getBay(targetLocNo)); // 鐩爣搴撲綅鍒�
crnCommand.setDestinationPosZ(Utils.getLev(targetLocNo)); // 鐩爣搴撲綅灞�
@@ -483,7 +494,7 @@
}
@Override
- public synchronized CommandResponse sendCommand(DualCrnCommand command) {
+ public CommandResponse sendCommand(DualCrnCommand command) {
this.crnProtocol.setLastCommandTime(System.currentTimeMillis());
CommandResponse response = null;
try {
--
Gitblit v1.9.1