From 6fb006c40ff90a615fa3c3a55a65c99b55acc03d Mon Sep 17 00:00:00 2001
From: zxl <763096477@qq.com>
Date: 星期二, 29 七月 2025 14:43:35 +0800
Subject: [PATCH] 提取videoServiceImpl方法
---
framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoServiceMakeUpImpl.java | 132 ++++++++++++++++++++++++++++++++++++++++++++
framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoServiceImpl.java | 6 +-
framework/src/main/java/cn/lili/modules/lmk/service/impl/MyCollectServiceImpl.java | 29 +--------
3 files changed, 139 insertions(+), 28 deletions(-)
diff --git a/framework/src/main/java/cn/lili/modules/lmk/service/impl/MyCollectServiceImpl.java b/framework/src/main/java/cn/lili/modules/lmk/service/impl/MyCollectServiceImpl.java
index d5cd650..c2ae06e 100644
--- a/framework/src/main/java/cn/lili/modules/lmk/service/impl/MyCollectServiceImpl.java
+++ b/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; // 绉婚櫎浜唂inal
- 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);
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 8de5366..9cc98f7 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
@@ -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涓病鏈夊氨鎶婃暟鎹簱鐨勫啓鍒皉edis涓�
@@ -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涓病鏈夊氨鎶婃暟鎹簱鐨勫啓鍒皉edis涓�
@@ -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涓病鏈夊氨鎶婃暟鎹簱鐨勫啓鍒皉edis涓�
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