From add46ca247cb527b0e8fabd217ac73e84ac7e5cd Mon Sep 17 00:00:00 2001
From: zxl <763096477@qq.com>
Date: 星期一, 04 八月 2025 18:11:38 +0800
Subject: [PATCH] 主页视频,厨神,大健康,商品二维码优惠卷领取状态,优惠卷领取状态

---
 framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoServiceImpl.java |   82 ++++++++++++++++++++++++++++++++++++++--
 1 files changed, 77 insertions(+), 5 deletions(-)

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 da35abc..c2f1777 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
@@ -4,6 +4,7 @@
 import cn.lili.cache.CachePrefix;
 import cn.lili.common.properties.RocketmqCustomProperties;
 import cn.lili.common.security.context.UserContext;
+import cn.lili.common.utils.CommonUtil;
 import cn.lili.elasticsearch.EsSuffix;
 import cn.lili.modules.lmk.constant.RedisKeyExpireConstant;
 import cn.lili.modules.lmk.domain.dto.VideoEsUpdateDTO;
@@ -46,6 +47,7 @@
 import org.springframework.data.elasticsearch.core.SearchHits;
 import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
 import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 import lombok.RequiredArgsConstructor;
 import cn.lili.utils.PageUtil;
@@ -54,6 +56,8 @@
 import org.springframework.util.Assert;
 
 import java.util.*;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 /**
@@ -423,6 +427,12 @@
             page.getRecords().forEach(v -> {
                 v.setTagList(tagMap.get(v.getId()));
                 v.setCoverUrl(cosUtil.getPreviewUrl(v.getCoverUrl()));
+                v.getGoodsList().forEach(goods ->{
+                    if (StringUtils.isNotBlank(goods.getThumbnail())&&!goods.getThumbnail().contains("http")) {
+                        goods.setThumbnail(cosUtil.getPreviewUrl(goods.getThumbnail()));
+                    }
+
+                });
             });
         }
         return Result.ok().data(page.getRecords()).total(page.getTotal());
@@ -547,6 +557,17 @@
         switch (query.getVideoFrom()) {
             case "recommend":// 鍔犺浇鎺ㄨ崘瑙嗛
                 baseMapper.recommendVideo(page, query);
+                //鎺ㄨ崘瑙嗛閲嶆柊鎺掑簭
+                buildRecommendVideoList(page, query.getVideoId());
+//                WxVideoVO wxVideoVO = null;
+//                if (StringUtils.isNotBlank(query.getVideoId())) {
+//                    wxVideoVO  = baseMapper.recommendVideoByVideoId(query);
+//                }
+//                List<WxVideoVO> records = page.getRecords();
+//                Collections.shuffle(records);
+//                if (wxVideoVO!=null) {
+//                    records.set(0, wxVideoVO);
+//                }
                 break;
             case "author":  // 鍔犺浇瑙嗛涓婚〉鎴戝彂甯冪殑瑙嗛
                 AuthorVideoQuery query1 = new AuthorVideoQuery();
@@ -631,7 +652,7 @@
      * @param mysqlNum
      * @return
      */
