From 93fb58c4c5b94537f1c45f7ab5fa0c83eea1ef43 Mon Sep 17 00:00:00 2001 From: zlg <482370576@qq.com> Date: Thu, 18 Jul 2024 21:13:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=B8=8A=E4=BC=A0=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jd/platform/async/callback/IWorker.java | 7 +++- .../SchisandraOssMinioController.java | 36 ++++++++++++------- .../oss/common/utils/CaffeineUtil.java | 10 +++--- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/schisandra-cloud-storage-asyncTool/src/main/java/com/jd/platform/async/callback/IWorker.java b/schisandra-cloud-storage-asyncTool/src/main/java/com/jd/platform/async/callback/IWorker.java index ffe000a..709142f 100644 --- a/schisandra-cloud-storage-asyncTool/src/main/java/com/jd/platform/async/callback/IWorker.java +++ b/schisandra-cloud-storage-asyncTool/src/main/java/com/jd/platform/async/callback/IWorker.java @@ -1,8 +1,13 @@ package com.jd.platform.async.callback; +import java.io.IOException; +import java.rmi.ServerException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; import java.util.Map; import com.jd.platform.async.wrapper.WorkerWrapper; +import jdk.nashorn.internal.runtime.regexp.joni.exception.InternalException; /** * 每个最小执行单元需要实现该接口 @@ -17,7 +22,7 @@ public interface IWorker { * @param object object * @param allWrappers 任务包装 */ - V action(T object, Map allWrappers); + V action(T object, Map allWrappers) throws IOException, NoSuchAlgorithmException, InvalidKeyException, InternalException; /** * 超时、异常时,返回的默认值 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 8cc5556..bb19c2b 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 @@ -6,6 +6,7 @@ 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; @@ -14,6 +15,7 @@ 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; @@ -170,13 +172,20 @@ public class SchisandraOssMinioController { * @author zlg * @date: 2024/6/26 13:55 */ - @Cacheable(value = "MinioListDir", key = "#userId+#bucket+#dirName",unless = "#result == null") @GetMapping("listDir") public Result listMinioInfo(@RequestParam String userId, @RequestParam String dirName, @RequestParam String bucket) throws Exception { Preconditions.checkNotNull(userId, "不能为空"); MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId); bean.getMinioOssConfig().setBucketName(bucket); - return Result.ok(bean.listDir(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); + return Result.ok(list); + } + } /** @@ -230,7 +239,7 @@ public class SchisandraOssMinioController { * @author zlg * @date: 2024/6/26 14:34 */ - @CacheEvict(value = "MinioListDir", key = "#userId+#bucket+#filePath") + @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, "不能为空"); @@ -238,9 +247,7 @@ public class SchisandraOssMinioController { Preconditions.checkNotNull(filePath, "不能为空"); int index=filePath.lastIndexOf("/"); String fileName = filePath.substring(index + 1); - - System.out.println(caffeineUtil.caffeineUtil().getIfPresent("MinioListDir" + userId + bucket + fileName)); - caffeineUtil.caffeineUtil().invalidate("MinioListDir" + userId + bucket + fileName); + caffeineUtil.caffeineBuild().invalidate("MinioListDir" + userId + bucket + fileName); MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId); bean.getMinioOssConfig().setBucketName(bucket); bean.delete(filePath); @@ -254,12 +261,17 @@ public class SchisandraOssMinioController { * @author zlg * @date: 2024/6/26 14:34 */ - @PostMapping("uploadFile") - public Result uploadMinioFile(@RequestParam String userId, @RequestParam MultipartFile file, @RequestParam String fileName, @RequestParam String bucket) throws IOException { + public Result uploadMinioFile(@RequestParam String userId, @RequestParam MultipartFile file, @RequestParam String path, @RequestParam String bucket) throws IOException { Preconditions.checkNotNull(userId, "不能为空"); - Preconditions.checkNotNull(fileName, "不能为空"); + Preconditions.checkNotNull(path, "不能为空"); Preconditions.checkNotNull(bucket, "不能为空"); + Preconditions.checkNotNull(file, "不能为空"); + if (path.lastIndexOf("") == path.length() - 1) { + path=path+file.getName(); + }else{ + path=path+"/"+file.getOriginalFilename(); + } // 获取文件输入流 InputStream is = file.getInputStream(); MinioOssClient bean = SpringUtil.getBean(OssConstant.OssType.MINIO + userId); @@ -268,13 +280,13 @@ public class SchisandraOssMinioController { 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); + String key = redisUtil.buildKey(USER_OSS_PREFIX, "upload", formattedDate, userId, path); HashMap map = new HashMap<>(); - map.put("fileName", fileName); + map.put("fileName", path); map.put("descreption", "这是一个文件"); map.put("size", String.valueOf(file.getSize())); map.put("time", formattedDate); - if (bean.upLoad(is, fileName, true) != null) { + if (bean.upLoad(is, path, true) != null) { redisUtil.setNx(key, map, 30L, TimeUnit.DAYS); return Result.ok(); } else { diff --git a/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-common/src/main/java/com/schisandra/oss/common/utils/CaffeineUtil.java b/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-common/src/main/java/com/schisandra/oss/common/utils/CaffeineUtil.java index ceeadca..ea1de3f 100644 --- a/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-common/src/main/java/com/schisandra/oss/common/utils/CaffeineUtil.java +++ b/schisandra-cloud-storage-oss/schisandra-cloud-storage-oss-common/src/main/java/com/schisandra/oss/common/utils/CaffeineUtil.java @@ -15,14 +15,14 @@ import java.util.concurrent.TimeUnit; @Configuration @Setter @Slf4j -public class CaffeineUtil { +public class CaffeineUtil { public static int maximumSize=10000; - public static int expiresTime = 3; + public static int expiresTime = 1; public static TimeUnit unitTime = TimeUnit.MINUTES; -// @Bean - public Cache caffeineUtil(){ - Cache cache = Caffeine.newBuilder() + @Bean + public Cache caffeineBuild(){ + Cache cache = Caffeine.newBuilder() .maximumSize(maximumSize) .expireAfterWrite(expiresTime, unitTime) .build();