Browse Source

fix:个人库上传调整

liaoyitao 1 month ago
parent
commit
c8e70d7cd7

+ 2 - 2
src/main/java/com/lqkj/link/module/zone/controller/ResourceController.java

@@ -275,7 +275,7 @@ public class ResourceController {
275 275
         String authHeader = request.getHeader("Authorization");
276 276
         String userCode = jwtService.decryptUsernameWithHeader(authHeader);
277 277
         Integer userId = userInfoService.detailByUserCode(userCode).getUserId();
278
-        return MessageBean.ok(baseService.ossAddModel(file, "resource/model/" + userId + "/"), "oss上传");
278
+        return MessageBean.ok(baseService.ossAddModel(file, "resource/model/" + request.getLocalAddr() + "/" +  request.getLocalPort() + request.getContextPath() + "/" +  userId + "/"), "oss上传");
279 279
     }
280 280
 
281 281
 
@@ -288,6 +288,6 @@ public class ResourceController {
288 288
     public MessageBean<String> ossCheckCapacity(HttpServletRequest request){
289 289
         String authHeader = request.getHeader("Authorization");
290 290
         String userCode = jwtService.decryptUsernameWithHeader(authHeader);
291
-        return MessageBean.ok(resourceService.ossCheckCapacity(userCode), "检查容量");
291
+        return MessageBean.ok(resourceService.ossCheckCapacity(userCode, request), "检查容量");
292 292
     }
293 293
 }

+ 3 - 2
src/main/java/com/lqkj/link/module/zone/service/ResourceService.java

@@ -9,6 +9,7 @@ import com.lqkj.link.module.zone.repository.ModelInfoRepository;
9 9
 import com.lqkj.link.util.AliOSSUtils;
10 10
 import com.lqkj.link.util.FileUtils;
11 11
 import com.lqkj.link.util.Unzipper;
12
+import jakarta.servlet.http.HttpServletRequest;
12 13
 import org.apache.commons.compress.archivers.ArchiveException;
13 14
 import org.springframework.beans.factory.annotation.Autowired;
14 15
 import org.springframework.data.domain.Page;
@@ -196,9 +197,9 @@ public class ResourceService {
196 197
      * @param userCode
197 198
      * @return
198 199
      */
199
-    public String ossCheckCapacity(String userCode) {
200
+    public String ossCheckCapacity(String userCode, HttpServletRequest request) {
200 201
         UserInfo userInfo = userInfoRepository.findByUserCode(userCode);
201
-        Long aLong = aliOSSUtils.ossCheckCapacity("resource/model/" + userInfo.getUserId() + "/");
202
+        Long aLong = aliOSSUtils.ossCheckCapacity("resource/model/" + request.getLocalAddr() + "/" +  request.getLocalPort() + request.getContextPath() + "/" +  userInfo.getUserId() + "/");
202 203
         return "个人库 已使用" + FileUtils.convertBytes(aLong) + "/20G";
203 204
     }
204 205
 }

+ 6 - 1
src/main/java/com/lqkj/link/util/AliOSSUtils.java

@@ -43,7 +43,7 @@ public class AliOSSUtils {
43 43
         String fileName = "file/" + LocalDate.now() + "/" + UUID.randomUUID() + originalFilename.substring(originalFilename.lastIndexOf("."));
44 44
         //上传文件到 OSS
45 45
         try {
46
-            Thread.sleep(200);
46
+            Thread.sleep(100);
47 47
         } catch (InterruptedException e) {
48 48
             throw new RuntimeException(e);
49 49
         }
@@ -67,6 +67,11 @@ public class AliOSSUtils {
67 67
             String originalFilename = file.getOriginalFilename();
68 68
             String fileName = "file/" + LocalDate.now() + "/" + UUID.randomUUID() + originalFilename.substring(originalFilename.lastIndexOf("."));
69 69
             //上传文件到 OSS
70
+            try {
71
+                Thread.sleep(100);
72
+            } catch (InterruptedException e) {
73
+                throw new RuntimeException(e);
74
+            }
70 75
             OSS ossClient = new OSSClientBuilder().build(aliProperties.getEndpoint(), aliProperties.getAccessKeyId(), aliProperties.getAccessKeySecret());
71 76
             threadPoolUtil.getTaskExecutor().execute(() -> {
72 77
                 ossClient.putObject(aliProperties.getBucketName(), fileName, inputStream);