Ver código fonte

update DiskShareService

reghao 6 meses atrás
pai
commit
696b2d5609

+ 14 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/model/constant/AlbumType.java

@@ -1,5 +1,8 @@
 package cn.reghao.tnb.content.app.disk.model.constant;
 
+import java.util.HashMap;
+import java.util.Map;
+
 /**
  * @author reghao
  * @date 2025-09-06 16:11:57
@@ -17,6 +20,13 @@ public enum AlbumType {
         this.value = value;
     }
 
+    private static Map<Integer, AlbumType> map = new HashMap<>();
+    static {
+        for (AlbumType albumType : AlbumType.values()) {
+            map.put(albumType.value, albumType);
+        }
+    }
+
     public String getName() {
         return this.name();
     }
@@ -31,4 +41,8 @@ public enum AlbumType {
     public int getValue() {
         return value;
     }
+
+    public static AlbumType getByCode(int code) {
+        return map.get(code);
+    }
 }

+ 3 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/model/vo/DiskShareInfo.java

@@ -1,6 +1,7 @@
 package cn.reghao.tnb.content.app.disk.model.vo;
 
 import cn.reghao.jutil.jdk.converter.DateTimeConverter;
+import cn.reghao.tnb.content.app.disk.model.constant.AlbumType;
 import cn.reghao.tnb.content.app.disk.model.po.DiskShare;
 import lombok.Getter;
 import lombok.NoArgsConstructor;
@@ -13,12 +14,14 @@ import lombok.NoArgsConstructor;
 @Getter
 public class DiskShareInfo {
     private long shareId;
+    private String albumType;
     private String albumName;
     private String shareAt;
     private int num;
 
     public DiskShareInfo(DiskShare diskShare, String albumName, int num) {
         this.shareId = diskShare.getShareId();
+        this.albumType = AlbumType.getByCode(diskShare.getAlbumType()).getName();
         this.albumName = albumName;
         this.shareAt = DateTimeConverter.format(diskShare.getCreateAt());
         this.num = num;

+ 20 - 1
content/content-service/src/main/java/cn/reghao/tnb/content/app/disk/service/DiskShareService.java

@@ -103,10 +103,29 @@ public class DiskShareService {
         Page page = new Page(pageNumber, pageSize);
         List<DiskShareInfo> list = diskShareMapper.findDiskShareByPage(page, loginUser).stream()
                 .map(diskShare -> {
-                    String albumName = diskAlbumMapper.findDiskAlbum(diskShare.getAlbumId()).getAlbumName();
+                    int albumType = diskShare.getAlbumType();
+                    long albumId = diskShare.getAlbumId();
+                    String albumName = "";
+                    if (albumType == AlbumType.cam.getValue()) {
+                        CamDevice camDevice = diskCamRepository.getCamDevice(albumId, loginUser);
+                        if (camDevice == null) {
+                            return null;
+                        }
+                        albumName = camDevice.getCamName();
+                    } else if (albumType == AlbumType.image.getValue()) {
+                        DiskAlbum diskAlbum = diskAlbumMapper.findDiskAlbum(albumId);
+                        if (diskAlbum == null) {
+                            return null;
+                        }
+                        albumName = diskAlbum.getAlbumName();
+                    } else {
+                        return null;
+                    }
+
                     int num = diskShareMapper.countDiskShareTo(diskShare.getShareId());
                     return new DiskShareInfo(diskShare, albumName, num);
                 })
+                .filter(Objects::nonNull)
                 .collect(Collectors.toList());
 
         int total = diskShareMapper.countDiskShare(loginUser);