package com.newvideo.service.imp;
|
|
import java.io.Serializable;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import javax.annotation.Resource;
|
|
import org.hibernate.CacheMode;
|
import org.hibernate.HibernateException;
|
import org.hibernate.Session;
|
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.orm.hibernate4.HibernateCallback;
|
import org.springframework.stereotype.Service;
|
|
import com.newvideo.dao.SuperVideoTypeDao;
|
import com.newvideo.dao.VideoInfoDao;
|
import com.newvideo.dao.VideoTypeDao;
|
import com.newvideo.domain.CategoryVideo;
|
import com.newvideo.domain.DetailSystem;
|
import com.newvideo.domain.SuperHotType;
|
import com.newvideo.domain.SuperVideoType;
|
import com.newvideo.domain.VideoInfo;
|
import com.newvideo.domain.VideoResource;
|
import com.newvideo.domain.VideoType;
|
import com.newvideo.domain.web.DetailSystemSelect;
|
import com.newvideo.util.Constant;
|
import com.newvideo.util.StringUtil;
|
|
@Service
|
public class ClassService {
|
@Resource
|
private VideoTypeDao videoTypeDao;
|
@Resource
|
private VideoInfoDao videoInfoDao;
|
@Resource
|
private SuperVideoTypeDao superVideoTypeDao;
|
|
public SuperVideoTypeDao getSuperVideoTypeDao() {
|
return superVideoTypeDao;
|
}
|
|
public void setSuperVideoTypeDao(SuperVideoTypeDao superVideoTypeDao) {
|
this.superVideoTypeDao = superVideoTypeDao;
|
}
|
|
public VideoInfoDao getVideoInfoDao() {
|
return videoInfoDao;
|
}
|
|
public void setVideoInfoDao(VideoInfoDao videoInfoDao) {
|
this.videoInfoDao = videoInfoDao;
|
}
|
|
public VideoTypeDao getVideoTypeDao() {
|
return videoTypeDao;
|
}
|
|
public void setVideoTypeDao(VideoTypeDao videoTypeDao) {
|
this.videoTypeDao = videoTypeDao;
|
}
|
|
public ClassService() {
|
|
}
|
|
public List<VideoType> getTypeList() {
|
List<VideoType> list = videoTypeDao.list("from VideoType v where v.show='1' and v.parent=null");
|
VideoType type = new VideoType(0);
|
type.setName("全部");
|
type.setShow("1");
|
list.add(0, type);
|
return list;
|
}
|
|
public VideoType getTypeById(String id) {
|
|
return videoTypeDao.find(VideoType.class, id);
|
}
|
|
public VideoType getTypeById(long id) {
|
|
return videoTypeDao.find(VideoType.class, id);
|
}
|
|
@Cacheable(value = "classCache", key = "'getFirstTypeList'+'-'+#parentId")
|
public List<VideoType> getFirstTypeList(String parentId) {
|
if (StringUtil.isNullOrEmpty(parentId) || parentId.equalsIgnoreCase("0"))
|
return getTypeList();
|
|
List<VideoType> list = videoTypeDao
|
.list("from VideoType v where v.show='1' and v.parent.id=" + parentId + " order by v.orderby desc");
|
VideoType type = new VideoType(Integer.parseInt(parentId));
|
type.setName("全部");
|
type.setShow("1");
|
list.add(0, type);
|
return list;
|
}
|
|
public List<VideoType> getAllTypeList() {
|
|
List<VideoType> list = videoTypeDao.list("from VideoType v order by v.orderby desc");
|
return list;
|
}
|
|
public List<VideoType> getNextTypeList(String pid) {
|
|
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 void createType(VideoType type) {
|
|
videoTypeDao.create(type);
|
}
|
|
public void updateType(VideoType type) {
|
|
videoTypeDao.update(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();
|
}
|
|
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;
|
}
|
|
@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 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 (resourceWhere.endsWith("or"))
|
resourceWhere = resourceWhere.substring(0, resourceWhere.length() - 2);
|
|
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";
|
}
|
//select v.id,v.`name`,v.`tag`,v.`picture`,v.`hpicture`,v.`latest_hpicture`,v.watchcount,v.commentcount,v.vpicture 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 v.contentType=1 and ca.id is not null AND rv.`resourceid` IS NOT NULL ? ) a using(id)
|
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,v.vpicture FROM (SELECT DISTINCT(ca.videoid) AS videoid FROM wk_category_video ca LEFT JOIN wk_video_type t ON t.`id`=ca.`videotypeid` AND (t.`id`="+type+" OR t.`pid`="+type+") WHERE t.`id`>0 ) a LEFT JOIN wk_video_video v ON v.`id`=a.videoid WHERE v.`id` IS NOT NULL AND v.`show`=1 AND v.contentType=1 ? ",
|
(page - 1) * pageCount, pageCount, new Serializable[] { orderby }));
|
}
|
|
List<VideoInfo> list = new ArrayList<VideoInfo>();
|
|
long startTime = System.currentTimeMillis();
|
|
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,v.vpicture 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 v.contentType=1 AND ca.id>0 AND t.`id`>0 AND rv.`resourceid`>0 %s) a using(id)",
|
// typeNew, typeNew, resourceWhereNew, orderbyNew);
|
String sql="SELECT v.id,v.`name`,v.`tag`,v.`picture`,v.`hpicture`,v.`latest_hpicture`,v.watchcount,v.commentcount,v.vpicture FROM (SELECT DISTINCT(ca.videoid) AS videoid FROM wk_category_video ca LEFT JOIN wk_video_type t ON t.`id`=ca.`videotypeid` AND (t.`id`="+typeNew+" OR t.`pid`="+typeNew+") WHERE t.`id`>0 ) a LEFT JOIN wk_video_video v ON v.`id`=a.videoid WHERE v.`id` IS NOT NULL AND v.`show`=1 AND v.contentType=1 "+orderbyNew;
|
list = session.createSQLQuery(sql).setFirstResult((page - 1) * pageCount).setCacheable(true)
|
.setMaxResults(pageCount).list();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return list;
|
}
|
});
|
|
System.out.println("查询SQL费时:" + (System.currentTimeMillis() - startTime));
|
return getVideoInfoData(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] + ""));
|
info.setVpicture(obj[8]+"" );
|
if (obj.length > 9) {
|
String[] resourceIds = (obj[9] + "").split(",");
|
List<VideoResource> resourceList = new ArrayList<VideoResource>();
|
for (String rid : resourceIds)
|
resourceList.add(new VideoResource(rid));
|
info.setResourceList(resourceList);
|
}
|
dataList.add(info);
|
}
|
return dataList;
|
}
|
|
@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 yearWhere = "";
|
if (!StringUtil.isNullOrEmpty(startYear) && !StringUtil.isNullOrEmpty(endYear)) {
|
yearWhere = " and (v.year>=" + startYear + " and v.year<=" + endYear + ") ";
|
}
|
|
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;
|
}
|
});
|
|
}
|
|
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();
|
}
|
|
if (wheres.startsWith("or"))
|
wheres = wheres.substring(2, wheres.length());
|
List<VideoInfo> list = new ArrayList<VideoInfo>();
|
|
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;
|
}
|
|
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] + "");
|
|
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);
|
}
|
|
List result = videoInfoDao.sqlList(sql, (page - 1) * Constant.pageCount, Constant.pageCount, null);
|
|
List<VideoInfo> list = parseVideoListAmin(result);
|
return list;
|
}
|
|
public long getTypeVideoListAdminCount(String type, 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 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);
|
}
|
|
return videoInfoDao.getCountSQL(sql);
|
}
|
|
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;
|
}
|
|
public VideoType getRootVideoType(VideoType ty) {
|
|
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 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;
|
}
|
});
|
|
}
|
|
/**
|
* 首页大分类--后台编辑使用
|
*
|
* @param detailSystem
|
* @param page
|
* @return
|
*/
|
|
@SuppressWarnings("unchecked")
|
public List<com.newvideo.domain.web.VideoTypeAdmin> getVideoTypeAdmin(final int detailSystem, final int pid,
|
final int page) {
|
return (List<com.newvideo.domain.web.VideoTypeAdmin>) videoTypeDao
|
.excute(new HibernateCallback<List<com.newvideo.domain.web.VideoTypeAdmin>>() {
|
public List<com.newvideo.domain.web.VideoTypeAdmin> doInHibernate(Session session)
|
throws HibernateException {
|
List<com.newvideo.domain.web.VideoTypeAdmin> hotTypeList = new ArrayList<com.newvideo.domain.web.VideoTypeAdmin>();
|
try {
|
List<DetailSystem> detailSystemList = session.createQuery("from DetailSystem").list();
|
String where = "";
|
|
List<VideoType> list = null;
|
if (detailSystem > 0) {
|
where += " where vb.detailSystem.id= " + detailSystem;
|
|
if (pid > 0)
|
|
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();
|
|
List<DetailSystemSelect> dssList = new ArrayList<DetailSystemSelect>();
|
|
for (DetailSystem ds : detailSystemList) {
|
DetailSystemSelect dss = new DetailSystemSelect();
|
dss.setDetailSystem(ds);
|
dss.setSelected(false);
|
dssList.add(dss);
|
}
|
|
// 设置已经存在的
|
for (DetailSystem ds : detailSystemS) {
|
|
for (DetailSystemSelect dss : dssList) {
|
if (dss.getDetailSystem().getId().equalsIgnoreCase(ds.getId())) {
|
dss.setSelected(true);
|
break;
|
}
|
}
|
}
|
|
hotTypeList.add(new com.newvideo.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) {
|
|
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 });
|
}
|
|
/**
|
* 显示视频大分类区
|
*/
|
|
@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");
|
}
|
|
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);
|
}
|
|
for (SuperVideoType videoType : typeList) {
|
session.persist(videoType);
|
}
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return null;
|
}
|
});
|
|
}
|
|
public void deleteSuperVideoType(SuperVideoType videoType) {
|
superVideoTypeDao.delete(videoType);
|
}
|
|
}
|