admin
2021-09-24 f788607ff771a47bc60d6a86e00b3433c40f3d2c
src/main/java/com/yeshi/buwan/service/imp/juhe/FunTV2ServiceImpl.java
@@ -6,24 +6,24 @@
import com.yeshi.buwan.dao.juhe.funtv.FunTVVideo2Dao;
import com.yeshi.buwan.dao.juhe.funtv.VideoFunTV2Dao;
import com.yeshi.buwan.dao.video.AlbumVideoMapDao;
import com.yeshi.buwan.domain.ResourceVideo;
import com.yeshi.buwan.domain.VideoDetailInfo;
import com.yeshi.buwan.domain.VideoInfo;
import com.yeshi.buwan.domain.VideoResource;
import com.yeshi.buwan.domain.entity.PlayUrl;
import com.yeshi.buwan.domain.system.DetailSystemConfig;
import com.yeshi.buwan.domain.video.AlbumVideoMap;
import com.yeshi.buwan.funtv.FunTVUtil2;
import com.yeshi.buwan.funtv.entity.FunTVAlbum2;
import com.yeshi.buwan.funtv.entity.FunTVShortVideo2;
import com.yeshi.buwan.funtv.entity.FunTVVideo2;
import com.yeshi.buwan.funtv.entity.VideoFunTV2;
import com.yeshi.buwan.service.imp.CategoryVideoService;
import com.yeshi.buwan.service.imp.ResourceVideoService;
import com.yeshi.buwan.service.imp.VideoInfoService;
import com.yeshi.buwan.service.imp.VideoResourceService;
import com.yeshi.buwan.videos.funtv.FunTVUtil2;
import com.yeshi.buwan.videos.funtv.entity.FunTVAlbum2;
import com.yeshi.buwan.videos.funtv.entity.FunTVShortVideo2;
import com.yeshi.buwan.videos.funtv.entity.FunTVVideo2;
import com.yeshi.buwan.videos.funtv.entity.VideoFunTV2;
import com.yeshi.buwan.service.imp.*;
import com.yeshi.buwan.service.inter.juhe.FunTV2Service;
import com.yeshi.buwan.util.StringUtil;
import com.yeshi.buwan.util.mq.CMQManager;
import com.yeshi.buwan.util.video.VideoConstant;
import com.yeshi.buwan.vo.AcceptData;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -63,6 +63,9 @@
    @Resource
    private VideoResourceService videoResourceService;
    @Resource
    private DetailSystemConfigService detailSystemConfigService;
    @Override
