From 7b6dabd2ac8b30edf695e0d09c22129c16961f84 Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@163.com> Date: 星期一, 28 十月 2024 14:00:00 +0800 Subject: [PATCH] # --- zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/AllocateService.java | 100 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 96 insertions(+), 4 deletions(-) diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/AllocateService.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/AllocateService.java index 3ec330b..93f3c33 100644 --- a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/AllocateService.java +++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/AllocateService.java @@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.zy.acs.framework.common.Cools; import com.zy.acs.manager.common.utils.LocUtils; +import com.zy.acs.manager.core.domain.Lane; import com.zy.acs.manager.manager.entity.Agv; import com.zy.acs.manager.manager.entity.AgvModel; import com.zy.acs.manager.manager.entity.Task; @@ -15,10 +16,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.stream.Collectors; /** * Created by vincent on 8/12/2024 @@ -69,16 +68,109 @@ return result; } + /** + * it can break the limit of the number of agv backpack + */ public synchronized Agv execute(Task task) { List<Agv> availableAgvList = getAvailableAgv(); if (Cools.isEmpty(availableAgvList)) { + log.warn("No available agv to assign the task[{}]", task.getSeqNum()); return null; + } + List<String> availableAgvNos = availableAgvList.stream().map(Agv::getUuid).distinct().collect(Collectors.toList()); + + Integer maxAgvCountInLane = configService.getVal("maxAgvCountInLane", Integer.class); + + // checkout lane + Lane originLane = taskService.checkoutOriginLane(task); + Lane destinationLane = 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 (!Cools.isEmpty(agvNosByOriLane) && agvNosByOriLane.size() >= maxAgvCountInLane) { + + availableAgvNosByOriLane = Cools.getIntersection(agvNosByOriLane, availableAgvNos); + availableAgvNosByOriLane = availableAgvNosByOriLane.stream().filter(agvNo -> { + Agv agv = agvService.selectByUuid(agvNo); + + return agv.getStatus() == 1; + }).collect(Collectors.toList()); + } } + // allocate about destination + List<String> availableAgvNosByDestLane = new ArrayList<>(availableAgvNos); + if (null != destinationLane) { + List<String> agvNosByDestLane = findAgvNosByLane(destinationLane); + if (!Cools.isEmpty(agvNosByDestLane) && agvNosByDestLane.size() >= maxAgvCountInLane) { + + availableAgvNosByDestLane = Cools.getIntersection(agvNosByDestLane, availableAgvNos); + availableAgvNosByDestLane = availableAgvNosByDestLane.stream().filter(agvNo -> { + Agv agv = agvService.selectByUuid(agvNo); + + return agv.getStatus() == 1; + }).collect(Collectors.toList()); + } + } + + // valid + if (Cools.isEmpty(availableAgvNosByOriLane)) { + log.warn("No available agv to assign the task origin[{}]", task.getSeqNum()); + return null; + } + if (Cools.isEmpty(availableAgvNosByDestLane)) { + log.warn("No available agv to assign the task destination[{}]", task.getSeqNum()); + return null; + } + + List<String> actualAvailableAgvNos = Cools.getIntersection(availableAgvNosByOriLane, availableAgvNosByDestLane); + if (Cools.isEmpty(actualAvailableAgvNos)) { + log.warn("No available agv to assign the task[{}]", task.getSeqNum()); + return null; + } + + actualAvailableAgvNos.sort(new Comparator<String>() { + @Override + public int compare(String o1, String o2) { + return 0; + } + }); + + String s = actualAvailableAgvNos.stream().findFirst().orElse(null); + + + /** + * 1. 鍒ゆ柇task鐨勮捣濮嬬偣鍜岀洰鐨勭偣鎵�鍦ㄧ殑宸烽亾鎵胯浇浠诲姟鏁伴噺锛� + * 濡傛灉鏁伴噺宸茬粡杈惧埌璐熻浇锛屽垯鍒ゆ柇璐熻浇浠诲姟鐨凙GV鏄惁杩樻湁绌鸿儗绡擄紝濡傛灉鏈夊垯浼樺厛娲惧彂缁欏畠锛� + * 濡傛灉娌℃湁浜嗭紝閭d箞鍒欓樆濉炰换鍔★紝鐩村埌璇ュ贩閬撻噴鏀� + * + * 2. 杞绌洪棽灏忚溅锛岀洰鏍囨槸璁╂瘡鍙板皬杞﹂兘鍔ㄨ捣鏉� + * 鍒ゆ柇閫昏緫锛氳儗绡撴暟閲忔渶灏戠殑灏忚溅杞鐨勬椂鍊欙紝浼樺厛绾ф渶楂� + */ + + task.setOriLaneHash(originLane.getHashCode()); + task.setDestLaneHash(destinationLane.getHashCode()); + return null; } + private List<String> findAgvNosByLane(Lane lane) { + if (null == lane) { + return null; + } + List<Task> taskList = taskService.findRunningTasksByLaneHash(lane.getHashCode()); + if (Cools.isEmpty(taskList)) { + return null; + } + return taskList.stream().map(task -> { + return agvService.getById(task.getAgvId()).getUuid(); + }).distinct().collect(Collectors.toList()); + } + public synchronized Agv execute(Task task, Map<String, List<Long>> taskAllot, List<Long> taskIds) { String oriLocNo = task.getOriLoc$(); int oriLocRow = LocUtils.getRow(oriLocNo); -- Gitblit v1.9.1