| | |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.yeshi.buwan.service.inter.video.VideoInfoExtraService; |
| | | import org.hibernate.CacheMode; |
| | | import org.hibernate.HibernateException; |
| | | import org.hibernate.Session; |
| | |
| | | import com.yeshi.buwan.dao.VideoInfoDao; |
| | | import com.yeshi.buwan.dao.VideoTypeDao; |
| | | import com.yeshi.buwan.domain.CategoryVideo; |
| | | import com.yeshi.buwan.domain.DetailSystem; |
| | | import com.yeshi.buwan.domain.system.DetailSystem; |
| | | import com.yeshi.buwan.domain.SuperHotType; |
| | | import com.yeshi.buwan.domain.SuperVideoType; |
| | | import com.yeshi.buwan.domain.VideoInfo; |
| | |
| | | |
| | | @Service |
| | | public class ClassService { |
| | | @Resource |
| | | private VideoTypeDao videoTypeDao; |
| | | @Resource |
| | | private VideoInfoDao videoInfoDao; |
| | | @Resource |
| | | private SuperVideoTypeDao superVideoTypeDao; |
| | | @Resource |
| | | private VideoTypeDao videoTypeDao; |
| | | @Resource |
| | | private VideoInfoDao videoInfoDao; |
| | | @Resource |
| | | private SuperVideoTypeDao superVideoTypeDao; |
| | | |
| | | public List<VideoType> getTypeList() { |
| | | List<VideoType> list = videoTypeDao.list("from VideoType v where v.show='1' and v.parent=null"); |
| | | return list; |
| | | } |
| | | @Resource |
| | | private VideoInfoExtraService videoInfoExtraService; |
| | | |
| | | public VideoType getTypeById(String id) { |
| | | public List<VideoType> getTypeList() { |
| | | List<VideoType> list = videoTypeDao.list("from VideoType v where v.show='1' and v.parent=null"); |
| | | return list; |
| | | } |
| | | |
| | | return videoTypeDao.find(VideoType.class, id); |
| | | } |
| | | public VideoType getTypeById(String id) { |
| | | |
| | | public VideoType getTypeById(long id) { |
| | | return videoTypeDao.find(VideoType.class, id); |
| | | } |
| | | |
| | | return videoTypeDao.find(VideoType.class, id); |
| | | } |
| | | public VideoType getTypeById(long id) { |
| | | |
| | | @Cacheable(value = "classCache", key = "'getFirstTypeList'+'-'+#parentId") |
| | | public List<VideoType> getFirstTypeList(String parentId) { |
| | | if (StringUtil.isNullOrEmpty(parentId) || parentId.equalsIgnoreCase("0")) |
| | | return getTypeList(); |
| | | return videoTypeDao.find(VideoType.class, id); |
| | | } |
| | | |
| | | List<VideoType> list = videoTypeDao |
| | | .list("from VideoType v where v.show='1' and v.parent.id=" + parentId + " order by v.orderby desc"); |
| | | return list; |
| | | } |
| | | @Cacheable(value = "classCache", key = "'getFirstTypeList'+'-'+#parentId") |
| | | public List<VideoType> getFirstTypeList(String parentId) { |
| | | if (StringUtil.isNullOrEmpty(parentId) || parentId.equalsIgnoreCase("0")) |
| | | return getTypeList(); |
| | | |
| | | public List<VideoType> getAllTypeList() { |
| | | List<VideoType> list = videoTypeDao |
| | | .list("from VideoType v where v.show='1' and v.parent.id=" + parentId + " order by v.orderby desc"); |
| | | return list; |
| | | } |
| | | |
| | | List<VideoType> list = videoTypeDao.list("from VideoType v order by v.orderby desc"); |
| | | return list; |
| | | } |
| | | public List<VideoType> getAllTypeList() { |
| | | |
| | | public List<VideoType> getNextTypeList(String pid) { |
| | | List<VideoType> list = videoTypeDao.list("from VideoType v order by v.orderby desc"); |
| | | return list; |
| | | } |
| | | |
| | | if (StringUtil.isNullOrEmpty(pid)) { |
| | | List<VideoType> list = videoTypeDao |
| | | .list("from VideoType v where v.show='1' and v.parent=null order by v.orderby desc"); |
| | | return list; |
| | | } |
| | | if (Integer.parseInt(pid) > 0) { |
| | | List<VideoType> list = videoTypeDao.list( |
| | | (new StringBuilder("from VideoType v where v.show='1' and v.parent.id=")).append(pid).toString() |
| | | + " order by v.orderby desc"); |
| | | return list; |
| | | } else { |
| | | List<VideoType> list = videoTypeDao |
| | | .list("from VideoType v where v.show='1' and v.parent=null order by v.orderby desc"); |
| | | return list; |
| | | } |
| | | } |
| | | public List<VideoType> getNextTypeList(String pid) { |
| | | |
| | | @SuppressWarnings("unchecked") |
| | | public void deleteVideoType(final String id) { |
| | | videoTypeDao.excute(new HibernateCallback() { |
| | | public Object doInHibernate(Session session) throws HibernateException { |
| | | try { |
| | | session.getTransaction().begin(); |
| | | List<SuperVideoType> list = session.createQuery("from SuperVideoType sv where sv.type.id=?") |
| | | .setParameter(0, Long.parseLong(id)).list(); |
| | | for (SuperVideoType sv : list) |
| | | session.delete(sv); |
| | | session.delete(new VideoType(Long.parseLong(id))); |
| | | session.flush(); |
| | | session.getTransaction().commit(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | session.getTransaction().rollback(); |
| | | } |
| | | return null; |
| | | } |
| | | }); |
| | | if (StringUtil.isNullOrEmpty(pid)) { |
| | | List<VideoType> list = videoTypeDao |
| | | .list("from VideoType v where v.show='1' and v.parent=null order by v.orderby desc"); |
| | | return list; |
| | | } |
| | | if (Integer.parseInt(pid) > 0) { |
| | | List<VideoType> list = videoTypeDao.list( |
| | | (new StringBuilder("from VideoType v where v.show='1' and v.parent.id=")).append(pid).toString() |
| | | + " order by v.orderby desc"); |
| | | return list; |
| | | } else { |
| | | List<VideoType> list = videoTypeDao |
| | | .list("from VideoType v where v.show='1' and v.parent=null order by v.orderby desc"); |
| | | return list; |
| | | } |
| | | } |
| | | |
| | | } |
| | | @SuppressWarnings("unchecked") |
| | | public void deleteVideoType(final String id) { |
| | | videoTypeDao.excute(new HibernateCallback() { |
| | | public Object doInHibernate(Session session) throws HibernateException { |
| | | try { |
| | | session.getTransaction().begin(); |
| | | List<SuperVideoType> list = session.createQuery("from SuperVideoType sv where sv.type.id=?") |
| | | .setParameter(0, Long.parseLong(id)).list(); |
| | | for (SuperVideoType sv : list) |
| | | session.delete(sv); |
| | | session.delete(new VideoType(Long.parseLong(id))); |
| | | session.flush(); |
| | | session.getTransaction().commit(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | session.getTransaction().rollback(); |
| | | } |
| | | return null; |
| | | } |
| | | }); |
| | | |
| | | public VideoType getType(long id) { |
| | | } |
| | | |
| | | return videoTypeDao.find(VideoType.class, Long.valueOf(id)); |
| | | } |
| | | public VideoType getType(long id) { |
| | | |
| | | public void createType(VideoType type) { |
| | | return videoTypeDao.find(VideoType.class, Long.valueOf(id)); |
| | | } |
| | | |
| | | videoTypeDao.create(type); |
| | | } |
| | | public void createType(VideoType type) { |
| | | |
| | | public void updateType(VideoType type) { |
| | | videoTypeDao.create(type); |
| | | } |
| | | |
| | | videoTypeDao.update(type); |
| | | } |
| | | public void updateType(VideoType type) { |
| | | |
| | | public long getTypeVideoCount(String type) { |
| | | String wheres = ""; |
| | | String sts[] = getChildrenType(Integer.parseInt(type)); |
| | | String as[]; |
| | | int j = (as = sts).length; |
| | | for (int i = 0; i < j; i++) { |
| | | String st = as[i]; |
| | | wheres = (new StringBuilder(String.valueOf(wheres))).append("or h.videoType.id=").append(Long.parseLong(st)) |
| | | .append(" ").toString(); |
| | | } |
| | | videoTypeDao.update(type); |
| | | } |
| | | |
| | | if (wheres.startsWith("or")) |
| | | wheres = wheres.substring(2, wheres.length()); |
| | | long count = videoInfoDao |
| | | .getCount("select count(*) from CategoryVideo as h where h.video.show='1' and (h.videoType.id=" + type |
| | | + " or h.videoType.parent.id=" + type + ")"); |
| | | return count; |
| | | } |
| | | public long getTypeVideoCount(String type) { |
| | | String wheres = ""; |
| | | String sts[] = getChildrenType(Integer.parseInt(type)); |
| | | String as[]; |
| | | int j = (as = sts).length; |
| | | for (int i = 0; i < j; i++) { |
| | | String st = as[i]; |
| | | wheres = (new StringBuilder(String.valueOf(wheres))).append("or h.videoType.id=").append(Long.parseLong(st)) |
| | | .append(" ").toString(); |
| | | } |
| | | |
| | | @SuppressWarnings("unchecked") |
| | | public String[] getChildrenType(final int type) { |
| | | return (String[]) videoTypeDao.excute(new HibernateCallback<String[]>() { |
| | | public String[] doInHibernate(Session session) throws HibernateException { |
| | | String sts[] = new String[] {}; |
| | | try { |
| | | List<String> list = session.createSQLQuery( |
| | | (new StringBuilder("select queryChildrenType(")).append(type).append(")").toString()) |
| | | .list(); |
| | | sts = list.get(0).toString().substring(2, list.get(0).toString().length()).split(","); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | if (wheres.startsWith("or")) |
| | | wheres = wheres.substring(2, wheres.length()); |
| | | long count = videoInfoDao |
| | | .getCount("select count(*) from CategoryVideo as h where h.video.show='1' and (h.videoType.id=" + type |
| | | + " or h.videoType.parent.id=" + type + ")"); |
| | | return count; |
| | | } |
| | | |
| | | return sts; |
| | | } |
| | | }); |
| | | @SuppressWarnings("unchecked") |
| | | public String[] getChildrenType(final int type) { |
| | | return (String[]) videoTypeDao.excute(new HibernateCallback<String[]>() { |
| | | public String[] doInHibernate(Session session) throws HibernateException { |
| | | String sts[] = new String[]{}; |
| | | try { |
| | | List<String> list = session.createSQLQuery( |
| | | (new StringBuilder("select queryChildrenType(")).append(type).append(")").toString()) |
| | | .list(); |
| | | sts = list.get(0).toString().substring(2, list.get(0).toString().length()).split(","); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | return sts; |
| | | } |
| | | }); |
| | | |
| | | /** |
| | | * |
| | | * @param type |
| | | * @param page |
| | | * @param order |
| | | * 1-最近更新 2-最热 4-评论最多 |
| | | * @return |
| | | */ |
| | | public List<VideoInfo> getTypeVideoList(String type, int page, int order) { |
| | | String orderby = ""; |
| | | if (order == 1) { |
| | | orderby = " order by FROM_UNIXTIME(h.updatetime/1000) desc"; |
| | | } else if (order == 2) { |
| | | orderby = " order by h.latestWatchCount desc"; |
| | | } else if (order == 3) { |
| | | orderby = " order by h.commentCount desc"; |
| | | } |
| | | String wheres = ""; |
| | | if (StringUtil.isNullOrEmpty(type)) |
| | | return videoInfoDao.list("from VideoInfo as h where h.videoType.parent=null and h.show='1' ?", |
| | | (page - 1) * Constant.pageCount, Constant.pageCount, new String[] { orderby }); |
| | | String sts[] = getChildrenType(Integer.parseInt(type)); |
| | | String as[]; |
| | | int j = (as = sts).length; |
| | | for (int i = 0; i < j; i++) { |
| | | String st = as[i]; |
| | | wheres = (new StringBuilder(String.valueOf(wheres))).append("or h.videoType.id=").append(Long.parseLong(st)) |
| | | .append(" ").toString(); |
| | | } |
| | | } |
| | | |
| | | if (wheres.startsWith("or")) |
| | | wheres = wheres.substring(2, wheres.length()); |
| | | List<VideoInfo> list = videoInfoDao.list("from VideoInfo as h where h.show='1' and (" + wheres + ") " + orderby, |
| | | (page - 1) * Constant.pageCount, Constant.pageCount, new String[] {}); |
| | | return list; |
| | | } |
| | | /** |
| | | * @param type |
| | | * @param page |
| | | * @param order 1-最近更新 2-最热 4-评论最多 |
| | | * @return |
| | | */ |
| | | public List<VideoInfo> getTypeVideoList(String type, int page, int order) { |
| | | String orderby = ""; |
| | | if (order == 1) { |
| | | orderby = " order by FROM_UNIXTIME(h.updatetime/1000) desc"; |
| | | } else if (order == 2) { |
| | | orderby = " order by h.latestWatchCount desc"; |
| | | } else if (order == 3) { |
| | | orderby = " order by h.commentCount desc"; |
| | | } |
| | | String wheres = ""; |
| | | if (StringUtil.isNullOrEmpty(type)) |
| | | return videoInfoDao.list("from VideoInfo as h where h.videoType.parent=null and h.show='1' ?", |
| | | (page - 1) * Constant.pageCount, Constant.pageCount, new String[]{orderby}); |
| | | String sts[] = getChildrenType(Integer.parseInt(type)); |
| | | String as[]; |
| | | int j = (as = sts).length; |
| | | for (int i = 0; i < j; i++) { |
| | | String st = as[i]; |
| | | wheres = (new StringBuilder(String.valueOf(wheres))).append("or h.videoType.id=").append(Long.parseLong(st)) |
| | | .append(" ").toString(); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param type |
| | | * @param ds |
| | | * @param page |
| | | * @param order |
| | | * @param resourceList |
| | | * @return |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | @Cacheable(value = "longTimeCache", key = "'getTypeVideoList'+'-'+#type+'-'+#ds.id+'-'+#page+'-'+#pageCount+'-'+#order+'-'+#cachemd5") |
| | | public List<VideoInfo> getTypeVideoList(String type, DetailSystem ds, final int page, final int pageCount, |
| | | int order, List<Long> resourceList, String cachemd5) { |
| | | String resourceWhere = ""; |
| | | for (Long re : resourceList) { |
| | | resourceWhere += " rv.resourceid=" + re + " or"; |
| | | } |
| | | if (wheres.startsWith("or")) |
| | | wheres = wheres.substring(2, wheres.length()); |
| | | List<VideoInfo> list = videoInfoDao.list("from VideoInfo as h where h.show='1' and (" + wheres + ") " + orderby, |
| | | (page - 1) * Constant.pageCount, Constant.pageCount, new String[]{}); |
| | | return list; |
| | | } |
| | | |
| | | if (resourceWhere.endsWith("or")) |
| | | resourceWhere = resourceWhere.substring(0, resourceWhere.length() - 2); |
| | | /** |
| | | * @param type |
| | | * @param ds |
| | | * @param page |
| | | * @param order |
| | | * @param resourceList |
| | | * @return |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | @Cacheable(value = "longTimeCache", key = "'getTypeVideoList'+'-'+#type+'-'+#ds.id+'-'+#page+'-'+#pageCount+'-'+#order+'-'+#cachemd5") |
| | | public List<VideoInfo> getTypeVideoList(String type, DetailSystem ds, final int page, final int pageCount, |
| | | int order, List<Long> resourceList, String cachemd5) { |
| | | String resourceWhere = ""; |
| | | for (Long re : resourceList) { |
| | | resourceWhere += " rv.resourceid=" + re + " or"; |
| | | } |
| | | |
| | | String orderby = ""; |
| | | if (order == 1) { |
| | | orderby = " order by FROM_UNIXTIME(v.updatetime/1000) desc"; |
| | | } else if (order == 2) { |
| | | orderby = " order by v.watchcount desc"; |
| | | } else if (order == 3) { |
| | | orderby = " order by v.commentcount desc"; |
| | | } |
| | | if (resourceWhere.endsWith("or")) |
| | | resourceWhere = resourceWhere.substring(0, resourceWhere.length() - 2); |
| | | |
| | | String wheres = ""; |
| | | if (StringUtil.isNullOrEmpty(type)) { |
| | | return getVideoInfoData(videoInfoDao.sqlList( |
| | | "select v.id,v.`name`,v.`tag`,v.`picture`,v.`hpicture`,v.`latest_hpicture`,v.watchcount,v.commentcount from wk_video_video v INNER JOIN (SELECT DISTINCT(v.id) FROM wk_category_video ca LEFT JOIN wk_video_video v ON v.id= ca.videoid LEFT JOIN wk_resource_video rv ON rv.`videoid`= v.`id` AND( ? ) WHERE v.show= 1 and ca.id is not null AND rv.`resourceid` IS NOT NULL ? ) a using(id)", |
| | | (page - 1) * pageCount, pageCount, new Serializable[] { resourceWhere, orderby, })); |
| | | } |
| | | String orderby = ""; |
| | | if (order == 1) { |
| | | orderby = " order by FROM_UNIXTIME(v.updatetime/1000) desc"; |
| | | } else if (order == 2) { |
| | | orderby = " order by v.watchcount desc"; |
| | | } else if (order == 3) { |
| | | orderby = " order by v.commentcount desc"; |
| | | } |
| | | |
| | | List<VideoInfo> list = new ArrayList<VideoInfo>(); |
| | | String wheres = ""; |
| | | if (StringUtil.isNullOrEmpty(type)) { |
| | | return getVideoInfoData(videoInfoDao.sqlList( |
| | | "select v.id,v.`name`,v.`tag`,v.`picture`,v.`hpicture`,v.`latest_hpicture`,v.watchcount,v.commentcount from wk_video_video v INNER JOIN (SELECT DISTINCT(v.id) FROM wk_category_video ca LEFT JOIN wk_video_video v ON v.id= ca.videoid LEFT JOIN wk_resource_video rv ON rv.`videoid`= v.`id` AND( ? ) WHERE v.show= 1 and ca.id is not null AND rv.`resourceid` IS NOT NULL ? ) a using(id)", |
| | | (page - 1) * pageCount, pageCount, new Serializable[]{resourceWhere, orderby,}), resourceList); |
| | | } |
| | | |
| | | long startTime = System.currentTimeMillis(); |
| | | List<VideoInfo> list = new ArrayList<>(); |
| | | |
| | | final String typeNew = type; |
| | | final String resourceWhereNew = resourceWhere; |
| | | final String orderbyNew = orderby; |
| | | list = (List<VideoInfo>) videoTypeDao.excute(new HibernateCallback() { |
| | | public Object doInHibernate(Session session) throws HibernateException { |
| | | List<VideoInfo> list = new ArrayList<VideoInfo>(); |
| | | try { |
| | | session.setCacheMode(CacheMode.GET); |
| | | String sql = String.format( |
| | | "select v.id,v.`name`,v.`tag`,v.`picture`,v.`hpicture`,v.`latest_hpicture`,v.watchcount,v.commentcount from wk_video_video v INNER JOIN (SELECT DISTINCT(v.id) FROM wk_video_video v LEFT JOIN wk_category_video ca ON v.id=ca.videoid LEFT JOIN wk_video_type t ON t.`id`=ca.`videotypeid` AND (t.`id`=%s OR t.`pid`=%s) LEFT JOIN wk_resource_video rv ON rv.`videoid`=v.`id` AND (%s) WHERE v.show=1 AND ca.id>0 AND t.`id`>0 AND rv.`resourceid`>0 %s) a using(id)", |
| | | typeNew, typeNew, resourceWhereNew, orderbyNew); |
| | | System.out.println(sql); |
| | | long startTime = System.currentTimeMillis(); |
| | | |
| | | list = session.createSQLQuery(sql).setFirstResult((page - 1) * pageCount).setCacheable(true) |
| | | .setMaxResults(pageCount).list(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return list; |
| | | } |
| | | }); |
| | | final String typeNew = type; |
| | | final String resourceWhereNew = resourceWhere; |
| | | final String orderbyNew = orderby; |
| | | list = (List<VideoInfo>) videoTypeDao.excute(new HibernateCallback() { |
| | | public Object doInHibernate(Session session) throws HibernateException { |
| | | List<VideoInfo> list = new ArrayList<>(); |
| | | try { |
| | | session.setCacheMode(CacheMode.GET); |
| | | String sql = String.format( |
| | | "select v.id,v.`name`,v.`tag`,v.`picture`,v.`hpicture`,v.`latest_hpicture`,v.watchcount,v.commentcount from wk_video_video v INNER JOIN (SELECT DISTINCT(v.id) FROM wk_video_video v LEFT JOIN wk_category_video ca ON v.id=ca.videoid LEFT JOIN wk_video_type t ON t.`id`=ca.`videotypeid` AND (t.`id`=%s OR t.`pid`=%s) LEFT JOIN wk_resource_video rv ON rv.`videoid`=v.`id` AND (%s) WHERE v.show=1 AND ca.id>0 AND t.`id`>0 AND rv.`resourceid`>0 %s) a using(id)", |
| | | typeNew, typeNew, resourceWhereNew, orderbyNew); |
| | | System.out.println(sql); |
| | | |
| | | System.out.println("查询SQL费时:" + (System.currentTimeMillis() - startTime)); |
| | | return getVideoInfoData(list); |
| | | } |
| | | list = session.createSQLQuery(sql).setFirstResult((page - 1) * pageCount).setCacheable(true) |
| | | .setMaxResults(pageCount).list(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return list; |
| | | } |
| | | }); |
| | | |
| | | public List<VideoInfo> getVideoInfoData(List list) { |
| | | List<VideoInfo> dataList = new ArrayList<VideoInfo>(); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | Object[] obj = (Object[]) list.get(i); |
| | | VideoInfo info = new VideoInfo(); |
| | | info.setId(obj[0] + ""); |
| | | info.setName(obj[1] + ""); |
| | | info.setTag(obj[2] + ""); |
| | | info.setPicture(obj[3] + ""); |
| | | info.setHpicture(obj[4] + ""); |
| | | info.setLatestHpicture(obj[5] + ""); |
| | | info.setWatchCount(obj[6] + ""); |
| | | info.setCommentCount(Integer.parseInt(obj[7] + "")); |
| | | if (obj.length > 8) { |
| | | String[] resourceIds = (obj[8] + "").split(","); |
| | | List<VideoResource> resourceList = new ArrayList<VideoResource>(); |
| | | for (String rid : resourceIds) |
| | | resourceList.add(new VideoResource(rid)); |
| | | info.setResourceList(resourceList); |
| | | } |
| | | if(obj.length > 9){ |
| | | info.setVpicture(obj[9]+""); |
| | | } |
| | | dataList.add(info); |
| | | } |
| | | return dataList; |
| | | } |
| | | System.out.println("查询SQL费时:" + (System.currentTimeMillis() - startTime)); |
| | | return getVideoInfoData(list, resourceList); |
| | | } |
| | | |
| | | @SuppressWarnings("unchecked") |
| | | public List<VideoInfo> getTypeVideoList(String type, String startYear, String endYear, DetailSystem ds, |
| | | final int page, int order) { |
| | | String orderby = ""; |
| | | if (order == 1) { |
| | | orderby = " order by v.watchcount desc, v.updatetime desc"; |
| | | } else if (order == 2) { |
| | | // orderby = " order by v.updatetime desc,v.watchcount desc"; |
| | | // 豆豆系 |
| | | // if (ds.getPackageName().contains("doudou")) |
| | | orderby = " order by FROM_UNIXTIME(v.createtime/1000) desc"; |
| | | public List<VideoInfo> getVideoInfoData(List list, List<Long> resourceIdList) { |
| | | List<VideoInfo> dataList = new ArrayList<>(); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | Object[] obj = (Object[]) list.get(i); |
| | | VideoInfo info = new VideoInfo(); |
| | | info.setId(obj[0] + ""); |
| | | info.setName(obj[1] + ""); |
| | | info.setTag(obj[2] + ""); |
| | | info.setPicture(obj[3] + ""); |
| | | info.setHpicture(obj[4] + ""); |
| | | info.setLatestHpicture(obj[5] + ""); |
| | | info.setWatchCount(obj[6] + ""); |
| | | info.setCommentCount(obj[7]!=null? Integer.parseInt(obj[7] + ""):0); |
| | | if (obj.length > 8) { |
| | | String[] resourceIds = (obj[8] + "").split(","); |
| | | List<VideoResource> resourceList = new ArrayList<>(); |
| | | for (String rid : resourceIds) |
| | | resourceList.add(new VideoResource(rid)); |
| | | info.setResourceList(resourceList); |
| | | } |
| | | if (obj.length > 9) { |
| | | info.setVpicture(obj[9] + ""); |
| | | } |
| | | dataList.add(info); |
| | | } |
| | | |
| | | } else if (order == 3) { |
| | | orderby = " order by v.orderby desc,v.watchcount desc, v.updatetime desc"; |
| | | } else if (order == 4) { |
| | | orderby = " order by v.score desc,v.updatetime desc"; |
| | | } |
| | | dataList = videoInfoExtraService.batchExtra(dataList, resourceIdList); |
| | | |
| | | String yearWhere = ""; |
| | | if (!StringUtil.isNullOrEmpty(startYear) && !StringUtil.isNullOrEmpty(endYear)) { |
| | | yearWhere = " and (v.year>=" + startYear + " and v.year<=" + endYear + ") "; |
| | | } |
| | | return dataList; |
| | | } |
| | | |
| | | String wheres = ""; |
| | | if (StringUtil.isNullOrEmpty(type)) { |
| | | final String yearWhereNew = yearWhere; |
| | | final String orderbyNew = orderby; |
| | | return (List<VideoInfo>) videoTypeDao.excute(new HibernateCallback() { |
| | | public Object doInHibernate(Session session) throws HibernateException { |
| | | try { |
| | | return session |
| | | .createSQLQuery( |
| | | "SELECT v.* FROM wk_category_video ca left join wk_video_video v on v.id=ca.videoid where v.show=1 " |
| | | + yearWhereNew + " group by v.id ?") |
| | | .addEntity(VideoInfo.class).setParameter(0, orderbyNew) |
| | | .setFirstResult((page - 1) * Constant.pageCount).setMaxResults(Constant.pageCount) |
| | | .list(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | }); |
| | | @SuppressWarnings("unchecked") |
| | | public List<VideoInfo> getTypeVideoList(String type, String startYear, String endYear, DetailSystem ds, |
| | | final int page, int order) { |
| | | String orderby = ""; |
| | | if (order == 1) { |
| | | orderby = " order by v.watchcount desc, v.updatetime desc"; |
| | | } else if (order == 2) { |
| | | // orderby = " order by v.updatetime desc,v.watchcount desc"; |
| | | // 豆豆系 |
| | | // if (ds.getPackageName().contains("doudou")) |
| | | orderby = " order by FROM_UNIXTIME(v.createtime/1000) desc"; |
| | | |
| | | } |
| | | } else if (order == 3) { |
| | | orderby = " order by v.orderby desc,v.watchcount desc, v.updatetime desc"; |
| | | } else if (order == 4) { |
| | | orderby = " order by v.score desc,v.updatetime desc"; |
| | | } |
| | | |
| | | String sts[] = getChildrenType(Integer.parseInt(type)); |
| | | String as[]; |
| | | int j = (as = sts).length; |
| | | for (int i = 0; i < j; i++) { |
| | | String st = as[i]; |
| | | wheres = (new StringBuilder(String.valueOf(wheres))).append("or ca.videotypeid=").append(Long.parseLong(st)) |
| | | .append(" ").toString(); |
| | | } |
| | | String yearWhere = ""; |
| | | if (!StringUtil.isNullOrEmpty(startYear) && !StringUtil.isNullOrEmpty(endYear)) { |
| | | yearWhere = " and (v.year>=" + startYear + " and v.year<=" + endYear + ") "; |
| | | } |
| | | |
| | | if (wheres.startsWith("or")) |
| | | wheres = wheres.substring(2, wheres.length()); |
| | | List<VideoInfo> list = new ArrayList<VideoInfo>(); |
| | | String wheres = ""; |
| | | if (StringUtil.isNullOrEmpty(type)) { |
| | | final String yearWhereNew = yearWhere; |
| | | final String orderbyNew = orderby; |
| | | return (List<VideoInfo>) videoTypeDao.excute(new HibernateCallback() { |
| | | public Object doInHibernate(Session session) throws HibernateException { |
| | | try { |
| | | return session |
| | | .createSQLQuery( |
| | | "SELECT v.* FROM wk_category_video ca left join wk_video_video v on v.id=ca.videoid where v.show=1 " |
| | | + yearWhereNew + " group by v.id ?") |
| | | .addEntity(VideoInfo.class).setParameter(0, orderbyNew) |
| | | .setFirstResult((page - 1) * Constant.pageCount).setMaxResults(Constant.pageCount) |
| | | .list(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | }); |
| | | |
| | | final String wheresNew = wheres; |
| | | final String yearWhereNew = yearWhere; |
| | | final String orderbyNew = orderby; |
| | | list = (List<VideoInfo>) videoTypeDao.excute(new HibernateCallback<List<VideoInfo>>() { |
| | | public List<VideoInfo> doInHibernate(Session session) throws HibernateException { |
| | | List<VideoInfo> list = new ArrayList<VideoInfo>(); |
| | | try { |
| | | list = session |
| | | .createSQLQuery( |
| | | "select v.* from wk_category_video ca left join wk_video_video v on v.id=ca.videoid where v.show=1 and (" |
| | | + wheresNew + ") " + yearWhereNew + " group by v.id " + orderbyNew) |
| | | .addEntity(VideoInfo.class).setFirstResult((page - 1) * Constant.pageCount) |
| | | .setMaxResults(Constant.pageCount).list(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return list; |
| | | } |
| | | }); |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | String sts[] = getChildrenType(Integer.parseInt(type)); |
| | | String as[]; |
| | | int j = (as = sts).length; |
| | | for (int i = 0; i < j; i++) { |
| | | String st = as[i]; |
| | | wheres = (new StringBuilder(String.valueOf(wheres))).append("or ca.videotypeid=").append(Long.parseLong(st)) |
| | | .append(" ").toString(); |
| | | } |
| | | |
| | | private List<VideoInfo> parseVideoListAmin(List list) { |
| | | List<VideoInfo> resultList = new ArrayList<VideoInfo>(); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | Object[] objs = (Object[]) list.get(i); |
| | | VideoInfo video = new VideoInfo(); |
| | | video.setId(objs[0] + ""); |
| | | video.setName(objs[1] + ""); |
| | | video.setPicture(objs[2] + ""); |
| | | video.setLatestHpicture(objs[3] + ""); |
| | | video.setHpicture(objs[4] + ""); |
| | | video.setCreatetime(Long.parseLong(objs[5] + "")); |
| | | video.setShow(objs[6] + ""); |
| | | if (wheres.startsWith("or")) |
| | | wheres = wheres.substring(2, wheres.length()); |
| | | List<VideoInfo> list = new ArrayList<>(); |
| | | |
| | | final String wheresNew = wheres; |
| | | final String yearWhereNew = yearWhere; |
| | | final String orderbyNew = orderby; |
| | | list = (List<VideoInfo>) videoTypeDao.excute(new HibernateCallback<List<VideoInfo>>() { |
| | | public List<VideoInfo> doInHibernate(Session session) throws HibernateException { |
| | | List<VideoInfo> list = new ArrayList<>(); |
| | | try { |
| | | list = session |
| | | .createSQLQuery( |
| | | "select v.* from wk_category_video ca left join wk_video_video v on v.id=ca.videoid where v.show=1 and (" |
| | | + wheresNew + ") " + yearWhereNew + " group by v.id " + orderbyNew) |
| | | .addEntity(VideoInfo.class).setFirstResult((page - 1) * Constant.pageCount) |
| | | .setMaxResults(Constant.pageCount).list(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return list; |
| | | } |
| | | }); |
| | | |
| | | return list; |
| | | } |
| | | |
| | | private List<VideoInfo> parseVideoListAmin(List list) { |
| | | List<VideoInfo> resultList = new ArrayList<>(); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | Object[] objs = (Object[]) list.get(i); |
| | | VideoInfo video = new VideoInfo(); |
| | | video.setId(objs[0] + ""); |
| | | video.setName(objs[1] + ""); |
| | | video.setPicture(objs[2] + ""); |
| | | video.setLatestHpicture(objs[3] + ""); |
| | | video.setHpicture(objs[4] + ""); |
| | | video.setCreatetime(Long.parseLong(objs[5] + "")); |
| | | video.setShow(objs[6] + ""); |
| | | |
| | | boolean isEx = false; |
| | | for (VideoInfo info : resultList) { |
| | | if (info.getId().equalsIgnoreCase(video.getId())) { |
| | | isEx = true; |
| | | break; |
| | | } |
| | | } |
| | | if (!isEx) |
| | | resultList.add(video); |
| | | } |
| | | return resultList; |
| | | } |
| | | |
| | | public List<VideoInfo> getTypeVideoListAdmin(String type, int page, String key, int contenttype) { |
| | | String ctwhere = ""; |
| | | if (contenttype == 1) |
| | | ctwhere = " and v.`contenttype`=1 "; |
| | | else if (contenttype > 1) { |
| | | ctwhere = " and v.`contenttype`>1 "; |
| | | } |
| | | String sql = ""; |
| | | if (StringUtil.isNullOrEmpty(type)) |
| | | sql = String.format( |
| | | "SELECT v.`id`,v.name,v.`picture`,v.`latest_hpicture`,v.`hpicture`,v.`createtime`,v.`show` FROM wk_video_video v LEFT JOIN wk_category_video cv ON cv.`videoid`=v.`id` LEFT JOIN wk_video_type ty ON ty.`id`=cv.`videotypeid` WHERE v.`name` LIKE %s %s ORDER BY v.`createtime` DESC", |
| | | "'" + key + "%'", ctwhere); |
| | | else { |
| | | sql = String.format( |
| | | "SELECT v.`id`,v.name,v.`picture`,v.`latest_hpicture`,v.`hpicture`,v.`createtime`,v.`show` FROM wk_video_video v LEFT JOIN wk_category_video cv ON cv.`videoid`=v.`id` LEFT JOIN wk_video_type ty ON ty.`id`=cv.`videotypeid` WHERE (ty.`id`=%s OR ty.`pid`=%s) AND v.`name` LIKE %s %s ORDER BY v.`createtime` DESC", |
| | | type, type, "'" + key + "%'", ctwhere); |
| | | } |
| | | |
| | | boolean isEx = false; |
| | | for (VideoInfo info : resultList) { |
| | | if (info.getId().equalsIgnoreCase(video.getId())) { |
| | | isEx = true; |
| | | break; |
| | | } |
| | | } |
| | | if (!isEx) |
| | | resultList.add(video); |
| | | } |
| | | return resultList; |
| | | } |
| | | List result = videoInfoDao.sqlList(sql, (page - 1) * Constant.pageCount, Constant.pageCount, null); |
| | | |
| | | public List<VideoInfo> getTypeVideoListAdmin(String type, int page, String key, int contenttype) { |
| | | String ctwhere = ""; |
| | | if (contenttype == 1) |
| | | ctwhere = " and v.`contenttype`=1 "; |
| | | else if (contenttype > 1) { |
| | | ctwhere = " and v.`contenttype`>1 "; |
| | | } |
| | | String sql = ""; |
| | | if (StringUtil.isNullOrEmpty(type)) |
| | | sql = String.format( |
| | | "SELECT v.`id`,v.name,v.`picture`,v.`latest_hpicture`,v.`hpicture`,v.`createtime`,v.`show` FROM wk_video_video v LEFT JOIN wk_category_video cv ON cv.`videoid`=v.`id` LEFT JOIN wk_video_type ty ON ty.`id`=cv.`videotypeid` WHERE v.`name` LIKE %s %s ORDER BY v.`createtime` DESC", |
| | | "'" + key + "%'", ctwhere); |
| | | else { |
| | | sql = String.format( |
| | | "SELECT v.`id`,v.name,v.`picture`,v.`latest_hpicture`,v.`hpicture`,v.`createtime`,v.`show` FROM wk_video_video v LEFT JOIN wk_category_video cv ON cv.`videoid`=v.`id` LEFT JOIN wk_video_type ty ON ty.`id`=cv.`videotypeid` WHERE (ty.`id`=%s OR ty.`pid`=%s) AND v.`name` LIKE %s %s ORDER BY v.`createtime` DESC", |
| | | type, type, "'" + key + "%'", ctwhere); |
| | | } |
| | | List<VideoInfo> list = parseVideoListAmin(result); |
| | | return list; |
| | | } |
| | | |
| | | List result = videoInfoDao.sqlList(sql, (page - 1) * Constant.pageCount, Constant.pageCount, null); |
| | | public long getTypeVideoListAdminCount(String type, String key, int contenttype) { |
| | | |
| | | List<VideoInfo> list = parseVideoListAmin(result); |
| | | return list; |
| | | } |
| | | String wheres = ""; |
| | | String ctwhere = ""; |
| | | if (contenttype == 1) |
| | | ctwhere = " and v.`contenttype`=1 "; |
| | | else if (contenttype > 1) { |
| | | ctwhere = " and v.`contenttype`>1 "; |
| | | } |
| | | |
| | | public long getTypeVideoListAdminCount(String type, String key, int contenttype) { |
| | | String sql = ""; |
| | | if (StringUtil.isNullOrEmpty(type)) |
| | | sql = String.format( |
| | | "SELECT count(v.`id`) FROM wk_video_video v LEFT JOIN wk_category_video cv ON cv.`videoid`=v.`id` LEFT JOIN wk_video_type ty ON ty.`id`=cv.`videotypeid` WHERE v.`name` LIKE %s %s", |
| | | "'" + key + "%'", ctwhere); |
| | | else { |
| | | sql = String.format( |
| | | "SELECT count(v.`id`) FROM wk_video_video v LEFT JOIN wk_category_video cv ON cv.`videoid`=v.`id` LEFT JOIN wk_video_type ty ON ty.`id`=cv.`videotypeid` WHERE (ty.`id`=%s OR ty.`pid`=%s) AND v.`name` LIKE %s %s", |
| | | type, type, "'" + key + "%'", ctwhere); |
| | | } |
| | | |
| | | String wheres = ""; |
| | | String ctwhere = ""; |
| | | if (contenttype == 1) |
| | | ctwhere = " and v.`contenttype`=1 "; |
| | | else if (contenttype > 1) { |
| | | ctwhere = " and v.`contenttype`>1 "; |
| | | } |
| | | return videoInfoDao.getCountSQL(sql); |
| | | } |
| | | |
| | | String sql = ""; |
| | | if (StringUtil.isNullOrEmpty(type)) |
| | | sql = String.format( |
| | | "SELECT count(v.`id`) FROM wk_video_video v LEFT JOIN wk_category_video cv ON cv.`videoid`=v.`id` LEFT JOIN wk_video_type ty ON ty.`id`=cv.`videotypeid` WHERE v.`name` LIKE %s %s", |
| | | "'" + key + "%'", ctwhere); |
| | | else { |
| | | sql = String.format( |
| | | "SELECT count(v.`id`) FROM wk_video_video v LEFT JOIN wk_category_video cv ON cv.`videoid`=v.`id` LEFT JOIN wk_video_type ty ON ty.`id`=cv.`videotypeid` WHERE (ty.`id`=%s OR ty.`pid`=%s) AND v.`name` LIKE %s %s", |
| | | type, type, "'" + key + "%'", ctwhere); |
| | | } |
| | | public long getTypeVideoListAdminPage(String type, String key, int contenttype) { |
| | | long count = getTypeVideoListAdminCount(type, key, contenttype); |
| | | return count % (long) Constant.pageCount != 0L ? count / (long) Constant.pageCount + 1L |
| | | : count / (long) Constant.pageCount; |
| | | } |
| | | |
| | | return videoInfoDao.getCountSQL(sql); |
| | | } |
| | | public VideoType getRootVideoType(VideoType ty) { |
| | | |
| | | public long getTypeVideoListAdminPage(String type, String key, int contenttype) { |
| | | long count = getTypeVideoListAdminCount(type, key, contenttype); |
| | | return count % (long) Constant.pageCount != 0L ? count / (long) Constant.pageCount + 1L |
| | | : count / (long) Constant.pageCount; |
| | | } |
| | | ty = videoTypeDao.find(VideoType.class, ty.getId()); |
| | | while (ty.getParent() != null) |
| | | ty = ty.getParent(); |
| | | return ty; |
| | | } |
| | | |
| | | public VideoType getRootVideoType(VideoType ty) { |
| | | @SuppressWarnings("unchecked") |
| | | public void deleteHotTypeAdmin(final String hotTypeId) { |
| | | videoTypeDao.excute(new HibernateCallback() { |
| | | public Object doInHibernate(Session session) throws HibernateException { |
| | | try { |
| | | session.getTransaction().begin(); |
| | | List<SuperHotType> list = session.createQuery("from SuperHotType sh where sh.hotType.id=?") |
| | | .setParameter(0, hotTypeId).list(); |
| | | if (list != null && list.size() > 0) { |
| | | for (SuperHotType st : list) { |
| | | session.delete(st); |
| | | } |
| | | } |
| | | session.flush(); |
| | | session.getTransaction().commit(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | session.getTransaction().rollback(); |
| | | } |
| | | return null; |
| | | } |
| | | }); |
| | | |
| | | ty = videoTypeDao.find(VideoType.class, ty.getId()); |
| | | while (ty.getParent() != null) |
| | | ty = ty.getParent(); |
| | | return ty; |
| | | } |
| | | } |
| | | |
| | | @SuppressWarnings("unchecked") |
| | | public void deleteHotTypeAdmin(final String hotTypeId) { |
| | | videoTypeDao.excute(new HibernateCallback() { |
| | | public Object doInHibernate(Session session) throws HibernateException { |
| | | try { |
| | | session.getTransaction().begin(); |
| | | List<SuperHotType> list = session.createQuery("from SuperHotType sh where sh.hotType.id=?") |
| | | .setParameter(0, hotTypeId).list(); |
| | | if (list != null && list.size() > 0) { |
| | | for (SuperHotType st : list) { |
| | | session.delete(st); |
| | | } |
| | | } |
| | | session.flush(); |
| | | session.getTransaction().commit(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | session.getTransaction().rollback(); |
| | | } |
| | | return null; |
| | | } |
| | | }); |
| | | @SuppressWarnings("unchecked") |
| | | public void deleteVideoTypeAdmin(final String videoTypeId) { |
| | | videoTypeDao.excute(new HibernateCallback() { |
| | | public Object doInHibernate(Session session) throws HibernateException { |
| | | try { |
| | | List<SuperVideoType> list = session.createQuery("from SuperVideoType sh where sh.type.id=?") |
| | | .setParameter(0, videoTypeId).list(); |
| | | session.getTransaction().begin(); |
| | | if (list != null && list.size() > 0) { |
| | | for (SuperVideoType st : list) { |
| | | session.delete(st); |
| | | } |
| | | } |
| | | session.flush(); |
| | | session.getTransaction().commit(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | session.getTransaction().rollback(); |
| | | } |
| | | return null; |
| | | } |
| | | }); |
| | | |
| | | } |
| | | } |
| | | |
| | | @SuppressWarnings("unchecked") |
| | | public void deleteVideoTypeAdmin(final String videoTypeId) { |
| | | videoTypeDao.excute(new HibernateCallback() { |
| | | public Object doInHibernate(Session session) throws HibernateException { |
| | | try { |
| | | List<SuperVideoType> list = session.createQuery("from SuperVideoType sh where sh.type.id=?") |
| | | .setParameter(0, videoTypeId).list(); |
| | | session.getTransaction().begin(); |
| | | if (list != null && list.size() > 0) { |
| | | for (SuperVideoType st : list) { |
| | | session.delete(st); |
| | | } |
| | | } |
| | | session.flush(); |
| | | session.getTransaction().commit(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | session.getTransaction().rollback(); |
| | | } |
| | | return null; |
| | | } |
| | | }); |
| | | @SuppressWarnings("unchecked") |
| | | public void deleteVideoTypeAdmin(final String videtype, final String detailSystem) { |
| | | videoTypeDao.excute(new HibernateCallback() { |
| | | public Object doInHibernate(Session session) throws HibernateException { |
| | | try { |
| | | List<SuperVideoType> list = session |
| | | .createQuery("from SuperVideoType sh where sh.type.id=? and sh.detailSystem.id=?") |
| | | .setParameter(0, Long.parseLong(videtype)).setParameter(1, detailSystem).list(); |
| | | session.getTransaction().begin(); |
| | | if (list != null && list.size() > 0) { |
| | | for (SuperVideoType st : list) { |
| | | session.delete(st); |
| | | } |
| | | } |
| | | session.flush(); |
| | | session.getTransaction().commit(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | session.getTransaction().rollback(); |
| | | } |
| | | return null; |
| | | } |
| | | }); |
| | | |
| | | } |
| | | } |
| | | |
| | | @SuppressWarnings("unchecked") |
| | | public void deleteVideoTypeAdmin(final String videtype, final String detailSystem) { |
| | | videoTypeDao.excute(new HibernateCallback() { |
| | | public Object doInHibernate(Session session) throws HibernateException { |
| | | try { |
| | | List<SuperVideoType> list = session |
| | | .createQuery("from SuperVideoType sh where sh.type.id=? and sh.detailSystem.id=?") |
| | | .setParameter(0, Long.parseLong(videtype)).setParameter(1, detailSystem).list(); |
| | | session.getTransaction().begin(); |
| | | if (list != null && list.size() > 0) { |
| | | for (SuperVideoType st : list) { |
| | | session.delete(st); |
| | | } |
| | | } |
| | | session.flush(); |
| | | session.getTransaction().commit(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | session.getTransaction().rollback(); |
| | | } |
| | | return null; |
| | | } |
| | | }); |
| | | @SuppressWarnings("unchecked") |
| | | public void deleteHotTypeAdmin(final String hotTypeId, final String detailSystem) { |
| | | videoTypeDao.excute(new HibernateCallback() { |
| | | public Object doInHibernate(Session session) throws HibernateException { |
| | | try { |
| | | List<SuperHotType> list = session |
| | | .createQuery("from SuperHotType sh where sh.hotType.id=? and sh.detailSystem.id=?") |
| | | .setParameter(0, hotTypeId).setParameter(1, detailSystem).list(); |
| | | session.getTransaction().begin(); |
| | | if (list != null && list.size() > 0) { |
| | | for (SuperHotType st : list) { |
| | | session.delete(st); |
| | | } |
| | | } |
| | | session.flush(); |
| | | session.getTransaction().commit(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | session.getTransaction().rollback(); |
| | | } |
| | | return null; |
| | | } |
| | | }); |
| | | |
| | | } |
| | | } |
| | | |
| | | @SuppressWarnings("unchecked") |
| | | public void deleteHotTypeAdmin(final String hotTypeId, final String detailSystem) { |
| | | videoTypeDao.excute(new HibernateCallback() { |
| | | public Object doInHibernate(Session session) throws HibernateException { |
| | | try { |
| | | List<SuperHotType> list = session |
| | | .createQuery("from SuperHotType sh where sh.hotType.id=? and sh.detailSystem.id=?") |
| | | .setParameter(0, hotTypeId).setParameter(1, detailSystem).list(); |
| | | session.getTransaction().begin(); |
| | | if (list != null && list.size() > 0) { |
| | | for (SuperHotType st : list) { |
| | | session.delete(st); |
| | | } |
| | | } |
| | | session.flush(); |
| | | session.getTransaction().commit(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | session.getTransaction().rollback(); |
| | | } |
| | | return null; |
| | | } |
| | | }); |
| | | /** |
| | | * 首页大分类--后台编辑使用 |
| | | * |
| | | * @param detailSystem |
| | | * @param page |
| | | * @return |
| | | */ |
| | | |
| | | } |
| | | @SuppressWarnings("unchecked") |
| | | public List<com.yeshi.buwan.domain.web.VideoTypeAdmin> getVideoTypeAdmin(final String systemId, final int detailSystem, final int pid, |
| | | final int page) { |
| | | return (List<com.yeshi.buwan.domain.web.VideoTypeAdmin>) videoTypeDao |
| | | .excute(new HibernateCallback<List<com.yeshi.buwan.domain.web.VideoTypeAdmin>>() { |
| | | public List<com.yeshi.buwan.domain.web.VideoTypeAdmin> doInHibernate(Session session) |
| | | throws HibernateException { |
| | | List<com.yeshi.buwan.domain.web.VideoTypeAdmin> hotTypeList = new ArrayList<>(); |
| | | try { |
| | | List<DetailSystem> detailSystemList = session.createQuery("from DetailSystem ds where ds.system.id=" + systemId).list(); |
| | | String where = ""; |
| | | |
| | | /** |
| | | * 首页大分类--后台编辑使用 |
| | | * |
| | | * @param detailSystem |
| | | * @param page |
| | | * @return |
| | | */ |
| | | List<VideoType> list = null; |
| | | if (detailSystem > 0) { |
| | | where += " where vb.detailSystem.id= " + detailSystem; |
| | | |
| | | @SuppressWarnings("unchecked") |
| | | public List<com.yeshi.buwan.domain.web.VideoTypeAdmin> getVideoTypeAdmin(final int detailSystem, final int pid, |
| | | final int page) { |
| | | return (List<com.yeshi.buwan.domain.web.VideoTypeAdmin>) videoTypeDao |
| | | .excute(new HibernateCallback<List<com.yeshi.buwan.domain.web.VideoTypeAdmin>>() { |
| | | public List<com.yeshi.buwan.domain.web.VideoTypeAdmin> doInHibernate(Session session) |
| | | throws HibernateException { |
| | | List<com.yeshi.buwan.domain.web.VideoTypeAdmin> hotTypeList = new ArrayList<com.yeshi.buwan.domain.web.VideoTypeAdmin>(); |
| | | try { |
| | | List<DetailSystem> detailSystemList = session.createQuery("from DetailSystem").list(); |
| | | String where = ""; |
| | | if (pid > 0) |
| | | |
| | | List<VideoType> list = null; |
| | | if (detailSystem > 0) { |
| | | where += " where vb.detailSystem.id= " + detailSystem; |
| | | list = session |
| | | .createQuery("select vb.type from SuperVideoType vb " + where |
| | | + " and vb.type.parent!=null and vb.type.parent.id=" + pid |
| | | + " group by vb.type.id order by vb.createtime desc") |
| | | .setFirstResult((page - 1) * Constant.pageCount) |
| | | .setMaxResults(Constant.pageCount).list(); |
| | | else |
| | | list = session |
| | | .createQuery("select vb.type from SuperVideoType vb " + where |
| | | + " and vb.type.parent=null group by vb.type.id order by vb.createtime desc") |
| | | .setFirstResult((page - 1) * Constant.pageCount) |
| | | .setMaxResults(Constant.pageCount).list(); |
| | | } else { |
| | | if (pid > 0) |
| | | list = session |
| | | .createQuery("from VideoType vb where vb.parent!=null and vb.parent.id=" |
| | | + pid + " order by vb.createtime desc") |
| | | .setFirstResult((page - 1) * Constant.pageCount) |
| | | .setMaxResults(Constant.pageCount).list(); |
| | | else |
| | | list = session |
| | | .createQuery( |
| | | "from VideoType vb where vb.parent=null order by vb.createtime desc") |
| | | .setFirstResult((page - 1) * Constant.pageCount) |
| | | .setMaxResults(Constant.pageCount).list(); |
| | | } |
| | | for (VideoType vb : list) { |
| | | List<DetailSystem> detailSystemS = session |
| | | .createQuery("select vb.detailSystem from SuperVideoType vb where vb.type.id=?") |
| | | .setParameter(0, vb.getId()).list(); |
| | | |
| | | if (pid > 0) |
| | | List<DetailSystemSelect> dssList = new ArrayList<>(); |
| | | |
| | | list = session |
| | | .createQuery("select vb.type from SuperVideoType vb " + where |
| | | + " and vb.type.parent!=null and vb.type.parent.id=" + pid |
| | | + " group by vb.type.id order by vb.createtime desc") |
| | | .setFirstResult((page - 1) * Constant.pageCount) |
| | | .setMaxResults(Constant.pageCount).list(); |
| | | else |
| | | list = session |
| | | .createQuery("select vb.type from SuperVideoType vb " + where |
| | | + " and vb.type.parent=null group by vb.type.id order by vb.createtime desc") |
| | | .setFirstResult((page - 1) * Constant.pageCount) |
| | | .setMaxResults(Constant.pageCount).list(); |
| | | } else { |
| | | if (pid > 0) |
| | | list = session |
| | | .createQuery("from VideoType vb where vb.parent!=null and vb.parent.id=" |
| | | + pid + " order by vb.createtime desc") |
| | | .setFirstResult((page - 1) * Constant.pageCount) |
| | | .setMaxResults(Constant.pageCount).list(); |
| | | else |
| | | list = session |
| | | .createQuery( |
| | | "from VideoType vb where vb.parent=null order by vb.createtime desc") |
| | | .setFirstResult((page - 1) * Constant.pageCount) |
| | | .setMaxResults(Constant.pageCount).list(); |
| | | } |
| | | for (VideoType vb : list) { |
| | | List<DetailSystem> detailSystemS = session |
| | | .createQuery("select vb.detailSystem from SuperVideoType vb where vb.type.id=?") |
| | | .setParameter(0, vb.getId()).list(); |
| | | for (DetailSystem ds : detailSystemList) { |
| | | DetailSystemSelect dss = new DetailSystemSelect(); |
| | | dss.setDetailSystem(ds); |
| | | dss.setSelected(false); |
| | | dssList.add(dss); |
| | | } |
| | | |
| | | List<DetailSystemSelect> dssList = new ArrayList<DetailSystemSelect>(); |
| | | // 设置已经存在的 |
| | | for (DetailSystem ds : detailSystemS) { |
| | | |
| | | for (DetailSystem ds : detailSystemList) { |
| | | DetailSystemSelect dss = new DetailSystemSelect(); |
| | | dss.setDetailSystem(ds); |
| | | dss.setSelected(false); |
| | | dssList.add(dss); |
| | | } |
| | | for (DetailSystemSelect dss : dssList) { |
| | | if (dss.getDetailSystem().getId().equalsIgnoreCase(ds.getId())) { |
| | | dss.setSelected(true); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 设置已经存在的 |
| | | for (DetailSystem ds : detailSystemS) { |
| | | hotTypeList.add(new com.yeshi.buwan.domain.web.VideoTypeAdmin(vb, dssList)); |
| | | } |
| | | |
| | | for (DetailSystemSelect dss : dssList) { |
| | | if (dss.getDetailSystem().getId().equalsIgnoreCase(ds.getId())) { |
| | | dss.setSelected(true); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return hotTypeList; |
| | | } |
| | | }); |
| | | |
| | | hotTypeList.add(new com.yeshi.buwan.domain.web.VideoTypeAdmin(vb, dssList)); |
| | | } |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return hotTypeList; |
| | | } |
| | | }); |
| | | /** |
| | | * 获取热门分类数量 |
| | | * |
| | | * @param detailSystem |
| | | * @return |
| | | */ |
| | | public long getVideoTypeAdminCount(int detailSystem, int pid) { |
| | | |
| | | } |
| | | String where = ""; |
| | | if (detailSystem > 0) { |
| | | |
| | | /** |
| | | * 获取热门分类数量 |
| | | * |
| | | * @param detailSystem |
| | | * @return |
| | | */ |
| | | public long getVideoTypeAdminCount(int detailSystem, int pid) { |
| | | where += " where bv.detailsystem= " + detailSystem; |
| | | if (pid > 0) |
| | | return videoTypeDao.getCountSQL( |
| | | "select count(*) from (select count(*) from wk_video_super_class bv left join wk_video_type v on v.id=bv.classid " |
| | | + where + " and v.pid=" + pid + " group by bv.hottypeid) s"); |
| | | else |
| | | return videoTypeDao.getCountSQL( |
| | | "select count(*) from (select count(*) from wk_video_super_class bv left join wk_video_type v on v.id=bv.classid " |
| | | + where + " and v.pid IS NULL group by bv.hottypeid) s"); |
| | | } else { |
| | | if (pid > 0) |
| | | return videoTypeDao |
| | | .getCount("select count(*) from VideoType vt where vt.parent!=null and vt.parent.id=" + pid); |
| | | else |
| | | return videoTypeDao.getCount("select count(*) from VideoType vt where vt.parent=null"); |
| | | } |
| | | } |
| | | |
| | | String where = ""; |
| | | if (detailSystem > 0) { |
| | | public void updateVideoTypes(final String videoid, final List<VideoType> typeList) { |
| | | videoTypeDao.excute(new HibernateCallback() { |
| | | public Object doInHibernate(Session session) throws HibernateException { |
| | | try { |
| | | session.createQuery("delete from CategoryVideo cv where cv.video.id=?").setParameter(0, videoid) |
| | | .executeUpdate(); |
| | | session.getTransaction().begin(); |
| | | for (VideoType vt : typeList) { |
| | | CategoryVideo cv = new CategoryVideo(); |
| | | cv.setVideo(new VideoInfo(videoid)); |
| | | cv.setVideoType(vt); |
| | | session.persist(cv); |
| | | } |
| | | session.flush(); |
| | | session.getTransaction().commit(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | session.getTransaction().rollback(); |
| | | } |
| | | return null; |
| | | } |
| | | }); |
| | | |
| | | where += " where bv.detailsystem= " + detailSystem; |
| | | if (pid > 0) |
| | | return videoTypeDao.getCountSQL( |
| | | "select count(*) from (select count(*) from wk_video_super_class bv left join wk_video_type v on v.id=bv.classid " |
| | | + where + " and v.pid=" + pid + " group by bv.hottypeid) s"); |
| | | else |
| | | return videoTypeDao.getCountSQL( |
| | | "select count(*) from (select count(*) from wk_video_super_class bv left join wk_video_type v on v.id=bv.classid " |
| | | + where + " and v.pid IS NULL group by bv.hottypeid) s"); |
| | | } else { |
| | | if (pid > 0) |
| | | return videoTypeDao |
| | | .getCount("select count(*) from VideoType vt where vt.parent!=null and vt.parent.id=" + pid); |
| | | else |
| | | return videoTypeDao.getCount("select count(*) from VideoType vt where vt.parent=null"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void updateVideoTypes(final String videoid, final List<VideoType> typeList) { |
| | | videoTypeDao.excute(new HibernateCallback() { |
| | | public Object doInHibernate(Session session) throws HibernateException { |
| | | try { |
| | | session.createQuery("delete from CategoryVideo cv where cv.video.id=?").setParameter(0, videoid) |
| | | .executeUpdate(); |
| | | session.getTransaction().begin(); |
| | | for (VideoType vt : typeList) { |
| | | CategoryVideo cv = new CategoryVideo(); |
| | | cv.setVideo(new VideoInfo(videoid)); |
| | | cv.setVideoType(vt); |
| | | session.persist(cv); |
| | | } |
| | | session.flush(); |
| | | session.getTransaction().commit(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | session.getTransaction().rollback(); |
| | | } |
| | | return null; |
| | | } |
| | | }); |
| | | /** |
| | | * 获取某个视频的分类 |
| | | * |
| | | * @param vid |
| | | * @return |
| | | */ |
| | | @Cacheable(value = "homeCache", key = "'getVideoTypeList'+'-'+#vid") |
| | | public List<VideoType> getVideoTypeList(String vid) { |
| | | return videoTypeDao.list("select cv.videoType from CategoryVideo cv where cv.video.id=?", new String[]{vid}); |
| | | } |
| | | |
| | | } |
| | | /** |
| | | * 显示视频大分类区 |
| | | */ |
| | | |
| | | /** |
| | | * 获取某个视频的分类 |
| | | * |
| | | * @param vid |
| | | * @return |
| | | */ |
| | | @Cacheable(value = "homeCache", key = "'getVideoTypeList'+'-'+#vid") |
| | | public List<VideoType> getVideoTypeList(String vid) { |
| | | return videoTypeDao.list("select cv.videoType from CategoryVideo cv where cv.video.id=?", new String[] { vid }); |
| | | } |
| | | @Cacheable(value = "classCache", key = "'getSuperVideoTypeList'+'-'+#detailSystem") |
| | | public List<SuperVideoType> getSuperVideoTypeList(String detailSystem) { |
| | | return superVideoTypeDao.list( |
| | | "from SuperVideoType s where s.detailSystem.id=" + detailSystem + " order by s.type.orderby desc"); |
| | | } |
| | | |
| | | /** |
| | | * 显示视频大分类区 |
| | | */ |
| | | @Cacheable(value = "classCache", key = "'getSuperVideoTypeTitleList'+'-'+#detailSystem") |
| | | public List<SuperVideoType> getSuperVideoTypeTitleList(String detailSystem) { |
| | | return superVideoTypeDao.list( |
| | | "from SuperVideoType s where s.detailSystem.id=" + detailSystem + " and s.type.showTitle='1' order by s.type.orderby desc"); |
| | | } |
| | | |
| | | @Cacheable(value = "classCache", key = "'getSuperVideoTypeList'+'-'+#detailSystem") |
| | | public List<SuperVideoType> getSuperVideoTypeList(String detailSystem) { |
| | | return superVideoTypeDao.list( |
| | | "from SuperVideoType s where s.detailSystem.id=" + detailSystem + " order by s.type.orderby desc"); |
| | | } |
| | | |
| | | @Cacheable(value = "classCache", key = "'getSuperVideoTypeTitleList'+'-'+#detailSystem") |
| | | public List<SuperVideoType> getSuperVideoTypeTitleList(String detailSystem) { |
| | | return superVideoTypeDao.list( |
| | | "from SuperVideoType s where s.detailSystem.id=" + detailSystem + " and s.type.showTitle='1' order by s.type.orderby desc"); |
| | | } |
| | | |
| | | public void addSuperVideoType(SuperVideoType sv) { |
| | | List<SuperVideoType> list = superVideoTypeDao.list("from SuperVideoType sv where sv.type.id=" |
| | | + sv.getType().getId() + " and sv.detailSystem.id=" + sv.getDetailSystem().getId()); |
| | | if (list != null && list.size() > 0) |
| | | return; |
| | | superVideoTypeDao.create(sv); |
| | | } |
| | | public void addSuperVideoType(SuperVideoType sv) { |
| | | List<SuperVideoType> list = superVideoTypeDao.list("from SuperVideoType sv where sv.type.id=" |
| | | + sv.getType().getId() + " and sv.detailSystem.id=" + sv.getDetailSystem().getId()); |
| | | if (list != null && list.size() > 0) |
| | | return; |
| | | superVideoTypeDao.create(sv); |
| | | } |
| | | |
| | | @SuppressWarnings("unchecked") |
| | | public void updateSuperVideoTypeList(final String detailSystemId, final List<SuperVideoType> typeList) { |
| | | videoTypeDao.excute(new HibernateCallback() { |
| | | public Object doInHibernate(Session session) throws HibernateException { |
| | | try { |
| | | List<SuperVideoType> list = session |
| | | .createQuery("from SuperVideoType sh where sh.detailSystem.id=" + detailSystemId).list(); |
| | | for (SuperVideoType ad : list) { |
| | | session.delete(ad); |
| | | } |
| | | @SuppressWarnings("unchecked") |
| | | public void updateSuperVideoTypeList(final String detailSystemId, final List<SuperVideoType> typeList) { |
| | | videoTypeDao.excute(new HibernateCallback() { |
| | | public Object doInHibernate(Session session) throws HibernateException { |
| | | try { |
| | | List<SuperVideoType> list = session |
| | | .createQuery("from SuperVideoType sh where sh.detailSystem.id=" + detailSystemId).list(); |
| | | for (SuperVideoType ad : list) { |
| | | session.delete(ad); |
| | | } |
| | | |
| | | for (SuperVideoType videoType : typeList) { |
| | | session.persist(videoType); |
| | | } |
| | | for (SuperVideoType videoType : typeList) { |
| | | session.persist(videoType); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | }); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | }); |
| | | |
| | | } |
| | | } |
| | | |
| | | public void deleteSuperVideoType(SuperVideoType videoType) { |
| | | superVideoTypeDao.delete(videoType); |
| | | } |
| | | public void deleteSuperVideoType(SuperVideoType videoType) { |
| | | superVideoTypeDao.delete(videoType); |
| | | } |
| | | |
| | | public List<VideoType> getAllVideoType() { |
| | | return videoTypeDao.list("from VideoType vt where vt.parent = null"); |
| | | } |
| | | public List<VideoType> getAllVideoType() { |
| | | return videoTypeDao.list("from VideoType vt where vt.parent = null"); |
| | | } |
| | | |
| | | |
| | | } |