|
|
@@ -0,0 +1,81 @@
|
|
|
+package cn.reghao.tnb.content.app.disk.service;
|
|
|
+
|
|
|
+import cn.reghao.jutil.jdk.db.PageList;
|
|
|
+import cn.reghao.tnb.account.api.dto.AccountAvatar;
|
|
|
+import cn.reghao.tnb.account.api.iface.AccountQuery;
|
|
|
+import cn.reghao.tnb.content.app.disk.db.mapper.DiskShareMapper;
|
|
|
+import cn.reghao.tnb.content.app.disk.model.dto.ShareCreate;
|
|
|
+import cn.reghao.tnb.content.app.disk.model.dto.ShareRevoke;
|
|
|
+import cn.reghao.tnb.content.app.disk.model.po.DiskShare;
|
|
|
+import cn.reghao.tnb.content.app.disk.model.po.DiskShareTo;
|
|
|
+import cn.reghao.tnb.content.app.disk.model.vo.DiskShareInfo;
|
|
|
+import cn.reghao.tnb.content.app.util.IdService;
|
|
|
+import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author reghao
|
|
|
+ * @date 2025-09-05 17:03:48
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class DiskShareService {
|
|
|
+ @DubboReference(check = false, retries = 0, timeout = 60_000)
|
|
|
+ private AccountQuery accountQuery;
|
|
|
+
|
|
|
+ private final IdService idService;
|
|
|
+ private final DiskShareMapper diskShareMapper;
|
|
|
+
|
|
|
+ public DiskShareService(IdService idService, DiskShareMapper diskShareMapper) {
|
|
|
+ this.idService = idService;
|
|
|
+ this.diskShareMapper = diskShareMapper;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void createShare(ShareCreate shareCreate) {
|
|
|
+ long shareId = idService.getLongId();
|
|
|
+ DiskShare diskShare = new DiskShare();
|
|
|
+
|
|
|
+ List<DiskShareTo> list = shareCreate.getShareToList().stream()
|
|
|
+ .map(userIdStr -> {
|
|
|
+ long userId = accountQuery.getUserIdLong(userIdStr);
|
|
|
+ return new DiskShareTo(shareId, userId);
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ diskShareMapper.save(diskShare);
|
|
|
+ if (!list.isEmpty()) {
|
|
|
+ diskShareMapper.saveDiskShareTo(list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public PageList<DiskShareInfo> getShareList() {
|
|
|
+ return PageList.empty();
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<AccountAvatar> getShareToList(long shareId) {
|
|
|
+ List<Long> userIds = diskShareMapper.findDiskShareToList(shareId);
|
|
|
+ return userIds.stream()
|
|
|
+ .map(userId -> accountQuery.getAccountAvatar(userId))
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ public void revokeShare(ShareRevoke shareRevoke) {
|
|
|
+ long shareId = shareRevoke.getShareId();
|
|
|
+ List<Long> userIds = shareRevoke.getRevokeList().stream()
|
|
|
+ .map(userIdStr -> accountQuery.getUserIdLong(userIdStr))
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (!userIds.isEmpty()) {
|
|
|
+ diskShareMapper.deleteDiskShareTo(shareId, userIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void getSharedAlbums(long userId) {
|
|
|
+ List<Long> albumIds = diskShareMapper.findSharedAlbums(userId);
|
|
|
+ }
|
|
|
+}
|