package com.newvideo.service.imp; import java.util.ArrayList; import java.util.List; import javax.annotation.Resource; import org.springframework.stereotype.Service; import com.newvideo.dao.VideoIntersectionDao; import com.newvideo.dao.VideoIntersectionVideoDao; import com.newvideo.domain.VideoInfo; import com.newvideo.domain.VideoIntersection; import com.newvideo.domain.VideoIntersectionVideo; import com.newvideo.util.Constant; @Service public class IntersectionService { @Resource private VideoIntersectionDao videoIntersectionDao; @Resource private VideoIntersectionVideoDao videoIntersectionVideoDao; public VideoIntersectionVideoDao getVideoIntersectionVideoDao() { return videoIntersectionVideoDao; } public void setVideoIntersectionVideoDao(VideoIntersectionVideoDao videoIntersectionVideoDao) { this.videoIntersectionVideoDao = videoIntersectionVideoDao; } public VideoIntersectionDao getVideoIntersectionDao() { return videoIntersectionDao; } public void setVideoIntersectionDao(VideoIntersectionDao videoIntersectionDao) { this.videoIntersectionDao = videoIntersectionDao; } // 添加合集 public void addIntersection(VideoIntersection section) { videoIntersectionDao.create(section); } public void updateIntersection(VideoIntersection section) { videoIntersectionDao.update(section); } public void deleteIntersection(VideoIntersection section) { videoIntersectionDao.delete(section); } public void deleteIntersectionVideo(VideoIntersectionVideo section) { videoIntersectionVideoDao.delete(section); } // 添加合集视频 public void addIntersectionVideo(VideoIntersectionVideo sectionVideo) { List list = videoIntersectionVideoDao.list( "from VideoIntersectionVideo v where v.intersection.id=? and v.video.id=?", new String[] { sectionVideo.getIntersection().getId(), sectionVideo.getVideo().getId() }); if (list == null || list.size() == 0) videoIntersectionVideoDao.create(sectionVideo); } public List getIntersectionList() { return videoIntersectionDao.list("from VideoIntersection"); } public List getIntersectionList(String key, int pageIndex) { return videoIntersectionDao.list("from VideoIntersection vi where vi.name like ? ", (pageIndex - 1) * Constant.pageCount, Constant.pageCount, new String[] { "%" + key + "%" }); } public long getIntersectionListCount(String key) { return videoIntersectionDao.getCount("select count(*) from VideoIntersection vi where vi.name like ? ", new String[] { "%" + key + "%" }); } public List getIntersectionListByPage(int page) { return videoIntersectionDao.list("from VideoIntersection", Constant.pageCount * (page - 1), Constant.pageCount, new String[] {}); } public long getIntersectionListPage() { return videoIntersectionDao.getCount("select count(*) from VideoIntersection"); } public VideoIntersection getIntersectionById(String id) { return videoIntersectionDao.find(VideoIntersection.class, id); } public List getIntersectionVideoList(String intersectionId) { List videoList = new ArrayList(); List list = videoIntersectionVideoDao.list( "from VideoIntersectionVideo v where v.video.show=1 and v.intersection.id=?", new String[] { intersectionId }); for (VideoIntersectionVideo vi : list) if (vi.getVideo() != null) videoList.add(vi.getVideo()); return videoList; } public VideoIntersectionVideo getIntersectionVideoById(String id) { return videoIntersectionVideoDao.find(VideoIntersectionVideo.class, id); } public List getIntersectionVideoList(String intersectionId, String key, int pageIndex) { List videoList = new ArrayList(); List list = videoIntersectionVideoDao.list( "from VideoIntersectionVideo v where v.video.show=1 and v.intersection.id=? and v.video.name like ?", (pageIndex - 1) * Constant.pageCount, Constant.pageCount, new String[] { intersectionId, "%" + key + "%" }); for (VideoIntersectionVideo vi : list) if (vi.getVideo() != null) videoList.add(vi.getVideo()); return videoList; } public long getIntersectionVideoListCount(String intersectionId, String key) { return videoIntersectionVideoDao.getCount( "select count(*) from VideoIntersectionVideo v where v.video.show=1 and v.intersection.id=? and v.video.name like ?", new String[] { intersectionId, "%" + key + "%" }); } public List getIntersectionVideoListByInersection(String intersectionId) { List list = videoIntersectionVideoDao.list( "from VideoIntersectionVideo v where v.video.show=1 and v.intersection.id=?", new String[] { intersectionId }); return list; } public List getIntersectionVideoListByInersection(String intersectionId, String key, int pageIndex) { List list = videoIntersectionVideoDao.list( "from VideoIntersectionVideo v where v.video.show=1 and v.intersection.id=? and v.video.name like ?", (pageIndex - 1) * Constant.pageCount, Constant.pageCount, new String[] { intersectionId, "%" + key + "%" }); return list; } public long getIntersectionVideoListByInersectionCount(String intersectionId, String key) { return videoIntersectionVideoDao.getCount( "select count(*) from VideoIntersectionVideo v where v.video.show=1 and v.intersection.id=? and v.video.name like ?", new String[] { intersectionId, "%" + key + "%" }); } }