From f7b2baec57a19039ca85880bbba4e17fe27f0511 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期三, 10 三月 2021 18:21:13 +0800 Subject: [PATCH] 删除冗余代码,初步优化首页的推荐专题,3.8.7之后在我的里面添加VIP分类 --- src/main/java/com/yeshi/buwan/controller/parser/HomeParser.java | 214 ++++++++++++++++++++++++++++++++++------------------- 1 files changed, 136 insertions(+), 78 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 2567b24..5e4d7ae 100644 --- a/src/main/java/com/yeshi/buwan/controller/parser/HomeParser.java +++ b/src/main/java/com/yeshi/buwan/controller/parser/HomeParser.java @@ -2,51 +2,32 @@ import java.io.IOException; import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; +import java.util.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import com.yeshi.buwan.domain.*; +import com.yeshi.buwan.domain.system.DetailSystemConfig; +import com.yeshi.buwan.domain.system.DetailSystem; +import com.yeshi.buwan.domain.video.VideoWatchHistory; +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.PPTVService; +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.log.VideoLogFactory; import com.yeshi.buwan.vo.AcceptData; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.methods.GetMethod; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; -import com.yeshi.buwan.domain.Config; -import com.yeshi.buwan.domain.DetailSystem; -import com.yeshi.buwan.domain.HomeAd; -import com.yeshi.buwan.domain.HomeType; -import com.yeshi.buwan.domain.HomeVideo; -import com.yeshi.buwan.domain.RecommendAd; -import com.yeshi.buwan.domain.UserInfo; -import com.yeshi.buwan.domain.VideoDetailInfo; -import com.yeshi.buwan.domain.VideoInfo; -import com.yeshi.buwan.domain.VideoType; import com.yeshi.buwan.domain.entity.PlayUrl; -import com.yeshi.buwan.service.imp.AdService; -import com.yeshi.buwan.service.imp.AttentionService; -import com.yeshi.buwan.service.imp.ClassService; -import com.yeshi.buwan.service.imp.CollectionService; -import com.yeshi.buwan.service.imp.CommentService; -import com.yeshi.buwan.service.imp.ConfigService; -import com.yeshi.buwan.service.imp.HomeAdService; -import com.yeshi.buwan.service.imp.HomeTypeService; -import com.yeshi.buwan.service.imp.StatisticsService; -import com.yeshi.buwan.service.imp.SystemService; -import com.yeshi.buwan.service.imp.UserService; -import com.yeshi.buwan.service.imp.VideoManager; -import com.yeshi.buwan.util.CacheUtil; -import com.yeshi.buwan.util.Constant; -import com.yeshi.buwan.util.JsonUtil; -import com.yeshi.buwan.util.JuheVideoUtil; -import com.yeshi.buwan.util.StringUtil; -import com.yeshi.buwan.util.TimeUtil; -import com.yeshi.buwan.util.Utils; -import com.yeshi.buwan.util.VideoPictureUtil; import com.yeshi.buwan.util.JuHe.VideoResourceUtil; import com.yeshi.buwan.util.video.VideoDetailUtil; import com.yeshi.buwan.util.zhibo.MeiNvZhiBoUtil; @@ -63,7 +44,7 @@ @Resource private HomeTypeService homeTypeService; @Resource - private ConfigService configService; + private DetailSystemConfigService configService; @Resource private AdService adService; @Resource @@ -86,6 +67,20 @@ @Resource private ClassParser classParser; + @Resource + private VideoDetailUtil videoDetailUtil; + + @Resource + private ResourceVideoService resourceVideoService; + + @Resource + private PPTVService pptvService; + + @Resource + private VideoWatchHistoryService videoWatchHistoryService; + + private final Logger playLogger = LoggerFactory.getLogger("videoPlay"); + @RequireUid public void getHomeAd(AcceptData acceptData, HttpServletRequest request, PrintWriter out) { String vtid = request.getParameter("Vtid"); @@ -95,28 +90,6 @@ DetailSystem detailSystem = systemService.getDetailSystemByPackage(acceptData.getPackageName()); List<HomeAd> list = homeAdService.getHomeAdList(detailSystem); - - // 娴嬭瘯璺宠浆灏忕▼搴� - // JSONObject xcx = new JSONObject(); - // xcx.put("thumb", - // "http://img.zcool.cn/community/0169235af03daea801206aba8664d7.jpeg@260w_195h_1c_1e_1o_100sh.jpg"); - // xcx.put("title", "娴嬭瘯鏍囬"); - // xcx.put("desc", "绠�浠�"); - // xcx.put("path", "pages/index/index"); - // xcx.put("username", "gh_33b9bea57aff"); - // xcx.put("url", "http://video.yeshitv.com"); - - // 娴嬭瘯鏍囬 - // HomeAd homeAd = new HomeAd(); - // homeAd.setClazz("com"); - // homeAd.setLinkType(5); - // homeAd.setOrderby(0); - // homeAd.setPicture( - // "http://img.zcool.cn/community/0169235af03daea801206aba8664d7.jpeg@260w_195h_1c_1e_1o_100sh.jpg"); - // homeAd.setVideo(new VideoInfo(1 + "")); - // homeAd.setParams(xcx.toString()); - // homeAd.setTitle("鏍囬"); - // list.add(homeAd); if (acceptData.getPlatform().equalsIgnoreCase("ios"))// IOS娴嬭瘯 { @@ -172,7 +145,6 @@ } else { classParser.getRecommendCategoryVideoBanner(acceptData, request, out); } - } // 棣栭〉绫诲瀷鑾峰彇 @@ -187,10 +159,11 @@ if (StringUtil.isNullOrEmpty(vtid)) { vtid = "309"; // 涓轰簡鍏煎浠ュ墠鐨勬帹鑽� } + DetailSystem detailSystem = systemService.getDetailSystemByPackage(acceptData.getPackageName()); JSONObject object = new JSONObject(); - List<Long> resourceList = videoResouceUtil.getAvailableResourceIds(acceptData.getPlatform(), acceptData.getVersion()); + List<Long> resourceList = videoResouceUtil.getAvailableResourceIds(acceptData.getDetailSystem(), acceptData.getVersion()); List<HomeType> list1 = homeTypeService.getHomeType(detailSystem.getId(), resourceList, CacheUtil.getMD5Long(resourceList), -1, Long.parseLong(vtid)); List<HomeType> list = new ArrayList<>(); @@ -356,6 +329,8 @@ String resourceId = request.getParameter("ResourceId"); String thirdType = request.getParameter("Type"); String loginUid = request.getParameter("LoginUid"); + String position = request.getParameter("Position"); + String from = request.getParameter("From"); if (StringUtil.isNullOrEmpty(videoId)) { out.print(JsonUtil.loadFalseJson("璇蜂笂浼燰ideoId")); @@ -366,10 +341,68 @@ return; } - List<Long> resourceList = videoResouceUtil.getAvailableResourceIds(acceptData.getPlatform(), acceptData.getVersion()); + DetailSystem detailSystem = systemService.getDetailSystemByPackage(acceptData.getPackageName()); - VideoInfo info = (videoDeailUtil.getVideoInfo(videoId, resourceId, resourceList, - CacheUtil.getMD5Long(resourceList))); + List<Long> resourceList = videoResouceUtil.getAvailableResourceIds(acceptData.getDetailSystem(), acceptData.getVersion()); + + //鑾峰彇浼樺厛灞曠ず鐨勬笭閬� + if (StringUtil.isNullOrEmpty(resourceId)) { + Set<Long> rids = new HashSet<>(); + rids.addAll(resourceList); + VideoResource defaultVideoResource = resourceVideoService.getDefaultVideoResource(videoId, rids); + if (defaultVideoResource != null) { + resourceId = defaultVideoResource.getId(); + } + } + + ThreadUtil.run(new Runnable() { + @Override + public void run() { + int p = 0; + if (!StringUtil.isNullOrEmpty(position)) { + p = Integer.parseInt(position); + } + + VideoWatchHistory history = new VideoWatchHistory(); + history.setDevice(acceptData.getDevice()); + history.setVideoId(videoId); + history.setUid(loginUid); + history.setPosition(p); + videoWatchHistoryService.add(history); + } + }); + + playLogger.info(VideoLogFactory.createUserVideoDetailLog(acceptData.getDevice(), loginUid, acceptData.getDetailSystem().getId(), videoId, resourceId, from)); + + + //PPTV缃戦〉鎾斁 + if (resourceId != null && Integer.parseInt(resourceId) == PPTVUtil.RESOURCE_ID) { + JSONObject data = new JSONObject(); + PPTVSeries series = pptvService.getSeriesDetailByVideoId(videoId); + int p = 0; + if (!StringUtil.isNullOrEmpty(position)) { + p = Integer.parseInt(position); + } else { + //鍙栨挱鏀捐褰� + VideoWatchHistory history = videoWatchHistoryService.getWatchHistory(acceptData.getDevice(), videoId); + if (history != null && history.getPosition() != null) { + p = history.getPosition(); + } + } + + p = p >= series.getSeries().size() ? 0 : p; + + String playUrl = PPTVUtil.getPlayUrl(series, series.getSeries().get(p)); + data.put("videoId", videoId); + data.put("playUrl", playUrl); + data.put("pptv", true); + out.print(JsonUtil.loadTrueJson(data.toString())); + return; + } + + + VideoInfo info = videoDeailUtil.getVideoInfo(detailSystem.getId(), videoId, resourceId, resourceList, + CacheUtil.getMD5Long(resourceList)); List<VideoType> typeList = classService.getVideoTypeList(info.getId()); if (typeList != null && typeList.size() > 0) { @@ -386,23 +419,8 @@ if (StringUtil.isNullOrEmpty(vd.getExtraId())) vd.setExtraId(vd.getId() + ""); } - System.out.println(info.getPlayPicture()); - // info.setPicture(VideoPictureUtil.getShowPicture(info, platform, - // version)); - - // 杩囨护鐗堟潈瑙嗛鍏抽敭瀛� - DetailSystem detailSystem = systemService.getDetailSystemByPackage(acceptData.getPackageName()); - // 缁熻娣诲姞 - // statisticsService.addStatistics(detailSystem.getId(), videoId); JSONArray array = new JSONArray(); - array.add("http://cloud.letv.com"); - if ((acceptData.getPlatform().equalsIgnoreCase("android") - && acceptData.getVersion() > 12) || acceptData.getPlatform().equalsIgnoreCase("ios")) { - for (String st : Constant.POJIE_LIST) - array.add(st); - } - long count = commentService.getComment2ListCount(videoId, thirdType); if (info != null) info.setCommentCount((int) count); @@ -431,6 +449,46 @@ out.print(JsonUtil.loadTrueJson(StringUtil.outPutResultJson(Utils.convertVideo(info)), array.toString(), obj.toString())); } + + /** + * 鑾峰彇瑙嗛鐨勫墽闆嗗垪琛� + * + * @param acceptData + * @param request + * @param out + */ + @RequireUid + public void getVideoEpisodeList(AcceptData acceptData, HttpServletRequest request, PrintWriter out) { + String videoId = request.getParameter("VideoId"); + String resourceId = request.getParameter("ResourceId"); + String page = request.getParameter("Page");//椤电爜 + + if (StringUtil.isNullOrEmpty(videoId)) { + out.print(JsonUtil.loadFalseJson("璇蜂笂浼燰ideoId")); + return; + } + if (StringUtil.isNullOrEmpty(resourceId)) { + out.print(JsonUtil.loadFalseJson("璇蜂笂浼燫esourceId")); + return; + } + + if (StringUtil.isNullOrEmpty(page)) { + out.print(JsonUtil.loadFalseJson("璇蜂笂浼燩age")); + return; + } + + + List<VideoDetailInfo> list = videoDetailUtil.getVideoDetailList(videoId, new VideoResource(resourceId), Integer.parseInt(page), 100); + if (list == null) + list = new ArrayList<>(); + JSONObject data = new JSONObject(); + String listStr = StringUtil.outPutResultJson(list); + boolean hasMore = list != null && list.size() > 0; + data.put("list", listStr); + data.put("hasMore", hasMore); + out.print(JsonUtil.loadTrueJson(data.toString())); + } + @RequireUid public void getNewVideoDetail(AcceptData acceptData, HttpServletRequest request, PrintWriter out) { @@ -481,7 +539,7 @@ DetailSystem detailSystem = systemService.getDetailSystemByPackage(acceptData.getPackageName()); - PlayUrl pu = videoDeailUtil.getPlayUrl(detailSystem.getId(), id, type, Integer.parseInt(resourceId), videoId); + PlayUrl pu = videoDeailUtil.getPlayUrl(acceptData, detailSystem.getId(), id, type, Integer.parseInt(resourceId), videoId); if (pu != null) { if (!StringUtil.isNullOrEmpty(pu.getUrl())) @@ -535,7 +593,7 @@ public void isPraise(AcceptData acceptData, HttpServletRequest request, PrintWriter out) { DetailSystem detailSystem = systemService.getDetailSystemByPackage(acceptData.getPackageName()); - Config config = configService.getConfigByKey("banner_praise", detailSystem, acceptData.getVersion()); + DetailSystemConfig config = configService.getConfigByKey("banner_praise", detailSystem, acceptData.getVersion()); if ("鏄�".equals(config.getValue())) { out.print(JsonUtil.loadTrueJson("1")); } else { -- Gitblit v1.8.0