From 89e370bfdda29ac8a8f7080a18dc09a6ddc75c09 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期一, 26 十月 2020 18:42:16 +0800 Subject: [PATCH] 风行爱奇艺视频更新 --- src/main/java/com/yeshi/buwan/service/manager/SolrAlbumDataManager.java | 55 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 48 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/yeshi/buwan/service/manager/SolrAlbumDataManager.java b/src/main/java/com/yeshi/buwan/service/manager/SolrAlbumDataManager.java index 8fe3f86..3949aa9 100644 --- a/src/main/java/com/yeshi/buwan/service/manager/SolrAlbumDataManager.java +++ b/src/main/java/com/yeshi/buwan/service/manager/SolrAlbumDataManager.java @@ -2,8 +2,13 @@ import com.yeshi.buwan.domain.SolrVideo; import com.yeshi.buwan.domain.VideoInfo; +import com.yeshi.buwan.domain.video.AlbumVideoMap; +import com.yeshi.buwan.dto.search.SolrResultDTO; +import com.yeshi.buwan.service.imp.VideoInfoService; +import com.yeshi.buwan.service.inter.juhe.AlbumVideoMapService; import com.yeshi.buwan.util.factory.SolrVideoFactory; import org.apache.solr.client.solrj.response.UpdateResponse; +import org.springframework.data.domain.Sort; import org.springframework.data.solr.core.SolrTemplate; import org.springframework.data.solr.core.query.Criteria; import org.springframework.data.solr.core.query.Query; @@ -23,6 +28,12 @@ @Resource private SolrTemplate solrTemplate; + + @Resource + private AlbumVideoMapService albumVideoMapService; + + @Resource + private VideoInfoService videoInfoService; public void saveOrUpdate(VideoInfo videoInfo) { @@ -61,11 +72,10 @@ return solrVideo; } - public List<SolrVideo> findByKey(String key, Integer contentType, Integer videoType, int page) { - int pageSize = 20; - Query query = new SimpleQuery("name:\"" + key+"\""); + public SolrResultDTO findByKey(String key, Integer contentType, Integer videoType, int page, int pageSize) { + Query query = new SimpleQuery("name:\"" + key + "\""); - Criteria criteria =new Criteria("contenttype").is(contentType); + Criteria criteria = new Criteria("contenttype").is(contentType); if (videoType != null) criteria = criteria.and("root_video_type").is(videoType); @@ -75,17 +85,18 @@ query.addCriteria(criteria); /** 璁剧疆鍒嗛〉寮�濮嬭褰曟暟(绗竴椤�) 榛樿0 */ - query.setOffset((page - 1) * page); + query.setOffset((page - 1) * pageSize); /** 璁剧疆姣忛〉鏄剧ず璁板綍鏁帮紝榛樿10 */ query.setRows(pageSize); + query.addSort(new Sort(Sort.Direction.DESC, "year")); ScoredPage<SolrVideo> result = solrTemplate.queryForPage(query, SolrVideo.class); System.out.println("鎬昏褰曟暟锛�" + result.getTotalElements()); List<SolrVideo> list = result.getContent(); - return list; + return new SolrResultDTO(list, (int) result.getTotalElements()); } public List<String> getSuggestKeyList(String key) { - Query query = new SimpleQuery("name:\""+key+"\""); + Query query = new SimpleQuery("name:\"" + key + "\""); /** 璁剧疆鍒嗛〉寮�濮嬭褰曟暟(绗竴椤�) 榛樿0 */ query.setOffset(0); /** 璁剧疆姣忛〉鏄剧ず璁板綍鏁帮紝榛樿10 */ @@ -101,4 +112,34 @@ } + /** + * 鍚屾鎵�鏈変笓杈� + */ + public void syncAllAlbum() { + long count = albumVideoMapService.countAll(); + int pageSize = 100; + int pageCount = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1); + for (int i = 3; i < pageCount; i++) { + List<String> videoIds = new ArrayList<>(); + List<AlbumVideoMap> albumVideoMapList = albumVideoMapService.listAll(i + 1, pageSize); + for (AlbumVideoMap map : albumVideoMapList) { + videoIds.add(map.getVideoId()); + } + List<VideoInfo> videoList = videoInfoService.listByVideoIds(videoIds); + saveOrUpdate(videoList); + } + } + + public void syncAlbum(String videoId) { + AlbumVideoMap map = albumVideoMapService.selectByVideoId(videoId); + if (map == null) + return; + + List<VideoInfo> videoList = new ArrayList<>(); + VideoInfo video = videoInfoService.getVideoInfo(videoId); + if (video != null) + videoList.add(video); + saveOrUpdate(videoList); + } + } -- Gitblit v1.8.0