From a043db2de5a336cddad2ac7cda153c4d05d8b93f Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Wed, 12 Mar 2025 22:48:18 +0800 Subject: [PATCH] =?UTF-8?q?BUGFIX:=20=E9=9A=90=E8=97=8F=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E4=B8=8D=E5=87=BAminio=E7=9A=84=E7=9B=B8=E5=85=B3=E6=95=B0?= =?UTF-8?q?=E6=8D=AE;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ai/da/service/impl/DesignServiceImpl.java | 1 + .../da/service/impl/LibraryServiceImpl.java | 124 ++++++++++-------- 2 files changed, 73 insertions(+), 52 deletions(-) diff --git a/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java b/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java index 4c3460a3..1859094b 100644 --- a/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java @@ -1408,6 +1408,7 @@ public class DesignServiceImpl extends ServiceImpl impleme d.setMinIOPath(o.getPath()); d.setPrintObject(new DesignPythonItemPrint()); })); + response.getOthers().removeIf(o -> !minioUtil.doesObjectExist(o.getMinIOPath())); return editDesignItemLayer(flag, designPythonOutfit, minioUtil.getPreSignedUrl(designPythonOutfit.getDesignUrl(), 24 * 60), editResponseColor(designItemDetails, response)); diff --git a/src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java b/src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java index ebc9893a..0e5df05e 100644 --- a/src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java @@ -183,73 +183,93 @@ public class LibraryServiceImpl extends ServiceImpl impl } } queryWrapper.orderByDesc("id"); - IPage page = getBaseMapper().selectPage( - new Page<>(query.getPage(), query.getSize()), queryWrapper); - if (CollectionUtils.isEmpty(page.getRecords())) { + // 1. 先查询所有符合条件的 Library 数据 + List libraryList = getBaseMapper().selectList(queryWrapper); + if (CollectionUtils.isEmpty(libraryList)) { return PageBaseResponse.success(new Page<>()); } + + // 2. 封装打点内容 Map map = null; - //封装打点内容 - Boolean isExist = page.getRecords().stream() + boolean isExist = libraryList.stream() .anyMatch(library -> library.getLevel1Type().equals(LibraryLevel1TypeEnum.MODELS.getRealName())); if (isExist) { - List libarayIds = page.getRecords().stream() + List libraryIds = libraryList.stream() .filter(library -> library.getLevel1Type().equals(LibraryLevel1TypeEnum.MODELS.getRealName())) .map(Library::getId) .collect(Collectors.toList()); - List libraryModelPointVOS = libraryModelPointService.selectByLibraryIds(libarayIds); + List libraryModelPointVOS = libraryModelPointService.selectByLibraryIds(libraryIds); if (!CollectionUtils.isEmpty(libraryModelPointVOS)) { - map = libraryModelPointVOS.stream().collect(Collectors.toMap(LibraryModelPointVO::getRelationId, v -> v)); + map = libraryModelPointVOS.stream() + .collect(Collectors.toMap(LibraryModelPointVO::getRelationId, v -> v)); } } Map finalMap = map; - AtomicInteger i = new AtomicInteger(); - IPage convert = page.convert((Function) library -> { - QueryLibraryPageVO libraryPageVO = CopyUtil.copyObject(library, QueryLibraryPageVO.class); - libraryPageVO.setDesignType(DesignTypeEnum.LIBRARY.getRealName()); - libraryPageVO.setMinIOPath(library.getUrl()); - String url = library.getUrl(); - if (minioUtil.doesObjectExist(url)) { - libraryPageVO.setUrl(minioUtil.getPreSignedUrl(library.getUrl(), 24 * 60)); - if (finalMap != null && finalMap.containsKey(library.getId())) { - libraryPageVO.setLibraryModelPoint(finalMap.get(library.getId())); - } - if (libraryPageVO.getLevel1Type().equals(LibraryLevel1TypeEnum.SKETCH_BOARD.getRealName())) { - if (!StringUtils.isEmpty(libraryPageVO.getLevel2Type())) { - Position position = Position.getPosition(libraryPageVO.getLevel2Type()); - libraryPageVO.setLevel2TypeEnum(new BizJson(position.getValue(), position.name(), BusinessException.getMessageFromResource(position.name()))); - } - } - if (libraryPageVO.getLevel1Type().equals(LibraryLevel1TypeEnum.PRINT_BOARD.getRealName())) { - PrintboardLevel2TypeEnum printboardLevel2TypeEnum = PrintboardLevel2TypeEnum.fromName(libraryPageVO.getLevel2Type()); - libraryPageVO.setLevel2TypeEnum(new BizJson(printboardLevel2TypeEnum.getValue(), printboardLevel2TypeEnum.name(), BusinessException.getMessageFromResource(printboardLevel2TypeEnum.name()))); - } - if (libraryPageVO.getLevel1Type().equals(LibraryLevel1TypeEnum.DESIGN_ELEMENTS.getRealName())) { - DesignElementsEnum designElementsEnum = DesignElementsEnum.fromName(libraryPageVO.getLevel2Type()); - libraryPageVO.setLevel2TypeEnum(new BizJson(designElementsEnum.getValue(), designElementsEnum.name(), BusinessException.getMessageFromResource(designElementsEnum.name()))); - } - return libraryPageVO; - }else { - i.getAndIncrement(); - return null; - } - }).getRecords().stream() - .filter(Objects::nonNull) - .collect(Collectors.collectingAndThen( - Collectors.toList(), - list -> new Page(page.getCurrent(), page.getSize(), page.getTotal()) { - @Override - public List getRecords() { - return list; - } - @Override - public long getTotal() { - return page.getTotal(); + // 3. 转换 Library 为 QueryLibraryPageVO,并通过 minioUtil 过滤掉不存在的 URL + List convertedList = libraryList.stream() + .map(library -> { + QueryLibraryPageVO libraryPageVO = CopyUtil.copyObject(library, QueryLibraryPageVO.class); + libraryPageVO.setDesignType(DesignTypeEnum.LIBRARY.getRealName()); + libraryPageVO.setMinIOPath(library.getUrl()); + String url = library.getUrl(); + if (minioUtil.doesObjectExist(url)) { + libraryPageVO.setUrl(minioUtil.getPreSignedUrl(url, 24 * 60)); + if (finalMap != null && finalMap.containsKey(library.getId())) { + libraryPageVO.setLibraryModelPoint(finalMap.get(library.getId())); + } + if (libraryPageVO.getLevel1Type().equals(LibraryLevel1TypeEnum.SKETCH_BOARD.getRealName())) { + if (!StringUtils.isEmpty(libraryPageVO.getLevel2Type())) { + Position position = Position.getPosition(libraryPageVO.getLevel2Type()); + libraryPageVO.setLevel2TypeEnum(new BizJson( + position.getValue(), + position.name(), + BusinessException.getMessageFromResource(position.name())) + ); } } - )); - return PageBaseResponse.success(convert); + if (libraryPageVO.getLevel1Type().equals(LibraryLevel1TypeEnum.PRINT_BOARD.getRealName())) { + PrintboardLevel2TypeEnum printboardLevel2TypeEnum = PrintboardLevel2TypeEnum.fromName(libraryPageVO.getLevel2Type()); + libraryPageVO.setLevel2TypeEnum(new BizJson( + printboardLevel2TypeEnum.getValue(), + printboardLevel2TypeEnum.name(), + BusinessException.getMessageFromResource(printboardLevel2TypeEnum.name())) + ); + } + if (libraryPageVO.getLevel1Type().equals(LibraryLevel1TypeEnum.DESIGN_ELEMENTS.getRealName())) { + DesignElementsEnum designElementsEnum = DesignElementsEnum.fromName(libraryPageVO.getLevel2Type()); + libraryPageVO.setLevel2TypeEnum(new BizJson( + designElementsEnum.getValue(), + designElementsEnum.name(), + BusinessException.getMessageFromResource(designElementsEnum.name())) + ); + } + return libraryPageVO; + } else { + // 如果对应的 MinIO 文件不存在,则返回 null,后续过滤掉 + return null; + } + }) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + + // 4. 手动分页 + int total = convertedList.size(); + int currentPage = query.getPage(); // 当前页码(从1开始) + int pageSize = query.getSize(); // 每页大小 + int fromIndex = (currentPage - 1) * pageSize; + int toIndex = Math.min(total, currentPage * pageSize); + List pageList = new ArrayList<>(); + if (fromIndex < total) { + pageList = convertedList.subList(fromIndex, toIndex); + } + + // 5. 构造 IPage 对象(使用 MyBatis-Plus 的 Page 实现) + IPage pageResult = new Page<>(currentPage, pageSize, total); + pageResult.setRecords(pageList); + + // 6. 返回结果 + return PageBaseResponse.success(pageResult); } @Override