admin
2021-03-25 f13ed98e1de0ec7b85ed179212cc095f63480eed
全网搜优酷兼容
18个文件已修改
4个文件已添加
2234 ■■■■ 已修改文件
src/main/java/com/yeshi/buwan/controller/parser/HomeParser.java 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/yeshi/buwan/controller/parser/UserParser.java 102 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/yeshi/buwan/dao/juhe/youku/YouKuSearchVideoMapDao.java 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/yeshi/buwan/domain/video/InternetSearchVideo.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/yeshi/buwan/dto/search/SolrVideoSearchFilter.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/yeshi/buwan/job/video/YouKuVideoUpdate.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/yeshi/buwan/mogotv/MogoTVApiUtil.java 163 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/yeshi/buwan/mogotv/MogoTVUtil.java 136 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/yeshi/buwan/service/imp/BanQuanService.java 1008 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/yeshi/buwan/service/imp/SearchService.java 251 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/yeshi/buwan/service/imp/VideoResourceService.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/yeshi/buwan/service/imp/juhe/YouKuServiceImpl.java 59 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/yeshi/buwan/service/inter/juhe/YouKuService.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/yeshi/buwan/service/manager/SolrAlbumVideoDataManager.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/yeshi/buwan/service/manager/SolrInternetSearchVideoDataManager.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/yeshi/buwan/util/factory/VideoInfoFactory.java 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/yeshi/buwan/util/video/VideoDetailUtil.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/yeshi/buwan/youku/YouKuUtil.java 137 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/test/java/com/hxh/spring/test/GeneralTest.java 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/test/java/com/hxh/spring/test/Iqiyi2.java 15 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/test/java/com/hxh/spring/test/SolrTest.java 106 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/test/java/com/hxh/spring/test/video/YouKuTest.java 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/yeshi/buwan/controller/parser/HomeParser.java
@@ -15,20 +15,27 @@
import com.yeshi.buwan.domain.recommend.HomeRecommendSpecial;
import com.yeshi.buwan.domain.system.DetailSystemConfig;
import com.yeshi.buwan.domain.system.DetailSystem;
import com.yeshi.buwan.domain.video.InternetSearchVideo;
import com.yeshi.buwan.domain.video.VideoWatchHistory;
import com.yeshi.buwan.dto.log.BaseLog;
import com.yeshi.buwan.pptv.PPTVUtil;
import com.yeshi.buwan.pptv.entity.PPTVSeries;
import com.yeshi.buwan.service.imp.*;
import com.yeshi.buwan.service.inter.juhe.InternetSearchVideoService;
import com.yeshi.buwan.service.inter.juhe.PPTVService;
import com.yeshi.buwan.service.inter.juhe.YouKuService;
import com.yeshi.buwan.service.inter.recommend.HomeRecommendSpecialService;
import com.yeshi.buwan.service.inter.video.VideoWatchHistoryService;
import com.yeshi.buwan.util.*;
import com.yeshi.buwan.util.annotation.RequireUid;
import com.yeshi.buwan.util.factory.VideoInfoFactory;
import com.yeshi.buwan.util.log.LoggerUtil;
import com.yeshi.buwan.util.log.UserActiveLogFactory;
import com.yeshi.buwan.util.log.VideoLogFactory;
import com.yeshi.buwan.vo.AcceptData;
import com.yeshi.buwan.youku.YouKuUtil;
import com.yeshi.buwan.youku.entity.YouKuSearchVideoMap;
import com.yeshi.buwan.youku.entity.YouKuShowDetail;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;
@@ -347,9 +354,44 @@
        out.print(JsonUtil.loadTrueJson(object.toString()));
    }
    @Resource
    private InternetSearchVideoService internetSearchVideoService;
    @Resource
    private YouKuUtil youKuUtil;
    public void getVideoDetailForInternetSearch(AcceptData acceptData, String videoId, HttpServletRequest request, PrintWriter out) {
        InternetSearchVideo internetSearchVideo = internetSearchVideoService.selectByPrimaryKey(videoId);
        String resourceId = request.getParameter("ResourceId");
        if (StringUtil.isNullOrEmpty(resourceId)) {
            resourceId = internetSearchVideo.getResourceIds().split(",")[0];
        }
        if (Integer.parseInt(resourceId) == YouKuUtil.RESOURCE_ID) {
            VideoInfo info = null;
            try {
                info = youKuUtil.getVideoInfo(internetSearchVideo);
            } catch (Exception e) {
                out.print(JsonUtil.loadFalseAdmin(e.getMessage()));
                return;
            }
            JSONArray array = new JSONArray();
            JSONObject obj = new JSONObject();
            out.print(JsonUtil.loadTrueJson(StringUtil.outPutResultJson(Utils.convertVideo(info)), array.toString(),
                    obj.toString()));
        }
    }
    @RequireUid
    public void getVideoDetail(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
        String videoId = request.getParameter("VideoId");
        if (!NumberUtil.isNumeric(videoId)) {
            getVideoDetailForInternetSearch(acceptData, videoId, request, out);
            return;
        }
        String resourceId = request.getParameter("ResourceId");
        String thirdType = request.getParameter("Type");
        String loginUid = request.getParameter("LoginUid");
@@ -477,6 +519,7 @@
                    obj.toString()));
    }
    /**
     * 获取视频的剧集列表
     *
@@ -532,6 +575,12 @@
            return;
        }
        if (!NumberUtil.isNumeric(detailId)) {
            out.print(JsonUtil.loadFalseJson(""));
            return;
        }
        boolean collect = collectionService.isCollect(acceptData.getUid(), detailId, thirdType);
        if (collect)
            out.print(JsonUtil.loadTrueJson(""));
src/main/java/com/yeshi/buwan/controller/parser/UserParser.java
@@ -2,19 +2,25 @@
import com.yeshi.buwan.domain.*;
import com.yeshi.buwan.domain.Collection;
import com.yeshi.buwan.domain.solr.SolrAlbumVideo;
import com.yeshi.buwan.domain.system.DetailSystem;
import com.yeshi.buwan.domain.user.LoginUser;
import com.yeshi.buwan.domain.video.InternetSearchVideo;
import com.yeshi.buwan.dto.log.BaseLog;
import com.yeshi.buwan.dto.search.SolrResultDTO;
import com.yeshi.buwan.dto.search.SolrVideoSearchFilter;
import com.yeshi.buwan.dto.user.LoginInfoDto;
import com.yeshi.buwan.exception.user.LoginUserException;
import com.yeshi.buwan.exception.user.RegisterUserException;
import com.yeshi.buwan.pptv.PPTVUtil;
import com.yeshi.buwan.service.imp.*;
import com.yeshi.buwan.service.inter.juhe.InternetSearchVideoService;
import com.yeshi.buwan.service.manager.SolrAlbumVideoDataManager;
import com.yeshi.buwan.util.*;
import com.yeshi.buwan.util.JuHe.VideoResourceUtil;
import com.yeshi.buwan.util.annotation.RequireUid;
import com.yeshi.buwan.util.email.MailSenderUtil;
import com.yeshi.buwan.util.factory.VideoInfoFactory;
import com.yeshi.buwan.util.log.LoggerUtil;
import com.yeshi.buwan.util.log.UserActiveLogFactory;
import com.yeshi.buwan.util.video.VideoCategoryConstant;
@@ -449,10 +455,68 @@
    }
    @Resource
    private InternetSearchVideoService internetSearchVideoService;
    private void guessLikeForInternetSearch(AcceptData acceptData, String videoId, PrintWriter out) {
        InternetSearchVideo internetSearchVideo = internetSearchVideoService.selectByPrimaryKey(videoId);
        if (internetSearchVideo != null) {
            int rootType = internetSearchVideo.getRootType();
            SolrVideoSearchFilter filter = new SolrVideoSearchFilter();
            filter.setVideoType(rootType);
            filter.setResourceIds(new String[]{PPTVUtil.RESOURCE_ID + ""});
            filter.setSortKey("watchcount");
            SolrResultDTO dto = solrDataManager.find(filter, 1, 20);
            List<SolrAlbumVideo> solrAlbumVideoList = new ArrayList<>();
            solrAlbumVideoList.addAll(dto.getVideoList());
            List<VideoInfo> list = new ArrayList<>();
            for (int i = 0; i < 4; i++) {
                if (solrAlbumVideoList.size() > 0) {
                    int p = (int) (Math.random() * solrAlbumVideoList.size());
                    SolrAlbumVideo solrAlbumVideo = solrAlbumVideoList.get(p);
                    list.add(VideoInfoFactory.create(solrAlbumVideo));
                    solrAlbumVideoList.remove(p);
                }
            }
            if (list.size() < 4) {
                filter.setResourceIds(null);
                dto = solrDataManager.find(filter, 1, 20);
                solrAlbumVideoList.clear();
                solrAlbumVideoList.addAll(dto.getVideoList());
                for (int i = list.size(); i < 4; i++) {
                    if (solrAlbumVideoList.size() > 0) {
                        int p = (int) (Math.random() * solrAlbumVideoList.size());
                        SolrAlbumVideo solrAlbumVideo = solrAlbumVideoList.get(p);
                        list.add(VideoInfoFactory.create(solrAlbumVideo));
                        solrAlbumVideoList.remove(p);
                    }
                }
            }
            JSONObject object = new JSONObject();
            object.put("count", list.size() + "");
            JSONArray array = new JSONArray();
            for (int i = 0; i < list.size(); i++) {
                array.add(StringUtil.outPutResultJson(list.get(i)));
            }
            object.put("data", array);
            out.print(JsonUtil.loadTrueJson(object.toString()));
        }
    }
    // 猜你喜欢
    public void guessLike(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
        String videoId = request.getParameter("VideoId");
        if (!NumberUtil.isNumeric(videoId)) {
            guessLikeForInternetSearch(acceptData, videoId, out);
            return;
        }
        DetailSystem ds = systemService.getDetailSystemByPackage(acceptData.getPackageName());
@@ -625,6 +689,39 @@
    }
    private void getRelativeVideosForInternetSearch(AcceptData acceptData, String videoId, PrintWriter out) {
        InternetSearchVideo internetSearchVideo = internetSearchVideoService.selectByPrimaryKey(videoId);
        if (internetSearchVideo != null) {
            SolrVideoSearchFilter filter = new SolrVideoSearchFilter();
            filter.setKey(internetSearchVideo.getName());
            filter.setFuzzy(true);
            SolrResultDTO dto = solrDataManager.find(filter, 1, 20);
            List<SolrAlbumVideo> solrAlbumVideoList = new ArrayList<>();
            solrAlbumVideoList.addAll(dto.getVideoList());
            List<VideoInfo> list = new ArrayList<>();
            for (int i = 0; i < 4; i++) {
                if (i < solrAlbumVideoList.size()) {
                    SolrAlbumVideo solrAlbumVideo = solrAlbumVideoList.get(i);
                    list.add(VideoInfoFactory.create(solrAlbumVideo));
                }
            }
            JSONObject object = new JSONObject();
            object.put("count", list.size() + "");
            JSONArray array = new JSONArray();
            for (int i = 0; i < list.size(); i++) {
                array.add(StringUtil.outPutResultJson(list.get(i)));
            }
            object.put("data", array);
            out.print(JsonUtil.loadTrueJson(object.toString()));
        }
    }
    /**
     * 相关视频
     *
@@ -638,6 +735,11 @@
            return;
        }
        if (!NumberUtil.isNumeric(videoId)) {
            getRelativeVideosForInternetSearch(acceptData, videoId, out);
            return;
        }
        List<Long> resourceList = videoResouceUtil.getAvailableResourceIds(acceptData.getDetailSystem(), acceptData.getVersion());
        DetailSystem ds = systemService.getDetailSystemByPackage(acceptData.getPackageName());
src/main/java/com/yeshi/buwan/dao/juhe/youku/YouKuSearchVideoMapDao.java
New file
@@ -0,0 +1,33 @@
package com.yeshi.buwan.dao.juhe.youku;
import com.yeshi.buwan.youku.entity.YouKuSearchVideoMap;
import com.yeshi.buwan.dao.base.MongodbBaseDao;
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.stereotype.Repository;
import java.util.Date;
@Repository
public class YouKuSearchVideoMapDao extends MongodbBaseDao<YouKuSearchVideoMap> {
    public void updateSelective(YouKuSearchVideoMap bean) {
        Query query = new Query();
        Update update = new Update();
        query.addCriteria(Criteria.where("videoId").is(bean.getVideoId()));
        if (bean.getShowId() != null) {
            update.set("showId", bean.getShowId());
        }
        if (bean.getCreateTime() != null) {
            update.set("createTime", bean.getCreateTime());
        }
        update.set("updateTime", new Date());
        update(query, update);
    }
    public YouKuSearchVideoMap selectByVideoId(String videoId) {
        return get(videoId);
    }
}
src/main/java/com/yeshi/buwan/domain/video/InternetSearchVideo.java
@@ -51,7 +51,7 @@
    @Field
    private String resourceIds;
    @Transient
//    @Transient
    @Field
    private Date solrTime;
src/main/java/com/yeshi/buwan/dto/search/SolrVideoSearchFilter.java
@@ -1,6 +1,10 @@
package com.yeshi.buwan.dto.search;
public class SolrVideoSearchFilter {
    //是否模糊
    private boolean fuzzy;
    private String key;
    //演员
    private String actor;
@@ -88,4 +92,12 @@
    public void setArea(String area) {
        this.area = area;
    }
    public boolean isFuzzy() {
        return fuzzy;
    }
    public void setFuzzy(boolean fuzzy) {
        this.fuzzy = fuzzy;
    }
}
src/main/java/com/yeshi/buwan/job/video/YouKuVideoUpdate.java
@@ -85,7 +85,15 @@
                "电影", "电视剧", "动漫", "综艺"
        };
        if (!StringUtil.isNullOrEmpty(param)) {
            updateCategory(param);
            if (param.length() < 10) {
                updateCategory(param);
            } else {
                String[] ids = param.split(",");
                for (String id : ids) {
                    YouKuShowDetail detail = getShowDetail(id);
                    youKuService.save(detail);
                }
            }
        } else {
            for (String type : types) {
                updateCategory(type);
src/main/java/com/yeshi/buwan/mogotv/MogoTVApiUtil.java
New file
@@ -0,0 +1,163 @@
package com.yeshi.buwan.mogotv;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.yeshi.buwan.youku.entity.YouKuShowDetail;
import com.yeshi.buwan.youku.entity.YouKuShowSimple;
import com.yeshi.buwan.youku.entity.YouKuVideo;
import org.json.JSONObject;
import org.yeshi.utils.HttpUtil;
import org.yeshi.utils.StringUtil;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.net.URLEncoder;
import java.util.*;
public class MogoTVApiUtil {
//1.列表
//    https://pianku.api.mgtv.com/rider/list/pcweb/v4?platform=pcweb&channelId=2&pn=1&pc=80&hudong=0&_support=10000000&kind=a1&area=a1&sort=c2&abroad=0&src=intelmgtv&callback=jsonp_1616647932020_11155
//
//            2.详情:
//    https://pcweb.api.mgtv.com/video/info?cid=341719&_support=10000000&abroad=0&src=intelmgtv&callback=jsonp_1616648013226_52720
//
//            3.视频列表
//    https://pcweb.api.mgtv.com/episode/list?src=intelmgtv&abroad=0&_support=10000000&version=5.5.35&video_id=11026579&page=0&size=30&abroad=0&src=intelmgtv&callback=jsonp_1616648013585_27530
//
//    isIntact:1表示正片
    private final static String APP_ID = "758bef946d0050ef";
    private final static String APP_SECRET = "e113a131d49e1f837402e2807f2daf58";
    private static String request(String action, Map<String, String> ps) {
        Map<String, String> params = new HashMap<>();
        params.put("action", action);
        params.put("client_id", APP_ID);
        params.put("format", "json");
        params.put("timestamp", System.currentTimeMillis() / 1000 + "");
        params.put("version", "3.0");
        params.put("format", "json");
        params.putAll(ps);
        List<String> list = new ArrayList<>();
        for (Iterator<String> its = params.keySet().iterator(); its.hasNext(); ) {
            String key = its.next();
            try {
                list.add(key + URLEncoder.encode(params.get(key), "UTF-8"));
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        Collections.sort(list);
        String sign = StringUtil.Md5(StringUtil.concat(list, "") + APP_SECRET);
        params.put("sign", sign);
        ps.put("opensysparams", new JSONObject(params).toString());
        return HttpUtil.get("https://openapi.youku.com/router/rest.json", ps, new HashMap<>());
    }
    /**
     * 获取节目详情
     *
     * @param id
     * @return
     */
    public static YouKuShowDetail getShowDetail(String id) {
        String url = String.format("https://openapi.youku.com/v2/shows/show.json?client_id=%s&show_id=%s", APP_ID, id);
        String result = HttpUtil.get(url);
        return new Gson().fromJson(result, YouKuShowDetail.class);
    }
    /**
     * 根据分类拉取数据
     *
     * @param category
     * @param page
     */
    public static ListResultDTO getShowListByCategory(String category, int page, int pageSize) {
        try {
            String url = String.format("https://openapi.youku.com/v2/shows/by_category.json?client_id=%s&paid=1&category=%s&page=%s&count=" + pageSize, APP_ID, URLEncoder.encode(category, "UTF-8"), page);
            String result = HttpUtil.get(url);
            net.sf.json.JSONObject resultJson = net.sf.json.JSONObject.fromObject(result);
            int total = resultJson.optInt("total");
            Type type = new TypeToken<List<YouKuShowSimple>>() {
            }.getType();
            List<YouKuShowSimple> list = new Gson().fromJson(resultJson.optJSONArray("shows").toString(), type);
            return new ListResultDTO(list, total);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static ListResultDTO getVideoList(String showId, int page, int pageSize) {
        Map<String, String> params = new HashMap<>();
        params.put("show_id", showId);
        params.put("show_videotype", "正片");
        params.put("page", page + "");
        params.put("pageLength", pageSize + "");
        String result = MogoTVApiUtil.request("youku.api.video.byprogram.get", params);
        System.out.println(result);
        net.sf.json.JSONObject resultJson = net.sf.json.JSONObject.fromObject(result);
        int total = resultJson.optInt("total");
        Type type = new TypeToken<List<YouKuVideo>>() {
        }.getType();
        List<YouKuVideo> videoList = new Gson().fromJson(resultJson.optJSONArray("videos").toString(), type);
        if (videoList != null)
            for (YouKuVideo video : videoList) {
                video.setShowId(showId);
            }
        return new ListResultDTO(videoList, total);
    }
    public static void main(String[] args) {
//        YouKuShowDetail detail = getShowDetail("1e61efbfbdefbfbd04ef");
//        System.out.println(detail);
        getVideoList("0a17e614d7e311e68ce4", 1, 20);
//        ListResultDTO resultDTO = getShowListByCategory("电视剧", 1);
//        System.out.println(resultDTO);
    }
    public static class ListResultDTO {
        private List list;
        private int total;
        public ListResultDTO(List list, int total) {
            this.list = list;
            this.total = total;
        }
        public List getList() {
            return list;
        }
        public void setList(List list) {
            this.list = list;
        }
        public int getTotal() {
            return total;
        }
        public void setTotal(int total) {
            this.total = total;
        }
    }
}
src/main/java/com/yeshi/buwan/mogotv/MogoTVUtil.java
New file
@@ -0,0 +1,136 @@
package com.yeshi.buwan.mogotv;
import com.yeshi.buwan.domain.VideoDetailInfo;
import com.yeshi.buwan.domain.VideoInfo;
import com.yeshi.buwan.domain.VideoResource;
import com.yeshi.buwan.domain.entity.PlayUrl;
import com.yeshi.buwan.domain.video.InternetSearchVideo;
import com.yeshi.buwan.service.imp.VideoResourceService;
import com.yeshi.buwan.service.imp.VideoTypeService;
import com.yeshi.buwan.service.inter.juhe.InternetSearchVideoService;
import com.yeshi.buwan.service.inter.juhe.YouKuService;
import com.yeshi.buwan.util.factory.VideoInfoFactory;
import com.yeshi.buwan.util.video.VideoConstant;
import com.yeshi.buwan.youku.entity.YouKuSearchVideoMap;
import com.yeshi.buwan.youku.entity.YouKuShowDetail;
import com.yeshi.buwan.youku.entity.YouKuVideo;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Component
public class MogoTVUtil {
    @Resource
    private InternetSearchVideoService internetSearchVideoService;
    @Resource
    private YouKuService youKuService;
    @Resource
    private VideoResourceService videoResourceService;
    @Resource
    private VideoTypeService videoTypeService;
    public final static int RESOURCE_ID = 26;
    public static VideoDetailInfo convertToDetail(YouKuVideo youKuVideo) {
        VideoDetailInfo detail = new VideoDetailInfo();
        switch (youKuVideo.getCategory()) {
            case "电影":
                detail.setTag(youKuVideo.getTitle());
                break;
            case "电视剧":
            case "动漫":
                detail.setTag(youKuVideo.getShow_videoseq() + "");
                break;
            case "综艺":
                detail.setTag(youKuVideo.getShow_videostage() + " " + youKuVideo.getTitle());
                break;
        }
        detail.setName(youKuVideo.getTitle());
        detail.setExtraId(youKuVideo.getVideoid());
        detail.setType("url");
        return detail;
    }
    public VideoInfo getVideoInfo(InternetSearchVideo internetSearchVideo) throws Exception {
        YouKuSearchVideoMap map = youKuService.selectByVideoId(internetSearchVideo.getId());
        if (map == null) {
            throw new Exception("视频源不存在");
        }
        YouKuShowDetail showDetail = youKuService.getSimpleShowDetail(map.getShowId());
        showDetail.setVideoList(youKuService.getVideoList(showDetail.getId(), 1, 100));
        VideoInfo info = VideoInfoFactory.create(internetSearchVideo);
        info.setIntroduction(showDetail.getDescription());
        info.setVideoDetailList(MogoTVUtil.convertToDetail(showDetail.getVideoList()));
        info.setPlayPicture(info.getHpicture());
        //获取资源列表
        List<String> rids = Arrays.asList(internetSearchVideo.getResourceIds().split(","));
        List<VideoResource> resourceList = videoResourceService.getResource(rids);
        for (VideoResource vr : resourceList) {
            if (vr.getId().equalsIgnoreCase(RESOURCE_ID + ""))
                vr.setChecked(true);
        }
        info.setResourceList(resourceList);
        info.setShowType(MogoTVUtil.getShowType(internetSearchVideo));
        info.setScore(new BigDecimal(showDetail.getScore()).setScale(1).toString());
        //获取分类详情
        info.setVideoType(videoTypeService.getVideoType(info.getVideoType().getId()));
        info.setCommentCount(0);
        info.setVideocount((int) (Math.random() * 1000));
        return info;
    }
    public static List<VideoDetailInfo> convertToDetail(List<YouKuVideo> youKuVideoList) {
        List<VideoDetailInfo> detailList = new ArrayList<>();
        for (YouKuVideo video : youKuVideoList) {
            detailList.add(convertToDetail(video));
        }
        return detailList;
    }
    public static int getShowType(InternetSearchVideo video) {
        if (video == null)
            return 2;
        switch (video.getRootType()) {
            case VideoConstant
                    .VIDEO_CATEGORY_DIANYING:
                return 1;
            case VideoConstant
                    .VIDEO_CATEGORY_DIANSHIJU:
            case VideoConstant
                    .VIDEO_CATEGORY_DONGMAN:
                return 2;
            case VideoConstant
                    .VIDEO_CATEGORY_ZONGYI:
                return 1;
        }
        return 2;
    }
    public PlayUrl getPlayUrl(String detailSystemId, String id, String type, int resourceid, String videoid) {
        PlayUrl playUrl = new PlayUrl();
        VideoResource videoResource = videoResourceService.getResource(resourceid + "");
        playUrl.setResource(videoResource);
        YouKuVideo youKuVideo = youKuService.getVideoDetail(id);
        playUrl.setUrl(youKuVideo.getLink());
        playUrl.setPlayType(1);
        playUrl.setParams("");
        return playUrl;
    }
}
src/main/java/com/yeshi/buwan/service/imp/BanQuanService.java
@@ -6,6 +6,7 @@
import javax.annotation.Resource;
import com.yeshi.buwan.util.NumberUtil;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.cache.annotation.CacheEvict;
@@ -30,588 +31,589 @@
@Service
public class BanQuanService {
    @Resource
    private VideoBanQuanDao videoBanQuanDao;
    @Resource
    private VideoBanQuanVideoDao videoBanQuanVideoDao;
    @Resource
    private WebVideoDao webVideoDao;
    @Resource
    private VideoBanQuanDao videoBanQuanDao;
    @Resource
    private VideoBanQuanVideoDao videoBanQuanVideoDao;
    @Resource
    private WebVideoDao webVideoDao;
    @SuppressWarnings("unchecked")
    @CacheEvict(value = "topCache", allEntries = true)
    public void addBanQuanVideo(final List<VideoBanQuanVideo> list) {
        videoBanQuanDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                try {
                    session.getTransaction().begin();
                    for (int i = 0; i < list.size(); i++) {
                        List<VideoBanQuanVideo> bl = session
                                .createQuery("from VideoBanQuanVideo v where v.detailSystem.id="
                                        + list.get(i).getDetailSystem().getId() + " and v.info.id="
                                        + list.get(i).getInfo().getId())
                                .list();
                        if (bl == null || bl.size() == 0) {
                            session.persist(list.get(i));
                        }
                    }
                    session.flush();
                    session.getTransaction().commit();
                } catch (Exception e) {
                    e.printStackTrace();
                    session.getTransaction().rollback();
                }
                return null;
            }
        });
    @SuppressWarnings("unchecked")
    @CacheEvict(value = "topCache", allEntries = true)
    public void addBanQuanVideo(final List<VideoBanQuanVideo> list) {
        videoBanQuanDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                try {
                    session.getTransaction().begin();
                    for (int i = 0; i < list.size(); i++) {
                        List<VideoBanQuanVideo> bl = session
                                .createQuery("from VideoBanQuanVideo v where v.detailSystem.id="
                                        + list.get(i).getDetailSystem().getId() + " and v.info.id="
                                        + list.get(i).getInfo().getId())
                                .list();
                        if (bl == null || bl.size() == 0) {
                            session.persist(list.get(i));
                        }
                    }
                    session.flush();
                    session.getTransaction().commit();
                } catch (Exception e) {
                    e.printStackTrace();
                    session.getTransaction().rollback();
                }
                return null;
            }
        });
    }
    }
    @SuppressWarnings("unchecked")
    public void addBanQuanKey(final List<VideoBanQuan> list) {
        videoBanQuanDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                try {
                    session.getTransaction().begin();
                    for (int i = 0; i < list.size(); i++) {
                        List<VideoBanQuan> bl = session
                                .createQuery("from VideoBanQuan v where v.detailSystem.id="
                                        + list.get(i).getDetailSystem().getId() + " and v.name=?")
                                .setParameter(0, list.get(i).getName()).list();
                        if (bl == null || bl.size() == 0) {
                            session.persist(list.get(i));
                        }
                    }
                    session.flush();
                    session.getTransaction().commit();
                } catch (Exception e) {
                    e.printStackTrace();
                    session.getTransaction().rollback();
                }
                return null;
            }
        });
    @SuppressWarnings("unchecked")
    public void addBanQuanKey(final List<VideoBanQuan> list) {
        videoBanQuanDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                try {
                    session.getTransaction().begin();
                    for (int i = 0; i < list.size(); i++) {
                        List<VideoBanQuan> bl = session
                                .createQuery("from VideoBanQuan v where v.detailSystem.id="
                                        + list.get(i).getDetailSystem().getId() + " and v.name=?")
                                .setParameter(0, list.get(i).getName()).list();
                        if (bl == null || bl.size() == 0) {
                            session.persist(list.get(i));
                        }
                    }
                    session.flush();
                    session.getTransaction().commit();
                } catch (Exception e) {
                    e.printStackTrace();
                    session.getTransaction().rollback();
                }
                return null;
            }
        });
    }
    }
    public VideoBanQuanVideo getBanQuanVideo(String id) {
    public VideoBanQuanVideo getBanQuanVideo(String id) {
        return videoBanQuanVideoDao.find(VideoBanQuanVideo.class, id);
    }
        return videoBanQuanVideoDao.find(VideoBanQuanVideo.class, id);
    }
    public VideoBanQuan getBanQuanKey(String id) {
    public VideoBanQuan getBanQuanKey(String id) {
        return videoBanQuanDao.find(VideoBanQuan.class, id);
    }
        return videoBanQuanDao.find(VideoBanQuan.class, id);
    }
    public void updateVideoBanQuanVideo(VideoBanQuanVideo video) {
    public void updateVideoBanQuanVideo(VideoBanQuanVideo video) {
        videoBanQuanVideoDao.update(video);
    }
        videoBanQuanVideoDao.update(video);
    }
    public void updateVideoBanQuan(VideoBanQuan video) {
    public void updateVideoBanQuan(VideoBanQuan video) {
        videoBanQuanDao.update(video);
    }
        videoBanQuanDao.update(video);
    }
    public void deleteBanQuanVideo(final List<VideoBanQuanVideo> list) {
        videoBanQuanDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                try {
                    session.getTransaction().begin();
                    for (int i = 0; i < list.size(); i++) {
                        session.delete(list.get(i));
                    }
                    session.flush();
                    session.getTransaction().commit();
                } catch (Exception e) {
                    e.printStackTrace();
                    session.getTransaction().rollback();
                }
                return null;
            }
        });
    public void deleteBanQuanVideo(final List<VideoBanQuanVideo> list) {
        videoBanQuanDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                try {
                    session.getTransaction().begin();
                    for (int i = 0; i < list.size(); i++) {
                        session.delete(list.get(i));
                    }
                    session.flush();
                    session.getTransaction().commit();
                } catch (Exception e) {
                    e.printStackTrace();
                    session.getTransaction().rollback();
                }
                return null;
            }
        });
    }
    }
    public void deleteBanQuanKey(final List<VideoBanQuan> list) {
        videoBanQuanDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                try {
                    session.getTransaction().begin();
                    for (int i = 0; i < list.size(); i++) {
                        session.delete(list.get(i));
                    }
                    session.flush();
                    session.getTransaction().commit();
                } catch (Exception e) {
                    e.printStackTrace();
                    session.getTransaction().rollback();
                }
                return null;
            }
        });
    public void deleteBanQuanKey(final List<VideoBanQuan> list) {
        videoBanQuanDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                try {
                    session.getTransaction().begin();
                    for (int i = 0; i < list.size(); i++) {
                        session.delete(list.get(i));
                    }
                    session.flush();
                    session.getTransaction().commit();
                } catch (Exception e) {
                    e.printStackTrace();
                    session.getTransaction().rollback();
                }
                return null;
            }
        });
    }
    }
    public void deleteBanQuanKeyByKey(final String key) {
        videoBanQuanDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                try {
                    session.getTransaction().begin();
                    session.createQuery("delete from VideoBanQuan vb where vb.name=?").setParameter(0, key)
                            .executeUpdate();
                    session.flush();
                    session.getTransaction().commit();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return null;
            }
        });
    public void deleteBanQuanKeyByKey(final String key) {
        videoBanQuanDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                try {
                    session.getTransaction().begin();
                    session.createQuery("delete from VideoBanQuan vb where vb.name=?").setParameter(0, key)
                            .executeUpdate();
                    session.flush();
                    session.getTransaction().commit();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return null;
            }
        });
    }
    }
    @CacheEvict(value = "topCache", allEntries = true)
    public void deleteBanQuanVideoByVID(final String videoid) {
        videoBanQuanDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                try {
                    session.getTransaction().begin();
                    session.createQuery("delete from VideoBanQuanVideo vb where vb.info.id=?").setParameter(0, videoid)
                            .executeUpdate();
                    session.flush();
                    session.getTransaction().commit();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return null;
            }
        });
    @CacheEvict(value = "topCache", allEntries = true)
    public void deleteBanQuanVideoByVID(final String videoid) {
        videoBanQuanDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                try {
                    session.getTransaction().begin();
                    session.createQuery("delete from VideoBanQuanVideo vb where vb.info.id=?").setParameter(0, videoid)
                            .executeUpdate();
                    session.flush();
                    session.getTransaction().commit();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return null;
            }
        });
    }
    }
    public List<VideoBanQuanVideo> getBanQuanVideoList(int page, String key, int detailSystemId) {
        String sql = "";
        if (detailSystemId == 0)
            sql = "from VideoBanQuanVideo vb where vb.name like ?";
        else
            sql = "from VideoBanQuanVideo vb where vb.name like ? and vb.detailSystem.id=" + detailSystemId;
    public List<VideoBanQuanVideo> getBanQuanVideoList(int page, String key, int detailSystemId) {
        String sql = "";
        if (detailSystemId == 0)
            sql = "from VideoBanQuanVideo vb where vb.name like ?";
        else
            sql = "from VideoBanQuanVideo vb where vb.name like ? and vb.detailSystem.id=" + detailSystemId;
        return videoBanQuanVideoDao.list(sql, (page - 1) * Constant.pageCount, Constant.pageCount,
                new String[] { "%" + key + "%" });
    }
        return videoBanQuanVideoDao.list(sql, (page - 1) * Constant.pageCount, Constant.pageCount,
                new String[]{"%" + key + "%"});
    }
    public long getBanQuanVideoPage(String key, int detailSystemId) {
        String sql = "";
        if (detailSystemId == 0) {
            sql = "select count(*)  from VideoBanQuanVideo v where v.name like ?";
        } else {
            sql = "select count(*)  from VideoBanQuanVideo v where v.name like ? and v.detailSystem.id="
                    + detailSystemId;
        }
    public long getBanQuanVideoPage(String key, int detailSystemId) {
        String sql = "";
        if (detailSystemId == 0) {
            sql = "select count(*)  from VideoBanQuanVideo v where v.name like ?";
        } else {
            sql = "select count(*)  from VideoBanQuanVideo v where v.name like ? and v.detailSystem.id="
                    + detailSystemId;
        }
        long count = videoBanQuanVideoDao.getCount(sql, new String[] { "%" + key + "%" });
        long count = videoBanQuanVideoDao.getCount(sql, new String[]{"%" + key + "%"});
        return count % Constant.pageCount == 0 ? count / Constant.pageCount : count / Constant.pageCount + 1;
    }
        return count % Constant.pageCount == 0 ? count / Constant.pageCount : count / Constant.pageCount + 1;
    }
    public List<VideoBanQuan> getBanQuanKeyList(int page, String key, int detailSystemId) {
        String sql = "";
        if (detailSystemId == 0)
            sql = "from VideoBanQuan vb where vb.name like ?";
        else
            sql = "from VideoBanQuan vb where vb.name like ? and vb.detailSystem.id=" + detailSystemId;
    public List<VideoBanQuan> getBanQuanKeyList(int page, String key, int detailSystemId) {
        String sql = "";
        if (detailSystemId == 0)
            sql = "from VideoBanQuan vb where vb.name like ?";
        else
            sql = "from VideoBanQuan vb where vb.name like ? and vb.detailSystem.id=" + detailSystemId;
        return videoBanQuanDao.list(sql, (page - 1) * Constant.pageCount, Constant.pageCount,
                new String[] { "%" + key + "%" });
    }
        return videoBanQuanDao.list(sql, (page - 1) * Constant.pageCount, Constant.pageCount,
                new String[]{"%" + key + "%"});
    }
    public List<String> getBanQuanKeyListAll(int detailSystemId) {
        String sql = "";
        if (detailSystemId == 0)
            sql = "from VideoBanQuan vb";
        else
            sql = "from VideoBanQuan vb where  vb.detailSystem.id=" + detailSystemId;
    public List<String> getBanQuanKeyListAll(int detailSystemId) {
        String sql = "";
        if (detailSystemId == 0)
            sql = "from VideoBanQuan vb";
        else
            sql = "from VideoBanQuan vb where  vb.detailSystem.id=" + detailSystemId;
        List<VideoBanQuan> bList = videoBanQuanDao.list(sql);
        List<String> keyList = new ArrayList<>();
        if (bList != null)
            for (VideoBanQuan b : bList)
                keyList.add(b.getName());
        return keyList;
    }
        List<VideoBanQuan> bList = videoBanQuanDao.list(sql);
        List<String> keyList = new ArrayList<>();
        if (bList != null)
            for (VideoBanQuan b : bList)
                keyList.add(b.getName());
        return keyList;
    }
    public long getBanQuanKeyPage(String key, int detailSystemId) {
        String sql = "";
        if (detailSystemId == 0) {
            sql = "select count(*)  from VideoBanQuan v where v.name like ?";
        } else {
            sql = "select count(*)  from VideoBanQuan v where v.name like ? and v.detailSystem.id=" + detailSystemId;
        }
    public long getBanQuanKeyPage(String key, int detailSystemId) {
        String sql = "";
        if (detailSystemId == 0) {
            sql = "select count(*)  from VideoBanQuan v where v.name like ?";
        } else {
            sql = "select count(*)  from VideoBanQuan v where v.name like ? and v.detailSystem.id=" + detailSystemId;
        }
        long count = videoBanQuanVideoDao.getCount(sql, new String[] { "%" + key + "%" });
        long count = videoBanQuanVideoDao.getCount(sql, new String[]{"%" + key + "%"});
        return count % Constant.pageCount == 0 ? count / Constant.pageCount : count / Constant.pageCount + 1;
    }
        return count % Constant.pageCount == 0 ? count / Constant.pageCount : count / Constant.pageCount + 1;
    }
    // 过滤版权视频
    // 过滤版权视频
    @SuppressWarnings({ "rawtypes", "unchecked" })
    @Cacheable(value = "userCache", key = "'getBanQuanVideo'+'-'+#cacheMD5+'-'+#detailSystemId")
    public List<VideoInfo> getBanQuanVideo(final List<VideoInfo> list, final String detailSystemId, String cacheMD5) {
        if (list == null || list.size() == 0)
            return list;
        List<VideoInfo> newList = (List<VideoInfo>) videoBanQuanDao.excute(new HibernateCallback<List<VideoInfo>>() {
            public List<VideoInfo> doInHibernate(Session session) throws HibernateException {
                String sql = "";
                for (VideoInfo vi : list) {
                    sql += " (SELECT v.`id`,bv.`videoid`,bv.`detailsystemid`,bv.`show` FROM wk_video_video v LEFT JOIN wk_video_banquan_video bv ON bv.`videoid`=v.`id` WHERE v.`id`="
                            + vi.getId() + ") UNION ALL";
                }
                if (sql.endsWith("UNION ALL"))
                    sql = sql.substring(0, sql.length() - 9);
    @SuppressWarnings({"rawtypes", "unchecked"})
    @Cacheable(value = "userCache", key = "'getBanQuanVideo'+'-'+#cacheMD5+'-'+#detailSystemId")
    public List<VideoInfo> getBanQuanVideo(final List<VideoInfo> list, final String detailSystemId, String cacheMD5) {
        if (list == null || list.size() == 0)
            return list;
        List<VideoInfo> newList = (List<VideoInfo>) videoBanQuanDao.excute(new HibernateCallback<List<VideoInfo>>() {
            public List<VideoInfo> doInHibernate(Session session) throws HibernateException {
                String sql = "";
                for (VideoInfo vi : list) {
                    if (NumberUtil.isNumeric(vi.getId()))
                        sql += " (SELECT v.`id`,bv.`videoid`,bv.`detailsystemid`,bv.`show` FROM wk_video_video v LEFT JOIN wk_video_banquan_video bv ON bv.`videoid`=v.`id` WHERE v.`id`="
                                + vi.getId() + ") UNION ALL";
                }
                if (sql.endsWith("UNION ALL"))
                    sql = sql.substring(0, sql.length() - 9);
                try {
                    List rlist = session.createSQLQuery(sql).list();
                    for (int i = 0; i < rlist.size(); i++) {
                        Object[] objs = (Object[]) rlist.get(i);
                        if (!StringUtil.isNullOrEmpty(objs[1] + "") && "1".equalsIgnoreCase(objs[3] + "")
                                && detailSystemId.equalsIgnoreCase(objs[2] + "")) {
                            // 是版权视频
                            // if (list.size() > i)
                            // list.get(i).setShow("0");
                            // 20171009 update
                            for (VideoInfo vi : list) {
                                if (vi.getId().equals(objs[1] + "")) {
                                    vi.setShow("0");
                                }
                            }
                try {
                    List rlist = session.createSQLQuery(sql).list();
                    for (int i = 0; i < rlist.size(); i++) {
                        Object[] objs = (Object[]) rlist.get(i);
                        if (!StringUtil.isNullOrEmpty(objs[1] + "") && "1".equalsIgnoreCase(objs[3] + "")
                                && detailSystemId.equalsIgnoreCase(objs[2] + "")) {
                            // 是版权视频
                            // if (list.size() > i)
                            // list.get(i).setShow("0");
                            // 20171009 update
                            for (VideoInfo vi : list) {
                                if (vi.getId().equals(objs[1] + "")) {
                                    vi.setShow("0");
                                }
                            }
                        }
                        // else {
                        // if (list.size() > i)
                        // list.get(i).setShow("1");
                        // }
                    }
                        }
                        // else {
                        // if (list.size() > i)
                        // list.get(i).setShow("1");
                        // }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return list;
            }
        });
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return list;
            }
        });
        for (int i = 0; i < newList.size(); i++) {
            if ("0".equalsIgnoreCase(newList.get(i).getShow())) {
                newList.remove(i);
                i--;
            }
        }
        return newList;
    }
        for (int i = 0; i < newList.size(); i++) {
            if ("0".equalsIgnoreCase(newList.get(i).getShow())) {
                newList.remove(i);
                i--;
            }
        }
        return newList;
    }
    @SuppressWarnings("rawtypes")
    public List<HomeVideo> getBanQuanHomeVideo(final List<HomeVideo> list, final String detailSystemId) {
    @SuppressWarnings("rawtypes")
    public List<HomeVideo> getBanQuanHomeVideo(final List<HomeVideo> list, final String detailSystemId) {
        videoBanQuanDao.excute(new HibernateCallback<List<HomeVideo>>() {
            public List<HomeVideo> doInHibernate(Session session) throws HibernateException {
                String sql = "";
                for (HomeVideo hv : list) {
                    sql += " (SELECT v.`id`,bv.`videoid`,bv.`detailsystemid`,bv.`show` FROM wk_video_video v LEFT JOIN wk_video_banquan_video bv ON bv.`videoid`=v.`id` WHERE v.`id`="
                            + hv.getVideo().getId() + ") UNION ALL";
                }
                if (sql.endsWith("UNION ALL"))
                    sql = sql.substring(0, sql.length() - 9);
                try {
                    List rlist = session.createSQLQuery(sql).list();
                    for (int i = 0; i < rlist.size(); i++) {
                        Object[] objs = (Object[]) rlist.get(i);
                        if (!StringUtil.isNullOrEmpty(objs[1] + "") && "1".equalsIgnoreCase(objs[2] + "")
                                && detailSystemId.equalsIgnoreCase(objs[3] + "")) {
                            // 是版权视频
                            // list.get(i).getVideo().setShow("0");
                            // 20171009 update
                            for (HomeVideo hv : list) {
                                if (hv.getVideo().getId().equals(objs[1] + "")) {
                                    hv.getVideo().setShow("0");
                                }
                            }
                        }
                        // else
                        // list.get(i).getVideo().setShow("1");
                    }
        videoBanQuanDao.excute(new HibernateCallback<List<HomeVideo>>() {
            public List<HomeVideo> doInHibernate(Session session) throws HibernateException {
                String sql = "";
                for (HomeVideo hv : list) {
                    sql += " (SELECT v.`id`,bv.`videoid`,bv.`detailsystemid`,bv.`show` FROM wk_video_video v LEFT JOIN wk_video_banquan_video bv ON bv.`videoid`=v.`id` WHERE v.`id`="
                            + hv.getVideo().getId() + ") UNION ALL";
                }
                if (sql.endsWith("UNION ALL"))
                    sql = sql.substring(0, sql.length() - 9);
                try {
                    List rlist = session.createSQLQuery(sql).list();
                    for (int i = 0; i < rlist.size(); i++) {
                        Object[] objs = (Object[]) rlist.get(i);
                        if (!StringUtil.isNullOrEmpty(objs[1] + "") && "1".equalsIgnoreCase(objs[2] + "")
                                && detailSystemId.equalsIgnoreCase(objs[3] + "")) {
                            // 是版权视频
                            // list.get(i).getVideo().setShow("0");
                            // 20171009 update
                            for (HomeVideo hv : list) {
                                if (hv.getVideo().getId().equals(objs[1] + "")) {
                                    hv.getVideo().setShow("0");
                                }
                            }
                        }
                        // else
                        // list.get(i).getVideo().setShow("1");
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return list;
            }
        });
                return list;
            }
        });
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getVideo().getShow().equalsIgnoreCase("0")) {
                list.remove(i);
                i--;
            }
        }
        return list;
    }
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getVideo().getShow().equalsIgnoreCase("0")) {
                list.remove(i);
                i--;
            }
        }
        return list;
    }
    /**
     * 管理页面操作
     */
    /**
     * 管理页面操作
     */
    @SuppressWarnings("unchecked")
    public List<BanquanKeyAdmin> getBanquanKeyAdmin(final String key, final int detailSystem, final int page) {
    @SuppressWarnings("unchecked")
    public List<BanquanKeyAdmin> getBanquanKeyAdmin(final String key, final int detailSystem, final int page) {
        return (List<BanquanKeyAdmin>) videoBanQuanDao.excute(new HibernateCallback<List<BanquanKeyAdmin>>() {
            public List<BanquanKeyAdmin> doInHibernate(Session session) throws HibernateException {
                List<BanquanKeyAdmin> banquanList = new ArrayList<>();
                try {
                    List<DetailSystem> detailSystemList = session.createQuery("from DetailSystem").list();
                    String where = "";
                    if (detailSystem > 0)
                        where = "where vb.detailSystem.id=" + detailSystem + " and";
                    else
                        where = "where";
        return (List<BanquanKeyAdmin>) videoBanQuanDao.excute(new HibernateCallback<List<BanquanKeyAdmin>>() {
            public List<BanquanKeyAdmin> doInHibernate(Session session) throws HibernateException {
                List<BanquanKeyAdmin> banquanList = new ArrayList<>();
                try {
                    List<DetailSystem> detailSystemList = session.createQuery("from DetailSystem").list();
                    String where = "";
                    if (detailSystem > 0)
                        where = "where vb.detailSystem.id=" + detailSystem + " and";
                    else
                        where = "where";
                    List<VideoBanQuan> list = session
                            .createQuery("from VideoBanQuan vb " + where
                                    + " vb.name like ? group by vb.name order by vb.createtime desc")
                            .setParameter(0, "%" + key + "%").setFirstResult((page - 1) * Constant.pageCount)
                            .setMaxResults(Constant.pageCount).list();
                    for (VideoBanQuan vb : list) {
                        List<DetailSystem> detailSystemS = session
                                .createQuery("select vb.detailSystem from VideoBanQuan vb where vb.name=?")
                                .setParameter(0, vb.getName()).list();
                    List<VideoBanQuan> list = session
                            .createQuery("from VideoBanQuan vb " + where
                                    + " vb.name like ? group by vb.name order by vb.createtime desc")
                            .setParameter(0, "%" + key + "%").setFirstResult((page - 1) * Constant.pageCount)
                            .setMaxResults(Constant.pageCount).list();
                    for (VideoBanQuan vb : list) {
                        List<DetailSystem> detailSystemS = session
                                .createQuery("select vb.detailSystem from VideoBanQuan vb where vb.name=?")
                                .setParameter(0, vb.getName()).list();
                        List<DetailSystemSelect> dssList = new ArrayList<>();
                        List<DetailSystemSelect> dssList = new ArrayList<>();
                        for (DetailSystem ds : detailSystemList) {
                            DetailSystemSelect dss = new DetailSystemSelect();
                            dss.setDetailSystem(ds);
                            dss.setSelected(false);
                            dssList.add(dss);
                        }
                        for (DetailSystem ds : detailSystemList) {
                            DetailSystemSelect dss = new DetailSystemSelect();
                            dss.setDetailSystem(ds);
                            dss.setSelected(false);
                            dssList.add(dss);
                        }
                        // 设置已经存在的
                        for (DetailSystem ds : detailSystemS) {
                        // 设置已经存在的
                        for (DetailSystem ds : detailSystemS) {
                            for (DetailSystemSelect dss : dssList) {
                                if (dss.getDetailSystem().getId().equalsIgnoreCase(ds.getId())) {
                                    dss.setSelected(true);
                                    break;
                                }
                            }
                        }
                        banquanList.add(new BanquanKeyAdmin(vb, dssList));
                    }
                            for (DetailSystemSelect dss : dssList) {
                                if (dss.getDetailSystem().getId().equalsIgnoreCase(ds.getId())) {
                                    dss.setSelected(true);
                                    break;
                                }
                            }
                        }
                        banquanList.add(new BanquanKeyAdmin(vb, dssList));
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return banquanList;
            }
        });
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return banquanList;
            }
        });
    }
    }
    public long getBanquanKeyAdminCount(String key, int detailSystem) {
        String where = "";
        if (detailSystem > 0)
            where = "where vb.detailsystem=" + detailSystem + " and";
        else
            where = "where";
    public long getBanquanKeyAdminCount(String key, int detailSystem) {
        String where = "";
        if (detailSystem > 0)
            where = "where vb.detailsystem=" + detailSystem + " and";
        else
            where = "where";
        return videoBanQuanVideoDao.getCountSQL("select count(*) from (select count(*) from wk_video_banquan vb "
                + where + " vb.name like '%" + key + "%' group by vb.name ) s");
    }
        return videoBanQuanVideoDao.getCountSQL("select count(*) from (select count(*) from wk_video_banquan vb "
                + where + " vb.name like '%" + key + "%' group by vb.name ) s");
    }
    @SuppressWarnings("rawtypes")
    public void addBanQuanKeyAdmin(final String key, final String detailSystemId) {
        videoBanQuanDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                try {
                    List list = session.createQuery("from VideoBanQuan vb where vb.name=? and vb.detailSystem.id=?")
                            .setParameter(0, key).setParameter(0, detailSystemId).list();
                    session.getTransaction().begin();
                    if (list == null || list.size() == 0) {
                        VideoBanQuan vb = new VideoBanQuan();
                        vb.setCreatetime(System.currentTimeMillis() + "");
                        vb.setDetailSystem(new DetailSystem(detailSystemId));
                        vb.setName(key);
                        vb.setShow(true);
                        vb.setVideoType(1);
                        vb.setVideoResource(new VideoResource("6"));
                        session.persist(vb);
                    }
                    session.flush();
                    session.getTransaction().commit();
    @SuppressWarnings("rawtypes")
    public void addBanQuanKeyAdmin(final String key, final String detailSystemId) {
        videoBanQuanDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                try {
                    List list = session.createQuery("from VideoBanQuan vb where vb.name=? and vb.detailSystem.id=?")
                            .setParameter(0, key).setParameter(0, detailSystemId).list();
                    session.getTransaction().begin();
                    if (list == null || list.size() == 0) {
                        VideoBanQuan vb = new VideoBanQuan();
                        vb.setCreatetime(System.currentTimeMillis() + "");
                        vb.setDetailSystem(new DetailSystem(detailSystemId));
                        vb.setName(key);
                        vb.setShow(true);
                        vb.setVideoType(1);
                        vb.setVideoResource(new VideoResource("6"));
                        session.persist(vb);
                    }
                    session.flush();
                    session.getTransaction().commit();
                } catch (Exception e) {
                    e.printStackTrace();
                    session.getTransaction().rollback();
                }
                } catch (Exception e) {
                    e.printStackTrace();
                    session.getTransaction().rollback();
                }
                return null;
            }
        });
                return null;
            }
        });
    }
    }
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public void deleteBanQuanKeyAdmin(final String key, final String detailSystemId) {
        videoBanQuanDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                try {
                    session.getTransaction().begin();
                    List<VideoBanQuan> list = session
                            .createQuery("from VideoBanQuan vb where vb.name=? and vb.detailSystem.id=?")
                            .setParameter(0, key).setParameter(1, detailSystemId).list();
                    if (list != null && list.size() > 0) {
                        for (VideoBanQuan vb : list)
                            session.delete(vb);
                    }
                    session.flush();
                    session.getTransaction().commit();
    @SuppressWarnings({"unchecked", "rawtypes"})
    public void deleteBanQuanKeyAdmin(final String key, final String detailSystemId) {
        videoBanQuanDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                try {
                    session.getTransaction().begin();
                    List<VideoBanQuan> list = session
                            .createQuery("from VideoBanQuan vb where vb.name=? and vb.detailSystem.id=?")
                            .setParameter(0, key).setParameter(1, detailSystemId).list();
                    if (list != null && list.size() > 0) {
                        for (VideoBanQuan vb : list)
                            session.delete(vb);
                    }
                    session.flush();
                    session.getTransaction().commit();
                } catch (Exception e) {
                    e.printStackTrace();
                    session.getTransaction().rollback();
                }
                return null;
            }
        });
                } catch (Exception e) {
                    e.printStackTrace();
                    session.getTransaction().rollback();
                }
                return null;
            }
        });
    }
    }
    @SuppressWarnings("unchecked")
    public List<BanquanVideoAdmin> getBanquanVideoAdmin(final String key, final int detailSystem, final int page) {
    @SuppressWarnings("unchecked")
    public List<BanquanVideoAdmin> getBanquanVideoAdmin(final String key, final int detailSystem, final int page) {
        return (List<BanquanVideoAdmin>) videoBanQuanDao.excute(new HibernateCallback<List<BanquanVideoAdmin>>() {
            public List<BanquanVideoAdmin> doInHibernate(Session session) throws HibernateException {
                List<BanquanVideoAdmin> banquanList = new ArrayList<>();
                try {
                    List<DetailSystem> detailSystemList = session.createQuery("from DetailSystem").list();
                    String where = "";
                    if (detailSystem > 0)
                        where += " where vb.detailSystem.id= " + detailSystem + " and ";
                    else
                        where += " where ";
        return (List<BanquanVideoAdmin>) videoBanQuanDao.excute(new HibernateCallback<List<BanquanVideoAdmin>>() {
            public List<BanquanVideoAdmin> doInHibernate(Session session) throws HibernateException {
                List<BanquanVideoAdmin> banquanList = new ArrayList<>();
                try {
                    List<DetailSystem> detailSystemList = session.createQuery("from DetailSystem").list();
                    String where = "";
                    if (detailSystem > 0)
                        where += " where vb.detailSystem.id= " + detailSystem + " and ";
                    else
                        where += " where ";
                    List<VideoBanQuanVideo> list = session
                            .createQuery("from VideoBanQuanVideo vb " + where
                                    + " vb.info.name like ? group by vb.info.id order by vb.createtime desc")
                            .setParameter(0, "%" + key + "%").setFirstResult((page - 1) * Constant.pageCount)
                            .setMaxResults(Constant.pageCount).list();
                    for (VideoBanQuanVideo vb : list) {
                        List<DetailSystem> detailSystemS = session
                                .createQuery("select vb.detailSystem from VideoBanQuanVideo vb where vb.info.id=?")
                                .setParameter(0, vb.getInfo().getId()).list();
                    List<VideoBanQuanVideo> list = session
                            .createQuery("from VideoBanQuanVideo vb " + where
                                    + " vb.info.name like ? group by vb.info.id order by vb.createtime desc")
                            .setParameter(0, "%" + key + "%").setFirstResult((page - 1) * Constant.pageCount)
                            .setMaxResults(Constant.pageCount).list();
                    for (VideoBanQuanVideo vb : list) {
                        List<DetailSystem> detailSystemS = session
                                .createQuery("select vb.detailSystem from VideoBanQuanVideo vb where vb.info.id=?")
                                .setParameter(0, vb.getInfo().getId()).list();
                        List<DetailSystemSelect> dssList = new ArrayList<>();
                        List<DetailSystemSelect> dssList = new ArrayList<>();
                        for (DetailSystem ds : detailSystemList) {
                            DetailSystemSelect dss = new DetailSystemSelect();
                            dss.setDetailSystem(ds);
                            dss.setSelected(false);
                            dssList.add(dss);
                        }
                        for (DetailSystem ds : detailSystemList) {
                            DetailSystemSelect dss = new DetailSystemSelect();
                            dss.setDetailSystem(ds);
                            dss.setSelected(false);
                            dssList.add(dss);
                        }
                        // 设置已经存在的
                        for (DetailSystem ds : detailSystemS) {
                        // 设置已经存在的
                        for (DetailSystem ds : detailSystemS) {
                            for (DetailSystemSelect dss : dssList) {
                                if (dss.getDetailSystem().getId().equalsIgnoreCase(ds.getId())) {
                                    dss.setSelected(true);
                                    break;
                                }
                            }
                        }
                        banquanList.add(new BanquanVideoAdmin(vb, dssList));
                    }
                            for (DetailSystemSelect dss : dssList) {
                                if (dss.getDetailSystem().getId().equalsIgnoreCase(ds.getId())) {
                                    dss.setSelected(true);
                                    break;
                                }
                            }
                        }
                        banquanList.add(new BanquanVideoAdmin(vb, dssList));
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return banquanList;
            }
        });
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return banquanList;
            }
        });
    }
    }
    public long getBanquanVideoAdminCount(String key, int detailSystem) {
    public long getBanquanVideoAdminCount(String key, int detailSystem) {
        String where = "";
        if (detailSystem > 0)
            where += " where bv.detailsystemid= " + detailSystem + " and ";
        else
            where += " where ";
        String where = "";
        if (detailSystem > 0)
            where += " where bv.detailsystemid= " + detailSystem + " and ";
        else
            where += " where ";
        return videoBanQuanVideoDao.getCountSQL(
                "select count(*) from  (select count(*) from wk_video_banquan_video bv left join wk_video_video v on v.id=bv.videoid "
                        + where + "    v.name like '%" + key + "%' group by bv.videoid) s");
    }
        return videoBanQuanVideoDao.getCountSQL(
                "select count(*) from  (select count(*) from wk_video_banquan_video bv left join wk_video_video v on v.id=bv.videoid "
                        + where + "    v.name like '%" + key + "%' group by bv.videoid) s");
    }
    @SuppressWarnings("rawtypes")
    public void addBanQuanVideoAdmin(final String videoid, final String detailSystemId) {
        videoBanQuanDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                try {
                    List list = session
                            .createQuery("from VideoBanQuanVideo vb where vb.info.id=? and vb.detailSystem.id=?")
                            .setParameter(0, videoid).setParameter(1, detailSystemId).list();
                    session.getTransaction().begin();
                    if (list == null || list.size() == 0) {
                        VideoBanQuanVideo vb = new VideoBanQuanVideo();
                        vb.setCreatetime(System.currentTimeMillis() + "");
                        vb.setDetailSystem(new DetailSystem(detailSystemId));
                        vb.setInfo(new VideoInfo(videoid));
                        vb.setName(((VideoInfo) session.get(VideoInfo.class, videoid)).getName());
                        vb.setShow(true);
                        session.persist(vb);
                    }
                    session.flush();
                    session.getTransaction().commit();
    @SuppressWarnings("rawtypes")
    public void addBanQuanVideoAdmin(final String videoid, final String detailSystemId) {
        videoBanQuanDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                try {
                    List list = session
                            .createQuery("from VideoBanQuanVideo vb where vb.info.id=? and vb.detailSystem.id=?")
                            .setParameter(0, videoid).setParameter(1, detailSystemId).list();
                    session.getTransaction().begin();
                    if (list == null || list.size() == 0) {
                        VideoBanQuanVideo vb = new VideoBanQuanVideo();
                        vb.setCreatetime(System.currentTimeMillis() + "");
                        vb.setDetailSystem(new DetailSystem(detailSystemId));
                        vb.setInfo(new VideoInfo(videoid));
                        vb.setName(((VideoInfo) session.get(VideoInfo.class, videoid)).getName());
                        vb.setShow(true);
                        session.persist(vb);
                    }
                    session.flush();
                    session.getTransaction().commit();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return null;
            }
        });
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return null;
            }
        });
    }
    }
    @SuppressWarnings("unchecked")
    public void deleteBanQuanVideoAdmin(final String videoid, final String detailSystemId) {
        videoBanQuanDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                try {
                    session.getTransaction().begin();
                    List<VideoBanQuanVideo> list = session
                            .createQuery("from VideoBanQuanVideo vb where vb.info.id=? and vb.detailSystem.id=?")
                            .setParameter(0, videoid).setParameter(1, detailSystemId).list();
                    if (list != null && list.size() > 0) {
                        for (VideoBanQuanVideo vb : list)
                            session.delete(vb);
                    }
                    session.flush();
                    session.getTransaction().commit();
                } catch (Exception e) {
                    e.printStackTrace();
                    session.getTransaction().rollback();
                }
                return null;
            }
        });
    @SuppressWarnings("unchecked")
    public void deleteBanQuanVideoAdmin(final String videoid, final String detailSystemId) {
        videoBanQuanDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                try {
                    session.getTransaction().begin();
                    List<VideoBanQuanVideo> list = session
                            .createQuery("from VideoBanQuanVideo vb where vb.info.id=? and vb.detailSystem.id=?")
                            .setParameter(0, videoid).setParameter(1, detailSystemId).list();
                    if (list != null && list.size() > 0) {
                        for (VideoBanQuanVideo vb : list)
                            session.delete(vb);
                    }
                    session.flush();
                    session.getTransaction().commit();
                } catch (Exception e) {
                    e.printStackTrace();
                    session.getTransaction().rollback();
                }
                return null;
            }
        });
    }
    }
    public boolean isNeedWebPlay(String detailSystemId, String videoid) {
        return webVideoDao.getCount("select count(*) from WebVideo web where web.detailSystem.id=? and web.info.id=?",
                new Serializable[] { detailSystemId, videoid }) > 0;
    }
    public boolean isNeedWebPlay(String detailSystemId, String videoid) {
        return webVideoDao.getCount("select count(*) from WebVideo web where web.detailSystem.id=? and web.info.id=?",
                new Serializable[]{detailSystemId, videoid}) > 0;
    }
}
src/main/java/com/yeshi/buwan/service/imp/SearchService.java
@@ -5,6 +5,7 @@
import com.yeshi.buwan.domain.*;
import com.yeshi.buwan.domain.solr.SolrAlbumVideo;
import com.yeshi.buwan.domain.system.DetailSystem;
import com.yeshi.buwan.domain.video.InternetSearchVideo;
import com.yeshi.buwan.domain.web.DetailSystemSelect;
import com.yeshi.buwan.domain.web.HotSearchAdmin;
import com.yeshi.buwan.dto.search.SolrResultDTO;
@@ -12,6 +13,7 @@
import com.yeshi.buwan.pptv.PPTVUtil;
import com.yeshi.buwan.service.inter.video.VideoInfoExtraService;
import com.yeshi.buwan.service.manager.SolrAlbumVideoDataManager;
import com.yeshi.buwan.service.manager.SolrInternetSearchVideoDataManager;
import com.yeshi.buwan.util.*;
import com.yeshi.buwan.util.factory.VideoInfoFactory;
import com.yeshi.buwan.util.video.VideoConstant;
@@ -31,7 +33,7 @@
@Service
public class SearchService {
    private Logger logger= LoggerFactory.getLogger(SearchService.class);
    private Logger logger = LoggerFactory.getLogger(SearchService.class);
    @Resource
@@ -50,6 +52,9 @@
    private DetailSystemDao detailSystemDao;
    @Resource
    private SolrAlbumVideoDataManager solrAlbumDataManager;
    @Resource
    private SolrInternetSearchVideoDataManager solrInternetSearchVideoDataManager;
    @Resource
    private VideoInfoExtraService videoInfoExtraService;
@@ -251,9 +256,94 @@
    }
    @Cacheable(value = "userCache", key = "'searchNew'+'-'+#detailSystem+'-'+#key+'-'+#page+'-'+#videoType+'-'+#system+'-'+#cacheMD5")
    public VideoListResultVO searchNew(String detailSystem, String ip, String uid, String key, int page, int videoType,
                                       String system, List<Long> resourceList, String cacheMD5) {
    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 SearchResult searchAlbum(int videoType, String key, int page, int pageSize) {
        List<VideoInfo> localList = new ArrayList<>();
        //专辑视频集合
        Set<String> solrAlbumVids = new HashSet<>();
        SolrVideoSearchFilter filter = new SolrVideoSearchFilter();
        filter.setKey(key);
        if (videoType == Constant.SEARCH_RESULT_TYPE_HIGH_DEFINITION) {
            filter.setResourceIds(new String[]{PPTVUtil.RESOURCE_ID + ""});
            logger.info("高清搜索# key:{}", key);
        } else
            filter.setVideoType(videoType == 0 ? null : videoType);
        filter.setContentType(1);
        SolrResultDTO solrResultDTO = solrAlbumDataManager.find(filter, page, pageSize);
        Set<String> albumSet = new HashSet<>();
        int albumCount = 0;
        if (solrResultDTO != null) {
            albumCount = solrResultDTO.getTotalCount();
            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);
                solrAlbumVids.add(video.getId());
            }
        }
        //第一页而且不为高清时搜索
        if (page == 1 && videoType != Constant.SEARCH_RESULT_TYPE_HIGH_DEFINITION) {
            //page为1时 全网搜
            SolrResultDTO internetSearchResultDTO = solrInternetSearchVideoDataManager.find(filter, 1, 20);
            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);
                }
            }
            //todo 按关键词的匹配度排序
        }
        return new SearchResult(albumCount, localList);
    }
    private void filterSearchResult(List<VideoInfo> localList, List<Long> resourceList) {
        String sql = "";
        String resourceWhere = "";
        for (Long re : resourceList) {
            resourceWhere += " rv.resourceid=" + re + " or";
@@ -262,6 +352,40 @@
        if (resourceWhere.endsWith("or"))
            resourceWhere = resourceWhere.substring(0, resourceWhere.length() - 2);
        List<String> filterVideoIdList = new ArrayList<>();
        for (int i = 0; i < localList.size(); i++) {
            if (NumberUtil.isNumeric(localList.get(i).getId())) {
                filterVideoIdList.add(localList.get(i).getId());
                sql += " select count(*) from wk_resource_video rv left join wk_video_video v on rv.videoid=v.id where v.id is not null and v.show=1 and rv.videoid="
                        + localList.get(i).getId() + " and (" + resourceWhere + ") union all";
            }
        }
        if (sql.endsWith("union all"))
            sql = sql.substring(0, sql.length() - 9);
        List rlist = StringUtil.isNullOrEmpty(sql) ? new ArrayList() : videoInfoDao.sqlList(sql);
        Set<String> deleteVids = new HashSet<>();
        for (int i = 0; i < filterVideoIdList.size(); i++) {
            if (Integer.parseInt(rlist.get(i) + "") < 1) {
                deleteVids.add(filterVideoIdList.get(i));
            }
        }
        for (int i = 0; i < localList.size(); i++) {
            if (deleteVids.contains(localList.get(i).getId())) {
                localList.remove(i);
                i--;
            }
        }
    }
    @Cacheable(value = "userCache", key = "'searchNew'+'-'+#detailSystem+'-'+#key+'-'+#page+'-'+#videoType+'-'+#system+'-'+#cacheMD5")
    public VideoListResultVO searchNew(String detailSystem, String ip, String uid, String key, int page, int videoType,
                                       String system, List<Long> resourceList, String cacheMD5) {
        SearchHistory sh = new SearchHistory();
        sh.setCreatetime((new StringBuilder(String.valueOf(System.currentTimeMillis()))).toString());
        sh.setIp(ip);
@@ -286,55 +410,18 @@
            localList = new ArrayList<>();
            //先搜索专辑
            int pageSize = 20;
            //专辑视频集合
            Set<String> solrAlbumVids = new HashSet<>();
            SolrVideoSearchFilter filter = new SolrVideoSearchFilter();
            filter.setKey(key);
            if (videoType == Constant.SEARCH_RESULT_TYPE_HIGH_DEFINITION) {
                filter.setResourceIds(new String[]{PPTVUtil.RESOURCE_ID + ""});
                logger.info("高清搜索# key:{}",key);
            } else
                filter.setVideoType(videoType == 0 ? null : videoType);
            filter.setContentType(1);
            SolrResultDTO solrResultDTO = solrAlbumDataManager.find(filter, page, pageSize);
            if (solrResultDTO != null) {
                albumCount = solrResultDTO.getTotalCount();
                for (SolrAlbumVideo sv : (List<SolrAlbumVideo>) solrResultDTO.getVideoList()) {
                    VideoInfo video = VideoInfoFactory.create(sv);
                    video.setShowType(1);
                    if (!StringUtil.isNullOrEmpty(video.getMainActor())) {
                        video.setMainActor("主演:" + video.getMainActor());
                    }
                    //设置tag
                    String tag = "";
                    if (!StringUtil.isNullOrEmpty(sv.getYear())) {
                        tag += sv.getYear() + "/";
                    }
                    if (video.getVideoType() != null) {
                        String vt = VideoConstant.getMainCategoryName(sv.getRootVideoType());
                        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);
                    localList.add(video);
                    solrAlbumVids.add(video.getId());
                }
            SearchResult searchResult = searchAlbum(videoType, key, page, pageSize);
            if (searchResult != null && searchResult.videoInfoList != null) {
                localList.addAll(searchResult.videoInfoList);
            }
            int commonSolrPage = page - solrResultDTO.getTotalCount() / pageSize;
            Set<String> solrAlbumVids = new HashSet<>();
            for (VideoInfo videoInfo : localList) {
                solrAlbumVids.add(videoInfo.getId());
            }
            int commonSolrPage = page - searchResult.getTotalCount() / pageSize;
            if (videoType == 0 && commonSolrPage > 0) {
                //搜索原始的
@@ -350,42 +437,13 @@
                }
            }
            System.out.println("搜索耗时:" + (System.currentTimeMillis() - startt));
            String sql = "";
            startt = System.currentTimeMillis();
            for (int i = 0; i < localList.size(); i++) {
                sql += " select count(*) from wk_resource_video rv left join wk_video_video v on rv.videoid=v.id where v.id is not null and v.show=1 and rv.videoid="
                        + localList.get(i).getId() + " and (" + resourceWhere + ") union all";
            }
            if (sql.endsWith("union all"))
                sql = sql.substring(0, sql.length() - 9);
            List rlist = StringUtil.isNullOrEmpty(sql) ? new ArrayList() : videoInfoDao.sqlList(sql);
            List<Integer> pList = new ArrayList<>();
            for (int i = 0; i < localList.size(); i++) {
                if (Integer.parseInt(rlist.get(i) + "") < 1) {
                    pList.add(i);
                    // localList.remove(i);
                    // i--;
                }
            }
            Collections.sort(pList);
            for (int i = pList.size() - 1; i >= 0; i--) {
                localList.remove((int) pList.get(i));
            }
            System.out.println("排除耗时:" + (System.currentTimeMillis() - startt));
            filterSearchResult(localList, resourceList);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
        }
        if (localList != null && localList.size() > 0) {
            for (VideoInfo info : localList) {
                list.add(info);
            }
            list.addAll(localList);
        }
        //获取附加信息
@@ -649,4 +707,31 @@
        return videoInfoList;
    }
    class SearchResult {
        private int totalCount;
        private List<VideoInfo> videoInfoList;
        public SearchResult(int totalCount, List<VideoInfo> videoInfoList) {
            this.totalCount = totalCount;
            this.videoInfoList = videoInfoList;
        }
        public int getTotalCount() {
            return totalCount;
        }
        public void setTotalCount(int totalCount) {
            this.totalCount = totalCount;
        }
        public List<VideoInfo> getVideoInfoList() {
            return videoInfoList;
        }
        public void setVideoInfoList(List<VideoInfo> videoInfoList) {
            this.videoInfoList = videoInfoList;
        }
    }
}
src/main/java/com/yeshi/buwan/service/imp/VideoResourceService.java
@@ -13,6 +13,7 @@
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -29,6 +30,15 @@
        return (VideoResource) videoResourceDao.find(VideoResource.class, id);
    }
    public List<VideoResource> getResource(List<String> ids) {
        List<VideoResource> videoResources = new ArrayList<>();
        for (String id : ids) {
            videoResources.add(getResource(id));
        }
        return videoResources;
    }
    public void addResource(VideoResource re) {
        videoResourceDao.create(re);
    }
