| | |
| | | package com.hxh.spring.test; |
| | | |
| | | import com.yeshi.buwan.dao.HomeNoticeDao; |
| | | import com.yeshi.buwan.domain.HomeNotice; |
| | | import com.yeshi.buwan.domain.SolrVideo; |
| | | import com.yeshi.buwan.dao.juhe.youku.InternetSearchVideoDao; |
| | | import com.yeshi.buwan.dao.video.AlbumVideoMapDao; |
| | | import com.yeshi.buwan.domain.VideoInfo; |
| | | import com.yeshi.buwan.domain.solr.SolrAlbumVideo; |
| | | import com.yeshi.buwan.domain.solr.SolrShortVideo; |
| | | import com.yeshi.buwan.domain.video.AlbumVideoMap; |
| | | import com.yeshi.buwan.domain.video.InternetSearchVideo; |
| | | import com.yeshi.buwan.dto.search.SolrResultDTO; |
| | | import com.yeshi.buwan.dto.search.SolrShortVideoSearchFilter; |
| | | import com.yeshi.buwan.dto.search.SolrVideoSearchFilter; |
| | | import com.yeshi.buwan.iqiyi.util.IqiyiUtil; |
| | | import com.yeshi.buwan.service.imp.VideoInfoService; |
| | | import com.yeshi.buwan.service.manager.SolrAlbumDataManager; |
| | | import com.yeshi.buwan.service.inter.juhe.AlbumVideoMapService; |
| | | import com.yeshi.buwan.service.inter.juhe.InternetSearchVideoService; |
| | | import com.yeshi.buwan.service.manager.SolrCommonVideoDataManager; |
| | | import com.yeshi.buwan.service.manager.search.SolrAlbumVideoDataManager; |
| | | import com.yeshi.buwan.service.manager.search.SolrInternetSearchVideoDataManager; |
| | | import com.yeshi.buwan.service.manager.search.SolrShortVideoDataManager; |
| | | import com.yeshi.buwan.util.StringUtil; |
| | | import com.yeshi.buwan.util.factory.VideoInfoFactory; |
| | | import com.yeshi.buwan.util.video.VideoConstant; |
| | | import net.sf.json.JSONObject; |
| | | import org.junit.Test; |
| | | import org.junit.runner.RunWith; |
| | | import org.springframework.data.solr.server.support.HttpSolrClientFactory; |
| | | import org.springframework.data.solr.server.support.HttpSolrClientFactoryBean; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | | import org.springframework.data.mongodb.core.query.Update; |
| | | import org.springframework.test.context.ContextConfiguration; |
| | | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
| | | import org.springframework.test.context.web.WebAppConfiguration; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | |
| | | @RunWith(SpringJUnit4ClassRunner.class) |
| | |
| | | public class SolrTest { |
| | | |
| | | @Resource |
| | | private SolrAlbumDataManager solrDataManager; |
| | | private SolrAlbumVideoDataManager solrDataManager; |
| | | |
| | | @Resource |
| | | private SolrCommonVideoDataManager solrCommonVideoDataManager; |
| | | |
| | | @Resource |
| | | private VideoInfoService videoInfoService; |
| | | |
| | | @Resource |
| | | private HomeNoticeDao homeNoticeDao; |
| | | @Resource |
| | | private AlbumVideoMapService albumVideoMapService; |
| | | |
| | | @Resource |
| | | private SolrInternetSearchVideoDataManager solrInternetSearchVideoDataManager; |
| | | |
| | | @Resource |
| | | private SolrShortVideoDataManager solrShortVideoDataManager; |
| | | |
| | | @Resource |
| | | private InternetSearchVideoService internetSearchVideoService; |
| | | |
| | | @Test |
| | | public void test1() { |
| | |
| | | |
| | | @Test |
| | | public void addSolrAlbum() { |
| | | solrDataManager.syncAlbum("8224447"); |
| | | |
| | | HttpSolrClientFactory factory=new HttpSolrClientFactory(); |
| | | |
| | | solrDataManager.syncAlbum("8268378"); |
| | | System.out.println(); |
| | | } |
| | | |
| | | |
| | | @Test |
| | | public void syncSolrCommonVideo() { |
| | | // solrCommonVideoDataManager.syncAllVideo(); |
| | | } |
| | | |
| | | |
| | | private VideoInfo loadAlbumData(VideoInfo video) { |
| | | video.setShowType(1); |
| | | if (!StringUtil.isNullOrEmpty(video.getMainActor())) { |
| | | video.setMainActor("主演:" + video.getMainActor()); |
| | | } |
| | | |
| | | //设置tag |
| | | String tag = ""; |
| | | if (!StringUtil.isNullOrEmpty(video.getYear())) { |
| | | tag += video.getYear() + "/"; |
| | | } |
| | | |
| | | if (video.getVideoType() != null) { |
| | | String vt = VideoConstant.getMainCategoryName(video.getVideoType().getId()); |
| | | if (!StringUtil.isNullOrEmpty(vt)) { |
| | | tag += vt + "/"; |
| | | } |
| | | } |
| | | |
| | | if (!StringUtil.isNullOrEmpty(video.getArea())) { |
| | | tag += video.getArea() + "/"; |
| | | } |
| | | |
| | | if (tag.endsWith("/")) |
| | | tag = tag.substring(0, tag.length() - 1); |
| | | video.setTag(tag); |
| | | |
| | | return video; |
| | | } |
| | | |
| | | |
| | | private int searchAll(String key) { |
| | | int page = 1; |
| | | int pageSize = 20; |
| | | SolrVideoSearchFilter filter = new SolrVideoSearchFilter(); |
| | | filter.setKey(key); |
| | | filter.setContentType(1); |
| | | List<VideoInfo> localList = new ArrayList<>(); |
| | | SolrResultDTO solrResultDTO = solrDataManager.find(filter, page, pageSize); |
| | | Set<String> albumSet = new HashSet<>(); |
| | | if (solrResultDTO != null) { |
| | | for (SolrAlbumVideo sv : (List<SolrAlbumVideo>) solrResultDTO.getVideoList()) { |
| | | VideoInfo video = VideoInfoFactory.create(sv); |
| | | albumSet.add(video.getName() + "#" + video.getVideoType().getId()); |
| | | video = loadAlbumData(video); |
| | | localList.add(video); |
| | | } |
| | | } |
| | | |
| | | |
| | | //全网搜 |
| | | SolrResultDTO internetSearchResultDTO = solrInternetSearchVideoDataManager.find(filter, page, pageSize); |
| | | if (internetSearchResultDTO != null && internetSearchResultDTO.getVideoList().size() > 0) { |
| | | List<InternetSearchVideo> isvList = internetSearchResultDTO.getVideoList(); |
| | | //删除前面有的数据,根据rootType与名称筛选 |
| | | for (int i = 0; i < isvList.size(); i++) { |
| | | String uniqueId = isvList.get(i).getName() + "#" + isvList.get(i).getRootType(); |
| | | if (albumSet.contains(uniqueId)) { |
| | | isvList.remove(i); |
| | | i--; |
| | | } |
| | | } |
| | | for (InternetSearchVideo sv : isvList) { |
| | | VideoInfo video = VideoInfoFactory.create(sv); |
| | | video = loadAlbumData(video); |
| | | localList.add(video); |
| | | } |
| | | } |
| | | return localList.size(); |
| | | } |
| | | |
| | | |
| | | @Test |
| | | public void search() { |
| | | String key = "大唐狄公案"; |
| | | SolrVideoSearchFilter filter = new SolrVideoSearchFilter(); |
| | | filter.setKey(key); |
| | | filter.setContentType(1); |
| | | |
| | | SolrResultDTO internetSearchResultDTO = solrInternetSearchVideoDataManager.find(filter, 1, 10); |
| | | } |
| | | |
| | | |
| | | @Test |
| | | public void addInternet() { |
| | | InternetSearchVideo list = internetSearchVideoService.selectByPrimaryKey("38ac0127d0cc3433e09964e757ab3505"); //listAll(1, 10); |
| | | solrInternetSearchVideoDataManager.saveOrUpdate(list); |
| | | } |
| | | |
| | | @Test |
| | | public void deleteInternet() { |
| | | String st = "161469b4aa35ca7ae1cc5d3ddaa23276,3b57b603b4eef496ce0de50f06ca40c0"; |
| | | |
| | | |
| | | for (String id : st.split(",")) |
| | | solrInternetSearchVideoDataManager.deleteById(id); |
| | | } |
| | | |
| | | |
| | | @Resource |
| | | private AlbumVideoMapDao albumVideoMapDao; |
| | | |
| | | @Test |
| | | public void test2() { |
| | | |
| | | for (int i = 0; i < 100; i++) { |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("id").type(7)); |
| | | query.limit(100); |
| | | List<AlbumVideoMap> list = albumVideoMapDao.findList(query); |
| | | |
| | | |
| | | for (AlbumVideoMap map : list) { |
| | | AlbumVideoMap newMap = new AlbumVideoMap(); |
| | | newMap.setVideoCount(map.getVideoCount()); |
| | | newMap.setRootVideoType(map.getRootVideoType()); |
| | | newMap.setVideoId(map.getVideoId()); |
| | | newMap.setCreateTime(new Date()); |
| | | newMap.setId(map.getVideoId()); |
| | | albumVideoMapDao.save(newMap); |
| | | albumVideoMapDao.deleteByPrimaryKey(map.getId()); |
| | | } |
| | | try { |
| | | Thread.sleep(1000); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // @Test |
| | | // public void clear(){ |
| | | // solrDataManager.clear(); |
| | | // } |
| | | |
| | | @Resource |
| | | private com.yeshi.buwan.job.video.ShortVideoUpdateJob shortVideoUpdateJob; |
| | | |
| | | @Test |
| | | public void iqiyiShortVideo() { |
| | | |
| | | JSONObject params = new JSONObject(); |
| | | params.put("videoType", 155); |
| | | params.put("url", "https://list.iqiyi.com/www/7/186-------------24-1-2-iqiyi--.html?s_source=PCW_LC"); |
| | | |
| | | try { |
| | | shortVideoUpdateJob.updateIqiyiShortVideo(params.toString()); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | //https://v.qq.com/channel/ent?_all=1&channel=ent&iarea=2&listpage=1&sort=40 |
| | | @Test |
| | | public void tencentShortVideo() { |
| | | JSONObject params = new JSONObject(); |
| | | params.put("videoType", 155); |
| | | params.put("area", "日韩"); |
| | | params.put("url", "https://v.qq.com/channel/ent?_all=1&channel=ent&iarea=2&listpage=1&sort=40"); |
| | | |
| | | try { |
| | | shortVideoUpdateJob.updateTencentShortVideo(params.toString()); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | public void clearShortVideo() { |
| | | SolrShortVideoSearchFilter filter = new SolrShortVideoSearchFilter(); |
| | | for (int i = 0; i < 4; i++) { |
| | | SolrResultDTO dto = solrShortVideoDataManager.find(filter, 1, 500); |
| | | List<SolrShortVideo> list = (List<SolrShortVideo>) dto.getVideoList(); |
| | | for (SolrShortVideo video : list) { |
| | | solrShortVideoDataManager.deleteById(video.getId()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | @Test |
| | | public void addToAlbum() { |
| | | albumVideoMapService.add(videoInfoService.getVideoInfo("8441251")); |
| | | } |
| | | |
| | | |
| | | @Test |
| | | public void getById() { |
| | | |
| | | SolrAlbumVideo solrAlbumVideo = solrDataManager.findOne("8441251"); |
| | | System.out.println(solrAlbumVideo); |
| | | } |
| | | |
| | | @Test |
| | | public void syncInternetSearch(){ |
| | | solrInternetSearchVideoDataManager.syncAllAlbum(); |
| | | } |
| | | |
| | | @Resource |
| | | private InternetSearchVideoDao internetSearchVideoDao; |
| | | |
| | | @Test |
| | | public void updateTag(){ |
| | | Query query=new Query(); |
| | | query.addCriteria(Criteria.where("tag").is("评分:null")); |
| | | List<InternetSearchVideo> list = internetSearchVideoDao.findList(query); |
| | | for(InternetSearchVideo video:list){ |
| | | InternetSearchVideo update=new InternetSearchVideo(); |
| | | update.setTag("评分:9.0"); |
| | | update.setId(video.getId()); |
| | | internetSearchVideoDao.updateSelective(update); |
| | | } |
| | | System.out.println(list); |
| | | } |
| | | |
| | | } |