admin
2020-08-22 813d2cae75cbae3f216de5f493af643c5a560c82
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
package com.yeshi.buwan.service.imp;
 
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.hibernate.HibernateException;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate4.HibernateCallback;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import com.yeshi.buwan.dao.CategoryVideoDao;
import com.yeshi.buwan.dao.VideoInfoDao;
import com.yeshi.buwan.domain.CategoryVideo;
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.VideoType;
import com.yeshi.buwan.domain.VideoUrl;
import com.yeshi.buwan.domain.entity.PlayUrl;
 
@Service
public class VideoInfoService {
 
    @Autowired
    private VideoInfoDao dao;
 
    @Autowired
    private CategoryVideoDao cdao;
 
    @Autowired
    private ResourceVideoService resourceVideoService;
 
    @Resource
    private VideoResourceService videoResourceService;
 
    public VideoInfo getVideoInfo(String vid) {
        return dao.find(VideoInfo.class, vid);
    }
 
    @SuppressWarnings("unchecked")
    public List<VideoInfo> simpleRandomVideoList(final int i) {
        return (List<VideoInfo>) dao.excute(new HibernateCallback<List<VideoInfo>>() {
 
            @Override
            public List<VideoInfo> doInHibernate(Session session) throws HibernateException {
                SQLQuery query = session.createSQLQuery(
                        "SELECT v.* FROM wk_video_video v RIGHT JOIN (SELECT * FROM wk_recommend_category_cache WHERE videotypeid = 152 ORDER BY RAND() LIMIT 0,"
                                + i + ")  c ON c.videoid=v.id");
                query.addEntity(VideoInfo.class);
                return query.list();
            }
        });
    }
 
    public VideoInfo getVideoInfo(String name, VideoType videoType) {
        List<VideoInfo> list = dao.list(
                "select c.video from CategoryVideo c where c.video.name = ? and c.videoType.id = ?",
                new Serializable[] { name, videoType.getId() });
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
 
    @Transactional
    public void save(VideoInfo videoInfo) {
        dao.save(videoInfo);
        CategoryVideo ca = new CategoryVideo();
        ca.setVideo(videoInfo);
        ca.setVideoType(videoInfo.getVideoType());
        cdao.create(ca);
        List<VideoResource> resourceList = videoInfo.getResourceList();
        ResourceVideo rs = null;
        for (VideoResource videoResource : resourceList) {
            rs = new ResourceVideo();
            rs.setResource(videoResource);
            rs.setVideo(videoInfo);
            resourceVideoService.save(rs);
        }
    }
 
    public List<VideoDetailInfo> getVideoDetailList(String videoid, VideoResource vr) {
        VideoInfo find = dao.find(VideoInfo.class, videoid);
        if (find != null) {
            if (vr.getName().equals("AcFun")) {
                List<VideoDetailInfo> detailInfos = new ArrayList<VideoDetailInfo>();
                VideoDetailInfo vd = new VideoDetailInfo();
                vd.setVideo(find);
                vd.setIntroduction(find.getIntroduction());
                vd.setName(find.getName());
                vd.setTag("");
                vd.setType("acFunVideo");
                vd.setId(Long.parseLong(find.getId()));
                vd.setWatchCount(Long.parseLong(find.getWatchCount()));
                VideoUrl vurl = new VideoUrl();
                vurl.setResource(vr);
                vurl.setUrl(find.getBaseurl());
                vurl.setInvalid(0 + "");
                vurl.setBaseUrl(find.getBaseurl());
                List<VideoUrl> urls = new ArrayList<VideoUrl>();
                urls.add(vurl);
                vd.setUrls(urls);
                detailInfos.add(vd);
                return detailInfos;
            }
        }
 
        return null;
    }
 
    public PlayUrl getPlayUrl(String detailSystemId, String id, String type, int resourceid, String videoid) {
        if (type.equals("acFunVideo")) {
            PlayUrl playUrl = new PlayUrl();
            VideoResource videoResource = videoResourceService.getResource(resourceid + "");
            playUrl.setResource(videoResource);
            VideoInfo find = dao.find(VideoInfo.class, videoid);
            playUrl.setUrl(find.getBaseurl());
            playUrl.setPlayType(1);
            playUrl.setParams("");
            // 添加播放次数
            find.setWatchCount("" + (Integer.parseInt(find.getWatchCount()) + 1));
            dao.update(find);
            return playUrl;
        }
        return null;
    }
 
}