admin
2020-09-12 2778cf2a16823f9b1153a0549b47f7b503176a17
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
package com.yeshi.buwan.util.video;
 
import com.yeshi.buwan.dao.VideoInfoDao;
import com.yeshi.buwan.domain.ResourceVideo;
import com.yeshi.buwan.domain.VideoDetailInfo;
import com.yeshi.buwan.domain.VideoInfo;
import com.yeshi.buwan.domain.VideoResource;
import com.yeshi.buwan.domain.entity.PlayUrl;
import com.yeshi.buwan.iqiyi.util.IqiyiUtil;
import com.yeshi.buwan.iqiyi.util.IqiyiUtil2;
import com.yeshi.buwan.service.imp.VideoInfoService;
import com.yeshi.buwan.service.imp.juhe.*;
import com.yeshi.buwan.service.inter.juhe.Iqiyi2Service;
import com.yeshi.buwan.sohu.SoHuUtil;
import com.yeshi.buwan.util.StringUtil;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.orm.hibernate4.HibernateCallback;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.util.List;
 
@Component
public class VideoDetailUtil {
    @Resource
    private IqiyiUtil iqiyiUtil;
 
    @Resource
    private SoHuUtil soHuUtil;
 
    @Resource
    private IqiyiService iqiyiService;
 
    @Resource
    private Iqiyi2Service iqiyi2Service;
 
    @Resource
    private SoHuService soHuService;
 
    @Resource
    private VideoInfoDao videoInfoDao;
 
    @Resource
    private FunTVService funTVService;
 
    @Resource
    private PPTVService pptvService;
 
    @Resource
    private VideoInfoService videoInfoService;
 
    @SuppressWarnings("unchecked")
//    @Cacheable(value = "homeCache", key = "'getVideoInfo'+'-'+#videoid+'-'+#resourceId+'-'+#cacheMD5")
    public VideoInfo getVideoInfo(final String videoid, final String resourceId, final List<Long> reList,
                                  String cacheMD5) {
 
        return (VideoInfo) videoInfoDao.excute(new HibernateCallback<VideoInfo>() {
            public VideoInfo doInHibernate(Session session) throws HibernateException {
 
                VideoInfo video = null;
                VideoResource resource = null;
                try {
                    if (!StringUtil.isNullOrEmpty(resourceId)) {
 
                        // 来源限制判断
                        boolean isCan = false;
                        for (long re : reList)
                            if (resourceId.equalsIgnoreCase(re + "")) {
                                isCan = true;
                            }
                        if (!isCan)
                            return null;
 
                        List<ResourceVideo> list = session
                                .createQuery("FROM ResourceVideo rv where rv.video.id=? and rv.resource.id=?")
                                .setParameter(0, videoid).setParameter(1, resourceId).list();
                        if (list != null && list.size() > 0) {
                            ResourceVideo rv = list.get(0);
                            List<VideoResource> resourceList = session
                                    .createQuery("select rv.resource from ResourceVideo rv where rv.video.id=?")
                                    .setParameter(0, videoid).list();
 
                            rv.getVideo().setVideoDetailList(getVideoDetailList(videoid, rv.getResource()));
                            for (VideoResource r : resourceList) {
                                if (r.getId().equalsIgnoreCase(rv.getResource().getId())) {
                                    r.setChecked(true);
                                }
                            }
                            rv.getVideo().setResourceList(resourceList);
                            video = rv.getVideo();
 
                            resource = rv.getResource();
                        }
                    } else {
                        List<ResourceVideo> list = session
                                .createQuery(
                                        "FROM ResourceVideo rv where rv.video.id=? order by rv.resource.orderby desc")
                                .setParameter(0, videoid).list();
                        // 来源筛查
 
                        if (list != null)
                            for (int i = 0; i < list.size(); i++) {
                                boolean isC = false;
                                for (Long id : reList) {
                                    if ((id + "").equalsIgnoreCase(list.get(i).getResource().getId())) {
                                        isC = true;
                                        break;
                                    }
                                }
                                if (!isC) {
                                    list.remove(i);
                                    i--;
                                }
                            }
 
                        if (list != null && list.size() > 0) {
                            ResourceVideo rv = list.get(0);
                            List<VideoResource> resourceList = session
                                    .createQuery(
                                            "select rv.resource from ResourceVideo rv where rv.video.id=? order by rv.resource.id desc")
                                    .setParameter(0, videoid).list();
 
                            rv.getVideo().setVideoDetailList(getVideoDetailList(videoid, rv.getResource()));
 
                            for (int i = 0; i < resourceList.size(); i++) {
                                VideoResource r = resourceList.get(i);
                                if (r.getId().equalsIgnoreCase(rv.getResource().getId())) {
                                    r.setChecked(true);
                                }
                                boolean isS = false;
                                for (Long id : reList) {
                                    if ((id + "").equalsIgnoreCase(r.getId())) {
                                        isS = true;
                                        break;
                                    }
                                }
                                // 不在允许的resource里面
                                if (!isS) {
                                    resourceList.remove(i);
                                    i--;
                                }
 
                            }
                            rv.getVideo().setResourceList(resourceList);
                            video = rv.getVideo();
                            resource = rv.getResource();
                        }
                    }
 
                } catch (Exception e) {
                    e.printStackTrace();
                }
 
                try {
                    if (video.getVideoDetailList() != null && video.getVideoDetailList().size() == 1) {
                        video.getVideoDetailList().get(0).setName(video.getName());
                        video.getVideoDetailList().get(0).setTag(video.getName());
                    }
 
                    if (video != null && resource != null) {
                        video.setShowType(getShowType(video.getId(), resource));
                    }
                } catch (Exception e) {
 
                }
                return video;
            }
        });
    }
 
