admin
2025-02-20 f537abe9f3646c739beaf15076246a2f71a347e9
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.util.factory.vo;
 
import com.yeshi.buwan.domain.VideoInfo;
import com.yeshi.buwan.domain.VideoResource;
import com.yeshi.buwan.domain.VideoType;
import com.yeshi.buwan.domain.video.VideoInfoV2;
import com.yeshi.buwan.util.StringUtil;
import com.yeshi.buwan.util.TimeUtil;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * @author hxh
 * @title: VideoInfoV2Factory
 * @description: 新版视频信息工厂
 * @date 2022/3/17 10:32
 */
public class VideoInfoV2Factory {
    public static VideoInfoV2 create(VideoInfo video) {
        VideoInfoV2 v2 = new VideoInfoV2();
        v2.setId(video.getId());
        v2.setName(video.getName());
 
        VideoType rootType = getRootVideoType(video.getVideoType());
        if (rootType != null) {
            v2.setCategory(rootType.getName());
        }
        v2.setLeafCategorys(null);
        v2.setLeafCategoryIds(getLeafCategoryIds(video.getTypeList()));
 
        List<Long> resourceIds = new ArrayList<>();
        for (VideoResource r : video.getResourceList()) {
            resourceIds.add(Long.parseLong(r.getId()));
        }
        v2.setResourceIds(resourceIds);
        v2.setActors(getListFromString(video.getMainActor()));
        v2.setDirectors(getListFromString(video.getDirector()));
        //获取发布日期
        v2.setReleaseDate(getRealaseDate(video));
 
        v2.setYear(Integer.parseInt(video.getYear()));
        v2.setVpicture(video.getVpicture());
        v2.setHpicture(video.getHpicture());
        v2.setShow("1".equalsIgnoreCase(video.getShow()) ? true : false);
        v2.setScore(video.getScore());
        v2.setTag(video.getTag());
 
        VideoInfoV2.VideoUpdateInfo updateInfo = new VideoInfoV2.VideoUpdateInfo();
        updateInfo.setFinish("1".equalsIgnoreCase(video.getFinish()) ? true : false);
 
        v2.setUpdateInfo(updateInfo);
        v2.setCreateTime(new Date(video.getCreatetime()));
        if (video.getUpdatetime() != null) {
            v2.setUpdateTime(new Date(Long.parseLong(video.getUpdatetime())));
        }
        v2.setAreas(getListFromString(video.getArea()));
        v2.setContentType(video.getContentType());
        v2.setFeeType(video.getFree());
        return v2;
    }
 
    private static List<Integer> getLeafCategoryIds(List<VideoType> typeList) {
        List<Integer> tList = new ArrayList<>();
        if (typeList != null)
            for (VideoType vt : typeList) {
                tList.add(Integer.parseInt(vt.getId() + ""));
            }
        return tList;
    }
 
    private static Date getRealaseDate(VideoInfo video) {
        if (StringUtil.isNullOrEmpty(video.getYear())) {
            return null;
        }
 
        String date = video.getYear();
        if (StringUtil.isNullOrEmpty(video.getMonth())) {
            date += "-01";
        } else {
            if (video.getMonth().trim().length() == 1) {
                date += "-0" + video.getMonth();
            } else {
                date += "-" + video.getMonth();
            }
        }
 
        if (StringUtil.isNullOrEmpty(video.getDay())) {
            date += "-01";
        } else {
            if (video.getDay().trim().length() == 1) {
                date += "-0" + video.getDay().trim();
            } else {
                date += "-" + video.getDay().trim();
            }
        }
        return new Date(TimeUtil.convertGernalTime(date, "yyyy-MM-dd"));
    }
 
 
    private static VideoType getRootVideoType(VideoType type) {
        if (type == null) {
            return null;
        }
        while (type.getParent() != null) {
            type = type.getParent();
        }
        return type;
    }
 
    private static List<String> getListFromString(String st) {
        if (StringUtil.isNullOrEmpty(st)) {
            return new ArrayList<>();
        }
        String[] sts = null;
        if (st.contains(",")) {
            sts = st.split(",");
        } else {
            sts = st.split(" ");
        }
 
        List<String> list = new ArrayList<>();
        if (sts != null && sts.length > 0) {
            for (String s : sts) {
                if (!StringUtil.isNullOrEmpty(s)) {
                    list.add(s.trim());
                }
            }
        }
        return list;
    }
 
 
}