admin
2021-07-30 19533a17aa55fafc70d0a385928e785cb50e1ebc
src/main/java/com/yeshi/buwan/service/imp/VideoInfoService.java
@@ -1,18 +1,20 @@
package com.yeshi.buwan.service.imp;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.*;
import javax.annotation.Resource;
import com.yeshi.buwan.util.HibernateSessionFactory;
import com.yeshi.buwan.util.StringUtil;
import com.yeshi.buwan.util.TimeUtil;
import com.yeshi.buwan.util.mq.CMQManager;
import com.yeshi.buwan.util.video.VideoConstant;
import org.hibernate.HibernateException;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.orm.hibernate4.HibernateCallback;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -43,9 +45,18 @@
    @Resource
    private VideoResourceService videoResourceService;
    @Resource
    private ClearService clearService;
    public VideoInfo getVideoInfo(String vid) {
        return videoInfoDao.find(VideoInfo.class, vid);
    }
    @Cacheable(value = "videoCache",key = "'getVideoInfoDetail-'+#vid")
    public VideoInfo getVideoInfoCache(String vid) {
        return videoInfoDao.find(VideoInfo.class, vid);
    }
    @SuppressWarnings("unchecked")
    public List<VideoInfo> simpleRandomVideoList(final int i) {
@@ -137,12 +148,12 @@
    /**
     * 是否存在相同的视频
     * 是否存在相同的视频(根据名称与上映时间)
     *
     * @param newVideoInfo
     * @return
     */
    public VideoInfo getExistSameVideo(VideoInfo newVideoInfo) {
    public VideoInfo getExistSameVideoWithTime(VideoInfo newVideoInfo) {
        int year = Integer.parseInt(newVideoInfo.getYear());
        List<VideoInfo> list = videoInfoDao.listByName(newVideoInfo.getName(), 0, 5);
        if (list != null && list.size() > 0)
@@ -184,6 +195,57 @@
    }
    /**
     * 根据名称与主演
     *
     * @param newVideoInfo
     * @return
     */
    public VideoInfo getExistSameVideoWithDirector(VideoInfo newVideoInfo) {
        List<VideoInfo> list = videoInfoDao.listByName(newVideoInfo.getName(), 0, 5);
        if (list != null && list.size() > 0) {
            if (VideoConstant.isMainCategory(newVideoInfo.getVideoType().getId())) {
                for (int i = 0; i < list.size(); i++) {
                    VideoInfo vi = list.get(i);
                    if (getSameDirectorOrActorCount(vi.getDirector(), newVideoInfo.getDirector()) > 0 || getSameDirectorOrActorCount(vi.getMainActor(), newVideoInfo.getMainActor()) > 0) {
//                        if (getSameDirectorOrActorCount(vi.getMainActor(), newVideoInfo.getMainActor()) > 0) {
                        //主分类一样
                        if (vi.getVideoType() != null && newVideoInfo.getVideoType() != null && vi.getVideoType().getId() == newVideoInfo.getVideoType().getId())
                            return list.get(i);
//                        }
                    }
                }
            } else {
                return list.get(0);
            }
        }
        return null;
    }
    private int getSameDirectorOrActorCount(String d1, String d2) {
        if (!StringUtil.isNullOrEmpty(d1) && !StringUtil.isNullOrEmpty(d2)) {
            List<String> d1List = new ArrayList<>();
            if (d1.contains("/")) {
                d1List.addAll(Arrays.asList(d1.trim().split("/")));
            } else {
                d1List.addAll(Arrays.asList(d1.trim().split(" ")));
            }
            List<String> d2List = new ArrayList<>();
            if (d2.contains("/"))
                d2List.addAll(Arrays.asList(d2.trim().split("/")));
            else
                d2List.addAll(Arrays.asList(d2.trim().split(" ")));
            d1List.retainAll(d2List);
            return d1List.size();
        }
        return 0;
    }
    public List<VideoInfo> listByVideoIds(List<String> videoIds) {
        return videoInfoDao.listByVideoIds(videoIds);
    }
@@ -202,4 +264,66 @@
        videoInfoDao.statisticVideoExtraInfo(videoId);
    }
    /**
     * 列表查询
     *
     * @param query
     * @return
     */
    public List<VideoInfo> list(VideoInfoDao.DaoQuery query) {
        return videoInfoDao.list(query);
    }
    public long count(VideoInfoDao.DaoQuery query) {
        return videoInfoDao.count(query);
    }
    public void updateVideoInfo(VideoInfo videoInfo) {
        VideoInfo oldVideo = videoInfoDao.find(VideoInfo.class, videoInfo.getId());
        if (oldVideo == null)
            return;
        videoInfoDao.updateSelective(videoInfo);
        //是否需要更新搜索引擎
        boolean needUpdateSolr = false;
        //tag变化
        if (videoInfo.getTag() != null && !videoInfo.getTag().equalsIgnoreCase(oldVideo.getTag())) {
            needUpdateSolr = true;
        }
        //名称变化
        if (videoInfo.getName() != null && !videoInfo.getName().equalsIgnoreCase(oldVideo.getName())) {
            needUpdateSolr = true;
        }
        //picture变化
        if (videoInfo.getHpicture() != null && !videoInfo.getHpicture().equalsIgnoreCase(oldVideo.getHpicture())) {
            needUpdateSolr = true;
        }
        if (videoInfo.getVpicture() != null && !videoInfo.getVpicture().equalsIgnoreCase(oldVideo.getVpicture())) {
            needUpdateSolr = true;
        }
        if (videoInfo.getPicture() != null && !videoInfo.getPicture().equalsIgnoreCase(oldVideo.getPicture())) {
            needUpdateSolr = true;
        }
        //视频类型发生变化
        if (videoInfo.getVideoType() != null && (oldVideo.getVideoType() == null || videoInfo.getVideoType().getId() != oldVideo.getVideoType().getId())) {
            needUpdateSolr = true;
        }
        //是否显示
        if (videoInfo.getShow() != null && !videoInfo.getShow().equalsIgnoreCase(oldVideo.getShow())) {
            needUpdateSolr = true;
        }
        if (needUpdateSolr) {
            CMQManager.getInstance().addSolrMsg(videoInfo.getId());
        }
    }
}