Merge remote-tracking branch 'origin/release/3.0' into release/3.0
This commit is contained in:
@@ -440,6 +440,16 @@ public class MinioUtil {
|
|||||||
return getPreSignedUrl(bucketName, String.valueOf(fileName), expiry);
|
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) {
|
public boolean doesObjectExist(String bucketName, String objectName) {
|
||||||
try {
|
try {
|
||||||
minioClient.statObject(
|
minioClient.statObject(
|
||||||
|
|||||||
@@ -40,4 +40,6 @@ public class CollectionElementVO {
|
|||||||
|
|
||||||
private String urlWithWhiteSide;
|
private String urlWithWhiteSide;
|
||||||
|
|
||||||
|
private String originalUrl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,13 +101,21 @@ public class CollectionServiceImpl extends ServiceImpl<CollectionMapper, Collect
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Objects.nonNull(byId)) {
|
if (Objects.nonNull(byId)) {
|
||||||
response.setMoodTemplateName(byId.getName());
|
if (minioUtil.doesObjectExist(byId.getUrl())) {
|
||||||
response.setMoodTemplateUrl(minioUtil.getPreSignedUrl(byId.getUrl(), 24 * 60));
|
response.setMoodTemplateName(byId.getName());
|
||||||
|
response.setMoodTemplateUrl(minioUtil.getPreSignedUrl(byId.getUrl(), 24 * 60));
|
||||||
|
}else {
|
||||||
|
response.setMoodTemplateId(null);
|
||||||
|
if (!StringUtils.isBlank(response.getMoodboardPosition())) {
|
||||||
|
response.setMoodboardPosition(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Map<String, List<CollectionElement>> maps = collectionElements
|
Map<String, List<CollectionElement>> maps = collectionElements
|
||||||
.stream()
|
.stream()
|
||||||
.collect(Collectors.groupingBy(CollectionElement::getLevel1Type));
|
.collect(Collectors.groupingBy(CollectionElement::getLevel1Type));
|
||||||
|
|
||||||
maps.forEach((k, v) -> {
|
maps.forEach((k, v) -> {
|
||||||
CollectionLevel1TypeEnum level1TypeEnum = CollectionLevel1TypeEnum.uploadOf(k);
|
CollectionLevel1TypeEnum level1TypeEnum = CollectionLevel1TypeEnum.uploadOf(k);
|
||||||
if (Objects.isNull(level1TypeEnum)) {
|
if (Objects.isNull(level1TypeEnum)) {
|
||||||
@@ -115,43 +123,70 @@ public class CollectionServiceImpl extends ServiceImpl<CollectionMapper, Collect
|
|||||||
}
|
}
|
||||||
switch (level1TypeEnum) {
|
switch (level1TypeEnum) {
|
||||||
case MOOD_BOARD:
|
case MOOD_BOARD:
|
||||||
response.setMoodBoards(CopyUtil.copyList(v, CollectionElementVO.class, (o, d) -> {
|
List<CollectionElementVO> moodBoards = CopyUtil.copyList(v, CollectionElementVO.class, (o, d) -> {
|
||||||
d.setDesignType(DesignTypeEnum.COLLECTION.getRealName());
|
d.setDesignType(DesignTypeEnum.COLLECTION.getRealName());
|
||||||
d.setUrl(minioUtil.getPreSignedUrl(o.getUrl(), 24 * 60));
|
|
||||||
}));
|
|
||||||
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));
|
|
||||||
}));
|
|
||||||
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();
|
String url = o.getUrl();
|
||||||
if (url.contains(".")) {
|
d.setOriginalUrl(url);
|
||||||
String[] split = url.split("\\.");
|
if (minioUtil.doesObjectExist(url)) {
|
||||||
d.setUrlWithWhiteSide(minioUtil.getPreSignedUrl(split[0] + "-show." + split[1], 24 * 60));
|
d.setUrl(minioUtil.getPreSignedUrl(url, 24 * 60));
|
||||||
}else {
|
|
||||||
d.setUrlWithWhiteSide(minioUtil.getPreSignedUrl(url + "-show", 24 * 60));
|
|
||||||
}
|
}
|
||||||
}));
|
});
|
||||||
|
response.setMoodBoards(moodBoards.stream()
|
||||||
|
.filter(d -> minioUtil.doesObjectExist(d.getOriginalUrl()))
|
||||||
|
.collect(Collectors.toList()));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PRINT_BOARD:
|
||||||
|
List<CollectionElementVO> printBoards = CopyUtil.copyList(v, CollectionElementVO.class, (o, d) -> {
|
||||||
|
d.setIsPin(o.getHasPin());
|
||||||
|
d.setDesignType(DesignTypeEnum.COLLECTION.getRealName());
|
||||||
|
String url = o.getUrl();
|
||||||
|
d.setOriginalUrl(url);
|
||||||
|
if (minioUtil.doesObjectExist(url)) {
|
||||||
|
d.setUrl(minioUtil.getPreSignedUrl(url, 24 * 60));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
response.setPrintBoards(printBoards.stream()
|
||||||
|
.filter(d -> minioUtil.doesObjectExist(d.getOriginalUrl()))
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SKETCH_BOARD:
|
||||||
|
List<CollectionElementVO> sketchBoards = CopyUtil.copyList(v, CollectionElementVO.class, (o, d) -> {
|
||||||
|
d.setIsPin(o.getHasPin());
|
||||||
|
d.setDesignType(DesignTypeEnum.COLLECTION.getRealName());
|
||||||
|
String url = o.getUrl();
|
||||||
|
d.setOriginalUrl(url);
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
response.setSketchBoards(sketchBoards.stream()
|
||||||
|
.filter(d -> minioUtil.doesObjectExist(d.getOriginalUrl()))
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
break;
|
||||||
|
|
||||||
case COLOR_BOARD:
|
case COLOR_BOARD:
|
||||||
response.setColorBoards(resolveColorBoard(v));
|
response.setColorBoards(resolveColorBoard(v));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MARKETING_SKETCH:
|
case MARKETING_SKETCH:
|
||||||
response.setMarketingSketchs(CopyUtil.copyList(v, CollectionElementVO.class, (o, d) -> {
|
response.setMarketingSketchs(CopyUtil.copyList(v, CollectionElementVO.class, (o, d) -> {
|
||||||
d.setDesignType(DesignTypeEnum.COLLECTION.getRealName());
|
d.setDesignType(DesignTypeEnum.COLLECTION.getRealName());
|
||||||
}));
|
}));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (CollectionUtil.isNotEmpty(response.getColorBoards())) {
|
if (CollectionUtil.isNotEmpty(response.getColorBoards())) {
|
||||||
List<CollectionColorVO> collect = response.getColorBoards().stream()
|
List<CollectionColorVO> collect = response.getColorBoards().stream()
|
||||||
.distinct()
|
.distinct()
|
||||||
|
|||||||
@@ -1348,6 +1348,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
|||||||
throw new BusinessException("design.not.found");
|
throw new BusinessException("design.not.found");
|
||||||
}
|
}
|
||||||
List<DesignItemDetail> designItemDetails = designItemDetailService.selectByDesignItemId(designItemId);
|
List<DesignItemDetail> designItemDetails = designItemDetailService.selectByDesignItemId(designItemId);
|
||||||
|
designItemDetails.removeIf(designItemDetail -> !minioUtil.doesObjectExist(designItemDetail.getPath()));
|
||||||
if (CollectionUtil.isEmpty(designItemDetails)) {
|
if (CollectionUtil.isEmpty(designItemDetails)) {
|
||||||
throw new BusinessException("designItemDetails.not.found");
|
throw new BusinessException("designItemDetails.not.found");
|
||||||
}
|
}
|
||||||
@@ -1384,6 +1385,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
|||||||
if (!StringUtil.isNullOrEmpty(o.getUndividedLayer())) d.setUndividedLayer(minioUtil.getPreSignedUrl(o.getUndividedLayer(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
if (!StringUtil.isNullOrEmpty(o.getUndividedLayer())) d.setUndividedLayer(minioUtil.getPreSignedUrl(o.getUndividedLayer(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||||
// 根据designItemDetailId获取印花
|
// 根据designItemDetailId获取印花
|
||||||
List<DesignItemDetailPrint> prints = designItemDetailPrintService.getByDesignItemDetailId(o.getId(), "print");
|
List<DesignItemDetailPrint> prints = designItemDetailPrintService.getByDesignItemDetailId(o.getId(), "print");
|
||||||
|
prints.removeIf(print -> !minioUtil.doesObjectExist(print.getPath()));
|
||||||
// 判断有无印花
|
// 判断有无印花
|
||||||
if (CollectionUtil.isNotEmpty(prints)) {
|
if (CollectionUtil.isNotEmpty(prints)) {
|
||||||
// 有印花
|
// 有印花
|
||||||
@@ -1408,6 +1410,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
|||||||
d.setMinIOPath(o.getPath());
|
d.setMinIOPath(o.getPath());
|
||||||
d.setPrintObject(new DesignPythonItemPrint());
|
d.setPrintObject(new DesignPythonItemPrint());
|
||||||
}));
|
}));
|
||||||
|
response.getOthers().removeIf(o -> !minioUtil.doesObjectExist(o.getMinIOPath()));
|
||||||
return editDesignItemLayer(flag, designPythonOutfit,
|
return editDesignItemLayer(flag, designPythonOutfit,
|
||||||
minioUtil.getPreSignedUrl(designPythonOutfit.getDesignUrl(), 24 * 60),
|
minioUtil.getPreSignedUrl(designPythonOutfit.getDesignUrl(), 24 * 60),
|
||||||
editResponseColor(designItemDetails, response));
|
editResponseColor(designItemDetails, response));
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ import java.time.LocalDate;
|
|||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -182,51 +183,93 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
queryWrapper.orderByDesc("id");
|
queryWrapper.orderByDesc("id");
|
||||||
IPage<Library> page = getBaseMapper().selectPage(
|
// 1. 先查询所有符合条件的 Library 数据
|
||||||
new Page<>(query.getPage(), query.getSize()), queryWrapper);
|
List<Library> libraryList = getBaseMapper().selectList(queryWrapper);
|
||||||
if (CollectionUtils.isEmpty(page.getRecords())) {
|
if (CollectionUtils.isEmpty(libraryList)) {
|
||||||
return PageBaseResponse.success(new Page<>());
|
return PageBaseResponse.success(new Page<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 2. 封装打点内容
|
||||||
Map<Long, LibraryModelPointVO> map = null;
|
Map<Long, LibraryModelPointVO> map = null;
|
||||||
//封装打点内容
|
boolean isExist = libraryList.stream()
|
||||||
Boolean isExist = page.getRecords().stream()
|
|
||||||
.anyMatch(library -> library.getLevel1Type().equals(LibraryLevel1TypeEnum.MODELS.getRealName()));
|
.anyMatch(library -> library.getLevel1Type().equals(LibraryLevel1TypeEnum.MODELS.getRealName()));
|
||||||
if (isExist) {
|
if (isExist) {
|
||||||
List<Long> libarayIds = page.getRecords().stream()
|
List<Long> libraryIds = libraryList.stream()
|
||||||
.filter(library -> library.getLevel1Type().equals(LibraryLevel1TypeEnum.MODELS.getRealName()))
|
.filter(library -> library.getLevel1Type().equals(LibraryLevel1TypeEnum.MODELS.getRealName()))
|
||||||
.map(Library::getId)
|
.map(Library::getId)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
List<LibraryModelPointVO> libraryModelPointVOS = libraryModelPointService.selectByLibraryIds(libarayIds);
|
List<LibraryModelPointVO> libraryModelPointVOS = libraryModelPointService.selectByLibraryIds(libraryIds);
|
||||||
if (!CollectionUtils.isEmpty(libraryModelPointVOS)) {
|
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<Long, LibraryModelPointVO> finalMap = map;
|
Map<Long, LibraryModelPointVO> finalMap = map;
|
||||||
IPage<QueryLibraryPageVO> convert = page.convert((Function<Library, QueryLibraryPageVO>) library -> {
|
|
||||||
QueryLibraryPageVO libraryPageVO = CopyUtil.copyObject(library, QueryLibraryPageVO.class);
|
// 3. 转换 Library 为 QueryLibraryPageVO,并通过 minioUtil 过滤掉不存在的 URL
|
||||||
libraryPageVO.setDesignType(DesignTypeEnum.LIBRARY.getRealName());
|
List<QueryLibraryPageVO> convertedList = libraryList.stream()
|
||||||
libraryPageVO.setMinIOPath(library.getUrl());
|
.map(library -> {
|
||||||
libraryPageVO.setUrl(minioUtil.getPreSignedUrl(library.getUrl(), 24 * 60));
|
QueryLibraryPageVO libraryPageVO = CopyUtil.copyObject(library, QueryLibraryPageVO.class);
|
||||||
if (finalMap != null && finalMap.containsKey(library.getId())) {
|
libraryPageVO.setDesignType(DesignTypeEnum.LIBRARY.getRealName());
|
||||||
libraryPageVO.setLibraryModelPoint(finalMap.get(library.getId()));
|
libraryPageVO.setMinIOPath(library.getUrl());
|
||||||
}
|
String url = library.getUrl();
|
||||||
if (libraryPageVO.getLevel1Type().equals(LibraryLevel1TypeEnum.SKETCH_BOARD.getRealName())) {
|
if (minioUtil.doesObjectExist(url)) {
|
||||||
if (!StringUtils.isEmpty(libraryPageVO.getLevel2Type())) {
|
libraryPageVO.setUrl(minioUtil.getPreSignedUrl(url, 24 * 60));
|
||||||
Position position = Position.getPosition(libraryPageVO.getLevel2Type());
|
if (finalMap != null && finalMap.containsKey(library.getId())) {
|
||||||
libraryPageVO.setLevel2TypeEnum(new BizJson(position.getValue(), position.name(), BusinessException.getMessageFromResource(position.name())));
|
libraryPageVO.setLibraryModelPoint(finalMap.get(library.getId()));
|
||||||
}
|
}
|
||||||
}
|
if (libraryPageVO.getLevel1Type().equals(LibraryLevel1TypeEnum.SKETCH_BOARD.getRealName())) {
|
||||||
if (libraryPageVO.getLevel1Type().equals(LibraryLevel1TypeEnum.PRINT_BOARD.getRealName())) {
|
if (!StringUtils.isEmpty(libraryPageVO.getLevel2Type())) {
|
||||||
PrintboardLevel2TypeEnum printboardLevel2TypeEnum = PrintboardLevel2TypeEnum.fromName(libraryPageVO.getLevel2Type());
|
Position position = Position.getPosition(libraryPageVO.getLevel2Type());
|
||||||
libraryPageVO.setLevel2TypeEnum(new BizJson(printboardLevel2TypeEnum.getValue(), printboardLevel2TypeEnum.name(), BusinessException.getMessageFromResource(printboardLevel2TypeEnum.name())));
|
libraryPageVO.setLevel2TypeEnum(new BizJson(
|
||||||
}
|
position.getValue(),
|
||||||
if (libraryPageVO.getLevel1Type().equals(LibraryLevel1TypeEnum.DESIGN_ELEMENTS.getRealName())) {
|
position.name(),
|
||||||
DesignElementsEnum designElementsEnum = DesignElementsEnum.fromName(libraryPageVO.getLevel2Type());
|
BusinessException.getMessageFromResource(position.name()))
|
||||||
libraryPageVO.setLevel2TypeEnum(new BizJson(designElementsEnum.getValue(), designElementsEnum.name(), BusinessException.getMessageFromResource(designElementsEnum.name())));
|
);
|
||||||
}
|
}
|
||||||
return libraryPageVO;
|
}
|
||||||
});
|
if (libraryPageVO.getLevel1Type().equals(LibraryLevel1TypeEnum.PRINT_BOARD.getRealName())) {
|
||||||
return PageBaseResponse.success(convert);
|
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<QueryLibraryPageVO> pageList = new ArrayList<>();
|
||||||
|
if (fromIndex < total) {
|
||||||
|
pageList = convertedList.subList(fromIndex, toIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. 构造 IPage 对象(使用 MyBatis-Plus 的 Page 实现)
|
||||||
|
IPage<QueryLibraryPageVO> pageResult = new Page<>(currentPage, pageSize, total);
|
||||||
|
pageResult.setRecords(pageList);
|
||||||
|
|
||||||
|
// 6. 返回结果
|
||||||
|
return PageBaseResponse.success(pageResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user