fix: 缓存修复,命名修改
This commit is contained in:
@@ -11,6 +11,7 @@ import com.schisandra.oss.application.oss.core.ali.AliOssClient;
|
||||
import com.schisandra.oss.application.oss.core.ali.AliOssConfiguration;
|
||||
import com.schisandra.oss.application.oss.model.OssInfo;
|
||||
import com.schisandra.oss.common.entity.Result;
|
||||
import com.schisandra.oss.common.utils.CaffeineUtil;
|
||||
import com.schisandra.oss.domain.bo.SchisandraOssAliBO;
|
||||
import com.schisandra.oss.domain.redis.RedisUtil;
|
||||
import com.schisandra.oss.domain.service.SchisandraOssAliDomainService;
|
||||
@@ -57,6 +58,8 @@ public class SchisandraOssAliController {
|
||||
private final String USER_OSS_PREFIX = "oss:user:heat";
|
||||
@Resource
|
||||
RedisUtil redisUtil;
|
||||
@Resource
|
||||
CaffeineUtil caffeineUtil;
|
||||
|
||||
/**
|
||||
* 根据id返回单条配置信息
|
||||
@@ -206,11 +209,22 @@ public class SchisandraOssAliController {
|
||||
public Result<String> listAliDir(@RequestParam String userId, @RequestParam String bucket, @RequestParam String prefix) throws Exception {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
AliOssClient bean = SpringUtil.getBean(OssConstant.OssType.ALI + userId);
|
||||
bean.getAliOssConfig().setBucketName(bucket);
|
||||
List<OssInfo> caf= (List<OssInfo>) caffeineUtil.caffeineBuild().getIfPresent("AliListDir" + userId + bucket + prefix);
|
||||
if (caf!=null){
|
||||
return Result.ok(caf);
|
||||
}
|
||||
if (prefix == null)
|
||||
prefix = "";
|
||||
if (bean.listAliInfo(bucket, prefix) != null) {
|
||||
return Result.ok(bean.listAliInfo(bucket, prefix));
|
||||
else {
|
||||
if (prefix.lastIndexOf("/")<prefix.length()-1) {
|
||||
prefix=prefix+"/";
|
||||
}
|
||||
}
|
||||
bean.getAliOssConfig().setBucketName(bucket);
|
||||
List<OssInfo> list=bean.listAliInfo(bucket, prefix);
|
||||
if (list != null) {
|
||||
caffeineUtil.caffeineBuild().put("AliListDir" + userId + bucket + prefix,list);
|
||||
return Result.ok(list);
|
||||
} else {
|
||||
return Result.fail("获取文件目录信息失败");
|
||||
}
|
||||
@@ -227,19 +241,34 @@ public class SchisandraOssAliController {
|
||||
public Result seleteBucket(@RequestParam String userId) {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
AliOssClient bean = SpringUtil.getBean(OssConstant.OssType.ALI + userId);
|
||||
if (bean.selectAllBucket() != null) {
|
||||
return Result.ok(bean.selectAllBucket());
|
||||
List<HashMap<String,String>> caf= (List<HashMap<String, String>>) caffeineUtil.caffeineBuild().getIfPresent("AliBucket" + userId);
|
||||
if (caf!=null){
|
||||
return Result.ok(caf);
|
||||
}
|
||||
List<HashMap<String,String>> list=bean.selectAllBucket();
|
||||
if (list!= null) {
|
||||
caffeineUtil.caffeineBuild().put("AliBucket" + userId,list);
|
||||
return Result.ok(list);
|
||||
} else {
|
||||
return Result.fail("查询失败");
|
||||
}
|
||||
|
||||
}
|
||||
@Cacheable(value = "aliBucket", key = "#userId+#bucket",unless = "#result==null")
|
||||
@PostMapping("getBucketSize")
|
||||
public Result<String> getBucketSize(@RequestParam String userId, @RequestParam String bucket) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
AliOssClient bean = SpringUtil.getBean(OssConstant.OssType.ALI + userId);
|
||||
return Result.ok(bean.getAliBucketSize(bucket));
|
||||
String caf= (String) caffeineUtil.caffeineBuild().getIfPresent("AliBucket" + userId + bucket);
|
||||
if (caf!=null){
|
||||
return Result.ok(caf);
|
||||
}
|
||||
String size=bean.getAliBucketSize(bucket);
|
||||
if (size != null){
|
||||
caffeineUtil.caffeineBuild().put("AliBucket" + userId + bucket,size);
|
||||
return Result.ok(size);
|
||||
}else {
|
||||
return Result.fail();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,6 +285,7 @@ public class SchisandraOssAliController {
|
||||
AliOssClient bean = SpringUtil.getBean(OssConstant.OssType.ALI + userId);
|
||||
bean.getAliOssConfig().setBucketName(bucket);
|
||||
if (bean.createBucket(bucket).equals(bucket)) {
|
||||
caffeineUtil.caffeineBuild().invalidate("AliBucket" + userId);
|
||||
return Result.ok(bean.createBucket(bucket));
|
||||
} else {
|
||||
return Result.fail("创建失败");
|
||||
@@ -276,6 +306,7 @@ public class SchisandraOssAliController {
|
||||
AliOssClient bean = SpringUtil.getBean(OssConstant.OssType.ALI + userId);
|
||||
bean.getAliOssConfig().setBucketName(bucket);
|
||||
if (bean.deleteBucket(bucket).equals("yes")) {
|
||||
caffeineUtil.caffeineBuild().invalidate("AliBucket" + userId);
|
||||
return Result.ok(bean.deleteBucket(bucket));
|
||||
} else {
|
||||
return Result.fail("删除失败,或许桶已经不存在");
|
||||
@@ -291,33 +322,39 @@ public class SchisandraOssAliController {
|
||||
* @date: 2024/6/26 14:34
|
||||
*/
|
||||
@PostMapping("uploadFile")
|
||||
public Result<OssInfo> uploadAliFile(@RequestParam String userId, @RequestParam MultipartFile file, @RequestParam String fileName, @RequestParam String bucket) throws IOException {
|
||||
public Result<OssInfo> uploadAliFile(SchisandraOssAliDTO schisandraOssAliDTO, @RequestParam MultipartFile file) throws IOException {
|
||||
String fileName=schisandraOssAliDTO.getPath();
|
||||
String bucket=schisandraOssAliDTO.getBucketName();
|
||||
String userId= String.valueOf(schisandraOssAliDTO.getUserId());
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(fileName, "不能为空");
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
|
||||
//设置热力图
|
||||
Date date = new Date();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String formattedDate = dateFormat.format(date);
|
||||
String key = redisUtil.buildKey(USER_OSS_PREFIX + ":" + userId, formattedDate);
|
||||
int count = 1;
|
||||
if (redisUtil.exist(key)) {
|
||||
count = Integer.parseInt(redisUtil.get(key));
|
||||
redisUtil.set(key, String.valueOf(count + 1));
|
||||
Preconditions.checkNotNull(file, "不能为空");
|
||||
if (fileName.lastIndexOf("") == fileName.length() - 1) {
|
||||
fileName=fileName+file.getName();
|
||||
}else{
|
||||
redisUtil.set(key, String.valueOf(1));
|
||||
fileName=fileName+"/"+file.getOriginalFilename();
|
||||
}
|
||||
// 获取文件输入流
|
||||
InputStream is = file.getInputStream();
|
||||
AliOssClient bean = SpringUtil.getBean(OssConstant.OssType.ALI + userId);
|
||||
bean.getAliOssConfig().setBucketName(bucket);
|
||||
//设置热力图
|
||||
Date date = new Date();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String formattedDate = dateFormat.format(date);
|
||||
String key = redisUtil.buildKey(USER_OSS_PREFIX, "upload", formattedDate, userId, fileName);
|
||||
HashMap<Object, Object> map = new HashMap<>();
|
||||
map.put("fileName", fileName);
|
||||
map.put("descreption", "这是一个文件");
|
||||
map.put("size", String.valueOf(file.getSize()));
|
||||
map.put("time", formattedDate);
|
||||
if (bean.upLoad(is, fileName, true) != null) {
|
||||
return Result.ok(bean.upLoad(is, fileName, true));
|
||||
redisUtil.setNx(key, map, 30L, TimeUnit.DAYS);
|
||||
caffeineUtil.caffeineBuild().invalidate("AliListDir" + userId + bucket + fileName);
|
||||
return Result.ok();
|
||||
} else {
|
||||
return Result.fail();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -380,7 +417,9 @@ public class SchisandraOssAliController {
|
||||
Preconditions.checkNotNull(filePath, "不能为空");
|
||||
AliOssClient bean = SpringUtil.getBean(OssConstant.OssType.ALI + userId);
|
||||
bean.getAliOssConfig().setBucketName(bucket);
|
||||
String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
|
||||
bean.delete(filePath);
|
||||
caffeineUtil.caffeineBuild().invalidate("AliListDir" + userId + bucket + fileName);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@@ -401,6 +440,9 @@ public class SchisandraOssAliController {
|
||||
AliOssClient bean = SpringUtil.getBean(OssConstant.OssType.ALI + userId);
|
||||
bean.getAliOssConfig().setBucketName(bucket);
|
||||
try {
|
||||
String fileName= oldFileName.substring(oldFileName.lastIndexOf("/") + 1);
|
||||
newFileName=newFileName+fileName;
|
||||
caffeineUtil.caffeineBuild().invalidate("AliListDir" + userId + bucket + fileName);
|
||||
bean.rename(oldFileName, newFileName);
|
||||
} catch (Exception e) {
|
||||
return Result.fail(e.getMessage());
|
||||
|
@@ -3,15 +3,22 @@ package com.schisandra.oss.application.controller;
|
||||
import cn.hutool.core.util.ZipUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.gson.Gson;
|
||||
import com.mybatisflex.annotation.RelationOneToMany;
|
||||
import com.schisandra.oss.application.convert.SchisandraOssMinioDTOConverter;
|
||||
import com.schisandra.oss.application.convert.SchisandraOssQiniuDTOConverter;
|
||||
import com.schisandra.oss.application.dto.SchisandraOssMinioDTO;
|
||||
import com.schisandra.oss.application.dto.SchisandraOssQiniuDTO;
|
||||
import com.schisandra.oss.application.oss.constant.OssConstant;
|
||||
import com.schisandra.oss.application.oss.core.minio.MinioOssClient;
|
||||
import com.schisandra.oss.application.oss.core.minio.MinioOssConfiguration;
|
||||
import com.schisandra.oss.application.oss.model.OssInfo;
|
||||
import com.schisandra.oss.common.entity.Result;
|
||||
import com.schisandra.oss.common.utils.CaffeineUtil;
|
||||
import com.schisandra.oss.domain.bo.SchisandraOssAliBO;
|
||||
import com.schisandra.oss.domain.bo.SchisandraOssMinioBO;
|
||||
import com.schisandra.oss.domain.redis.RedisUtil;
|
||||
import com.schisandra.oss.domain.service.SchisandraOssMinioDomainService;
|
||||
@@ -35,6 +42,7 @@ import java.net.URLEncoder;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -80,9 +88,9 @@ public class SchisandraOssMinioController {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 返回当前用户minio表所有数据
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
@@ -232,7 +240,6 @@ public class SchisandraOssMinioController {
|
||||
* @author zlg
|
||||
* @date: 2024/6/26 14:34
|
||||
*/
|
||||
@CacheEvict(value = "MinioListDir", key = "#userId+#bucket+#filePath.substring(filePath.lastIndexOf('/'))")
|
||||
@PostMapping("deleteFile")
|
||||
public Result deleteMinioFile(@RequestParam String bucket, @RequestParam String userId, @RequestParam String filePath) {
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
@@ -255,12 +262,11 @@ public class SchisandraOssMinioController {
|
||||
* @date: 2024/6/26 14:34
|
||||
*/
|
||||
@PostMapping(value = "uploadFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public Result<Object> uploadMinioFile(@RequestPart("file") MultipartFile file,SchisandraOssMinioDTO schisandraOssMinioDTO) throws IOException {
|
||||
public Result<Object> uploadMinioFile(SchisandraOssMinioDTO schisandraOssMinioDTO,@RequestParam MultipartFile file) throws IOException {
|
||||
String path=schisandraOssMinioDTO.getPath();
|
||||
String bucket=schisandraOssMinioDTO.getBucketName();
|
||||
String userId=schisandraOssMinioDTO.getUserId();
|
||||
Preconditions.checkNotNull(path, "path不能为空");
|
||||
Preconditions.checkNotNull(file, "file不能为空");
|
||||
Preconditions.checkNotNull(bucket, "bucket不能为空");
|
||||
Preconditions.checkNotNull(userId, "userId不能为空");
|
||||
if (path.lastIndexOf("") == path.length() - 1) {
|
||||
@@ -284,6 +290,7 @@ public class SchisandraOssMinioController {
|
||||
map.put("time", formattedDate);
|
||||
if (bean.upLoad(is, path, true) != null) {
|
||||
redisUtil.setNx(key, map, 30L, TimeUnit.DAYS);
|
||||
caffeineUtil.caffeineBuild().invalidate("MinioListDir"+userId+bucket+schisandraOssMinioDTO.getPath());
|
||||
return Result.ok();
|
||||
} else {
|
||||
return Result.fail();
|
||||
@@ -298,7 +305,6 @@ public class SchisandraOssMinioController {
|
||||
* @author zlg
|
||||
* @date: 2024/6/27 9:41
|
||||
*/
|
||||
@Caching(cacheable = @Cacheable(value = "MinioListDir", key = "#userId+#bucket+#newFileName"), evict = @CacheEvict(value = "MinioListDir", key = "#userId+#bucket+#oldFileName"))
|
||||
@PostMapping("renameFile")
|
||||
public Result renameMinioFile(@RequestParam String userId, @RequestParam String bucket, @RequestParam String oldFileName, @RequestParam String newFileName) throws IOException {
|
||||
|
||||
@@ -306,6 +312,7 @@ public class SchisandraOssMinioController {
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
Preconditions.checkNotNull(oldFileName, "不能为空");
|
||||
Preconditions.checkNotNull(newFileName, "不能为空");
|
||||
String path=oldFileName.substring(0,oldFileName.lastIndexOf("/")+1);
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
|
||||
bean.getMinioOssConfig().setBucketName(bucket);
|
||||
try {
|
||||
@@ -313,6 +320,7 @@ public class SchisandraOssMinioController {
|
||||
} catch (Exception e) {
|
||||
return Result.fail(e.getMessage());
|
||||
}
|
||||
caffeineUtil.caffeineBuild().invalidate("MinioListDir"+userId+bucket+path);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@@ -332,12 +340,14 @@ public class SchisandraOssMinioController {
|
||||
Preconditions.checkNotNull(oldFilePath, "不能为空");
|
||||
Preconditions.checkNotNull(newFilePath, "不能为空");
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
|
||||
String path=oldFilePath.substring(0,oldFilePath.lastIndexOf("/")+1);
|
||||
bean.getMinioOssConfig().setBucketName(bucket);
|
||||
try {
|
||||
bean.copy(oldFilePath, newFilePath);
|
||||
} catch (Exception e) {
|
||||
return Result.fail(e.getMessage());
|
||||
}
|
||||
caffeineUtil.caffeineBuild().invalidate("MinioListDir"+userId+bucket+path);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@@ -401,20 +411,33 @@ public class SchisandraOssMinioController {
|
||||
* @author zlg
|
||||
* @date: 2024/6/26 17:37
|
||||
*/
|
||||
@Cacheable(value = "minioBucket", key = "#userId", unless = "#result==null")
|
||||
@PostMapping("seleteBucket")
|
||||
public Result<String> seleteBucket(@RequestParam String userId) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
|
||||
return Result.ok(bean.selectAllBucket());
|
||||
List<HashMap<String,String>>list= (List<HashMap<String, String>>) caffeineUtil.caffeineBuild().getIfPresent("MinioBucket"+userId);
|
||||
if (list!=null){
|
||||
return Result.ok(list);
|
||||
}
|
||||
list=bean.selectAllBucket();
|
||||
if (list==null){
|
||||
return Result.fail();
|
||||
}
|
||||
caffeineUtil.caffeineBuild().put("MinioBucket",list);
|
||||
return Result.ok(list);
|
||||
}
|
||||
|
||||
@Cacheable(value = "minioBucket", key = "#userId+#bucket", unless = "#result==null")
|
||||
@PostMapping("getBucketSize")
|
||||
public Result<String> getBucketSize(@RequestParam String userId, @RequestParam String bucket) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO+userId);
|
||||
return Result.ok(bean.getMinioBucketSize(bucket));
|
||||
String size= (String) caffeineUtil.caffeineBuild().getIfPresent("MinioBucket"+userId+bucket);
|
||||
if (size!=null){
|
||||
return Result.ok(size);
|
||||
}
|
||||
size=bean.getMinioBucketSize(bucket);
|
||||
caffeineUtil.caffeineBuild().put("MinioBucket"+userId+bucket,size);
|
||||
return Result.ok(size);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -424,13 +447,13 @@ public class SchisandraOssMinioController {
|
||||
* @author zlg
|
||||
* @date: 2024/6/26 17:38
|
||||
*/
|
||||
@CacheEvict(value = "minioBucket", key = "#userId")
|
||||
@PostMapping("createBucket")
|
||||
public Result<String> createBucket(@RequestParam String userId, @RequestParam String bucket) {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
|
||||
bean.getMinioOssConfig().setBucketName(bucket);
|
||||
caffeineUtil.caffeineBuild().invalidate("MinioBucket"+userId);
|
||||
return Result.ok(bean.createBucket(bucket));
|
||||
}
|
||||
|
||||
@@ -441,13 +464,14 @@ public class SchisandraOssMinioController {
|
||||
* @author zlg
|
||||
* @date: 2024/6/26 17:38
|
||||
*/
|
||||
@CacheEvict(value = "minioBucket", key = "#userId")
|
||||
|
||||
@PostMapping("deleteBucket")
|
||||
public Result<String> deleteBucket(@RequestParam String userId, @RequestParam String bucket) {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId);
|
||||
bean.getMinioOssConfig().setBucketName(bucket);
|
||||
caffeineUtil.caffeineBuild().invalidate("MinioBucket"+userId);
|
||||
return Result.ok(bean.deleteBucket(bucket));
|
||||
}
|
||||
|
||||
|
@@ -15,6 +15,7 @@ import com.schisandra.oss.application.oss.core.qiniu.QiNiuOssConfiguration;
|
||||
import com.schisandra.oss.application.oss.exception.OssException;
|
||||
import com.schisandra.oss.application.oss.model.OssInfo;
|
||||
import com.schisandra.oss.common.entity.Result;
|
||||
import com.schisandra.oss.common.utils.CaffeineUtil;
|
||||
import com.schisandra.oss.domain.bo.SchisandraOssQiniuBO;
|
||||
import com.schisandra.oss.domain.redis.RedisUtil;
|
||||
import com.schisandra.oss.domain.service.SchisandraOssQiniuDomainService;
|
||||
@@ -62,6 +63,9 @@ public class SchisandraOssQiniuController {
|
||||
@Resource
|
||||
private QiNiuOssConfiguration qiNiuOssConfiguration;
|
||||
|
||||
@Resource
|
||||
CaffeineUtil caffeineUtil;
|
||||
|
||||
/**
|
||||
* 根据id返回单条配置信息
|
||||
*
|
||||
@@ -115,15 +119,26 @@ public class SchisandraOssQiniuController {
|
||||
* @date: 2024/6/26 13:55
|
||||
*/
|
||||
@GetMapping("listDir")
|
||||
@Cacheable(value = "qiniuListDir",key = "#target + #userId + #dirName",unless = "#result == null")
|
||||
public Result<String> listQiniuInfo(@RequestParam String userId, @RequestParam String prefix, @RequestParam String bucket) throws Exception {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
if (prefix != null) {
|
||||
int index=prefix.lastIndexOf("/");
|
||||
if (index <prefix.length()-1) {
|
||||
prefix=prefix+"/";
|
||||
}
|
||||
}
|
||||
List<OssInfo> list= (List<OssInfo>) caffeineUtil.caffeineBuild().getIfPresent("QiniuListDir"+userId + bucket + prefix);
|
||||
if (list!=null) {
|
||||
return Result.ok(list);
|
||||
}
|
||||
QiNiuOssClient bean = SpringUtil.getBean(OssConstant.OssType.QINIU + userId);
|
||||
bean.getQiNiuOssConfig().setBucketName(bucket);
|
||||
if (bean.listfile(bucket, prefix).isEmpty()) {
|
||||
list=bean.listfile(bucket, prefix);
|
||||
if (list==null) {
|
||||
return Result.fail();
|
||||
} else {
|
||||
return Result.ok(bean.listfile(bucket, prefix));
|
||||
caffeineUtil.caffeineBuild().put("QiniuListDir"+userId + bucket +prefix , list);
|
||||
return Result.ok(list);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -135,7 +150,6 @@ public class SchisandraOssQiniuController {
|
||||
* @date: 2024/6/27 9:41
|
||||
*/
|
||||
@PostMapping("renameFile")
|
||||
@CacheEvict(value = "qiniuListDir",key = "#target + #userId + #dirName")
|
||||
public Result renameQiniuFile(@RequestParam String userId, @RequestParam String bucket, @RequestParam String oldFileName, @RequestParam String newFileName) throws IOException {
|
||||
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
@@ -144,11 +158,13 @@ public class SchisandraOssQiniuController {
|
||||
Preconditions.checkNotNull(newFileName, "不能为空");
|
||||
QiNiuOssClient bean = SpringUtil.getBean(OssConstant.OssType.QINIU + userId);
|
||||
bean.getQiNiuOssConfig().setBucketName(bucket);
|
||||
String path=oldFileName.substring(0,oldFileName.lastIndexOf("/")+1);
|
||||
try {
|
||||
bean.rename(oldFileName, newFileName);
|
||||
} catch (Exception e) {
|
||||
return Result.fail(e.getMessage());
|
||||
}
|
||||
caffeineUtil.caffeineBuild().invalidate("QiniuListDir"+userId + bucket +path);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@@ -160,7 +176,6 @@ public class SchisandraOssQiniuController {
|
||||
* @date: 2024/6/27 9:52
|
||||
*/
|
||||
@PostMapping("copyFile")
|
||||
@CacheEvict(value = "qiniuListDir",key = "#target + #userId + #dirName")
|
||||
public Result copyQiniuFile(@RequestParam String userId, @RequestParam String bucket, @RequestParam String oldFilePath, @RequestParam String newFilePath) throws IOException {
|
||||
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
@@ -169,11 +184,13 @@ public class SchisandraOssQiniuController {
|
||||
Preconditions.checkNotNull(newFilePath, "不能为空");
|
||||
QiNiuOssClient bean = SpringUtil.getBean(OssConstant.OssType.QINIU + userId);
|
||||
bean.getQiNiuOssConfig().setBucketName(bucket);
|
||||
String path=oldFilePath.substring(0,oldFilePath.lastIndexOf("/")+1);
|
||||
try {
|
||||
bean.copy(oldFilePath, newFilePath);
|
||||
} catch (Exception e) {
|
||||
return Result.fail(e.getMessage());
|
||||
}
|
||||
caffeineUtil.caffeineBuild().invalidate("QiniuListDir"+userId + bucket +path);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@@ -235,15 +252,16 @@ public class SchisandraOssQiniuController {
|
||||
* @date: 2024/7/8 14:34
|
||||
*/
|
||||
@PostMapping("deleteFile")
|
||||
@CacheEvict(value = "qiniuListDir",key = "#target + #userId + #dirName")
|
||||
public Result deleteQiniuFile(@RequestParam String bucket, @RequestParam String userId, @RequestParam String filePath) {
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(filePath, "不能为空");
|
||||
QiNiuOssClient bean = SpringUtil.getBean(OssConstant.OssType.QINIU + userId);
|
||||
bean.getQiNiuOssConfig().setBucketName(bucket);
|
||||
String path=filePath.substring(filePath.lastIndexOf("/")+1);
|
||||
try {
|
||||
bean.delete(filePath);
|
||||
caffeineUtil.caffeineBuild().invalidate("QiniuListDir"+userId+bucket+path);
|
||||
return Result.ok();
|
||||
} catch (OssException e) {
|
||||
return Result.fail();
|
||||
@@ -258,12 +276,16 @@ public class SchisandraOssQiniuController {
|
||||
* @date: 2024/7/8 14:34
|
||||
*/
|
||||
@PostMapping("uploadFile")
|
||||
@CacheEvict(value = "qiniuListDir",key = "#target + #userId + #dirName")
|
||||
public Result<OssInfo> uploadQiniuFile(@RequestParam String userId, @RequestParam MultipartFile file, @RequestParam String fileName, @RequestParam String bucket) throws IOException {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(fileName, "不能为空");
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
public Result<OssInfo> uploadQiniuFile(SchisandraOssQiniuDTO schisandraOssQiniuDTO, @RequestParam MultipartFile file) throws IOException {
|
||||
|
||||
Preconditions.checkNotNull(schisandraOssQiniuDTO, "不能为空");
|
||||
String userId=schisandraOssQiniuDTO.getUserId();
|
||||
String path=schisandraOssQiniuDTO.getPath();
|
||||
String bucket=schisandraOssQiniuDTO.getBucketName();
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(path, "不能为空");
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
String fileName=path+file.getOriginalFilename();
|
||||
//设置热力图
|
||||
Date date = new Date();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
@@ -276,12 +298,12 @@ public class SchisandraOssQiniuController {
|
||||
} else {
|
||||
redisUtil.set(key, String.valueOf(1));
|
||||
}
|
||||
|
||||
// 获取文件输入流
|
||||
InputStream is = file.getInputStream();
|
||||
QiNiuOssClient bean = SpringUtil.getBean(OssConstant.OssType.QINIU + userId);
|
||||
bean.getQiNiuOssConfig().setBucketName(bucket);
|
||||
if (bean.upLoad(is, fileName, true) != null) {
|
||||
caffeineUtil.caffeineBuild().invalidate("QiniuListDir"+userId+bucket+path);
|
||||
return Result.ok(bean.upLoad(is, fileName, true));
|
||||
}
|
||||
return Result.fail();
|
||||
@@ -299,17 +321,34 @@ public class SchisandraOssQiniuController {
|
||||
public Result seleteBucket(@RequestParam String userId) {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
QiNiuOssClient bean = SpringUtil.getBean(OssConstant.OssType.QINIU + userId);
|
||||
if (bean.selectAllBucket().isEmpty()) {
|
||||
return Result.fail();
|
||||
} else
|
||||
return Result.ok(bean.selectAllBucket());
|
||||
List<HashMap<String, String>> list= (List<HashMap<String, String>>) caffeineUtil.caffeineBuild().getIfPresent("QiniuBucket"+userId);
|
||||
if (list!=null){
|
||||
return Result.ok(list);
|
||||
}
|
||||
list=bean.selectAllBucket();
|
||||
if (list==null){
|
||||
return Result.fail();
|
||||
}else {
|
||||
caffeineUtil.caffeineBuild().put("QiniuBucket"+userId,list);
|
||||
return Result.ok(list);
|
||||
}
|
||||
|
||||
}
|
||||
@Cacheable(value = "qiniuBucket", key = "#userId+#bucket",unless = "#result==null")
|
||||
@PostMapping("getBucketSize")
|
||||
public Result<String> getBucketSize(@RequestParam String userId, @RequestParam String bucket) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
QiNiuOssClient bean = SpringUtil.getBean(OssConstant.OssType.QINIU + userId);
|
||||
return Result.ok(bean.getQiniuBucketSize(bucket));
|
||||
String size= (String) caffeineUtil.caffeineBuild().getIfPresent("QiniuBucket"+userId+bucket);
|
||||
if (size!=null){
|
||||
return Result.ok(size);
|
||||
}
|
||||
size=bean.getQiniuBucketSize(bucket);
|
||||
if (size==null){
|
||||
return Result.fail();
|
||||
}else {
|
||||
caffeineUtil.caffeineBuild().put("QiniuBucket"+userId+bucket,size);
|
||||
return Result.ok(size);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @description: 删除bucket
|
||||
@@ -318,13 +357,13 @@ public class SchisandraOssQiniuController {
|
||||
* @date: 2024/7/8 17:38
|
||||
*/
|
||||
@PostMapping("deleteBucket")
|
||||
@CacheEvict(value = "qiniuBucket",key = "#userId+#bucket")
|
||||
public Result deleteBucket(@RequestParam String userId, @RequestParam String bucket) {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
QiNiuOssClient bean = SpringUtil.getBean(OssConstant.OssType.QINIU + userId);
|
||||
bean.getQiNiuOssConfig().setBucketName(bucket);
|
||||
if (bean.deleteBucket(bucket) == 1) {
|
||||
caffeineUtil.caffeineBuild().invalidate("QiniuBucket"+userId);
|
||||
return Result.ok();
|
||||
} else
|
||||
return Result.fail("删除桶失败");
|
||||
@@ -340,7 +379,6 @@ public class SchisandraOssQiniuController {
|
||||
*/
|
||||
@SneakyThrows
|
||||
@PostMapping("createBucket")
|
||||
@CacheEvict(value = "qiniuBucket",key = "#userId+#bucket")
|
||||
public Result<String> createBucket(@RequestParam String userId, @RequestParam String bucket, @RequestParam String region) {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
@@ -348,6 +386,7 @@ public class SchisandraOssQiniuController {
|
||||
bean.getQiNiuOssConfig().setBucketName(bucket);
|
||||
bean.getQiNiuOssConfig().setRegion(region);
|
||||
if (bean.createBucket(bucket, region) == 1) {
|
||||
caffeineUtil.caffeineBuild().invalidate("QiniuBucket"+userId);
|
||||
return Result.ok(bean.createBucket(bucket, region));
|
||||
} else
|
||||
return Result.fail("创建桶失败");
|
||||
|
@@ -10,10 +10,12 @@ import com.qcloud.cos.model.DeleteObjectsResult;
|
||||
import com.schisandra.oss.application.convert.SchisandraOssTencentDTOConverter;
|
||||
import com.schisandra.oss.application.dto.SchisandraOssTencentDTO;
|
||||
import com.schisandra.oss.application.oss.constant.OssConstant;
|
||||
import com.schisandra.oss.application.oss.core.minio.MinioOssClient;
|
||||
import com.schisandra.oss.application.oss.core.tencent.TencentOssClient;
|
||||
import com.schisandra.oss.application.oss.core.tencent.TencentOssConfiguration;
|
||||
import com.schisandra.oss.application.oss.model.OssInfo;
|
||||
import com.schisandra.oss.common.entity.Result;
|
||||
import com.schisandra.oss.domain.bo.SchisandraOssQiniuBO;
|
||||
import com.schisandra.oss.common.utils.CaffeineUtil;
|
||||
import com.schisandra.oss.domain.bo.SchisandraOssTencentBO;
|
||||
import com.schisandra.oss.domain.redis.RedisUtil;
|
||||
import com.schisandra.oss.domain.service.SchisandraOssTencentDomainService;
|
||||
@@ -39,7 +41,6 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@@ -60,8 +61,19 @@ public class SchisandraOssTencentController {
|
||||
@Resource
|
||||
RedisUtil redisUtil;
|
||||
@Resource
|
||||
CaffeineUtil caffeineUtil;
|
||||
@Resource
|
||||
private SchisandraOssTencentDomainService schisandraOssTencentDomainService;
|
||||
|
||||
private static void extracted(SchisandraOssTencentDTO schisandraOssTencentDTO) {
|
||||
Preconditions.checkNotNull(schisandraOssTencentDTO.getUserId(), "不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssTencentDTO.getBasePath(), "不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssTencentDTO.getBucketName(), "不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssTencentDTO.getSecretId(), "不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssTencentDTO.getSecretKey(), "不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssTencentDTO.getRegion(), "地域不能为空");
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id返回单条配置信息
|
||||
*
|
||||
@@ -80,6 +92,7 @@ public class SchisandraOssTencentController {
|
||||
|
||||
/**
|
||||
* 返回当前用户tencent表所有数据
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
@@ -106,7 +119,6 @@ public class SchisandraOssTencentController {
|
||||
return Result.ok(SchisandraOssTencentDTOConverter.INSTANCE.convertBOToDTOList(list));
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("init")
|
||||
public Result initTencent(@RequestParam String userId, @RequestParam String Id) {
|
||||
if (log.isInfoEnabled()) {
|
||||
@@ -117,7 +129,7 @@ public class SchisandraOssTencentController {
|
||||
bo.setId(Id);
|
||||
bo.setStatus(String.valueOf(true));
|
||||
if (schisandraOssTencentDomainService.update(bo)) {
|
||||
return tencentOssConfiguration.tencentOssClient(userId);
|
||||
return tencentOssConfiguration.tencentOssClient(userId, Id);
|
||||
} else {
|
||||
return Result.fail("初始化失败");
|
||||
}
|
||||
@@ -147,21 +159,32 @@ public class SchisandraOssTencentController {
|
||||
* @author zlg
|
||||
* @date: 2024/6/29 13:28
|
||||
*/
|
||||
@Cacheable(value = "TencentBucket", key = "#userId")
|
||||
@PostMapping("seleteBucket")
|
||||
public Result<String> seleteBucket(@RequestParam String userId) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
TencentOssClient bean = SpringUtil.getBean(OssConstant.OssType.TENCENT + userId);
|
||||
return Result.ok(bean.selectAllBucket());
|
||||
List<HashMap<String, String>> list = (List<HashMap<String, String>>) caffeineUtil.caffeineBuild().getIfPresent("TencentBucket" + userId);
|
||||
if (list != null) {
|
||||
return Result.ok(list);
|
||||
}
|
||||
list = bean.selectAllBucket();
|
||||
caffeineUtil.caffeineBuild().put("TencentBucket" + userId, list);
|
||||
return Result.ok(list);
|
||||
}
|
||||
|
||||
@Cacheable(value = "TencentBucket", key = "#userId+#bucket")
|
||||
@PostMapping("getBucketSize")
|
||||
public Result<String> getBucketSize(@RequestParam String userId, @RequestParam String bucket) throws Exception {
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
TencentOssClient bean = SpringUtil.getBean(OssConstant.OssType.TENCENT + userId);
|
||||
bean.getTencentOssConfig().setBucketName(bucket);
|
||||
return Result.ok(bean.getTencentBucketSize(bucket));
|
||||
String size = (String) caffeineUtil.caffeineBuild().getIfPresent("TencentBucket" + userId + bucket);
|
||||
if (size != null) {
|
||||
return Result.ok(size);
|
||||
}
|
||||
size = bean.getTencentBucketSize(bucket);
|
||||
caffeineUtil.caffeineBuild().put("TencentBucket" + userId + bucket,size);
|
||||
return Result.ok(size);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,14 +194,20 @@ public class SchisandraOssTencentController {
|
||||
* @author zlg
|
||||
* @date: 2024/6/29 13:28
|
||||
*/
|
||||
@Cacheable(value = "TencentBucketDir", key = "#userId+#bucket+#dirName")
|
||||
|
||||
@GetMapping("listDir")
|
||||
public Result<String> listTencentInfo(@RequestParam String userId, @RequestParam String dirName, @RequestParam String bucket) throws Exception {
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
TencentOssClient bean = SpringUtil.getBean(OssConstant.OssType.TENCENT + userId);
|
||||
List<OssInfo> list = (List<OssInfo>) caffeineUtil.caffeineBuild().getIfPresent("TencentlistDir" + userId + dirName + bucket);
|
||||
if (list != null) {
|
||||
return Result.ok(list);
|
||||
}
|
||||
bean.getTencentOssConfig().setBucketName(bucket);
|
||||
return Result.ok(bean.listTargetDir(bucket, dirName));
|
||||
list = bean.listTargetDir(bucket, dirName);
|
||||
caffeineUtil.caffeineBuild().put("TencentlistDir" + userId + dirName + bucket, list);
|
||||
return Result.ok(list);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -195,6 +224,7 @@ public class SchisandraOssTencentController {
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
TencentOssClient bean = SpringUtil.getBean(OssConstant.OssType.TENCENT + userId);
|
||||
// bean.getTencentOssConfig().setBucketName(bucket);
|
||||
caffeineUtil.caffeineBuild().invalidate("TencentBucket" + userId);
|
||||
return Result.ok(bean.createBuctet(bucket, appId));
|
||||
}
|
||||
|
||||
@@ -205,14 +235,14 @@ public class SchisandraOssTencentController {
|
||||
* @author zlg
|
||||
* @date: 2024/6/29 13:27
|
||||
*/
|
||||
@CacheEvict(value = "TencentBucket", key = "#userId")
|
||||
|
||||
@PostMapping("deleteBucket")
|
||||
public Result<String> deleteBucket(@RequestParam String userId, @RequestParam String bucket, @RequestParam String appId) {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
TencentOssClient bean = SpringUtil.getBean(OssConstant.OssType.TENCENT + userId);
|
||||
// bean.getTencentOssConfig().setBucketName(bucket);
|
||||
if (bean.deleteBucket(bucket, appId)) {
|
||||
caffeineUtil.caffeineBuild().invalidate("TencentBucket" + userId);
|
||||
return Result.ok();
|
||||
} else {
|
||||
return Result.fail();
|
||||
@@ -242,29 +272,42 @@ public class SchisandraOssTencentController {
|
||||
* @date: 2024/7/1 16:01
|
||||
*/
|
||||
@PostMapping("uploadTencent")
|
||||
public Result<String> uploadTencent(@RequestParam String userId, @RequestParam String bucket, @RequestParam String target, @RequestParam MultipartFile file) throws IOException {
|
||||
public Result<String> uploadTencent(SchisandraOssTencentDTO schisandraOssTencentDTO,@RequestParam MultipartFile file) throws IOException {
|
||||
String userId = schisandraOssTencentDTO.getUserId();
|
||||
String bucket = schisandraOssTencentDTO.getBucketName();
|
||||
String target = schisandraOssTencentDTO.getPath();
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
if (!target.isEmpty()) {
|
||||
target = target + "/" + file.getOriginalFilename();
|
||||
Preconditions.checkNotNull(file, "不能为空");
|
||||
String path = target;
|
||||
if (path.lastIndexOf("/") == path.length() - 1) {
|
||||
path=path+file.getName();
|
||||
}else{
|
||||
path=path+"/"+file.getOriginalFilename();
|
||||
}
|
||||
TencentOssClient bean = SpringUtil.getBean(OssConstant.OssType.TENCENT + userId);
|
||||
// 获取文件输入流
|
||||
InputStream is = file.getInputStream();
|
||||
TencentOssClient bean = SpringUtil.getBean(OssConstant.OssType.TENCENT + userId);
|
||||
bean.getTencentOssConfig().setBucketName(bucket);
|
||||
//设置热力图
|
||||
Date date = new Date();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String formattedDate = dateFormat.format(date);
|
||||
String key = redisUtil.buildKey(USER_OSS_PREFIX + ":" + userId, formattedDate);
|
||||
int count = 1;
|
||||
if (redisUtil.exist(key)) {
|
||||
count = Integer.parseInt(redisUtil.get(key));
|
||||
redisUtil.set(key, String.valueOf(count + 1));
|
||||
String key = redisUtil.buildKey(USER_OSS_PREFIX, "upload", formattedDate, userId, path);
|
||||
HashMap<Object, Object> map = new HashMap<>();
|
||||
map.put("fileName", path);
|
||||
map.put("descreption", "这是一个文件");
|
||||
map.put("size", String.valueOf(file.getSize()));
|
||||
map.put("time", formattedDate);
|
||||
if (bean.upLoadParts(is, path) != null) {
|
||||
redisUtil.setNx(key, map, 30L, TimeUnit.DAYS);
|
||||
caffeineUtil.caffeineBuild().invalidate("TencentlistDir" + userId + bucket +target);
|
||||
return Result.ok();
|
||||
} else {
|
||||
redisUtil.set(key, String.valueOf(1));
|
||||
return Result.fail();
|
||||
}
|
||||
return Result.ok(bean.upLoadParts(is, target, file.getOriginalFilename()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 腾讯云对象存储下载文件
|
||||
* @param: [userId, bucket, target]
|
||||
@@ -319,7 +362,6 @@ public class SchisandraOssTencentController {
|
||||
* @author zlg
|
||||
* @date: 2024/7/1 16:02
|
||||
*/
|
||||
@Caching(cacheable = @Cacheable(value = "TencentBucketDir", key = "#userId+#targetBucket+#targetName"), evict = @CacheEvict(value = "MinioListDir", key = "#userId+#sourceBucket+#SourceName"))
|
||||
@PostMapping("moveFile")
|
||||
public Result<String> moveTencent(@RequestParam String userId, @RequestParam String sourceBucket, @RequestParam String targetBucket, @RequestParam String targetName, @RequestParam String SourceName) throws IOException {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
@@ -338,15 +380,17 @@ public class SchisandraOssTencentController {
|
||||
* @author zlg
|
||||
* @date: 2024/7/1 16:02
|
||||
*/
|
||||
@Cacheable(value = "TencentBucketDir", key = "#userId+#targetBucket+#targetName")
|
||||
@PostMapping("copyFile")
|
||||
public Result<String> copyTencent(@RequestParam String userId, @RequestParam String sourceBucket, @RequestParam String targetBucket, @RequestParam String targetName, @RequestParam String SourceName) throws IOException {
|
||||
public Result<String> copyTencent(@RequestParam String userId, @RequestParam String sourceBucket, @RequestParam String targetName, @RequestParam String SourceName) throws IOException {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
TencentOssClient bean = SpringUtil.getBean(OssConstant.OssType.TENCENT + userId);
|
||||
CopyResult copyResult = bean.copyTencent(SourceName, targetName, sourceBucket, targetBucket);
|
||||
|
||||
CopyResult copyResult = bean.copyTencent(SourceName, targetName, sourceBucket, sourceBucket);
|
||||
if (copyResult == null) {
|
||||
return Result.fail();
|
||||
}
|
||||
String path=SourceName.substring(0,SourceName.lastIndexOf("/"));
|
||||
caffeineUtil.caffeineBuild().invalidate("TencentlistDir" + userId + sourceBucket +path);
|
||||
return Result.ok(copyResult);
|
||||
}
|
||||
|
||||
@@ -366,10 +410,11 @@ public class SchisandraOssTencentController {
|
||||
if (deleteResult == null) {
|
||||
return Result.fail();
|
||||
}
|
||||
String path=target.get(0).toString().substring(0,target.lastIndexOf("/"));
|
||||
caffeineUtil.caffeineBuild().invalidate("TencentlistDir" + userId + bucketName +path);
|
||||
return Result.ok(deleteResult);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增腾讯云对象存储配置表
|
||||
*/
|
||||
@@ -428,13 +473,4 @@ public class SchisandraOssTencentController {
|
||||
|
||||
}
|
||||
|
||||
private static void extracted(SchisandraOssTencentDTO schisandraOssTencentDTO) {
|
||||
Preconditions.checkNotNull(schisandraOssTencentDTO.getUserId(), "不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssTencentDTO.getBasePath(), "不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssTencentDTO.getBucketName(), "不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssTencentDTO.getSecretId(), "不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssTencentDTO.getSecretKey(), "不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssTencentDTO.getRegion(), "地域不能为空");
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ import com.google.common.base.Preconditions;
|
||||
import com.schisandra.oss.application.convert.SchisandraUserOssDTOConverter;
|
||||
import com.schisandra.oss.application.dto.SchisandraUserOssDTO;
|
||||
import com.schisandra.oss.common.entity.Result;
|
||||
import com.schisandra.oss.common.utils.CaffeineUtil;
|
||||
import com.schisandra.oss.domain.bo.SchisandraUserOssBO;
|
||||
import com.schisandra.oss.domain.redis.RedisUtil;
|
||||
import com.schisandra.oss.domain.service.SchisandraFileHeatmapDomainService;
|
||||
@@ -41,7 +42,8 @@ public class SchisandraUserOssController {
|
||||
*/
|
||||
@Resource
|
||||
private SchisandraFileHeatmapDomainService schisandraFileHeatmapDomainService;
|
||||
|
||||
@Resource
|
||||
CaffeineUtil caffeineUtil;
|
||||
/**
|
||||
* 新增用户对象存储映射表
|
||||
*/
|
||||
@@ -64,6 +66,7 @@ public class SchisandraUserOssController {
|
||||
Preconditions.checkNotNull(schisandraUserOssDTO.getUpdateTime(), "更新时间不能为空");
|
||||
Preconditions.checkNotNull(schisandraUserOssDTO.getIsDeleted(), "不能为空");
|
||||
SchisandraUserOssBO SchisandraUserOssBO = SchisandraUserOssDTOConverter.INSTANCE.convertDTOToBO(schisandraUserOssDTO);
|
||||
caffeineUtil.caffeineBuild().invalidate("userOss"+ schisandraUserOssDTO.getUserId());
|
||||
return Result.ok(schisandraUserOssDomainService.add(SchisandraUserOssBO));
|
||||
} catch (Exception e) {
|
||||
log.error("SchisandraUserOssController.register.error:{}", e.getMessage(), e);
|
||||
@@ -94,6 +97,7 @@ public class SchisandraUserOssController {
|
||||
Preconditions.checkNotNull(schisandraUserOssDTO.getUpdateTime(), "更新时间不能为空");
|
||||
Preconditions.checkNotNull(schisandraUserOssDTO.getIsDeleted(), "不能为空");
|
||||
SchisandraUserOssBO schisandraUserOssBO = SchisandraUserOssDTOConverter.INSTANCE.convertDTOToBO(schisandraUserOssDTO);
|
||||
caffeineUtil.caffeineBuild().invalidate("userOss"+ schisandraUserOssDTO.getUserId());
|
||||
return Result.ok(schisandraUserOssDomainService.update(schisandraUserOssBO));
|
||||
} catch (Exception e) {
|
||||
log.error("SchisandraUserOssController.update.error:{}", e.getMessage(), e);
|
||||
@@ -124,6 +128,7 @@ public class SchisandraUserOssController {
|
||||
Preconditions.checkNotNull(schisandraUserOssDTO.getUpdateTime(), "更新时间不能为空");
|
||||
Preconditions.checkNotNull(schisandraUserOssDTO.getIsDeleted(), "不能为空");
|
||||
SchisandraUserOssBO schisandraUserOssBO = SchisandraUserOssDTOConverter.INSTANCE.convertDTOToBO(schisandraUserOssDTO);
|
||||
caffeineUtil.caffeineBuild().invalidate("userOss"+ schisandraUserOssDTO.getUserId());
|
||||
return Result.ok(schisandraUserOssDomainService.delete(schisandraUserOssBO));
|
||||
} catch (Exception e) {
|
||||
log.error("SchisandraUserOssController.delete.error:{}", e.getMessage(), e);
|
||||
@@ -146,6 +151,7 @@ public class SchisandraUserOssController {
|
||||
if (SchisandraUserOssDTOList.isEmpty()) {
|
||||
return Result.fail("没有查询到用户对象存储映射表信息");
|
||||
} else {
|
||||
caffeineUtil.caffeineBuild().put("userOss"+ userId,SchisandraUserOssDTOList);
|
||||
return Result.ok(SchisandraUserOssDTOList);
|
||||
}
|
||||
}
|
||||
|
@@ -14,6 +14,7 @@ import java.util.Date;
|
||||
*/
|
||||
@Data
|
||||
public class SchisandraOssAliDTO implements Serializable {
|
||||
private String path;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@@ -14,7 +14,7 @@ import java.util.Date;
|
||||
*/
|
||||
@Data
|
||||
public class SchisandraOssQiniuDTO implements Serializable {
|
||||
|
||||
private String path;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@@ -14,7 +14,7 @@ import java.util.Date;
|
||||
*/
|
||||
@Data
|
||||
public class SchisandraOssTencentDTO implements Serializable {
|
||||
|
||||
private String path;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@@ -101,12 +101,7 @@ public class QiNiuOssClient implements StandardOssClient {
|
||||
*/
|
||||
public List<OssInfo> listfile(String bucket, String prefix) {
|
||||
String delimiter = "";
|
||||
if (prefix != null) {
|
||||
int index=prefix.lastIndexOf("/");
|
||||
if (index <prefix.length()-1) {
|
||||
prefix=prefix+"/";
|
||||
}
|
||||
}
|
||||
|
||||
BucketManager.FileListIterator fileListIterator = bucketManager.createFileListIterator(bucket, prefix, 1000, delimiter);
|
||||
List<OssInfo> infos = new ArrayList<>();
|
||||
while (fileListIterator.hasNext()){
|
||||
|
@@ -44,6 +44,8 @@ import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -199,7 +201,7 @@ public class TencentOssClient implements StandardOssClient {
|
||||
}
|
||||
}
|
||||
|
||||
public HashMap<String, String> listTargetDir(String bucket, String dirName) {
|
||||
public List<OssInfo> listTargetDir(String bucket, String dirName) {
|
||||
if (dirName != null) {
|
||||
int index=dirName.lastIndexOf("/");
|
||||
if (index<dirName.length()-1){
|
||||
@@ -210,15 +212,32 @@ public class TencentOssClient implements StandardOssClient {
|
||||
listObjectsRequest.setBucketName(bucket);
|
||||
listObjectsRequest.setPrefix(dirName);
|
||||
listObjectsRequest.setMaxKeys(1000);
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
ObjectListing results = cosClient.listObjects(listObjectsRequest);
|
||||
long fileSize = 0L;
|
||||
List<OssInfo> list= new ArrayList<>();
|
||||
for (COSObjectSummary objectSummary : results.getObjectSummaries()) {
|
||||
if (!objectSummary.getKey().equals(dirName + "/")) {
|
||||
map.put(objectSummary.getKey(), DataSizeUtil.format(objectSummary.getSize()));
|
||||
if (!objectSummary.getKey().equals(dirName)) {
|
||||
if (objectSummary.getKey().lastIndexOf("/") == objectSummary.getKey().length() - 1) {
|
||||
OssInfo ossInfo=new OssInfo();
|
||||
ossInfo.setIsDir(true);
|
||||
ossInfo.setPath(objectSummary.getKey());
|
||||
String name=objectSummary.getKey().split("/")[objectSummary.getKey().split("/").length-1];
|
||||
ossInfo.setName(name);
|
||||
list.add(ossInfo);
|
||||
} else {
|
||||
OssInfo ossInfo=new OssInfo();
|
||||
String name=objectSummary.getKey().substring(objectSummary.getKey().lastIndexOf("/")+1);
|
||||
ossInfo.setIsDir(false);
|
||||
ossInfo.setName(name);
|
||||
ossInfo.setCreateTime(String.valueOf(objectSummary.getLastModified()));
|
||||
ossInfo.setLength(DataSizeUtil.format(objectSummary.getSize()));
|
||||
ossInfo.setPath(objectSummary.getKey());
|
||||
list.add(ossInfo);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return map;
|
||||
return list;
|
||||
}
|
||||
|
||||
public String shareTencentObject(String bucket, String target) {
|
||||
@@ -234,11 +253,10 @@ public class TencentOssClient implements StandardOssClient {
|
||||
}
|
||||
|
||||
|
||||
public Upload upLoadParts(InputStream is, String targetName, String fileName) {
|
||||
public Upload upLoadParts(InputStream is, String targetName) {
|
||||
TransferManager transferManager = createTransferManager();
|
||||
ObjectMetadata objectMetadata = new ObjectMetadata();
|
||||
// int inputStreamLength = 1024 * 1024;
|
||||
// byte data[] = new byte[inputStreamLength];
|
||||
|
||||
try {
|
||||
objectMetadata.setContentLength(is.available());
|
||||
} catch (IOException e) {
|
||||
|
@@ -53,9 +53,9 @@ public class TencentOssConfiguration {
|
||||
private SchisandraOssTencentDomainService schisandraOssTencentDomainService;
|
||||
|
||||
|
||||
public Result tencentOssClient(String userId) {
|
||||
public Result tencentOssClient(String userId,String id) {
|
||||
CompletableFuture<SchisandraOssTencentDTO> futurePrice = CompletableFuture.supplyAsync(() -> {
|
||||
SchisandraOssTencentBO schisandraOssTencentBO = schisandraOssTencentDomainService.getTencentOssConfig(userId);
|
||||
SchisandraOssTencentBO schisandraOssTencentBO = schisandraOssTencentDomainService.selectOneById(id);
|
||||
SchisandraOssTencentDTO schisandraOssTencentDTO = SchisandraOssTencentDTOConverter.INSTANCE.convertBOToDTO(schisandraOssTencentBO);
|
||||
return schisandraOssTencentDTO;
|
||||
});
|
||||
|
Reference in New Issue
Block a user