src/main/java/com/yeshi/buwan/controller/api/ApiControllerV2.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/yeshi/buwan/controller/parser/HomeParser.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/yeshi/buwan/controller/parser/UserParser.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/yeshi/buwan/controller/parser/web/WebHomeParser.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/yeshi/buwan/domain/HomeVideo.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/yeshi/buwan/domain/VideoInfo.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/yeshi/buwan/service/imp/HomeTypeService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/resources/domain/HomeType.hbm.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/resources/domain/HomeVideo.hbm.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/yeshi/buwan/controller/api/ApiControllerV2.java
@@ -170,6 +170,8 @@ break; case "getHomeType": homeParser.getHomeType(acceptData, request, out); case "getHomeVideoList": homeParser.getHomeVideoList(acceptData, request, out); break; case "getVideoDetail": homeParser.getVideoDetail(acceptData, request, out); src/main/java/com/yeshi/buwan/controller/parser/HomeParser.java
@@ -186,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) @@ -294,6 +294,57 @@ return type; } // 首页类型获取 public void getHomeVideoList(AcceptData acceptData, HttpServletRequest request, PrintWriter out) { // 20170914 一级视频分类ID 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"); src/main/java/com/yeshi/buwan/controller/parser/UserParser.java
@@ -431,14 +431,42 @@ vt.setId(0); vt.setName("全部"); typeList.add(vt); Set<Long> set = new HashSet<>(); for (VideoInfo videoInfo : list) { if (videoInfo.getShowType() == 1 && videoInfo.getVideoType() != null) List<Long> set = new ArrayList<>(); //将视频内容分类并排序 Map<Long, List<VideoInfo>> videoMap = new HashMap<>(); for (int i = 0; i < list.size(); i++) { VideoInfo videoInfo = list.get(i); if (videoInfo.getShowType() == 1 && videoInfo.getVideoType() != null) { if (videoMap.get(videoInfo.getVideoType().getId()) == null) videoMap.put(videoInfo.getVideoType().getId(), new ArrayList<>()); videoMap.get(videoInfo.getVideoType().getId()).add(videoInfo); if (!set.contains(videoInfo.getVideoType().getId())) set.add(videoInfo.getVideoType().getId()); if (VersionUtil.isGraterThan390(acceptData.getPlatform(), acceptData.getVersion()) && (StringUtil.isNullOrEmpty(type) || type.equalsIgnoreCase("0"))) { list.remove(i); i--; } } } for (Iterator<Long> its = set.iterator(); its.hasNext(); ) { Long typeId = its.next(); //重新组织数据 if (VersionUtil.isGraterThan390(acceptData.getPlatform(), acceptData.getVersion()) && (StringUtil.isNullOrEmpty(type) || type.equalsIgnoreCase("0"))) { List<VideoInfo> albumVideoList = new ArrayList<>(); for (int i = 0; i < set.size(); i++) { Long typeId = set.get(i); String typeName = VideoConstant.getMainCategoryName(typeId); if (!StringUtil.isNullOrEmpty(typeName)) { videoMap.get(typeId).get(0).setAlbumMoreInfo(new VideoInfo.VideoAlbumMoreInfo(typeName, i + 1)); albumVideoList.addAll(videoMap.get(typeId)); } } list.addAll(0, albumVideoList); } for (int i = 0; i < set.size(); i++) { Long typeId = set.get(i); String typeName = VideoConstant.getMainCategoryName(typeId); if (!StringUtil.isNullOrEmpty(typeName)) { vt = new VideoType(); @@ -448,6 +476,7 @@ } } vt = new VideoType(); vt.setId(Constant.SEARCH_RESULT_TYPE_HIGH_DEFINITION); vt.setName("高清"); src/main/java/com/yeshi/buwan/controller/parser/web/WebHomeParser.java
@@ -191,7 +191,7 @@ private JSONArray getHomeType(String uid, String platform, String detailsystemid) { List<Long> resourceList = videoResouceUtil.getAvailableResourceIds(new DetailSystem("44"), 1); List<HomeType> list1 = homeTypeService.getHomeType(detailsystemid, resourceList, List<HomeType> list1 = homeTypeService.getHomeType(detailsystemid, platform, 1, resourceList, CacheUtil.getMD5Long(resourceList), 10, "recommend"); List<HomeType> list = new ArrayList<>(); for (HomeType ht : list1) src/main/java/com/yeshi/buwan/domain/HomeVideo.java
@@ -11,7 +11,6 @@ * 首页分类下面的视频 * * @author Administrator * */ @Entity public class HomeVideo implements Serializable{ @@ -33,6 +32,16 @@ private String tag; @Expose private int orderby; @Expose private Boolean bigPicture;//是否为大图显示 public Boolean getBigPicture() { return bigPicture; } public void setBigPicture(Boolean bigPicture) { this.bigPicture = bigPicture; } public int getOrderby() { return orderby; src/main/java/com/yeshi/buwan/domain/VideoInfo.java
@@ -129,6 +129,11 @@ @Transient private int definition; //搜索结果适用 @Expose private VideoAlbumMoreInfo albumMoreInfo; @Transient private VideoResourceMapExtraInfo videoResourceMapExtraInfo; @@ -139,6 +144,14 @@ public void setVideoResourceMapExtraInfo(VideoResourceMapExtraInfo videoResourceMapExtraInfo) { this.videoResourceMapExtraInfo = videoResourceMapExtraInfo; } public VideoAlbumMoreInfo getAlbumMoreInfo() { return albumMoreInfo; } public void setAlbumMoreInfo(VideoAlbumMoreInfo albumMoreInfo) { this.albumMoreInfo = albumMoreInfo; } public Integer getVideocount() { @@ -552,4 +565,30 @@ public void setDefinition(int definition) { this.definition = definition; } public static class VideoAlbumMoreInfo { private String name; private int jumpPosition; public VideoAlbumMoreInfo(String name, int jumpPosition) { this.name = name; this.jumpPosition = jumpPosition; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getJumpPosition() { return jumpPosition; } public void setJumpPosition(int jumpPosition) { this.jumpPosition = jumpPosition; } } } src/main/java/com/yeshi/buwan/service/imp/HomeTypeService.java
@@ -10,6 +10,7 @@ import com.yeshi.buwan.domain.*; import com.yeshi.buwan.domain.system.DetailSystem; import com.yeshi.buwan.service.inter.video.VideoInfoExtraService; import com.yeshi.buwan.util.VersionUtil; import org.hibernate.HibernateException; import org.hibernate.Session; import org.springframework.cache.annotation.Cacheable; @@ -49,8 +50,8 @@ } @SuppressWarnings("unchecked") @Cacheable(value = "homeCache", key = "'getHomeType'+'-'+#detailSystem+'-'+#cacheMd5+'-'+#maxNumber+'-'+#dataKey") public List<HomeType> getHomeType(final String detailSystem, final List<Long> resourceIds, String cacheMd5, @Cacheable(value = "homeCache", key = "'getHomeType'+'-'+#detailSystem+'-'+#version+'-'+#cacheMd5+'-'+#maxNumber+'-'+#dataKey") public List<HomeType> getHomeType(final String detailSystem, final String platform, final int version, final List<Long> resourceIds, String cacheMd5, final int maxNumber, final String dataKey) { List<HomeType> homeTypeList = (List<HomeType>) homeTypeDao.excute(new HibernateCallback<List<HomeType>>() { public List<HomeType> doInHibernate(Session session) throws HibernateException { @@ -65,13 +66,14 @@ resourceWhere = resourceWhere.substring(0, resourceWhere.length() - 2); List resultList = session .createSQLQuery( "SELECT ht.`id` as htid,ht.`name` as htname,ht.`columns` as htcolumns ,ht.`hasmore`,ht.`activity` ,ht.`params` ,ht.`ioscontrol`,ht.number,hvideo.id as hvid,hvideo.`videoid` AS hvvideoid,hvideo.`picture`as hvpicture ,hvideo.`tag` as hvtag, v.`id` as vid ,v.`picture` as vpicture ,v.`name` as vname ,v.`tag` as vtag ,v.`hpicture` as vhpicture ,v.`latest_hpicture` as vlatest_hpicture ,v.`watchcount` as vwatchcount,v.commentcount,ht.icon as hicon,ht.orderby as htorder,hvideo.orderby as hvorder,need_ad FROM (SELECT hv.* FROM `wk_resource_video` rv LEFT JOIN `wk_video_homevideo` hv ON rv.`videoid` =hv.`videoid` LEFT JOIN `wk_video_video` v ON v.`id` =hv.`videoid` LEFT JOIN `wk_video_banquan_video` bv ON bv.`videoid`=hv.`videoid` AND bv.`detailsystemid`=" "SELECT ht.`id` as htid,ht.`name` as htname,ht.`columns` as htcolumns ,ht.`hasmore`,ht.`activity` ,ht.`params` ,ht.`ioscontrol`,ht.number,hvideo.id as hvid,hvideo.`videoid` AS hvvideoid,hvideo.`picture`as hvpicture ,hvideo.`tag` as hvtag, v.`id` as vid ,v.`picture` as vpicture ,v.`name` as vname ,v.`tag` as vtag ,v.`hpicture` as vhpicture ,v.`latest_hpicture` as vlatest_hpicture ,v.`watchcount` as vwatchcount,v.commentcount,ht.icon as hicon,ht.orderby as htorder,hvideo.orderby as hvorder,need_ad,big_picture FROM (SELECT hv.* FROM `wk_resource_video` rv LEFT JOIN `wk_video_homevideo` hv ON rv.`videoid` =hv.`videoid` LEFT JOIN `wk_video_video` v ON v.`id` =hv.`videoid` LEFT JOIN `wk_video_banquan_video` bv ON bv.`videoid`=hv.`videoid` AND bv.`detailsystemid`=" + detailSystem + " AND bv.`show`=1 LEFT JOIN `wk_video_hometype` ht ON ht.id=hv.hometype WHERE (hv.`id`>0 AND v.`show` =1 AND ht.special_data_key='" + dataKey + "' AND (" + resourceWhere + " ) AND bv.`videoid` IS NULL ) GROUP BY (hv.`id`) ORDER BY hv.`orderby` desc,v.createtime DESC ) hvideo LEFT JOIN `wk_video_super_hometype` sht ON sht.`hometypeid`=hvideo.hometype LEFT JOIN `wk_video_hometype` ht ON sht.`hometypeid` =ht.`id` LEFT JOIN wk_video_video v ON v.`id`=hvideo.videoid WHERE sht.`detailsystemid` =" + detailSystem + " ORDER BY hvideo.`orderby` DESC,v.orderby desc,v.updatetime desc") + " ) AND bv.`videoid` IS NULL ) GROUP BY (hv.`id`) ORDER BY hv.big_picture desc, hv.`orderby` desc,v.createtime DESC ) hvideo LEFT JOIN `wk_video_super_hometype` sht ON sht.`hometypeid`=hvideo.hometype LEFT JOIN `wk_video_hometype` ht ON sht.`hometypeid` =ht.`id` LEFT JOIN wk_video_video v ON v.`id`=hvideo.videoid WHERE sht.`detailsystemid` =" + detailSystem + " ORDER BY hvideo.`orderby` DESC,v.orderby desc,v.updatetime desc") .list(); List<HomeType> homeTypeList = new ArrayList<>(); Map<String, Integer> homeTypeVideoCountMap = new HashMap<>(); for (int i = 0; i < resultList.size(); i++) { Object[] obj = (Object[]) resultList.get(i); HomeType ht = new HomeType(); @@ -84,6 +86,7 @@ ht.setIosControl(obj[6] + ""); ht.setNumber(Integer.parseInt(obj[7] + "")); ht.setOrderby(obj[21] + ""); ht.setNeedAd(Boolean.parseBoolean(obj[23] + "")); @@ -91,6 +94,7 @@ hv.setId(obj[8] + ""); hv.setPicture(obj[10] + ""); hv.setTag(obj[11] + ""); hv.setBigPicture(Boolean.parseBoolean(obj[24] + "")); VideoInfo video = new VideoInfo(); video.setId(obj[12] + ""); @@ -132,10 +136,26 @@ if (maxNumber > -1)// 根据maxNumber的数量来,适用于网页 mn = maxNumber; if (VersionUtil.isGraterThan390(platform, version)) { //计算已有大图数量 int bigCount = 0; for (HomeVideo hv1 : eHomeType.getHomeVideoList()) { if (hv.getBigPicture()) { bigCount++; } } mn += bigCount; } if (homeTypeVideoCountMap.get(eHomeType.getId()) == null) { homeTypeVideoCountMap.put(eHomeType.getId(), 0); } homeTypeVideoCountMap.put(eHomeType.getId(), homeTypeVideoCountMap.get(eHomeType.getId()) + 1); if (eHomeType.getHomeVideoList().size() < mn)// 加入指定的数量的数据 { eHomeType.getHomeVideoList().add(hv); } } else { List<HomeVideo> videolist = new ArrayList<>(); @@ -152,6 +172,11 @@ // } orderByType(homeTypeList); for (HomeType ht : homeTypeList) { //设置数量 if (homeTypeVideoCountMap.containsKey(ht.getId())) ht.setCount(homeTypeVideoCountMap.get(ht.getId())); } return homeTypeList; } catch (Exception e) { e.printStackTrace(); @@ -315,7 +340,7 @@ public List<HomeVideo> getHomeVideoList(String homeId, int page) { return homeVideoDao.list( "from HomeVideo h where h.type.id=? order by h.video.orderby desc,h.video.watchCount desc,h.createtime desc", "from HomeVideo h where h.type.id=? order by h.video.orderby desc,h.createtime desc", (page - 1) * Constant.pageCount, Constant.pageCount, new String[]{homeId}); } @@ -325,6 +350,60 @@ (page - 1) * Constant.pageCount, Constant.pageCount, new String[]{homeId, "%" + key + "%"}); } public List<HomeVideo> getHomeVideoList(String homeId, List<Long> resourceIds, Boolean bigPicture, int page, int pageSize) { List<HomeVideo> homeVideos = (List<HomeVideo>) homeVideoDao.excute(new HibernateCallback<List<HomeVideo>>() { @Override public List<HomeVideo> doInHibernate(Session session) throws HibernateException { List<String> rids = new ArrayList<>(); for (Long rid : resourceIds) { rids.add("rv.`resourceid`=" + rid); } String sql = String.format("SELECT hv.* FROM wk_video_homevideo hv LEFT JOIN wk_resource_video rv ON rv.`videoid`=hv.`videoid` LEFT JOIN wk_video_video v ON v.`id`=hv.`videoid` WHERE v.show=1 and hv.`hometype`=%s AND (%s) ", homeId, org.yeshi.utils.StringUtil.concat(rids, " or ")); if (bigPicture != null) { sql += " and hv.big_picture=" + (bigPicture ? 1 : 0); } sql += "GROUP BY hv.id ORDER BY hv.big_picture desc,hv.`orderby` DESC,hv.`createtime` DESC"; return session.createSQLQuery(sql).addEntity(HomeVideo.class).setFirstResult((page - 1) * pageSize).setMaxResults(pageSize).list(); } }); List<VideoInfo> videoInfoList = new ArrayList<>(); for (HomeVideo hv : homeVideos) { if (hv.getVideo() != null) videoInfoList.add(hv.getVideo()); } videoInfoExtraService.batchExtra(videoInfoList, resourceIds); return homeVideos; } public long getHomeVideoListCount(String homeId, List<Long> resourceIds, Boolean bigPicture) { return (Long) homeVideoDao.excute(new HibernateCallback<Long>() { @Override public Long doInHibernate(Session session) throws HibernateException { List<String> rids = new ArrayList<>(); for (Long rid : resourceIds) { rids.add("rv.`resourceid`=" + rid); } String sql = String.format("SELECT count(distinct(hv.id)) FROM wk_video_homevideo hv LEFT JOIN wk_resource_video rv ON rv.`videoid`=hv.`videoid` LEFT JOIN wk_video_video v ON v.`id`=hv.`videoid` WHERE v.show=1 and hv.`hometype`=%s AND (%s)", homeId, org.yeshi.utils.StringUtil.concat(rids, " or ")); if (bigPicture != null) { sql += " and hv.big_picture=" + (bigPicture ? 1 : 0); } return Long.parseLong(session.createSQLQuery(sql).uniqueResult() + ""); } }); } public long getHomeVideoListCount(String homeId, String key) { return homeVideoDao.getCount("select count(*) from HomeVideo h where h.type.id=? and h.video.name like ? ", new String[]{homeId, "%" + key + "%"}); src/main/resources/domain/HomeType.hbm.xml
@@ -24,6 +24,8 @@ <many-to-one name="admin" column="adminid"></many-to-one> <property name="icon" type="string"></property> <property name="specialDataKey" type="string" column="special_data_key"></property> <property name="refreshPosition" type="int" column="refresh_position"></property> <property name="moreTag" type="string" column="more_tag"></property> <list name="homeVideoList" lazy="false" inverse="true" cascade="delete"> src/main/resources/domain/HomeVideo.hbm.xml
@@ -12,6 +12,11 @@ <property name="createtime" type="string"></property> <property name="orderby"></property> <property name="tag" type="string"></property> <property name="bigPicture" type="boolean" column="big_picture"></property> <many-to-one name="type" column="hometype" lazy="false" unique="true"></many-to-one> <many-to-one name="video" column="videoid" lazy="false"