From 1d28c69a351ae108f4116a10f19f615c89a660a2 Mon Sep 17 00:00:00 2001
From: admin <2780501319@qq.com>
Date: 星期四, 01 四月 2021 01:58:43 +0800
Subject: [PATCH] 首页数据修改

---
 src/main/java/com/yeshi/buwan/controller/parser/HomeParser.java |  176 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 165 insertions(+), 11 deletions(-)

diff --git a/src/main/java/com/yeshi/buwan/controller/parser/HomeParser.java b/src/main/java/com/yeshi/buwan/controller/parser/HomeParser.java
index dbe8e6b..878c360 100644
--- a/src/main/java/com/yeshi/buwan/controller/parser/HomeParser.java
+++ b/src/main/java/com/yeshi/buwan/controller/parser/HomeParser.java
@@ -15,20 +15,30 @@
 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.vo.video.VideoDetailVO;
+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;
@@ -46,6 +56,9 @@
 
 @Controller
 public class HomeParser {
+
+    private Logger logger = LoggerFactory.getLogger(HomeParser.class);
+
     @Resource
     private SystemService systemService;
     @Resource
@@ -173,7 +186,7 @@
         JSONObject object = new JSONObject();
 
         List<Long> resourceList = videoResouceUtil.getAvailableResourceIds(acceptData.getDetailSystem(), acceptData.getVersion());
-        List<HomeType> list1 = homeTypeService.getHomeType(detailSystem.getId(), resourceList,
+        List<HomeType> list1 = homeTypeService.getHomeType(detailSystem.getId(), acceptData.getPlatform(), acceptData.getVersion(), resourceList,
                 CacheUtil.getMD5Long(resourceList), -1, special != null ? special.getDataKey() : null);
         List<HomeType> list = new ArrayList<>();
         for (HomeType ht : list1)
@@ -281,6 +294,57 @@
         return type;
     }
 
+
+    // 棣栭〉绫诲瀷鑾峰彇
+    public void getHomeVideoList(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
+
+        // 20170914 涓�绾ц棰戝垎绫籌D
+        String homeTypeId = request.getParameter("Id");
+        int page = Integer.parseInt(request.getParameter("Page"));
+
+        if (StringUtil.isNullOrEmpty(homeTypeId)) {
+            out.print(JsonUtil.loadFalseJson(""));
+            return;
+        }
+
+        HomeType homeType = homeTypeService.getHomeTypeById(homeTypeId);
+        if (homeType == null) {
+            out.print(JsonUtil.loadFalseJson(""));
+            return;
+        }
+
+        List<Long> resourceList = videoResouceUtil.getAvailableResourceIds(acceptData.getDetailSystem(), acceptData.getVersion());
+        //鏌ヨ澶у浘
+        List<HomeVideo> bigPictureVideos = homeTypeService.getHomeVideoList(homeTypeId, resourceList, true, page, homeType.getNumber());
+
+
+        //澶у浘闇�瑕佹瘡娆¢兘杩斿洖
+
+        JSONObject object = new JSONObject();
+
+        Long count = homeTypeService.getHomeVideoListCount(homeTypeId, resourceList, null);
+        List<HomeVideo> list1 = homeTypeService.getHomeVideoList(homeTypeId, resourceList, false, page, homeType.getNumber());
+        List<HomeVideo> list = new ArrayList<>();
+        list.addAll(bigPictureVideos);
+        list.addAll(list1);
+        JSONObject data = new JSONObject();
+        data.put("count", count);
+        JSONArray array = new JSONArray();
+        for (int i = 0; i < list.size(); i++)
+            array.add(StringUtil.outPutResultJson(list.get(i)));
+        object.put("list", array);
+
+        //鍒ゆ柇鏄惁杩樻湁涓嬩竴椤�
+        int totalPage = (int) ((count - bigPictureVideos.size()) % homeType.getNumber() == 0 ? (count - bigPictureVideos.size()) / homeType.getNumber() : (count - bigPictureVideos.size()) / homeType.getNumber() + 1);
+
+        if (page >= totalPage) {
+            page = 0;
+        }
+        data.put("page", page);
+        out.print(JsonUtil.loadTrueJson(object.toString()));
+    }
+
+
     @RequireUid
     public void getMoreVideo(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
         String type = request.getParameter("Type");
@@ -347,9 +411,81 @@
         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();
+
+        if (VersionUtil.isGraterThan390(acceptData.getPlatform(), acceptData.getVersion())) {
+            out.print(JsonUtil.loadTrueJson(StringUtil.outPutResultJson(new VideoDetailVO(Utils.convertVideo(info), new VideoDetailVO.VideoAdInfo(true, false), null)), array.toString(),
+                    obj.toString()));
+        } else {
+            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");
@@ -453,29 +589,41 @@
             info.setCommentCount((int) count);
 
         JSONObject obj = new JSONObject();
+        VideoDetailVO.AttentionInfo attention = null;
         if (info.getVideoDetailList() != null)
             if (info.getVideoDetailList().size() > 1) {// 澶氶泦,鍙叧娉�
                 boolean isAttention = false;
                 if (!StringUtil.isNullOrEmpty(loginUid)) {
                     isAttention = attentionService.isAddAttention(loginUid, info.getId());
                 }
+                attention = new VideoDetailVO.AttentionInfo();
+                attention.setName(info.getName());
+                attention.setPicture(info.getPicture());
+                if (StringUtil.isNullOrEmpty(info.getUpdatetime())) {
+                    attention.setUpdateInfo("鏇存柊:" + TimeUtil.getCommentTime(info.getCreatetime()));
+                } else {
+                    attention.setUpdateInfo("鏇存柊:" + TimeUtil.getCommentTime(Long.parseLong(info.getUpdatetime())));
+                }
+                attention.setAttention(isAttention);
+
+                //鍏煎鑰佺増鏈�
                 JSONObject attentionInfo = new JSONObject();
-                attentionInfo.put("Name", info.getName());
-                attentionInfo.put("Picture", info.getPicture());
-                if (StringUtil.isNullOrEmpty(info.getUpdatetime()))
-                    attentionInfo.put("UpdateInfo", "鏇存柊:" + TimeUtil.getCommentTime(info.getCreatetime()));
-                else
-                    attentionInfo.put("UpdateInfo", "鏇存柊:" + TimeUtil.getCommentTime(Long.parseLong(info.getUpdatetime())));
-                attentionInfo.put("IsAttention", isAttention);
+                attentionInfo.put("Picture", attention.getPicture());
+                attentionInfo.put("Name", attention.getName());
+                attentionInfo.put("UpdateInfo", attention.getUpdateInfo());
+                attentionInfo.put("IsAttention", attention.isAttention());
                 obj.put("Attention", attentionInfo);
             }
         UserInfo user = userService.getUserInfo(acceptData.getUid());
-        if (Utils.isTest(request, user, detailSystem.getId()))
-            out.print(JsonUtil.loadTrueJson(""));
-        else
+        if (VersionUtil.isGraterThan390(acceptData.getPlatform(), acceptData.getVersion())) {
+            out.print(JsonUtil.loadTrueJson(StringUtil.outPutResultJson(new VideoDetailVO(Utils.convertVideo(info), new VideoDetailVO.VideoAdInfo(true, true), attention)), array.toString(),
+                    obj.toString()));
+        } else {
             out.print(JsonUtil.loadTrueJson(StringUtil.outPutResultJson(Utils.convertVideo(info)), array.toString(),
                     obj.toString()));
+        }
     }
+
 
     /**
      * 鑾峰彇瑙嗛鐨勫墽闆嗗垪琛�
@@ -532,6 +680,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(""));

--
Gitblit v1.8.0