| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | @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 { |
| | |
| | | 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,hvideo.big_picture,refresh_position,more_tag 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.`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.big_picture desc, 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(); |
| | |
| | | ht.setParams(obj[5] + ""); |
| | | ht.setIosControl(obj[6] + ""); |
| | | ht.setNumber(Integer.parseInt(obj[7] + "")); |
| | | ht.setRefreshPosition(Integer.parseInt(obj[25] + "")); |
| | | ht.setMoreTag(obj[26] + ""); |
| | | |
| | | |
| | | ht.setOrderby(obj[21] + ""); |
| | | ht.setNeedAd(Boolean.parseBoolean(obj[23] + "")); |
| | |
| | | hv.setId(obj[8] + ""); |
| | | hv.setPicture(obj[10] + ""); |
| | | hv.setTag(obj[11] + ""); |
| | | // hv.setBigPicture(Integer.parseInt(obj[24] + "") > 0); |
| | | |
| | | VideoInfo video = new VideoInfo(); |
| | | video.setId(obj[12] + ""); |
| | |
| | | if (maxNumber > -1)// 根据maxNumber的数量来,适用于网页 |
| | | mn = maxNumber; |
| | | |
| | | if (VersionUtil.isGraterThan390(platform, version)) { |
| | | //计算已有大图数量 |
| | | int bigCount = 0; |
| | | for (HomeVideo hv1 : eHomeType.getHomeVideoList()) { |
| | | if (hv1.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<>(); |
| | |
| | | // } |
| | | orderByType(homeTypeList); |
| | | |
| | | for (HomeType ht : homeTypeList) { |
| | | //设置数量 |
| | | if (homeTypeVideoCountMap.containsKey(ht.getId())) |
| | | ht.setCount(homeTypeVideoCountMap.get(ht.getId())); |
| | | } |
| | | return homeTypeList; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | return homeTypeList; |
| | | } |
| | | |
| | | @Cacheable(value = "homeCache", key = "'getHomeTypeList'+'-'+#detailSystem+'-'+#version+'-'+#dataKey+'-'+#page+'-'+#pageSize") |
| | | public List<HomeType> getHomeTypeList(String detailSystem, int version, String dataKey, int page, int pageSize) { |
| | | return homeTypeDao.list("select sht.homeType from SuperHomeType sht where sht.detailSystem.id=? and sht.homeType.specialDataKey=? order by sht.homeType.orderby DESC,sht.homeType.createtime DESC", (page - 1) * pageSize, pageSize, new Serializable[]{detailSystem, dataKey}); |
| | | } |
| | | |
| | | @Cacheable(value = "homeCache", key = "'countHomeType'+'-'+#detailSystem+'-'+#version+'-'+#dataKey") |
| | | public long countHomeType(String detailSystem, int version, String dataKey) { |
| | | return homeTypeDao.getCount("select count(*) from SuperHomeType sht where sht.detailSystem.id=? and sht.homeType.specialDataKey=?", new Serializable[]{detailSystem, dataKey}); |
| | | } |
| | | |
| | | |
| | | private void orderByType(List<HomeType> homeTypeList) { |
| | | Collections.sort(homeTypeList, new Comparator<HomeType>() { |
| | | public int compare(HomeType o1, HomeType o2) { |
| | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | private int index(List<HomeType> list, HomeType ht) { |
| | | if (list == null) |
| | |
| | | homeTypeDao.update(type); |
| | | } |
| | | |
| | | public void updateHomeVideo(HomeVideo type) { |
| | | |
| | | homeVideoDao.update(type); |
| | | } |
| | | |
| | | public List<DetailSystemSelect> getDetailSystemSelectByType(String homeType) { |
| | | List<DetailSystemSelect> li = new ArrayList<>(); |
| | | List<DetailSystem> list = detailSystemDao |
| | |
| | | return li; |
| | | } |
| | | |
| | | public void addHomeTypeVideo(HomeVideo video) { |
| | | |
| | | long count = homeVideoDao.getCount("select count(*) from HomeVideo h where h.type.id=? and h.video.id=?", |
| | | new String[]{video.getType().getId(), video.getVideo().getId()}); |
| | | if (count <= 0L) |
| | | homeVideoDao.create(video); |
| | | } |
| | | |
| | | public void addHomeTypeVideo(List<HomeVideo> list) { |
| | | HomeVideo info; |
| | | for (Iterator<HomeVideo> iterator = list.iterator(); iterator.hasNext(); addHomeTypeVideo(info)) |
| | | info = (HomeVideo) iterator.next(); |
| | | } |
| | | |
| | | public void deleteHomeVideo(HomeVideo video) { |
| | | |
| | | homeVideoDao.delete(video); |
| | | } |
| | | |
| | | public void deleteHomeTypeVideo(List<HomeVideo> list) { |
| | | HomeVideo video; |
| | | for (Iterator<HomeVideo> iterator = list.iterator(); iterator.hasNext(); deleteHomeVideo(video)) |
| | | video = (HomeVideo) iterator.next(); |
| | | } |
| | | |
| | | public long getHomeVideoCount(String homeId) { |
| | | |
| | | return homeVideoDao.getCount("from HomeVideo h where h.type.id=?", new String[]{homeId}); |
| | | } |
| | | |
| | | public long getHomeTypeVideoPage(String homeId) { |
| | | long count = getHomeVideoCount(homeId); |
| | | return count % (long) Constant.pageCount != 0L ? count / (long) Constant.pageCount + 1L |
| | | : count / (long) Constant.pageCount; |
| | | } |
| | | |
| | | 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", |
| | | (page - 1) * Constant.pageCount, Constant.pageCount, new String[]{homeId}); |
| | | } |
| | | |
| | | public List<HomeVideo> getHomeVideoList(String homeId, String key, int page) { |
| | | return homeVideoDao.list( |
| | | "from HomeVideo h where h.type.id=? and h.video.name like ? order by h.video.orderby desc,h.video.watchCount desc,h.createtime desc", |
| | | (page - 1) * Constant.pageCount, Constant.pageCount, new String[]{homeId, "%" + key + "%"}); |
| | | } |
| | | |
| | | 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 + "%"}); |
| | | } |
| | | |
| | | public Serializable addHomeType(HomeType type) { |
| | | return homeTypeDao.save(type); |
| | |
| | | andList.add("sh.homeType.name like ?"); |
| | | andList.add("sh.detailSystem.id=" + detailSystem); |
| | | if (dataKey != null) { |
| | | andList.add("sh.homeType.specialDataKey='" + dataKey+"'"); |
| | | andList.add("sh.homeType.specialDataKey='" + dataKey + "'"); |
| | | } |
| | | sql = "select sh.homeType from SuperHomeType sh where " + org.yeshi.utils.StringUtil.concat(andList, " and ") + " order by sh.homeType.orderby desc"; |
| | | } else { |
| | | andList.add("zb.name like ?"); |
| | | andList.add("zb.system.id=" + systemId); |
| | | if (dataKey != null) { |
| | | andList.add("zb.specialDataKey='" + dataKey+"'"); |
| | | andList.add("zb.specialDataKey='" + dataKey + "'"); |
| | | } |
| | | sql = "from HomeType zb where " + org.yeshi.utils.StringUtil.concat(andList, " and ") + " order by zb.orderby desc"; |
| | | } |
| | |
| | | andList.add("c.special_data_key='" + dataKey + "'"); |
| | | } |
| | | |
| | | sql = "select count(*) from (select count(*) from wk_video_super_hometype zb left join wk_video_hometype c on c.id=zb.hometypeid where " + org.yeshi.utils.StringUtil.concat(andList, " and ") + " group by zb.hometypeid) s"; |
| | | sql = "select count(*) from (select count(*) from wk_video_hometype c left join wk_video_super_hometype zb on c.id=zb.hometypeid where " + org.yeshi.utils.StringUtil.concat(andList, " and ") + " group by c.id) s"; |
| | | } |
| | | return homeTypeDao.getCountSQL(sql); |
| | | } |