-    private Integer getCommentNum(String videoId, Integer mysqlNum) {
+    public Integer getCommentNum(String videoId, Integer mysqlNum) {
         Object redisNum = cache.get(CachePrefix.VIDEO_COMMENT_NUM.getPrefixWithId(videoId));
         if (Objects.isNull(redisNum)) {
             // redis涓病鏈夊氨鎶婃暟鎹簱鐨勫啓鍒皉edis涓�
@@ -648,7 +669,7 @@
      * @param mysqlNum
      * @return
      */
-    private Integer getCollectNum(String videoId, Integer mysqlNum) {
+    public Integer getCollectNum(String videoId, Integer mysqlNum) {
         Object redisNum = cache.get(CachePrefix.VIDEO_COLLECT_NUM.getPrefixWithId(videoId));
         if (Objects.isNull(redisNum)) {
             // redis涓病鏈夊氨鎶婃暟鎹簱鐨勫啓鍒皉edis涓�
@@ -665,7 +686,7 @@
      * @param mysqlNum
      * @return
      */
-    private Integer getThumbsUpNum(String videoId, Integer mysqlNum) {
+    public Integer getThumbsUpNum(String videoId, Integer mysqlNum) {
         Object redisNum = cache.get(CachePrefix.VIDEO_THUMBS_UP_NUM.getPrefixWithId(videoId));
         if (Objects.isNull(redisNum)) {
             // redis涓病鏈夊氨鎶婃暟鎹簱鐨勫啓鍒皉edis涓�
@@ -679,7 +700,10 @@
     public Result healthRecommendVideo(WxHealthVideoQuery query) {
         IPage<WxVideoVO> page = PageUtil.getPage(query, WxVideoVO.class);
         //鑾峰彇澶у仴搴疯棰戝垪琛�
+
         baseMapper.recommendHealthVideo(page,query);
+        buildRecommendVideoList(page, query.getVideoId());
+
         if (page.getTotal() > 0) {
             page.getRecords().forEach(v -> {
                 v.setAuthorAvatar(cosUtil.getPreviewUrl(v.getAuthorAvatar()));
@@ -703,8 +727,11 @@
     @Override
     public Result kitchenRecommendVideo(WxKitchenVideoQuery query) {
         IPage<WxVideoVO> page = PageUtil.getPage(query, WxVideoVO.class);
-         baseMapper.wxKitchenVideoQuery(page, query);
-         page.getRecords().forEach(v -> {
+        baseMapper.wxKitchenVideoQuery(page, query);
+
+        buildRecommendVideoList(page, query.getVideoId());
+
+        page.getRecords().forEach(v -> {
              v.setAuthorAvatar(cosUtil.getPreviewUrl(v.getAuthorAvatar()));
              if (VideoContentTypeEnum.VIDEO.getValue().equals(v.getVideoContentType())) {
                  v.setVideoUrl(cosUtil.getPreviewUrl(v.getVideoFileKey()));
@@ -714,6 +741,51 @@
         return Result.ok().data(page.getRecords()).total(page.getTotal());
     }
 
+    /**
+     *
+     * @param page
+     * @param videoId videoId鎺ㄨ崘鐨勮棰慽d
+     */
+    private void buildRecommendVideoList(IPage<WxVideoVO> page, String videoId) {
+        //鏌ヨ鍒版湁瑙嗛鍒楄〃
+
+        if(org.apache.commons.collections.CollectionUtils.isNotEmpty(page.getRecords())){
+            //鐜板皢瑙嗛椤哄簭鎵撲贡
+            Collections.shuffle(page.getRecords());
+
+            WxVideoVO wxVideoVO = null;
+            if (StringUtils.isNotBlank(videoId)){
+                VideoQuery videoQuery = new VideoQuery();
+                videoQuery.setVideoId(videoId);
+                wxVideoVO  = baseMapper.recommendVideoByVideoId(videoQuery);
+
+                boolean found = false;
+                int foundIndex = -1;
+
+                List<WxVideoVO> records = page.getRecords();
+                //鍒ゆ柇浜岀淮鐮佽繃鏉ョ殑videoId鏄惁瀛樺湪涓巔age.getRecords閲嶅 璁板綍涓嬫爣
+                for (int i = 0; i < records.size(); i++) {
+                    if (wxVideoVO.getId().equals(records.get(i).getId())) {
+                        found = true;
+                        foundIndex = i;
+                        break;
+                    }
+                }
+                if (found){
+                    WxVideoVO matchedRecord = records.remove(foundIndex);
+                    records.add(0, matchedRecord);
+                }else {
+                    // 濡傛灉娌℃壘鍒帮紝鏇挎崲棣栦綅
+                    records.set(0, wxVideoVO);
+
+                }
+
+
+            }
+        }
+
+    }
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void updateCollectNumBatch(List<CollectTypeNumVO> numList) {

--
Gitblit v1.8.0