提交 d3aecb57 编写于 作者: 街头小贩's avatar 街头小贩

重构AlbumPicture的thumb

上级 732e6b5c
......@@ -83,21 +83,7 @@ public class AlbumPictureServiceImpl implements AlbumPictureService {
return Collections.emptyMap();
}
List<Long> albumIds = albumIdSet.stream().filter(albumId -> albumId > 0).collect(Collectors.toList());
//上传图片的路径转换
UploadImagePathConvert uipc = new UploadImagePathConvert(imageIO.getImageBucketDomain(), imageIO.getUploadImageDirectName());
Consumer<AlbumPicture> action = (ap) -> {
try {
String imageThumbPath = uipc.decode(ap.getLink(), ImageDirectoryEnum.DEFAT, scale).map(URL::toString).orElse(defaultPicture);
ap.setThumb(imageThumbPath);
String imageOriginalPath = uipc.decode(ap.getLink(), ImageDirectoryEnum.DEFAT, "auto").map(URL::toString).orElse(defaultPicture);
ap.setLink(imageOriginalPath);
} catch (MalformedURLException ex) {
if (logger.isDebugEnabled()) {
logger.debug(String.format("%s is malformed fail", ap.getLink()), ex);
}
}
};
return albumPictureDao.findAllByAlbum(albumIds).peek(action).collect(Collectors.groupingBy(AlbumPicture::getAlbumId, Collectors.toCollection(()->new BoundedTreeSet<>(showSize))));//限制数量
return thumbMapper(albumPictureDao.findAllByAlbum(albumIds), imageIO, scale, defaultPicture).collect(Collectors.groupingBy(AlbumPicture::getAlbumId, Collectors.toCollection(()->new BoundedTreeSet<>(showSize))));//限制数量
}
@Override
......@@ -106,22 +92,37 @@ public class AlbumPictureServiceImpl implements AlbumPictureService {
return Stream.empty();
}
List<Long> albumIds = albumIdSet.stream().filter(albumId -> albumId > 0).collect(Collectors.toList());
return thumbMapper(albumPictureDao.findAllByAlbum(albumIds), imageIO, scale, defaultPicture);
}
private static Stream<AlbumPicture> thumbMapper(Stream<AlbumPicture> aps, ImageIOMeta imageIO, String thumbScale, String defaultPic){
//上传图片的路径转换
final UploadImagePathConvert uipc = new UploadImagePathConvert(imageIO.getImageBucketDomain(), imageIO.getUploadImageDirectName());
Consumer<AlbumPicture> action = ap->{
Function<AlbumPicture,AlbumPicture> decodeMapper = (ap)->{
String tmpThumb=null, tmpLink=null;
try {
String imagePath = uipc
.decode(ap.getLink(), ImageDirectoryEnum.DEFAT, scale)
.map(URL::toString)
.orElse(defaultPicture); //"/static/img/140x140.png"
ap.setLink(imagePath);
}catch (MalformedURLException ex) {
tmpLink = uipc.decode(ap.getLink(), ImageDirectoryEnum.DEFAT, "auto").map(URL::toString).orElse(defaultPic); //"/static/img/140x140.png"
tmpThumb = uipc.decode(ap.getLink(), ImageDirectoryEnum.DEFAT, thumbScale).map(URL::toString).orElse(defaultPic);
} catch (MalformedURLException ex) {
if (logger.isDebugEnabled()) {
logger.debug(String.format("%s is malformed fail", ap.getLink()), ex);
}
}
if(tmpLink!=null){
AlbumPicture safeIns = new AlbumPicture();
safeIns.setLink(tmpLink);
safeIns.setThumb(Commons.optional(tmpThumb, defaultPic));
safeIns.setCover(ap.isCover());
safeIns.setStatus(ap.isStatus());
safeIns.setCaption(ap.getCaption());
safeIns.setId(ap.getId());
safeIns.setRanking(ap.getRanking());
safeIns.setAlbum(ap.getAlbum());
return safeIns;
}
return ap;
};
return albumPictureDao.findAllByAlbum(albumIds).peek(action);
return aps.map(decodeMapper);
}
@Override
......@@ -146,4 +147,4 @@ public class AlbumPictureServiceImpl implements AlbumPictureService {
}
return albumPictureDao.delete(idSet);
}
}
\ No newline at end of file
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册