admin
2023-04-12 f06a592dd1a7e995bf313ccb5efe7dff73ccfc4e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package com.yeshi.buwan.service.imp;
 
import java.util.ArrayList;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Service;
 
import com.yeshi.buwan.dao.VideoIntersectionDao;
import com.yeshi.buwan.dao.VideoIntersectionVideoDao;
import com.yeshi.buwan.domain.VideoInfo;
import com.yeshi.buwan.domain.VideoIntersection;
import com.yeshi.buwan.domain.VideoIntersectionVideo;
import com.yeshi.buwan.util.Constant;
 
@Service
public class IntersectionService {
    @Resource
    private VideoIntersectionDao videoIntersectionDao;
    @Resource
    private VideoIntersectionVideoDao videoIntersectionVideoDao;
 
 
    // 添加合集
    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<VideoIntersectionVideo> 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<VideoIntersection> getIntersectionList() {
        return videoIntersectionDao.list("from VideoIntersection");
    }
 
    public List<VideoIntersection> 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<VideoIntersection> 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<VideoInfo> getIntersectionVideoList(String intersectionId) {
        List<VideoInfo> videoList = new ArrayList<VideoInfo>();
        List<VideoIntersectionVideo> 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<VideoInfo> getIntersectionVideoList(String intersectionId, String key, int pageIndex) {
        List<VideoInfo> videoList = new ArrayList<VideoInfo>();
        List<VideoIntersectionVideo> 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<VideoIntersectionVideo> getIntersectionVideoListByInersection(String intersectionId) {
        List<VideoIntersectionVideo> list = videoIntersectionVideoDao.list(
                "from VideoIntersectionVideo v where v.video.show=1 and v.intersection.id=?",
                new String[]{intersectionId});
        return list;
    }
 
    public List<VideoIntersectionVideo> getIntersectionVideoListByInersection(String intersectionId, String key,
                                                                              int pageIndex) {
        List<VideoIntersectionVideo> 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 + "%"});
    }
 
}