From f537abe9f3646c739beaf15076246a2f71a347e9 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期四, 20 二月 2025 16:57:55 +0800 Subject: [PATCH] IOS广告增加区域屏蔽 --- src/main/java/com/yeshi/buwan/service/imp/VideoInfoService.java | 427 +++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 319 insertions(+), 108 deletions(-) diff --git a/src/main/java/com/yeshi/buwan/service/imp/VideoInfoService.java b/src/main/java/com/yeshi/buwan/service/imp/VideoInfoService.java index aea17ab..fdf6028 100644 --- a/src/main/java/com/yeshi/buwan/service/imp/VideoInfoService.java +++ b/src/main/java/com/yeshi/buwan/service/imp/VideoInfoService.java @@ -1,135 +1,346 @@ package com.yeshi.buwan.service.imp; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -import javax.annotation.Resource; - +import com.yeshi.buwan.dao.CategoryVideoDao; +import com.yeshi.buwan.dao.VideoInfoDao; +import com.yeshi.buwan.domain.*; +import com.yeshi.buwan.domain.entity.PlayUrl; +import com.yeshi.buwan.dto.mq.VideoDataChangeMQMsg; +import com.yeshi.buwan.util.StringUtil; +import com.yeshi.buwan.util.mq.rabbit.RabbitmqManager; +import com.yeshi.buwan.util.video.VideoConstant; import org.hibernate.HibernateException; import org.hibernate.SQLQuery; import org.hibernate.Session; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.Cacheable; import org.springframework.orm.hibernate4.HibernateCallback; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.yeshi.buwan.dao.CategoryVideoDao; -import com.yeshi.buwan.dao.VideoInfoDao; -import com.yeshi.buwan.domain.CategoryVideo; -import com.yeshi.buwan.domain.ResourceVideo; -import com.yeshi.buwan.domain.VideoDetailInfo; -import com.yeshi.buwan.domain.VideoInfo; -import com.yeshi.buwan.domain.VideoResource; -import com.yeshi.buwan.domain.VideoType; -import com.yeshi.buwan.domain.VideoUrl; -import com.yeshi.buwan.domain.entity.PlayUrl; +import javax.annotation.Resource; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; @Service public class VideoInfoService { - @Autowired - private VideoInfoDao dao; + @Autowired + private VideoInfoDao videoInfoDao; - @Autowired - private CategoryVideoDao cdao; + @Autowired + private CategoryVideoDao categoryVideoDao; - @Autowired - private ResourceVideoService resourceVideoService; + @Autowired + private ResourceVideoService resourceVideoService; - @Resource - private VideoResourceService videoResourceService; + @Resource + private VideoResourceService videoResourceService; - public VideoInfo getVideoInfo(String vid) { - return dao.find(VideoInfo.class, vid); - } + @Resource + private ClearService clearService; - @SuppressWarnings("unchecked") - public List<VideoInfo> simpleRandomVideoList(final int i) { - return (List<VideoInfo>) dao.excute(new HibernateCallback<List<VideoInfo>>() { + @Resource + private RabbitmqManager rabbitmqManager; - @Override - public List<VideoInfo> doInHibernate(Session session) throws HibernateException { - SQLQuery query = session.createSQLQuery( - "SELECT v.* FROM wk_video_video v RIGHT JOIN (SELECT * FROM wk_recommend_category_cache WHERE videotypeid = 152 ORDER BY RAND() LIMIT 0," - + i + ") c ON c.videoid=v.id"); - query.addEntity(VideoInfo.class); - return query.list(); - } - }); - } - public VideoInfo getVideoInfo(String name, VideoType videoType) { - List<VideoInfo> list = dao.list( - "select c.video from CategoryVideo c where c.video.name = ? and c.videoType.id = ?", - new Serializable[] { name, videoType.getId() }); - if (list.size() > 0) { - return list.get(0); - } - return null; - } - @Transactional - public void save(VideoInfo videoInfo) { - dao.save(videoInfo); - CategoryVideo ca = new CategoryVideo(); - ca.setVideo(videoInfo); - ca.setVideoType(videoInfo.getVideoType()); - cdao.create(ca); - List<VideoResource> resourceList = videoInfo.getResourceList(); - ResourceVideo rs = null; - for (VideoResource videoResource : resourceList) { - rs = new ResourceVideo(); - rs.setResource(videoResource); - rs.setVideo(videoInfo); - resourceVideoService.save(rs); - } - } + @Transactional + public VideoInfo getVideoInfo(String vid) { + return videoInfoDao.find(VideoInfo.class, vid); + } - public List<VideoDetailInfo> getVideoDetailList(String videoid, VideoResource vr) { - VideoInfo find = dao.find(VideoInfo.class, videoid); - if (find != null) { - if (vr.getName().equals("AcFun")) { - List<VideoDetailInfo> detailInfos = new ArrayList<VideoDetailInfo>(); - VideoDetailInfo vd = new VideoDetailInfo(); - vd.setVideo(find); - vd.setIntroduction(find.getIntroduction()); - vd.setName(find.getName()); - vd.setTag(""); - vd.setType("acFunVideo"); - vd.setId(Long.parseLong(find.getId())); - vd.setWatchCount(Long.parseLong(find.getWatchCount())); - VideoUrl vurl = new VideoUrl(); - vurl.setResource(vr); - vurl.setUrl(find.getBaseurl()); - vurl.setInvalid(0 + ""); - vurl.setBaseUrl(find.getBaseurl()); - List<VideoUrl> urls = new ArrayList<VideoUrl>(); - urls.add(vurl); - vd.setUrls(urls); - detailInfos.add(vd); - return detailInfos; - } - } + @Cacheable(value = "videoCache", key = "'getVideoInfoDetail-'+#vid") + public VideoInfo getVideoInfoCache(String vid) { + return videoInfoDao.find(VideoInfo.class, vid); + } - return null; - } - public PlayUrl getPlayUrl(String detailSystemId, String id, String type, int resourceid, String videoid) { - if (type.equals("acFunVideo")) { - PlayUrl playUrl = new PlayUrl(); - VideoResource videoResource = videoResourceService.getResource(resourceid + ""); - playUrl.setResource(videoResource); - VideoInfo find = dao.find(VideoInfo.class, videoid); - playUrl.setUrl(find.getBaseurl()); - playUrl.setPlayType(1); - playUrl.setParams(""); - // 娣诲姞鎾斁娆℃暟 - find.setWatchCount("" + (Integer.parseInt(find.getWatchCount()) + 1)); - dao.update(find); - return playUrl; - } - return null; - } + @SuppressWarnings("unchecked") + public List<VideoInfo> simpleRandomVideoList(final int i) { + return (List<VideoInfo>) videoInfoDao.excute(new HibernateCallback<List<VideoInfo>>() { + + @Override + public List<VideoInfo> doInHibernate(Session session) throws HibernateException { + SQLQuery query = session.createSQLQuery( + "SELECT v.* FROM wk_video_video v RIGHT JOIN (SELECT * FROM wk_recommend_category_cache WHERE videotypeid = 152 ORDER BY RAND() LIMIT 0," + + i + ") c ON c.videoid=v.id"); + query.addEntity(VideoInfo.class); + return query.list(); + } + }); + } + + public VideoInfo getVideoInfo(String name, VideoType videoType) { + List<VideoInfo> list = videoInfoDao.list( + "select c.video from CategoryVideo c where c.video.name = ? and c.videoType.id = ?", + new Serializable[]{name, videoType.getId()}); + if (list.size() > 0) { + return list.get(0); + } + return null; + } + + @Transactional + public void saveWithCategoryAndResource(VideoInfo videoInfo) { + videoInfoDao.save(videoInfo); + rabbitmqManager.addVideoDataChanged(new VideoDataChangeMQMsg(VideoDataChangeMQMsg.TYPE_VIDEO_INFO, videoInfo.getId(), VideoDataChangeMQMsg.ACTION_ADD)); + CategoryVideo ca = new CategoryVideo(); + ca.setVideo(videoInfo); + ca.setVideoType(videoInfo.getVideoType()); + categoryVideoDao.create(ca); + rabbitmqManager.addVideoDataChanged(new VideoDataChangeMQMsg(VideoDataChangeMQMsg.TYPE_VIDEO_CATEGORY, videoInfo.getId(), VideoDataChangeMQMsg.ACTION_ADD)); + List<VideoResource> resourceList = videoInfo.getResourceList(); + ResourceVideo rs = null; + for (VideoResource videoResource : resourceList) { + rs = new ResourceVideo(); + rs.setResource(videoResource); + rs.setVideo(videoInfo); + resourceVideoService.save(rs); + } + rabbitmqManager.addVideoDataChanged(new VideoDataChangeMQMsg(VideoDataChangeMQMsg.TYPE_VIDEO_RESOURCE, videoInfo.getId(), VideoDataChangeMQMsg.ACTION_ADD)); + } + + + @Transactional + public Serializable save(VideoInfo videoInfo) { + Serializable id = videoInfoDao.save(videoInfo); + rabbitmqManager.addVideoDataChanged(new VideoDataChangeMQMsg(VideoDataChangeMQMsg.TYPE_VIDEO_INFO, videoInfo.getId(), VideoDataChangeMQMsg.ACTION_ADD)); + return id; + } + + @Transactional + public void update(VideoInfo videoInfo) { + videoInfoDao.update(videoInfo); + rabbitmqManager.addVideoDataChanged(new VideoDataChangeMQMsg(VideoDataChangeMQMsg.TYPE_VIDEO_INFO, videoInfo.getId(), VideoDataChangeMQMsg.ACTION_UPDATE)); + } + + public List<VideoDetailInfo> getVideoDetailList(String videoid, VideoResource vr, int page, int pageSize) { + VideoInfo find = videoInfoDao.find(VideoInfo.class, videoid); + if (find != null) { + if (vr.getName().equals("AcFun")) { + List<VideoDetailInfo> detailInfos = new ArrayList<VideoDetailInfo>(); + VideoDetailInfo vd = new VideoDetailInfo(); + vd.setVideo(find); + vd.setIntroduction(find.getIntroduction()); + vd.setName(find.getName()); + vd.setTag(""); + vd.setType("acFunVideo"); + vd.setId(Long.parseLong(find.getId())); + vd.setWatchCount(Long.parseLong(find.getWatchCount())); + VideoUrl vurl = new VideoUrl(); + vurl.setResource(vr); + vurl.setUrl(find.getBaseurl()); + vurl.setInvalid(0 + ""); + vurl.setBaseUrl(find.getBaseurl()); + List<VideoUrl> urls = new ArrayList<VideoUrl>(); + urls.add(vurl); + vd.setUrls(urls); + detailInfos.add(vd); + return detailInfos; + } + } + + return null; + } + + public PlayUrl getPlayUrl(String detailSystemId, String id, String type, int resourceid, String videoid) { + if (type.equals("acFunVideo")) { + PlayUrl playUrl = new PlayUrl(); + VideoResource videoResource = videoResourceService.getResource(resourceid + ""); + playUrl.setResource(videoResource); + VideoInfo find = videoInfoDao.find(VideoInfo.class, videoid); + playUrl.setUrl(find.getBaseurl()); + playUrl.setPlayType(1); + playUrl.setParams(""); + // 娣诲姞鎾斁娆℃暟 + find.setWatchCount("" + (Integer.parseInt(find.getWatchCount()) + 1)); + videoInfoDao.update(find); + return playUrl; + } + return null; + } + + + /** + * 鏄惁瀛樺湪鐩稿悓鐨勮棰�(鏍规嵁鍚嶇О涓庝笂鏄犳椂闂�) + * + * @param newVideoInfo + * @return + */ + public VideoInfo getExistSameVideoWithTime(VideoInfo newVideoInfo) { + int year = Integer.parseInt(newVideoInfo.getYear()); + List<VideoInfo> list = videoInfoDao.listByName(newVideoInfo.getName(), 0, 5); + if (list != null && list.size() > 0) + for (int i = 0; i < list.size(); i++) { + if (Math.abs(Integer.parseInt(list.get(i).getYear()) - year) < 2) {// 骞翠唤鐩稿樊1骞翠互涓嬩笖灞炰簬鍚屼竴涓垎绫绘墠褰掍负涓�璧� + // 鍒ゆ柇鍒嗙被 + if (VideoConstant.isMainCategory(newVideoInfo.getVideoType().getId())) {// 姝g墖鍒嗙被 + List<CategoryVideo> cvList = categoryVideoDao.listByVideoId(list.get(i).getId()); + boolean isS = false; + for (CategoryVideo cv : cvList) { + if (newVideoInfo.getVideoType().getId() == cv.getVideoType().getId() + || (cv.getVideoType().getParent() != null && newVideoInfo.getVideoType().getId() == + cv.getVideoType().getParent().getId())) {// 绫诲瀷鐩稿悓 + return list.get(i); + } + } + } else // 涓嶅繀姣旇緝鍒嗙被--鍙鍚嶇О鐩稿悓鍒欏垽鏂负鐩稿悓 + { // 鍒ゆ柇涓婁釜鏄惁涓烘鐗囧垎绫� + List<CategoryVideo> typeList = categoryVideoDao.listByVideoId(list.get(i).getId()); + boolean isZhengpian = false; + if (typeList != null) + for (CategoryVideo categoryVideo : typeList) { + VideoType ltype = categoryVideo.getVideoType(); + if (VideoConstant.isMainCategory(ltype.getId()) + || (ltype.getParent() != null && VideoConstant.isMainCategory(ltype.getParent().getId()))) { + isZhengpian = true; + break; + } + } + + if (!isZhengpian) + return list.get(i); + else + return null; + } + } + } + return null; + } + + + /** + * 鏍规嵁鍚嶇О涓庝富婕� + * + * @param newVideoInfo + * @return + */ + public VideoInfo getExistSameVideoWithDirector(VideoInfo newVideoInfo) { + List<VideoInfo> list = videoInfoDao.listByName(newVideoInfo.getName(), 0, 5); + if (list != null && list.size() > 0) { + if (VideoConstant.isMainCategory(newVideoInfo.getVideoType().getId())) { + for (int i = 0; i < list.size(); i++) { + VideoInfo vi = list.get(i); + if (getSameDirectorOrActorCount(vi.getDirector(), newVideoInfo.getDirector()) > 0 || getSameDirectorOrActorCount(vi.getMainActor(), newVideoInfo.getMainActor()) > 0) { +// if (getSameDirectorOrActorCount(vi.getMainActor(), newVideoInfo.getMainActor()) > 0) { + //涓诲垎绫讳竴鏍� + if (vi.getVideoType() != null && newVideoInfo.getVideoType() != null && vi.getVideoType().getId() == newVideoInfo.getVideoType().getId()) + return list.get(i); +// } + } + } + } else { + return list.get(0); + } + } + return null; + } + + private int getSameDirectorOrActorCount(String d1, String d2) { + if (!StringUtil.isNullOrEmpty(d1) && !StringUtil.isNullOrEmpty(d2)) { + List<String> d1List = new ArrayList<>(); + if (d1.contains("/")) { + d1List.addAll(Arrays.asList(d1.trim().split("/"))); + } else { + d1List.addAll(Arrays.asList(d1.trim().split(" "))); + } + + List<String> d2List = new ArrayList<>(); + if (d2.contains("/")) + d2List.addAll(Arrays.asList(d2.trim().split("/"))); + else + d2List.addAll(Arrays.asList(d2.trim().split(" "))); + + d1List.retainAll(d2List); + + return d1List.size(); + } + + return 0; + } + + + public List<VideoInfo> listByVideoIds(List<String> videoIds) { + return videoInfoDao.listByVideoIds(videoIds); + } + + @Transactional + public void hiddenVideo(String id) { + VideoInfo videoInfo = videoInfoDao.find(VideoInfo.class, id); + if (videoInfo != null && "1".equalsIgnoreCase(videoInfo.getShow())) { + videoInfo.setShow("0"); + videoInfoDao.update(videoInfo); + } + } + + + //浠庢柊缁熻 + public void statisticVideoExtraInfo(String videoId) { + videoInfoDao.statisticVideoExtraInfo(videoId); + } + + /** + * 鍒楄〃鏌ヨ + * + * @param query + * @return + */ + public List<VideoInfo> list(VideoInfoDao.DaoQuery query) { + return videoInfoDao.list(query); + } + + public long count(VideoInfoDao.DaoQuery query) { + return videoInfoDao.count(query); + } + + + public void updateVideoInfo(VideoInfo videoInfo) { + VideoInfo oldVideo = videoInfoDao.find(VideoInfo.class, videoInfo.getId()); + if (oldVideo == null) + return; + + videoInfoDao.updateSelective(videoInfo); + //鏄惁闇�瑕佹洿鏂版悳绱㈠紩鎿� + boolean needUpdateSolr = false; + //tag鍙樺寲 + if (videoInfo.getTag() != null && !videoInfo.getTag().equalsIgnoreCase(oldVideo.getTag())) { + needUpdateSolr = true; + } + + //鍚嶇О鍙樺寲 + if (videoInfo.getName() != null && !videoInfo.getName().equalsIgnoreCase(oldVideo.getName())) { + needUpdateSolr = true; + } + + //picture鍙樺寲 + if (videoInfo.getHpicture() != null && !videoInfo.getHpicture().equalsIgnoreCase(oldVideo.getHpicture())) { + needUpdateSolr = true; + } + if (videoInfo.getVpicture() != null && !videoInfo.getVpicture().equalsIgnoreCase(oldVideo.getVpicture())) { + needUpdateSolr = true; + } + + if (videoInfo.getPicture() != null && !videoInfo.getPicture().equalsIgnoreCase(oldVideo.getPicture())) { + needUpdateSolr = true; + } + + //瑙嗛绫诲瀷鍙戠敓鍙樺寲 + if (videoInfo.getVideoType() != null && (oldVideo.getVideoType() == null || videoInfo.getVideoType().getId() != oldVideo.getVideoType().getId())) { + needUpdateSolr = true; + } + + //鏄惁鏄剧ず + if (videoInfo.getShow() != null && !videoInfo.getShow().equalsIgnoreCase(oldVideo.getShow())) { + needUpdateSolr = true; + } + + if (needUpdateSolr) { + rabbitmqManager.addSolrMsg(videoInfo.getId()); + } + + + } } -- Gitblit v1.8.0