فهرست منبع

content-service 中使用 PostAlbum 和 PostItem 代替 ImagePost 和 ImageFile

reghao 6 ماه پیش
والد
کامیت
18a5a8ba01
22فایلهای تغییر یافته به همراه212 افزوده شده و 475 حذف شده
  1. 0 1
      content/content-service/src/main/java/cn/reghao/tnb/content/app/data/controller/ImagePostController.java
  2. 0 21
      content/content-service/src/main/java/cn/reghao/tnb/content/app/data/db/mapper/ImageFileMapper.java
  3. 0 25
      content/content-service/src/main/java/cn/reghao/tnb/content/app/data/db/mapper/ImagePostMapper.java
  4. 0 78
      content/content-service/src/main/java/cn/reghao/tnb/content/app/data/db/repository/ImageRepository.java
  5. 0 41
      content/content-service/src/main/java/cn/reghao/tnb/content/app/data/model/po/ImageFile.java
  6. 0 38
      content/content-service/src/main/java/cn/reghao/tnb/content/app/data/model/po/ImagePost.java
  7. 10 9
      content/content-service/src/main/java/cn/reghao/tnb/content/app/data/model/vo/AlbumCard.java
  8. 4 4
      content/content-service/src/main/java/cn/reghao/tnb/content/app/data/model/vo/ImageAlbumCard.java
  9. 0 47
      content/content-service/src/main/java/cn/reghao/tnb/content/app/data/model/vo/ImageAlbumQuery.java
  10. 60 51
      content/content-service/src/main/java/cn/reghao/tnb/content/app/data/service/ImagePostService.java
  11. 1 0
      content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/db/mapper/PostAlbumMapper.java
  12. 1 0
      content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/db/mapper/PostItemMapper.java
  13. 19 0
      content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/db/repository/AlbumRepository.java
  14. 15 0
      content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/model/po/PostAlbum.java
  15. 29 1
      content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/model/po/PostItem.java
  16. 10 15
      content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/service/AlbumService.java
  17. 15 23
      content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/service/ContentService.java
  18. 0 45
      content/content-service/src/main/resources/mapper/data/ImageFileMapper.xml
  19. 0 69
      content/content-service/src/main/resources/mapper/data/ImagePostMapper.xml
  20. 11 2
      content/content-service/src/main/resources/mapper/vod/PostAlbumMapper.xml
  21. 10 5
      content/content-service/src/main/resources/mapper/vod/PostItemMapper.xml
  22. 27 0
      content/content-service/src/test/java/cn/reghao/tnb/content/app/vod/service/PostAlbumTest.java

+ 0 - 1
content/content-service/src/main/java/cn/reghao/tnb/content/app/data/controller/ImagePostController.java

@@ -7,7 +7,6 @@ import cn.reghao.tnb.common.auth.AuthUser;
 import cn.reghao.tnb.common.auth.UserContext;
 import cn.reghao.tnb.content.api.dto.ImagePublishSbt;
 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.vo.AlbumCard;
 import cn.reghao.tnb.content.app.data.service.ImagePostService;
 import io.swagger.v3.oas.annotations.tags.Tag;

+ 0 - 21
content/content-service/src/main/java/cn/reghao/tnb/content/app/data/db/mapper/ImageFileMapper.java

@@ -1,21 +0,0 @@
-package cn.reghao.tnb.content.app.data.db.mapper;
-
-import cn.reghao.jutil.jdk.db.BaseMapper;
-import cn.reghao.jutil.jdk.db.Page;
-import cn.reghao.tnb.content.app.data.model.po.ImageFile;
-import org.apache.ibatis.annotations.Mapper;
-import org.apache.ibatis.annotations.Param;
-
-import java.util.List;
-
-/**
- * @author reghao
- * @date 2021-12-08 14:41:35
- */
-@Mapper
-public interface ImageFileMapper extends BaseMapper<ImageFile> {
-    List<Integer> countByAlbumId(long albumId);
-    ImageFile findByUrl(String url);
-    List<String> findImageFileIdsByPage(@Param("page") Page page, @Param("albumId") long albumId);
-    List<ImageFile> findByImageFileIds(List<String> list);
-}

+ 0 - 25
content/content-service/src/main/java/cn/reghao/tnb/content/app/data/db/mapper/ImagePostMapper.java

