From 6fc22784b8e57fadcc14b274b72c52e8dc6c8212 Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Wed, 12 Mar 2025 21:26:24 +0800 Subject: [PATCH 1/6] =?UTF-8?q?BUGFIX:=20=E9=9A=90=E8=97=8F=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E4=B8=8D=E5=87=BAminio=E7=9A=84=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=95=B0=E6=8D=AE;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ai/da/common/utils/MinioUtil.java | 10 +++++ .../service/impl/CollectionServiceImpl.java | 41 ++++++++++++++----- .../ai/da/service/impl/DesignServiceImpl.java | 2 + .../da/service/impl/LibraryServiceImpl.java | 39 ++++++++++-------- 4 files changed, 65 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/ai/da/common/utils/MinioUtil.java b/src/main/java/com/ai/da/common/utils/MinioUtil.java index d3cdc76f..f622b66f 100644 --- a/src/main/java/com/ai/da/common/utils/MinioUtil.java +++ b/src/main/java/com/ai/da/common/utils/MinioUtil.java @@ -440,6 +440,16 @@ public class MinioUtil { return getPreSignedUrl(bucketName, String.valueOf(fileName), expiry); } + public boolean doesObjectExist(String path) { + if (!path.contains("/")) { + throw new BusinessException("the.path.is.error"); + } + int index = path.indexOf("/"); + String bucketName = path.substring(0, index); + String objectName = path.substring(index + 1); + return doesObjectExist(bucketName, objectName); + } + public boolean doesObjectExist(String bucketName, String objectName) { try { minioClient.statObject( diff --git a/src/main/java/com/ai/da/service/impl/CollectionServiceImpl.java b/src/main/java/com/ai/da/service/impl/CollectionServiceImpl.java index 5f29b7c9..5999d78c 100644 --- a/src/main/java/com/ai/da/service/impl/CollectionServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/CollectionServiceImpl.java @@ -101,8 +101,15 @@ public class CollectionServiceImpl extends ServiceImpl> maps = collectionElements @@ -117,27 +124,41 @@ public class CollectionServiceImpl extends ServiceImpl { d.setDesignType(DesignTypeEnum.COLLECTION.getRealName()); - d.setUrl(minioUtil.getPreSignedUrl(o.getUrl(), 24 * 60)); + String url = o.getUrl(); + if (minioUtil.doesObjectExist(url)) { + d.setUrl(minioUtil.getPreSignedUrl(url, 24 * 60)); + } else { + response.getMoodBoards().remove(d); + } })); break; case PRINT_BOARD: response.setPrintBoards(CopyUtil.copyList(v, CollectionElementVO.class, (o, d) -> { d.setIsPin(o.getHasPin()); d.setDesignType(DesignTypeEnum.COLLECTION.getRealName()); - d.setUrl(minioUtil.getPreSignedUrl(o.getUrl(), 24 * 60)); + String url = o.getUrl(); + if (minioUtil.doesObjectExist(url)) { + d.setUrl(minioUtil.getPreSignedUrl(url, 24 * 60)); + } else { + response.getPrintBoards().remove(d); + } })); break; case SKETCH_BOARD: response.setSketchBoards(CopyUtil.copyList(v, CollectionElementVO.class, (o, d) -> { d.setIsPin(o.getHasPin()); d.setDesignType(DesignTypeEnum.COLLECTION.getRealName()); - d.setUrl(minioUtil.getPreSignedUrl(o.getUrl(), 24 * 60)); String url = o.getUrl(); - if (url.contains(".")) { - String[] split = url.split("\\."); - d.setUrlWithWhiteSide(minioUtil.getPreSignedUrl(split[0] + "-show." + split[1], 24 * 60)); - }else { - d.setUrlWithWhiteSide(minioUtil.getPreSignedUrl(url + "-show", 24 * 60)); + if (minioUtil.doesObjectExist(url)) { + d.setUrl(minioUtil.getPreSignedUrl(url, 24 * 60)); + if (url.contains(".")) { + String[] split = url.split("\\."); + d.setUrlWithWhiteSide(minioUtil.getPreSignedUrl(split[0] + "-show." + split[1], 24 * 60)); + } else { + d.setUrlWithWhiteSide(minioUtil.getPreSignedUrl(url + "-show", 24 * 60)); + } + } else { + response.getSketchBoards().remove(d); } })); break; 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 5e8d4023..4c3460a3 100644 --- a/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java @@ -1346,6 +1346,7 @@ public class DesignServiceImpl extends ServiceImpl impleme throw new BusinessException("design.not.found"); } List designItemDetails = designItemDetailService.selectByDesignItemId(designItemId); + designItemDetails.removeIf(designItemDetail -> !minioUtil.doesObjectExist(designItemDetail.getPath())); if (CollectionUtil.isEmpty(designItemDetails)) { throw new BusinessException("designItemDetails.not.found"); } @@ -1382,6 +1383,7 @@ public class DesignServiceImpl extends ServiceImpl impleme if (!StringUtil.isNullOrEmpty(o.getUndividedLayer())) d.setUndividedLayer(minioUtil.getPreSignedUrl(o.getUndividedLayer(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME)); // 根据designItemDetailId获取印花 List prints = designItemDetailPrintService.getByDesignItemDetailId(o.getId(), "print"); + prints.removeIf(print -> !minioUtil.doesObjectExist(print.getPath())); // 判断有无印花 if (CollectionUtil.isNotEmpty(prints)) { // 有印花 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 2c237cf9..c5ce2b79 100644 --- a/src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java @@ -206,25 +206,30 @@ public class LibraryServiceImpl extends ServiceImpl impl QueryLibraryPageVO libraryPageVO = CopyUtil.copyObject(library, QueryLibraryPageVO.class); libraryPageVO.setDesignType(DesignTypeEnum.LIBRARY.getRealName()); libraryPageVO.setMinIOPath(library.getUrl()); - 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()))); + 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 { + return null; } - 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; }); return PageBaseResponse.success(convert); } From 7839ac33228ee48606b2f4ef727561678d70e3de Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Wed, 12 Mar 2025 21:54:23 +0800 Subject: [PATCH 2/6] =?UTF-8?q?BUGFIX:=20=E9=9A=90=E8=97=8F=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E4=B8=8D=E5=87=BAminio=E7=9A=84=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=95=B0=E6=8D=AE;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../da/service/impl/LibraryServiceImpl.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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 c5ce2b79..b57096d8 100644 --- a/src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java @@ -51,6 +51,7 @@ import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; /** @@ -202,6 +203,7 @@ public class LibraryServiceImpl extends ServiceImpl impl } } 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()); @@ -228,9 +230,25 @@ public class LibraryServiceImpl extends ServiceImpl impl } 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 list.size(); + } + } + )); return PageBaseResponse.success(convert); } From 484a8d1d93aab88316f3006260207aa027d4abce Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Wed, 12 Mar 2025 22:00:07 +0800 Subject: [PATCH 3/6] =?UTF-8?q?BUGFIX:=20=E9=9A=90=E8=97=8F=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E4=B8=8D=E5=87=BAminio=E7=9A=84=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=95=B0=E6=8D=AE;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b57096d8..ebc9893a 100644 --- a/src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java @@ -245,7 +245,7 @@ public class LibraryServiceImpl extends ServiceImpl impl @Override public long getTotal() { - return list.size(); + return page.getTotal(); } } )); From d3ee0e5f4f0c5288b4bedd37e06a88882f381a82 Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Wed, 12 Mar 2025 22:06:39 +0800 Subject: [PATCH 4/6] =?UTF-8?q?BUGFIX:=20=E9=9A=90=E8=97=8F=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E4=B8=8D=E5=87=BAminio=E7=9A=84=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=95=B0=E6=8D=AE;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/CollectionServiceImpl.java | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/ai/da/service/impl/CollectionServiceImpl.java b/src/main/java/com/ai/da/service/impl/CollectionServiceImpl.java index 5999d78c..bf598dcd 100644 --- a/src/main/java/com/ai/da/service/impl/CollectionServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/CollectionServiceImpl.java @@ -115,6 +115,7 @@ public class CollectionServiceImpl extends ServiceImpl> maps = collectionElements .stream() .collect(Collectors.groupingBy(CollectionElement::getLevel1Type)); + maps.forEach((k, v) -> { CollectionLevel1TypeEnum level1TypeEnum = CollectionLevel1TypeEnum.uploadOf(k); if (Objects.isNull(level1TypeEnum)) { @@ -122,30 +123,34 @@ public class CollectionServiceImpl extends ServiceImpl { + List moodBoards = CopyUtil.copyList(v, CollectionElementVO.class, (o, d) -> { d.setDesignType(DesignTypeEnum.COLLECTION.getRealName()); String url = o.getUrl(); if (minioUtil.doesObjectExist(url)) { d.setUrl(minioUtil.getPreSignedUrl(url, 24 * 60)); - } else { - response.getMoodBoards().remove(d); } - })); + }); + response.setMoodBoards(moodBoards.stream() + .filter(d -> minioUtil.doesObjectExist(d.getUrl())) + .collect(Collectors.toList())); break; + case PRINT_BOARD: - response.setPrintBoards(CopyUtil.copyList(v, CollectionElementVO.class, (o, d) -> { + List printBoards = CopyUtil.copyList(v, CollectionElementVO.class, (o, d) -> { d.setIsPin(o.getHasPin()); d.setDesignType(DesignTypeEnum.COLLECTION.getRealName()); String url = o.getUrl(); if (minioUtil.doesObjectExist(url)) { d.setUrl(minioUtil.getPreSignedUrl(url, 24 * 60)); - } else { - response.getPrintBoards().remove(d); } - })); + }); + response.setPrintBoards(printBoards.stream() + .filter(d -> minioUtil.doesObjectExist(d.getUrl())) + .collect(Collectors.toList())); break; + case SKETCH_BOARD: - response.setSketchBoards(CopyUtil.copyList(v, CollectionElementVO.class, (o, d) -> { + List sketchBoards = CopyUtil.copyList(v, CollectionElementVO.class, (o, d) -> { d.setIsPin(o.getHasPin()); d.setDesignType(DesignTypeEnum.COLLECTION.getRealName()); String url = o.getUrl(); @@ -157,22 +162,28 @@ public class CollectionServiceImpl extends ServiceImpl minioUtil.doesObjectExist(d.getUrl())) + .collect(Collectors.toList())); break; + case COLOR_BOARD: response.setColorBoards(resolveColorBoard(v)); break; + case MARKETING_SKETCH: response.setMarketingSketchs(CopyUtil.copyList(v, CollectionElementVO.class, (o, d) -> { d.setDesignType(DesignTypeEnum.COLLECTION.getRealName()); })); break; + default: + break; } }); + if (CollectionUtil.isNotEmpty(response.getColorBoards())) { List collect = response.getColorBoards().stream() .distinct() 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 5/6] =?UTF-8?q?BUGFIX:=20=E9=9A=90=E8=97=8F=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E4=B8=8D=E5=87=BAminio=E7=9A=84=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=95=B0=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 From 7e55b1f85e7578ed360b5426425001b80a34f9b1 Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Thu, 13 Mar 2025 17:53:35 +0800 Subject: [PATCH 6/6] =?UTF-8?q?BUGFIX:=20=E9=9A=90=E8=97=8F=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E4=B8=8D=E5=87=BAminio=E7=9A=84=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=95=B0=E6=8D=AE;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ai/da/model/vo/CollectionElementVO.java | 2 ++ .../com/ai/da/service/impl/CollectionServiceImpl.java | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/ai/da/model/vo/CollectionElementVO.java b/src/main/java/com/ai/da/model/vo/CollectionElementVO.java index ff4e5b88..53a1888a 100644 --- a/src/main/java/com/ai/da/model/vo/CollectionElementVO.java +++ b/src/main/java/com/ai/da/model/vo/CollectionElementVO.java @@ -40,4 +40,6 @@ public class CollectionElementVO { private String urlWithWhiteSide; + private String originalUrl; + } diff --git a/src/main/java/com/ai/da/service/impl/CollectionServiceImpl.java b/src/main/java/com/ai/da/service/impl/CollectionServiceImpl.java index bf598dcd..a90ba255 100644 --- a/src/main/java/com/ai/da/service/impl/CollectionServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/CollectionServiceImpl.java @@ -126,12 +126,13 @@ public class CollectionServiceImpl extends ServiceImpl moodBoards = CopyUtil.copyList(v, CollectionElementVO.class, (o, d) -> { d.setDesignType(DesignTypeEnum.COLLECTION.getRealName()); String url = o.getUrl(); + d.setOriginalUrl(url); if (minioUtil.doesObjectExist(url)) { d.setUrl(minioUtil.getPreSignedUrl(url, 24 * 60)); } }); response.setMoodBoards(moodBoards.stream() - .filter(d -> minioUtil.doesObjectExist(d.getUrl())) + .filter(d -> minioUtil.doesObjectExist(d.getOriginalUrl())) .collect(Collectors.toList())); break; @@ -140,12 +141,13 @@ public class CollectionServiceImpl extends ServiceImpl minioUtil.doesObjectExist(d.getUrl())) + .filter(d -> minioUtil.doesObjectExist(d.getOriginalUrl())) .collect(Collectors.toList())); break; @@ -154,6 +156,7 @@ public class CollectionServiceImpl extends ServiceImpl minioUtil.doesObjectExist(d.getUrl())) + .filter(d -> minioUtil.doesObjectExist(d.getOriginalUrl())) .collect(Collectors.toList())); break;