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/VideoServiceImpl.java | 187 +++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 175 insertions(+), 12 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 4f22dc3..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
@@ -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;
/**
@@ -247,6 +251,81 @@
String destination = rocketmqCustomProperties.getVideoTopic() + ":" + VideoTagsEnum.ES_DOC_ADD_OR_UPDATE.name();
rocketMQTemplate.asyncSend(destination, JSON.toJSONString(videoIndex), RocketmqSendCallbackBuilder.commonCallback());
return Result.ok("鍙戝竷鎴愬姛锛岃棰戝鏍镐腑~");
+ } @Override
+ @Transactional(rollbackFor = Exception.class)
+ public Result systemPublish(WxVideoForm form) {
+ // 1.淇濆瓨瑙嗛
+ Video video = WxVideoForm.getEntityByForm(form, null);
+ video.setAuthorId(UserContext.getCurrentUserId());
+ video.setStatus(VideoStatusEnum.PUBLISHED.getValue());
+ video.setCoverUrl(form.getCover());
+ video.setVideoType(VideoTypeEnum.VIDEO.getValue());
+ video.setRecommend(Boolean.FALSE);
+ if (VideoContentTypeEnum.IMG.getValue().equals(form.getVideoContentType())) {
+ video.setVideoImgs(JSON.toJSONString(form.getVideoImgs()));
+ }
+ baseMapper.insert(video);
+ // 2.澶勭悊鏍囩
+ List<SimpleVideoTagVO> esTagList = new ArrayList<>(2);
+ List<VideoTagRef> videoTagRefs = form.getTags().stream().map(tag -> {
+ VideoTagRef videoTagRef = new VideoTagRef();
+ videoTagRef.setVideoId(video.getId());
+ if (StringUtils.isBlank(tag.getId())) {
+ VideoTag videoTag = new LambdaQueryChainWrapper<>(videoTagService.getBaseMapper())
+ .eq(VideoTag::getTagName, tag.getTagName())
+ .one();
+ if (Objects.nonNull(videoTag)) {
+ videoTagRef.setVideoTagId(videoTag.getId());
+ } else {
+ videoTag = new VideoTag();
+ videoTag.setTagName(tag.getTagName());
+ videoTag.setCreateType(TagCreateTypeEnum.SYSTEM.getValue());
+ videoTagService.save(videoTag);
+ videoTagRef.setVideoTagId(videoTag.getId());
+ }
+ } else {
+ videoTagRef.setVideoTagId(tag.getId());
+ }
+ SimpleVideoTagVO esTag = new SimpleVideoTagVO();
+ esTag.setVideoId(video.getId());
+ esTag.setTagName(tag.getTagName());
+ esTag.setId(tag.getId());
+ esTagList.add(esTag);
+ return videoTagRef;
+ }).collect(Collectors.toList());
+ videoTagRefService.saveBatch(videoTagRefs);
+ // 3. 淇濆瓨瑙嗛鏂囦欢淇℃伅
+ lmkFileService.addByForm(form.getFileInfo());
+ // 4. 澶勭悊閫夋嫨鐨勫晢鍝�
+ List<VideoGoods> videoGoods = new ArrayList<>(2);
+ if (CollectionUtils.isNotEmpty(form.getGoodsList())) {
+ for (int i = 0; i < form.getGoodsList().size(); i++) {
+ VideoGoods e = new VideoGoods();
+ e.setVideoId(video.getId());
+ e.setGoodsId(form.getGoodsList().get(i).getGoodsId());
+ e.setGoodsSkuId(form.getGoodsList().get(i).getGoodsSkuId());
+ e.setGoodsNum(form.getGoodsList().get(i).getGoodsNum());
+ e.setOrderNum(i);
+ videoGoodsService.save(e);
+ }
+ videoGoodsService.saveBatch(videoGoods);
+ }
+ // 5. 鏋勫缓es涓暟鎹紝mq寮傛澶勭悊
+ VideoIndex videoIndex = new VideoIndex();
+ BeanUtils.copyProperties(video, videoIndex);
+ videoIndex.setAuthorName(UserContext.getCurrentUser().getNickName());
+ videoIndex.setAuthorAvatar(UserContext.getCurrentUser().getFace());
+ videoIndex.setCoverFileKey(video.getCoverUrl());
+ List<VideoGoodsDetailVO> esGoodsList = videoGoods.stream().map(goods -> {
+ VideoGoodsDetailVO vo = new VideoGoodsDetailVO();
+ BeanUtils.copyProperties(goods, vo);
+ return vo;
+ }).collect(Collectors.toList());
+ videoIndex.setGoodsList(esGoodsList);
+ videoIndex.setTagList(esTagList);
+ String destination = rocketmqCustomProperties.getVideoTopic() + ":" + VideoTagsEnum.ES_DOC_ADD_OR_UPDATE.name();
+ rocketMQTemplate.asyncSend(destination, JSON.toJSONString(videoIndex), RocketmqSendCallbackBuilder.commonCallback());
+ return Result.ok("鍙戝竷鎴愬姛锛岃棰戝鏍镐腑~");
}
@Override
@@ -348,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());
@@ -472,6 +557,16 @@
switch (query.getVideoFrom()) {
case "recommend":// 鍔犺浇鎺ㄨ崘瑙嗛
baseMapper.recommendVideo(page, query);
+ //鎺ㄨ崘瑙嗛閲嶆柊鎺掑簭
+ 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();
@@ -497,10 +592,16 @@
videoEsQuery.setPageNumber((int) query.getPageNumber());
videoEsQuery.setPageSize((int) query.getPageSize());
return this.esSearch(videoEsQuery);
- case "goodsSimilarly":
+ case "goodsSimilarly": // 鎮寕鐩稿悓鍟嗗搧鐨勬帹鑽愯棰�
GoodsSimilarlyQuery goodsSimilarlyQuery = new GoodsSimilarlyQuery();
BeanUtils.copyProperties(query, goodsSimilarlyQuery);
baseMapper.goodsSimilarlyPage(page, goodsSimilarlyQuery);
+ break;
+ case "history":
+ VideoHistoryQuery videoHistoryQuery = new VideoHistoryQuery();
+ BeanUtils.copyProperties(query, videoHistoryQuery);
+ videoHistoryQuery.setUserId(UserContext.getCurrentUserId());
+ baseMapper.getHistoryPage(page, videoHistoryQuery);
break;
default:
break;
@@ -525,6 +626,7 @@
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()));
@@ -549,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涓�
@@ -566,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涓�
@@ -583,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涓�
@@ -597,9 +699,10 @@
public Result healthRecommendVideo(WxHealthVideoQuery query) {
IPage<WxVideoVO> page = PageUtil.getPage(query, WxVideoVO.class);
//鑾峰彇澶у仴搴疯棰戝垪琛�
- baseMapper.recommendHealthVideo(page,query);
+ baseMapper.recommendHealthVideo(page,query);
if (page.getTotal() > 0) {
page.getRecords().forEach(v -> {
+ 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()));
@@ -622,6 +725,7 @@
IPage<WxVideoVO> page = PageUtil.getPage(query, WxVideoVO.class);
baseMapper.wxKitchenVideoQuery(page, query);
page.getRecords().forEach(v -> {
+ 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()));
@@ -672,13 +776,24 @@
@Override
public Result saveViewRecord(VideoFootPrintForm form) {
- FootPrint footPrint = new FootPrint();
- footPrint.setViewType(ViewTypeEnum.VIDEO.getValue());
- footPrint.setRefId(form.getVideoId());
- footPrint.setMemberId(UserContext.getCurrentUserId());
- footPrint.setViewDuration(form.getViewDuration());
- footPrint.setPlayAt(form.getPlayAt());
- footprintService.saveFootprint(footPrint);
+ FootPrint one = new LambdaQueryChainWrapper<>(footprintService.getBaseMapper())
+ .eq(FootPrint::getRefId, form.getVideoId())
+ .eq(FootPrint::getMemberId, UserContext.getCurrentUserId())
+ .eq(FootPrint::getViewType, ViewTypeEnum.VIDEO.getValue())
+ .one();
+ if (Objects.nonNull(one)) {
+ one.setViewDuration(one.getViewDuration() + form.getViewDuration());
+ one.setPlayAt(form.getPlayAt());
+ footprintService.updateById(one);
+ } else {
+ FootPrint footPrint = new FootPrint();
+ footPrint.setViewType(ViewTypeEnum.VIDEO.getValue());
+ footPrint.setRefId(form.getVideoId());
+ footPrint.setMemberId(UserContext.getCurrentUserId());
+ footPrint.setViewDuration(form.getViewDuration());
+ footPrint.setPlayAt(form.getPlayAt());
+ footprintService.saveFootprint(footPrint);
+ }
return Result.ok();
}
@@ -720,6 +835,7 @@
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()));
@@ -758,6 +874,7 @@
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()));
@@ -795,6 +912,7 @@
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()));
@@ -1199,6 +1317,7 @@
// 鍒ゆ柇鏄惁鍏虫敞浣滆�呫�佹槸鍚︾偣璧炪�佹槸鍚︽敹钘�
wxVideoVO.setCollected(CollectionUtils.isNotEmpty(collectMap.get(wxVideoVO.getId())));
wxVideoVO.setThumbsUp(CollectionUtils.isNotEmpty(thumbsUpMap.get(wxVideoVO.getId())));
+ wxVideoVO.setAuthorAvatar(cosUtil.getPreviewUrl(wxVideoVO.getAuthorAvatar()));
if (UserContext.getCurrentUserId().equals(wxVideoVO.getAuthorId())) {
wxVideoVO.setSubscribeThisAuthor(Boolean.TRUE);
} else {
@@ -1216,4 +1335,48 @@
return Result.ok().data(vos).total(searchHits.getTotalHits());
}
+ @Override
+ public Result getHistoryPage(VideoHistoryQuery query) {
+ query.setUserId(UserContext.getCurrentUserId());
+ IPage<VideoHistoryVO> page = PageUtil.getPage(query, VideoHistoryVO.class);
+ baseMapper.getHistoryPage(page, query);
+ if (CollectionUtils.isNotEmpty(page.getRecords())) {
+ if (page.getTotal() > 0) {
+ List<String> videoIds = page.getRecords().stream().map(VideoHistoryVO::getId).collect(Collectors.toList());
+ Map<String, List<SimpleVideoTagVO>> tagMap = videoTagRefService.getTagsByVideoIds(videoIds)
+ .stream()
+ .collect(Collectors.groupingBy(SimpleVideoTagVO::getVideoId));
+ Map<String, List<SimpleMyCollectVO>> collectMap = myCollectService.getCollectsByVideoIds(videoIds)
+ .stream()
+ .collect(Collectors.groupingBy(SimpleMyCollectVO::getRefId));
+ Map<String, List<SimpleMyThumbsUpVO>> thumbsUpMap = thumbsUpRecordService.getThumbssByVideoIds(videoIds)
+ .stream()
+ .collect(Collectors.groupingBy(SimpleMyThumbsUpVO::getRefId));
+ List<String> subscribes = mySubscribeService.getSubscribesByUserId(UserContext.getCurrentUserId());
+ // 3. 鑾峰彇瑙嗛涓存椂璁块棶鍦板潃銆佽缃棰戞爣绛俱�佹垜鏄惁鏀惰棌銆佹槸鍚︾偣璧炪�佷綔鑰呮槸鍚﹀叧娉�
+ page.getRecords().forEach(v -> {
+ v.setTagList(tagMap.get(v.getId()));
+ v.setCollected(CollectionUtils.isNotEmpty(collectMap.get(v.getId())));
+ 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());
+ }
}
--
Gitblit v1.8.0