From c6c5a8ce0f42d46ea2fe0312c9eda67a49fd3917 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期一, 01 二月 2021 18:58:21 +0800 Subject: [PATCH] 完善根据IP屏蔽广告,创建会员实体 --- src/main/java/com/yeshi/buwan/service/manager/SolrAlbumDataManager.java | 122 +++++++++++++++++++++++++++++++++++++--- 1 files changed, 111 insertions(+), 11 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..cc55f50 100644 --- a/src/main/java/com/yeshi/buwan/service/manager/SolrAlbumDataManager.java +++ b/src/main/java/com/yeshi/buwan/service/manager/SolrAlbumDataManager.java @@ -1,19 +1,34 @@ package com.yeshi.buwan.service.manager; +import com.yeshi.buwan.domain.ResourceVideo; import com.yeshi.buwan.domain.SolrVideo; import com.yeshi.buwan.domain.VideoInfo; +import com.yeshi.buwan.domain.VideoResource; +import com.yeshi.buwan.domain.video.AlbumVideoMap; +import com.yeshi.buwan.dto.search.SolrResultDTO; +import com.yeshi.buwan.dto.search.SolrVideoSearchFilter; +import com.yeshi.buwan.service.imp.ResourceVideoService; +import com.yeshi.buwan.service.imp.VideoInfoService; +import com.yeshi.buwan.service.inter.juhe.AlbumVideoMapService; +import com.yeshi.buwan.util.StringUtil; import com.yeshi.buwan.util.factory.SolrVideoFactory; import org.apache.solr.client.solrj.response.UpdateResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +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; import org.springframework.data.solr.core.query.SimpleQuery; +import org.springframework.data.solr.core.query.SolrDataQuery; import org.springframework.data.solr.core.query.result.ScoredPage; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * 鎼滅储寮曟搸-涓撹緫鏁版嵁绠$悊 @@ -21,12 +36,23 @@ @Component public class SolrAlbumDataManager { + private final Logger logger = LoggerFactory.getLogger(SolrAlbumDataManager.class); + @Resource private SolrTemplate solrTemplate; + @Resource + private AlbumVideoMapService albumVideoMapService; + + @Resource + private VideoInfoService videoInfoService; + + @Resource + private ResourceVideoService resourceVideoService; + public void saveOrUpdate(VideoInfo videoInfo) { - UpdateResponse updateResponse = solrTemplate.saveBean(SolrVideoFactory.create(videoInfo)); + UpdateResponse updateResponse = solrTemplate.saveBean(SolrVideoFactory.create(videoInfo, videoInfo.getResourceList())); if (updateResponse.getStatus() == 0) { solrTemplate.commit(); } else { @@ -37,7 +63,7 @@ public void saveOrUpdate(List<VideoInfo> videoInfoList) { List<SolrVideo> solrVideoList = new ArrayList<>(); for (VideoInfo vi : videoInfoList) { - solrVideoList.add(SolrVideoFactory.create(vi)); + solrVideoList.add(SolrVideoFactory.create(vi, vi.getResourceList())); } UpdateResponse updateResponse = solrTemplate.saveBeans(solrVideoList); if (updateResponse.getStatus() == 0) { @@ -47,7 +73,22 @@ } } + /** + *鍒犻櫎鎵�鏈� + */ + public void clear() { + Query query = new SimpleQuery("name:*"); + UpdateResponse updateResponse = solrTemplate.delete(query); + if (updateResponse.getStatus() == 0) { + solrTemplate.commit(); + } else { + solrTemplate.rollback(); + } + } + public void deleteById(String id) { + + UpdateResponse updateResponse = solrTemplate.deleteById(id); if (updateResponse.getStatus() == 0) { solrTemplate.commit(); @@ -61,31 +102,40 @@ 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 find(SolrVideoSearchFilter filter, int page, int pageSize) { + logger.info(filter.getKey() + "#" + page); + Query query = new SimpleQuery("name:\"" + filter.getKey() + "\""); - Criteria criteria =new Criteria("contenttype").is(contentType); + Criteria criteria = new Criteria("contenttype").is(filter.getContentType()); - if (videoType != null) - criteria = criteria.and("root_video_type").is(videoType); + if (filter.getVideoType() != null) { + criteria = criteria.and("root_video_type").is(filter.getVideoType()); + } + if (filter.getResourceIds() != null && filter.getResourceIds().length > 0) { + criteria = criteria.and("resourceIds").contains(filter.getResourceIds()); + } /** 娣诲姞鏉′欢 */ if (criteria != null) query.addCriteria(criteria); /** 璁剧疆鍒嗛〉寮�濮嬭褰曟暟(绗竴椤�) 榛樿0 */ - query.setOffset((page - 1) * page); + query.setOffset((page - 1) * pageSize); /** 璁剧疆姣忛〉鏄剧ず璁板綍鏁帮紝榛樿10 */ query.setRows(pageSize); + if (StringUtil.isNullOrEmpty(filter.getSortKey())) { + query.addSort(new Sort(Sort.Direction.DESC, "year")); + } else { + query.addSort(new Sort(Sort.Direction.DESC, filter.getSortKey())); + } 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 +151,54 @@ } + /** + * 鍚屾鎵�鏈変笓杈� + */ + 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); + + //鑾峰彇璧勬簮ID + List<ResourceVideo> rvList = resourceVideoService.getResourceList(videoList); + Map<String, List<VideoResource>> map = new HashMap<>(); + for (ResourceVideo rv : rvList) { + if (rv.getVideo() != null && rv.getResource() != null) { + if (map.get(rv.getVideo().getId()) == null) + map.put(rv.getVideo().getId(), new ArrayList<>()); + map.get(rv.getVideo().getId()).add(rv.getResource()); + } + } + for (VideoInfo vi : videoList) { + if (map.get(vi.getId()) != null) { + vi.setResourceList(map.get(vi.getId())); + } + } + + saveOrUpdate(videoList); + } + } + + public void syncAlbum(String videoId) { + AlbumVideoMap map = albumVideoMapService.selectByVideoId(videoId); + if (map == null) + return; + VideoInfo video = videoInfoService.getVideoInfo(videoId); + if (video != null) { + List<ResourceVideo> rvList = resourceVideoService.getResourceList(video.getId()); + List<VideoResource> vrList = new ArrayList<>(); + for (ResourceVideo rv : rvList) + vrList.add(rv.getResource()); + video.setResourceList(vrList); + saveOrUpdate(video); + } + } + } -- Gitblit v1.8.0