package com.newvideo.service.imp;
|
|
import javax.annotation.Resource;
|
|
import com.newvideo.dao.CategoryVideoDao;
|
import com.newvideo.domain.CategoryVideo;
|
import com.newvideo.domain.VideoType;
|
import com.newvideo.util.JuHe.VideoConstant;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import com.newvideo.dao.VideoInfoDao;
|
import com.newvideo.domain.VideoInfo;
|
|
import java.util.List;
|
|
@Service
|
public class VideoInfoService {
|
|
@Autowired
|
private VideoInfoDao videoInfoDao;
|
|
@Autowired
|
private CategoryVideoDao categoryVideoDao;
|
|
@Autowired
|
private ResourceVideoService resourceVideoService;
|
|
@Resource
|
private VideoResourceService videoResourceService;
|
|
|
public VideoInfo getVideoInfo(String id) {
|
return videoInfoDao.find(VideoInfo.class, id);
|
}
|
|
/**
|
* 是否存在相同的视频
|
*
|
* @param newVideoInfo
|
* @return
|
*/
|
public VideoInfo getExistSameVideo(VideoInfo newVideoInfo) {
|
int year = Integer.parseInt(newVideoInfo.getYear());
|
List<VideoInfo> list = videoInfoDao.listByName(newVideoInfo.getName(), 0, 5);
|
if (list != null && list.size() > 0)
|
for (int i = 0; i < list.size(); i++) {
|
if (Math.abs(Integer.parseInt(list.get(i).getYear()) - year) < 2) {// 年份相差1年以下且属于同一个分类才归为一起
|
// 判断分类
|
if (VideoConstant.isMainCategory(newVideoInfo.getVideoType().getId())) {// 正片分类
|
List<CategoryVideo> cvList = categoryVideoDao.listByVideoId(list.get(i).getId());
|
boolean isS = false;
|
for (CategoryVideo cv : cvList) {
|
if (newVideoInfo.getVideoType().getId() == cv.getVideoType().getId()
|
|| (cv.getVideoType().getParent() != null && newVideoInfo.getVideoType().getId() ==
|
cv.getVideoType().getParent().getId())) {// 类型相同
|
return list.get(i);
|
}
|
}
|
} else // 不必比较分类--只要名称相同则判断为相同
|
{ // 判断上个是否为正片分类
|
List<CategoryVideo> typeList = categoryVideoDao.listByVideoId(list.get(i).getId());
|
boolean isZhengpian = false;
|
if (typeList != null)
|
for (CategoryVideo categoryVideo : typeList) {
|
VideoType ltype = categoryVideo.getVideoType();
|
if (VideoConstant.isMainCategory(ltype.getId())
|
|| (ltype.getParent() != null && VideoConstant.isMainCategory(ltype.getParent().getId()))) {
|
isZhengpian = true;
|
break;
|
}
|
}
|
|
if (!isZhengpian)
|
return list.get(i);
|
else
|
return null;
|
}
|
}
|
}
|
return null;
|
}
|
|
}
|