| | |
| | | @Component |
| | | public class AutoRunScheduler { |
| | | |
| | | private static final AgvModelType DEFAULT_AGV_MODEL = AgvModelType.CTU_BOX_TRANSPORT_AGV; |
| | | |
| | | private final RedisSupport redis = RedisSupport.defaultRedisSupport; |
| | | |
| | | @Autowired |
| | |
| | | @Autowired |
| | | private BusService busService; |
| | | @Autowired |
| | | private TaskService taskService; |
| | | @Autowired |
| | | private MainService mainService; |
| | | @Autowired |
| | | private MainLockWrapService mainLockWrapService; |
| | | @Autowired |
| | | private ActionService actionService; |
| | | @Autowired |
| | | private SegmentService segmentService; |
| | | @Autowired |
| | | private TrafficService trafficService; |
| | | @Autowired |
| | | private ConfigService configService; |
| | | @Autowired |
| | |
| | | @Autowired |
| | | private SnowflakeIdWorker snowflakeIdWorker; |
| | | @Autowired |
| | | private AgvAreaDispatcher agvAreaDispatcher; |
| | | @Autowired |
| | | private AreaGovernService areaGovernService; |
| | | @Autowired |
| | | private CodeServiceImpl codeService; |
| | |
| | | // @Scheduled(cron = "0/1 * * * * ? ") |
| | | private void execute() { |
| | | if (!configService.getVal("TaskAssignMode", Boolean.class)) { return; } |
| | | this.autoRun(); |
| | | AgvModel agvModel = agvModelService.getOne(new LambdaQueryWrapper<AgvModel>().eq(AgvModel::getType, DEFAULT_AGV_MODEL.toString())); |
| | | if (null == agvModel) { return; } |
| | | |
| | | this.autoRun(agvModel); |
| | | } |
| | | |
| | | private void autoRun() { |
| | | private void autoRun(AgvModel agvModel) { |
| | | int availableAgvCount = this.getAvailableAgvCount(); |
| | | if (0 == availableAgvCount) { return; } |
| | | |
| | |
| | | String memo = "DEMO_STA_" + String.join("-", staPreNos); |
| | | |
| | | // 入库 |
| | | this.runStaToLoc0(memo); |
| | | this.runStaToLoc(agvModel, memo); |
| | | // 出库 |
| | | this.runLocToSta0(memo); |
| | | |
| | | this.runLocToSta(agvModel, memo); |
| | | // 移库 |
| | | this.runLocToLoc(memo); |
| | | this.runLocToLoc(agvModel, memo); |
| | | } |
| | | |
| | | // 入库 |
| | | private void runStaToLoc(String memo) { |
| | | // Integer startRow = Collections.min(locGroupList); |
| | | // Integer endRow = Collections.max(locGroupList); |
| | | Integer startRow = null; |
| | | Integer endRow = null; |
| | | private void runStaToLoc(AgvModel agvModel, String memo) { |
| | | |
| | | AgvModel agvModel = agvModelService.getOne(new LambdaQueryWrapper<AgvModel>().eq(AgvModel::getType, AgvModelType.CTU_BOX_TRANSPORT_AGV.toString())); |
| | | if (null == agvModel) { |
| | | return; |
| | | } |
| | | |
| | | // STOCK STA |
| | | LambdaQueryWrapper<Sta> stockWrapper = new LambdaQueryWrapper<Sta>() |
| | | .eq(Sta::getStaSts, StaStsType.STOCK.val()) |
| | | .eq(Sta::getStatus, StatusType.ENABLE.val) |
| | | // .in(Sta::getStaNo, staGroupList) |
| | | ; |
| | | List<Sta> stockList = staService.list(stockWrapper); |
| | | if (Cools.isEmpty(stockList)) { return; } |
| | | Collections.shuffle(stockList); |
| | | |
| | | // IDLE |
| | | LambdaQueryWrapper<Loc> idleWrapper = new LambdaQueryWrapper<Loc>().eq(Loc::getLocSts, LocStsType.IDLE.val()); |
| | | if (null != startRow) { idleWrapper.ge(Loc::getRow, startRow); } |
| | | if (null != endRow) { idleWrapper.le(Loc::getRow, endRow); } |
| | | List<Loc> idleList = locService.list(idleWrapper); |
| | | 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 < Math.min(agvModel.getBackpack(), Math.min(stockList.size(), idleList.size())) ; i++) { |
| | | Sta stockSta = stockList.get(i); |
| | | Loc idleLoc = idleList.get(i); |
| | | |
| | | TaskDto taskDto = new TaskDto(); |
| | | taskDto.setOriSta(stockSta.getStaNo()); |
| | | taskDto.setDestLoc(idleLoc.getLocNo()); |
| | | taskDto.setPriority(100); |
| | | taskDto.setSeqNum(String.valueOf(snowflakeIdWorker.nextId()).substring(15, 19)); |
| | | |
| | | param.getTaskList().add(taskDto); |
| | | } |
| | | |
| | | mainService.generateBusAndTask(param, memo); |
| | | } |
| | | |
| | | private void runStaToLoc0(String memo) { |
| | | AgvModel agvModel = agvModelService.getOne(new LambdaQueryWrapper<AgvModel>().eq(AgvModel::getType, AgvModelType.CTU_BOX_TRANSPORT_AGV.toString())); |
| | | if (null == agvModel) { return; } |
| | | |
| | | // STOCK STA |
| | | List<Sta> stockList = staService.list(new LambdaQueryWrapper<Sta>() |
| | | .eq(Sta::getStaSts, StaStsType.STOCK.val()) |
| | | .eq(Sta::getStatus, StatusType.ENABLE.val)); |
| | | List<Sta> stockList = staService.queryAvailableOutSta(1); |
| | | if (Cools.isEmpty(stockList)) { return; } |
| | | Collections.shuffle(stockList); |
| | | |
| | |
| | | param.setBatch(String.valueOf(snowflakeIdWorker.nextId()).substring(13, 19)); |
| | | for (int i = 0; i < Math.min(agvModel.getBackpack(), stockList.size()) ; i++) { |
| | | Sta stockSta = stockList.get(i); |
| | | String staCode = stockSta.getCode$(); |
| | | String staCode = codeService.getCacheById(stockSta.getCode()).getData(); |
| | | |
| | | Loc idleLoc = null; |
| | | |
| | |
| | | } |
| | | |
| | | // 出库 |
| | | private void runLocToSta(String memo) { |
| | | // Integer startRow = Collections.min(locGroupList); |
| | | // Integer endRow = Collections.max(locGroupList); |
| | | Integer startRow = null; |
| | | Integer endRow = null; |
| | | |
| | | AgvModel agvModel = agvModelService.getOne(new LambdaQueryWrapper<AgvModel>().eq(AgvModel::getType, AgvModelType.CTU_BOX_TRANSPORT_AGV.toString())); |
| | | if (null == agvModel) { |
| | | return; |
| | | } |
| | | int maxCapacity = agvModel.getBackpack(); |
| | | |
| | | // STA IDLE |
| | | LambdaQueryWrapper<Sta> idleWrapper = new LambdaQueryWrapper<Sta>() |
| | | .eq(Sta::getStaSts, StaStsType.IDLE.val()) |
| | | .eq(Sta::getStatus, StatusType.ENABLE.val) |
| | | // .in(Sta::getStaNo, staGroupList) |
| | | ; |
| | | List<Sta> idleList = staService.list(idleWrapper); |
| | | if (Cools.isEmpty(idleList)) { |
| | | return; |
| | | } |
| | | Collections.shuffle(idleList); |
| | | |
| | | // LOC STOCK |
| | | LambdaQueryWrapper<Loc> stockWrapper = new LambdaQueryWrapper<Loc>().eq(Loc::getLocSts, LocStsType.STOCK.val()); |
| | | if (null != startRow) { stockWrapper.ge(Loc::getRow, startRow); } |
| | | if (null != endRow) { stockWrapper.le(Loc::getRow, endRow); } |
| | | List<Loc> stockList = locService.list(stockWrapper); |
| | | if (Cools.isEmpty(stockList)) { |
| | | return; |
| | | } |
| | | Collections.shuffle(stockList); |
| | | |
| | | OpenBusSubmitParam param = new OpenBusSubmitParam(); |
| | | param.setBatch(String.valueOf(snowflakeIdWorker.nextId()).substring(13, 19)); |
| | | for (int i = 0; i < Math.min(maxCapacity, Math.min(idleList.size(), stockList.size())); i++) { |
| | | Loc stockLoc = stockList.get(i); |
| | | Sta idleSta = idleList.get(i); |
| | | |
| | | 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); |
| | | } |
| | | |
| | | mainService.generateBusAndTask(param, memo); |
| | | } |
| | | |
| | | private void runLocToSta0(String memo) { |
| | | AgvModel agvModel = agvModelService.getOne(new LambdaQueryWrapper<AgvModel>().eq(AgvModel::getType, AgvModelType.CTU_BOX_TRANSPORT_AGV.toString())); |
| | | if (null == agvModel) { return; } |
| | | private void runLocToSta(AgvModel agvModel, String memo) { |
| | | |
| | | // IDLE STA |
| | | List<Sta> idleList = staService.list(new LambdaQueryWrapper<Sta>() |
| | | .eq(Sta::getStaSts, StaStsType.IDLE.val()) |
| | | .eq(Sta::getStatus, StatusType.ENABLE.val)); |
| | | List<Sta> idleList = staService.queryAvailableInSta(1); |
| | | if (Cools.isEmpty(idleList)) { return; } |
| | | Collections.shuffle(idleList); |
| | | |
| | |
| | | param.setBatch(String.valueOf(snowflakeIdWorker.nextId()).substring(13, 19)); |
| | | for (int i = 0; i < Math.min(agvModel.getBackpack(), idleList.size()) ; i++) { |
| | | Sta idleSta = idleList.get(i); |
| | | String staCode = idleSta.getCode$(); |
| | | String staCode = codeService.getCacheById(idleSta.getCode()).getData(); |
| | | |
| | | Loc stockLoc = null; |
| | | |
| | |
| | | } |
| | | |
| | | // 移库 |
| | | private void runLocToLoc(String staTaskMemo) { |
| | | private void runLocToLoc(AgvModel agvModel, String staTaskMemo) { |
| | | String memo = "DEMO_LOC"; |
| | | |
| | | int availableAgvCount = this.getAvailableAgvCount(); |
| | |
| | | .in(Bus::getBusSts, BusStsType.RECEIVE.val(), BusStsType.PROGRESS.val()) |
| | | .in(Bus::getMemo, memo, staTaskMemo) |
| | | )) { return; } |
| | | |
| | | AgvModel agvModel = agvModelService.getOne(new LambdaQueryWrapper<AgvModel>().eq(AgvModel::getType, AgvModelType.CTU_BOX_TRANSPORT_AGV.toString())); |
| | | if (null == agvModel) { return; } |
| | | |
| | | int maxCapacity = agvModel.getBackpack(); |
| | | |