From 09c1e21cad0b474babb1d2f67f481b582adf0b0f Mon Sep 17 00:00:00 2001
From: zxl <763096477@qq.com>
Date: 星期二, 29 七月 2025 14:43:42 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into dev

---
 framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoServiceMakeUpImpl.java |  132 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 132 insertions(+), 0 deletions(-)

diff --git a/framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoServiceMakeUpImpl.java b/framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoServiceMakeUpImpl.java
new file mode 100644
index 0000000..58d40cd
--- /dev/null
+++ b/framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoServiceMakeUpImpl.java
@@ -0,0 +1,132 @@
+package cn.lili.modules.lmk.service.impl;
+
+
+import cn.lili.base.Result;
+import cn.lili.cache.Cache;
+import cn.lili.cache.CachePrefix;
+import cn.lili.common.security.context.UserContext;
+import cn.lili.modules.lmk.constant.RedisKeyExpireConstant;
+import cn.lili.modules.lmk.domain.entity.Video;
+import cn.lili.modules.lmk.domain.query.AuthorVideoQuery;
+import cn.lili.modules.lmk.domain.vo.SimpleMyThumbsUpVO;
+import cn.lili.modules.lmk.domain.vo.SimpleVideoTagVO;
+import cn.lili.modules.lmk.domain.vo.WxVideoVO;
+import cn.lili.modules.lmk.enums.general.VideoContentTypeEnum;
+import cn.lili.modules.lmk.mapper.VideoMapper;
+import cn.lili.modules.lmk.service.MySubscribeService;
+import cn.lili.modules.lmk.service.ThumbsUpRecordService;
+import cn.lili.modules.lmk.service.VideoService;
+import cn.lili.modules.lmk.service.VideoTagRefService;
+import cn.lili.utils.COSUtil;
+import cn.lili.utils.PageUtil;
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.RequiredArgsConstructor;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+/**
+ * lmk-shop-java
+ *
+ * @author : zxl
+ * @date : 2025-07-29 14:24
+ **/
+@Service
+@RequiredArgsConstructor
+public class VideoServiceMakeUpImpl{
+    private final VideoTagRefService videoTagRefService;
+    private final ThumbsUpRecordService thumbsUpRecordService;
+    private final MySubscribeService mySubscribeService;
+    private final VideoMapper videoMapper;
+
+    private final COSUtil cosUtil;
+    private final Cache cache;
+    /**
+     * 鑾峰彇瑙嗛涓婚〉浣滆�呮敹钘忚棰戝垎椤�
+     *
+     * @param query
+     * @return
+     */
+    Result getAuthorCollectVideoPage(AuthorVideoQuery query){
+        IPage<WxVideoVO> page = PageUtil.getPage(query, WxVideoVO.class);
+        videoMapper.getAuthorCollectVideoPage(page, query);
+        if (CollectionUtils.isNotEmpty(page.getRecords())) {
+            List<String> videoIds = page.getRecords().stream().map(WxVideoVO::getId).collect(Collectors.toList());
+            Map<String, List<SimpleVideoTagVO>> tagMap = videoTagRefService.getTagsByVideoIds(videoIds)
+                    .stream()
+                    .collect(Collectors.groupingBy(SimpleVideoTagVO::getVideoId));
+            Map<String, List<SimpleMyThumbsUpVO>> thumbsUpMap = thumbsUpRecordService.getThumbssByVideoIds(videoIds)
+                    .stream()
+                    .collect(Collectors.groupingBy(SimpleMyThumbsUpVO::getRefId));
+            List<String> subscribes = mySubscribeService.getSubscribesByUserId(UserContext.getCurrentUserId());
+            for (WxVideoVO v : page.getRecords()) {
+                v.setTagList(tagMap.get(v.getId()));
+                v.setCollected(Boolean.TRUE);
+                v.setThumbsUp(CollectionUtils.isNotEmpty(thumbsUpMap.get(v.getId())));
+                v.setCommentNum(this.getCommentNum(v.getId(), v.getCommentNum()));
+                v.setCollectNum(this.getCollectNum(v.getId(), v.getCollectNum()));
+                v.setThumbsUpNum(this.getThumbsUpNum(v.getId(), v.getThumbsUpNum()));
+                v.setAuthorAvatar(cosUtil.getPreviewUrl(v.getAuthorAvatar()));
+                if (VideoContentTypeEnum.VIDEO.getValue().equals(v.getVideoContentType())) {
+                    v.setVideoUrl(cosUtil.getPreviewUrl(v.getVideoFileKey()));
+                    v.setCoverUrl(cosUtil.getPreviewUrl(v.getCoverFileKey()));
+                } else if (VideoContentTypeEnum.IMG.getValue().equals(v.getVideoContentType()) && StringUtils.isNotBlank(v.getVideoImgs())) {
+                    v.setImgs(JSON.parseArray(v.getVideoImgs(), String.class).stream().map(fileKey -> cosUtil.getPreviewUrl(fileKey)).collect(Collectors.toList()));
+                }
+                if (CollectionUtils.isNotEmpty(v.getGoodsList())) {
+                    v.getGoodsList().stream().forEach(goods -> {
+                        goods.setThumbnail(cosUtil.getPreviewUrl(goods.getThumbnail()));
+                    });
+                }
+                v.setSubscribeThisAuthor(subscribes.contains(v.getAuthorId()));
+            }
+        }
+        return Result.ok().data(page.getRecords()).total(page.getTotal());
+
+    }
+    public Integer getCommentNum(String videoId, Integer mysqlNum) {
+        Object redisNum = cache.get(CachePrefix.VIDEO_COMMENT_NUM.getPrefixWithId(videoId));
+        if (Objects.isNull(redisNum)) {
+            // redis涓病鏈夊氨鎶婃暟鎹簱鐨勫啓鍒皉edis涓�
+            cache.put(CachePrefix.VIDEO_COMMENT_NUM.getPrefixWithId(videoId), mysqlNum, RedisKeyExpireConstant.COMMENT_NUM_EXPIRE, RedisKeyExpireConstant.EXPIRE_DAY);
+            return mysqlNum;
+        }
+        return (Integer) redisNum;
+    }
+    public Integer getCollectNum(String videoId, Integer mysqlNum) {
+        Object redisNum = cache.get(CachePrefix.VIDEO_COLLECT_NUM.getPrefixWithId(videoId));
+        if (Objects.isNull(redisNum)) {
+            // redis涓病鏈夊氨鎶婃暟鎹簱鐨勫啓鍒皉edis涓�
+            cache.put(CachePrefix.VIDEO_COLLECT_NUM.getPrefixWithId(videoId), mysqlNum, RedisKeyExpireConstant.COLLECT_NUM_EXPIRE, RedisKeyExpireConstant.EXPIRE_DAY);
+            return mysqlNum;
+        }
+        return (Integer) redisNum;
+    }
+
+    /**
+     * 浠巖edis涓幏鍙栫偣璧炴暟閲忥紝濡傛灉redis涓病鏈夊垯灏唌ysql涓殑鏁伴噺鍐欏叆鍒皉edis
+     *
+     * @param videoId
+     * @param mysqlNum
+     * @return
+     */
+    public Integer getThumbsUpNum(String videoId, Integer mysqlNum) {
+        Object redisNum = cache.get(CachePrefix.VIDEO_THUMBS_UP_NUM.getPrefixWithId(videoId));
+        if (Objects.isNull(redisNum)) {
+            // redis涓病鏈夊氨鎶婃暟鎹簱鐨勫啓鍒皉edis涓�
+            cache.put(CachePrefix.VIDEO_THUMBS_UP_NUM.getPrefixWithId(videoId), mysqlNum, RedisKeyExpireConstant.VIDEO_THUMBS_UP_EXPIRE, RedisKeyExpireConstant.EXPIRE_DAY);
+            return mysqlNum;
+        }
+        return (Integer) redisNum;
+    }
+
+
+
+}

--
Gitblit v1.8.0