package com.hxh.spring.test;
|
|
import com.yeshi.buwan.dao.HomeNoticeDao;
|
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.video.AlbumVideoMap;
|
import com.yeshi.buwan.domain.video.InternetSearchVideo;
|
import com.yeshi.buwan.dto.search.SolrResultDTO;
|
import com.yeshi.buwan.dto.search.SolrVideoSearchFilter;
|
import com.yeshi.buwan.pptv.PPTVUtil;
|
import com.yeshi.buwan.service.imp.VideoInfoService;
|
import com.yeshi.buwan.service.inter.juhe.AlbumVideoMapService;
|
import com.yeshi.buwan.service.inter.juhe.InternetSearchVideoService;
|
import com.yeshi.buwan.service.manager.SolrAlbumVideoDataManager;
|
import com.yeshi.buwan.service.manager.SolrCommonVideoDataManager;
|
import com.yeshi.buwan.service.manager.SolrInternetSearchVideoDataManager;
|
import com.yeshi.buwan.util.Constant;
|
import com.yeshi.buwan.util.StringUtil;
|
import com.yeshi.buwan.util.factory.VideoInfoFactory;
|
import com.yeshi.buwan.util.video.VideoConstant;
|
import org.junit.Test;
|
import org.junit.runner.RunWith;
|
import org.springframework.data.mongodb.core.query.Criteria;
|
import org.springframework.data.mongodb.core.query.Query;
|
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.*;
|
|
|
@RunWith(SpringJUnit4ClassRunner.class)
|
@ContextConfiguration(locations = {"classpath:spring.xml"})
|
@WebAppConfiguration
|
public class SolrTest {
|
|
@Resource
|
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 InternetSearchVideoService internetSearchVideoService;
|
|
@Test
|
public void test1() {
|
SolrVideoSearchFilter filter = new SolrVideoSearchFilter();
|
filter.setKey("");
|
filter.setVideoType(null);
|
filter.setContentType(1);
|
// filter.setResourceIds(new String[]{"24"});
|
|
SolrResultDTO dto = solrDataManager.find(filter, 1, 10);
|
System.out.println(dto);
|
}
|
|
@Test
|
public void addSolrAlbum() {
|
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() {
|
|
}
|
|
|
@Test
|
public void addInternet() {
|
InternetSearchVideo list = internetSearchVideoService.selectByPrimaryKey("9693a5f3de443fe48a5272ce12c859f3"); //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();
|
// }
|
|
|
}
|