From f788607ff771a47bc60d6a86e00b3433c40f3d2c Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期五, 24 九月 2021 15:22:03 +0800 Subject: [PATCH] 接入视频直播 --- src/main/java/com/yeshi/buwan/service/imp/recommend/HomeVideoServiceImpl.java | 61 ++++++++++++++++++++++++++---- 1 files changed, 53 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/yeshi/buwan/service/imp/recommend/HomeVideoServiceImpl.java b/src/main/java/com/yeshi/buwan/service/imp/recommend/HomeVideoServiceImpl.java index baf34b5..9d60758 100644 --- a/src/main/java/com/yeshi/buwan/service/imp/recommend/HomeVideoServiceImpl.java +++ b/src/main/java/com/yeshi/buwan/service/imp/recommend/HomeVideoServiceImpl.java @@ -3,15 +3,18 @@ import com.yeshi.buwan.dao.HomeVideoDao; import com.yeshi.buwan.domain.HomeVideo; import com.yeshi.buwan.domain.VideoInfo; +import com.yeshi.buwan.domain.solr.SolrShortVideo; import com.yeshi.buwan.domain.video.InternetSearchVideo; import com.yeshi.buwan.service.imp.VideoInfoService; import com.yeshi.buwan.service.inter.juhe.InternetSearchVideoService; import com.yeshi.buwan.service.inter.recommend.HomeVideoService; import com.yeshi.buwan.service.inter.video.VideoInfoExtraService; +import com.yeshi.buwan.service.manager.search.SolrShortVideoDataManager; import com.yeshi.buwan.util.Constant; import com.yeshi.buwan.util.NumberUtil; import com.yeshi.buwan.util.StringUtil; import com.yeshi.buwan.util.factory.VideoInfoFactory; +import com.yeshi.buwan.util.video.VideoUtil; import org.hibernate.Session; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; @@ -32,6 +35,9 @@ @Resource private InternetSearchVideoService internetSearchVideoService; + + @Resource + private SolrShortVideoDataManager solrShortVideoDataManager; @Resource private VideoInfoService videoInfoService; @@ -106,17 +112,55 @@ } - private List<HomeVideo> betchInternetVideos(List<HomeVideo> homeVideoList) { - for (HomeVideo hv : homeVideoList) { + private List<HomeVideo> betchInternetVideos(List<HomeVideo> homeVideoList, List<Long> resourceIds) { + for (int i = 0; i < homeVideoList.size(); i++) { + HomeVideo hv = homeVideoList.get(i); if (hv == null || hv.getVideo() != null || StringUtil.isNullOrEmpty(hv.getVideoId())) { continue; } - if (NumberUtil.isNumeric(hv.getVideoId())) { + if (VideoUtil.getVideoFromType(hv.getVideoId()) != HomeVideo.FROM_TYPE_INTERNET) { continue; } InternetSearchVideo internetSearchVideo = internetSearchVideoService.selectByPrimaryKeyCache(hv.getVideoId()); if (internetSearchVideo != null) { - hv.setVideo(VideoInfoFactory.create(internetSearchVideo)); + String[] rids = internetSearchVideo.getResourceIds().split(","); + List<Long> ridList = new ArrayList<>(); + for (String rid : rids) { + ridList.add(Long.parseLong(rid)); + } + ridList.retainAll(resourceIds); + if (ridList.size() > 0) + hv.setVideo(VideoInfoFactory.create(internetSearchVideo)); + else { + homeVideoList.remove(i); + i--; + } + } + + } + + return homeVideoList; + } + + private List<HomeVideo> betchShortVideos(List<HomeVideo> homeVideoList, List<Long> resourceIds) { + for (int i = 0; i < homeVideoList.size(); i++) { + HomeVideo hv = homeVideoList.get(i); + if (hv == null || hv.getVideo() != null || StringUtil.isNullOrEmpty(hv.getVideoId())) { + continue; + } + if (VideoUtil.getVideoFromType(hv.getVideoId()) != HomeVideo.FROM_TYPE_SHORT) { + continue; + } + + SolrShortVideo shortVideo = solrShortVideoDataManager.findOne(hv.getVideoId()); + if (shortVideo != null) { + Long rid = Long.parseLong(shortVideo.getResourceId() + ""); + if (resourceIds.contains(rid)) { + hv.setVideo(VideoInfoFactory.create(shortVideo)); + } else { + homeVideoList.remove(i); + i--; + } } } @@ -146,7 +190,7 @@ rids.add("rv.`resourceid`=" + rid); } - String sql = String.format("SELECT hv.* FROM wk_video_homevideo hv LEFT JOIN wk_resource_video rv ON rv.`videoid`=hv.`videoid` LEFT JOIN wk_video_video v ON v.`id`=hv.`videoid` WHERE hv.`hometype`=%s AND ( (v.show=1 AND hv.from_type=0 %s) OR hv.from_type>0 ) ", homeId, rids.size() == 0 ? "" :"AND ("+ org.yeshi.utils.StringUtil.concat(rids, " or ")+")"); + String sql = String.format("SELECT hv.* FROM wk_video_homevideo hv LEFT JOIN wk_resource_video rv ON rv.`videoid`=hv.`videoid` LEFT JOIN wk_video_video v ON v.`id`=hv.`videoid` WHERE hv.`hometype`=%s AND ( (v.show=1 AND hv.from_type=0 %s) OR hv.from_type>0 ) ", homeId, rids.size() == 0 ? "" : "AND (" + org.yeshi.utils.StringUtil.concat(rids, " or ") + ")"); sql += " GROUP BY hv.id ORDER BY hv.`orderby` DESC,hv.`createtime` DESC"; @@ -156,7 +200,8 @@ }); List<VideoInfo> videoInfoList = new ArrayList<>(); - homeVideos = betchInternetVideos(homeVideos); + homeVideos = betchInternetVideos(homeVideos, resourceIds); + homeVideos = betchShortVideos(homeVideos, resourceIds); for (int i = 0; i < homeVideos.size(); i++) { if (homeVideos.get(i).getVideo() == null) { homeVideos.remove(i); @@ -172,7 +217,7 @@ } } videoInfoExtraService.batchExtra(videoInfoList, resourceIds); - return betchInternetVideos(homeVideos); + return betchInternetVideos(homeVideos, resourceIds); } @Override @@ -186,7 +231,7 @@ rids.add("rv.`resourceid`=" + rid); } - String sql = String.format("SELECT count(distinct(hv.id)) from wk_video_homevideo hv LEFT JOIN wk_resource_video rv ON rv.`videoid`=hv.`videoid` LEFT JOIN wk_video_video v ON v.`id`=hv.`videoid` WHERE hv.`hometype`=%s AND ( (v.show=1 AND hv.from_type=0 %s) OR hv.from_type>0 ) ", homeId, rids.size() == 0 ? "" :"AND ("+ org.yeshi.utils.StringUtil.concat(rids, " or ")+")"); + String sql = String.format("SELECT count(distinct(hv.id)) from wk_video_homevideo hv LEFT JOIN wk_resource_video rv ON rv.`videoid`=hv.`videoid` LEFT JOIN wk_video_video v ON v.`id`=hv.`videoid` WHERE hv.`hometype`=%s AND ( (v.show=1 AND hv.from_type=0 %s) OR hv.from_type>0 ) ", homeId, rids.size() == 0 ? "" : "AND (" + org.yeshi.utils.StringUtil.concat(rids, " or ") + ")"); return Long.parseLong(session.createSQLQuery(sql).uniqueResult() + "") + (hasBigPicture != null && hasBigPicture ? 1 : 0); }); -- Gitblit v1.8.0