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 | 77 +++++++++++++++++++++++++++++++++++++- 1 files changed, 75 insertions(+), 2 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 f1655fa..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; } @@ -186,6 +199,66 @@ }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 } -- Gitblit v1.9.1