| | |
| | | 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.*; |
| | | import com.zy.acs.manager.core.integrate.dto.OpenBusSubmitParam; |
| | | import com.zy.acs.manager.core.service.AreaGovernService; |
| | | import com.zy.acs.manager.core.service.MainService; |
| | | import com.zy.acs.manager.manager.entity.*; |
| | | import com.zy.acs.manager.manager.enums.*; |
| | | 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.service.*; |
| | | import com.zy.acs.manager.manager.service.impl.CodeServiceImpl; |
| | | import com.zy.acs.manager.manager.service.impl.TaskServiceImpl; |
| | |
| | | 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.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Slf4j |
| | | @Component |
| | | //@Component |
| | | public class AutoRunScheduler { |
| | | |
| | | private static final AgvModelType DEFAULT_AGV_MODEL = AgvModelType.CTU_BOX_TRANSPORT_AGV; |
| | |
| | | } |
| | | |
| | | private void autoRun(AgvModel agvModel) { |
| | | int availableAgvCount = this.getAvailableAgvCount(); |
| | | if (0 == availableAgvCount) { |
| | | log.error("failed to run auto agv task, 跑库区域无可用小车"); |
| | | return; |
| | | } |
| | | |
| | | // List<String> staPreNos = getStaPrefixes(staGroupList); |
| | | List<String> staPreNos = new ArrayList<>(); |
| | | String memo = "DEMO_STA_" + String.join("-", staPreNos); |
| | | List<String> codes = getTestAreaCodes(); |
| | | if (codes.isEmpty()) { |
| | | log.error("failed to run auto agv task, 未配置跑库区域"); |
| | | String taskAssignModeArea = configService.getVal("TaskAssignModeArea", String.class); |
| | | if (Cools.isEmpty(taskAssignModeArea)) { |
| | | return; |
| | | } |
| | | // 入库 |
| | | this.runStaToLoc(agvModel, codes, memo); |
| | | // 出库 |
| | | this.runLocToSta(agvModel, codes, memo); |
| | | // 移库 |
| | | this.runLocToLoc(agvModel, codes, memo); |
| | | for (String areaCode : taskAssignModeArea.split(";")) { |
| | | List<String> testAreaCodes = getTestAreaCodes(areaCode); |
| | | if (testAreaCodes.isEmpty()) { |
| | | continue; |
| | | } |
| | | List<Area> list = areaService.list(new LambdaQueryWrapper<Area>().eq(Area::getName, areaCode)); |
| | | Optional<Integer> max = list.stream().map(Area::getPriority).filter(Objects::nonNull).max(Integer::compareTo); |
| | | Integer priority = max.isPresent() ? max.get() : null; |
| | | if (!Cools.isEmpty(priority)) { |
| | | // 入库 |
| | | this.runStaToLoc(agvModel, testAreaCodes, memo); |
| | | // 出库 |
| | | this.runLocToSta(agvModel, testAreaCodes, memo); |
| | | // 移库 |
| | | this.runLocToLoc(areaCode, agvModel, testAreaCodes, memo); |
| | | } else if (priority > 10) { |
| | | // 出库 |
| | | this.runLocToSta(agvModel, testAreaCodes, memo); |
| | | // 移库 |
| | | this.runLocToLoc(areaCode, agvModel, testAreaCodes, memo); |
| | | } else if (priority > 100) { |
| | | // 移库 |
| | | this.runLocToLoc(areaCode, agvModel, testAreaCodes, memo); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | // 入库 |
| | |
| | | } |
| | | |
| | | // 移库 |
| | | private void runLocToLoc(AgvModel agvModel, List<String> codes, String staTaskMemo) { |
| | | private void runLocToLoc(String area, AgvModel agvModel, List<String> codes, String staTaskMemo) { |
| | | String memo = "DEMO_LOC"; |
| | | |
| | | int availableAgvCount = this.getAvailableAgvCount(); |
| | | int availableAgvCount = this.getAvailableAgvCount(area); |
| | | |
| | | // 最多 ? 组bus运行 |
| | | if (availableAgvCount <= busService.count(new LambdaQueryWrapper<Bus>() |
| | |
| | | } |
| | | |
| | | |
| | | public List<String> getTestAreaCodes() { |
| | | String taskAssignModeArea = configService.getVal("TaskAssignModeArea", String.class); |
| | | if (Cools.isEmpty(taskAssignModeArea)) { |
| | | List<Code> list = codeService.list(new LambdaQueryWrapper<Code>().eq(Code::getStatus, 1)); |
| | | return list.stream().map(Code::getData).collect(Collectors.toList()); |
| | | } |
| | | List<Area> list = areaService.list(new LambdaQueryWrapper<Area>().eq(Area::getName, taskAssignModeArea)); |
| | | public List<String> getTestAreaCodes(String areaCode) { |
| | | List<Area> list = areaService.list(new LambdaQueryWrapper<Area>().eq(Area::getName, areaCode)); |
| | | if (list.isEmpty()) { |
| | | return Collections.emptyList(); |
| | | } |
| | | return areaGovernService.queryCodes(list.stream().map(Area::getId).collect(Collectors.toList())); |
| | | } |
| | | |
| | | public List<Long> getTestAreaAgvs() { |
| | | String taskAssignModeArea = configService.getVal("TaskAssignModeArea", String.class); |
| | | if (Cools.isEmpty(taskAssignModeArea)) { |
| | | List<Agv> list = agvService.list(new LambdaQueryWrapper<Agv>().eq(Agv::getStatus, 1)); |
| | | return list.stream().map(Agv::getId).collect(Collectors.toList()); |
| | | } |
| | | List<Area> list = areaService.list(new LambdaQueryWrapper<Area>().eq(Area::getName, taskAssignModeArea)); |
| | | public List<Long> getTestAreaAgvs(String areaCode) { |
| | | List<Area> list = areaService.list(new LambdaQueryWrapper<Area>().eq(Area::getName, areaCode)); |
| | | if (list.isEmpty()) { |
| | | return Collections.emptyList(); |
| | | } |
| | |
| | | return result; |
| | | } |
| | | |
| | | private int getAvailableAgvCount() { |
| | | private int getAvailableAgvCount(String areaCode) { |
| | | int res = 0; |
| | | List<Long> testAreaAgvs = getTestAreaAgvs(); |
| | | List<Long> testAreaAgvs = getTestAreaAgvs(areaCode); |
| | | for (Long agvId : testAreaAgvs) { |
| | | String agvNo = agvService.getAgvNo(agvId); |
| | | Agv agv = agvService.selectByUuid(agvNo); |