| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | import org.springframework.util.Assert; |
| | | |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | videoTag = new VideoTag(); |
| | | videoTag.setTagName(tag.getTagName()); |
| | | videoTag.setCreateType(TagCreateTypeEnum.USER.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 |
| | | @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()); |
| | | } |
| | |
| | | switch (query.getVideoFrom()) { |
| | | case "recommend":// 加载推荐视频 |
| | | baseMapper.recommendVideo(page, query); |
| | | //推荐视频重新排序 |
| | | List<WxVideoVO> records = page.getRecords(); |
| | | Collections.shuffle(records); |
| | | break; |
| | | case "author": // 加载视频主页我发布的视频 |
| | | AuthorVideoQuery query1 = new AuthorVideoQuery(); |
| | |
| | | baseMapper.getAuthorLikeVideoPage(page, query3); |
| | | break; |
| | | case "search": // 加载es搜索视频 |
| | | VideoEsQuery query4 = new VideoEsQuery(); |
| | | BeanUtils.copyProperties(query, query4); |
| | | query4.setPageNumber((int) query.getPageNumber()); |
| | | query4.setPageSize((int) query.getPageSize()); |
| | | return this.esSearch(query4); |
| | | VideoEsQuery videoEsQuery = new VideoEsQuery(); |
| | | BeanUtils.copyProperties(query, videoEsQuery); |
| | | videoEsQuery.setPageNumber((int) query.getPageNumber()); |
| | | videoEsQuery.setPageSize((int) query.getPageSize()); |
| | | return this.esSearch(videoEsQuery); |
| | | 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; |
| | | } |
| | |
| | | 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())); |
| | |
| | | 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())); |
| | |
| | | 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())); |
| | |
| | | |
| | | @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(); |
| | | } |
| | | |
| | |
| | | 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())); |
| | |
| | | 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())); |
| | |
| | | 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())); |
| | |
| | | // 判断是否关注作者、是否点赞、是否收藏 |
| | | 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 { |
| | |
| | | }).collect(Collectors.toList()); |
| | | 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()); |
| | | } |
| | | } |