zxl
4 天以前 6fb006c40ff90a615fa3c3a55a65c99b55acc03d
提取videoServiceImpl方法
2个文件已修改
1个文件已添加
167 ■■■■ 已修改文件
framework/src/main/java/cn/lili/modules/lmk/service/impl/MyCollectServiceImpl.java 29 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoServiceImpl.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoServiceMakeUpImpl.java 132 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/cn/lili/modules/lmk/service/impl/MyCollectServiceImpl.java
@@ -6,6 +6,7 @@
import cn.lili.modules.goods.entity.vos.GoodsVO;
import cn.lili.modules.lmk.domain.query.AuthorVideoQuery;
import cn.lili.modules.lmk.domain.vo.*;
import cn.lili.modules.lmk.service.MySubscribeService;
import cn.lili.modules.lmk.service.VideoService;
import cn.lili.rocketmq.RocketmqSendCallbackBuilder;
import cn.lili.rocketmq.tags.CommentTagsEnum;
@@ -24,6 +25,7 @@
import com.xkcoding.http.util.StringUtil;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import lombok.RequiredArgsConstructor;
import cn.lili.utils.PageUtil;
@@ -52,14 +54,8 @@
    private final RocketmqCustomProperties rocketmqCustomProperties;
    private final LmkFileServiceImpl fileService;
    private final RocketMQTemplate rocketMQTemplate;
    private VideoService videoService; // 移除了final
    private COSUtil cOSUtil;
    private final VideoServiceMakeUpImpl serviceMakeUp;
    @Autowired
    public void setVideoService(VideoService videoService) {
        // 这里可以添加额外的初始化逻辑
        this.videoService = videoService;
    }
    /**
@@ -202,24 +198,7 @@
            videoQuery.setPageSize(query.getPageSize());
            videoQuery.setPageNumber(query.getPageNumber());
            Result result = videoService.getAuthorCollectVideoPage(videoQuery);
            List<WxVideoVO> list = Optional.ofNullable(result.get("data"))
                    .filter(data -> data instanceof List<?>)
                    .map(data -> (List<?>) data)
                    .orElse(Collections.emptyList())
                    .stream()
                    .filter(WxVideoVO.class::isInstance)
                    .map(WxVideoVO.class::cast)
                    .collect(Collectors.toList());
            for (WxVideoVO wxVideoVO : list){
                if (!CollectionUtils.isEmpty(wxVideoVO.getImgs())){
                    List<String> newImages = wxVideoVO
                            .getImgs().stream().map(item -> cOSUtil.getPreviewUrl(item)).collect(Collectors.toList());
                    wxVideoVO.setImgs(newImages);
                }
            }
            return result;
            return serviceMakeUp.getAuthorCollectVideoPage(videoQuery);
        }else if (CollectTypeEnum.goods.getType().equals(query.getType())) {
            baseMapper.getGoodsCollectPage(page, userId);
framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoServiceImpl.java
@@ -651,7 +651,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中没有就把数据库的写到redis中
@@ -668,7 +668,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中没有就把数据库的写到redis中
@@ -685,7 +685,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中没有就把数据库的写到redis中
framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoServiceMakeUpImpl.java
New file
@@ -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中没有就把数据库的写到redis中
            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中没有就把数据库的写到redis中
            cache.put(CachePrefix.VIDEO_COLLECT_NUM.getPrefixWithId(videoId), mysqlNum, RedisKeyExpireConstant.COLLECT_NUM_EXPIRE, RedisKeyExpireConstant.EXPIRE_DAY);
            return mysqlNum;
        }
        return (Integer) redisNum;
    }
    /**
     * 从redis中获取点赞数量,如果redis中没有则将mysql中的数量写入到redis
     *
     * @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中没有就把数据库的写到redis中
            cache.put(CachePrefix.VIDEO_THUMBS_UP_NUM.getPrefixWithId(videoId), mysqlNum, RedisKeyExpireConstant.VIDEO_THUMBS_UP_EXPIRE, RedisKeyExpireConstant.EXPIRE_DAY);
            return mysqlNum;
        }
        return (Integer) redisNum;
    }
}