diff --git a/play-admin/pom.xml b/play-admin/pom.xml
index 8320fa4..1697214 100644
--- a/play-admin/pom.xml
+++ b/play-admin/pom.xml
@@ -36,6 +36,7 @@
1.0
+
io.jsonwebtoken
@@ -63,6 +64,11 @@
spring-boot-starter-data-redis
+
+ com.aliyun.oss
+ aliyun-sdk-oss
+
+
com.github.binarywang
@@ -92,7 +98,6 @@
-
\ No newline at end of file
diff --git a/play-admin/src/main/java/com/starry/admin/common/mybatis/handler/MyTenantLineHandler.java b/play-admin/src/main/java/com/starry/admin/common/mybatis/handler/MyTenantLineHandler.java
index f66e169..d4d7f6d 100644
--- a/play-admin/src/main/java/com/starry/admin/common/mybatis/handler/MyTenantLineHandler.java
+++ b/play-admin/src/main/java/com/starry/admin/common/mybatis/handler/MyTenantLineHandler.java
@@ -24,7 +24,7 @@ public class MyTenantLineHandler implements TenantLineHandler {
/**
* 排除过滤的表
*/
- private static final String[] TABLE_FILTER = {"sys_menu", "sys_tenant_package", "sys_tenant", "sys_dict", "sys_dict_data"};
+ private static final String[] TABLE_FILTER = {"sys_user", "sys_menu", "sys_tenant_package", "sys_tenant", "sys_dict", "sys_dict_data"};
/**
* 排除过滤的表前缀
@@ -38,6 +38,9 @@ public class MyTenantLineHandler implements TenantLineHandler {
if (StrUtil.isBlankIfStr(tenantId)) {
return new NullValue();
}
+ if (StrUtil.isBlankIfStr(tenantId)) {
+ tenantId = "9999";
+ }
return new StringValue(tenantId);
}
diff --git a/play-admin/src/main/java/com/starry/admin/common/oss/OssProperties.java b/play-admin/src/main/java/com/starry/admin/common/oss/OssProperties.java
new file mode 100644
index 0000000..f98d296
--- /dev/null
+++ b/play-admin/src/main/java/com/starry/admin/common/oss/OssProperties.java
@@ -0,0 +1,34 @@
+package com.starry.admin.common.oss;
+
+import lombok.Data;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.PropertySource;
+
+@Data
+@Configuration
+@ConfigurationProperties(prefix = "aliyun")
+@PropertySource(value = {"classpath:oss.properties"})
+public class OssProperties implements InitializingBean {
+
+ public String endpoint;
+ public String accessKeyId;
+ public String accessKeySecret;
+ public String bucketName;
+
+
+ public static String ENDPOINT = "";
+ public static String KEY_ID = "";
+ public static String KEY_SECRET = "";
+ public static String BUCKET_NAME = "";
+
+
+ @Override
+ public void afterPropertiesSet() throws Exception {
+ ENDPOINT = getEndpoint();
+ KEY_ID = getAccessKeyId();
+ KEY_SECRET = getAccessKeySecret();
+ BUCKET_NAME = getBucketName();
+ }
+}
diff --git a/play-admin/src/main/java/com/starry/admin/common/oss/controller/CosController.java b/play-admin/src/main/java/com/starry/admin/common/oss/controller/CosController.java
new file mode 100644
index 0000000..a19941f
--- /dev/null
+++ b/play-admin/src/main/java/com/starry/admin/common/oss/controller/CosController.java
@@ -0,0 +1,49 @@
+package com.starry.admin.common.oss.controller;
+
+import com.starry.admin.common.oss.service.IOssFileService;
+import com.starry.common.result.R;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+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.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+
+/**
+ * @author admin
+ * cos存储前端控制器
+ * @since 2022/11/13 17:51
+ */
+@Slf4j
+@RestController
+@RequestMapping("/cos")
+public class CosController {
+
+ @Resource
+ IOssFileService ossFileService;
+
+
+ @ApiOperation(value = "照片上传")
+ @PostMapping("/upload/image")
+ public R uploadImage(MultipartFile file) throws Exception {
+ if (!file.isEmpty()) {
+ String house = ossFileService.upload(file.getInputStream(), "house", file.getOriginalFilename());
+ return R.ok(house);
+ }
+ return R.error("上传照片异常,请联系管理员");
+ }
+
+ @ApiOperation(value = "获取cos临时密钥")
+ @GetMapping("/temp-key")
+ public R getTempKey() throws FileNotFoundException {
+ FileInputStream inputStream = new FileInputStream(new File("C:\\Users\\admin\\Pictures\\0001.jpg"));
+ ossFileService.upload(inputStream, "test", "0001.png");
+ return R.ok();
+ }
+}
diff --git a/play-admin/src/main/java/com/starry/admin/common/oss/service/IOssFileService.java b/play-admin/src/main/java/com/starry/admin/common/oss/service/IOssFileService.java
new file mode 100644
index 0000000..1615404
--- /dev/null
+++ b/play-admin/src/main/java/com/starry/admin/common/oss/service/IOssFileService.java
@@ -0,0 +1,23 @@
+package com.starry.admin.common.oss.service;
+
+import java.io.InputStream;
+
+public interface IOssFileService {
+
+ /**
+ * 文件上传阿里云
+ *
+ * @param inputStream InputStream
+ * @param module String
+ * @param originalFilename 文件名称
+ */
+ String upload(InputStream inputStream, String module, String originalFilename);
+
+ /**
+ * 删除文件
+ *
+ * @param url 文件地址
+ */
+ void remove(String url);
+
+}
diff --git a/play-admin/src/main/java/com/starry/admin/common/oss/service/impl/OssFileServiceImpl.java b/play-admin/src/main/java/com/starry/admin/common/oss/service/impl/OssFileServiceImpl.java
new file mode 100644
index 0000000..db242bd
--- /dev/null
+++ b/play-admin/src/main/java/com/starry/admin/common/oss/service/impl/OssFileServiceImpl.java
@@ -0,0 +1,98 @@
+package com.starry.admin.common.oss.service.impl;
+
+
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.io.FileTypeUtil;
+import cn.hutool.core.util.IdUtil;
+import com.aliyun.oss.ClientException;
+import com.aliyun.oss.OSS;
+import com.aliyun.oss.OSSClientBuilder;
+import com.aliyun.oss.OSSException;
+import com.aliyun.oss.model.CannedAccessControlList;
+import com.aliyun.oss.model.PutObjectRequest;
+import com.starry.admin.common.exception.CustomException;
+import com.starry.admin.common.oss.OssProperties;
+import com.starry.admin.common.oss.service.IOssFileService;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.exception.ExceptionUtils;
+import org.springframework.stereotype.Service;
+
+import java.io.InputStream;
+
+@Service
+@Slf4j
+public class OssFileServiceImpl implements IOssFileService {
+
+
+ @Override
+ public String upload(InputStream inputStream, String module, String filename) {
+ // 创建OSSClient实例。
+ OSS ossClient = new OSSClientBuilder().build(OssProperties.ENDPOINT, OssProperties.KEY_ID, OssProperties.KEY_SECRET);
+ log.info("OSSClient实例创建成功");
+ try {
+ //判断oss实例是否存在:如果不存在则创建,如果存在则获取
+ if (!ossClient.doesBucketExist(OssProperties.BUCKET_NAME)) {
+ //创建bucket
+ ossClient.createBucket(OssProperties.BUCKET_NAME);
+ log.info("bucket存储空间【{}】创建成功", OssProperties.BUCKET_NAME);
+ //设置oss实例的访问权限:公共读
+ ossClient.setBucketAcl(OssProperties.BUCKET_NAME, CannedAccessControlList.PublicRead);
+ log.info("【{}】存储空间访问权限设置为公共读成功", OssProperties.BUCKET_NAME);
+ }
+ //构建日期路径:avatar/2019/02/26/文件名
+ String folder = new DateTime().toString("yyyy/MM/dd");
+ //文件名:uuid.扩展名
+ filename = IdUtil.fastSimpleUUID() + FileTypeUtil.getType(inputStream);
+ //文件根路径
+ String key = module + "/" + folder + "/" + filename;
+ // 创建PutObjectRequest对象。
+ PutObjectRequest putObjectRequest = new PutObjectRequest(OssProperties.BUCKET_NAME, key, inputStream);
+ // 创建PutObject请求。
+ ossClient.putObject(putObjectRequest);
+ log.info("oss文件上传成功");
+ //阿里云文件绝对路径
+ String endpoint = OssProperties.ENDPOINT.substring(OssProperties.ENDPOINT.lastIndexOf("//") + 2);
+ //返回文件的访问路径
+ return "https://" + OssProperties.BUCKET_NAME + "." + endpoint + "/" + key;
+ } catch (OSSException oe) {
+ log.error("OSSException 文件上传失败:", oe);
+ throw new CustomException("OSS文件上传异常,{}" + oe.getMessage());
+ } catch (ClientException ce) {
+ log.error("ClientException 文件上传失败:{}", ExceptionUtils.getStackTrace(ce));
+ throw new CustomException("OSS文件上传异常,{}" + ce.getMessage());
+ } finally {
+ if (ossClient != null) {
+ ossClient.shutdown();
+ log.info("关闭ossClient");
+ }
+ }
+ }
+
+ @Override
+ public void remove(String url) {
+ OSS ossClient = new OSSClientBuilder().build(OssProperties.ENDPOINT, OssProperties.KEY_ID, OssProperties.KEY_SECRET);
+ log.info("OSSClient实例创建成功");
+ try {
+ String endpoint = OssProperties.ENDPOINT.substring(OssProperties.ENDPOINT.lastIndexOf("//") + 2);
+ //文件名(服务器上的文件路径)
+ String host = "https://" + OssProperties.BUCKET_NAME + "." + endpoint + "/";
+ String objectName = url.substring(host.length());
+ // 删除文件或目录。如果要删除目录,目录必须为空。
+ ossClient.deleteObject(OssProperties.BUCKET_NAME, objectName);
+ log.info("{}文件删除成功", objectName);
+ } catch (OSSException oe) {
+ log.error("OSSException 文件删除失败", oe);
+ throw new CustomException("OSS文件删除异常,{}" + oe.getMessage());
+ } catch (ClientException ce) {
+ log.error("ClientException 文件删除失败:{}", ExceptionUtils.getStackTrace(ce));
+ throw new CustomException("OSS文件删除异常,{}" + ce.getMessage());
+ } finally {
+ if (ossClient != null) {
+ // 关闭OSSClient。
+ ossClient.shutdown();
+ log.info("关闭ossClient");
+ }
+ }
+ }
+
+}
diff --git a/play-admin/src/main/java/com/starry/admin/modules/system/controller/SysUserController.java b/play-admin/src/main/java/com/starry/admin/modules/system/controller/SysUserController.java
index 690c271..2116c8c 100644
--- a/play-admin/src/main/java/com/starry/admin/modules/system/controller/SysUserController.java
+++ b/play-admin/src/main/java/com/starry/admin/modules/system/controller/SysUserController.java
@@ -4,6 +4,7 @@ package com.starry.admin.modules.system.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.starry.admin.common.component.JwtToken;
import com.starry.admin.common.domain.LoginUser;
+import com.starry.admin.common.oss.service.IOssFileService;
import com.starry.admin.modules.system.entity.SysRoleEntity;
import com.starry.admin.modules.system.entity.SysUserEntity;
import com.starry.admin.modules.system.service.SysRoleService;
@@ -14,7 +15,6 @@ import com.starry.common.annotation.Log;
import com.starry.common.constant.UserConstants;
import com.starry.common.enums.BusinessType;
import com.starry.common.result.R;
-import com.starry.common.utils.file.CosClientUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
@@ -47,6 +47,9 @@ public class SysUserController {
@Resource
private JwtToken tokenService;
+ @Resource
+ private IOssFileService ossFileService;
+
@ApiOperation(value = "注册用户")
@PostMapping(value = "register")
public R register(@RequestBody SysUserEntity user) {
@@ -133,7 +136,7 @@ public class SysUserController {
@PostMapping("/profile/avatar")
public R uploadAvatar(@RequestParam("avatarfile") MultipartFile file) throws Exception {
if (!file.isEmpty()) {
- String avatar = CosClientUtils.upload(file, "avatar");
+ String avatar = ossFileService.upload(file.getInputStream(), "avatar", file.getOriginalFilename());
if (userService.updateUserAvatar(SecurityUtils.getUserId(), avatar)) {
// 更新缓存用户头像
LoginUser loginUser = SecurityUtils.getLoginUser();
diff --git a/play-admin/src/main/resources/application-dev.yml b/play-admin/src/main/resources/application-dev.yml
index 66c6ff0..dc78890 100644
--- a/play-admin/src/main/resources/application-dev.yml
+++ b/play-admin/src/main/resources/application-dev.yml
@@ -90,13 +90,4 @@ xl:
authCode:
# 登录验证码是否开启,开发环境配置false方便测试
enable: false
-# 腾讯云cos配置
-cos:
- baseUrl: https://admin-125966.cos.ap-guangzhou.myqcloud.com
- secretId: AKIDdHsLgtxoSs3sWw73lz
- secretKey: zZxBD0b4QcZGmdFcotm
- regionName: ap-guangzhou
- bucketName: admin-125966
- folderPrefix: /upload
-
diff --git a/play-admin/src/main/resources/application-prod.yml b/play-admin/src/main/resources/application-prod.yml
index f559b6d..ceebfc6 100644
--- a/play-admin/src/main/resources/application-prod.yml
+++ b/play-admin/src/main/resources/application-prod.yml
@@ -85,12 +85,4 @@ xl:
login:
authCode:
# 登录验证码是否开启,开发环境配置false方便测试
- enable: false
-# 腾讯云cos配置
-cos:
- baseUrl: https://admin-125966.cos.ap-guangzhou.myqcloud.com
- secretId: AKIDdHsLgtxoSs3sWw73lz
- secretKey: zZxBD0b4QcZGmdFcotm
- regionName: ap-guangzhou
- bucketName: admin-125966
- folderPrefix: /upload
\ No newline at end of file
+ enable: false
\ No newline at end of file
diff --git a/play-admin/src/main/resources/application-test.yml b/play-admin/src/main/resources/application-test.yml
index 6cdfedd..e958a70 100644
--- a/play-admin/src/main/resources/application-test.yml
+++ b/play-admin/src/main/resources/application-test.yml
@@ -90,13 +90,5 @@ xl:
authCode:
# 登录验证码是否开启,开发环境配置false方便测试
enable: false
-# 腾讯云cos配置
-cos:
- baseUrl: https://admin-125966.cos.ap-guangzhou.myqcloud.com
- secretId: AKIDdHsLgtxoSs3sWw73lz
- secretKey: zZxBD0b4QcZGmdFcotm
- regionName: ap-guangzhou
- bucketName: admin-125966
- folderPrefix: /upload
diff --git a/play-admin/src/main/resources/oss.properties b/play-admin/src/main/resources/oss.properties
new file mode 100644
index 0000000..eddd26c
--- /dev/null
+++ b/play-admin/src/main/resources/oss.properties
@@ -0,0 +1,4 @@
+aliyun.endpoint=
+aliyun.accessKeyId=
+aliyun.accessKeySecret=
+aliyun.bucketName=
\ No newline at end of file
diff --git a/play-common/pom.xml b/play-common/pom.xml
index 48c8578..6816c05 100644
--- a/play-common/pom.xml
+++ b/play-common/pom.xml
@@ -93,31 +93,13 @@
com.github.gavlyukovskiy
p6spy-spring-boot-starter
-
-
- com.qcloud
- cos_api
-
-
- tencentcloud-sdk-java-common
- com.tencentcloudapi
-
-
- gson
- com.google.code.gson
-
-
-
+
+
com.google.code.gson
gson
-
- com.qcloud
- cos-sts_api
-
-
com.alibaba
transmittable-thread-local
diff --git a/play-common/src/main/java/com/starry/common/config/CosConfig.java b/play-common/src/main/java/com/starry/common/config/CosConfig.java
deleted file mode 100644
index 9894df8..0000000
--- a/play-common/src/main/java/com/starry/common/config/CosConfig.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package com.starry.common.config;
-
-import com.qcloud.cos.COSClient;
-import com.qcloud.cos.ClientConfig;
-import com.qcloud.cos.auth.BasicCOSCredentials;
-import com.qcloud.cos.auth.COSCredentials;
-import com.qcloud.cos.region.Region;
-import lombok.Data;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.stereotype.Component;
-
-/**
- * @author admin
- * 腾讯云cos对象存储配置类
- * @since 2022/10/28
- */
-@Data
-@Component
-@ConfigurationProperties(prefix = "cos")
-public class CosConfig {
- /**
- * 存储桶访问路径
- **/
- private String baseUrl;
- /**
- * 腾讯云账号秘钥
- **/
- private String secretId;
- /**
- * 密码秘钥
- **/
- private String secretKey;
- /**
- * 存储桶地区
- **/
- private String regionName;
- /**
- * 存储桶名称
- **/
- private String bucketName;
- /**
- * 上传的根目录
- **/
- private String folderPrefix;
-
- public COSClient getCosClient() {
- // 初始化用户信息
- COSCredentials cosCredentials = new BasicCOSCredentials(this.secretId, this.secretKey);
- // 设置地域
- Region region = new Region(this.regionName);
- ClientConfig config = new ClientConfig(region);
- // 生成COS客户端
- return new COSClient(cosCredentials, config);
- }
-
-}
diff --git a/play-common/src/main/java/com/starry/common/controller/CosController.java b/play-common/src/main/java/com/starry/common/controller/CosController.java
deleted file mode 100644
index 0047bf3..0000000
--- a/play-common/src/main/java/com/starry/common/controller/CosController.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package com.starry.common.controller;
-
-import com.starry.common.result.R;
-import com.starry.common.utils.file.CosClientUtils;
-import com.tencent.cloud.CosStsClient;
-import com.tencent.cloud.Response;
-import io.swagger.annotations.ApiOperation;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.multipart.MultipartFile;
-
-import java.util.TreeMap;
-
-/**
- * @author admin
- * cos存储前端控制器
- * @since 2022/11/13 17:51
- */
-@Slf4j
-@RestController
-@RequestMapping("/cos")
-public class CosController {
-
- @Value("${cos.secretId}")
- private String secretId;
- @Value("${cos.secretKey}")
- private String secretKey;
- @Value("${cos.regionName}")
- private String regionName;
- @Value("${cos.bucketName}")
- private String bucketName;
-
- @ApiOperation(value = "照片上传")
- @PostMapping("/upload/image")
- public R uploadImage(MultipartFile file) throws Exception {
- if (!file.isEmpty()) {
- String avatar = CosClientUtils.upload(file, "house");
- return R.ok(avatar);
- }
- return R.error("上传照片异常,请联系管理员");
- }
-
- @ApiOperation(value = "获取cos临时密钥")
- @GetMapping("/temp-key")
- public R getTempKey() {
- TreeMap config = new TreeMap<>();
- try {
- // 替换为您的云 api 密钥 SecretId
- config.put("secretId", secretId);
- // 替换为您的云 api 密钥 SecretKey
- config.put("secretKey", secretKey);
- // 临时密钥有效时长,单位是秒,默认 1800 秒,目前主账号最长 2 小时(即 7200 秒),子账号最长 36 小时(即 129600)秒
- config.put("durationSeconds", 1800);
- // 换成您的 bucket
- config.put("bucket", bucketName);
- // 换成 bucket 所在地区
- config.put("region", regionName);
-
- // 只允许用户访问 upload/house 目录下的资源
- config.put("allowPrefixes", new String[]{"upload/house/*"});
-
- // 密钥的权限列表。必须在这里指定本次临时密钥所需要的权限。
- String[] allowActions = new String[]{
- // 简单上传
- "name/cos:PutObject",
- // 表单上传、小程序上传
- "name/cos:PostObject",
- // 分块上传
- "name/cos:InitiateMultipartUpload", "name/cos:ListMultipartUploads", "name/cos:ListParts", "name/cos:UploadPart", "name/cos:CompleteMultipartUpload"};
- config.put("allowActions", allowActions);
-
- Response response = CosStsClient.getCredential(config);
- return R.ok(response);
- } catch (Exception e) {
- log.error("getTempKey error", e);
- throw new IllegalArgumentException("no valid secret !");
- }
- }
-}
diff --git a/play-common/src/main/java/com/starry/common/utils/file/CosClientUtils.java b/play-common/src/main/java/com/starry/common/utils/file/CosClientUtils.java
deleted file mode 100644
index 512c0a3..0000000
--- a/play-common/src/main/java/com/starry/common/utils/file/CosClientUtils.java
+++ /dev/null
@@ -1,95 +0,0 @@
-package com.starry.common.utils.file;
-
-
-import com.qcloud.cos.COSClient;
-import com.qcloud.cos.model.PutObjectRequest;
-import com.qcloud.cos.model.UploadResult;
-import com.qcloud.cos.transfer.TransferManager;
-import com.qcloud.cos.transfer.Upload;
-import com.starry.common.config.CosConfig;
-import com.starry.common.utils.SpringUtils;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.io.FilenameUtils;
-import org.springframework.web.multipart.MultipartFile;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-
-/**
- * @author admin
- * 腾讯云COS文件上传工具类
- * @since 2022/10/31
- */
-@Slf4j
-public class CosClientUtils {
-
- /**
- * 获取配置信息
- */
- private static final CosConfig cosConfig = SpringUtils.getBean(CosConfig.class);
-
- public static String upload(MultipartFile file, String dir) throws Exception {
- String originalFilename = file.getOriginalFilename();
- // 文件名
- String name = FilenameUtils.getBaseName(originalFilename) + "_" + System.currentTimeMillis() + originalFilename.substring(originalFilename.lastIndexOf("."));
- // 目录
- String folderName = cosConfig.getFolderPrefix() + "/" + dir + "/";
- String key = folderName + name;
- File localFile = null;
- try {
- localFile = transferToFile(file);
- String filePath = uploadFileToCos(localFile, key);
- log.info("upload COS successful: {}", filePath);
- return filePath;
- } catch (Exception e) {
- throw new Exception("文件上传失败");
- } finally {
- localFile.delete();
- }
- }
-
- /**
- * 用缓冲区来创建临时文件
- * 使用 MultipartFile.transferTo()
- *
- * @param multipartFile
- * @return
- */
- private static File transferToFile(MultipartFile multipartFile) throws IOException {
- String originalFilename = multipartFile.getOriginalFilename();
- String prefix = originalFilename.split("\\.")[0];
- String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
- File file = File.createTempFile(prefix, suffix);
- multipartFile.transferTo(file);
- return file;
- }
-
- /**
- * 上传文件到COS
- *
- * @param localFile
- * @param key
- * @return
- */
- private static String uploadFileToCos(File localFile, String key) throws InterruptedException {
- PutObjectRequest putObjectRequest = new PutObjectRequest(cosConfig.getBucketName(), key, localFile);
- // 获取连接
- COSClient cosClient = cosConfig.getCosClient();
- // 创建线程池
- ThreadPoolExecutor threadPool = new ThreadPoolExecutor(8, 16,
- 4, TimeUnit.SECONDS, new ArrayBlockingQueue<>(10), new ThreadPoolExecutor.AbortPolicy());
- // 传入一个threadPool, 若不传入线程池, 默认TransferManager中会生成一个单线程的线程池
- TransferManager transferManager = new TransferManager(cosClient, threadPool);
- // 返回一个异步结果Upload, 可同步的调用waitForUploadResult等待upload结束, 成功返回UploadResult, 失败抛出异常
- Upload upload = transferManager.upload(putObjectRequest);
- UploadResult uploadResult = upload.waitForUploadResult();
- transferManager.shutdownNow();
- cosClient.shutdown();
- String filePath = cosConfig.getBaseUrl() + uploadResult.getKey();
- return filePath;
- }
-
-}
diff --git a/pom.xml b/pom.xml
index 08580a7..237840a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -20,6 +20,7 @@
play-admin
play-common
play-generator
+ play-oss
@@ -50,12 +51,18 @@
2.2.11
4.6.0
+
+
5.6.205
+
+ 3.17.4
3.1.1
2.10.1
+ 3.24.3
+ 2.2.5
@@ -127,12 +134,7 @@
easyexcel
${easyexcel.version}
-
-
- com.qcloud
- cos_api
- ${cos-version}
-
+
com.google.code.gson
gson
@@ -145,12 +147,6 @@
1.9.1
-
-
- com.qcloud
- cos-sts_api
- ${cos_sts-version}
-
@@ -170,6 +166,11 @@
play-admin
1.0
+
+ com.aliyun.oss
+ aliyun-sdk-oss
+ ${aliyun-oss.version}
+
@@ -196,6 +197,18 @@
${weixin-java.version}
+
+ org.redisson
+ redisson-spring-boot-starter
+ ${redisson.version}
+
+
+
+ com.baomidou
+ lock4j-redisson-spring-boot-starter
+ ${lock4j.version}
+
+