| | |
| | | import com.yeshi.buwan.domain.HomeVideo; |
| | | import com.yeshi.buwan.domain.VideoInfo; |
| | | 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 javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | |
| | | @Resource |
| | | private InternetSearchVideoService internetSearchVideoService; |
| | | |
| | | @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) { |
| | | for (HomeVideo hv : homeVideoList) { |
| | | if (hv == null || hv.getVideo() == null || !StringUtil.isNullOrEmpty(hv.getVideoId())) { |
| | | if (hv == null || hv.getVideo() != null || StringUtil.isNullOrEmpty(hv.getVideoId())) { |
| | | continue; |
| | | } |
| | | if (NumberUtil.isNumeric(hv.getVideoId())) { |
| | |
| | | |
| | | @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 |
| | |
| | | |
| | | |
| | | 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"; |
| | | |
| | |
| | | }); |
| | | |
| | | List<VideoInfo> videoInfoList = new ArrayList<>(); |
| | | for (HomeVideo hv : homeVideos) { |
| | | if (hv.getVideo() != null) |
| | | videoInfoList.add(hv.getVideo()); |
| | | } |
| | | homeVideos = betchInternetVideos(homeVideos); |
| | | for (int i = 0; i < homeVideos.size(); i++) { |
| | | if (homeVideos.get(i).getVideo() == null) { |
| | | homeVideos.remove(i); |
| | | i--; |
| | | } |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | |
| | | @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); |
| | | }); |
| | | } |
| | | } |