From 32affb9328997ab51b2c88f7f034c16a1e7ed6d0 Mon Sep 17 00:00:00 2001
From: xiangpei <xiangpei@timesnew.cn>
Date: 星期五, 30 五月 2025 17:15:20 +0800
Subject: [PATCH] 评论点赞
---
framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoServiceImpl.java | 167 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 157 insertions(+), 10 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 f2f75a8..bf978a9 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
@@ -1,24 +1,30 @@
package cn.lili.modules.lmk.service.impl;
+import cn.lili.base.AbsQuery;
import cn.lili.common.security.context.UserContext;
-import cn.lili.modules.lmk.domain.entity.LmkFile;
+import cn.lili.modules.lmk.domain.entity.VideoAuditRecord;
import cn.lili.modules.lmk.domain.entity.VideoTag;
import cn.lili.modules.lmk.domain.entity.VideoTagRef;
+import cn.lili.modules.lmk.domain.form.*;
+import cn.lili.modules.lmk.domain.query.ManagerVideoQuery;
+import cn.lili.modules.lmk.domain.vo.*;
import cn.lili.modules.lmk.enums.general.TagCreateTypeEnum;
import cn.lili.modules.lmk.enums.general.VideoStatusEnum;
-import cn.lili.modules.lmk.service.LmkFileService;
-import cn.lili.modules.lmk.service.VideoTagRefService;
-import cn.lili.modules.lmk.service.VideoTagService;
+import cn.lili.modules.lmk.enums.general.ViewTypeEnum;
+import cn.lili.modules.lmk.service.*;
+import cn.lili.modules.member.entity.dos.FootPrint;
+import cn.lili.modules.member.service.FootprintService;
+import cn.lili.utils.COSUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import cn.lili.modules.lmk.domain.entity.Video;
import cn.lili.modules.lmk.mapper.VideoMapper;
-import cn.lili.modules.lmk.service.VideoService;
import cn.lili.base.Result;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
+import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import cn.lili.modules.lmk.domain.form.VideoForm;
-import cn.lili.modules.lmk.domain.vo.VideoVO;
import cn.lili.modules.lmk.domain.query.VideoQuery;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import lombok.RequiredArgsConstructor;
@@ -27,8 +33,7 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
import java.util.stream.Collectors;
/**
@@ -45,6 +50,11 @@
private final VideoTagService videoTagService;
private final VideoTagRefService videoTagRefService;
private final LmkFileService lmkFileService;
+ private final VideoAuditRecordService videoAuditRecordService;
+ private final MyCollectService myCollectService;
+ private final COSUtil cosUtil;
+ private final FootprintService footprintService;
+ private final MySubscribeService mySubscribeService;
/**
* 娣诲姞
@@ -114,9 +124,12 @@
* @return
*/
@Override
- public Result detail(Integer id) {
+ public Result detail(String id) {
VideoVO vo = baseMapper.getById(id);
Assert.notNull(vo, "璁板綍涓嶅瓨鍦�");
+ List<SimpleVideoTagVO> tags = videoTagRefService.getTagsByVideoIds(Arrays.asList(id));
+ vo.setTagList(tags);
+ vo.setVideoUrl(cosUtil.getPreviewUrl(vo.getVideoFileKey()));
return Result.ok().data(vo);
}
@@ -168,4 +181,138 @@
lmkFileService.addByForm(form.getFileInfo());
return Result.ok("鍙戝竷鎴愬姛锛岃棰戝鏍镐腑~");
}
+
+
+ @Override
+ public Result managerPage(ManagerVideoQuery query) {
+ IPage<VideoVO> page = PageUtil.getPage(query, VideoVO.class);
+ // 1. 鍏堟煡鍑鸿棰戜俊鎭�
+ baseMapper.managerPage(page, query);
+ // 2. 鍗曠嫭鏌ュ嚭鏍囩淇℃伅
+ if (page.getTotal() > 0) {
+ Map<String, List<SimpleVideoTagVO>> tagMap = videoTagRefService.getTagsByVideoIds(
+ page.getRecords().stream().map(VideoVO::getId).collect(Collectors.toList())
+ ).stream().collect(Collectors.groupingBy(SimpleVideoTagVO::getVideoId));;
+ // 3. 鑾峰彇瑙嗛涓存椂璁块棶鍦板潃銆佽缃棰戞爣绛�
+ page.getRecords().forEach(v -> {
+ v.setTagList(tagMap.get(v.getId()));
+// v.setVideoUrl(cosUtil.getPreviewUrl(v.getVideoFileKey()));
+ });
+ }
+ return Result.ok().data(page.getRecords()).total(page.getTotal());
+ }
+
+ @Override
+ public Result recommendSet(VideoRecommendForm form) {
+ new LambdaUpdateChainWrapper<>(baseMapper)
+ .eq(Video::getId, form.getId())
+ .set(Video::getRecommend, form.getRecommend())
+ .update();
+ return Result.ok("璁剧疆鎴愬姛");
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public Result auditing(VideoAuditingForm form) {
+ Video video = baseMapper.selectById(form.getId());
+ if (Objects.isNull(video)) {
+ throw new RuntimeException("瑙嗛涓嶅瓨鍦�");
+ }
+ // 1. 娣诲姞瀹℃牳璁板綍
+ VideoAuditRecord auditRecord = new VideoAuditRecord();
+ auditRecord.setVideoId(form.getId());
+ auditRecord.setAuditSuccess(form.getResult());
+ if (!form.getResult()) {
+ auditRecord.setEditSuggestion(form.getReason());
+ }
+ videoAuditRecordService.save(auditRecord);
+ // 2. 淇敼瑙嗛鐘舵��
+ if (form.getResult()) {
+ video.setStatus(VideoStatusEnum.PUBLISHED.getValue());
+ video.setAuditPassTime(new Date());
+ } else {
+ video.setStatus(VideoStatusEnum.REJECT.getValue());
+ }
+ baseMapper.updateById(video);
+ return Result.ok();
+ }
+
+
+ @Override
+ public Result up(String id) {
+ new LambdaUpdateChainWrapper<>(baseMapper)
+ .eq(Video::getId, id)
+ .set(Video::getStatus, VideoStatusEnum.PUBLISHED.getValue())
+ .update();
+ return Result.ok("涓婃灦鎴愬姛");
+ }
+
+
+ @Override
+ public Result down(VideoDownForm form) {
+ new LambdaUpdateChainWrapper<>(baseMapper)
+ .eq(Video::getId, form.getId())
+ .set(Video::getStatus, VideoStatusEnum.DISABLE.getValue())
+ .update();
+ // TODO 灏嗕笅鏋跺師鍥犱互閫氱煡鐨勬柟寮忓憡鐭ョ敤鎴�
+ return Result.ok("涓嬫灦鎴愬姛");
+ }
+
+ @Override
+ public Result recommendVideo(AbsQuery query) {
+ // 鎺ㄨ崘绠楁硶锛� 1. 鏍规嵁鐢ㄦ埛鐨勬敹钘忚棰戠殑鏍囩 2. 鏍规嵁鐢ㄦ埛鍏虫敞鐨勪綔鑰呯殑鍏跺畠瑙嗛 3. 鏍规嵁鐢ㄦ埛鐨勮鐪嬭褰曪紙瑙傜湅鏃堕暱杈冮暱鐨勩�侀噸澶嶈鐪嬫鏁拌緝澶氱殑锛� 4. 鍩轰簬鐩镐技鐢ㄦ埛鐨勮鐪嬭涓烘潵缁欒鐢ㄦ埛鎺ㄨ崘
+ IPage<WxVideoVO> page = PageUtil.getPage(query, WxVideoVO.class);
+ baseMapper.recommendVideo(page);
+ if (page.getTotal() > 0) {
+ 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<SimpleMyCollectVO>> collectMap =myCollectService.getCollectsByVideoIds(videoIds)
+ .stream()
+ .collect(Collectors.groupingBy(SimpleMyCollectVO::getRefId));
+ List<String> subscribes = mySubscribeService.getSubscribesByUserId(UserContext.getCurrentUserId());
+ // 3. 鑾峰彇瑙嗛涓存椂璁块棶鍦板潃銆佽缃棰戞爣绛俱�佹垜鏄惁鏀惰棌銆佷綔鑰呮槸鍚﹀叧娉�
+ page.getRecords().forEach(v -> {
+ v.setGoods(new VideoGoodsVO());
+ v.setTagList(tagMap.get(v.getId()));
+ v.setCollected(CollectionUtils.isNotEmpty(collectMap.get(v.getId())));
+ v.setVideoUrl(cosUtil.getPreviewUrl(v.getVideoFileKey()));
+ v.setSubscribeThisAuthor(subscribes.contains(v.getAuthorId()));
+ });
+ }
+ return Result.ok().data(page.getRecords());
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void updateCollectNumBatch(List<CollectTypeNumVO> numList) {
+ // 鎸�500鏉℃暟鎹繘琛屾媶鍒�
+ List<List<CollectTypeNumVO>> chunks = ListUtils.partition(numList, 500);
+ for (List<CollectTypeNumVO> chunk : chunks) {
+ baseMapper.updateCollectNumBatch(chunk);
+ }
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void updateCommentNumBatch(List<CollectTypeNumVO> numList) {
+ // 鎸�500鏉℃暟鎹繘琛屾媶鍒�
+ List<List<CollectTypeNumVO>> chunks = ListUtils.partition(numList, 500);
+ for (List<CollectTypeNumVO> chunk : chunks) {
+ baseMapper.updateCommentNumBatch(chunk);
+ }
+ }
+
+ @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);
+ return Result.ok();
+ }
}
--
Gitblit v1.8.0