| | |
| | | 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; |
| | | |
| | |
| | | @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; |
| | | } |
| | | |
| | |
| | | }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 |
| | | } |