admin
2021-01-25 d182390205a9828bd1091b06fa712e028004c687
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
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;
    }
 
}