admin
2021-03-29 ef37d60710c252e1d8473e8ce779696d497e857f
src/main/java/com/yeshi/buwan/controller/parser/HomeParser.java
@@ -12,18 +12,32 @@
import com.yeshi.buwan.domain.*;
import com.yeshi.buwan.domain.jump.JumpDetail;
import com.yeshi.buwan.domain.jump.JumpTypeEnum;
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.mogotv.MogoTVUtil;
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.tencent.TencentVideoUtil;
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;
@@ -41,6 +55,9 @@
@Controller
public class HomeParser {
    private Logger logger = LoggerFactory.getLogger(HomeParser.class);
    @Resource
    private SystemService systemService;
    @Resource
@@ -83,17 +100,23 @@
    @Resource
    private VideoWatchHistoryService videoWatchHistoryService;
    @Resource
    private HomeRecommendSpecialService homeRecommendSpecialService;
    private final Logger userPlayLogger = LoggerFactory.getLogger("videoPlayUser");
    @RequireUid
    public void getHomeAd(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
        String vtid = request.getParameter("Vtid");
        if (!"310".equals(vtid)) {
        HomeRecommendSpecial special = homeRecommendSpecialService.getSpecial(vtid);
        //兼容新版本
        if (special != null) {
            JSONObject object = new JSONObject();
            DetailSystem detailSystem = systemService.getDetailSystemByPackage(acceptData.getPackageName());
            List<HomeAd> list = homeAdService.getHomeAdList(detailSystem);
            List<HomeAd> list = homeAdService.getHomeAdList(detailSystem, special != null ? special.getDataKey() : null);
            if (acceptData.getPlatform().equalsIgnoreCase("ios"))// IOS测试
            {
@@ -119,7 +142,6 @@
                for (int i = 0; i < list.size(); i++)
                    array.add(StringUtil.outPutResultJson(list.get(i)));
                object.put("data", array);
            } else {
                for (HomeAd ad : list) {
                    if (ad.getVideo() != null) {
@@ -137,6 +159,7 @@
                object.put("data", array);
            }
            object.put("bannerSizeRate", special.getBannerSizeRate());
            out.print(JsonUtil.loadTrueJson(object.toString()));
        } else {
            classParser.getRecommendCategoryVideoBanner(acceptData, request, out);
@@ -156,12 +179,14 @@
            vtid = "309"; // 为了兼容以前的推荐
        }
        HomeRecommendSpecial special = homeRecommendSpecialService.getSpecial(vtid);
        DetailSystem detailSystem = systemService.getDetailSystemByPackage(acceptData.getPackageName());
        JSONObject object = new JSONObject();
        List<Long> resourceList = videoResouceUtil.getAvailableResourceIds(acceptData.getDetailSystem(), acceptData.getVersion());
        List<HomeType> list1 = homeTypeService.getHomeType(detailSystem.getId(), resourceList,
                CacheUtil.getMD5Long(resourceList), -1, Long.parseLong(vtid));
                CacheUtil.getMD5Long(resourceList), -1, special != null ? special.getDataKey() : null);
        List<HomeType> list = new ArrayList<>();
        for (HomeType ht : list1)
            list.add(ht);
@@ -201,7 +226,7 @@
                    if (adContent != null && adPosition != null) {
                        HomeType.HomeTypeAd ad = new Gson().fromJson(adContent.getValue(), HomeType.HomeTypeAd.class);
                        int adP = Integer.parseInt(adPosition.getValue());
                        if (adP < list.size()) {
                        if (adP < list.size() && adP > -1) {
                            HomeType homeType = new HomeType();
                            homeType.setAd(ad);
                            list.add(adP, homeType);
@@ -334,9 +359,75 @@
        out.print(JsonUtil.loadTrueJson(object.toString()));
    }
    @Resource
    private InternetSearchVideoService internetSearchVideoService;
    @Resource
    private YouKuUtil youKuUtil;
    @Resource
    private MogoTVUtil mogoTVUtil;
    @Resource
    private TencentVideoUtil tencentVideoUtil;
    public void getVideoDetailForInternetSearch(AcceptData acceptData, String videoId, HttpServletRequest request, PrintWriter out) {
        String loginUid = request.getParameter("LoginUid");
        String from = request.getParameter("From");
        InternetSearchVideo internetSearchVideo = internetSearchVideoService.selectByPrimaryKey(videoId);
        String resourceId = request.getParameter("ResourceId");
        if (StringUtil.isNullOrEmpty(resourceId)) {
            resourceId = internetSearchVideo.getResourceIds().split(",")[0];
        }
        VideoInfo info = null;
        if (Integer.parseInt(resourceId) == YouKuUtil.RESOURCE_ID) {
            try {
                info = youKuUtil.getVideoInfo(internetSearchVideo);
            } catch (Exception e) {
                logger.error("全网搜视频详情出错:" + videoId);
                e.printStackTrace();
                out.print(JsonUtil.loadFalseAdmin(e.getMessage()));
                return;
            }
        } else if (Integer.parseInt(resourceId) == MogoTVUtil.RESOURCE_ID) {
            try {
                info = mogoTVUtil.getVideoInfo(internetSearchVideo);
            } catch (Exception e) {
                logger.error("全网搜视频详情出错:" + videoId);
                out.print(JsonUtil.loadFalseAdmin(e.getMessage()));
                return;
            }
        } else if (Integer.parseInt(resourceId) == TencentVideoUtil.RESOURCE_ID) {
            try {
                info = tencentVideoUtil.getVideoInfo(internetSearchVideo);
            } catch (Exception e) {
                logger.error("全网搜视频详情出错:" + videoId);
                out.print(JsonUtil.loadFalseAdmin(e.getMessage()));
                return;
            }
        }
        LoggerUtil.getUserActiveLogger().info(UserActiveLogFactory.createVideoDetail(new BaseLog(acceptData, loginUid), videoId, info.getName(), from));
        info.setWatchCount("" + (int) (Math.random() * 1000));
        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");
@@ -409,12 +500,14 @@
            data.put("name", series.getName());
            data.put("pptv", true);
            out.print(JsonUtil.loadTrueJson(data.toString()));
            LoggerUtil.getUserActiveLogger().info(UserActiveLogFactory.createVideoDetail(new BaseLog(acceptData, loginUid), videoId, series.getName(), from));
            return;
        }
        VideoInfo info = videoDeailUtil.getVideoInfo(detailSystem.getId(), videoId, resourceId, resourceList,
                CacheUtil.getMD5Long(resourceList));
        LoggerUtil.getUserActiveLogger().info(UserActiveLogFactory.createVideoDetail(new BaseLog(acceptData, loginUid), videoId, info != null ? info.getName() : "", from));
        List<VideoType> typeList = classService.getVideoTypeList(info.getId());
        if (typeList != null && typeList.size() > 0) {
@@ -461,6 +554,7 @@
            out.print(JsonUtil.loadTrueJson(StringUtil.outPutResultJson(Utils.convertVideo(info)), array.toString(),
                    obj.toString()));
    }
    /**
     * 获取视频的剧集列表
@@ -517,6 +611,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(""));