| | |
| | | import com.zy.acs.common.utils.RedisSupport; |
| | | import com.zy.acs.framework.common.Cools; |
| | | import com.zy.acs.framework.common.R; |
| | | import com.zy.acs.manager.common.constant.AgvAreaDispatcher; |
| | | import com.zy.acs.manager.core.cache.CoreCache; |
| | | import com.zy.acs.manager.core.domain.CodeStepDto; |
| | | import com.zy.acs.manager.core.domain.type.JobType; |
| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.zy.acs.common.utils.News; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import javax.annotation.PreDestroy; |
| | |
| | | |
| | | private ScheduledExecutorService scheduler = null; |
| | | |
| | | private List<String> CODE_DATA_CACHE = new ArrayList<>(); |
| | | private List<String> ALL_CODE_DATA_CACHE = new ArrayList<>(); |
| | | |
| | | private List<String> LOC_CODE_DATA_CACHE = new ArrayList<>(); |
| | | |
| | |
| | | private ConfigService configService; |
| | | @Autowired |
| | | private AgvModelService agvModelService; |
| | | @Autowired |
| | | private AgvAreaDispatcher agvAreaDispatcher; |
| | | |
| | | @PostConstruct |
| | | public void init() { |
| | | int count = agvService.count(new LambdaQueryWrapper<Agv>().eq(Agv::getStatus, StatusType.ENABLE.val)); |
| | | if (count > 0) { |
| | | this.scheduler = Executors.newScheduledThreadPool(count); |
| | | } |
| | | // init all code data |
| | | List<Code> codeList = codeService.list(new LambdaQueryWrapper<Code>().eq(Code::getStatus, StatusType.ENABLE.val)); |
| | | this.ALL_CODE_DATA_CACHE = codeList.stream().map(Code::getData).distinct().collect(Collectors.toList()); |
| | | |
| | | // int all loc code data |
| | | List<Code> locCodeList = codeService.getAllLocCode(); |
| | | this.LOC_CODE_DATA_CACHE = locCodeList.stream().map(Code::getData).distinct().collect(Collectors.toList()); |
| | | |
| | | } |
| | | |
| | | // pick & drop logic -------------------------------------------------- |
| | | |
| | |
| | | } |
| | | break; |
| | | default: |
| | | log.warn("AGV {}: 未知阶段: {}", agvNo, jobType); |
| | | News.warn("AGV {}: 未知阶段: {}", agvNo, jobType); |
| | | break; |
| | | } |
| | | if (Cools.isEmpty(destinationCodeData)) { |
| | |
| | | } |
| | | |
| | | if (mainLockWrapService.buildMinorTask(agvId, TaskTypeType.MOVE, destinationCodeData, null)) { |
| | | log.info( "{}开始作业演示...", agvNo); |
| | | News.info( "{}开始作业演示...", agvNo); |
| | | |
| | | CoreCache.AGV_MOCK_STEP_CACHE.put(agvId, CodeStepDto.build(destinationCodeData, jobType)); |
| | | } |
| | |
| | | } |
| | | |
| | | private void patrolOfMove(String agvNo) { |
| | | if (!configService.getVal("TaskAssignMode", Boolean.class)) { return; } |
| | | Long agvId = agvService.getAgvId(agvNo); |
| | | if (0 < travelService.count(new LambdaQueryWrapper<Travel>() |
| | | .eq(Travel::getAgvId, agvId) |
| | |
| | | return; |
| | | } |
| | | if (mainLockWrapService.buildMinorTask(agvId, TaskTypeType.MOVE, destinationCodeData, null)) { |
| | | log.info( "{}开始走行演示...", agvNo); |
| | | News.info( "AGV[{}] 开启自动巡逻...", agvNo); |
| | | } |
| | | } |
| | | |
| | |
| | | * agv地图图标变化 |
| | | */ |
| | | public String getDestinationCode(String agvNo, AgvDetail agvDetail) { |
| | | |
| | | Code startCode = codeService.getCacheById(agvDetail.getRecentCode()); |
| | | Set<String> notInCodeSet = new HashSet<>(); |
| | | Long agvId = agvDetail.getAgvId(); |
| | | |
| | | List<String> codeList = AgvAreaDispatcher.AGV_AREA.get(agvNo); |
| | | List<String> disableCodeList = AgvAreaDispatcher.AGV_DISABLE_AREA.get(agvNo); |
| | | List<String> codeList = null; |
| | | if (agvAreaDispatcher.isAgvExistsInAnyArea(agvId)) { |
| | | codeList = agvAreaDispatcher.getCodesByAgvId(agvId); |
| | | } else { |
| | | codeList = ALL_CODE_DATA_CACHE; |
| | | } |
| | | Collections.shuffle(codeList); |
| | | |
| | | for (String endCodeData : codeList) { |
| | | if (disableCodeList.contains(endCodeData)) { continue; } |
| | | if (notInCodeSet.contains(endCodeData)) { continue; } |
| | | Code endCode = codeService.getCacheByData(endCodeData); |
| | | |
| | | // valid lane |
| | |
| | | executePatrolLogic(agvNo); |
| | | // executeUShapeConveyor(agvNo); |
| | | } catch (Exception e) { |
| | | log.error("执行AGV{}跑库任务时发生异常: {}", agvNo, e.getMessage()); |
| | | News.error("执行AGV{}跑库任务时发生异常", agvNo, e); |
| | | } |
| | | }; |
| | | |
| | | ScheduledFuture<?> scheduledFuture = scheduler.scheduleAtFixedRate(patrolTask, 0, SCHEDULE_TIME_INTERVAL, TimeUnit.MILLISECONDS); |
| | | |
| | | AGV_PATROL_MAP.put(agvNo, scheduledFuture); |
| | | log.info("已启动AGV{}的跑库任务。", agvNo); |
| | | News.info("已启动AGV{}的跑库任务。", agvNo); |
| | | return R.ok(); |
| | | } |
| | | |
| | |
| | | CoreCache.AGV_BACKPACK_USED_CACHE.remove(agvId); |
| | | CoreCache.AGV_MOCK_STEP_CACHE.remove(agvId); |
| | | CoreCache.AGV_MOCK_JOB_CACHE.remove(agvNo); |
| | | log.info("已停止AGV {} 的跑库任务。", agvNo); |
| | | News.info("已停止AGV {} 的跑库任务。", agvNo); |
| | | return R.ok("已停止AGV " + agvNo + " 的跑库任务。"); |
| | | } else { |
| | | log.error("未能成功停止AGV " + agvNo + " 的跑库任务。"); |
| | | News.error("未能成功停止AGV " + agvNo + " 的跑库任务。"); |
| | | return R.error("未能成功停止AGV " + agvNo + " 的跑库任务。"); |
| | | } |
| | | } |
| | | |
| | | @PostConstruct |
| | | public void init() { |
| | | int count = agvService.count(new LambdaQueryWrapper<Agv>().eq(Agv::getStatus, StatusType.ENABLE.val)); |
| | | if (count > 0) { |
| | | this.scheduler = Executors.newScheduledThreadPool(count); |
| | | } |
| | | // init all code data |
| | | List<Code> codeList = codeService.list(new LambdaQueryWrapper<Code>().eq(Code::getStatus, StatusType.ENABLE.val)); |
| | | this.CODE_DATA_CACHE = codeList.stream().map(Code::getData).distinct().collect(Collectors.toList()); |
| | | |
| | | // int all loc code data |
| | | List<Code> locCodeList = codeService.getAllLocCode(); |
| | | this.LOC_CODE_DATA_CACHE = locCodeList.stream().map(Code::getData).distinct().collect(Collectors.toList()); |
| | | |
| | | } |
| | | |
| | | @PreDestroy |
| | |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |