admin
2021-01-25 d182390205a9828bd1091b06fa712e028004c687
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
package com.newvideo.util.video;
 
import java.util.List;
 
import javax.annotation.Resource;
 
import com.newvideo.funtv.FunTVUtil2;
import com.newvideo.service.inter.FunTV2Service;
import com.newvideo.vo.AcceptData;
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 com.newvideo.dao.VideoInfoDao;
import com.newvideo.domain.ResourceVideo;
import com.newvideo.domain.VideoDetailInfo;
import com.newvideo.domain.VideoInfo;
import com.newvideo.domain.VideoResource;
import com.newvideo.domain.entity.PlayUrl;
import com.newvideo.iqiyi.util.IqiyiUtil;
import com.newvideo.service.imp.juhe.FunTVService;
import com.newvideo.service.imp.juhe.IqiyiService;
import com.newvideo.service.imp.juhe.LeService;
import com.newvideo.service.imp.juhe.PPTVService;
import com.newvideo.service.imp.juhe.SoHuService;
import com.newvideo.service.imp.juhe.YouKuService;
import com.newvideo.sohu.SoHuUtil;
import com.newvideo.util.StringUtil;
import com.newvideo.youku.YouKuUtil;
 
@Component
public class VideoDetailUtil {
    @Resource
    private IqiyiUtil iqiyiUtil;
    @Resource
    private SoHuUtil soHuUtil;
    @Resource
    private YouKuUtil youKuUtil;
    @Resource
    private IqiyiService iqiyiService;
    @Resource
    private SoHuService soHuService;
    @Resource
    private YouKuService youKuService;
    @Resource
    private VideoInfoDao videoInfoDao;
    @Resource
    private LeService leService;
 
    @Resource
    private FunTV2Service funTV2Service;
 
    @Resource
    private FunTVService funTVService;
 
    @Resource
    private PPTVService pptvService;
 
    public VideoInfoDao getVideoInfoDao() {
        return videoInfoDao;
    }
 
    public void setVideoInfoDao(VideoInfoDao videoInfoDao) {
        this.videoInfoDao = videoInfoDao;
    }
 
    public IqiyiUtil getIqiyiUtil() {
        return iqiyiUtil;
    }
 
    public void setIqiyiUtil(IqiyiUtil iqiyiUtil) {
        this.iqiyiUtil = iqiyiUtil;
    }
 
    public SoHuUtil getSoHuUtil() {
        return soHuUtil;
    }
 
    public void setSoHuUtil(SoHuUtil soHuUtil) {
        this.soHuUtil = soHuUtil;
    }
 
    public YouKuUtil getYouKuUtil() {
        return youKuUtil;
    }
 
    public void setYouKuUtil(YouKuUtil youKuUtil) {
        this.youKuUtil = youKuUtil;
    }
 
    public IqiyiService getIqiyiService() {
        return iqiyiService;
    }
 
    public void setIqiyiService(IqiyiService iqiyiService) {
        this.iqiyiService = iqiyiService;
    }
 
    public SoHuService getSoHuService() {
        return soHuService;
    }
 
    public void setSoHuService(SoHuService soHuService) {
        this.soHuService = soHuService;
    }
 
    public YouKuService getYouKuService() {
        return youKuService;
    }
 
    public void setYouKuService(YouKuService youKuService) {
        this.youKuService = youKuService;
    }
 
    @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>() {
            @Override
            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());
                    }
 
                    if (video != null && resource != null) {
                        video.setShowType(getShowType(video.getId(), resource));
                    }
                } catch (Exception e) {
 
                }
                return video;
            }
        });
    }
 
    private List<VideoDetailInfo> getVideoDetailList(String videoid, VideoResource vr) {
        int resourceId = Integer.parseInt(vr.getId());
 
        switch (resourceId) {
            case 13:
                return iqiyiService.getVideoDetailList(videoid);//爱奇艺
            case 14:
                return soHuService.getVideoDetailList(videoid);//搜狐
            case 15:
                return youKuService.getVideoDetailList(videoid);//优酷
            case 16:
                return pptvService.getVideoDetailList(videoid);//PPTV
            case 18:
                return leService.getVideoDetailList(videoid);//乐视
            case 19:
                return funTVService.getVideoDetailList(videoid);//风行
            case 24:
                return funTV2Service.getVideoDetailList(videoid, 1, 100);//风行2
        }
 
        return null;
    }
 
    public VideoDetailInfo getLatestVideoDetail(String videoid, VideoResource vr) {
 
        int resourceId = Integer.parseInt(vr.getId());
 
        switch (resourceId) {
            case 13:
                return iqiyiService.getLatestVideoDetail(videoid);
            //爱奇艺
            case 14:
                return soHuService.getLatestVideoDetail(videoid);
            //搜狐
            case 15:
                return youKuService.getLatestVideoDetail(videoid);
            //优酷
            case 16:
                return pptvService.getLatestVideoDetail(videoid);
            //PPTV
            case 18:
                return leService.getLatestVideoDetail(videoid);
            //乐视
            case 19:
                return funTVService.getLatestVideoDetail(videoid);
            //风行
            case 24:
                return funTV2Service.getLatestVideoDetail(videoid);
            //风行2
        }
 
        return null;
    }
 
    public int getShowType(String videoid, VideoResource vr) {
        int resourceId = Integer.parseInt(vr.getId());
 
        switch (resourceId) {
            case 13:
                return iqiyiUtil.getShowType(videoid);
            //爱奇艺
            case 14:
                return soHuUtil.getShowType(videoid);
            //搜狐
            case 15:
                return youKuService.getShowType(videoid);
            //优酷
            case 16:
                return pptvService.getShowType(videoid);
            //PPTV
            case 18:
                return leService.getShowType(videoid);
            //乐视
            case 19:
                return funTVService.getShowType(videoid);
            //风行
            case 24:
                return funTV2Service.getShowType(videoid);
            //风行2
        }
 
        return 1;
    }
 
    @Cacheable(value = "homeCache", key = "'getPlayUrl'+'-'+#detailSystemId+'-'+#id+'-'+#type+'-'+#resourceid")
    public PlayUrl getPlayUrl(AcceptData acceptData, 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 == 15)
            return youKuService.getPlayUrl(detailSystemId, id, type, resourceid, videoid);
        else if (resourceid == 16)// PPTV
            return pptvService.getPlayUrl(detailSystemId, id, type, resourceid, videoid);
        else if (resourceid == 18)// 乐视
            return leService.getPlayUrl(detailSystemId, id, type, resourceid, videoid);
        else if (resourceid == 19)// 乐视
            return funTVService.getPlayUrl(detailSystemId, id, type, resourceid, videoid);
        else if (resourceid == FunTVUtil2.RESOURCE_ID)// 风行
            return funTV2Service.getPlayUrl(acceptData, detailSystemId, resourceid, id, videoid);
        return null;
    }
}