package com.newvideo.service.imp; import java.io.Serializable; import java.util.List; import javax.annotation.Resource; import org.apache.log4j.Logger; 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.DetailSystemDao; import com.newvideo.dao.SystemInfoDao; import com.newvideo.domain.DetailSystem; import com.newvideo.domain.HomeAd; import com.newvideo.domain.HomeType; import com.newvideo.domain.HotSearch; import com.newvideo.domain.HotStar; import com.newvideo.domain.HotVideoType; import com.newvideo.domain.ShareContent; import com.newvideo.domain.SuperHomeAd; import com.newvideo.domain.SuperHomeNotice; import com.newvideo.domain.SuperHomeType; import com.newvideo.domain.SuperHotSearch; import com.newvideo.domain.SuperHotStar; import com.newvideo.domain.SuperHotType; import com.newvideo.domain.SuperRecommendAd; import com.newvideo.domain.SuperUserBanner; import com.newvideo.domain.SuperVideoType; import com.newvideo.domain.SystemInfo; import com.newvideo.domain.UserBanner; import com.newvideo.domain.VideoBanQuan; import com.newvideo.domain.VideoBanQuanVideo; import com.newvideo.domain.VideoType; import com.newvideo.domain.special.Special; import com.newvideo.domain.special.SuperSpecial; import com.newvideo.util.Constant; /** * 系统分类服务 * * @author Administrator * */ @Service public class SystemService { Logger log = Logger.getLogger(SystemService.class); @Resource private DetailSystemDao detailSystemDao; @Resource private SystemInfoDao systemInfoDao; @Resource private ClassService classService; @Resource private StarService starService; @Resource private SpecialService specialService; public List getDetailSystemList() { List list = detailSystemDao.list("from DetailSystem"); return list; } public List getDetailSystemList(String key, int pageIndex) { List list = detailSystemDao.list( "from DetailSystem ds where ds.appName like ? order by ds.createtime desc", (pageIndex - 1) * Constant.pageCount, Constant.pageCount, new String[] { "%" + key + "%" }); return list; } public long getDetailSystemListCount(String key) { return detailSystemDao.getCount("select count(*) from DetailSystem d where d.appName like ?", new String[] { "%" + key + "%" }); } @Cacheable(value = "homeCache", key = "'getDetailSystemByPackage'+'-'+#packageName") public DetailSystem getDetailSystemByPackage(String packageName) { long startTime = System.currentTimeMillis(); log.info("getDetailSystemByPackage开始请求"); List list = detailSystemDao.list("from DetailSystem d where d.packageName=?", new String[] { packageName }); log.info("getDetailSystemByPackage请求完成:" + (System.currentTimeMillis() - startTime)); if (list != null && list.size() > 0) return list.get(0); else return null; } public DetailSystem getDetailSystemById(String id) { return detailSystemDao.find(DetailSystem.class, id); } public void updateDetailSystem(DetailSystem system) { detailSystemDao.update(system); } public boolean addDetailSystem(DetailSystem system) { List list = detailSystemDao.list( "from DetailSystem ds where ds.system.id=" + system.getSystem().getId() + " and ds.packageName=? and ds.platform=" + system.getPlatform(), new String[] { system.getPackageName() }); if (list == null || list.size() == 0) { detailSystemDao.create(system); return true; } else return false; } public List getSystemList() { return systemInfoDao.list("from SystemInfo"); } @SuppressWarnings("unchecked") public void deleteDetailSystem(final String dsId) { detailSystemDao.excute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { try { session.getTransaction().begin(); List shlist = session.createQuery("from SuperHomeAd sz where sz.detailSystem.id=?") .setParameter(0, dsId).list(); for (SuperHomeAd sz : shlist) session.delete(sz); List shnlist = session .createQuery("from SuperHomeNotice sz where sz.detailSystem.id=?").setParameter(0, dsId) .list(); for (SuperHomeNotice sz : shnlist) session.delete(sz); List shtlist = session .createQuery("from SuperHomeType sz where sz.detailSystem.id=?").setParameter(0, dsId) .list(); for (SuperHomeType sz : shtlist) session.delete(sz); List shslist = session .createQuery("from SuperHotSearch sz where sz.detailSystem.id=?").setParameter(0, dsId) .list(); for (SuperHotSearch sz : shslist) session.delete(sz); List shotlist = session.createQuery("from SuperHotType sz where sz.detailSystem.id=?") .setParameter(0, dsId).list(); for (SuperHotType sz : shotlist) session.delete(sz); List sralist = session .createQuery("from SuperRecommendAd sz where sz.detailSystem.id=?").setParameter(0, dsId) .list(); for (SuperRecommendAd sz : sralist) session.delete(sz); List sublist = session .createQuery("from SuperUserBanner sz where sz.detailSystem.id=?").setParameter(0, dsId) .list(); for (SuperUserBanner sz : sublist) session.delete(sz); List svtlist = session .createQuery("from SuperVideoType sz where sz.detailSystem.id=?").setParameter(0, dsId) .list(); for (SuperVideoType sz : svtlist) session.delete(sz); List vbqlist = session.createQuery("from VideoBanQuan sz where sz.detailSystem.id=?") .setParameter(0, dsId).list(); for (VideoBanQuan sz : vbqlist) session.delete(sz); List vbvlist = session .createQuery("from VideoBanQuanVideo sz where sz.detailSystem.id=?").setParameter(0, dsId) .list(); for (VideoBanQuanVideo sz : vbvlist) session.delete(sz); List sclist = session.createQuery("from ShareContent sz where sz.detailSystem.id=?") .setParameter(0, dsId).list(); for (ShareContent sz : sclist) session.delete(sz); session.delete(new DetailSystem(dsId)); session.flush(); session.getTransaction().commit(); } catch (Exception e) { e.printStackTrace(); session.getTransaction().rollback(); } return null; } }); } HomeAdService homeAdService; HomeTypeService homeTypeService; HotVideoTypeService hotVideoTypeService; SearchService searchService; UserBannerService userBannerService; public void detailSystemClone(String fromid, String toId) { // 首页Banner List homeAdlist = homeAdService.getHomeAdList(new DetailSystem(fromid)); for (HomeAd ad : homeAdlist) { SuperHomeAd sa = new SuperHomeAd(); sa.setCreatetime(System.currentTimeMillis() + ""); sa.setDetailSystem(new DetailSystem(toId)); sa.setHomeAd(ad); homeAdService.addSuperHomeAd(sa); } // 首页栏目 List homeTypelist = homeTypeService.getHomeType(fromid); for (HomeType ht : homeTypelist) { SuperHomeType sa = new SuperHomeType(); sa.setCreatetime(System.currentTimeMillis() + ""); sa.setDetailSystem(new DetailSystem(toId)); sa.setHomeType(ht); homeTypeService.addSuperHomeType(sa); } // 视频大分类 List videoTypeList = classService.getSuperVideoTypeList(fromid); for (SuperVideoType ht : videoTypeList) { SuperVideoType sa = new SuperVideoType(); sa.setCreatetime(System.currentTimeMillis() + ""); sa.setDetailSystem(new DetailSystem(toId)); sa.setType(new VideoType(ht.getType().getId())); classService.addSuperVideoType(sa); } // 热门分类 List hotVideoTypeList = hotVideoTypeService.getSuperHotTypeList(fromid); for (HotVideoType ht : hotVideoTypeList) { SuperHotType sa = new SuperHotType(); sa.setCreatetime(System.currentTimeMillis() + ""); sa.setDetailSystem(new DetailSystem(toId)); sa.setHotType(ht); hotVideoTypeService.addSuperHotType(sa); } // 专题 List specialList = specialService.getSpecialList(fromid); for (Special special : specialList) { SuperSpecial sa = new SuperSpecial(); sa.setDetailSystem(new DetailSystem(toId)); sa.setSpecial(new Special(special.getId())); specialService.addSuperSpecial(sa); } // 明星 List hotStarList = starService.getHotStarList(fromid); for (HotStar hs : hotStarList) { SuperHotStar sa = new SuperHotStar(); sa.setDetailSystem(new DetailSystem(toId)); sa.setHotStar(new HotStar(hs.getId())); sa.setCreatetime(System.currentTimeMillis() + ""); starService.addSuperHotStar(sa); } // 热门搜索 List hotSearchList = searchService.getHotSearchListByDS(fromid); for (HotSearch hs : hotSearchList) { SuperHotSearch sa = new SuperHotSearch(); sa.setDetailSystem(new DetailSystem(toId)); sa.setHotSearch(new HotSearch(hs.getId())); sa.setCreatetime(System.currentTimeMillis() + ""); searchService.addSuperHotSearch(sa); } // 用户Banner List userBannerList = userBannerService.getUserBannerList(fromid); for (UserBanner ub : userBannerList) { SuperUserBanner sa = new SuperUserBanner(); sa.setDetailSystem(new DetailSystem(toId)); sa.setUserBanner(new UserBanner(ub.getId())); sa.setCreatetime(System.currentTimeMillis() + ""); userBannerService.addSuperUserBanner(sa); } // 直播 } public DetailSystem getDetailSystem(String system, String packageName) { List list = detailSystemDao.list("from DetailSystem ds where ds.system.id = ? and packageName = ? ",new Serializable[]{system,packageName}); if(list.size() > 0 ){ return list.get(0); } return null; } }