From a60e866f9d30de8ed50d3cd01c3979dfccb6d94b Mon Sep 17 00:00:00 2001
From: peng <peng.com>
Date: 星期五, 17 十月 2025 09:23:43 +0800
Subject: [PATCH] Merge branch 'dev' into user_action
---
framework/src/main/java/cn/lili/cos/CDNConfigProperty.java | 51 +++++++++++++++++
config/application.yml | 35 +++++++----
consumer/src/main/resources/application.yml | 4
framework/src/main/java/cn/lili/utils/TencentCdnUtil.java | 78 ++++++++++++++++++++++++++
framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoServiceImpl.java | 11 ++-
5 files changed, 162 insertions(+), 17 deletions(-)
diff --git a/config/application.yml b/config/application.yml
index 5bc02c2..f4abaa8 100644
--- a/config/application.yml
+++ b/config/application.yml
@@ -29,9 +29,10 @@
type: redis
# Redis
redis:
- host: 42.193.1.25
+ host: 127.0.0.1
+# host: 42.193.1.25
port: 6379
- password: ycl2018
+# password: ycl2018
database: 12
lettuce:
pool:
@@ -61,11 +62,13 @@
default-datasource:
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
- url: jdbc:mysql://42.193.1.25:3306/lilishop?useUnicode=true&characterEncoding=utf-8&useSSL=false&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
-# url: jdbc:mysql://127.0.0.1:3306/lilishop?useUnicode=true&characterEncoding=utf-8&useSSL=false&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
+# url: jdbc:mysql://42.193.1.25:3306/lilishop?useUnicode=true&characterEncoding=utf-8&useSSL=false&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
+ url: jdbc:mysql://127.0.0.1:3306/lilishop?useUnicode=true&characterEncoding=utf-8&useSSL=false&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
+# url: jdbc:mysql://1.95.67.54:6033/lilishop?useUnicode=true&characterEncoding=utf-8&useSSL=false&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
username: root
- password: 321$YcYl@1970!
-# password: 123456
+# password: 321$YcYl@1970!
+# password: 6c701c021355fc70fc156824e81fbead
+ password: 123456
maxActive: 50
initialSize: 20
maxWait: 60000
@@ -177,7 +180,7 @@
#缂撳瓨寮�鍚�
cache-enabled: true
#鏃ュ織
-# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+ # log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
global-config:
db-config:
#閫昏緫鍒犻櫎閰嶇疆瀛楁
@@ -222,10 +225,10 @@
faultTolerant: 3
system:
isDemoSite: false
- # 鑴辨晱绾у埆锛�
- # 0锛氫笉鍋氳劚鏁忓鐞�
- # 1锛氱鐞嗙鐢ㄦ埛鎵嬫満鍙风瓑淇℃伅鑴辨晱
- # 2锛氬晢瀹剁淇℃伅鑴辨晱锛堜负2鏃讹紝琛ㄧず绠$悊绔紝鍟嗗绔悓鏃惰劚鏁忥級
+ # 鑴辨晱绾у埆锛�
+ # 0锛氫笉鍋氳劚鏁忓鐞�
+ # 1锛氱鐞嗙鐢ㄦ埛鎵嬫満鍙风瓑淇℃伅鑴辨晱
+ # 2锛氬晢瀹剁淇℃伅鑴辨晱锛堜负2鏃讹紝琛ㄧず绠$悊绔紝鍟嗗绔悓鏃惰劚鏁忥級
sensitiveLevel: 1
statistics:
@@ -286,6 +289,8 @@
comment-group: lmk_comment_group
video-topic: lmk_video_topic # 瑙嗛
video-group: lmk_video_group
+ prize-topic: lmk_prize_topic # 鎶藉
+ prize-group: lmk_prize_group
msg-ext-topic: shop_lili_msg_topic
msg-ext-group: shop_lili_msg_group
goods-topic: shop_lili_goods_topic
@@ -328,7 +333,8 @@
durationSeconds: 1800 # STS涓存椂璁块棶鍑瘉鏈夋晥鏈燂紝鍗曚綅绉掞紝榛樿1800s锛屼富璐﹀彿鏈�闀�2灏忔椂锛屽瓙璐﹀彿(ARM鐢ㄦ埛)36灏忔椂
bucket: lmk-1356772813
region: ap-chengdu
- endpoint: https://lmk-1356772813.cos.ap-chengdu.myqcloud.com # 璁块棶鍩熷悕
+# endpoint: https://lmk-1356772813.cos.ap-chengdu.myqcloud.com # 璁块棶鍩熷悕
+ endpoint: https://media.meiyikuang.com # cdn璁块棶鍩熷悕
urlExpireMinute: 360 # 棰勭鍚島rl鏈夋晥鏃堕棿(鍒嗛挓)
actions: # sts鐨勬潈闄�
- cos:GetBucketACL
@@ -354,3 +360,8 @@
- cos:UploadPartCopy
resources: # 鑳芥搷浣滃摢浜涜祫婧�
- qcs::cos::uid/1356772813:lmk-1356772813/*
+
+cdn:
+ secretId: AKIDhIqIbhrwsfJm397vhLp570iEZheQ0OYX
+ secretKey: pQnyzmS4aCi9Skz2tWyFLG0Xu64saBcs
+ cdnDomain: https://media.meiyikuang.com
\ No newline at end of file
diff --git a/consumer/src/main/resources/application.yml b/consumer/src/main/resources/application.yml
index f7351bd..67f0a82 100644
--- a/consumer/src/main/resources/application.yml
+++ b/consumer/src/main/resources/application.yml
@@ -67,9 +67,9 @@
default-datasource:
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
- url: jdbc:mysql://127.0.0.1:3306/lilishop?useUnicode=true&characterEncoding=utf-8&useSSL=false&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
+ url: jdbc:mysql://1.95.67.54:6033/lilishop?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
username: root
- password: 123456
+ password: 6c701c021355fc70fc156824e81fbead
maxActive: 20
initialSize: 5
maxWait: 60000
diff --git a/framework/src/main/java/cn/lili/cos/CDNConfigProperty.java b/framework/src/main/java/cn/lili/cos/CDNConfigProperty.java
new file mode 100644
index 0000000..b2c486d
--- /dev/null
+++ b/framework/src/main/java/cn/lili/cos/CDNConfigProperty.java
@@ -0,0 +1,51 @@
+package cn.lili.cos;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * 璇诲彇閰嶇疆鏂囦欢鍏充簬cos鐨勯厤缃�
+ *
+ * @author锛歺p
+ * @date锛�2025/5/16 16:23
+ */
+@Configuration
+@ConfigurationProperties(prefix = "cdn")
+public class CDNConfigProperty {
+
+ /**
+ * 鑵捐ARM鐢ㄦ埛鐨剆ecretId
+ */
+ private String secretId;
+
+ /**
+ * 鑵捐ARM鐢ㄦ埛鐨剆ecretKey
+ */
+ private String secretKey;
+
+ private String cdnDomain;
+
+ public String getSecretId() {
+ return secretId;
+ }
+
+ public void setSecretId(String secretId) {
+ this.secretId = secretId;
+ }
+
+ public String getSecretKey() {
+ return secretKey;
+ }
+
+ public void setSecretKey(String secretKey) {
+ this.secretKey = secretKey;
+ }
+
+ public String getCdnDomain() {
+ return cdnDomain;
+ }
+
+ public void setCdnDomain(String cdnDomain) {
+ this.cdnDomain = cdnDomain;
+ }
+}
diff --git a/framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoServiceImpl.java b/framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoServiceImpl.java
index 9b1ef82..6e7c7cb 100644
--- a/framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoServiceImpl.java
+++ b/framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoServiceImpl.java
@@ -26,6 +26,7 @@
import cn.lili.rocketmq.tags.CommentTagsEnum;
import cn.lili.rocketmq.tags.VideoTagsEnum;
import cn.lili.utils.COSUtil;
+import cn.lili.utils.TencentCdnUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import cn.lili.modules.lmk.mapper.VideoMapper;
@@ -92,6 +93,7 @@
private final RocketMQTemplate rocketMQTemplate;
private final ThumbsUpRecordService thumbsUpRecordService;
private final ElasticsearchOperations restTemplate;
+ private final TencentCdnUtil cdnUtil;
@Qualifier("videoEsServiceImpl")
private final EsService esService;
@@ -588,6 +590,9 @@
video.setAuditPassTime(new Date());
fields.put("status", VideoStatusEnum.PUBLISHED.getValue());
+
+ // 璋僣dn棰勭儹
+ cdnUtil.pushUrlsCache(new String[]{video.getCoverUrl(), video.getVideoFileKey()});
} else {
video.setStatus(VideoStatusEnum.REJECT.getValue());
fields.put("status", VideoStatusEnum.REJECT.getValue());
@@ -600,6 +605,7 @@
dto.setFields(fields);
String destination = rocketmqCustomProperties.getVideoTopic() + ":" + VideoTagsEnum.ES_DOC_UPDATE_SOME_FIELD.name();
rocketMQTemplate.asyncSend(destination, JSON.toJSONString(dto), RocketmqSendCallbackBuilder.commonCallback());
+
return Result.ok();
}
@@ -738,7 +744,7 @@
v.setCollectNum(this.getCollectNum(v.getId(), v.getCollectNum()));
v.setThumbsUpNum(this.getThumbsUpNum(v.getId(), v.getThumbsUpNum()));
String authorAvatar = v.getAuthorAvatar();
- if (StringUtils.isNotBlank(authorAvatar)&&!authorAvatar.contains("http")) {
+ if (StringUtils.isNotBlank(authorAvatar) && !authorAvatar.contains("http")) {
v.setAuthorAvatar(cosUtil.getPreviewUrl(v.getAuthorAvatar()));
}
if (VideoContentTypeEnum.VIDEO.getValue().equals(v.getVideoContentType())) {
@@ -860,7 +866,6 @@
}
/**
- *
* @param page
* @param videoId videoId鎺ㄨ崘鐨勮棰慽d
*/
@@ -1541,7 +1546,7 @@
v.setAuthorAvatar(cosUtil.getPreviewUrl(v.getAuthorAvatar()));
if (VideoContentTypeEnum.VIDEO.getValue().equals(v.getVideoContentType())) {
v.setVideoUrl(cosUtil.getPreviewUrl(v.getVideoFileKey()));
- if(StringUtils.isNotBlank(v.getCoverFileKey())){
+ if (StringUtils.isNotBlank(v.getCoverFileKey())) {
v.setCoverUrl(cosUtil.getPreviewUrl(v.getCoverFileKey()));
}
diff --git a/framework/src/main/java/cn/lili/utils/TencentCdnUtil.java b/framework/src/main/java/cn/lili/utils/TencentCdnUtil.java
new file mode 100644
index 0000000..de2653e
--- /dev/null
+++ b/framework/src/main/java/cn/lili/utils/TencentCdnUtil.java
@@ -0,0 +1,78 @@
+package cn.lili.utils;
+
+import cn.lili.cos.CDNConfigProperty;
+import com.tencentcloudapi.cdn.v20180606.CdnClient;
+import com.tencentcloudapi.cdn.v20180606.models.DescribePushTasksRequest;
+import com.tencentcloudapi.cdn.v20180606.models.DescribePushTasksResponse;
+import com.tencentcloudapi.cdn.v20180606.models.PushUrlsCacheRequest;
+import com.tencentcloudapi.cdn.v20180606.models.PushUrlsCacheResponse;
+import com.tencentcloudapi.common.Credential;
+import com.tencentcloudapi.common.exception.TencentCloudSDKException;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import java.util.Arrays;
+
+@Slf4j
+@Service
+@RequiredArgsConstructor
+public class TencentCdnUtil {
+ private final CDNConfigProperty cdnConfigProperty;
+
+ public void pushUrlsCache(String[] urls) {
+ try {
+ // 棰勫鐞哢RLs锛屾坊鍔燙DN鍩熷悕
+ String[] processedUrls = processUrlsWithCdnDomain(urls);
+
+ log.info("cdn閾炬帴锛歿}", Arrays.toString(processedUrls));
+ // 涓轰簡淇濇姢瀵嗛挜瀹夊叏锛屽缓璁皢瀵嗛挜璁剧疆鍦ㄧ幆澧冨彉閲忎腑鎴栬�呴厤缃枃浠朵腑锛岃鍙傝�冩湰鏂囧嚟璇佺鐞嗙珷鑺傘��
+ // 纭紪鐮佸瘑閽ュ埌浠g爜涓湁鍙兘闅忎唬鐮佹硠闇茶�屾毚闇诧紝鏈夊畨鍏ㄩ殣鎮o紝骞朵笉鎺ㄨ崘銆�
+ Credential cred = new Credential(cdnConfigProperty.getSecretId(), cdnConfigProperty.getSecretKey());
+ CdnClient client = new CdnClient(cred, "ap-guangzhou");
+
+ PushUrlsCacheRequest req = new PushUrlsCacheRequest();
+ req.setUrls(processedUrls);
+
+ PushUrlsCacheResponse resp = client.PushUrlsCache(req);
+
+ log.info("cdn棰勭儹杩斿洖锛歿}", client.gson.toJson(resp));
+
+ } catch (TencentCloudSDKException e) {
+ log.warn("cdn棰勭儹澶辫触锛歿}", e.toString());
+ }
+ }
+
+ /**
+ * 澶勭悊URL鍒楄〃锛屽湪姣忎釜URL鍓嶆坊鍔燙DN鍩熷悕
+ *
+ * @param urls 鍘熷URL鍒楄〃
+ * @return 娣诲姞浜咰DN鍩熷悕鐨勫畬鏁碪RL鍒楄〃
+ */
+ public String[] processUrlsWithCdnDomain(String[] urls) {
+ if (urls == null || urls.length == 0) {
+ return urls;
+ }
+
+ String cdnDomain = cdnConfigProperty.getCdnDomain();
+ if (cdnDomain == null || cdnDomain.isEmpty()) {
+ return urls;
+ }
+
+ String[] processedUrls = new String[urls.length];
+ for (int i = 0; i < urls.length; i++) {
+ // 濡傛灉URL宸茬粡鍖呭惈鍗忚锛屽垯鐩存帴鎷兼帴
+ if (urls[i].startsWith("http://") || urls[i].startsWith("https://")) {
+ processedUrls[i] = urls[i];
+ } else {
+ // 纭繚cdnDomain鏈熬娌℃湁鏂滄潬锛寀rls寮�澶存病鏈夋枩鏉�
+ String domain = cdnDomain.endsWith("/") ? cdnDomain.substring(0, cdnDomain.length() - 1) : cdnDomain;
+ String path = urls[i].startsWith("/") ? urls[i].substring(1) : urls[i];
+ processedUrls[i] = domain + "/" + path;
+ }
+ }
+
+ return processedUrls;
+ }
+
+}
--
Gitblit v1.8.0