Skip to content

Commit

Permalink
[DEV:文件服务] 上线测试服务器1<Auto> -e:test -m:file-service -type:single -v:1.4…
Browse files Browse the repository at this point in the history
… -rp:8089 -de:<-e ACTIVE=dev -e UNIQUE_ID=0 -e SERVER_PORT=8089>
  • Loading branch information
welsir committed Dec 23, 2023
1 parent 6824baa commit 5f3010a
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,23 @@
import com.example.filesystem.pojo.vo.DownloadFileVO;
import com.example.filesystem.pojo.vo.OSSFileVO;
import com.example.filesystem.pojo.vo.UploadFileVO;
import com.example.filesystem.util.ConcurrentUtil;
import org.apache.tomcat.jni.OS;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
* @Description
Expand All @@ -28,6 +35,8 @@ public class OSSOperatorController {
@Resource
AbstractOSSFileStrategy strategy;

private static final ExecutorService executorService = Executors.newFixedThreadPool(50);

@PostMapping("/upload")
public Result<?> upload(@Validated OSSFileVO commonFileVO){
UploadFileVO res = strategy.upload(commonFileVO);
Expand All @@ -40,4 +49,25 @@ public Result<?> download(@Validated DownloadFileVO commonFileVO){
return Result.success(res);
}

@PostMapping("/upload/list")
public Result<?> upload(MultipartFile[] files,String[] md5List,String[] pathList,String bucket){
ArrayList<UploadFileVO> res = new ArrayList<>();
OSSFileVO ossFileVO = new OSSFileVO();
ossFileVO.setFile(files[0]);
ossFileVO.setPath(pathList[0]);
ossFileVO.setMd5(md5List[0]);
ossFileVO.setBucket(bucket);
Callable<UploadFileVO> file1 = ()->strategy.upload(ossFileVO);
ossFileVO.setFile(files[1]);
ossFileVO.setPath(pathList[1]);
ossFileVO.setMd5(md5List[1]);
Callable<UploadFileVO> file2 = ()->strategy.upload(ossFileVO);

Future<UploadFileVO> res1 = ConcurrentUtil.doJob(executorService, file1);
Future<UploadFileVO> res2 = ConcurrentUtil.doJob(executorService, file2);

res.add(ConcurrentUtil.futureGet(res1));
res.add(ConcurrentUtil.futureGet(res2));
return Result.success(res);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(BaseException.class)
public Result handleException(HttpServletRequest request,
Exception ex) {
logger.error("Handle Exception Request Url:{},Exception:{}", request.getRequestURL(), ex);
logger.error("Handle Exception Request Url:%s,Exception:%s", request.getRequestURL(), ex);
Result result;
//系统异常
if (ex instanceof BaseException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ public class OSSFileVO extends CommonFileVO{

@NotBlank(message = "bucket不能为空")
private String bucket;

}
29 changes: 29 additions & 0 deletions src/main/java/com/example/filesystem/util/ConcurrentUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.example.filesystem.util;

import com.example.filesystem.common.BaseException;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;

/**
* @Description
* @Author welsir
* @Date 2023/12/23 20:03
*/
public class ConcurrentUtil {

public static <T> Future<T> doJob(ExecutorService executorService, Callable<T> callable) {
return executorService.submit(callable);
}

public static <T> T futureGet(Future<T> future) {
try {
return future.get();
} catch (InterruptedException | ExecutionException e) {
throw new BaseException(e.toString());
}
}

}

0 comments on commit 5f3010a

Please sign in to comment.