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;
|
}
|
|
|
}
|