| New file |
| | |
| | | package com.zy.acs.manager.core.scheduler; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.zy.acs.common.constant.RedisConstant; |
| | | import com.zy.acs.common.utils.RedisSupport; |
| | | import com.zy.acs.framework.common.Cools; |
| | | import com.zy.acs.framework.common.SnowflakeIdWorker; |
| | | import com.zy.acs.manager.common.domain.TaskDto; |
| | | import com.zy.acs.manager.core.service.AreaGovernService; |
| | | import com.zy.acs.manager.core.service.MainService; |
| | | import com.zy.acs.manager.manager.controller.param.OpenBusSubmitParam; |
| | | import com.zy.acs.manager.manager.entity.*; |
| | | import com.zy.acs.manager.manager.enums.AgvModelType; |
| | | import com.zy.acs.manager.manager.enums.BusStsType; |
| | | import com.zy.acs.manager.manager.enums.LocStsType; |
| | | import com.zy.acs.manager.manager.enums.StatusType; |
| | | import com.zy.acs.manager.manager.service.*; |
| | | import com.zy.acs.manager.manager.service.impl.CodeServiceImpl; |
| | | import com.zy.acs.manager.system.service.ConfigService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.*; |
| | | |
| | | @Slf4j |
| | | @Component |
| | | public class ConveyorAutoRunScheduler { |
| | | |
| | | private static final AgvModelType DEFAULT_AGV_MODEL = AgvModelType.CTU_BOX_TRANSPORT_AGV; |
| | | |
| | | private final RedisSupport redis = RedisSupport.defaultRedisSupport; |
| | | |
| | | @Autowired |
| | | private AgvService agvService; |
| | | @Autowired |
| | | private BusService busService; |
| | | @Autowired |
| | | private MainService mainService; |
| | | @Autowired |
| | | private ConfigService configService; |
| | | @Autowired |
| | | private LocService locService; |
| | | @Autowired |
| | | private StaService staService; |
| | | @Autowired |
| | | private AgvModelService agvModelService; |
| | | @Autowired |
| | | private SnowflakeIdWorker snowflakeIdWorker; |
| | | @Autowired |
| | | private AreaGovernService areaGovernService; |
| | | @Autowired |
| | | private CodeServiceImpl codeService; |
| | | |
| | | // @Scheduled(fixedRate = 500) // 固定频率执行,不同步 |
| | | @Scheduled(fixedDelay = 1000) // 固定频率执行,同步 |
| | | // @Scheduled(cron = "0/1 * * * * ? ") |
| | | private void execute() { |
| | | //if (!configService.getVal("ConveyorTaskAssignMode", Boolean.class)) { return; } |
| | | AgvModel agvModel = agvModelService.getOne(new LambdaQueryWrapper<AgvModel>().eq(AgvModel::getType, DEFAULT_AGV_MODEL.toString())); |
| | | if (null == agvModel) { return; } |
| | | |
| | | //this.autoRun(agvModel); |
| | | } |
| | | |
| | | private void autoRun(AgvModel agvModel) { |
| | | int availableAgvCount = this.getAvailableAgvCount(); |
| | | if (0 == availableAgvCount) { return; } |
| | | |
| | | // List<String> staPreNos = getStaPrefixes(staGroupList); |
| | | List<String> staPreNos = new ArrayList<>(); |
| | | String memo = "DEMO_STA_" + String.join("-", staPreNos); |
| | | |
| | | |
| | | // 最多 ? 组bus运行 |
| | | if (1 <= busService.count(new LambdaQueryWrapper<Bus>() |
| | | .in(Bus::getBusSts, BusStsType.RECEIVE.val(), BusStsType.PROGRESS.val()) |
| | | .in(Bus::getMemo, memo) |
| | | )) { return; } |
| | | |
| | | |
| | | // 出库 |
| | | this.runLocToSta(agvModel, memo); |
| | | |
| | | } |
| | | |
| | | |
| | | // 出库 |
| | | private void runLocToSta(AgvModel agvModel, String memo) { |
| | | |
| | | // IDLE STA |
| | | List<Sta> idleList = new ArrayList<>(); |
| | | idleList.add(staService.selectByStaNo("1001")); |
| | | idleList.add(staService.selectByStaNo("1007")); |
| | | if (Cools.isEmpty(idleList)) { return; } |
| | | Collections.shuffle(idleList); |
| | | |
| | | OpenBusSubmitParam param = new OpenBusSubmitParam(); |
| | | param.setBatch(String.valueOf(snowflakeIdWorker.nextId()).substring(13, 19)); |
| | | for (int i = 0; i < agvModel.getBackpack() ; i++) { |
| | | Sta idleSta = idleList.get(i); |
| | | String staCode = codeService.getCacheById(idleSta.getCode()).getData(); |
| | | |
| | | Loc stockLoc = null; |
| | | |
| | | // 所在区域的条码,如果没有area绑定,就全地图 |
| | | List<String> codeList = areaGovernService.queryCodesByOneCode(staCode); |
| | | if (Cools.isEmpty(codeList)) { |
| | | stockLoc = locService.selectRandOneByLocSts(LocStsType.STOCK.val(), 1); |
| | | } else { |
| | | Collections.shuffle(codeList); |
| | | for (String codeData : codeList) { |
| | | Code code = codeService.getCacheByData(codeData); |
| | | if (null == code) { break; } |
| | | List<Loc> locList = locService.list(new LambdaQueryWrapper<Loc>() |
| | | .eq(Loc::getCode, code.getId()).eq(Loc::getLocSts, LocStsType.STOCK.val())); |
| | | if (Cools.isEmpty(locList)) { |
| | | break; |
| | | } else if (locList.size() == 1) { |
| | | stockLoc = locList.get(0); |
| | | } else { |
| | | Collections.shuffle(locList); |
| | | stockLoc = locList.get(0); |
| | | } |
| | | if (null != stockLoc) { |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (null == stockLoc) { break; } |
| | | |
| | | TaskDto taskDto = new TaskDto(); |
| | | taskDto.setOriLoc(stockLoc.getLocNo()); |
| | | taskDto.setDestSta(idleSta.getStaNo()); |
| | | taskDto.setPriority(100); |
| | | taskDto.setSeqNum(String.valueOf(snowflakeIdWorker.nextId()).substring(15, 19)); |
| | | |
| | | param.getTaskList().add(taskDto); |
| | | } |
| | | if (Cools.isEmpty(param.getTaskList())) { return; } |
| | | |
| | | mainService.generateBusAndTask(param, memo); |
| | | } |
| | | |
| | | |
| | | |
| | | public static List<String> getStaPrefixes(List<String> staGroupList) { |
| | | Set<String> rowSet = new HashSet<>(); |
| | | for (String s : staGroupList) { |
| | | rowSet.add(s.split("-")[0]); |
| | | } |
| | | List<String> result = new ArrayList<>(rowSet); |
| | | result.sort(Comparator.comparingInt(Integer::parseInt)); |
| | | return result; |
| | | } |
| | | |
| | | private int getAvailableAgvCount() { |
| | | int res = 0; |
| | | List<Agv> agvList = agvService.list(new LambdaQueryWrapper<Agv>().eq(Agv::getStatus, StatusType.ENABLE.val)); |
| | | if (Cools.isEmpty(agvList)) { |
| | | return res; |
| | | } |
| | | for (Agv agv : agvList) { |
| | | if (null == redis.getObject(RedisConstant.AGV_ONLINE_FLAG, agv.getUuid())) { |
| | | continue; |
| | | } |
| | | if (!agv.getStatusBool()) { |
| | | continue; |
| | | } |
| | | res++; |
| | | } |
| | | |
| | | return res; |
| | | } |
| | | |
| | | } |