admin
2021-08-27 8fee151ffae0c3818694b7318583814bf92663e2
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
package com.yeshi.buwan.service.imp.juhe;
 
import com.yeshi.buwan.dao.VideoInfoDao;
import com.yeshi.buwan.dao.VideoResourceDao;
import com.yeshi.buwan.dao.juhe.funtv.FunTVAlbumDao;
import com.yeshi.buwan.dao.juhe.funtv.FunTVAlbumVideoMapDao;
import com.yeshi.buwan.dao.juhe.funtv.FunTVVideoDao;
import com.yeshi.buwan.dao.juhe.funtv.VideoFunTVNewDao;
import com.yeshi.buwan.domain.*;
import com.yeshi.buwan.domain.entity.PlayUrl;
import com.yeshi.buwan.domain.push.VideoPushHistory;
import com.yeshi.buwan.videos.funtv.FunTVUtil;
import com.yeshi.buwan.videos.funtv.entity.FunTVAlbum;
import com.yeshi.buwan.videos.funtv.entity.FunTVAlbumVideoMap;
import com.yeshi.buwan.videos.funtv.entity.FunTVVideo;
import com.yeshi.buwan.videos.funtv.entity.VideoFunTV;
import com.yeshi.buwan.service.imp.*;
import com.yeshi.buwan.service.imp.push.PushService;
import com.yeshi.buwan.util.StringUtil;
import net.sf.json.JSONObject;
import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.data.domain.Sort;
import org.springframework.orm.hibernate4.HibernateCallback;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.io.Serializable;
import java.math.BigInteger;
import java.util.*;
 
@Service
public class FunTVService implements IVideoDetail {
    @Resource
    private VideoFunTVNewDao videoFunTVNewDao;
 
    @Resource
    private FunTVVideoDao funTVVideoDao;
 
    @Resource
    private FunTVAlbumDao funTVAlbumDao;
 
    @Resource
    private FunTVAlbumVideoMapDao funTVAlbumVideoMapDao;
 
    @Resource
    private StatisticsService statisticsService;
    @Resource
    private PushService pushService;
 
    @Resource
    private VideoService videoService;
    @Resource
    private VideoResourceService videoResourceService;
    @Resource
    private BanQuanService banQuanService;
 
    @Resource
    private VideoInfoDao videoInfoDao;
 
    @Resource
    private VideoResourceDao videoResourceDao;
 
    @Resource
    private VideoManager videoManager;
 
    @Resource
    private ResourceVideoService resourceVideoService;
 
    static Logger logger = Logger.getLogger(FunTVService.class);
 
    //TODO 迁移走
    public FunTVAlbum getAlbumByAid(String aid) {
        FunTVAlbum album = funTVAlbumDao.get(aid);
        return album;
    }
 
    public FunTVVideo getFunTVVideoByVid(String vid) {
        FunTVVideo video = funTVVideoDao.get(vid);
        return video;
    }
 
    public void saveAlbum(FunTVAlbum album) {
        if (album.getUpdatetime() == null)
            album.setUpdatetime(new Date());
        funTVAlbumDao.save(album);
    }
 
    public void saveVideo(FunTVVideo video) {
        funTVVideoDao.save(video);
    }
 
