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 | 185 ++++++++++++++++++++++++++++++++++++++------- 1 files changed, 155 insertions(+), 30 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 3dacb70..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,20 +3,25 @@ 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; import javax.annotation.Resource; import java.util.ArrayList; +import java.util.Date; import java.util.List; @Service @@ -31,17 +36,131 @@ @Resource private InternetSearchVideoService internetSearchVideoService; - private List<HomeVideo> betchInternetVideos(List<HomeVideo> homeVideoList) { - for (HomeVideo hv : homeVideoList) { - if (hv == null || hv.getVideo() == null || !StringUtil.isNullOrEmpty(hv.getVideoId())) { + @Resource + private SolrShortVideoDataManager solrShortVideoDataManager; + + @Resource + private VideoInfoService videoInfoService; + + + public void deleteHomeVideo(HomeVideo video) { + + homeVideoDao.delete(video); + } + + public void deleteHomeTypeVideo(List<HomeVideo> list) { + + for (HomeVideo homeVideo : list) { + deleteHomeVideo(homeVideo); + } + } + + + public void updateHomeVideo(HomeVideo homeVideo) { + + homeVideoDao.update(homeVideo); + } + + public void addHomeVideo(List<HomeVideo> list) { + if (list != null) + for (HomeVideo homeVideo : list) { + addHomeVideo(homeVideo); + } + } + + public void addHomeVideo(HomeVideo video) { + + if (video.getFromType() == null) + video.setFromType(HomeVideo.FROM_TYPE_LOCAL); + + if (video.getCreatetime() == null) + video.setCreatetime(System.currentTimeMillis() + ""); + + if (video.getVideoUpdateTime() == null) { + video.setVideoUpdateTime(new Date()); + } + + if (video.getVideoName() == null) { + + switch (video.getFromType()) { + + case HomeVideo.FROM_TYPE_LOCAL: { + //鍙栬棰戝悕绉� + VideoInfo videoInfo = videoInfoService.getVideoInfo(video.getVideoId()); + if (videoInfo != null) { + video.setVideoName(videoInfo.getName()); + } + } + break; + case HomeVideo.FROM_TYPE_INTERNET: { + //鍙栬棰戝悕绉� + InternetSearchVideo internetSearchVideo = internetSearchVideoService.selectByPrimaryKey(video.getVideoId()); + if (internetSearchVideo != null) { + video.setVideoName(internetSearchVideo.getName()); + } + } + break; + } + + } + + + long count = homeVideoDao.getCount("select count(*) from HomeVideo h where h.type.id=? and h.videoId=?", + new String[]{video.getType().getId(), video.getVideoId()}); + if (count <= 0L) + homeVideoDao.create(video); + } + + + 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--; + } } } @@ -51,16 +170,12 @@ @Override public List<HomeVideo> getHomeVideoList(String homeId, String key, int page) { - List<HomeVideo> homeVideoList = homeVideoDao.list( - "from HomeVideo h where h.type.id=? and h.video.name like ? order by h.bigPicture desc, h.video.orderby desc,h.video.watchCount desc,h.createtime desc", - (page - 1) * Constant.pageCount, Constant.pageCount, new String[]{homeId, "%" + key + "%"}); - return betchInternetVideos(homeVideoList); + return getHomeVideoList(homeId, null, null, null, page, Constant.pageCount); } @Override public long getHomeVideoListCount(String homeId, String key) { - return homeVideoDao.getCount("select count(*) from HomeVideo h where h.type.id=? and h.video.name like ? ", - new String[]{homeId, "%" + key + "%"}); + return getHomeVideoListCount(homeId, null, null, null); } @Override @@ -70,11 +185,12 @@ List<String> rids = new ArrayList<>(); - for (Long rid : resourceIds) { - rids.add("rv.`resourceid`=" + rid); - } + if (resourceIds != null) + for (Long rid : resourceIds) { + 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 v.show=1 and hv.`hometype`=%s AND (%s) ", homeId, 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"; @@ -84,31 +200,40 @@ }); List<VideoInfo> videoInfoList = new ArrayList<>(); - for (HomeVideo hv : homeVideos) { - if (hv.getVideo() != null) - videoInfoList.add(hv.getVideo()); + 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); + i--; + } } - homeVideos = betchInternetVideos(homeVideos); + + for (HomeVideo hv : homeVideos) { + if (hv.getVideo() != null) { + hv.getVideo().setIntroduction(""); + hv.getVideo().setVideoType(null); + videoInfoList.add(hv.getVideo()); + } + } videoInfoExtraService.batchExtra(videoInfoList, resourceIds); - return betchInternetVideos(homeVideos); + return betchInternetVideos(homeVideos, resourceIds); } @Override - @Cacheable(value = "homeCache", key = "'getHomeVideoListCount-'+#homeId+'-'+#resourceKey+'-'+#bigPicture") - public long getHomeVideoListCount(String homeId, String resourceKey, List<Long> resourceIds, Boolean bigPicture) { + @Cacheable(value = "homeCache", key = "'getHomeVideoListCount-'+#homeId+'-'+#resourceKey+'-'+#hasBigPicture") + public long getHomeVideoListCount(String homeId, String resourceKey, List<Long> resourceIds, Boolean hasBigPicture) { return (Long) homeVideoDao.excute((Session session) -> { List<String> rids = new ArrayList<>(); - for (Long rid : resourceIds) { - rids.add("rv.`resourceid`=" + rid); - } + if (resourceIds != null) + for (Long rid : resourceIds) { + 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 v.show=1 and hv.`hometype`=%s AND (%s)", homeId, 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 ") + ")"); - if (bigPicture != null) { - sql += " and hv.big_picture=" + (bigPicture ? 1 : 0); - } - return Long.parseLong(session.createSQLQuery(sql).uniqueResult() + ""); + return Long.parseLong(session.createSQLQuery(sql).uniqueResult() + "") + (hasBigPicture != null && hasBigPicture ? 1 : 0); }); } } -- Gitblit v1.8.0