|
|
@@ -1,20 +1,24 @@
|
|
|
package com.zhongshu.card.server.core.service.oss;
|
|
|
|
|
|
-import com.google.common.collect.Lists;
|
|
|
import com.github.microservice.net.ResultContent;
|
|
|
import com.github.microservice.net.ResultState;
|
|
|
+import com.github.microservice.netdisk.client.model.file.FileItemModel;
|
|
|
+import com.github.microservice.netdisk.client.model.file.FileStoreModel;
|
|
|
+import com.github.microservice.netdisk.client.model.remote.RemoteFile;
|
|
|
+import com.github.microservice.netdisk.client.service.NetDiskOssService;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import com.zhongshu.card.client.type.oss.PlatformStoreType;
|
|
|
+import com.zhongshu.card.server.core.dao.org.OrganizationDao;
|
|
|
import com.zhongshu.card.server.core.dao.org.UserCountDao;
|
|
|
import com.zhongshu.card.server.core.domain.org.UserAccount;
|
|
|
-import com.zhongshu.card.server.core.model.upLoadFile.AliObjectStorageStore;
|
|
|
-import com.zhongshu.card.server.core.model.upLoadFile.PlatformFileItem;
|
|
|
-import com.zhongshu.card.server.core.model.upLoadFile.RemoteFile;
|
|
|
-import com.zhongshu.card.server.core.model.upLoadFile.StsToken;
|
|
|
+import com.zhongshu.card.server.core.model.upLoadFile.*;
|
|
|
import com.zhongshu.card.server.core.model.upLoadFile.oss.ALiObjectStorage;
|
|
|
import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collection;
|
|
|
@@ -28,7 +32,7 @@ import java.util.stream.Collectors;
|
|
|
*/
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
-public class NetDiskOssService extends SuperService {
|
|
|
+public class NetDiskOssBusService extends SuperService {
|
|
|
|
|
|
@Autowired
|
|
|
private AliObjectStorageStore aliObjectStorageStore;
|
|
|
@@ -39,10 +43,46 @@ public class NetDiskOssService extends SuperService {
|
|
|
@Autowired
|
|
|
UserCountDao userCountDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private NetDiskOssService netDiskOssService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrganizationDao organizationDao;
|
|
|
+
|
|
|
+ public ResultContent<com.github.microservice.netdisk.client.model.token.StsToken> getUploadFileToken(RemoteGetTokenFileParam param) {
|
|
|
+ com.github.microservice.netdisk.client.model.remote.RemoteFile remoteFile = new RemoteFile();
|
|
|
+ UserAccount user = getCurrentUserAccount();
|
|
|
|
|
|
+ Boolean isReserveName = param.getIsReserveName();
|
|
|
+ String fileName = param.getFileName();
|
|
|
+ List<String[]> allPaths = buildPathByUser(param.getFileNames(), user);
|
|
|
+ Collection<String[]> paths = allPaths.parallelStream().map((path) -> {
|
|
|
+ return this.toPlatformFileStoreObjectPath(user, path, isReserveName, fileName);
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
|
|
+ remoteFile.setAccountId(param.getOid());
|
|
|
+ remoteFile.setPath(paths);
|
|
|
+ com.github.microservice.netdisk.client.content.ResultContent<com.github.microservice.netdisk.client.model.token.StsToken> content = netDiskOssService.getUploadToken(remoteFile);
|
|
|
+ if (content.getState() == com.github.microservice.netdisk.client.content.ResultState.Success) {
|
|
|
+ return ResultContent.buildSuccess(content.getContent());
|
|
|
+ } else {
|
|
|
+ return ResultContent.buildFail(content.getMsg());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- public ResultContent<StsToken> getUploadToken(RemoteFile remoteFile) {
|
|
|
+ public ResultContent<FileStoreModel> uploadFinish(FileItemModel fileItems) {
|
|
|
+ FileItemModel[] arr = new FileItemModel[]{fileItems};
|
|
|
+ com.github.microservice.netdisk.client.content.ResultContent<List<FileStoreModel>> content = netDiskOssService.uploadFinish(arr);
|
|
|
+ if (content.getState() == com.github.microservice.netdisk.client.content.ResultState.Success) {
|
|
|
+ List<FileStoreModel> list = content.getContent();
|
|
|
+ return ResultContent.buildSuccess(list.get(0));
|
|
|
+ } else {
|
|
|
+ return ResultContent.buildFail(content.getMsg());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public ResultContent<StsToken> getUploadToken(RemoteBusFile remoteFile) {
|
|
|
// PathAssert.validate(remoteFile.getPath());
|
|
|
String userId = getCurrentUserId();
|
|
|
UserAccount user = userCountDao.findTopByUserId(userId);
|
|
|
@@ -80,7 +120,7 @@ public class NetDiskOssService extends SuperService {
|
|
|
.isReserveName(isReserveName).orgiFileName(fileName).build().toPath(PlatformFileItem.PathType.OSS);
|
|
|
}
|
|
|
|
|
|
- public List<String[]> buildPathByUser(RemoteFile param, UserAccount user) {
|
|
|
+ public List<String[]> buildPathByUser(RemoteBusFile param, UserAccount user) {
|
|
|
List<String[]> paths = new ArrayList<>();
|
|
|
param.getFileNames().forEach(it -> {
|
|
|
String[] split = it.split("\\.");
|
|
|
@@ -89,4 +129,14 @@ public class NetDiskOssService extends SuperService {
|
|
|
});
|
|
|
return paths;
|
|
|
}
|
|
|
+
|
|
|
+ public List<String[]> buildPathByUser(List<String> fileNames, UserAccount user) {
|
|
|
+ List<String[]> paths = new ArrayList<>();
|
|
|
+ fileNames.forEach(it -> {
|
|
|
+ String[] split = it.split("\\.");
|
|
|
+ List<String> path = Lists.newArrayList(new String[]{user.getId(), UUID.randomUUID().toString() + "." + split[1]});
|
|
|
+ paths.add(path.toArray(new String[0]));
|
|
|
+ });
|
|
|
+ return paths;
|
|
|
+ }
|
|
|
}
|