@@ -1,25 +0,0 @@
-package cn.reghao.tnb.content.app.data.db.mapper;
-
-import cn.reghao.jutil.jdk.db.BaseMapper;
-import cn.reghao.jutil.jdk.db.Page;
-import cn.reghao.tnb.content.app.data.model.po.ImagePost;
-import cn.reghao.tnb.content.app.data.model.vo.ImageAlbumCard;
-import cn.reghao.tnb.content.app.data.model.vo.ImageAlbumQuery;
-import org.apache.ibatis.annotations.Mapper;
-import org.apache.ibatis.annotations.Param;
-
-import java.util.List;
-
-/**
- * @author reghao
- * @date 2023-08-19 02:33:11
- */
-@Mapper
-public interface ImagePostMapper extends BaseMapper<ImagePost> {
-    void updateAlbumCount(@Param("albumId") long albumId, @Param("total") long total);
-
-    int countByCriteria(ImageAlbumQuery imageAlbumQuery);
-    List<ImagePost> findImageAlbumByPage(@Param("page") Page page, @Param("imageAlbumQuery") ImageAlbumQuery imageAlbumQuery);
-
-    ImageAlbumCard findImageAlbumCardByAlbumId(long albumId);
-}

+ 0 - 78
content/content-service/src/main/java/cn/reghao/tnb/content/app/data/db/repository/ImageRepository.java

@@ -1,78 +0,0 @@
-package cn.reghao.tnb.content.app.data.db.repository;
-
-import cn.reghao.jutil.jdk.db.Page;
-import cn.reghao.tnb.content.app.data.db.mapper.ImagePostMapper;
-import cn.reghao.tnb.content.app.data.db.mapper.ImageFileMapper;
-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.ImageAlbumQuery;
-import org.springframework.stereotype.Repository;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.util.Collections;
-import java.util.List;
-
-/**
- * @author reghao
- * @date 2023-08-28 15:00:43
- */
-@Repository
-public class ImageRepository {
-    private final ImagePostMapper imagePostMapper;
-    private final ImageFileMapper imageFileMapper;
-
-    public ImageRepository(ImagePostMapper imagePostMapper, ImageFileMapper imageFileMapper) {
-        this.imagePostMapper = imagePostMapper;
-        this.imageFileMapper = imageFileMapper;
-    }
-
-    public void saveImageAlbum(ImagePost imagePost) {
-        imagePostMapper.save(imagePost);
-    }
-
-    @Transactional(rollbackFor = Exception.class)
-    public void addAlbumImage(long albumId, int imageCount, ImageFile imageFile) {
-        imagePostMapper.updateAlbumCount(albumId, imageCount);
-        imageFileMapper.save(imageFile);
-    }
-
-    public int countByCriteria(ImageAlbumQuery imageAlbumQuery) {
-        int total = imagePostMapper.countByCriteria(imageAlbumQuery);
-        return total;
-    }
-
-    public List<ImagePost> findImageAlbumByPage(Page page, ImageAlbumQuery imageAlbumQuery) {
-        List<ImagePost> list = imagePostMapper.findImageAlbumByPage(page, imageAlbumQuery);
-        return list;
-    }
-
-    public int countImageFiles(long albumId) {
-        return imageFileMapper.countByAlbumId(albumId).size();
-    }
-
-    public List<String> getImageFileIds(long albumId, Page page) {
-        return imageFileMapper.findImageFileIdsByPage(page, albumId);
-    }
-
-    public List<ImageFile> getImageFiles(List<String> imageFileIds) {
-        if (imageFileIds.isEmpty()) {
-            return Collections.emptyList();
-        }
-
-        return imageFileMapper.findByImageFileIds(imageFileIds);
-    }
-
-    public ImageFile getByUrl(String url) {
-        return imageFileMapper.findByUrl(url);
-    }
-
-    public ImagePost getImageAlbum(long albumId) {
-        ImageAlbumQuery imageAlbumQuery = new ImageAlbumQuery.Builder()
-                .albumId(albumId)
-                .build();
-
-        Page page = new Page(1, 1);
-        List<ImagePost> list = imagePostMapper.findImageAlbumByPage(page, imageAlbumQuery);
-        return list.isEmpty() ? null : list.get(0);
-    }
-}

+ 0 - 41
content/content-service/src/main/java/cn/reghao/tnb/content/app/data/model/po/ImageFile.java