    public void saveFunTVAlbum(FunTVAlbum pm, List<FunTVVideo> videoList) {
        FunTVAlbum dpm = getAlbumByAid(pm.getAid());
        if (dpm == null) {
            saveAlbum(pm);
        }
 
        for (FunTVVideo pv : videoList) {
            FunTVVideo dpv = getFunTVVideoByVid(pv.getVid());
            if (dpv == null) {
                saveVideo(pv);
            }
 
            FunTVAlbumVideoMap pvm = new FunTVAlbumVideoMap(pm.getAid(), pv.getVid());
            funTVAlbumVideoMapDao.save(pvm);
        }
    }
 
 
    @SuppressWarnings("unchecked")
    public void updateVideoInfo(final VideoInfo info, final VideoInfo video, final FunTVAlbum p,
                                final boolean isUpdate) {
        final VideoInfo vi = video;
        videoResourceDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
 
                vi.setTag(info.getTag());
                vi.setVideocount(p.getVideoList() != null ? p.getVideoList().size() : 1);
                vi.setLatestHpicture(info.getLatestHpicture());
                vi.setLatestVpicture(info.getLatestVpicture());
                try {
                    session.getTransaction().begin();
 
                    if (isUpdate)
                        vi.setUpdatetime(System.currentTimeMillis() + "");
                    session.update(vi);
 
                    VideoFunTV vft = new VideoFunTV();
                    vft.setAid(p.getAid());
                    vft.setVideoId(Long.parseLong(vi.getId()));
                    vft.setVid(null);
                    vft.setId(vft.createId());
 
 
                    long count = videoFunTVNewDao.countByVideoIdAndAid(Long.parseLong(vi.getId()), p.getAid());
                    if (count <= 0L) {// 加入
                        VideoFunTV ftv = new VideoFunTV();
                        ftv.setVideoId(Long.parseLong(vi.getId()));
                        ftv.setAid(p.getAid());
                        ftv.setId(ftv.createId());
                        videoFunTVNewDao.save(ftv);
                    }
 
                    Object obj = session.createSQLQuery(String.format(
                            "select count(*) from wk_resource_video rv where rv.videoid=%s and rv.resourceid=%s",
                            vi.getId(), 19 + "")).uniqueResult();
                    if (Integer.parseInt(obj + "") <= 0) {// 加入
                        session.createSQLQuery(String.format(
                                "insert into wk_resource_video(videoid,resourceid) values(%s,%s)", vi.getId(), 19 + ""))
                                .executeUpdate();
                    }
 
                    // 获取最新一集的信息
                    List<FunTVVideo> plist = funTVVideoDao.listByAid(p.getAid(), "num", Sort.Direction.DESC, 0, 1);
                    if (plist.size() > 0) {
                        List<VideoDetailInfo> detailList = new ArrayList<>();
                        detailList.add(FunTVUtil.convertFunTVVideoToVideoDetail(plist.get(0), p));
                        vi.setVideoDetailList(detailList);
                    }
                    session.flush();
                    session.getTransaction().commit();
                } catch (Exception e) {
                    session.getTransaction().rollback();
                    System.out.println("出错:" + e.getMessage());
                }
 
                return null;
            }
        });
        if (isUpdate) {
            if (vi.getVideoDetailList() != null && vi.getVideoDetailList().size() > 0) {
                VideoPushHistory vh = new VideoPushHistory();
                vh.setCreatetime(System.currentTimeMillis() + "");
                vh.setDetailId(vi.getVideoDetailList().get(0).getExtraId());
                vh.setResourceId(19 + "");
                vh.setTag(vi.getTag());
                vh.setType(vi.getVideoDetailList().get(0).getType());
                vh.setVideoInfo(vi);
                pushService.addVideoPushHistory(vh);
            }
        }
    }
 
    // 添加单个视频进入
    @SuppressWarnings("unchecked")
    public void updateVideoInfo(final VideoInfo info, final VideoInfo video, final FunTVVideo p, final String genre) {
        final VideoInfo vi = video;
        videoResourceDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
 
                vi.setTag(info.getTag());
                vi.setLatestHpicture(info.getLatestHpicture());
                vi.setLatestVpicture(info.getLatestVpicture());
                try {
                    session.getTransaction().begin();
                    session.update(vi);
                    VideoFunTV vft = new VideoFunTV();
                    vft.setAid(null);
                    vft.setVideoId(Long.parseLong(vi.getId()));
                    vft.setVid(p.getVid());
                    vft.setId(vft.createId());
 
                    long count = videoFunTVNewDao.countByVideoIdAndVid(Long.parseLong(vi.getId()), p.getVid());
 
                    if (count <= 0) {// 加入
                        VideoFunTV ftv = new VideoFunTV();
                        ftv.setVideoId(vft.getVideoId());
                        ftv.setVid(vft.getVid());
                        ftv.setId(ftv.createId());
                        videoFunTVNewDao.save(ftv);
                    }
 
                    Object obj = null;
 
                    List<Integer> typeList = FunTVUtil.getShortVideoType(p, p.getCate(), p.getSubCate());
                    if (typeList != null)
                        for (Integer ty : typeList) {
                            CategoryVideo cv = new CategoryVideo();
                            cv.setVideo(new VideoInfo(vi.getId()));
                            cv.setVideoType(new VideoType(ty));
                            obj = session
                                    .createQuery(
                                            "select count(*)  from CategoryVideo cv where cv.videoType.id=? and cv.video.id=?")
                                    .setParameter(0, (long) ty).setParameter(1, vi.getId()).uniqueResult();
                            if (Integer.parseInt(obj + "") <= 0)
                                videoService.addCategoryVideo(cv);
                        }
 
                    obj = session.createQuery(String.format(
                            "select count(*) from ResourceVideo rv where rv.video.id=%s and rv.resource.id=%s",
                            vi.getId(), 19 + "")).uniqueResult();
                    if (Integer.parseInt(obj + "") <= 0) {// 加入
                        ResourceVideo rv = new ResourceVideo();
                        rv.setResource(new VideoResource(19 + ""));
                        rv.setVideo(new VideoInfo(vi.getId()));
                        session.createSQLQuery(String.format(
                                "insert into wk_resource_video(videoid,resourceid) values(%s,%s)", vi.getId(), 19 + ""))
                                .executeUpdate();
                    }
                    session.flush();
                    session.getTransaction().commit();
                } catch (Exception e) {
                    System.out.println("出错:" + e.getMessage());
                }
 
                return null;
            }
        });
 
    }
 
    public Serializable addVideoInfo(VideoInfo info, FunTVAlbum p) {
        Serializable id = videoInfoDao.save(info);
        return id;
    }
 
    public Serializable addVideoInfo(VideoInfo info, FunTVVideo p) {
        Serializable id = videoInfoDao.save(info);
        return id;
    }
 
    public void saveVideoFunTV(VideoFunTV vyk) {
        try {
            if (vyk.getId() == null)
                vyk.setId(vyk.createId());
            videoFunTVNewDao.save(vyk);
        } catch (Exception e) {
 
        }
 
    }
 
    // 错误
    public void addPlayStatistics(String detailSystemId, String id) {
        List<VideoFunTV> list = videoFunTVNewDao.listByVid(id);
        if (list != null && list.size() > 0) {
            statisticsService.addStatistics(detailSystemId, list.get(0).getVideoId() + "");
        } else {
            list = videoFunTVNewDao.listByAid(id);
            if (list != null && list.size() > 0)
                statisticsService.addStatistics(detailSystemId, list.get(0).getVideoId() + "");
        }
    }
 
 
    public VideoDetailInfo getLatestVideoDetail(String videoid) {
        List<VideoFunTV> list = videoFunTVNewDao.listByVideoId(Long.parseLong(videoid));
        if (list != null && list.size() > 0) {
            final VideoFunTV vft = list.get(0);
            if (vft.getAid() != null) {// 按节目查找视频
                List<FunTVVideo> videoList = funTVVideoDao.listByAid(vft.getAid(), "num", Sort.Direction.DESC, 0, 1);
                List<VideoDetailInfo> detailList = new ArrayList<>();
                for (FunTVVideo pv : videoList) {
                    FunTVAlbum album = funTVAlbumDao.get(pv.getAid());
                    detailList.add(FunTVUtil.convertFunTVVideoToVideoDetail(pv, album));
                }
                return detailList.get(0);
            } else if (vft.getVid() != null) {// 单个视频----待定
            }
        }
 
        return null;
    }
 
    @SuppressWarnings("unchecked")
    public void addFunTVAlbumToVideoInfo(final FunTVAlbum p, final boolean isUpdate) {
 
        final VideoInfo info = FunTVUtil.convertFunTVAlbumToVideoInfo(p);
        // 类型计算
        final List<Integer> typeList = new ArrayList<>();
 
        int type = FunTVUtil.getFunTVAlbumType(p);
        boolean exist = false;
        for (Integer i : typeList)
            if (i == type)
                exist = true;
        if (!exist && type > 0)
            typeList.add(type);
 
        if (typeList.size() == 0)
            typeList.add(299);
 
        try {
            List<VideoInfo> infoList = videoInfoDao.list("from VideoInfo vi where vi.name=?",
                    new Serializable[]{p.getTitle()});
            boolean isSame = false;
            VideoInfo video = null;
            for (VideoInfo vi : infoList) {
                final VideoInfo newVi = vi;
                boolean issame = (Boolean) videoInfoDao.excute(new HibernateCallback<Boolean>() {
                    public Boolean doInHibernate(Session session) throws HibernateException {
                        return FunTVUtil.isSameVideo(typeList, p, newVi, session);
                    }
                });
                if (issame) {
                    isSame = true;
                    video = vi;
                    break;
                }
            }
 
            if (infoList != null && infoList.size() > 0 && isSame) {// 无需加入
                updateVideoInfo(info, video, p, isUpdate);
            } else {// 需要新加入videoinfo
                Serializable id = addVideoInfo(info, p);
 
                if (id != null) {
                    info.setId(id.toString());
 
                    for (Integer ty : typeList) {
                        CategoryVideo cv = new CategoryVideo();
                        cv.setVideo(new VideoInfo(info.getId()));
                        cv.setVideoType(new VideoType(ty));
                        videoService.addCategoryVideo(cv);
                    }
 
                    VideoFunTV vft = new VideoFunTV();
                    vft.setAid(p.getAid());
                    vft.setVideoId(Long.parseLong(info.getId()));
                    vft.setVid(null);
                    vft.setId(vft.createId());
                    saveVideoFunTV(vft);
 
                    videoResourceService.excuteSQL(String.format(
                            "insert into wk_resource_video(videoid,resourceid) values(%s,%s)", info.getId(), 19 + ""));
                }
            }
 
        } catch (Exception e) {
            e.printStackTrace();
        }
 
    }
 
    public void addVideoToVideoInfo(final FunTVVideo p) {
        VideoInfo info = FunTVUtil.convertVideoToVideoInfo(p);
        try {
            synchronized (p.getTitle().intern()) { // 发现了有重复生成VideoInfo.所有根据名称加个锁(一定要加intern())cxx
 
                List<VideoInfo> infoList = videoInfoDao.list("from VideoInfo vi where vi.name=?",
                        new Serializable[]{p.getTitle()});
                if (infoList != null && infoList.size() > 0) {// 无需加入
                    // updateVideoInfo(info, infoList.get(0), p, genre);
                    return;
                } else {// 需要新加入videoinfo
                    Serializable id = addVideoInfo(info, p);
                    List<Integer> typeList = new ArrayList<>();
                    typeList = FunTVUtil.getShortVideoType(p, p.getCate(), p.getSubCate());
 
                    if (typeList == null || typeList.size() <= 0)
                        return;
 
                    if (id != null) {
                        info.setId(id.toString());
 
                        for (Integer ty : typeList) {
                            CategoryVideo cv = new CategoryVideo();
                            cv.setVideo(new VideoInfo(info.getId()));
                            cv.setVideoType(new VideoType(ty));
                            videoService.addCategoryVideo(cv);
                        }
 
                        VideoFunTV vft = new VideoFunTV();
                        vft.setAid(null);
                        vft.setVideoId(Long.parseLong(info.getId()));
                        vft.setVid(p.getVid());
                        vft.setId(vft.createId());
                        saveVideoFunTV(vft);
                        videoResourceService.excuteSQL(
                                String.format("insert into wk_resource_video(videoid,resourceid) values(%s,%s)",
                                        info.getId(), 19 + ""));
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
 
    }
 
    public int getShowType(String videoId) {
        List<VideoFunTV> list = videoFunTVNewDao.listByVideoId(Long.parseLong(videoId));
        if (list != null && list.size() > 0) {
            if (list.get(0) != null) {
                FunTVAlbum album = funTVAlbumDao.get(list.get(0).getAid());
 
                if (album.getVideoType().contains("电视剧") || album.getVideoType().contains("动漫"))
                    return 2;
            } else {
                return 1;
            }
        }
 
        return 1;
    }
 
    @SuppressWarnings("unchecked")
    public PlayUrl getPlayUrl(String detailSystemId, String id, String type, int resourceid, String videoId) {
        logger.info(String.format("%s#%s#%s#%s", detailSystemId, resourceid, type, id));
        PlayUrl playUrl = new PlayUrl();
 
        List<VideoResource> list = videoResourceDao.list("from VideoResource vr where vr.id=" + resourceid);
        if (list != null && list.size() > 0)
            playUrl.setResource(list.get(0));
        if (StringUtil.isNullOrEmpty(videoId))
            addPlayStatistics(detailSystemId, id);
        else
            statisticsService.addStatistics(detailSystemId, videoId);
        if (!type.equalsIgnoreCase("funtvvideo")) {
            List<BigInteger> idList = (List<BigInteger>) videoResourceDao.sqlList(
                    "SELECT yk.`videoid` FROM wk_video_funtv yk WHERE yk.`albumid`= ( SELECT p.`aid` FROM wk_funtv_video v LEFT JOIN wk_funtv_album_video_map p ON p.`funvideoid`=v.`id`  WHERE v.`id`=?)",
                    new Serializable[]{id});
            if (idList != null && idList.size() > 0) {
                boolean isNeedWeb = banQuanService.isNeedWebPlay(detailSystemId, idList.get(0) + "");
                if (isNeedWeb)
                    playUrl.setPlayType(1);
            }
        }
 
        FunTVVideo fvideo = funTVVideoDao.get(id);
        JSONObject object = new JSONObject();
        object.put("vid", fvideo.getVid());
        playUrl.setParams(object.toString());
        if (fvideo.getPlayMUrl() != null)
            playUrl.setUrl(fvideo.getPlayMUrl().replace("alliance=2501", "malliance=0"));
        playUrl.setPlayType(1);// 全部跳转网页
        return playUrl;
    }
 
    public List<VideoDetailInfo> getVideoDetailList(String videoid, int page, int pageSize) {
        List<VideoFunTV> list = videoFunTVNewDao.listByVideoId(Long.parseLong(videoid));
        if (list != null && list.size() > 0) {
            final VideoFunTV vft = list.get(0);
            if (vft != null && vft.getAid() != null) {// 按节目查找视频
                String aid = vft.getAid();
                FunTVAlbum album = funTVAlbumDao.get(aid);
                if (album == null) {
                    resourceVideoService.delete(videoid, FunTVUtil.RESOURCE_ID + "");
                }
                final String type = album.getVideoType();
                Sort.Direction sort = Sort.Direction.ASC;
                if (type != null)
                    if (type.contains("电影")) {
                        sort = Sort.Direction.DESC;
                    } else if (type.contains("电视剧")) {
                        sort = Sort.Direction.ASC;
                    } else if (type.contains("综艺")) {
                        sort = Sort.Direction.DESC;
                    } else if (type.contains("动漫")) {
                        sort = Sort.Direction.ASC;
                    } else
                        sort = Sort.Direction.DESC;
 
 
                List<FunTVVideo> videoList = funTVVideoDao.listByAid(aid, "num", sort, (page - 1) * pageSize, pageSize);
                if (album == null && videoList.size() > 0) {//处理电影
                    album = new FunTVAlbum();
                    album.setTitle(videoList.get(0).getTitle());
                    album.setVideoType(videoList.get(0).getCate());
                }
 
                List<VideoDetailInfo> detailList = new ArrayList<>();
                for (FunTVVideo pv : videoList)
                    detailList.add(FunTVUtil.convertFunTVVideoToVideoDetail(pv, album));
                return detailList;
            } else if (vft.getVid() != null) {// 单个视频
                FunTVVideo pv = funTVVideoDao.get(vft.getVid());
                List<VideoDetailInfo> detailList = new ArrayList<>();
                VideoDetailInfo detail = new VideoDetailInfo();
                detail.setId(Long.parseLong(pv.getVid()));
                detail.setExtraId(pv.getId() + "");
                detail.setName(pv.getTitle());
                detail.setTag(pv.getDesc());
                detail.setType("funtvvideo");
                List<VideoUrl> urlList = new ArrayList<>();
                VideoUrl vu = new VideoUrl();
                vu.setAdmin(null);
                vu.setBaseUrl(pv.getPlayUrl());
                vu.setInvalid(0 + "");
                vu.setResource(new VideoResource("19"));
                vu.setUrl(pv.getPlayMUrl());
                urlList.add(vu);
                detail.setUrls(urlList);
                detailList.add(detail);
                return detailList;
            }
        }else{//删除来源
            resourceVideoService.delete(videoid,FunTVUtil.RESOURCE_ID+"");
        }
 
        return null;
    }
 
    public FunTVVideo getLatestFunTVVideo(String programid) {
        FunTVVideo video = funTVVideoDao.getLatestVideo(programid);
        return video;
    }
 
    public void deleteVideoByAid(String aid) {
        // 查询出对应的VID与videoid
        final FunTVAlbum album = getAlbumByAid(aid);
 
        if (album != null) {
            String videoId = (String) videoResourceDao.excute(new HibernateCallback<String>() {
                @SuppressWarnings("unchecked")
                public String doInHibernate(Session session) throws HibernateException {
                    String videoid = null;
                    List<FunTVVideo> list = funTVVideoDao.listByAid(album.getAid(), 0, 1000);
                    session.getTransaction().begin();
                    try {
                        for (FunTVVideo tv : list) {// 删除视频
                            funTVVideoDao.delete(tv.getVid());
                        }
                        funTVAlbumDao.delete(album.getAid());// 删除专辑
                        List<VideoFunTV> ftlist = videoFunTVNewDao.listByAid(album.getAid());
 
                        if (ftlist.size() > 0) {
                            Object obj = session.createQuery(
                                    "select count(*) from ResourceVideo rv where rv.resource.id!=19 and rv.video.id="
                                            + ftlist.get(0).getVideoId())
                                    .uniqueResult();
                            if (Integer.parseInt(obj + "") <= 0) {
                                videoid = ftlist.get(0).getVideoId() + "";
                            }
                        }
                        for (VideoFunTV funTV : ftlist)
                            videoFunTVNewDao.delete(funTV.getId());
                        session.flush();
                        session.getTransaction().commit();
                    } catch (Exception e) {
                        session.getTransaction().rollback();
                    }
                    return videoid;
                }
            });
 
            if (videoId != null) {// 可以删除视频
                videoManager.deleteVideo(videoId);
            }
 
        }
 
    }
 
    public void deleteVideoByVid(String vid) {
        // 查询出对应的VID与videoid
        final FunTVVideo video = getFunTVVideoByVid(vid);
        if (video != null) {
            String videoId = (String) videoResourceDao.excute(new HibernateCallback<String>() {
 
                @SuppressWarnings("unchecked")
                public String doInHibernate(Session session) throws HibernateException {
                    String videoid = null;
 
                    //TODO 处理
                    List<FunTVVideo> list = session
                            .createQuery("select m.video from FunTVAlbumVideoMap m where m.album.id=" + video.getId())
                            .list();
                    session.getTransaction().begin();
                    try {
 
                        for (FunTVVideo tv : list) {// 删除视频
                            session.delete(tv);
                        }
                        session.delete(video);// 删除专辑
                        List<VideoFunTV> ftlist = session
                                .createQuery(
                                        "from VideoFunTV vf where vf.vid=" + video.getVid())
                                .list();
                        if (ftlist.size() > 0) {
                            Object obj = session.createQuery(
                                    "select count(*) from ResourceVideo rv where rv.resource.id!=19 and rv.video.id="
                                            + ftlist.get(0).getVideoId())
                                    .uniqueResult();
                            if (Integer.parseInt(obj + "") <= 0) {
                                videoid = ftlist.get(0).getVideoId() + "";
                            }
                        }
                        for (VideoFunTV funTV : ftlist) {
                            videoFunTVNewDao.delete(funTV.getId());
                        }
                        session.flush();
                        session.getTransaction().commit();
                    } catch (Exception e) {
                        session.getTransaction().rollback();
                    }
                    return videoid;
                }
            });
 
            if (videoId != null) {// 可以删除视频
                videoManager.deleteVideo(videoId);
            }
 
        }
 
    }
 
    public PlayUrl getPlayUrl(String detailSystemId, String resourceid, String type, String id) {
        return null;
    }
 
}