package com.yeshi.buwan.controller.parser;
|
|
import com.yeshi.buwan.domain.VideoInfo;
|
import com.yeshi.buwan.domain.VideoType;
|
import com.yeshi.buwan.domain.solr.SolrAlbumVideo;
|
import com.yeshi.buwan.domain.solr.SolrShortVideo;
|
import com.yeshi.buwan.domain.special.SearchSpecial;
|
import com.yeshi.buwan.domain.special.SearchSpecialPositionMap;
|
import com.yeshi.buwan.domain.video.InternetSearchVideo;
|
import com.yeshi.buwan.dto.search.SolrResultDTO;
|
import com.yeshi.buwan.service.inter.search.SearchSpecialPositionMapService;
|
import com.yeshi.buwan.service.inter.search.SearchSpecialService;
|
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.*;
|
import com.yeshi.buwan.util.factory.VideoInfoFactory;
|
import com.yeshi.buwan.vo.AcceptData;
|
import net.sf.json.JSONArray;
|
import net.sf.json.JSONObject;
|
import org.springframework.stereotype.Controller;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletRequest;
|
import java.io.PrintWriter;
|
import java.util.ArrayList;
|
import java.util.Collections;
|
import java.util.List;
|
|
@Controller
|
public class SearchParser {
|
@Resource
|
private SearchSpecialService searchSpecialService;
|
|
@Resource
|
private SearchSpecialPositionMapService searchSpecialPositionMapService;
|
|
@Resource
|
private SolrAlbumVideoDataManager solrAlbumVideoDataManager;
|
|
@Resource
|
private SolrInternetSearchVideoDataManager solrInternetSearchVideoDataManager;
|
|
@Resource
|
private SolrShortVideoDataManager solrShortVideoDataManager;
|
|
|
/**
|
* 获取专题视频
|
*
|
* @param acceptData
|
* @param out
|
*/
|
public void getSpecialVideo(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
|
String key = request.getParameter("key");
|
SearchSpecial searchSpecial = searchSpecialService.selectByPrimaryKey(key);
|
if (searchSpecial == null) {
|
out.print(JsonUtil.loadFalseJson("搜索专题不存在"));
|
return;
|
}
|
|
String page = request.getParameter("page");
|
if (!NumberUtil.isNumeric(page)) {
|
out.print(JsonUtil.loadFalseJson("页码错误"));
|
return;
|
}
|
int pageIndex = Integer.parseInt(page);
|
switch (key) {
|
case "3#hanju-bagua":
|
pageIndex++;
|
break;
|
case "3#hanju-news":
|
pageIndex += 2;
|
break;
|
case "3#hanju-stars":
|
pageIndex += 3;
|
break;
|
case "3#hanju-hots":
|
pageIndex += 4;
|
|
case "3#hanju-music":
|
pageIndex += 5;
|
break;
|
}
|
|
List<VideoInfo> videoInfoList = new ArrayList<>();
|
|
int pageSize = Constant.pageCount;
|
boolean hasNextPage = false;
|
if (searchSpecial.getAlbumQuery() != null) {
|
SolrResultDTO solrResultDTO = solrAlbumVideoDataManager.find(searchSpecial.getAlbumQuery(), pageIndex, pageSize);
|
if (solrResultDTO != null) {
|
List<SolrAlbumVideo> list = solrResultDTO.getVideoList();
|
if (list != null) {
|
for (SolrAlbumVideo av : list) {
|
videoInfoList.add(VideoInfoFactory.create(av));
|
}
|
if (list.size() > 0) {
|
hasNextPage = true;
|
}
|
}
|
}
|
}
|
|
if (searchSpecial.getInternetQuery() != null) {
|
SolrResultDTO solrResultDTO = solrInternetSearchVideoDataManager.find(searchSpecial.getInternetQuery(), pageIndex, pageSize);
|
if (solrResultDTO != null) {
|
List<InternetSearchVideo> list = solrResultDTO.getVideoList();
|
if (list != null) {
|
for (InternetSearchVideo av : list) {
|
videoInfoList.add(VideoInfoFactory.create(av));
|
}
|
if (list.size() > 0) {
|
hasNextPage = true;
|
}
|
}
|
}
|
}
|
|
if (searchSpecial.getShortQuery() != null) {
|
SolrResultDTO solrResultDTO = solrShortVideoDataManager.find(searchSpecial.getShortQuery(), pageIndex, pageSize);
|
if (solrResultDTO != null) {
|
List<SolrShortVideo> list = solrResultDTO.getVideoList();
|
if (list != null) {
|
for (SolrShortVideo av : list) {
|
videoInfoList.add(VideoInfoFactory.create(av));
|
}
|
Collections.shuffle(videoInfoList);
|
if (list.size() > 0) {
|
hasNextPage = true;
|
}
|
}
|
}
|
}
|
|
JSONArray array = new JSONArray();
|
for (int i = 0; i < videoInfoList.size(); i++) {
|
videoInfoList.get(i).setPicture(VideoPictureUtil.getShowPicture(videoInfoList.get(i), acceptData.getPlatform(), acceptData.getVersion() + ""));
|
array.add(StringUtil.outPutResultJson(videoInfoList.get(i)));
|
}
|
JSONObject data = new JSONObject();
|
data.put("hasNextPage", hasNextPage);
|
data.put("list", array);
|
data.put("column", searchSpecial.getColumn());
|
out.print(JsonUtil.loadTrueJson(data.toString()));
|
}
|
|
|
public void getSearchVideoType(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
|
String pid = request.getParameter("pid");
|
if (StringUtil.isNullOrEmpty(pid)) {
|
out.print(JsonUtil.loadFalseJson("位置ID不能为空"));
|
return;
|
}
|
JSONArray array = new JSONArray();
|
List<SearchSpecialPositionMap> mapList = searchSpecialPositionMapService.listDetailByPosition(pid, 0, 50);
|
for (SearchSpecialPositionMap map : mapList) {
|
JSONObject item = new JSONObject();
|
item.put("name", StringUtil.isNullOrEmpty(map.getShowName()) ? map.getSpecial().getName() : map.getShowName());
|
item.put("id", map.getSpecialId());
|
item.put("icon", map.getIcon());
|
array.add(item);
|
}
|
JSONObject data = new JSONObject();
|
data.put("list", array);
|
data.put("count", array.size());
|
out.print(JsonUtil.loadTrueJson(data.toString()));
|
}
|
|
|
}
|