@@ -106,7 +109,7 @@
            }
        } else {//视频不存在
            //判断2个视频实体是否为同一视频
            VideoInfo oldVideo = videoInfoService.getExistSameVideo(newVideoInfo);
            VideoInfo oldVideo = videoInfoService.getExistSameVideoWithTime(newVideoInfo);
            if (oldVideo == null) {
                //添加视频
                Serializable id = videoInfoDao.save(newVideoInfo);
@@ -126,6 +129,7 @@
            //加入专辑视频映射
            AlbumVideoMap map = new AlbumVideoMap();
            map.setId(newVideoInfo.getId());
            map.setCreateTime(new Date());
            map.setVideoId(newVideoInfo.getId());
            map.setRootVideoType(newVideoInfo.getVideoType().getId());
@@ -151,29 +155,45 @@
        FunTVAlbum2 album2 = funTVAlbum2Dao.get(id);
        if (album2 == null)
            return null;
        List<FunTVVideo2> video2List = funTVVideo2Dao.listByMediaId(id);
        if (video2List != null) {
            Comparator<FunTVVideo2> cm = new Comparator<FunTVVideo2>() {
                @Override
                public int compare(FunTVVideo2 o1, FunTVVideo2 o2) {
                    return Integer.parseInt(o1.getNum()) - Integer.parseInt(o2.getNum());
                }
            };
            Collections.sort(video2List, cm);
        }
        List<FunTVVideo2> video2List = listAllEpisodeList(id);
        album2.setEpisodes(video2List);
        return album2;
    }
    private List<FunTVVideo2> getEpisodeList(String mediaId, int page, int pageSize) {
        List<FunTVVideo2> video2List = funTVVideo2Dao.listByMediaId(mediaId, (page - 1) * pageSize, pageSize);
        return video2List;
    }
    private List<FunTVVideo2> listAllEpisodeList(String mediaId) {
        int page = 1;
        int pageSize = 100;
        List<FunTVVideo2> video2List = new ArrayList<>();
        List<FunTVVideo2> tempList = new ArrayList<>();
        do {
            tempList = getEpisodeList(mediaId, page, pageSize);
            if (tempList != null)
                video2List.addAll(tempList);
            page++;
        } while (tempList != null && tempList.size() > 0);
        return video2List;
    }
    @Override
    public List<VideoDetailInfo> getVideoDetailList(String id) {
    public List<VideoDetailInfo> getVideoDetailList(String id, int page, int pageSize) {
        VideoFunTV2 videoFunTV2 = videoFunTV2Dao.selectByVideoId(id);
        if (videoFunTV2 == null)
            return null;
        FunTVAlbum2 album2 = getAlbumDetail(videoFunTV2.getMediaId());
        FunTVAlbum2 album2 = funTVAlbum2Dao.get(videoFunTV2.getMediaId());
        if (album2 == null)
            return null;
        List<FunTVVideo2> episodeList = getEpisodeList(album2.getId(), page, pageSize);
        List<VideoDetailInfo> list = new ArrayList<>();
        if (album2 != null && album2.getEpisodes() != null)
            for (FunTVVideo2 video2 : album2.getEpisodes())
        if (episodeList != null)
            for (FunTVVideo2 video2 : episodeList)
                list.add(FunTVUtil2.convertFunTVVideoToVideoDetail(video2, album2));
        return list;
    }
@@ -199,18 +219,65 @@
            return 1;
    }
    private int getPlayType(AcceptData acceptData, FunTVVideo2 video2) {
        //如果是正在上线的版本就用SDK播放,否则采用H5
        DetailSystemConfig config = detailSystemConfigService.getConfigByKey("funshion_sdk_player", acceptData.getDetailSystem(), acceptData.getVersion());
        //默认SDK播放
        if (config == null)
            return FunTVUtil2.PLAY_SDK;
        String channel = acceptData.getChannel();
        if (StringUtil.isNullOrEmpty(channel)) {
            channel = "qq";
        }
        channel = channel.toLowerCase().trim();
        JSONObject data = JSONObject.fromObject(config.getValue());
        JSONObject channelJSON = data.optJSONObject(channel);
        //渠道不存在就当做QQ渠道做处理
        if (channelJSON == null)
            channelJSON = data.optJSONObject("qq");
        if (channelJSON == null)
            return FunTVUtil2.PLAY_SDK;
        int version = channelJSON.optInt("version");
        if (acceptData.getVersion() < version) {
            //取设定值
            String type = channelJSON.optString("type");
            if ("html".equalsIgnoreCase(type)) {
                return FunTVUtil2.PLAY_HTML;
            } else if ("sdk".equalsIgnoreCase(type)) {
                return FunTVUtil2.PLAY_SDK;
            } else {
                return FunTVUtil2.PLAY_NONE;
            }
        } else {
            //取设定相反值
            String type = channelJSON.optString("type");
            if ("html".equalsIgnoreCase(type)) {
                return FunTVUtil2.PLAY_SDK;
            } else if ("sdk".equalsIgnoreCase(type)) {
                return FunTVUtil2.PLAY_HTML;
            } else {
                return FunTVUtil2.PLAY_NONE;
            }
        }
    }
    @Override
    public PlayUrl getPlayUrl(String detailSystemId, int resourceId, String id, String videoId) {
    public PlayUrl getPlayUrl(AcceptData acceptData, String detailSystemId, int resourceId, String id, String videoId) {
        FunTVVideo2 video2 = funTVVideo2Dao.get(id);
        VideoResource vr = videoResourceService.getResource(resourceId + "");
        int t = FunTVUtil2.getPlayType(video2);
        int t = getPlayType(acceptData, video2);
        PlayUrl pu = new PlayUrl();
        pu.setParams("");
        pu.setPlayType(t);
        pu.setResource(vr);
        pu.setAid(video2.getMediaId());
        pu.setVid(video2.getId());
        pu.setCode(video2.getCeCode());
        if (t == FunTVUtil2.PLAY_NONE) {
            pu.setUrl("");
        } else {
@@ -240,28 +307,11 @@
        VideoFunTV2 videoFunTV2 = videoFunTV2Dao.selectByMediaId(mediaId);
        if (videoFunTV2 == null)
            return;
        List<ResourceVideo> resourceVideoList = resourceVideoService.getResourceList(videoFunTV2.getVideoId() + "");
        for (int i = 0; i < resourceVideoList.size(); i++) {
            ResourceVideo rv = resourceVideoList.get(i);
            if (rv.getResource() != null && Integer.parseInt(rv.getResource().getId()) == FunTVUtil2.RESOURCE_ID) {
                //删除资源映射
                resourceVideoService.delete(rv);
                resourceVideoList.remove(i);
                i--;
            }
        }
        if (resourceVideoList.size() == 0) {
            //隐藏视频
            videoInfoService.hiddenVideo(videoFunTV2.getVideoId() + "");
            //更新搜索引擎
            CMQManager.getInstance().addSolrMsg(videoFunTV2.getVideoId() + "");
        }
        videoFunTV2Dao.deleteByVideoId(videoFunTV2.getVideoId());
        resourceVideoService.delete(videoFunTV2.getVideoId() + "", FunTVUtil2.RESOURCE_ID + "");
        //删除媒体与媒体对应的视频
        funTVAlbum2Dao.delete(mediaId);
        List<FunTVVideo2> video2List = funTVVideo2Dao.listByMediaId(mediaId);
        List<FunTVVideo2> video2List = listAllEpisodeList(mediaId);
        if (video2List != null)
            for (FunTVVideo2 video2 : video2List)
                funTVVideo2Dao.delete(video2.getId());