From 76f3d1eeefc239f1a8d5b52d061640536b649d36 Mon Sep 17 00:00:00 2001
From: DB <2502523450@qq.com>
Date: Tue, 31 Oct 2023 18:35:03 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0cdn=E4=B8=8A=E4=BC=A0?=
=?UTF-8?q?=EF=BC=8C=E4=BF=AE=E8=AE=A2=E5=95=86=E5=93=81=E7=AE=A1=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitignore | 2 +-
Cpop-Core/pom.xml | 10 ++
.../core/config/TencentCosProperties.java | 40 +++++
.../cpop/core/handler/TencentCosHandler.java | 154 ++++++++++++++++++
.../src/main/resources/application-core.yml | 12 ++
.../src/main/resources/application-dev.yml | 16 +-
.../src/main/resources/application.yml | 2 +-
.../src/main/resources/logback.xml | 64 ++++++++
.../com/cpop/mall/business/bo/ProductBo.java | 6 +
.../cpop/mall/business/bo/ProductPageBo.java | 12 ++
.../mall/business/bo/ProductRecordBo.java | 6 +
.../backstage/BackstageProductController.java | 14 ++
.../cpop/mall/business/entity/Product.java | 5 +
.../service/impl/ProductServiceImpl.java | 9 +-
.../cpop/mall/business/vo/ProductPageVo.java | 2 +
.../mall/business/vo/ProductRecordVo.java | 6 +
.../controller/SysCommonController.java | 25 +++
17 files changed, 373 insertions(+), 12 deletions(-)
create mode 100644 Cpop-Core/src/main/java/com/cpop/core/config/TencentCosProperties.java
create mode 100644 Cpop-Core/src/main/java/com/cpop/core/handler/TencentCosHandler.java
create mode 100644 Cpop-Core/src/main/resources/application-core.yml
create mode 100644 Cpop-Mall/Cpop-Mall-Web/src/main/resources/logback.xml
diff --git a/.gitignore b/.gitignore
index 2867377..74dbdaa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,7 +19,7 @@ target/
*.iws
*.iml
*.ipr
-
+*.log
### NetBeans ###
/nbproject/private/
/nbbuild/
diff --git a/Cpop-Core/pom.xml b/Cpop-Core/pom.xml
index 70d1a9b..1b56efb 100644
--- a/Cpop-Core/pom.xml
+++ b/Cpop-Core/pom.xml
@@ -97,6 +97,16 @@
org.springframework.boot
spring-boot-starter-quartz
+
+
+ com.qcloud
+ cos_api
+
+
+
+ org.bouncycastle
+ bcprov-jdk15on
+
diff --git a/Cpop-Core/src/main/java/com/cpop/core/config/TencentCosProperties.java b/Cpop-Core/src/main/java/com/cpop/core/config/TencentCosProperties.java
new file mode 100644
index 0000000..52ddb83
--- /dev/null
+++ b/Cpop-Core/src/main/java/com/cpop/core/config/TencentCosProperties.java
@@ -0,0 +1,40 @@
+package com.cpop.core.config;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+/**
+ * @author DB
+ * @createTime 2023/10/31 15:46
+ * @description 腾讯yun配置
+ */
+@Data
+@ConfigurationProperties(prefix = "tencent.cos")
+public class TencentCosProperties {
+
+ /**
+ * id
+ */
+ private String secretId;
+
+ /**
+ * 密钥
+ */
+ private String secretKey;
+
+ /**
+ * 桶名
+ */
+ private String bucketName;
+
+ /**
+ * 加速路径
+ */
+ private String cdnUrl;
+
+ /**
+ * 地区
+ */
+ private String region;
+
+}
diff --git a/Cpop-Core/src/main/java/com/cpop/core/handler/TencentCosHandler.java b/Cpop-Core/src/main/java/com/cpop/core/handler/TencentCosHandler.java
new file mode 100644
index 0000000..ed86c5a
--- /dev/null
+++ b/Cpop-Core/src/main/java/com/cpop/core/handler/TencentCosHandler.java
@@ -0,0 +1,154 @@
+package com.cpop.core.handler;
+
+import com.cpop.core.base.exception.UtilException;
+import com.cpop.core.config.TencentCosProperties;
+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.http.HttpProtocol;
+import com.qcloud.cos.model.ObjectMetadata;
+import com.qcloud.cos.model.PutObjectRequest;
+import com.qcloud.cos.model.StorageClass;
+import com.qcloud.cos.model.UploadResult;
+import com.qcloud.cos.region.Region;
+import com.qcloud.cos.transfer.TransferManager;
+import com.qcloud.cos.transfer.TransferManagerConfiguration;
+import com.qcloud.cos.transfer.Upload;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.stereotype.Component;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ * @author DB
+ * @createTime 2023/10/31 15:03
+ * @description 腾讯云SDK相关工具类
+ */
+@Component
+@EnableConfigurationProperties(TencentCosProperties.class)
+public class TencentCosHandler {
+
+ /**
+ * 腾讯云配置
+ */
+ @Autowired
+ private TencentCosProperties properties;
+
+ /**
+ * @descriptions 创建 TransferManager 实例,这个实例用来后续调用高级接口
+ * @author DB
+ * @date 2023/10/31 16:48
+ * @return: com.qcloud.cos.transfer.TransferManager
+ */
+ private TransferManager createTransferManager() {
+ // 创建一个 COSClient 实例,这是访问 COS 服务的基础实例。
+ // 详细代码参见本页: 简单操作 -> 创建 COSClient
+ COSClient cosClient = createCosClient();
+ // 自定义线程池大小,建议在客户端与 COS 网络充足(例如使用腾讯云的 CVM,同地域上传 COS)的情况下,设置成16或32即可,可较充分的利用网络资源
+ // 对于使用公网传输且网络带宽质量不高的情况,建议减小该值,避免因网速过慢,造成请求超时。
+ ExecutorService threadPool = Executors.newFixedThreadPool(32);
+ // 传入一个 threadPool, 若不传入线程池,默认 TransferManager 中会生成一个单线程的线程池。
+ TransferManager transferManager = new TransferManager(cosClient, threadPool);
+ // 设置高级接口的配置项
+ // 分块上传阈值和分块大小分别为 5MB 和 1MB
+ TransferManagerConfiguration transferManagerConfiguration = new TransferManagerConfiguration();
+ transferManagerConfiguration.setMultipartUploadThreshold(5 * 1024 * 1024);
+ transferManagerConfiguration.setMinimumUploadPartSize(1 * 1024 * 1024);
+ transferManager.setConfiguration(transferManagerConfiguration);
+ return transferManager;
+ }
+
+ /**
+ * @descriptions 创建 COSClient 实例,这个实例用来后续调用请求
+ * @author DB
+ * @date 2023/10/31 16:47
+ * @return: com.qcloud.cos.COSClient
+ */
+ private COSClient createCosClient() {
+ // 设置用户身份信息。
+ // SECRETID 和 SECRETKEY 请登录访问管理控制台 https://console.cloud.tencent.com/cam/capi 进行查看和管理
+ // 用户的 SecretId,建议使用子账号密钥,授权遵循最小权限指引,降低使用风险。子账号密钥获取可参见 https://cloud.tencent.com/document/product/598/37140
+ String secretId = properties.getSecretId();
+ // 用户的 SecretKey,建议使用子账号密钥,授权遵循最小权限指引,降低使用风险。子账号密钥获取可参见 https://cloud.tencent.com/document/product/598/37140
+ String secretKey = properties.getSecretKey();
+ COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
+ // ClientConfig 中包含了后续请求 COS 的客户端设置:
+ ClientConfig clientConfig = new ClientConfig();
+ // 设置 bucket 的地域
+ // COS_REGION 请参见 https://cloud.tencent.com/document/product/436/6224
+ clientConfig.setRegion(new Region(properties.getRegion()));
+ // 设置请求协议, http 或者 https
+ // 5.6.53 及更低的版本,建议设置使用 https 协议
+ // 5.6.54 及更高版本,默认使用了 https
+ clientConfig.setHttpProtocol(HttpProtocol.https);
+ // 以下的设置,是可选的:
+ // 设置 socket 读取超时,默认 30s
+ clientConfig.setSocketTimeout(30 * 1000);
+ // 设置建立连接超时,默认 30s
+ clientConfig.setConnectionTimeout(30 * 1000);
+ // 如果需要的话,设置 http 代理,ip 以及 port
+ //clientConfig.setHttpProxyIp("httpProxyIp");
+ //clientConfig.setHttpProxyPort(80);
+ // 生成 cos 客户端。
+ return new COSClient(cred, clientConfig);
+ }
+
+ /**
+ * @descriptions 关闭 TransferManager
+ * @author DB
+ * @date 2023/10/31 17:09
+ * @param transferManager 管理器
+ * @return: void
+ */
+ private void shutdownTransferManager(TransferManager transferManager) {
+ // 指定参数为 true, 则同时会关闭 transferManager 内部的 COSClient 实例。
+ // 指定参数为 false, 则不会关闭 transferManager 内部的 COSClient 实例。
+ transferManager.shutdownNow(true);
+ }
+
+ /**
+ * @descriptions cdn上传
+ * @author DB
+ * @date 2023/10/31 17:21
+ * @param file 文件
+ * @return: com.qcloud.cos.model.UploadResult
+ */
+ public UploadResult cdnUpload(MultipartFile file) {
+ TransferManager transferManager = createTransferManager();
+ try {
+ ObjectMetadata objectMetadata = new ObjectMetadata();
+ // 上传的流如果能够获取准确的流长度,则推荐一定填写 content-length
+ // 如果确实没办法获取到,则下面这行可以省略,但同时高级接口也没办法使用分块上传了
+ objectMetadata.setContentLength(file.getSize());
+ objectMetadata.setContentType(file.getContentType());
+ InputStream inputStream = file.getInputStream();
+ PutObjectRequest putObjectRequest = new PutObjectRequest(properties.getBucketName(), properties.getSecretKey(),inputStream , objectMetadata);
+ // 设置存储类型(如有需要,不需要请忽略此行代码), 默认是标准(Standard), 低频(standard_ia)
+ // 更多存储类型请参见 https://cloud.tencent.com/document/product/436/33417
+ putObjectRequest.setStorageClass(StorageClass.Standard_IA);
+ Upload upload = transferManager.upload(putObjectRequest);
+ inputStream.close();
+ return upload.waitForUploadResult();
+ } catch (IOException | InterruptedException e) {
+ throw new UtilException(e);
+ } finally {
+ shutdownTransferManager(transferManager);
+ }
+ }
+
+ /**
+ * @descriptions 获取cdn路径
+ * @author DB
+ * @date 2023/10/31 17:56
+ * @return: java.lang.String
+ */
+ public String getCdnUrl(){
+ return properties.getCdnUrl();
+ }
+}
diff --git a/Cpop-Core/src/main/resources/application-core.yml b/Cpop-Core/src/main/resources/application-core.yml
new file mode 100644
index 0000000..921bc44
--- /dev/null
+++ b/Cpop-Core/src/main/resources/application-core.yml
@@ -0,0 +1,12 @@
+tencent:
+ cos:
+ #id
+ secretId: AKIDFK8hz0kDRP6XjdGciX5LK3VfYBWaMs7V
+ #密钥
+ secretKey: 92g38wUlkSt50e17wUllUw71pMcaIjtl
+ #
+ bucketName: dataresource-1302318474
+ #cdn地址
+ cdnUrl: .cos.accelerate.myqcloud.com/
+ #地区
+ region: ap-guangzhou
diff --git a/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application-dev.yml b/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application-dev.yml
index dbf9d9b..4c65ecb 100644
--- a/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application-dev.yml
+++ b/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application-dev.yml
@@ -19,13 +19,13 @@ spring:
#redis配置
redis:
#地址
- host: localhost
+ host: 106.52.49.102
#端口
- port: 6379
+ port: 6333
#数据库
- database: 0
+ database: 10
#密码
- password:
+ password: Jambox.123*
#连接超时
timeout: 5000
jedis:
@@ -55,9 +55,9 @@ mybatis-flex:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
datasource:
mall:
- url: jdbc:mysql://localhost:3306/cpop-dev?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
+ url: jdbc:mysql://sh-cynosdbmysql-grp-fggo83js.sql.tencentcdb.com:20965/cpop_test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root
- password: root
+ password: Customer0401
jambox:
url: jdbc:mysql://sh-cynosdbmysql-grp-fggo83js.sql.tencentcdb.com:20965/jambox_test?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true
username: root
@@ -105,4 +105,6 @@ logging:
wx:
pay:
#通知地址
- notifyUrl: https://frp-oak.top:11899/Cpop-Mall/wxPay/callback/notify/order
\ No newline at end of file
+ notifyUrl: https://frp-oak.top:11899/Cpop-Mall/wxPay/callback/notify/order
+ #支付成功
+ notifyRefund: https://frp-oak.top:11899/Cpop-Mall/wxPay/callback/notify/refund
\ No newline at end of file
diff --git a/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application.yml b/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application.yml
index dc90df2..d9036c8 100644
--- a/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application.yml
+++ b/Cpop-Mall/Cpop-Mall-Web/src/main/resources/application.yml
@@ -31,7 +31,7 @@ spring:
max-file-size: 1024MB
max-request-size: 300MB
profiles:
- active: test,mall,system
+ active: dev,core,mall,system
datasource:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
diff --git a/Cpop-Mall/Cpop-Mall-Web/src/main/resources/logback.xml b/Cpop-Mall/Cpop-Mall-Web/src/main/resources/logback.xml
new file mode 100644
index 0000000..53bd533
--- /dev/null
+++ b/Cpop-Mall/Cpop-Mall-Web/src/main/resources/logback.xml
@@ -0,0 +1,64 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ [%d{yyyy-MM-dd HH:mm:ss.SSS}] %level [%thread] %file:%line - %msg%n
+ UTF-8
+
+
+
+
+ ${LOG_HOME}/${LOG_PREFIX}-info.log
+ true
+
+
+ INFO
+ ACCEPT
+ DENY
+
+
+ ${LOG_HOME}/${LOG_PREFIX}-info-%d{yyyyMMdd}.log.%d
+ 7
+
+
+ [%d{yyyy-MM-dd HH:mm:ss.SSS}] %level [%thread] %file:%line - %msg%n
+ UTF-8
+
+
+
+
+ ${LOG_HOME}/${LOG_PREFIX}-error.log
+ true
+
+
+ ERROR
+ ACCEPT
+ DENY
+
+
+ ${LOG_HOME}/${LOG_PREFIX}-error-%d{yyyyMMdd}.log.%d
+ 7
+
+
+ [%d{yyyy-MM-dd HH:mm:ss.SSS}] %level [%thread] %file:%line - %msg%n
+ UTF-8
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/bo/ProductBo.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/bo/ProductBo.java
index f351565..98b00be 100644
--- a/Cpop-Mall/src/main/java/com/cpop/mall/business/bo/ProductBo.java
+++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/bo/ProductBo.java
@@ -89,6 +89,12 @@ public class ProductBo implements Serializable {
@ApiModelProperty("购买限制(0:会员限制;1:新客限定;2:用户限购)")
private Integer buyRestrict;
+ /**
+ * 限制数量
+ */
+ @ApiModelProperty("限制数量")
+ private Long limitNum;
+
/**
* 规格集合
*/
diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/bo/ProductPageBo.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/bo/ProductPageBo.java
index 1315cac..d6646d7 100644
--- a/Cpop-Mall/src/main/java/com/cpop/mall/business/bo/ProductPageBo.java
+++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/bo/ProductPageBo.java
@@ -55,4 +55,16 @@ public class ProductPageBo implements Serializable {
@ApiModelProperty("产品id")
private String productId;
+ /**
+ * 上下架
+ */
+ @ApiModelProperty("上下架")
+ private Boolean isUp;
+
+ /**
+ * 授权校区
+ */
+ @ApiModelProperty("授权校区")
+ private String authorizedStoreId;
+
}
diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/bo/ProductRecordBo.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/bo/ProductRecordBo.java
index ec22bae..9b80a48 100644
--- a/Cpop-Mall/src/main/java/com/cpop/mall/business/bo/ProductRecordBo.java
+++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/bo/ProductRecordBo.java
@@ -49,4 +49,10 @@ public class ProductRecordBo implements Serializable {
*/
@ApiModelProperty("记录消耗积分")
private Integer recordPoints;
+
+ /**
+ * 乐观锁标记
+ */
+ @ApiModelProperty("乐观锁标记")
+ private Integer version;
}
diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/controller/backstage/BackstageProductController.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/controller/backstage/BackstageProductController.java
index fa1ad78..285a338 100644
--- a/Cpop-Mall/src/main/java/com/cpop/mall/business/controller/backstage/BackstageProductController.java
+++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/controller/backstage/BackstageProductController.java
@@ -170,6 +170,20 @@ public class BackstageProductController {
return R.ok();
}
+ /**
+ * @descriptions 商城商品置顶
+ * @author DB
+ * @date 2023/10/23 12:15
+ * @param productId 商城-商品id
+ * @return: com.cpop.core.base.R
+ */
+ @PutMapping("/productIsTop")
+ @ApiOperation("商城商品置顶")
+ public R productIsTop(@RequestParam("productId") @ApiParam(value = "商城-商品Id",required = true) String productId) {
+ productService.updateChain().setRaw(PRODUCT.IS_TOP, "if(is_top = 0, 1, 0)").where(PRODUCT.ID.eq(productId)).update();
+ return R.ok();
+ }
+
}
diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/entity/Product.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/entity/Product.java
index 6a0144d..91d12c4 100644
--- a/Cpop-Mall/src/main/java/com/cpop/mall/business/entity/Product.java
+++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/entity/Product.java
@@ -90,6 +90,11 @@ public class Product extends BaseEntity implements Serializable {
*/
private Boolean isUp;
+ /**
+ * 是否置顶
+ */
+ private Boolean isTop;
+
/**
* 最高价
*/
diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/ProductServiceImpl.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/ProductServiceImpl.java
index d649c70..b95f360 100644
--- a/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/ProductServiceImpl.java
+++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/ProductServiceImpl.java
@@ -89,6 +89,10 @@ public class ProductServiceImpl extends ServiceImpl impl
.and(PRODUCT.PRODUCT_NAME.like(bo.getProductName()))
.and(PRODUCT.PRODUCT_TYPE.eq(bo.getProductType()))
.and(PRODUCT.BUY_RESTRICT.eq(bo.getBuyRestrict()))
+ .and(PRODUCT.IS_UP.eq(bo.getIsUp()))
+ .and(PRODUCT.STORE_IDS.like(bo.getAuthorizedStoreId()))
+ //置顶
+ .orderBy(PRODUCT.IS_TOP.desc())
.orderBy(PRODUCT.CREATE_TIME.desc())
.orderBy(pageDomain.getOrderByColumn()),
ProductPageVo.class,
@@ -244,15 +248,14 @@ public class ProductServiceImpl extends ServiceImpl impl
productSpecifications.forEach(item -> {
item.setProductId(product.getId());
});
- productSpecificationService.saveBatch(productSpecifications);
+ productSpecificationService.updateBatch(productSpecifications);
//存商品记录详情
List recordList = BeanUtils.mapToList(bo.getRecordList(), ProductRecord.class);
ProductRecordService specificationRecordService = SpringUtils.getBean(ProductRecordService.class);
- specificationRecordService.updateChain().where(PRODUCT_RECORD.PRODUCT_ID.eq(product.getId())).remove();
recordList.forEach(item -> {
item.setProductId(product.getId());
});
- specificationRecordService.saveBatch(recordList);
+ specificationRecordService.updateBatch(recordList);
}
/**
diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/vo/ProductPageVo.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/vo/ProductPageVo.java
index 2ea347c..66e3e42 100644
--- a/Cpop-Mall/src/main/java/com/cpop/mall/business/vo/ProductPageVo.java
+++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/vo/ProductPageVo.java
@@ -1,5 +1,6 @@
package com.cpop.mall.business.vo;
+import com.cpop.core.annontation.StringArrayConvert;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.mybatisflex.annotation.RelationOneToMany;
import io.swagger.annotations.ApiModel;
@@ -49,6 +50,7 @@ public class ProductPageVo implements Serializable {
/**
* 商店(校区)集合
*/
+ @StringArrayConvert
@ApiModelProperty("商店(校区)集合")
private String storeIds;
diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/vo/ProductRecordVo.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/vo/ProductRecordVo.java
index 0a9a9bd..3a393a5 100644
--- a/Cpop-Mall/src/main/java/com/cpop/mall/business/vo/ProductRecordVo.java
+++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/vo/ProductRecordVo.java
@@ -56,4 +56,10 @@ public class ProductRecordVo implements Serializable {
*/
@ApiModelProperty("记录消耗积分")
private Integer recordPoints;
+
+ /**
+ * 标记
+ */
+ @ApiModelProperty("标记")
+ private Integer version;
}
diff --git a/Cpop-System/src/main/java/com/cpop/system/business/controller/SysCommonController.java b/Cpop-System/src/main/java/com/cpop/system/business/controller/SysCommonController.java
index d2512fb..c1e3a48 100644
--- a/Cpop-System/src/main/java/com/cpop/system/business/controller/SysCommonController.java
+++ b/Cpop-System/src/main/java/com/cpop/system/business/controller/SysCommonController.java
@@ -3,9 +3,11 @@ package com.cpop.system.business.controller;
import com.cpop.core.base.R;
import com.cpop.core.config.CpopConfig;
import com.cpop.core.config.ServerConfig;
+import com.cpop.core.handler.TencentCosHandler;
import com.cpop.core.utils.file.FileUploadUtils;
import com.cpop.core.utils.file.FileUtils;
import com.cpop.system.business.vo.SysFileVo;
+import com.qcloud.cos.model.UploadResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
@@ -32,6 +34,9 @@ public class SysCommonController {
@Autowired
private CpopConfig cpopConfig;
+ @Autowired
+ private TencentCosHandler tencentCosHandler;
+
/**
* 通用上传请求(单个)
*/
@@ -56,4 +61,24 @@ public class SysCommonController {
return R.fail(e.getMessage());
}
}
+
+ /**
+ * @descriptions cdn加速上传
+ * @author DB
+ * @date 2023/10/31 17:24
+ * @param file 文件
+ * @return: com.cpop.core.base.R
+ */
+ @ApiOperation("cdn加速上传")
+ @PostMapping("/cdnUpload")
+ public R cdnUpload(MultipartFile file) {
+ UploadResult uploadResult = tencentCosHandler.cdnUpload(file);
+ String filename = FileUploadUtils.getInstance().extractFilename(file);
+ SysFileVo sysFileVo = new SysFileVo();
+ sysFileVo.setUrl( "https://" + uploadResult.getBucketName() + tencentCosHandler.getCdnUrl() + uploadResult.getKey())
+ .setFileName(filename)
+ .setNewFileName(FileUtils.getInstance().getName(filename))
+ .setOriginalFilename(file.getOriginalFilename());
+ return R.ok(sysFileVo);
+ }
}