From 052ee1f9c0b9e2bc8bbd4cf135ae45fed7422023 Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@163.com> Date: 星期一, 28 十月 2024 10:36:28 +0800 Subject: [PATCH] # --- zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java | 145 +++++++++++++++++++++++++++++------------------ 1 files changed, 89 insertions(+), 56 deletions(-) diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java index 434718d..c35cd65 100644 --- a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java +++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java @@ -67,6 +67,8 @@ @Autowired private ValidService validService; @Autowired + private AllocateService allocateService; + @Autowired private CodeService codeService; @Autowired private MapService mapService; @@ -88,8 +90,7 @@ private TrafficService trafficService; @Autowired private AgvModelService agvModelService; - @Autowired - private MissionAssignService missionAssignService; + @SuppressWarnings("all") @Transactional @@ -101,7 +102,7 @@ String batch = busSubmitParam.getBatch(); List<TaskDto> taskDtoList = busSubmitParam.getTaskList(); if (Cools.isEmpty(taskDtoList)) { - throw new BusinessException("taskDtoList 涓嶈兘涓虹┖"); + throw new BusinessException("taskList can't be empty!"); } // 浼樺厛绾ф帓搴� @@ -120,7 +121,7 @@ bus.setMemo(memo); if (!busService.save(bus)) { - throw new BusinessException("浠诲姟淇濆瓨澶辫触"); + throw new BusinessException("Internal Server Error!"); } // 淇濆瓨浠诲姟 @@ -128,7 +129,7 @@ task.setBusId(bus.getId()); task.setTaskSts(TaskStsType.INIT.val()); if (!taskService.save(task)) { - throw new BusinessException(task.getSeqNum() + "浠诲姟淇濆瓨澶辫触"); + throw new BusinessException("seqNum:" + task.getSeqNum() + " failed to save!"); } // 淇敼搴撲綅鐘舵�� @@ -140,44 +141,44 @@ case LOC_TO_LOC: oriLoc = locService.getById(task.getOriLoc()); if (!oriLoc.getLocSts().equals(LocStsType.STOCK.val())) { - throw new BusinessException("oriLoc锛�" + task.getOriLoc$() + " 涓嶆槸鍦ㄥ簱鐘舵��"); + throw new BusinessException("oriLoc锛�" + task.getOriLoc$() + " is not in STOCK status"); } oriLoc.setLocSts(LocStsType.PAKOUT.val()); oriLoc.setUpdateTime(now); if (!locService.updateById(oriLoc)) { - throw new BusinessException("oriLoc锛�" + task.getOriLoc$() + " 淇敼搴撲綅鐘舵�佸け璐�"); + throw new BusinessException("oriLoc锛�" + task.getOriLoc$() + " failed to update"); } destLoc = locService.getById(task.getDestLoc()); if (!destLoc.getLocSts().equals(LocStsType.IDLE.val())) { - throw new BusinessException("destLoc锛�" + task.getDestLoc$() + " 涓嶆槸绌洪棽鐘舵��"); + throw new BusinessException("destLoc锛�" + task.getDestLoc$() + " is not in IDLE status"); } destLoc.setLocSts(LocStsType.PAKIN.val()); destLoc.setUpdateTime(now); if (!locService.updateById(destLoc)) { - throw new BusinessException("destLoc锛�" + task.getDestLoc$() + " 淇敼搴撲綅鐘舵�佸け璐�"); + throw new BusinessException("destLoc锛�" + task.getDestLoc$() + " failed to update"); } break; case LOC_TO_STA: oriLoc = locService.getById(task.getOriLoc()); if (!oriLoc.getLocSts().equals(LocStsType.STOCK.val())) { - throw new BusinessException("oriLoc锛�" + task.getOriLoc$() + " 涓嶆槸鍦ㄥ簱鐘舵��"); + throw new BusinessException("oriLoc锛�" + task.getOriLoc$() + " is not in STOCK status"); } oriLoc.setLocSts(LocStsType.PAKOUT.val()); oriLoc.setUpdateTime(now); if (!locService.updateById(oriLoc)) { - throw new BusinessException("oriLoc锛�" + task.getOriLoc$() + " 淇敼搴撲綅鐘舵�佸け璐�"); + throw new BusinessException("oriLoc锛�" + task.getOriLoc$() + " failed to update"); } break; case STA_TO_LOC: destLoc = locService.getById(task.getDestLoc()); if (!destLoc.getLocSts().equals(LocStsType.IDLE.val())) { - throw new BusinessException("destLoc锛�" + task.getDestLoc$() + " 涓嶆槸绌洪棽鐘舵��"); + throw new BusinessException("destLoc锛�" + task.getDestLoc$() + " is not in IDLE status"); } destLoc.setLocSts(LocStsType.PAKIN.val()); destLoc.setUpdateTime(now); if (!locService.updateById(destLoc)) { - throw new BusinessException("destLoc锛�" + task.getDestLoc$() + " 淇敼搴撲綅鐘舵�佸け璐�"); + throw new BusinessException("destLoc锛�" + task.getDestLoc$() + " failed to update"); } break; case STA_TO_STA: @@ -194,7 +195,7 @@ * 浠诲姟鍒嗛厤缁欒溅杈� ( 杞﹁締姝ゆ椂鏄┖闂蹭笖闈欐鐨� ) */ @Transactional - public synchronized void infuseAgvForTask(Bus bus) { + public synchronized void allocateTask(Bus bus) { try { Date now = new Date(); List<Task> taskList = taskService.list(new LambdaQueryWrapper<Task>() @@ -207,39 +208,54 @@ bus.setBusSts(BusStsType.PROGRESS.val()); bus.setUpdateTime(now); if (!busService.updateById(bus)) { - log.error("Bus [{}] 鏇存柊澶辫触 锛侊紒锛�", bus.getUuid()); + log.error("Bus [{}] failed to Update 锛侊紒锛�", bus.getUuid()); } return; } - List<Long> taskIds = taskList.stream().map(Task::getId).distinct().collect(Collectors.toList()); - Map<String, List<Long>> taskAllot = new HashMap<>(); + List<Long> taskIds = taskList.stream().map(Task::getId).distinct().collect(Collectors.toList()); for (Task task : taskList) { - Agv agv = missionAssignService.execute(task, taskAllot, taskIds); + Agv agv = allocateService.execute(task); if (null == agv) { - log.warn("{}浠诲姟寮傚父锛屾棤娉曟绱㈢┖闂睞gv...", task.getSeqNum()); + log.warn("Task[{}] has an issue锛� because it failed to checkout agv which is idle...", task.getSeqNum()); continue; } - - task.setAgvId(agv.getId()); task.setTaskSts(TaskStsType.WAITING.val()); task.setIoTime(now); task.setUpdateTime(now); if (!taskService.updateById(task)) { - throw new BusinessException(task.getSeqNum() + "浠诲姟鏇存柊澶辫触"); - } - - if (taskAllot.containsKey(agv.getUuid())) { - taskAllot.get(agv.getUuid()).add(task.getId()); - } else { - taskAllot.put(agv.getUuid(), Utils.singletonList(task.getId())); + throw new BusinessException("seqNum: " + task.getSeqNum() + " failed to update"); } } -// bus.setUpdateTime(now); -// if (!busService.updateById(bus)) { -// throw new BusinessException(bus.getSeqNum() + "鎬荤嚎鏇存柊澶辫触"); + + // ------------------------------------------ + + +// +// Map<String, List<Long>> taskAllot = new HashMap<>(); +// for (Task task : taskList) { +// Agv agv = missionAssignService.execute(task, taskAllot, taskIds); +// if (null == agv) { +// log.warn("Task[{}] has an issue锛� because it failed to checkout agv which is idle...", task.getSeqNum()); +// continue; +// } +// +// +// task.setAgvId(agv.getId()); +// task.setTaskSts(TaskStsType.WAITING.val()); +// task.setIoTime(now); +// task.setUpdateTime(now); +// if (!taskService.updateById(task)) { +// throw new BusinessException("seqNum: " + task.getSeqNum() + " failed to update"); +// } +// +// if (taskAllot.containsKey(agv.getUuid())) { +// taskAllot.get(agv.getUuid()).add(task.getId()); +// } else { +// taskAllot.put(agv.getUuid(), Utils.singletonList(task.getId())); +// } // } } catch (Exception e) { log.error("mainService.infuseAgvForTask", e); @@ -251,38 +267,30 @@ * 瑙f瀽鍙栨斁璐ч泦鍚堜换鍔�,杩涜鏈�浼樼殑鎺掑垪缁勫悎椤哄簭 ( 杞﹁締姝ゆ椂鏄┖闂蹭笖闈欐鐨� ) */ @Transactional - public synchronized void mergeMajorTask(Long agvId, List<Task> taskList) { + public synchronized void buildMajorTask(Long agvId, List<Task> taskList) { if (Cools.isEmpty(taskList)) { return; } boolean lockAcquired = false; try { if (!(lockAcquired = this.lock.tryLock(LOCK_TIMEOUT, TimeUnit.SECONDS))) { throw new CoolException("generate [task] action fail, cause can not acquire lock ..."); } - Date now = new Date(); - final String sameGroupXy = configService.getVal( "sameGroupXy", String.class); + // valid ----------------------------------------------- Agv agv = agvService.getById(agvId); - if (!agvService.judgeEnable(agv.getId(), agvDetail -> agvDetail.getVol() > agv.getChargeLine())) { + if (!agvService.judgeEnable(agv.getId(), true)) { throw new CoolException("AGV[" + agv.getUuid() + "]褰撳墠涓嶅彲鐢�..."); } - if (!Cools.isEmpty(taskService.selectInSts(agvId, TaskStsType.ASSIGN, TaskStsType.PROGRESS))) { throw new CoolException("AGV[" + agv.getUuid() + "]鍒嗛厤浠诲姟澶辫触锛屽凡瀛樺湪鎵ц浠诲姟..."); } - AgvDetail agvDetail = agvDetailService.selectByAgvId(agvId); - assert agvDetail != null; - if (agvDetail.getPos() == 0) { - if (!agvDetail.getAgvStatus().equals(AgvStatusType.CHARGE)) { - throw new CoolException("AGV[" + agv.getUuid() + "]褰撳墠涓嶅湪瀹氫綅..."); - } - } - + // execute ---------------------------------------------------- + Date now = new Date(); // sort and sub taskList.sort(new Comparator<Task>() { @Override public int compare(Task o1, Task o2) { - return 0; + return o1.getPriority() - o2.getPriority(); } }); Integer backpack = agvService.getBackpack(agv); @@ -290,15 +298,17 @@ taskList = taskList.subList(0, backpack); } + List<AgvBackpackDto> backpackDtoList = new ArrayList<>(); + /** - * single agvId + * 鍚屽贩閬撳綊绫� + * same lane for every single agvId * - * key: y + TaskPosDto.PosType.ORI_LOC / ORI_STA / DEST_LOC / DEST_STA + * key: y(val) + TaskPosDto.PosType.ORI_LOC / ORI_STA / DEST_LOC / DEST_STA * val: new TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType) */ Map<String, List<TaskPosDto>> groups = new HashMap<>(); - - List<AgvBackpackDto> backpackDtoList = new ArrayList<>(); + final String sameGroupXy = configService.getVal( "sameGroupXy", String.class); int backpackLev = 0; for (Task task : taskList) { @@ -362,7 +372,31 @@ } /** - * List<TaskPosDto>: task list on the same channel + * 1.Map<String, List<TaskPosDto>> groups + * + * key: 1000 + ORI_LOC + * val: [TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType), TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType),...] + * + * key: 3000 + ORI_LOC + * val: [TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType), TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType),...] + * + * key: 2000 + ORI_LOC + * val: [TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType), TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType),...] + * + * ...... + * + * 2.ArrayList<List<TaskPosDto>> list + * [ + * [TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType), TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType),...], + * [TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType), TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType),...], + * [TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType), TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType),...], + * ...... + * ] + */ + + /** + * 瀵规墍鏈夊贩閬撹繘琛屾湁搴忔帓搴忥紝鍏堟槸閽堝List涓轰竴涓崟浣嶏紝瀵逛粬浠繘琛孎irstWeight鎺掑簭锛岀浉褰撲簬琛�1鐨刱ey鐨勬暟鍊艰繘琛屾湁搴忔帓搴� + * List<TaskPosDto>: task list on the same lane * ArrayList<List<TaskPosDto>>: all the task list by one agv */ ArrayList<List<TaskPosDto>> list = new ArrayList<>(groups.values()); @@ -371,7 +405,7 @@ double o2CompVal = (o2.get(0).getFirstWeight(sameGroupXy) * 100) + o2.get(0).getPosType().compOffset; return (int) (o1CompVal - o2CompVal); }); - + // 閽堝Dto锛屾寜鐓econdWeight杩涜鎺掑簭 for (List<TaskPosDto> taskPosDtoList : list) { taskPosDtoList.sort((o1, o2) -> (int) (o1.getSecondWeight(sameGroupXy) * 100 - o2.getSecondWeight(sameGroupXy) * 100)); } @@ -608,11 +642,6 @@ AgvDetail agvDetail = agvDetailService.selectByAgvId(agvId); assert agvDetail != null; - if (agvDetail.getPos() == 0) { - if (!agvDetail.getAgvStatus().equals(AgvStatusType.CHARGE)) { - throw new CoolException("AGV[" + agv.getUuid() + "]褰撳墠涓嶅湪瀹氫綅..."); - } - } List<Action> actionList = new ArrayList<>(); // start node @@ -999,6 +1028,7 @@ } for (Action action : actionList) { action.setActionSts(ActionStsType.ISSUED.val()); + action.setStartTime(now); action.setUpdateTime(now); if (!actionService.updateById(action)) { throw new BusinessException(action.getPriority() + " - " + action.getName() + "鍔ㄤ綔鏇存柊澶辫触"); @@ -1148,6 +1178,7 @@ if (null != action) { action.setActionSts(ActionStsType.FINISH.val()); + action.setEndTime(now); action.setUpdateTime(now); if (!actionService.updateById(action)) { log.error("Action [{}] 鏇存柊澶辫触 锛侊紒锛�", action.getPriority() + " - " + action.getName()); @@ -1180,6 +1211,7 @@ ); if (null != action) { action.setActionSts(ActionStsType.FINISH.val()); + action.setEndTime(now); action.setUpdateTime(now); if (!actionService.updateById(action)) { log.error("Action [{}] 鏇存柊澶辫触 锛侊紒锛�", action.getPriority() + " - " + action.getName()); @@ -1254,6 +1286,7 @@ ); for (Action action : actionList) { action.setActionSts(ActionStsType.FINISH.val()); + action.setEndTime(now); action.setUpdateTime(now); if (!actionService.updateById(action)) { log.error("Action [{}] 鏇存柊澶辫触 锛侊紒锛�", action.getPriority() + " - " + action.getName()); -- Gitblit v1.9.1