// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov. // Jad home page: http://www.kpdus.com/jad.html // Decompiler options: packimports(3) // Source File Name: StarService.java package com.newvideo.service.imp; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import javax.annotation.Resource; 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.BaseDao; import com.newvideo.dao.DetailSystemDao; import com.newvideo.dao.HotStarDao; import com.newvideo.dao.SuperHotStarDao; import com.newvideo.dao.VideoInfoDao; import com.newvideo.domain.DetailSystem; import com.newvideo.domain.HotStar; import com.newvideo.domain.SuperHotStar; import com.newvideo.domain.VideoInfo; import com.newvideo.domain.web.DetailSystemSelect; import com.newvideo.domain.web.HotStarAdmin; import com.newvideo.util.Constant; import com.newvideo.util.SolrUtil; import com.newvideo.util.StringUtil; @Service public class StarService { @Resource private HotStarDao hotStarDao; @Resource private VideoInfoDao videoInfoDao; @Resource private SuperHotStarDao superHotStarDao; @Resource private DetailSystemDao detailSystemDao; public SuperHotStarDao getSuperHotStarDao() { return superHotStarDao; } public void setSuperHotStarDao(SuperHotStarDao superHotStarDao) { this.superHotStarDao = superHotStarDao; } public VideoInfoDao getVideoInfoDao() { return videoInfoDao; } public void setVideoInfoDao(VideoInfoDao videoInfoDao) { this.videoInfoDao = videoInfoDao; } public HotStarDao getHotStarDao() { return hotStarDao; } public void setHotStarDao(HotStarDao hotStarDao) { this.hotStarDao = hotStarDao; } public StarService() { } @Cacheable(value = "classCache", key = "'getHotStarList'+'-'+#page+'-'+#pageCount") public List getHotStarList(int page, int pageCount) { List list = hotStarDao.list("from HotStar h order by h.orderby desc,h.createtime desc", (page - 1) * pageCount, pageCount, new String[] {}); return list; } public List getHotStarList(String detailSystem, int page) { List list = hotStarDao.list( "select h.hotStar from SuperHotStar h where h.detailSystem.id=? order by h.hotStar.orderby desc,h.hotStar.createtime desc", (page - 1) * Constant.pageCount, Constant.pageCount, new String[] { detailSystem }); return list; } @Cacheable(value = "classCache", key = "'getHotStarDetail'+'-'+#id") public HotStar getHotStarDetail(String id) { return hotStarDao.find(HotStar.class, id); } public long getHotStarCount() { return hotStarDao.getCount("select count(*) from HotStar"); } public long getHotStarCount(String detailSystem) { return hotStarDao.getCount("select count(*) from SuperHotStar s where s.detailSystem.id=?", new String[] { detailSystem }); } public List getHotStarVideo(String starId, int page) { List list = videoInfoDao.list( "select h.video from HotStarVideo as h LEFT JOIN h.video as v where h.video.show='1' and v.id=h.video.id and h.star.id=? order by h.video.updatetime desc", (page - 1) * Constant.pageCount, Constant.pageCount, new String[] { starId }); return list; } public long getHotStarVideoCount(String starId) { long count = hotStarDao.getCount( "select count(*) from HotStarVideo as h where h.video.show='1' and h.star.id=?", new String[] { starId }); return count; } public List getStarList() { return hotStarDao.list("from HotStar h order by h.orderby DESC"); } public HotStar getStar(String id) { if (!StringUtil.isNullOrEmpty(id)) { return (HotStar) hotStarDao.find(HotStar.class, id); } else { return null; } } public HotStar addStar(HotStar star) { if (star != null) { hotStarDao.save(star); List list = hotStarDao.list("from HotStar h where h.createtime=? and h.name=?", new String[] { star.getCreatetime(), star.getName() }); if (list != null && list.size() > 0) return (HotStar) list.get(0); } return null; } public HotStar updateStar(HotStar star) { if (star != null) { hotStarDao.update(star); List list = hotStarDao.list("from HotStar h where h.createtime=? and h.name=?", new String[] { star.getCreatetime(), star.getName() }); if (list != null && list.size() > 0) return (HotStar) list.get(0); } return null; } public void deleteStar(final HotStar star) { if (star != null) { hotStarDao.excute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { try { @SuppressWarnings("unchecked") List list = session.createQuery("from SuperHotStar sh where sh.hotStar.id=?") .setParameter(0, star.getId()).list(); session.getTransaction().begin(); for (SuperHotStar sh : list) { session.delete(sh); } session.createQuery("delete from HotStar hs where hs.id=?").setParameter(0, star.getId()) .executeUpdate(); session.flush(); session.getTransaction().commit(); } catch (Exception e) { e.printStackTrace(); session.getTransaction().rollback(); } return null; } }); } } @SuppressWarnings("unchecked") @Cacheable(value = "classCache", key = "'getStarVideo'+'-'+#detailSystemId+'-'+#starId+'-'+#pageIndex+'-'+#cachemd5") public List getStarVideo(String detailSystemId, String starId, int pageIndex, List resourceList, String cachemd5) { String resourceWhere = ""; for (Long rid : resourceList) resourceWhere += String.format(" rv.`resourceid`=%d or", rid); if (resourceWhere.endsWith("or")) resourceWhere = resourceWhere.substring(0, resourceWhere.length() - 2); List list = null; Session session = hotStarDao.getSession(); try { HotStar star = (HotStar) session.get(HotStar.class, starId); String sql = String.format( "SELECT v.* FROM wk_video_video v LEFT JOIN wk_resource_video rv ON rv.`videoid`=v.`id` AND (%s) WHERE v.`contenttype`=1 AND v.`show`=1 AND v.`mainactor` LIKE '%s' AND rv.`videoid` IS NOT NULL and v.area is not null and v.area !='' GROUP BY v.`id` ORDER BY FROM_UNIXTIME(v.`updatetime`/1000) DESC", resourceWhere, "%" + star.getName() + "%"); list = session.createSQLQuery(sql).addEntity(VideoInfo.class) .setFirstResult((pageIndex - 1) * Constant.pageCount).setMaxResults(Constant.pageCount).list(); } catch (Exception e) { e.printStackTrace(); } return list; } @Cacheable(value = "classCache", key = "'getStarVideo'+'-'+#detailSystemId+'-'+#starId+'-'+#pageIndex+'-'+#cachemd5") public List getStarVideo(String detailSystemId, String starId, int pageIndex, String cachemd5) { HotStar star = hotStarDao.find(HotStar.class, starId); return SolrUtil.searchStarVideos(star.getName(), pageIndex); } @Cacheable(value = "classCache", key = "'getStarVideoCount'+'-'+#detailSystemId+'-'+#starId") public long getStarVideoCount(String detailSystemId, String starId) { long count = 0; try { HotStar star = (HotStar) hotStarDao.find(HotStar.class, starId); count = hotStarDao.getCount( "select count(*) from CategoryVideo cv where cv.video.mainActor like ? and cv.video.contentType=1 and cv.video.area is not null and cv.video.area!=''", new Serializable[] { "%" + star.getName() + "%" }); } catch (Exception e) { e.printStackTrace(); } return count; } public long getStarVideoPage(String detailSystemId, String starId) { long count = getStarVideoCount(detailSystemId, starId); return count % (long) Constant.pageCount != 0L ? count / (long) Constant.pageCount + 1L : count / (long) Constant.pageCount; } @SuppressWarnings("unchecked") public List getHotStarAdmin(String key, int detailSystem, int page) { key = StringUtil.isNullOrEmpty(key) ? "" : key; List zhiBoClassList = new ArrayList(); try { List detailSystemList = detailSystemDao.list("from DetailSystem"); String sql = ""; if (detailSystem > 0) sql = "select sh.hotStar from SuperHotStar sh where sh.detailSystem.id=" + detailSystem + " and sh.hotStar.name like ? order by sh.hotStar.orderby desc"; else sql = "from HotStar zb where zb.name like ? order by zb.orderby desc"; List list = hotStarDao.list(sql, (page - 1) * Constant.pageCount, Constant.pageCount, new Serializable[] { "%" + key + "%" }); for (HotStar vb : list) { List detailSystemS = detailSystemDao .list("select vb.detailSystem from SuperHotStar vb where vb.hotStar.id=" + vb.getId()); List dssList = new ArrayList(); 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; } } } SuperHotStar sz = new SuperHotStar(); sz.setDetailSystem(null); sz.setHotStar(vb); zhiBoClassList.add(new HotStarAdmin(sz, dssList)); } } catch (Exception e) { e.printStackTrace(); } return zhiBoClassList; } public long getHotStarAdminCount(String key, int detailSystem) { key = StringUtil.isNullOrEmpty(key) ? "" : key; String sql = ""; if (detailSystem > 0) sql = "select count(*) from (select count(*) from wk_video_super_hotstar zb left join wk_video_hotstar c on c.id=zb.hotstarid where zb.detailsystemid=" + detailSystem + " and c.name like '%" + key + "%' group by zb.hotstarid) s"; else sql = "select count(*) from (select count(*) from wk_video_hotstar zb left join wk_video_hotstar c on c.id=zb.id where c.name like '%" + key + "%' group by zb.id) s"; return hotStarDao.getCountSQL(sql); } @SuppressWarnings("unchecked") public void deleteHotStarAdmin(final String classId, final String detailSystemId) { hotStarDao.excute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { try { List list = session .createQuery("from SuperHotStar vb where vb.hotStar.id=? and vb.detailSystem.id=?") .setParameter(0, classId).setParameter(1, detailSystemId).list(); if (list != null && list.size() > 0) { session.getTransaction().begin(); for (SuperHotStar vb : list) session.delete(vb); session.flush(); session.getTransaction().commit(); } } catch (Exception e) { e.printStackTrace(); } return null; } }); } /** * 明星 */ public List getHotStarList(String detailSystem) { return hotStarDao.list("select hs.hotStar FROM SuperHotStar hs where hs.detailSystem.id=" + detailSystem + " order by hs.hotStar.orderby desc"); } public List getSuperHotStarList(String detailSystem) { return superHotStarDao.list( "FROM SuperHotStar hs where hs.detailSystem.id=" + detailSystem + " order by hs.hotStar.orderby desc"); } public void addSuperHotStar(SuperHotStar sv) { List list = superHotStarDao.list("from SuperHotStar sv where sv.hotStar.id=" + sv.getHotStar().getId() + " and sv.detailSystem.id=" + sv.getDetailSystem().getId()); if (list != null && list.size() > 0) return; superHotStarDao.create(sv); } public void updateSuperHotStar(SuperHotStar hotSearch) { superHotStarDao.update(hotSearch); } public void deleteSuperHotStar(SuperHotStar hotSearch) { superHotStarDao.delete(hotSearch); } @SuppressWarnings("unchecked") public void updateSuperHotStarList(final String detailSystemId, final List typeList) { hotStarDao.excute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { try { List list = session .createQuery("from SuperHotStar sh where sh.detailSystem.id=" + detailSystemId).list(); session.getTransaction().begin(); for (SuperHotStar ad : list) { session.delete(ad); } for (SuperHotStar videoType : typeList) { session.persist(videoType); } session.flush(); session.getTransaction().commit(); } catch (Exception e) { e.printStackTrace(); session.getTransaction().rollback(); } return null; } }); } @Cacheable(value = "foundCache", key = "'getHotStarOnMain'+'-'+#detailSystemId") public List getHotStarOnMain(String detailSystemId) { return hotStarDao.list("select hs.hotStar FROM SuperHotStar hs where hs.detailSystem.id=" + detailSystemId + " order by hs.hotStar.orderby desc", 0, 3, null); } }