    private List<VideoDetailInfo> getVideoDetailList(String videoid, VideoResource vr) {
        if (vr.getName().contains("爱奇艺2")) {
            return iqiyi2Service.getVideoDetailList(videoid);
        } else if (vr.getName().contains("爱奇艺")) {
            return iqiyiService.getVideoDetailList(videoid);
        } else if (vr.getName().contains("搜狐")) {
            return soHuService.getVideoDetailList(videoid);
        } else if (vr.getName().contains("PPTV"))
            return pptvService.getVideoDetailList(videoid);
        else if (vr.getName().contains("风行"))
            return funTVService.getVideoDetailList(videoid);
        else if (vr.getName().contains("AcFun")) {
            return videoInfoService.getVideoDetailList(videoid, vr);
        }
        return null;
    }
 
    public VideoDetailInfo getLatestVideoDetail(String videoid, VideoResource vr) {
        if (vr.getName().contains("爱奇艺2")) {
            return iqiyi2Service.getLatestVideoDetail(videoid);
        } else if (vr.getName().contains("爱奇艺")) {
            return iqiyiService.getLatestVideoDetail(videoid);
        } else if (vr.getName().contains("搜狐")) {
            return soHuService.getLatestVideoDetail(videoid);
        } else if (vr.getName().contains("PPTV"))
            return pptvService.getLatestVideoDetail(videoid);
        else if (vr.getName().contains("风行"))
            return funTVService.getLatestVideoDetail(videoid);
        return null;
    }
 
    public int getShowType(String videoid, VideoResource vr) {
        if (vr.getName().contains("爱奇艺2")) {
            return iqiyi2Service.getShowType(videoid);
        } else if (vr.getName().contains("爱奇艺")) {
            return iqiyiUtil.getShowType(videoid);
        } else if (vr.getName().contains("搜狐")) {
            return soHuUtil.getShowType(videoid);
        } else if (vr.getName().contains("PPTV")) {
            return pptvService.getShowType(videoid);
        } else if (vr.getName().contains("风行")) {
            return funTVService.getShowType(videoid);
        }
        return 1;
    }
 
    @Cacheable(value = "homeCache", key = "'getPlayUrl'+'-'+#detailSystemId+'-'+#id+'-'+#type+'-'+#resourceid")
    public PlayUrl getPlayUrl(String detailSystemId, String id, String type, int resourceid, String videoid) {
        if (resourceid == 13) {// 爱奇艺
            return iqiyiUtil.getPlayUrl(detailSystemId, resourceid + "", type, id);
        } else if (resourceid == 14) {// 搜狐
            return soHuUtil.getPlayUrl(detailSystemId, resourceid + "", type, id);
        } else if (resourceid == 16)// PPTV
            return pptvService.getPlayUrl(detailSystemId, id, type, resourceid, videoid);
        else if (resourceid == 19)// 风行
            return funTVService.getPlayUrl(detailSystemId, id, type, resourceid, videoid);
        else if (resourceid == 21)//acfun
            return videoInfoService.getPlayUrl(detailSystemId, id, type, resourceid, videoid);
        else if (resourceid == 22)//爱奇艺2
            return iqiyi2Service.getPlayUrl(detailSystemId, resourceid, id, videoid);
        return null;
    }
 
}