|
|
@@ -5,21 +5,21 @@ import cn.reghao.jutil.jdk.db.Page;
|
|
|
import cn.reghao.jutil.jdk.db.PageList;
|
|
|
import cn.reghao.jutil.jdk.result.Result;
|
|
|
import cn.reghao.jutil.web.WebResult;
|
|
|
-import cn.reghao.jutil.tool.id.SnowFlake;
|
|
|
import cn.reghao.oss.sdk.model.dto.media.ImageInfo;
|
|
|
import cn.reghao.tnb.account.api.iface.AccountQuery;
|
|
|
import cn.reghao.tnb.common.auth.UserContext;
|
|
|
import cn.reghao.tnb.content.api.constant.PostScope;
|
|
|
+import cn.reghao.tnb.content.api.constant.PostType;
|
|
|
import cn.reghao.tnb.content.api.dto.ImagePublishSbt;
|
|
|
-import cn.reghao.tnb.content.app.data.db.repository.ImageRepository;
|
|
|
import cn.reghao.tnb.content.app.data.model.dto.AlbumImageData;
|
|
|
-import cn.reghao.tnb.content.app.data.model.po.ImagePost;
|
|
|
-import cn.reghao.tnb.content.app.data.model.po.ImageFile;
|
|
|
import cn.reghao.tnb.content.app.data.model.vo.AlbumCard;
|
|
|
import cn.reghao.tnb.content.app.data.model.vo.ImageAlbumCard;
|
|
|
-import cn.reghao.tnb.content.app.data.model.vo.ImageAlbumQuery;
|
|
|
import cn.reghao.tnb.content.app.data.model.vo.ImageData;
|
|
|
+import cn.reghao.tnb.content.app.util.IdService;
|
|
|
import cn.reghao.tnb.content.app.vod.db.repository.AlbumRepository;
|
|
|
+import cn.reghao.tnb.content.app.vod.model.po.PostAlbum;
|
|
|
+import cn.reghao.tnb.content.app.vod.model.po.PostItem;
|
|
|
+import cn.reghao.tnb.content.app.vod.model.query.AlbumQuery;
|
|
|
import cn.reghao.tnb.content.app.vod.service.ContentPermission;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
@@ -44,15 +44,13 @@ public class ImagePostService {
|
|
|
private OssService ossService;
|
|
|
|
|
|
private final int pageSize = 12;
|
|
|
- private final SnowFlake idGenerator;
|
|
|
- private final ImageRepository imageRepository;
|
|
|
private final AlbumRepository albumRepository;
|
|
|
private final ContentPermission contentPermission;
|
|
|
+ private final IdService idService;
|
|
|
|
|
|
- public ImagePostService(ImageRepository imageRepository, AlbumRepository albumRepository,
|
|
|
- ContentPermission contentPermission) {
|
|
|
- this.idGenerator = new SnowFlake(1L, 1L);
|
|
|
- this.imageRepository = imageRepository;
|
|
|
+ public ImagePostService(AlbumRepository albumRepository, ContentPermission contentPermission,
|
|
|
+ IdService idService) {
|
|
|
+ this.idService = idService;
|
|
|
this.albumRepository = albumRepository;
|
|
|
this.contentPermission = contentPermission;
|
|
|
}
|
|
|
@@ -60,21 +58,28 @@ public class ImagePostService {
|
|
|
public Result create(ImagePublishSbt imagePublishSbt) {
|
|
|
String albumName = imagePublishSbt.getAlbumName();
|
|
|
int scope = imagePublishSbt.getScope();
|
|
|
- long albumId = idGenerator.nextId();
|
|
|
- ImagePost imagePost = new ImagePost(albumId, albumName, scope);
|
|
|
- imageRepository.saveImageAlbum(imagePost);
|
|
|
+ long albumId = idService.getLongId();
|
|
|
+ PostAlbum postAlbum = new PostAlbum(albumId, albumName, scope);
|
|
|
+ albumRepository.savePostAlbum(postAlbum);
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
public Result add(AlbumImageData albumImageData) {
|
|
|
+ long loginUser = UserContext.getUserId();
|
|
|
long albumId = albumImageData.getAlbumId();
|
|
|
- ImagePost imagePost = imageRepository.getImageAlbum(albumId);
|
|
|
- if (imagePost == null) {
|
|
|
+ AlbumQuery albumQuery = new AlbumQuery.Builder()
|
|
|
+ .createBy(loginUser)
|
|
|
+ .albumId(albumId)
|
|
|
+ .build();
|
|
|
+ Page page = new Page(1, 1);
|
|
|
+ List<PostAlbum> list = albumRepository.getPostAlbums(page, albumQuery);
|
|
|
+ if (list.isEmpty()) {
|
|
|
String errMsg = String.format("相册 %s 不存在", albumId);
|
|
|
return Result.fail(errMsg);
|
|
|
}
|
|
|
+ PostAlbum postAlbum = list.get(0);
|
|
|
|
|
|
- int total = imageRepository.countImageFiles(albumId);
|
|
|
+ int total = albumRepository.countPostItem(albumId);
|
|
|
int imageCount = total + 1;
|
|
|
if (imageCount > 1000) {
|
|
|
String errMsg = "一个相册最多可包含 1000 张图片";
|
|
|
@@ -82,9 +87,9 @@ public class ImagePostService {
|
|
|
}
|
|
|
|
|
|
String imageFileId = albumImageData.getImageFileId();
|
|
|
- int channelId = imagePost.getChannelId();
|
|
|
+ int channelCode = postAlbum.getChannelCode();
|
|
|
try {
|
|
|
- ImageInfo imageInfo = ossService.getImageInfo(channelId, imageFileId);
|
|
|
+ ImageInfo imageInfo = ossService.getImageInfo(channelCode, imageFileId);
|
|
|
/*Map<String, ConvertedImageInfo> map = imageFileIds.stream()
|
|
|
.map(imageFileId -> ossService.getWebpInfo(channelId, imageFileId))
|
|
|
.filter(Objects::nonNull)
|
|
|
@@ -93,19 +98,18 @@ public class ImagePostService {
|
|
|
String errMsg = String.format("相册 %s 中的图片转换为 webp 失败", albumId);
|
|
|
return Result.fail(errMsg);
|
|
|
}*/
|
|
|
-
|
|
|
- ImageFile imageFile = new ImageFile(albumId, channelId, imageInfo);
|
|
|
- Integer channelScope = ossService.getChannelScope(channelId);
|
|
|
+ PostItem postItem = new PostItem(albumId, channelCode, imageInfo);
|
|
|
+ Integer channelScope = ossService.getChannelScope(channelCode);
|
|
|
if (channelScope == null ) {
|
|
|
- String errMsg = String.format("channelId %s 的 scope 在 oss 中不存在", channelId);
|
|
|
+ String errMsg = String.format("channelCode %s 的 scope 在 oss 中不存在", channelCode);
|
|
|
return Result.fail(errMsg);
|
|
|
}
|
|
|
|
|
|
- int scope = imagePost.getScope();
|
|
|
+ int scope = postAlbum.getScope();
|
|
|
if (channelScope != scope) {
|
|
|
- ossService.setObjectScope(channelId, imageFileId, scope);
|
|
|
+ ossService.setObjectScope(channelCode, imageFileId, scope);
|
|
|
}
|
|
|
- imageRepository.addAlbumImage(albumId, imageCount, imageFile);
|
|
|
+ albumRepository.addAlbumImage(albumId, imageCount, postItem);
|
|
|
return Result.success();
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
@@ -126,29 +130,30 @@ public class ImagePostService {
|
|
|
scopes.add(PostScope.PRIVATE.getCode());
|
|
|
}
|
|
|
|
|
|
- ImageAlbumQuery imageAlbumQuery = new ImageAlbumQuery.Builder()
|
|
|
- .userId(userId)
|
|
|
+ AlbumQuery albumQuery = new AlbumQuery.Builder()
|
|
|
+ .createBy(userId)
|
|
|
+ .postType(PostType.Image.getCode())
|
|
|
.scope(scopes)
|
|
|
.build();
|
|
|
- int total = imageRepository.countByCriteria(imageAlbumQuery);
|
|
|
+ int total = albumRepository.countPostAlbum(albumQuery);
|
|
|
Page page1 = new Page(page, pageSize);
|
|
|
- List<ImagePost> list = imageRepository.findImageAlbumByPage(page1, imageAlbumQuery);
|
|
|
- List<AlbumCard> albumCards = list.stream().map(imagePost -> {
|
|
|
+ List<PostAlbum> list = albumRepository.getPostAlbums(page1, albumQuery);
|
|
|
+ List<AlbumCard> albumCards = list.stream().map(postAlbum -> {
|
|
|
try {
|
|
|
- int scope = imagePost.getScope();
|
|
|
+ int scope = postAlbum.getScope();
|
|
|
if (scope != PostScope.PUBLIC.getCode()) {
|
|
|
- int channelCode = imagePost.getChannelId();
|
|
|
+ int channelCode = postAlbum.getChannelCode();
|
|
|
if (channelCode != 501) {
|
|
|
- String coverUrl = imagePost.getCoverUrl();
|
|
|
+ String coverUrl = postAlbum.getCoverUrl();
|
|
|
if (!coverUrl.isBlank()) {
|
|
|
- ImageFile imageFile = imageRepository.getByUrl(coverUrl);
|
|
|
- String objectId = imageFile.getObjectId();
|
|
|
- imagePost.setCoverUrl(ossService.getSignedUrl(channelCode, objectId));
|
|
|
+ PostItem postItem = albumRepository.getByUrl(coverUrl);
|
|
|
+ String objectId = postItem.getObjectId();
|
|
|
+ postAlbum.setCoverUrl(ossService.getSignedUrl(channelCode, objectId));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- String userIdStr = accountQuery.getUserIdStr(imagePost.getUserId());
|
|
|
- return new AlbumCard(imagePost, userIdStr);
|
|
|
+ String userIdStr = accountQuery.getUserIdStr(postAlbum.getCreateBy());
|
|
|
+ return new AlbumCard(postAlbum, userIdStr);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
@@ -159,14 +164,19 @@ public class ImagePostService {
|
|
|
}
|
|
|
|
|
|
public String getImageAlbum(long albumId, int pageNumber) {
|
|
|
- ImagePost imagePost = imageRepository.getImageAlbum(albumId);
|
|
|
- if (imagePost == null) {
|
|
|
+ AlbumQuery albumQuery = new AlbumQuery.Builder()
|
|
|
+ .albumId(albumId)
|
|
|
+ .build();
|
|
|
+ Page page = new Page(1, 1);
|
|
|
+ List<PostAlbum> postAlbumList = albumRepository.getPostAlbums(page, albumQuery);
|
|
|
+ if (postAlbumList.isEmpty()) {
|
|
|
return WebResult.notFound();
|
|
|
}
|
|
|
+ PostAlbum postAlbum = postAlbumList.get(0);
|
|
|
|
|
|
- long owner = imagePost.getUserId();
|
|
|
- int scope = imagePost.getScope();
|
|
|
long loginUser = UserContext.getUserId();
|
|
|
+ long owner = postAlbum.getCreateBy();
|
|
|
+ int scope = postAlbum.getScope();
|
|
|
if (scope == PostScope.PRIVATE.getCode() && owner != loginUser) {
|
|
|
return WebResult.notFound();
|
|
|
}
|
|
|
@@ -176,12 +186,11 @@ public class ImagePostService {
|
|
|
return WebResult.failWithMsg("permission denied");
|
|
|
}
|
|
|
|
|
|
- int total = imageRepository.countImageFiles(albumId);
|
|
|
+ int total = albumRepository.countImageFiles(albumId);
|
|
|
Page page1 = new Page(pageNumber, pageSize);
|
|
|
- List<String> imageFileIds = imageRepository.getImageFileIds(albumId, page1);
|
|
|
- List<ImageFile> imageFiles = imageRepository.getImageFiles(imageFileIds);
|
|
|
- Map<String, List<ImageFile>> map = imageFiles.stream()
|
|
|
- .collect(Collectors.groupingBy(ImageFile::getImageFileId));
|
|
|
+ List<PostItem> imageFiles = albumRepository.getImageFiles(albumId, page1);
|
|
|
+ Map<String, List<PostItem>> map = imageFiles.stream()
|
|
|
+ .collect(Collectors.groupingBy(PostItem::getObjectId));
|
|
|
|
|
|
List<ImageData> list = new ArrayList<>();
|
|
|
map.forEach((imageFileId, list1) -> {
|
|
|
@@ -205,13 +214,13 @@ public class ImagePostService {
|
|
|
});
|
|
|
|
|
|
PageList<ImageData> pageList = PageList.pageList(pageNumber, pageSize, total, list);
|
|
|
- String userIdStr = accountQuery.getUserIdStr(imagePost.getUserId());
|
|
|
- ImageAlbumCard imageAlbumCard = new ImageAlbumCard(imagePost, userIdStr);
|
|
|
+ String userIdStr = accountQuery.getUserIdStr(postAlbum.getCreateBy());
|
|
|
+ ImageAlbumCard imageAlbumCard = new ImageAlbumCard(postAlbum, userIdStr);
|
|
|
imageAlbumCard.setImages(pageList);
|
|
|
if (scope != PostScope.PUBLIC.getCode()) {
|
|
|
imageAlbumCard.getImages().getList().forEach(imageData -> {
|
|
|
String imageFileId = imageData.getImageFileId();
|
|
|
- int channelCode = imagePost.getChannelId();
|
|
|
+ int channelCode = postAlbum.getChannelCode();
|
|
|
if (channelCode != 501) {
|
|
|
try {
|
|
|
String signedUrl = ossService.getSignedUrl(channelCode, imageFileId);
|