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); }