diff --git a/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/controller/SchisandraOssAliController.java b/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/controller/SchisandraOssAliController.java index 0fa1d97..f090df9 100644 --- a/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/controller/SchisandraOssAliController.java +++ b/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/controller/SchisandraOssAliController.java @@ -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 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 caf= (List) 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("/") 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> caf= (List>) caffeineUtil.caffeineBuild().getIfPresent("AliBucket" + userId); + if (caf!=null){ + return Result.ok(caf); + } + List> 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 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 uploadAliFile(@RequestParam String userId, @RequestParam MultipartFile file, @RequestParam String fileName, @RequestParam String bucket) throws IOException { + public Result 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)); - } else { - redisUtil.set(key, String.valueOf(1)); + Preconditions.checkNotNull(file, "不能为空"); + if (fileName.lastIndexOf("") == fileName.length() - 1) { + fileName=fileName+file.getName(); + }else{ + 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 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()); diff --git a/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/controller/SchisandraOssMinioController.java b/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/controller/SchisandraOssMinioController.java index 6604f19..915fe62 100644 --- a/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/controller/SchisandraOssMinioController.java +++ b/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/controller/SchisandraOssMinioController.java @@ -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; @@ -73,23 +81,23 @@ public class SchisandraOssMinioController { public Result returnOneById(String Id) { SchisandraOssMinioBO bo = schisandraOssMinioDomainService.selectOneById(Id); SchisandraOssMinioDTO dto = SchisandraOssMinioDTOConverter.INSTANCE.convertBOToDTO(bo); - if (dto == null) { + if(dto == null){ return Result.fail("查询失败"); } return Result.ok(dto); } + /** * 返回当前用户minio表所有数据 - * * @param userId * @return */ @GetMapping("return_online") public Result returnOnline(String userId) { List list = schisandraOssMinioDomainService.selectAllPresent(userId); - if (list.isEmpty()) { + if(list.isEmpty()){ return Result.fail(); } return Result.ok(SchisandraOssMinioDTOConverter.INSTANCE.convertBOToDTOList(list)); @@ -170,12 +178,12 @@ public class SchisandraOssMinioController { Preconditions.checkNotNull(userId, "不能为空"); MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId); bean.getMinioOssConfig().setBucketName(bucket); - List object = (List) caffeineUtil.caffeineBuild().getIfPresent(userId + bucket + dirName); + List object= (List) caffeineUtil.caffeineBuild().getIfPresent(userId+bucket+dirName); if (object != null) { return Result.ok(object); - } else { - List list = bean.listDir(bucket, dirName); - caffeineUtil.caffeineBuild().put(userId + bucket + dirName, list); + }else { + List list=bean.listDir(bucket,dirName); + caffeineUtil.caffeineBuild().put(userId+bucket+dirName, list); return Result.ok(list); } @@ -232,13 +240,12 @@ 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, "不能为空"); Preconditions.checkNotNull(userId, "不能为空"); Preconditions.checkNotNull(filePath, "不能为空"); - int index = filePath.lastIndexOf("/"); + int index=filePath.lastIndexOf("/"); String fileName = filePath.substring(index + 1); caffeineUtil.caffeineBuild().invalidate("MinioListDir" + userId + bucket + fileName); MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId); @@ -255,18 +262,17 @@ public class SchisandraOssMinioController { * @date: 2024/6/26 14:34 */ @PostMapping(value = "uploadFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) - public Result uploadMinioFile(@RequestPart("file") MultipartFile file,SchisandraOssMinioDTO schisandraOssMinioDTO) throws IOException { - String path = schisandraOssMinioDTO.getPath(); - String bucket = schisandraOssMinioDTO.getBucketName(); - String userId = schisandraOssMinioDTO.getUserId(); + public Result 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) { - path = path + file.getName(); - } else { - path = path + "/" + file.getOriginalFilename(); + path=path+file.getName(); + }else{ + path=path+"/"+file.getOriginalFilename(); } // 获取文件输入流 InputStream is = file.getInputStream(); @@ -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 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>list= (List>) 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 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)); + MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO+userId); + 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 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 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)); } diff --git a/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/controller/SchisandraOssQiniuController.java b/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/controller/SchisandraOssQiniuController.java index 596b54d..a5cf07c 100644 --- a/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/controller/SchisandraOssQiniuController.java +++ b/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/controller/SchisandraOssQiniuController.java @@ -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 listQiniuInfo(@RequestParam String userId, @RequestParam String prefix, @RequestParam String bucket) throws Exception { Preconditions.checkNotNull(userId, "不能为空"); + if (prefix != null) { + int index=prefix.lastIndexOf("/"); + if (index list= (List) 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 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 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()) { + List> list= (List>) caffeineUtil.caffeineBuild().getIfPresent("QiniuBucket"+userId); + if (list!=null){ + return Result.ok(list); + } + list=bean.selectAllBucket(); + if (list==null){ return Result.fail(); - } else - return Result.ok(bean.selectAllBucket()); + }else { + caffeineUtil.caffeineBuild().put("QiniuBucket"+userId,list); + return Result.ok(list); + } + } - @Cacheable(value = "qiniuBucket", key = "#userId+#bucket",unless = "#result==null") @PostMapping("getBucketSize") public Result 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 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("创建桶失败"); diff --git a/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/controller/SchisandraOssTencentController.java b/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/controller/SchisandraOssTencentController.java index 21c2630..0529c28 100644 --- a/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/controller/SchisandraOssTencentController.java +++ b/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/controller/SchisandraOssTencentController.java @@ -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返回单条配置信息 * @@ -72,7 +84,7 @@ public class SchisandraOssTencentController { public Result returnOneById(String Id) { SchisandraOssTencentBO bo = schisandraOssTencentDomainService.selectOneById(Id); SchisandraOssTencentDTO dto = SchisandraOssTencentDTOConverter.INSTANCE.convertBOToDTO(bo); - if(dto == null){ + if (dto == null) { return Result.fail("查询失败"); } return Result.ok(dto); @@ -80,13 +92,14 @@ public class SchisandraOssTencentController { /** * 返回当前用户tencent表所有数据 + * * @param userId * @return */ @GetMapping("return_online") public Result returnOnline(String userId) { List list = schisandraOssTencentDomainService.selectAllPresent(userId); - if(list.isEmpty()){ + if (list.isEmpty()) { return Result.fail(); } return Result.ok(SchisandraOssTencentDTOConverter.INSTANCE.convertBOToDTOList(list)); @@ -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 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> list = (List>) 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 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 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 list = (List) 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 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 uploadTencent(@RequestParam String userId, @RequestParam String bucket, @RequestParam String target, @RequestParam MultipartFile file) throws IOException { + public Result 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 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] @@ -291,14 +334,14 @@ public class SchisandraOssTencentController { String formattedDate = dateFormat.format(date); AtomicInteger count = new AtomicInteger(0); InputStream[] inputStream2 = new InputStream[list.size()]; - list.keySet().forEach( name -> { + list.keySet().forEach(name -> { try { byte[] bytes = StreamUtils.copyToByteArray(list.get(name)); inputStream2[count.get()] = new ByteArrayInputStream(bytes); String key = redisUtil.buildKey(USER_OSS_PREFIX, "download", formattedDate, userId, name); HashMap map = new HashMap<>(); map.put("size", bytes.length); - map.put("time",formattedDate); + map.put("time", formattedDate); redisUtil.setNx(key, map, 30L, TimeUnit.DAYS); count.incrementAndGet(); } catch (IOException e) { @@ -307,8 +350,8 @@ public class SchisandraOssTencentController { }); ZipUtil.zip(output, path, inputStream2); } catch (Exception e) { - return Result.fail(); - } + return Result.fail(); + } return Result.ok(); } @@ -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 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 copyTencent(@RequestParam String userId, @RequestParam String sourceBucket, @RequestParam String targetBucket, @RequestParam String targetName, @RequestParam String SourceName) throws IOException { + public Result 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(), "地域不能为空"); - } - } diff --git a/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/controller/SchisandraUserOssController.java b/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/controller/SchisandraUserOssController.java index 3108394..be04750 100644 --- a/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/controller/SchisandraUserOssController.java +++ b/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/controller/SchisandraUserOssController.java @@ -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); } } diff --git a/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/dto/SchisandraOssAliDTO.java b/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/dto/SchisandraOssAliDTO.java index 68669b6..16af0fd 100644 --- a/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/dto/SchisandraOssAliDTO.java +++ b/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/dto/SchisandraOssAliDTO.java @@ -14,6 +14,7 @@ import java.util.Date; */ @Data public class SchisandraOssAliDTO implements Serializable { + private String path; /** * diff --git a/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/dto/SchisandraOssQiniuDTO.java b/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/dto/SchisandraOssQiniuDTO.java index 24df856..956ae41 100644 --- a/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/dto/SchisandraOssQiniuDTO.java +++ b/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/dto/SchisandraOssQiniuDTO.java @@ -14,7 +14,7 @@ import java.util.Date; */ @Data public class SchisandraOssQiniuDTO implements Serializable { - + private String path; /** * */ diff --git a/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/dto/SchisandraOssTencentDTO.java b/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/dto/SchisandraOssTencentDTO.java index 6b3aea0..f021b18 100644 --- a/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/dto/SchisandraOssTencentDTO.java +++ b/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/dto/SchisandraOssTencentDTO.java @@ -14,7 +14,7 @@ import java.util.Date; */ @Data public class SchisandraOssTencentDTO implements Serializable { - + private String path; /** * */ diff --git a/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/oss/core/qiniu/QiNiuOssClient.java b/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/oss/core/qiniu/QiNiuOssClient.java index 4f85ee7..95981e1 100644 --- a/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/oss/core/qiniu/QiNiuOssClient.java +++ b/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/oss/core/qiniu/QiNiuOssClient.java @@ -101,12 +101,7 @@ public class QiNiuOssClient implements StandardOssClient { */ public List listfile(String bucket, String prefix) { String delimiter = ""; - if (prefix != null) { - int index=prefix.lastIndexOf("/"); - if (index infos = new ArrayList<>(); while (fileListIterator.hasNext()){ diff --git a/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/oss/core/tencent/TencentOssClient.java b/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/oss/core/tencent/TencentOssClient.java index 029fea6..1224386 100644 --- a/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/oss/core/tencent/TencentOssClient.java +++ b/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/oss/core/tencent/TencentOssClient.java @@ -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 listTargetDir(String bucket, String dirName) { + public List listTargetDir(String bucket, String dirName) { if (dirName != null) { int index=dirName.lastIndexOf("/"); if (index map = new HashMap<>(); ObjectListing results = cosClient.listObjects(listObjectsRequest); long fileSize = 0L; + List 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) { diff --git a/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/oss/core/tencent/TencentOssConfiguration.java b/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/oss/core/tencent/TencentOssConfiguration.java index cfd6fa2..02492ae 100644 --- a/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/oss/core/tencent/TencentOssConfiguration.java +++ b/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-application/schisandra-cloud-storage-oss-application-controller/src/main/java/com/schisandra/oss/application/oss/core/tencent/TencentOssConfiguration.java @@ -53,9 +53,9 @@ public class TencentOssConfiguration { private SchisandraOssTencentDomainService schisandraOssTencentDomainService; - public Result tencentOssClient(String userId) { + public Result tencentOssClient(String userId,String id) { CompletableFuture futurePrice = CompletableFuture.supplyAsync(() -> { - SchisandraOssTencentBO schisandraOssTencentBO = schisandraOssTencentDomainService.getTencentOssConfig(userId); + SchisandraOssTencentBO schisandraOssTencentBO = schisandraOssTencentDomainService.selectOneById(id); SchisandraOssTencentDTO schisandraOssTencentDTO = SchisandraOssTencentDTOConverter.INSTANCE.convertBOToDTO(schisandraOssTencentBO); return schisandraOssTencentDTO; });