xiangpei
2025-06-03 3b9e74e575abc3a410cb7951792d49b63842c5da
framework/src/main/java/cn/lili/modules/lmk/service/impl/VideoServiceImpl.java
@@ -6,6 +6,7 @@
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.AuthorVideoQuery;
import cn.lili.modules.lmk.domain.query.ManagerVideoQuery;
import cn.lili.modules.lmk.domain.vo.*;
import cn.lili.modules.lmk.enums.general.TagCreateTypeEnum;
@@ -54,6 +55,7 @@
    private final MyCollectService myCollectService;
    private final COSUtil cosUtil;
    private final FootprintService footprintService;
    private final MySubscribeService mySubscribeService;
    /**
     * 添加
@@ -152,6 +154,7 @@
        Video video = VideoForm.getEntityByForm(form, null);
        video.setAuthorId(UserContext.getCurrentUserId());
        video.setStatus(VideoStatusEnum.AUDITING.getValue());
        video.setCoverUrl(form.getCover());
        baseMapper.insert(video);
        // 2.处理标签
        List<VideoTagRef> videoTagRefs = form.getTags().stream().map(tag -> {
@@ -270,12 +273,14 @@
            Map<String, List<SimpleMyCollectVO>> collectMap =myCollectService.getCollectsByVideoIds(videoIds)
                    .stream()
                    .collect(Collectors.groupingBy(SimpleMyCollectVO::getRefId));
            // 3. 获取视频临时访问地址、设置视频标签、我是否收藏
            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());
@@ -292,6 +297,16 @@
    }
    @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());
@@ -302,4 +317,25 @@
        footprintService.saveFootprint(footPrint);
        return Result.ok();
    }
    @Override
    public Result getAuthorInfo(String authorId) {
        VideoAccountVO vo = baseMapper.getAuthorInfo(authorId, UserContext.getCurrentUserId());
        vo.setSelf(authorId.equals(UserContext.getCurrentUserId()));
        // 查询获赞数
        List<String> videoIds = baseMapper.getVideoIdsByAuthor(authorId);
        if (CollectionUtils.isNotEmpty(videoIds)) {
            vo.setLikeNum(baseMapper.countAuthorVideoCollectNum(videoIds));
        } else {
            vo.setLikeNum(0L);
        }
        return Result.ok().data(vo);
    }
    @Override
    public Result getAuthorVideoPage(AuthorVideoQuery query) {
        IPage<WxVideoVO> page = PageUtil.getPage(query, WxVideoVO.class);
        baseMapper.getAuthorVideoPage(page, query);
        return Result.ok().data(page.getRecords()).total(page.getTotal());
    }
}