| | |
| | | import com.zy.acs.framework.common.Cools; |
| | | import com.zy.acs.manager.common.utils.CommonUtil; |
| | | import com.zy.acs.manager.core.domain.AgvCntDto; |
| | | import com.zy.acs.manager.core.domain.Lane; |
| | | import com.zy.acs.manager.core.domain.FilterLaneDto; |
| | | import com.zy.acs.manager.core.domain.Lane; |
| | | import com.zy.acs.manager.core.domain.TaskPosDto; |
| | | import com.zy.acs.manager.manager.entity.*; |
| | | import com.zy.acs.manager.manager.enums.StaTypeType; |
| | | import com.zy.acs.manager.manager.enums.StatusType; |
| | | import com.zy.acs.manager.manager.enums.TaskStsType; |
| | | import com.zy.acs.manager.manager.enums.TaskTypeType; |
| | | import com.zy.acs.manager.manager.enums.*; |
| | | import com.zy.acs.manager.manager.service.*; |
| | | import com.zy.acs.manager.system.service.ConfigService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | |
| | | return result; |
| | | } |
| | | |
| | | public synchronized Agv execute(Task task) { |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public synchronized String execute(Task task, AllocateSupport inbound, AllocateSupport normal) { |
| | | // inbound roller station |
| | | Sta rollerOriSta = getInboundRollerSta(task); |
| | | if (rollerOriSta != null) { |
| | | List<String> availableAgvNos = this.getAvailableAgvNos(agvAreaDispatcher.getAgvNosByTask(task), true); |
| | | FilterLaneDto filterLaneDto = this.filterThroughLane(task, availableAgvNos); |
| | | if (null != filterLaneDto) { |
| | | String agvNo = this.checkoutAgvForInboundRoller(task, rollerOriSta, filterLaneDto.getActualAvailableAgvNos()); |
| | | if (!Cools.isEmpty(agvNo)) { |
| | | task.setOriLaneHash(filterLaneDto.getOriginLane().getHashCode()); |
| | | task.setDestLaneHash(filterLaneDto.getDestinationLane().getHashCode()); |
| | | return agvService.selectByUuid(agvNo); |
| | | } |
| | | } |
| | | String inboundAgv = tryAllocateForRoller(task, rollerOriSta, true); |
| | | if (!Cools.isEmpty(inboundAgv)) { |
| | | inbound.success(task, inboundAgv, rollerOriSta); |
| | | return inboundAgv; |
| | | } |
| | | |
| | | // outbound roller station |
| | | Sta rollerDestSta = getOutboundRollerSta(task); |
| | | if (rollerDestSta != null) { |
| | | List<String> availableAgvNos = this.getAvailableAgvNos(agvAreaDispatcher.getAgvNosByTask(task), true); |
| | | FilterLaneDto filterLaneDto = this.filterThroughLane(task, availableAgvNos); |
| | | if (null != filterLaneDto) { |
| | | String agvNo = this.checkoutAgvForOutboundRoller(task, rollerDestSta, filterLaneDto.getActualAvailableAgvNos()); |
| | | if (!Cools.isEmpty(agvNo)) { |
| | | task.setOriLaneHash(filterLaneDto.getOriginLane().getHashCode()); |
| | | task.setDestLaneHash(filterLaneDto.getDestinationLane().getHashCode()); |
| | | return agvService.selectByUuid(agvNo); |
| | | } |
| | | } |
| | | String outboundAgv = tryAllocateForRoller(task, rollerDestSta, false); |
| | | if (!Cools.isEmpty(outboundAgv)) { |
| | | normal.success(task, outboundAgv, rollerDestSta); |
| | | return outboundAgv; |
| | | } |
| | | |
| | | return this.normalExecute(task); |
| | | String normalAgv = this.normalExecute(task); |
| | | if (!Cools.isEmpty(normalAgv)) { |
| | | normal.success(task, normalAgv, null); |
| | | return normalAgv; |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | private String tryAllocateForRoller(Task task, Sta rollerSta, boolean inbound) { |
| | | if (rollerSta == null) { |
| | | return null; |
| | | } |
| | | |
| | | List<String> availableAgvNos = this.getAvailableAgvNos(agvAreaDispatcher.getAgvNosByTask(task), true); |
| | | FilterLaneDto filterLaneDto = this.filterThroughLane(task, availableAgvNos); |
| | | if (filterLaneDto == null) { |
| | | return null; |
| | | } |
| | | |
| | | String agvNo = inbound |
| | | ? this.checkoutAgvForInboundRoller(task, rollerSta, filterLaneDto.getActualAvailableAgvNos()) |
| | | : this.checkoutAgvForOutboundRoller(task, rollerSta, filterLaneDto.getActualAvailableAgvNos()); |
| | | if (Cools.isEmpty(agvNo)) { |
| | | return null; |
| | | } |
| | | |
| | | // record lane hash for later dispatch/traffic-control logic |
| | | if (filterLaneDto.getOriginLane() != null) { |
| | | task.setOriLaneHash(filterLaneDto.getOriginLane().getHashCode()); |
| | | } |
| | | if (filterLaneDto.getDestinationLane() != null) { |
| | | task.setDestLaneHash(filterLaneDto.getDestinationLane().getHashCode()); |
| | | } |
| | | |
| | | return agvNo; |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * it can break the limit of the number of agv backpack |
| | | */ |
| | | public synchronized Agv normalExecute(Task task) { |
| | | public synchronized String normalExecute(Task task) { |
| | | List<String> availableAgvNos = this.getAvailableAgvNos(agvAreaDispatcher.getAgvNosByTask(task), false); |
| | | // List<String> availableAgvNos = this.getAvailableAgvNos(null); |
| | | if (Cools.isEmpty(availableAgvNos)) { |
| | |
| | | Lane originLane = filterLaneDto.getOriginLane(); |
| | | Lane destinationLane = filterLaneDto.getDestinationLane(); |
| | | List<String> actualAvailableAgvNos = filterLaneDto.getActualAvailableAgvNos(); |
| | | if (Cools.isEmpty(actualAvailableAgvNos)) { |
| | | return null; |
| | | } |
| | | |
| | | // choose min number of running task |
| | | actualAvailableAgvNos.sort(new Comparator<String>() { |
| | | @Override |
| | | public int compare(String agvNo1, String agvNo2) { |
| | | return calcAllocateWeight(agvNo1, task) - calcAllocateWeight(agvNo2, task); |
| | | } |
| | | }); |
| | | actualAvailableAgvNos.sort(Comparator.comparingInt(agvNo -> calcAllocateWeight(agvNo, task))); |
| | | |
| | | if (null != originLane) { |
| | | task.setOriLaneHash(originLane.getHashCode()); |
| | |
| | | task.setDestLaneHash(destinationLane.getHashCode()); |
| | | } |
| | | |
| | | return agvService.selectByUuid(actualAvailableAgvNos.stream().findFirst().orElse(null)); |
| | | return actualAvailableAgvNos.get(0); |
| | | } |
| | | |
| | | private String checkoutAgvForInboundRoller(Task task, Sta sta, List<String> availableAgvNos) { |
| | |
| | | } |
| | | |
| | | // has running task and within oriSta |
| | | // List<Segment> currSeg = segmentService.getByAgvAndState(agvId, SegmentStateType.WAITING.toString()); |
| | | int taskCnt = taskService.count(new LambdaQueryWrapper<Task>() |
| | | .eq(Task::getAgvId, agvId) |
| | | .eq(Task::getOriSta, sta.getId()) |
| | | .and(wrapper -> wrapper |
| | | .eq(Task::getTaskSts, TaskStsType.ASSIGN.val()) |
| | | .or() |
| | | .eq(Task::getTaskSts, TaskStsType.PROGRESS.val()) |
| | | ) |
| | | ); |
| | | if (taskCnt == 0) { |
| | | break; |
| | | // int taskCnt = taskService.count(new LambdaQueryWrapper<Task>() |
| | | // .eq(Task::getAgvId, agvId) |
| | | // .eq(Task::getOriSta, sta.getId()) |
| | | // .and(wrapper -> wrapper |
| | | // .eq(Task::getTaskSts, TaskStsType.ASSIGN.val()) |
| | | // .or() |
| | | // .eq(Task::getTaskSts, TaskStsType.PROGRESS.val()) |
| | | // ) |
| | | // ); |
| | | // if (taskCnt == 0) { |
| | | // continue; |
| | | // } |
| | | // in TransferStationHandler.hasDelayAtSta |
| | | Segment currSeg = segmentService.getRollerWaiting(agvId, sta.getCode(), TaskPosDto.PosType.ORI_STA); |
| | | if (null == currSeg) { |
| | | continue; |
| | | } |
| | | |
| | | // has enough backpack space to load |
| | | Integer backpack = agvService.getBackpack(agvId); |
| | | int countRemainingBackpack = segmentService.countRemainingBackpack(null, agvId); |
| | | if (countRemainingBackpack >= backpack) { |
| | | break; |
| | | List<Integer> usedBackpacks = segmentService.selectUsedBackpacks(null, agvId); |
| | | if (usedBackpacks.size() >= backpack) { |
| | | continue; |
| | | } |
| | | |
| | | return agvNo; |