src/main/java/com/yeshi/buwan/service/imp/juhe/YouKuServiceImpl.java
@@ -1,8 +1,15 @@
package com.yeshi.buwan.service.imp.juhe;
import com.yeshi.buwan.dao.juhe.youku.YouKuSearchVideoMapDao;
import com.yeshi.buwan.dao.juhe.youku.YouKuShowDetailDao;
import com.yeshi.buwan.dao.juhe.youku.YouKuVideoDao;
import com.yeshi.buwan.domain.VideoDetailInfo;
import com.yeshi.buwan.domain.video.InternetSearchVideo;
import com.yeshi.buwan.service.inter.juhe.InternetSearchVideoService;
import com.yeshi.buwan.service.inter.juhe.YouKuService;
import com.yeshi.buwan.util.factory.InternetSearchVideoFactory;
import com.yeshi.buwan.youku.YouKuUtil;
import com.yeshi.buwan.youku.entity.YouKuSearchVideoMap;
import com.yeshi.buwan.youku.entity.YouKuShowDetail;
import com.yeshi.buwan.youku.entity.YouKuVideo;
import org.springframework.data.domain.Sort;
@@ -18,9 +25,14 @@
public class YouKuServiceImpl implements YouKuService {
    @Resource
    private YouKuSearchVideoMapDao youKuSearchVideoMapDao;
    @Resource
    private YouKuShowDetailDao youKuShowDetailDao;
    @Resource
    private YouKuVideoDao youKuVideoDao;
    @Resource
    private InternetSearchVideoService internetSearchVideoService;
    @Override
    public void save(YouKuShowDetail detail) {
@@ -49,6 +61,28 @@
        return detail;
    }
    @Override
    public YouKuShowDetail getSimpleShowDetail(String showId) {
        YouKuShowDetail detail = youKuShowDetailDao.get(showId);
        return detail;
    }
    @Override
    public List<YouKuVideo> getVideoList(String showId, int page, int pageSize) {
        Query query = new Query();
        query.addCriteria(Criteria.where("showId").is(showId));
        query.with(new Sort(new Sort.Order(Sort.Direction.ASC, "show_videoseq")));
        query.skip((page - 1) * pageSize);
        query.limit(pageSize);
        List<YouKuVideo> videoList = youKuVideoDao.findList(query);
        return videoList;
    }
    @Override
    public YouKuVideo getVideoDetail(String id) {
        return youKuVideoDao.get(id);
    }
    @Override
    public long count(String category) {
@@ -67,4 +101,29 @@
        query.skip((page - 1) * pageSize);
        return youKuShowDetailDao.findList(query);
    }
    @Override
    public List<VideoDetailInfo> getVideoDetailList(String videoid, int page, int pageSize) {
        YouKuSearchVideoMap map = youKuSearchVideoMapDao.selectByVideoId(videoid);
        if (map == null)
            return null;
        return YouKuUtil.convertToDetail(getVideoList(map.getShowId(), page, pageSize));
    }
    @Override
    public YouKuSearchVideoMap selectByVideoId(String videoId) {
        YouKuSearchVideoMap map = youKuSearchVideoMapDao.selectByVideoId(videoId);
        return map;
    }
    @Override
    public void addToInternetSearch(YouKuShowDetail showDetail) throws Exception {
        InternetSearchVideo video = InternetSearchVideoFactory.create(showDetail);
        internetSearchVideoService.save(video);
        YouKuSearchVideoMap map = new YouKuSearchVideoMap();
        map.setShowId(showDetail.getId());
        map.setVideoId(video.getId());
        map.setCreateTime(new Date());
        youKuSearchVideoMapDao.save(map);
    }
}
src/main/java/com/yeshi/buwan/service/inter/juhe/YouKuService.java
@@ -1,6 +1,9 @@
package com.yeshi.buwan.service.inter.juhe;
import com.yeshi.buwan.domain.VideoDetailInfo;
import com.yeshi.buwan.youku.entity.YouKuSearchVideoMap;
import com.yeshi.buwan.youku.entity.YouKuShowDetail;
import com.yeshi.buwan.youku.entity.YouKuVideo;
import java.util.List;
@@ -15,8 +18,25 @@
    public YouKuShowDetail getShowDetail(String showId);
    public YouKuShowDetail getSimpleShowDetail(String showId);
    public List<YouKuVideo> getVideoList(String showId, int page, int pageSize);
    public YouKuVideo getVideoDetail(String id);
    public long count(String category);
    public List<YouKuShowDetail> list(String category, int page, int pageSize);
    public List<VideoDetailInfo> getVideoDetailList(final String videoid, int page, int pageSize);
    public YouKuSearchVideoMap selectByVideoId(String videoId);
    /**
     * 添加到全网搜
     *
     * @param showDetail
     */
    public void addToInternetSearch(YouKuShowDetail showDetail) throws Exception;
}
src/main/java/com/yeshi/buwan/service/manager/SolrAlbumVideoDataManager.java
@@ -135,7 +135,11 @@
        Query query = null;
        if (!StringUtil.isNullOrEmpty(filter.getKey())) {
            //solr精准检索需要带引号
            query = new SimpleQuery(new Criteria("nameStr").startsWith(filter.getKey()).or("mainactor").expression("\"" + filter.getKey() + "\""));
            if (filter.isFuzzy()) {
                query = new SimpleQuery(new Criteria("name").expression(filter.getKey()));
            } else {
                query = new SimpleQuery(new Criteria("nameStr").startsWith(filter.getKey()).or("mainactor").expression("\"" + filter.getKey() + "\""));
            }
        } else if (!StringUtil.isNullOrEmpty(filter.getActor())) {
            query = new SimpleQuery(new Criteria("mainactor").expression("\"" + filter.getActor() + "\""));
        } else if (!StringUtil.isNullOrEmpty(filter.getDirector())) {
src/main/java/com/yeshi/buwan/service/manager/SolrInternetSearchVideoDataManager.java
@@ -97,7 +97,7 @@
        Query query = null;
        if (!StringUtil.isNullOrEmpty(filter.getKey())) {
            //solr精准检索需要带引号
            query = new SimpleQuery(new Criteria("nameStr").startsWith(filter.getKey()).or("mainactor").expression("\"" + filter.getKey() + "\""));
            query = new SimpleQuery(new Criteria("nameStr").startsWith(filter.getKey()).or("actors").expression("\"" + filter.getKey() + "\""));
        } else if (!StringUtil.isNullOrEmpty(filter.getActor())) {
            query = new SimpleQuery(new Criteria("actors").expression("\"" + filter.getActor() + "\""));
        } else if (!StringUtil.isNullOrEmpty(filter.getDirector())) {
src/main/java/com/yeshi/buwan/util/factory/VideoInfoFactory.java
@@ -3,6 +3,7 @@
import com.yeshi.buwan.domain.solr.SolrAlbumVideo;
import com.yeshi.buwan.domain.VideoInfo;
import com.yeshi.buwan.domain.VideoType;
import com.yeshi.buwan.domain.video.InternetSearchVideo;
import com.yeshi.buwan.pptv.PPTVUtil;
public class VideoInfoFactory {
@@ -30,13 +31,51 @@
        video.setVideocount(solrVideo.getVideocount());
        video.setName(solrVideo.getName());
        video.setUpdatetime(solrVideo.getUpdatetime());
        video.setYear(solrVideo.getYear());
        video.setVideoType(new VideoType(solrVideo.getRootVideoType()));
        //PPTV来源需要返回高清标识
        if (solrVideo.getResourceIds()!=null&&solrVideo.getResourceIds().contains(PPTVUtil.RESOURCE_ID + ""))
        if (solrVideo.getResourceIds() != null && solrVideo.getResourceIds().contains(PPTVUtil.RESOURCE_ID + ""))
            video.setDefinition(1);
        else
            video.setDefinition(0);
        return video;
    }
    public static VideoInfo create(InternetSearchVideo solrVideo) {
        VideoInfo video = new VideoInfo();
        video.setMainActor(solrVideo.getActors());
        video.setShow(1 + "");
        video.setLatestHpicture("");
        video.setDuration("0");
        video.setScore("9.0");
        video.setVpicture(solrVideo.getVpicture());
        video.setLatestVpicture("");
        video.setId(solrVideo.getId());
        video.setTag(solrVideo.getTag());
        video.setHpicture(solrVideo.getHpicture());
        video.setArea(solrVideo.getArea());
        if (solrVideo.getCreateTime() != null)
            video.setCreatetime(solrVideo.getCreateTime().getTime());
        video.setWatchCount("0");
        video.setDirector(solrVideo.getDirector());
        video.setPicture(solrVideo.getVpicture());
        video.setContentType(1);
        video.setCommentCount(0);
        video.setVideocount(solrVideo.getVideoCount());
        video.setName(solrVideo.getName());
        if (solrVideo.getUpdateTime() != null)
            video.setUpdatetime(solrVideo.getUpdateTime().getTime() + "");
        video.setVideoType(new VideoType(solrVideo.getRootType()));
        //PPTV来源需要返回高清标识
        if (solrVideo.getResourceIds() != null && solrVideo.getResourceIds().contains(PPTVUtil.RESOURCE_ID + ""))
            video.setDefinition(1);
        else
            video.setDefinition(0);
        video.setYear(solrVideo.getYear());
        return video;
    }
}
src/main/java/com/yeshi/buwan/util/video/VideoDetailUtil.java
@@ -17,10 +17,12 @@
import com.yeshi.buwan.service.imp.juhe.SoHuService;
import com.yeshi.buwan.service.inter.juhe.FunTV2Service;
import com.yeshi.buwan.service.inter.juhe.Iqiyi2Service;
import com.yeshi.buwan.service.inter.juhe.YouKuService;
import com.yeshi.buwan.sohu.SoHuUtil;
import com.yeshi.buwan.util.StringUtil;
import com.yeshi.buwan.util.log.VideoLogFactory;
import com.yeshi.buwan.vo.AcceptData;
import com.yeshi.buwan.youku.YouKuUtil;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.slf4j.Logger;
@@ -64,11 +66,17 @@
    @Resource
    private VideoInfoService videoInfoService;
    @Resource
    private YouKuUtil youKuUtil;
    @Resource
    private YouKuService youKuService;
    @SuppressWarnings("unchecked")
//    @Cacheable(value = "homeCache", key = "'getVideoInfo'+'-'+#videoid+'-'+#resourceId+'-'+#cacheMD5")
    public VideoInfo getVideoInfo(String detailSystemId,final String videoid, final String resourceId, final List<Long> reList,
    public VideoInfo getVideoInfo(String detailSystemId, final String videoid, final String resourceId, final List<Long> reList,
                                  String cacheMD5) {
        playLogger.info(VideoLogFactory.createVideoDetailLog(detailSystemId, videoid,resourceId));
        playLogger.info(VideoLogFactory.createVideoDetailLog(detailSystemId, videoid, resourceId));
        return (VideoInfo) videoInfoDao.excute(new HibernateCallback<VideoInfo>() {
            public VideoInfo doInHibernate(Session session) throws HibernateException {
@@ -198,6 +206,8 @@
                return videoInfoService.getVideoDetailList(videoid, vr, page, pageSize);
            case SoHuUtil.RESOURCE_ID:
                return soHuService.getVideoDetailList(videoid, page, pageSize);
            case YouKuUtil.RESOURCE_ID:
                return youKuService.getVideoDetailList(videoid, page, pageSize);
            default:
                return null;
        }
@@ -217,6 +227,8 @@
                return funTVService.getLatestVideoDetail(videoid);
            case SoHuUtil.RESOURCE_ID:
                return soHuService.getLatestVideoDetail(videoid);
            case YouKuUtil.RESOURCE_ID:
                return soHuService.getLatestVideoDetail(videoid);
            default:
                return null;
        }
@@ -234,6 +246,8 @@
            case FunTVUtil.RESOURCE_ID:
                return funTVService.getShowType(videoid);
            case SoHuUtil.RESOURCE_ID:
                return soHuUtil.getShowType(videoid);
            case YouKuUtil.RESOURCE_ID:
                return soHuUtil.getShowType(videoid);
            default:
                return 1;
@@ -256,6 +270,8 @@
                return soHuUtil.getPlayUrl(detailSystemId, resourceid + "", type, id);
            case AcFunUtil.RESOURCE_ID:
                return videoInfoService.getPlayUrl(detailSystemId, id, type, resourceid, videoid);
            case YouKuUtil.RESOURCE_ID:
                return youKuUtil.getPlayUrl(detailSystemId, id, type, resourceid, videoid);
            default:
                return null;
        }
src/main/java/com/yeshi/buwan/youku/YouKuUtil.java
New file
@@ -0,0 +1,137 @@
package com.yeshi.buwan.youku;
import com.yeshi.buwan.domain.VideoDetailInfo;
import com.yeshi.buwan.domain.VideoInfo;
import com.yeshi.buwan.domain.VideoResource;
import com.yeshi.buwan.domain.entity.PlayUrl;
import com.yeshi.buwan.domain.video.InternetSearchVideo;
import com.yeshi.buwan.service.imp.VideoResourceService;
import com.yeshi.buwan.service.imp.VideoTypeService;
import com.yeshi.buwan.service.inter.juhe.InternetSearchVideoService;
import com.yeshi.buwan.service.inter.juhe.YouKuService;
import com.yeshi.buwan.util.JsonUtil;
import com.yeshi.buwan.util.factory.VideoInfoFactory;
import com.yeshi.buwan.util.video.VideoConstant;
import com.yeshi.buwan.youku.entity.YouKuSearchVideoMap;
import com.yeshi.buwan.youku.entity.YouKuShowDetail;
import com.yeshi.buwan.youku.entity.YouKuVideo;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Component
public class YouKuUtil {
    @Resource
    private InternetSearchVideoService internetSearchVideoService;
    @Resource
    private YouKuService youKuService;
    @Resource
    private VideoResourceService videoResourceService;
    @Resource
    private VideoTypeService videoTypeService;
    public final static int RESOURCE_ID = 20;
    public static VideoDetailInfo convertToDetail(YouKuVideo youKuVideo) {
        VideoDetailInfo detail = new VideoDetailInfo();
        switch (youKuVideo.getCategory()) {
            case "电影":
                detail.setTag(youKuVideo.getTitle());
                break;
            case "电视剧":
            case "动漫":
                detail.setTag(youKuVideo.getShow_videoseq() + "");
                break;
            case "综艺":
                detail.setTag(youKuVideo.getShow_videostage() + " " + youKuVideo.getTitle());
                break;
        }
        detail.setName(youKuVideo.getTitle());
        detail.setExtraId(youKuVideo.getVideoid());
        detail.setType("url");
        return detail;
    }
    public VideoInfo getVideoInfo(InternetSearchVideo internetSearchVideo) throws Exception {
        YouKuSearchVideoMap map = youKuService.selectByVideoId(internetSearchVideo.getId());
        if (map == null) {
            throw new Exception("视频源不存在");
        }
        YouKuShowDetail showDetail = youKuService.getSimpleShowDetail(map.getShowId());
        showDetail.setVideoList(youKuService.getVideoList(showDetail.getId(), 1, 100));
        VideoInfo info = VideoInfoFactory.create(internetSearchVideo);
        info.setIntroduction(showDetail.getDescription());
        info.setVideoDetailList(YouKuUtil.convertToDetail(showDetail.getVideoList()));
        info.setPlayPicture(info.getHpicture());
        //获取资源列表
        List<String> rids = Arrays.asList(internetSearchVideo.getResourceIds().split(","));
        List<VideoResource> resourceList = videoResourceService.getResource(rids);
        for (VideoResource vr : resourceList) {
            if (vr.getId().equalsIgnoreCase(RESOURCE_ID + ""))
                vr.setChecked(true);
        }
        info.setResourceList(resourceList);
        info.setShowType(YouKuUtil.getShowType(internetSearchVideo));
        info.setScore(new BigDecimal(showDetail.getScore()).setScale(1).toString());
        //获取分类详情
        info.setVideoType(videoTypeService.getVideoType(info.getVideoType().getId()));
        info.setCommentCount(0);
        info.setVideocount((int) (Math.random() * 1000));
        return info;
    }
    public static List<VideoDetailInfo> convertToDetail(List<YouKuVideo> youKuVideoList) {
        List<VideoDetailInfo> detailList = new ArrayList<>();
        for (YouKuVideo video : youKuVideoList) {
            detailList.add(convertToDetail(video));
        }
        return detailList;
    }
    public static int getShowType(InternetSearchVideo video) {
        if (video == null)
            return 2;
        switch (video.getRootType()) {
            case VideoConstant
                    .VIDEO_CATEGORY_DIANYING:
                return 1;
            case VideoConstant
                    .VIDEO_CATEGORY_DIANSHIJU:
            case VideoConstant
                    .VIDEO_CATEGORY_DONGMAN:
                return 2;
            case VideoConstant
                    .VIDEO_CATEGORY_ZONGYI:
                return 1;
        }
        return 2;
    }
    public PlayUrl getPlayUrl(String detailSystemId, String id, String type, int resourceid, String videoid) {
        PlayUrl playUrl = new PlayUrl();
        VideoResource videoResource = videoResourceService.getResource(resourceid + "");
        playUrl.setResource(videoResource);
        YouKuVideo youKuVideo = youKuService.getVideoDetail(id);
        playUrl.setUrl(youKuVideo.getLink());
        playUrl.setPlayType(1);
        playUrl.setParams("");
        return playUrl;
    }
}
src/test/java/com/hxh/spring/test/GeneralTest.java
@@ -2,16 +2,9 @@
import com.yeshi.buwan.dao.base.MongodbBaseDao;
import com.yeshi.buwan.dao.video.VideoResourceVersionMapDao;
import com.yeshi.buwan.domain.VideoInfo;
import com.yeshi.buwan.domain.recommend.HomeRecommendSpecial;
import com.yeshi.buwan.domain.recommend.SuperHomeRecommendSpecial;
import com.yeshi.buwan.domain.system.SystemConfig;
import com.yeshi.buwan.domain.video.InternetSearchVideo;
import com.yeshi.buwan.domain.video.VideoResourceVersionMap;
import com.yeshi.buwan.service.inter.video.VideoResourceVersionMapService;
import com.yeshi.buwan.tencent.entity.TencentCoverInfo;
import com.yeshi.buwan.youku.entity.YouKuShowDetail;
import com.yeshi.buwan.youku.entity.YouKuVideo;
import com.yeshi.buwan.youku.entity.YouKuSearchVideoMap;
import org.yeshi.utils.generater.SpringComponentGenerater;
import org.yeshi.utils.generater.entity.MongoDBDaoData;
import org.yeshi.utils.generater.entity.ServiceData;
@@ -21,7 +14,7 @@
    @org.junit.Test
    public void createDao() {
        try {
            SpringComponentGenerater.createMongoDao(new MongoDBDaoData.Builder().setBaseDaoClass(MongodbBaseDao.class).setDaoPackageName("com.yeshi.buwan.dao.juhe.tencent").setEntityClass(TencentCoverInfo.class).create(), "D:\\workspace\\buwan\\buwan-server\\src\\main\\java\\com\\yeshi\\buwan\\dao\\juhe\\tencent\\");
            SpringComponentGenerater.createMongoDao(new MongoDBDaoData.Builder().setBaseDaoClass(MongodbBaseDao.class).setDaoPackageName("com.yeshi.buwan.dao.juhe.youku").setEntityClass(YouKuSearchVideoMap.class).create(), "D:\\workspace\\BuWan\\src\\main\\java\\com\\yeshi\\buwan\\dao\\juhe\\youku\\");
        } catch (Exception e) {
            e.printStackTrace();
        }
src/test/java/com/hxh/spring/test/Iqiyi2.java
@@ -37,9 +37,9 @@
import java.util.Scanner;
//
@RunWith(SpringJUnit4ClassRunner.class) //使用junit4进行测试
@ContextConfiguration(locations = {"classpath:spring.xml"})
@WebAppConfiguration
//@RunWith(SpringJUnit4ClassRunner.class) //使用junit4进行测试
//@ContextConfiguration(locations = {"classpath:spring.xml"})
//@WebAppConfiguration
public class Iqiyi2 {
    private final static Logger errorLogger = LoggerFactory.getLogger("errorLogger");
@@ -273,7 +273,7 @@
    @Test
    public void addResources() {
        try {
            VideoInfo videoInfo = videoInfoService.getVideoInfo(8174476+"");
            VideoInfo videoInfo = videoInfoService.getVideoInfo(8174476 + "");
            if (videoInfo != null) {
                if ("1".equalsIgnoreCase(videoInfo.getShow())) {
                    List<VideoResource> resourceList = new ArrayList<>();
@@ -291,4 +291,11 @@
    }
    @Test
    public void getDetail() {
        IqiYiNewAPI.getAlbumOrVideoDetail(524533200L);
    }
}
src/test/java/com/hxh/spring/test/SolrTest.java
@@ -2,13 +2,23 @@
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;
@@ -18,8 +28,7 @@
import org.springframework.test.context.web.WebAppConfiguration;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.*;
@RunWith(SpringJUnit4ClassRunner.class)
@@ -40,6 +49,12 @@
    private HomeNoticeDao homeNoticeDao;
    @Resource
    private AlbumVideoMapService albumVideoMapService;
    @Resource
    private SolrInternetSearchVideoDataManager solrInternetSearchVideoDataManager;
    @Resource
    private InternetSearchVideoService internetSearchVideoService;
    @Test
    public void test1() {
@@ -66,13 +81,98 @@
    }
    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("59fafccefd20505b0aade6d9ba0e8ed1"); //listAll(1, 10);
        solrInternetSearchVideoDataManager.saveOrUpdate(list);
    }
    @Resource
    private AlbumVideoMapDao albumVideoMapDao;
    @Test
    public void test2() {
        for(int i=0;i<100;i++) {
        for (int i = 0; i < 100; i++) {
            Query query = new Query();
            query.addCriteria(Criteria.where("id").type(7));
            query.limit(100);
src/test/java/com/hxh/spring/test/video/YouKuTest.java
@@ -1,7 +1,13 @@
package com.hxh.spring.test.video;
import com.yeshi.buwan.domain.video.InternetSearchVideo;
import com.yeshi.buwan.job.video.YouKuVideoUpdate;
import com.yeshi.buwan.service.inter.juhe.InternetSearchVideoService;
import com.yeshi.buwan.service.inter.juhe.YouKuService;
import com.yeshi.buwan.util.factory.InternetSearchVideoFactory;
import com.yeshi.buwan.youku.YouKuApiUtil;
import com.yeshi.buwan.youku.entity.YouKuShowDetail;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
@@ -9,7 +15,10 @@
import org.springframework.test.context.web.WebAppConfiguration;
import javax.annotation.Resource;
import javax.swing.*;
import java.util.List;
//
@RunWith(SpringJUnit4ClassRunner.class) //使用junit4进行测试
@ContextConfiguration(locations = {"classpath:spring.xml"})
@WebAppConfiguration
@@ -18,10 +27,40 @@
    @Resource
    private YouKuVideoUpdate youKuVideoUpdate;
    @Resource
    private InternetSearchVideoService internetSearchVideoService;
    @Resource
    private YouKuService youKuService;
    @Test
    public void test1() {
        try {
            youKuVideoUpdate.updateLatestVideo("动漫");
            youKuVideoUpdate.updateLatestVideo("ceba4745ea10415eb791");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    @Test
    public void test2() {
        List<YouKuShowDetail> details = youKuService.list("电视剧", 2, 700);
        for (YouKuShowDetail detail : details) {
            try {
                InternetSearchVideo video = InternetSearchVideoFactory.create(detail);
                internetSearchVideoService.save(video);
            } catch (Exception e) {
                System.out.println(detail.getName() + ":" + detail.getId());
                e.printStackTrace();
            }
        }
    }
    @Test
    public void getDetail() {
        YouKuShowDetail detail = YouKuApiUtil.getShowDetail("ceba4745ea10415eb791");
        try {
            youKuService.addToInternetSearch(detail);
        } catch (Exception e) {
            e.printStackTrace();
        }