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/TrafficControlImplThread.java | 93 +++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 87 insertions(+), 6 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/impl/TrafficControlImplThread.java b/src/main/java/com/zy/core/thread/impl/TrafficControlImplThread.java
index 721e5ee..bcd0c2d 100644
--- a/src/main/java/com/zy/core/thread/impl/TrafficControlImplThread.java
+++ b/src/main/java/com/zy/core/thread/impl/TrafficControlImplThread.java
@@ -1,21 +1,30 @@
package com.zy.core.thread.impl;
import com.core.common.SpringUtils;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.zy.asrs.entity.WrkMast;
+import com.zy.asrs.service.WrkMastService;
import com.zy.asrs.utils.Utils;
import com.zy.common.model.NavigateNode;
+import com.zy.common.model.enums.NavigationMapType;
+import com.zy.common.utils.NavigateUtils;
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.RedisKeyType;
+import com.zy.core.enums.ShuttleProtocolStatusType;
import com.zy.core.enums.SlaveType;
+import com.zy.core.enums.WrkStsType;
import com.zy.core.model.TrafficControlDataModel;
+import com.zy.core.model.command.ShuttleRedisCommand;
import com.zy.core.model.param.OperateTrafficControlParam;
import com.zy.core.model.protocol.ShuttleProtocol;
import com.zy.core.thread.ShuttleThread;
import com.zy.core.thread.TrafficControlThread;
-import org.springframework.scheduling.annotation.Async;
+import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
@@ -78,7 +87,11 @@
@Override
public synchronized boolean processApply(TrafficControlDataModel applyData) {
ShuttleOperaUtils shuttleOperaUtils = SpringUtils.getBean(ShuttleOperaUtils.class);
- if (shuttleOperaUtils == null) {
+ WrkMastService wrkMastService = SpringUtils.getBean(WrkMastService.class);
+ ObjectMapper objectMapper = SpringUtils.getBean(ObjectMapper.class);
+ NavigateUtils navigateUtils = SpringUtils.getBean(NavigateUtils.class);
+ ShuttleDispatchUtils shuttleDispatchUtils = SpringUtils.getBean(ShuttleDispatchUtils.class);
+ if (shuttleOperaUtils == null || wrkMastService == null || objectMapper == null || navigateUtils == null || shuttleDispatchUtils == null) {
return false;
}
@@ -174,13 +187,77 @@
Long idleTime = pathIdleShuttleMap.get(shuttleProtocol.getShuttleNo());
if((System.currentTimeMillis() - idleTime) > 1000 * 10) {
//妫�娴嬮殰纰嶇墿杞�
- boolean checkObstacle = shuttleOperaUtils.checkObstacle(shuttleProtocol.getCurrentLocNo(), new ArrayList<Integer>() {{
+ int checkObstacle = shuttleOperaUtils.checkObstacle(shuttleProtocol.getCurrentLocNo(), new ArrayList<Integer>() {{
add(shuttleNo);
}}, totalNodeList);
pathIdleShuttleMap.remove(shuttleProtocol.getShuttleNo());
+
+ if (checkObstacle == 2) {
+ pathShuttleThread.restartCalcPath();
+ }
}
}else {
pathIdleShuttleMap.put(shuttleProtocol.getShuttleNo(), System.currentTimeMillis());
+ }
+ }else {
+ Object cancelTaskLock = redisUtil.get(RedisKeyType.TRAFFIC_CONTROL_SHUTTLE_OBSTACLE_CANCEL_TASK_LOCK.key + shuttleProtocol.getShuttleNo());
+ if(cancelTaskLock != null) {
+ return false;
+ }
+
+ Object obj = redisUtil.get(RedisKeyType.SHUTTLE_WORK_FLAG.key + shuttleProtocol.getTaskNo());
+ 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;
+ }
+
+ if (redisCommand.getCommandStep() != 0) {
+ return false;
+ }
+
+ long recordTime = System.currentTimeMillis();
+ if (pathShuttleThread.isDeviceIdle()) {
+ Object object = redisUtil.get(RedisKeyType.TRAFFIC_CONTROL_SHUTTLE_OBSTACLE_CANCEL_TASK.key + shuttleProtocol.getShuttleNo());
+ if(object == null) {
+ redisUtil.set(RedisKeyType.TRAFFIC_CONTROL_SHUTTLE_OBSTACLE_CANCEL_TASK.key + shuttleProtocol.getShuttleNo(), recordTime, 60 * 3);
+ }else {
+ recordTime = (long) object;
+ }
+ }else {
+ redisUtil.del(RedisKeyType.TRAFFIC_CONTROL_SHUTTLE_OBSTACLE_CANCEL_TASK.key + shuttleProtocol.getShuttleNo());
+ return false;
+ }
+
+ if(System.currentTimeMillis() - recordTime > 1000 * 15) {
+ WrkMast wrkMast = wrkMastService.selectShuttleHasMoveWorking(shuttleProtocol.getShuttleNo());
+ if(wrkMast != null) {
+ if (wrkMast.getWrkSts() == WrkStsType.MOVE_SHUTTLE.sts) {
+ if (shuttleProtocol.getTaskNo().equals(wrkMast.getWrkNo())) {
+ //璁$畻杩戠偣浣嶇疆
+ String endLocation = navigateUtils.calcEndLocation(shuttleProtocol.getCurrentLocNo(), wrkMast.getLocNo(), NavigationMapType.getMapTypes(NavigationMapType.NORMAL), null, null, 2);
+ if (endLocation == null) {
+ News.taskInfo(wrkMast.getWrkNo(), "{}浠诲姟锛岄殰纰嶇墿灏忚溅閬块殰杩戠偣浣嶇疆璁$畻澶辫触", wrkMast.getWrkNo());
+ return false;
+ }
+
+ pathShuttleThread.setSyncTaskNo(0);
+ pathShuttleThread.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
+ wrkMastService.deleteById(wrkMast);
+ shuttleDispatchUtils.dispatchShuttle(null, endLocation, shuttleProtocol.getShuttleNo());//璋冨害灏忚溅鍒拌揣鐗╄繎鐐�
+ redisUtil.set(RedisKeyType.TRAFFIC_CONTROL_SHUTTLE_OBSTACLE_CANCEL_TASK_LOCK.key + shuttleProtocol.getShuttleNo(), "cancelLock", 60);
+ }
+ }
+ }
}
}
return false;//node has shuttle
@@ -198,6 +275,10 @@
}
if(totalLocList.contains(locNo)) {
+ String first = totalLocList.get(0);
+ if(first.equals(locNo)) {//filter first node
+ continue;
+ }
return false;
}
}
@@ -211,7 +292,7 @@
applyRecordsMap.remove(shuttleNo);
redisUtil.set(RedisKeyType.TRAFFIC_CONTROL_SUCCESS_APPLY.key + shuttleNo + "_" + taskNo, 1, 60 * 60);
- News.info("receipt traffic {},{}", shuttleNo, taskNo);
+ News.info("[RCS Debug] receipt traffic {},{}", shuttleNo, taskNo);
return true;
}
@@ -335,7 +416,7 @@
public synchronized boolean operateTrafficControl(OperateTrafficControlParam param) {
long startTime = System.currentTimeMillis();
String operaType = param.getOperaType();
- News.info("Operate Traffic Control is Start " + operaType);
+ News.info("[RCS Debug] Operate Traffic Control is Start " + operaType);
boolean result = false;
if (operaType.equals("add")) {
@@ -354,7 +435,7 @@
new ArrayList<>(model.getTotalNodeList())
))
.collect(Collectors.toList());
- News.info("Operate Traffic Control is end " + (System.currentTimeMillis() - startTime) + "ms");
+ News.info("[RCS Debug] Operate Traffic Control is end " + (System.currentTimeMillis() - startTime) + "ms");
return result;
}
--
Gitblit v1.9.1