admin
2022-04-16 04f09e52ffd4681bdfd85e51acd3da0d1280c3d3
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
package com.yeshi.buwan.service.imp.video;
 
import com.yeshi.buwan.domain.*;
import com.yeshi.buwan.domain.video.InternetSearchVideo;
import com.yeshi.buwan.domain.video.VideoInfoV2;
import com.yeshi.buwan.service.imp.CategoryVideoService;
import com.yeshi.buwan.service.imp.ResourceVideoService;
import com.yeshi.buwan.service.imp.VideoInfoService;
import com.yeshi.buwan.service.imp.VideoTypeService;
import com.yeshi.buwan.service.inter.juhe.InternetSearchVideoService;
import com.yeshi.buwan.service.inter.video.VideoInfoV2Service;
import com.yeshi.buwan.service.inter.video.VideoV2ConvertService;
import com.yeshi.buwan.util.NumberUtil;
import com.yeshi.buwan.util.factory.VideoInfoFactory;
import com.yeshi.buwan.util.factory.vo.VideoInfoV2Factory;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import javax.lang.model.element.TypeParameterElement;
import java.util.ArrayList;
import java.util.List;
 
/**
 * @author hxh
 * @title: VideoV2ConvertServiceImpl
 * @description: TODO
 * @date 2022/3/17 15:34
 */
@Service
public class VideoV2ConvertServiceImpl implements VideoV2ConvertService {
 
    @Resource
    private VideoInfoV2Service videoInfoV2Service;
 
    @Resource
    private VideoInfoService videoInfoService;
 
    @Resource
    private InternetSearchVideoService internetSearchVideoService;
 
    @Resource
    private CategoryVideoService categoryVideoService;
 
    @Resource
    private VideoTypeService videoTypeService;
 
    @Resource
    private ResourceVideoService resourceVideoService;
 
 
    @Override
    public void asyncOldVideo(String videoId) throws Exception {
 
        if (videoInfoV2Service.selectById(videoId) != null) {
            throw new Exception("已经同步过");
        }
 
        VideoInfo videoInfo = null;
        if (NumberUtil.isNumeric(videoId)) {
            videoInfo = videoInfoService.getVideoInfo(videoId);
            if (videoInfo == null) {
                throw new Exception("视频不存在");
            }
 
            List<CategoryVideo> list = categoryVideoService.getCategoryList(videoId);
            List<VideoType> typeList = new ArrayList<>();
            for (CategoryVideo cv : list) {
                typeList.add(cv.getVideoType());
            }
            videoInfo.setTypeList(typeList);
 
            //获取根分类
            if (videoInfo.getVideoType() == null) {
                if (list != null && list.size() > 0) {
                    videoInfo.setVideoType(list.get(0).getVideoType());
                }
            }
 
            //获取资源列表
            List<ResourceVideo> rvList = resourceVideoService.getResourceList(videoId);
            List<VideoResource> rlist = new ArrayList<>();
            for (ResourceVideo rv : rvList) {
                rlist.add(rv.getResource());
            }
            videoInfo.setResourceList(rlist);
        } else {
            InternetSearchVideo internetSearchVideo = internetSearchVideoService.selectByPrimaryKey(videoId);
            if (internetSearchVideo == null) {
                throw new Exception("视频不存在");
            }
            String[] rs = internetSearchVideo.getResourceIds().split(",");
            List<VideoResource> rList = new ArrayList<>();
            for (String r : rs) {
                rList.add(new VideoResource(r.trim()));
            }
            VideoType videoType = videoTypeService.getVideoType(internetSearchVideo.getRootType());
            videoInfo = VideoInfoFactory.create(internetSearchVideo);
            videoInfo.setResourceList(rList);
            videoInfo.setVideoType(videoType);
        }
        VideoInfoV2 v2 = VideoInfoV2Factory.create(videoInfo);
        videoInfoV2Service.save(v2);
    }
}