@@ -1,41 +0,0 @@
-package cn.reghao.tnb.content.app.data.model.po;
-
-import cn.reghao.jutil.jdk.db.BaseObject;
-import cn.reghao.oss.sdk.model.dto.media.ImageInfo;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-import lombok.NoArgsConstructor;
-
-/**
- * 图像文件
- *
- * @author reghao
- * @date 2021-12-08 13:52:01
- */
-@NoArgsConstructor
-@EqualsAndHashCode(callSuper = true)
-@Data
-public class ImageFile extends BaseObject<Integer> {
-    private Long albumId;
-    private Integer channelCode;
-    // 原始文件的 objectId
-    private String imageFileId;
-    private String objectId;
-    private String format;
-    private String url;
-    private Integer width;
-    private Integer height;
-    private Boolean horizontal;
-
-    public ImageFile(Long albumId, int channelCode, ImageInfo imageInfo) {
-        this.albumId = albumId;
-        this.channelCode = channelCode;
-        this.imageFileId = imageInfo.getImageFileId();
-        this.objectId = imageInfo.getObjectId();
-        this.format = imageInfo.getFormat();
-        this.url = imageInfo.getUrl();
-        this.width = imageInfo.getWidth();
-        this.height = imageInfo.getHeight();
-        this.horizontal = imageInfo.getWidth() > imageInfo.getHeight();
-    }
-}

+ 0 - 38
content/content-service/src/main/java/cn/reghao/tnb/content/app/data/model/po/ImagePost.java

@@ -1,38 +0,0 @@
-package cn.reghao.tnb.content.app.data.model.po;
-
-import cn.reghao.jutil.jdk.db.BaseObject;
-import cn.reghao.tnb.common.auth.UserContext;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
-
-import java.time.LocalDateTime;
-
-/**
- * @author reghao
- * @date 2023-08-19 02:33:11
- */
-@NoArgsConstructor
-@Getter
-@Setter
-public class ImagePost extends BaseObject<Integer> {
-    private Long albumId;
-    private String albumName;
-    private Integer channelId;
-    private String coverUrl;
-    private Integer total;
-    private LocalDateTime createdAt;
-    private Integer scope;
-    private Long userId;
-
-    public ImagePost(long albumId, String albumName, int scope) {
-        this.albumId = albumId;
-        this.albumName = albumName;
-        this.channelId = 105;
-        this.coverUrl = "";
-        this.total = 0;
-        this.createdAt = LocalDateTime.now();
-        this.scope = scope;
-        this.userId = UserContext.getUserId();
-    }
-}

+ 10 - 9
content/content-service/src/main/java/cn/reghao/tnb/content/app/data/model/vo/AlbumCard.java

@@ -1,6 +1,7 @@
 package cn.reghao.tnb.content.app.data.model.vo;
 
-import cn.reghao.tnb.content.app.data.model.po.ImagePost;
+import cn.reghao.jutil.jdk.converter.DateTimeConverter;
+import cn.reghao.tnb.content.app.vod.model.po.PostAlbum;
 
 import java.time.LocalDateTime;
 
