From 60ae989adaef7383522235376ec3f67ad3a8070d Mon Sep 17 00:00:00 2001
From: zhanghua <314079846@qq.com>
Date: 星期四, 16 十月 2025 22:36:14 +0800
Subject: [PATCH] 视频审核通过对视频文件进行预热

---
 framework/src/main/java/cn/lili/cos/CDNConfigProperty.java                     |   51 ++++++++++++
 config/application.yml                                                         |   41 ++++++---
 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, 166 insertions(+), 19 deletions(-)

diff --git a/config/application.yml b/config/application.yml
index 5bc02c2..8998de7 100644
--- a/config/application.yml
+++ b/config/application.yml
@@ -29,9 +29,14 @@
     type: redis
   # Redis
   redis:
-    host: 42.193.1.25
+    host: 127.0.0.1
+#    host: 42.193.1.25
     port: 6379
-    password: ycl2018
+#    password: MuKang2025
+#    host: 1.95.67.54
+#    #    host: 42.193.1.25
+#    port: 9736
+#    password: myk2025redis
     database: 12
     lettuce:
       pool:
@@ -61,11 +66,12 @@
       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://127.0.0.1:3306/lilishop?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
         username: root
-        password: 321$YcYl@1970!
-#        password: 123456
+        password: 123456
+#        url: jdbc:mysql://1.95.67.54:6033/lilishop?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
+#        username: root
+#        password: 6c701c021355fc70fc156824e81fbead
         maxActive: 50
         initialSize: 20
         maxWait: 60000
@@ -177,7 +183,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 +228,10 @@
     faultTolerant: 3
   system:
     isDemoSite: false
-  #     鑴辨晱绾у埆锛�
-  #     0锛氫笉鍋氳劚鏁忓鐞�
-  #     1锛氱鐞嗙鐢ㄦ埛鎵嬫満鍙风瓑淇℃伅鑴辨晱
-  #     2锛氬晢瀹剁淇℃伅鑴辨晱锛堜负2鏃讹紝琛ㄧず绠$悊绔紝鍟嗗绔悓鏃惰劚鏁忥級
+    #     鑴辨晱绾у埆锛�
+    #     0锛氫笉鍋氳劚鏁忓鐞�
+    #     1锛氱鐞嗙鐢ㄦ埛鎵嬫満鍙风瓑淇℃伅鑴辨晱
+    #     2锛氬晢瀹剁淇℃伅鑴辨晱锛堜负2鏃讹紝琛ㄧず绠$悊绔紝鍟嗗绔悓鏃惰劚鏁忥級
     sensitiveLevel: 1
 
   statistics:
@@ -267,7 +273,7 @@
   data:
     elasticsearch:
       cluster-name: elasticsearch
-      cluster-nodes: 127.0.0.1:9200
+      cluster-nodes: 1.95.67.54:9200
       index:
         number-of-replicas: 0
         number-of-shards: 3
@@ -277,8 +283,8 @@
     #        username: elastic
     #        password: LiLiShopES
 
-#    logstash:
-#      server: 127.0.0.1:30560
+    #    logstash:
+    #      server: 127.0.0.1:30560
     rocketmq:
       promotion-topic: shop_lili_promotion_topic
       promotion-group: shop_lili_promotion_group
@@ -286,6 +292,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
@@ -354,3 +362,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