| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.zy.acs.common.enums.AgvStatusType; |
| | | import com.zy.acs.manager.manager.entity.Agv; |
| | | import com.zy.acs.manager.manager.entity.AgvDetail; |
| | | import com.zy.acs.manager.manager.entity.Guarantee; |
| | | import com.zy.acs.manager.manager.entity.Task; |
| | | import com.zy.acs.manager.manager.enums.GuaranteeScopeType; |
| | | 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.entity.*; |
| | | import com.zy.acs.manager.manager.enums.*; |
| | | import com.zy.acs.manager.manager.service.AgvDetailService; |
| | | import com.zy.acs.manager.manager.service.AgvService; |
| | | import com.zy.acs.manager.manager.service.SegmentService; |
| | | import com.zy.acs.manager.manager.service.TaskService; |
| | | import lombok.Data; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.time.LocalDateTime; |
| | |
| | | @Service |
| | | public class GuaranteeRuntimeService { |
| | | |
| | | private final AgvService agvService; |
| | | private final AgvDetailService agvDetailService; |
| | | private final TaskService taskService; |
| | | private final MainLockWrapService mainLockWrapService; |
| | | |
| | | public GuaranteeRuntimeService(AgvService agvService, |
| | | AgvDetailService agvDetailService, |
| | | TaskService taskService, |
| | | MainLockWrapService mainLockWrapService) { |
| | | this.agvService = agvService; |
| | | this.agvDetailService = agvDetailService; |
| | | this.taskService = taskService; |
| | | this.mainLockWrapService = mainLockWrapService; |
| | | } |
| | | @Autowired |
| | | private SegmentService segmentService; |
| | | @Autowired |
| | | private AgvService agvService; |
| | | @Autowired |
| | | private AgvDetailService agvDetailService; |
| | | @Autowired |
| | | private TaskService taskService; |
| | | @Autowired |
| | | private MainLockWrapService mainLockWrapService; |
| | | |
| | | public void prepare(Guarantee plan, LocalDateTime targetTime) { |
| | | int requiredCount = plan.getRequiredCount() == null ? 0 : plan.getRequiredCount(); |
| | |
| | | List<ChargeCandidate> candidates = new ArrayList<>(); |
| | | for (Agv agv : scopedAgvList) { |
| | | AgvDetail detail = agvDetailService.selectMajorByAgvId(agv.getId()); |
| | | if (detail == null || detail.getSoc() == null) { |
| | | if (null == detail || null == detail.getSoc() || null == detail.getAgvStatus()) { |
| | | continue; |
| | | } |
| | | if (detail.getAgvStatus().equals(AgvStatusType.CHARGE)) { |
| | | continue; |
| | | } |
| | | if (!isIdle(agv, detail)) { |
| | |
| | | } |
| | | } |
| | | if (available >= requiredCount) { |
| | | log.debug("Guarantee[{}] already has {} vehicles >= {}% SOC for {}", plan.getName(), available, minSoc, targetTime); |
| | | // log.debug("Guarantee[{}] already has {} vehicles >= {}% SOC for {}", plan.getName(), available, minSoc, targetTime); |
| | | return; |
| | | } |
| | | int shortage = requiredCount - available; |
| | | int shortage = requiredCount - available; // 还差多少辆 |
| | | candidates.sort(Comparator.comparingInt(ChargeCandidate::getSoc)); |
| | | int scheduled = 0; |
| | | int scheduled = 0; // 已经安排充电的AGV数量 |
| | | for (ChargeCandidate candidate : candidates) { |
| | | if (scheduled >= shortage) { |
| | | break; |
| | |
| | | if (detail.getAgvStatus() != null && detail.getAgvStatus().equals(AgvStatusType.CHARGE)) { |
| | | return false; |
| | | } |
| | | long busyCount = taskService.count(new LambdaQueryWrapper<Task>() |
| | | |
| | | if (0 < taskService.count(new LambdaQueryWrapper<Task>() |
| | | .eq(Task::getAgvId, agv.getId()) |
| | | // .and(i -> { |
| | | // i.eq(Task::getTaskSts, TaskStsType.WAITING.val()) |
| | | // .or().eq(Task::getTaskSts, TaskStsType.ASSIGN.val()) |
| | | // .or().eq(Task::getTaskSts, TaskStsType.PROGRESS.val()); |
| | | // }) |
| | | .in(Task::getTaskSts, |
| | | TaskStsType.WAITING.val(), |
| | | TaskStsType.ASSIGN.val(), |
| | | TaskStsType.PROGRESS.val())); |
| | | return busyCount == 0; |
| | | TaskStsType.PROGRESS.val()) |
| | | )) { |
| | | return false; |
| | | } |
| | | if (0 < segmentService.count(new LambdaQueryWrapper<Segment>() |
| | | .eq(Segment::getAgvId, agv.getId()) |
| | | .and( i -> { |
| | | // i.eq(Segment::getState, SegmentStateType.WAITING.toString()).or() |
| | | i.eq(Segment::getState, SegmentStateType.RUNNING.toString()); |
| | | }) |
| | | )) { |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | private List<Agv> findScopedAgvList(Guarantee plan) { |
| | |
| | | return agvService.list(wrapper); |
| | | } |
| | | |
| | | @Data |
| | | private static class ChargeCandidate { |
| | | private final Agv agv; |
| | | private final int soc; |
| | |
| | | this.soc = soc; |
| | | } |
| | | |
| | | public Agv getAgv() { |
| | | return agv; |
| | | } |
| | | |
| | | public int getSoc() { |
| | | return soc; |
| | | } |
| | | } |
| | | } |