@@ -18,14 +19,14 @@ public class AlbumCard {
     private Integer scope;
     private String userId;
 
-    public AlbumCard(ImagePost imagePost, String userIdStr) {
-        this.albumId = imagePost.getAlbumId();
-        this.albumName = imagePost.getAlbumName();
-        this.channelId = imagePost.getChannelId();
-        this.coverUrl = imagePost.getCoverUrl();
-        this.total = imagePost.getTotal();
-        this.createdAt = imagePost.getCreatedAt();
-        this.scope = imagePost.getScope();
+    public AlbumCard(PostAlbum postAlbum, String userIdStr) {
+        this.albumId = postAlbum.getAlbumId();
+        this.albumName = postAlbum.getAlbumName();
+        this.channelId = postAlbum.getChannelCode();
+        this.coverUrl = postAlbum.getCoverUrl();
+        this.total = postAlbum.getTotal();
+        this.createdAt = DateTimeConverter.localDateTime(postAlbum.getCreateAt());
+        this.scope = postAlbum.getScope();
         this.userId = userIdStr;
     }
 }

+ 4 - 4
content/content-service/src/main/java/cn/reghao/tnb/content/app/data/model/vo/ImageAlbumCard.java

@@ -1,7 +1,7 @@
 package cn.reghao.tnb.content.app.data.model.vo;
 
 import cn.reghao.jutil.jdk.db.PageList;
-import cn.reghao.tnb.content.app.data.model.po.ImagePost;
+import cn.reghao.tnb.content.app.vod.model.po.PostAlbum;
 import lombok.*;
 
 /**
@@ -18,9 +18,9 @@ public class ImageAlbumCard {
     private String userId;
     private PageList<ImageData> images;
 
-    public ImageAlbumCard(ImagePost imagePost, String userIdStr) {
-        this.albumId = imagePost.getAlbumId();
-        this.albumName = imagePost.getAlbumName();
+    public ImageAlbumCard(PostAlbum postAlbum, String userIdStr) {
+        this.albumId = postAlbum.getAlbumId();
+        this.albumName = postAlbum.getAlbumName();
         this.userId = userIdStr;
     }
 }

+ 0 - 47
content/content-service/src/main/java/cn/reghao/tnb/content/app/data/model/vo/ImageAlbumQuery.java

@@ -1,47 +0,0 @@
-package cn.reghao.tnb.content.app.data.model.vo;
-
-import lombok.Getter;
-
-import java.util.List;
-
-/**
- * @author reghao
- * @date 2023-10-25 23:09:18
- */
-@Getter
-public class ImageAlbumQuery {
-    private List<Integer> scope;
-    private Long userId;
-    private Long albumId;
-
-    private ImageAlbumQuery(Builder builder) {
-        this.scope = builder.scope;
-        this.userId = builder.userId;
-        this.albumId = builder.albumId;
-    }
-
-    public static final class Builder {
-        private List<Integer> scope;
-        private Long userId;
-        private Long albumId;
-
-        public Builder scope(List<Integer> scope) {
-            this.scope = scope;
-            return this;
-        }
-
-        public Builder userId(long userId) {
-            this.userId = userId;
-            return this;
-        }
-
-        public Builder albumId(long albumId) {
-            this.albumId = albumId;
-            return this;
-        }
-
-        public ImageAlbumQuery build() {
-            return new ImageAlbumQuery(this);
-        }
-    }
-}

+ 60 - 51
content/content-service/src/main/java/cn/reghao/tnb/content/app/data/service/ImagePostService.java

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

+ 1 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/db/mapper/PostAlbumMapper.java

@@ -16,6 +16,7 @@ import java.util.List;
 @Mapper
 public interface PostAlbumMapper extends BaseMapper<PostAlbum> {
     void updateAlbumCover(@Param("albumId") long albumId, @Param("coverUrl") String coverUrl);
+    void updateAlbumCount(@Param("albumId") long albumId, @Param("num") int num);
 
     int countByCriteria(AlbumQuery albumQuery);
     List<PostAlbum> findAlbumByPage(@Param("page") Page page, @Param("albumQuery") AlbumQuery albumQuery);

+ 1 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/db/mapper/PostItemMapper.java

@@ -19,4 +19,5 @@ public interface PostItemMapper extends BaseMapper<PostItem> {
     int countByAlbumId(long albumId);
     List<PostItem> findByAlbumIdByPage(@Param("page") Page page, @Param("albumId") long albumId);
     PostItem findByImagePost(@Param("imageFileId") String imageFileId, @Param("createBy") long createBy);
+    PostItem findByUrl(String url);
 }

+ 19 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/db/repository/AlbumRepository.java

@@ -7,6 +7,7 @@ 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 org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
 
@@ -32,6 +33,12 @@ public class AlbumRepository {
         postItemMapper.save(postItem);
     }
 
+    @Transactional(rollbackFor = Exception.class)
+    public void addAlbumImage(long albumId, int itemCount, PostItem postItem) {
+        postAlbumMapper.updateAlbumCount(albumId, itemCount);
+        postItemMapper.save(postItem);
+    }
+
     public void updateAlbumCover(long albumId, String coverUrl) {
         postAlbumMapper.updateAlbumCover(albumId, coverUrl);
     }
@@ -59,4 +66,16 @@ public class AlbumRepository {
     public List<PostAlbum> getPostAlbums(Page page, AlbumQuery albumQuery) {
         return postAlbumMapper.findAlbumByPage(page, albumQuery);
     }
+
+    public PostItem getByUrl(String url) {
+        return postItemMapper.findByUrl(url);
+    }
+
+    public int countImageFiles(long albumId) {
+        return postItemMapper.countByAlbumId(albumId);
+    }
+
+    public List<PostItem> getImageFiles(long albumId, Page page) {
+        return postItemMapper.findByAlbumIdByPage(page, albumId);
+    }
 }

+ 15 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/model/po/PostAlbum.java

@@ -19,19 +19,34 @@ import lombok.Setter;
 public class PostAlbum extends BaseObject<Integer> {
     private Long albumId;
     private String albumName;
+    private Integer channelCode;
     private String coverUrl;
     private Integer postType;
     private Integer total;
     private Integer scope;
+    private Long createAt;
     private Long createBy;
 
     public PostAlbum(long albumId, AlbumCreateDto albumCreateDto) {
         this.albumId = albumId;
         this.albumName = albumCreateDto.getAlbumName();
+        this.channelCode = 0;
         this.coverUrl = "";
         this.postType = PostType.Video.getCode();
         this.total = 0;
         this.scope = PostScope.PRIVATE.getCode();
+        this.createAt = System.currentTimeMillis();
+        this.createBy = UserContext.getUserId();
+    }
+
+    public PostAlbum(long albumId, String albumName, int scope) {
+        this.albumId = albumId;
+        this.albumName = albumName;
+        this.channelCode = 105;
+        this.coverUrl = "";
+        this.total = 0;
+        this.scope = scope;
+        this.createAt = System.currentTimeMillis();
         this.createBy = UserContext.getUserId();
     }
 }

+ 29 - 1
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/model/po/PostItem.java

@@ -1,7 +1,7 @@
 package cn.reghao.tnb.content.app.vod.model.po;
 
 import cn.reghao.jutil.jdk.db.BaseObject;
-import cn.reghao.tnb.content.app.vod.model.dto.AlbumActionDto;
+import cn.reghao.oss.sdk.model.dto.media.ImageInfo;
 import lombok.Getter;
 import lombok.NoArgsConstructor;
 
@@ -17,12 +17,40 @@ public class PostItem extends BaseObject<Integer> {
     private Long albumId;
     private String postId;
     private Integer pos;
+    private Integer channelCode;
+    private String objectId;
+    private String format;
+    private String url;
+    private Integer width;
+    private Integer height;
+    private Boolean horizontal;
+    @Deprecated
     private LocalDateTime addedAt;
 
     public PostItem(long albumId, String postId) {
         this.albumId = albumId;
         this.postId = postId;
         this.pos = 1;
+        this.channelCode = 0;
+        this.objectId = "";
+        this.format = "";
+        this.url = "";
+        this.width = 0;
+        this.height = 0;
+        this.horizontal = false;
         this.addedAt = LocalDateTime.now();
     }
+
+    public PostItem(long albumId, int channelCode, ImageInfo imageInfo) {
+        this.albumId = albumId;
+        this.postId = "";
+        this.pos = 1;
+        this.channelCode = channelCode;
+        this.objectId = imageInfo.getObjectId();
+        this.format = imageInfo.getFormat();
+        this.url = imageInfo.getUrl();
+        this.width = imageInfo.getWidth();
+        this.height = imageInfo.getHeight();
+        this.horizontal = imageInfo.getWidth() > imageInfo.getHeight();
+    }
 }

+ 10 - 15
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/service/AlbumService.java

@@ -13,8 +13,6 @@ import cn.reghao.tnb.content.api.constant.AlbumAction;
 import cn.reghao.tnb.content.api.constant.PostScope;
 import cn.reghao.tnb.content.api.constant.PostType;
 import cn.reghao.tnb.content.api.dto.VideoCard;
-import cn.reghao.tnb.content.app.data.db.repository.ImageRepository;
-import cn.reghao.tnb.content.app.data.model.po.ImageFile;
 import cn.reghao.tnb.content.app.vod.db.repository.AlbumRepository;
 import cn.reghao.tnb.content.app.vod.db.repository.VideoRepository;
 import cn.reghao.tnb.content.app.vod.model.dto.*;
@@ -44,18 +42,15 @@ public class AlbumService {
     private final int pageSize = 12;
     private final SnowFlake idGenerator;
     private final AlbumRepository albumRepository;
-    private final ImageRepository imageRepository;
     private final VideoRepository videoRepository;
     private final VideoPostQuery videoPostQuery;
     private final ContentPermission contentPermission;
 
-    public AlbumService(AlbumRepository albumRepository, ImageRepository imageRepository,
-                        VideoRepository videoRepository, VideoPostQuery videoPostQuery,
-                        ContentPermission contentPermission) {
+    public AlbumService(AlbumRepository albumRepository, VideoRepository videoRepository,
+                        VideoPostQuery videoPostQuery, ContentPermission contentPermission) {
         this.idGenerator = new SnowFlake(1L, 1L);
         this.albumRepository = albumRepository;
         this.videoPostQuery = videoPostQuery;
-        this.imageRepository = imageRepository;
         this.videoRepository = videoRepository;
         this.contentPermission = contentPermission;
     }
@@ -116,10 +111,10 @@ public class AlbumService {
             int scope = postAlbum.getScope();
             String coverUrl = postAlbum.getCoverUrl();
             if (scope != PostScope.PUBLIC.getCode() && coverUrl != null) {
-                ImageFile imageFile = imageRepository.getByUrl(coverUrl);
-                if (imageFile != null) {
-                    int channelCode = imageFile.getChannelCode();
-                    String objectId = imageFile.getObjectId();
+                PostItem postItem = albumRepository.getByUrl(coverUrl);
+                if (postItem != null) {
+                    int channelCode = postItem.getChannelCode();
+                    String objectId = postItem.getObjectId();
                     try {
                         String signedUrl = ossService.getSignedUrl(channelCode, objectId);
                         postAlbum.setCoverUrl(signedUrl);
@@ -152,10 +147,10 @@ public class AlbumService {
             int scope = postAlbum.getScope();
             String coverUrl = postAlbum.getCoverUrl();
             if (scope != PostScope.PUBLIC.getCode() && coverUrl != null) {
-                ImageFile imageFile = imageRepository.getByUrl(coverUrl);
-                if (imageFile != null) {
-                    int channelCode = imageFile.getChannelCode();
-                    String objectId = imageFile.getObjectId();
+                PostItem postItem = albumRepository.getByUrl(coverUrl);
+                if (postItem != null) {
+                    int channelCode = postItem.getChannelCode();
+                    String objectId = postItem.getObjectId();
                     try {
                         String signedUrl = ossService.getSignedUrl(channelCode, objectId);
                         postAlbum.setCoverUrl(signedUrl);

+ 15 - 23
content/content-service/src/main/java/cn/reghao/tnb/content/app/vod/service/ContentService.java

@@ -1,8 +1,7 @@
 package cn.reghao.tnb.content.app.vod.service;
 
 import cn.reghao.tnb.common.auth.UserContext;
-import cn.reghao.tnb.content.app.data.db.mapper.ImagePostMapper;
-import cn.reghao.tnb.content.app.data.model.vo.ImageAlbumQuery;
+import cn.reghao.tnb.content.api.constant.PostType;
 import cn.reghao.tnb.content.app.vod.db.mapper.PostAlbumMapper;
 import cn.reghao.tnb.content.app.vod.db.mapper.VideoPostMapper;
 import cn.reghao.tnb.content.app.vod.model.query.AlbumQuery;
@@ -19,14 +18,12 @@ import java.util.List;
 @Service
 public class ContentService {
     private final VideoPostMapper videoPostMapper;
-    private final ImagePostMapper imagePostMapper;
     private final PostAlbumMapper postAlbumMapper;
     private final ContentPermission contentPermission;
 
-    public ContentService(VideoPostMapper videoPostMapper, ImagePostMapper imagePostMapper,
-                          PostAlbumMapper postAlbumMapper, ContentPermission contentPermission) {
+    public ContentService(VideoPostMapper videoPostMapper, PostAlbumMapper postAlbumMapper,
+                          ContentPermission contentPermission) {
         this.videoPostMapper = videoPostMapper;
-        this.imagePostMapper = imagePostMapper;
         this.postAlbumMapper = postAlbumMapper;
         this.contentPermission = contentPermission;
     }
@@ -42,29 +39,24 @@ public class ContentService {
         }
         int videoCount = videoPostMapper.countByCriteria(videoQuery);
 
-        ImageAlbumQuery imageAlbumQuery;
-        if (owner == userId) {
-            imageAlbumQuery = new ImageAlbumQuery.Builder()
-                    .userId(userId)
-                    .build();
-        } else {
+        AlbumQuery.Builder builder = new AlbumQuery.Builder()
+                .postType(PostType.Image.getCode())
+                .createBy(userId);
+        if (owner != userId) {
             List<Integer> scopes = contentPermission.getUserScopes();
-            imageAlbumQuery = new ImageAlbumQuery.Builder()
-                    .userId(userId)
-                    .scope(scopes)
-                    .build();
+            builder.scope(scopes);
         }
-        int imageCount = imagePostMapper.countByCriteria(imageAlbumQuery);
+        int imageCount = postAlbumMapper.countByCriteria(builder.build());
 
-        AlbumQuery albumQuery;
-        if (owner == userId) {
-            albumQuery = new AlbumQuery.Builder().createBy(userId).build();
-        } else {
+        AlbumQuery.Builder builder1 = new AlbumQuery.Builder()
+                .postType(PostType.Video.getCode())
+                .createBy(userId);
+        if (owner != userId) {
             List<Integer> scopes = contentPermission.getUserScopes();
-            albumQuery = new AlbumQuery.Builder().createBy(userId).scope(scopes).build();
+            builder1.scope(scopes);
         }
 
-        int albumCount = postAlbumMapper.countByCriteria(albumQuery);
+        int albumCount = postAlbumMapper.countByCriteria(builder1.build());
         return new UserContentData(videoCount, imageCount, albumCount);
     }
 }

+ 0 - 45
content/content-service/src/main/resources/mapper/data/ImageFileMapper.xml

@@ -1,45 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-
-<mapper namespace="cn.reghao.tnb.content.app.data.db.mapper.ImageFileMapper">
-    <insert id="save" useGeneratedKeys="true" keyProperty="id">
-        insert into image_file
-        (`album_id`,`channel_code`,`image_file_id`,`object_id`,`format`,`url`,`width`,`height`,`horizontal`)
-        values 
-        (#{albumId},#{channelCode},#{imageFileId},#{objectId},#{format},#{url},#{width},#{height},#{horizontal})
-    </insert>
-    <insert id="saveAll" useGeneratedKeys="true" keyProperty="id">
-        insert into image_file
-        (`album_id`,`channel_code`,`image_file_id`,`object_id`,`format`,`url`,`width`,`height`,`horizontal`)
-        values
-        <foreach collection="list" item="item" index="index" separator=",">
-            (#{item.albumId},#{item.channelCode},#{item.imageFileId},#{item.objectId},#{item.format},#{item.url},#{item.width},#{item.height},#{item.horizontal})
-        </foreach>
-    </insert>
-
-    <select id="countByAlbumId" resultType="java.lang.Integer">
-        select count(*)
-        from image_file
-        where album_id=#{albumId}
-        group by image_file_id
-    </select>
-    <select id="findByUrl" resultType="cn.reghao.tnb.content.app.data.model.po.ImageFile">
-        select *
-        from image_file
-        where url=#{url}
-    </select>
-    <select id="findImageFileIdsByPage" resultType="java.lang.String">
-        select image_file_id
-        from image_file
-        where album_id=#{albumId}
-        group by image_file_id
-    </select>
-    <select id="findByImageFileIds" resultType="cn.reghao.tnb.content.app.data.model.po.ImageFile">
-        select *
-        from image_file
-        where image_file_id in
-        <foreach collection="list" item="id" index="index" open="(" close=")" separator=",">
-            #{id}
-        </foreach>
-    </select>
-</mapper>

+ 0 - 69
content/content-service/src/main/resources/mapper/data/ImagePostMapper.xml

@@ -1,69 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-
-<mapper namespace="cn.reghao.tnb.content.app.data.db.mapper.ImagePostMapper">
-    <insert id="save" useGeneratedKeys="true" keyProperty="id">
-        insert into image_post
-        (`user_id`,`album_id`,`album_name`,`channel_id`,`cover_url`,`total`,`scope`,`created_at`,`id`,`deleted`,`create_time`,`update_time`)
-        values
-        (#{userId},#{albumId},#{albumName},#{channelId},#{coverUrl},#{total},#{scope},#{createdAt},#{id},#{deleted},#{createTime},#{updateTime})
-    </insert>
-
-    <update id="updateAlbumCount">
-        update image_post
-        set update_time=now(),total=#{total}
-        where album_id=#{albumId}
-    </update>
-
-    <select id="countByCriteria" resultType="java.lang.Integer">
-        select count(*)
-        from image_post
-        <where>
-            <if test="scope != null">
-                scope in
-                <foreach collection="scope" item="id" index="index" open="(" close=")" separator=",">
-                    #{id}
-                </foreach>
-            </if>
-            <if test="userId != null">
-                and user_id=#{userId}
-            </if>
-        </where>
-    </select>
-    <select id="findImageAlbumByPage" resultType="cn.reghao.tnb.content.app.data.model.po.ImagePost">
-        select *
-        from image_post
-        <where>
-            deleted=0
-            <if test="imageAlbumQuery.scope != null">
-                and scope in
-                <foreach collection="imageAlbumQuery.scope" item="item" index="index" open="(" close=")" separator=",">
-                    #{item}
-                </foreach>
-            </if>
-            <if test="imageAlbumQuery.albumId != null">
-                and album_id=#{imageAlbumQuery.albumId}
-            </if>
-            <if test="imageAlbumQuery.userId != null">
-                and user_id=#{imageAlbumQuery.userId}
-            </if>
-        </where>
-    </select>
-
-    <resultMap id="imageAlbumCard" type="cn.reghao.tnb.content.app.data.model.vo.ImageAlbumCard">
-        <result property="userId" column="user_id"/>
-        <result property="albumId" column="album_id"/>
-        <result property="albumName" column="album_name"/>
-        <collection property="imageFiles" column="album_id" ofType="cn.reghao.tnb.content.app.data.model.po.ImageFile" select="getImages"/>
-    </resultMap>
-    <select id="findImageAlbumCardByAlbumId" resultMap="imageAlbumCard">
-        select *
-        from image_post
-        where album_id=#{albumId}
-    </select>
-    <select id="getImages" resultType="cn.reghao.tnb.content.app.data.model.po.ImageFile">
-        select *
-        from image_file
-        where album_id=#{albumId}
-    </select>
-</mapper>

+ 11 - 2
content/content-service/src/main/resources/mapper/vod/PostAlbumMapper.xml

@@ -4,9 +4,9 @@
 <mapper namespace="cn.reghao.tnb.content.app.vod.db.mapper.PostAlbumMapper">
     <insert id="save" useGeneratedKeys="true" keyProperty="id">
         insert into vod_post_album
-        (`album_id`,`album_name`,`cover_url`,`post_type`,`total`,`scope`,`create_by`)
+        (`album_id`,`album_name`,`channel_code`,`cover_url`,`post_type`,`total`,`scope`,`create_at`,`create_by`)
         values
-        (#{albumId},#{albumName},#{coverUrl},#{postType},#{total},#{scope},#{createBy})
+        (#{albumId},#{albumName},#{channelCode},#{coverUrl},#{postType},#{total},#{scope},#{createAt},#{createBy})
     </insert>
 
     <update id="updateAlbumCover">
@@ -14,6 +14,11 @@
         set cover_url=#{coverUrl}
         where album_id=#{albumId}
     </update>
+    <update id="updateAlbumCount">
+        update vod_post_album
+        set total=#{num}
+        where album_id=#{albumId}
+    </update>
 
     <select id="countByCriteria" resultType="java.lang.Integer">
         select count(*)
@@ -57,4 +62,8 @@
         </where>
         order by create_time desc
     </select>
+    <select id="findAll" resultType="cn.reghao.tnb.content.app.vod.model.po.PostAlbum">
+        select *
+        from vod_post_album
+    </select>
 </mapper>

+ 10 - 5
content/content-service/src/main/resources/mapper/vod/PostItemMapper.xml

@@ -4,16 +4,16 @@
 <mapper namespace="cn.reghao.tnb.content.app.vod.db.mapper.PostItemMapper">
     <insert id="save" useGeneratedKeys="true" keyProperty="id">
         insert into vod_post_item
-        (`album_id`,`post_id`,`pos`,`added_at`)
+        (`album_id`,`post_id`,`pos`,`channel_code`,`object_id`,`format`,`url`,`width`,`height`,`horizontal`)
         values
-        (#{albumId},#{postId},#{pos},#{addedAt})
+        (#{albumId},#{postId},#{pos},#{channelCode},#{objectId},#{format},#{url},#{width},#{height},#{horizontal})
     </insert>
     <insert id="saveAll" useGeneratedKeys="true" keyProperty="id">
         insert into vod_post_item
-        (`album_id`,`post_id`,`pos`,`added_at`)
+        (`album_id`,`post_id`,`pos`,`channel_code`,`object_id`,`format`,`url`,`width`,`height`,`horizontal`)
         values
         <foreach collection="list" item="item" index="index" separator=",">
-            (#{item.albumId},#{item.postId},#{item.pos},#{item.addedAt})
+            (#{item.albumId},#{item.postId},#{item.pos},#{item.channelCode},#{item.objectId},#{item.format},#{item.url},#{item.width},#{item.height},#{item.horizontal})
         </foreach>
     </insert>
 
@@ -41,6 +41,11 @@
                   from vod_post_album
                   where post_type=1 and create_by=#{createBy}
               )
-          and post_id=#{imageFileId}
+          and object_id=#{imageFileId}
+    </select>
+    <select id="findByUrl" resultType="cn.reghao.tnb.content.app.vod.model.po.PostItem">
+        select *
+        from vod_post_item
+        where url=#{url}
     </select>
 </mapper>

+ 27 - 0
content/content-service/src/test/java/cn/reghao/tnb/content/app/vod/service/PostAlbumTest.java

@@ -0,0 +1,27 @@
+package cn.reghao.tnb.content.app.vod.service;
+
+import cn.reghao.tnb.content.app.ContentApplication;
+import cn.reghao.tnb.content.app.vod.db.mapper.PostAlbumMapper;
+import cn.reghao.tnb.content.app.vod.db.mapper.PostItemMapper;
+import lombok.extern.slf4j.Slf4j;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ActiveProfiles;
+
+/**
+ * @author reghao
+ * @date 2025-09-06 23:41:05
+ */
+@Slf4j
+@ActiveProfiles("dev")
+@SpringBootTest(classes = ContentApplication.class)
+public class PostAlbumTest {
+    @Autowired
+    PostAlbumMapper postAlbumMapper;
+    @Autowired
+    PostItemMapper postItemMapper;
+    @Test
+    public void postAlbumTest() {
+    }
+}