| | |
| | | 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.LaneDto; |
| | | 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; |
| | |
| | | @Autowired |
| | | private LocService locService; |
| | | @Autowired |
| | | private LaneService laneService; |
| | | private LaneBuilder laneBuilder; |
| | | @Autowired |
| | | private AgvAreaDispatcher agvAreaDispatcher; |
| | | @Autowired |
| | |
| | | return result; |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public synchronized String execute(Task task, AllocateSupport inbound, AllocateSupport normal) { |
| | | // inbound roller station |
| | | Sta rollerOriSta = getInboundRollerSta(task); |
| | | String inboundAgv = tryAllocateForRoller(task, rollerOriSta, true); |
| | | if (!Cools.isEmpty(inboundAgv)) { |
| | | inbound.success(task, inboundAgv); |
| | | inbound.success(task, inboundAgv, rollerOriSta); |
| | | return inboundAgv; |
| | | } |
| | | |
| | |
| | | Sta rollerDestSta = getOutboundRollerSta(task); |
| | | String outboundAgv = tryAllocateForRoller(task, rollerDestSta, false); |
| | | if (!Cools.isEmpty(outboundAgv)) { |
| | | normal.success(task, outboundAgv); |
| | | normal.success(task, outboundAgv, rollerDestSta); |
| | | return outboundAgv; |
| | | } |
| | | |
| | | String normalAgv = this.normalExecute(task); |
| | | if (!Cools.isEmpty(normalAgv)) { |
| | | normal.success(task, normalAgv); |
| | | normal.success(task, normalAgv, null); |
| | | return normalAgv; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | // record lane hash for later dispatch/traffic-control logic |
| | | if (filterLaneDto.getOriginLane() != null) { |
| | | task.setOriLaneHash(filterLaneDto.getOriginLane().getHashCode()); |
| | | if (filterLaneDto.getOriginLaneDto() != null) { |
| | | task.setOriLaneHash(filterLaneDto.getOriginLaneDto().getHashCode()); |
| | | } |
| | | if (filterLaneDto.getDestinationLane() != null) { |
| | | task.setDestLaneHash(filterLaneDto.getDestinationLane().getHashCode()); |
| | | if (filterLaneDto.getDestinationLaneDto() != null) { |
| | | task.setDestLaneHash(filterLaneDto.getDestinationLaneDto().getHashCode()); |
| | | } |
| | | |
| | | return agvNo; |
| | |
| | | if (null == filterLaneDto) { |
| | | return null; |
| | | } |
| | | Lane originLane = filterLaneDto.getOriginLane(); |
| | | Lane destinationLane = filterLaneDto.getDestinationLane(); |
| | | LaneDto originLaneDto = filterLaneDto.getOriginLaneDto(); |
| | | LaneDto destinationLaneDto = filterLaneDto.getDestinationLaneDto(); |
| | | List<String> actualAvailableAgvNos = filterLaneDto.getActualAvailableAgvNos(); |
| | | if (Cools.isEmpty(actualAvailableAgvNos)) { |
| | | return null; |
| | | } |
| | | |
| | | // choose min number of running task |
| | | actualAvailableAgvNos.sort(Comparator.comparingInt(agvNo -> calcAllocateWeight(agvNo, task))); |
| | | actualAvailableAgvNos.sort((o1, o2) -> Integer.compare( |
| | | calcAllocateWeight(o2, task), |
| | | calcAllocateWeight(o1, task) |
| | | )); |
| | | |
| | | if (null != originLane) { |
| | | task.setOriLaneHash(originLane.getHashCode()); |
| | | if (null != originLaneDto) { |
| | | task.setOriLaneHash(originLaneDto.getHashCode()); |
| | | } |
| | | if (null != destinationLane) { |
| | | task.setDestLaneHash(destinationLane.getHashCode()); |
| | | if (null != destinationLaneDto) { |
| | | task.setDestLaneHash(destinationLaneDto.getHashCode()); |
| | | } |
| | | |
| | | return actualAvailableAgvNos.get(0); |
| | |
| | | } |
| | | |
| | | // 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) { |
| | | // 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) { |
| | | List<Integer> usedBackpacks = segmentService.selectUsedBackpacks(null, agvId); |
| | | if (usedBackpacks.size() >= backpack) { |
| | | continue; |
| | | } |
| | | |
| | |
| | | Integer maxAgvCountInLane = configService.getVal("maxAgvCountInLane", Integer.class); |
| | | |
| | | // checkout lane |
| | | Lane originLane = taskService.checkoutOriginLane(task); |
| | | Lane destinationLane = taskService.checkoutDestinationLane(task); |
| | | LaneDto originLaneDto = taskService.checkoutOriginLane(task); |
| | | LaneDto destinationLaneDto = taskService.checkoutDestinationLane(task); |
| | | |
| | | // allocate about origin |
| | | List<String> availableAgvNosByOriLane = new ArrayList<>(availableAgvNos); |
| | | if (null != originLane) { |
| | | List<String> agvNosByOriLane = findAgvNosByLane(originLane); // the agv list that had tasks in this lane |
| | | if (null != originLaneDto) { |
| | | List<String> agvNosByOriLane = findAgvNosByLane(originLaneDto); // the agv list that had tasks in this lane |
| | | // if full lane |
| | | if (agvNosByOriLane.size() >= maxAgvCountInLane) { |
| | | |
| | |
| | | |
| | | // allocate about destination |
| | | List<String> availableAgvNosByDestLane = new ArrayList<>(availableAgvNos); |
| | | if (null != destinationLane) { |
| | | List<String> agvNosByDestLane = findAgvNosByLane(destinationLane); |
| | | if (null != destinationLaneDto) { |
| | | List<String> agvNosByDestLane = findAgvNosByLane(destinationLaneDto); |
| | | if (agvNosByDestLane.size() >= maxAgvCountInLane) { |
| | | |
| | | availableAgvNosByDestLane = Cools.getIntersection(agvNosByDestLane, availableAgvNos); |
| | |
| | | return null; |
| | | } |
| | | |
| | | return new FilterLaneDto(originLane, destinationLane, actualAvailableAgvNos); |
| | | return new FilterLaneDto(originLaneDto, destinationLaneDto, actualAvailableAgvNos); |
| | | } |
| | | |
| | | public List<String> findAgvNosByLane(Lane lane) { |
| | | if (null == lane) { |
| | | public List<String> findAgvNosByLane(LaneDto laneDto) { |
| | | if (null == laneDto) { |
| | | return new ArrayList<>(); |
| | | } |
| | | List<Task> taskList = taskService.findRunningTasksByLaneHash(lane.getHashCode()); |
| | | List<Task> taskList = taskService.findRunningTasksByLaneHash(laneDto.getHashCode()); |
| | | if (Cools.isEmpty(taskList)) { |
| | | return new ArrayList<>(); |
| | | } |
| | |
| | | } |
| | | |
| | | public Boolean validCapacityOfLane(String agvNo, Code code) { |
| | | Lane lane = laneService.search(code.getData()); |
| | | if (null != lane) { |
| | | LaneDto laneDto = laneBuilder.search(code.getData()); |
| | | if (null != laneDto) { |
| | | Integer maxAgvCountInLane = configService.getVal("maxAgvCountInLane", Integer.class); |
| | | |
| | | List<String> agvNosByLane = this.findAgvNosByLane(lane); |
| | | List<String> agvNosByLane = this.findAgvNosByLane(laneDto); |
| | | agvNosByLane.remove(agvNo); |
| | | if (agvNosByLane.size() >= maxAgvCountInLane) { |
| | | return false; |