From 119778beae8103791feefb5955f60c2b3d4d757e Mon Sep 17 00:00:00 2001 From: Junjie <540245094@qq.com> Date: 星期六, 13 九月 2025 08:52:10 +0800 Subject: [PATCH] # --- src/main/java/com/zy/core/thread/impl/TrafficControlImplThread.java | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 103 insertions(+), 9 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 1f3f4f2..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; @@ -56,6 +65,17 @@ List<TrafficControlDataModel> allTrafficControl = getAllTrafficControl(); //鏇存柊浜ょ淇℃伅 redisUtil.set(RedisKeyType.TRAFFIC_CONTROL_MAP.key, allTrafficControl); + + for (TrafficControlDataModel dataModel : allTrafficControl) { + Integer shuttleNo = dataModel.getShuttleNo(); + Integer taskNo = dataModel.getTaskNo(); + + Object object1 = redisUtil.get(RedisKeyType.TRAFFIC_CONTROL_SUCCESS_APPLY.key + shuttleNo + "_" + taskNo); + if(object1 == null) { + redisUtil.set(RedisKeyType.TRAFFIC_CONTROL_SUCCESS_APPLY.key + shuttleNo + "_" + taskNo, 1, 60 * 60); + } + } + Thread.sleep(200); }catch (Exception e){ e.printStackTrace(); @@ -67,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; } @@ -163,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 @@ -187,6 +275,10 @@ } if(totalLocList.contains(locNo)) { + String first = totalLocList.get(0); + if(first.equals(locNo)) {//filter first node + continue; + } return false; } } @@ -199,7 +291,8 @@ operateTrafficControl(param); applyRecordsMap.remove(shuttleNo); - News.info("receipt traffic {},{}", shuttleNo, taskNo); + redisUtil.set(RedisKeyType.TRAFFIC_CONTROL_SUCCESS_APPLY.key + shuttleNo + "_" + taskNo, 1, 60 * 60); + News.info("[RCS Debug] receipt traffic {},{}", shuttleNo, taskNo); return true; } @@ -259,7 +352,7 @@ } @Override - public synchronized boolean cancelTrafficControl(Integer shuttleNo, Integer taskNo) { + public boolean cancelTrafficControl(Integer shuttleNo, Integer taskNo) { TrafficControlDataModel dataModel = queryTrafficControl(shuttleNo, taskNo); if (dataModel == null) { return false; @@ -273,7 +366,7 @@ } @Override - public synchronized boolean forceCancelTrafficControl(Integer shuttleNo) { + public boolean forceCancelTrafficControl(Integer shuttleNo) { TrafficControlDataModel dataModel = queryTrafficControl(shuttleNo); if (dataModel == null) { return false; @@ -323,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")) { @@ -342,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; } @@ -381,6 +474,7 @@ } trafficControlDataList.remove(idx);//鍙栨秷绠″埗 + redisUtil.del(RedisKeyType.TRAFFIC_CONTROL_SUCCESS_APPLY.key + shuttleNo + "_" + taskNo); return true; } -- Gitblit v1.9.1