admin
2024-09-05 ab35ac8b769b2d9816dffb33a64f2c6f7bd5dd6e
src/main/java/com/yeshi/buwan/service/imp/juhe/FunTVService.java
@@ -9,6 +9,8 @@
import com.yeshi.buwan.domain.*;
import com.yeshi.buwan.domain.entity.PlayUrl;
import com.yeshi.buwan.domain.push.VideoPushHistory;
import com.yeshi.buwan.util.Constant;
import com.yeshi.buwan.util.config.SystemConfigUtil;
import com.yeshi.buwan.videos.funtv.FunTVUtil;
import com.yeshi.buwan.videos.funtv.entity.FunTVAlbum;
import com.yeshi.buwan.videos.funtv.entity.FunTVAlbumVideoMap;
@@ -67,6 +69,9 @@
    @Resource
    private ResourceVideoService resourceVideoService;
    @Resource
    private DetailSystemConfigService detailSystemConfigService;
    static Logger logger = Logger.getLogger(FunTVService.class);
@@ -341,31 +346,43 @@
                }
            }
            Serializable videoId = null;
            if (infoList != null && infoList.size() > 0 && isSame) {// 无需加入
                updateVideoInfo(info, video, p, isUpdate);
                videoId = video.getId();
            } else {// 需要新加入videoinfo
                Serializable id = addVideoInfo(info, p);
                videoId = addVideoInfo(info, p);
            }
                if (id != null) {
                    info.setId(id.toString());
            if (videoId != null) {
                info.setId(videoId.toString());
                try {
                    for (Integer ty : typeList) {
                        CategoryVideo cv = new CategoryVideo();
                        cv.setVideo(new VideoInfo(info.getId()));
                        cv.setVideoType(new VideoType(ty));
                        videoService.addCategoryVideo(cv);
                    }
                }catch(Exception e){
                    VideoFunTV vft = new VideoFunTV();
                    vft.setAid(p.getAid());
                    vft.setVideoId(Long.parseLong(info.getId()));
                    vft.setVid(null);
                    vft.setId(vft.createId());
                    saveVideoFunTV(vft);
                    videoResourceService.excuteSQL(String.format(
                            "insert into wk_resource_video(videoid,resourceid) values(%s,%s)", info.getId(), 19 + ""));
                }
                VideoFunTV vft = new VideoFunTV();
                vft.setAid(p.getAid());
                vft.setVideoId(Long.parseLong(info.getId()));
                vft.setVid(null);
                vft.setId(vft.createId());
                saveVideoFunTV(vft);
                List<VideoResource> videoResources =   videoResourceService.getResourceByVideo(info);
                for(VideoResource vr:videoResources){
                    if(vr.getId().equalsIgnoreCase(19+"")){
                       return;
                    }
                }
                videoResourceService.excuteSQL(String.format(
                        "insert into wk_resource_video(videoid,resourceid) values(%s,%s)", info.getId(), 19 + ""));
            }
        } catch (Exception e) {
@@ -375,12 +392,13 @@
    }
    public void addVideoToVideoInfo(final FunTVVideo p) {
        // 将数据转为VideoInfo对象
        VideoInfo info = FunTVUtil.convertVideoToVideoInfo(p);
        try {
            synchronized (p.getTitle().intern()) { // 发现了有重复生成VideoInfo.所有根据名称加个锁(一定要加intern())cxx
                // 根据名称/类型/年代查询
                List<VideoInfo> infoList = videoInfoDao.list("from VideoInfo vi where vi.name=?",
                        new Serializable[]{p.getTitle()});
                        new Serializable[]{info.getName()});
                if (infoList != null && infoList.size() > 0) {// 无需加入
                    // updateVideoInfo(info, infoList.get(0), p, genre);
                    return;
@@ -437,7 +455,7 @@
    }
    @SuppressWarnings("unchecked")
    public PlayUrl getPlayUrl(String detailSystemId, String id, String type, int resourceid, String videoId) {
    public PlayUrl getPlayUrl(String detailSystemId, String id, String type, int resourceid, String videoId, String channel, int versionCode) {
        logger.info(String.format("%s#%s#%s#%s", detailSystemId, resourceid, type, id));
        PlayUrl playUrl = new PlayUrl();
@@ -465,7 +483,14 @@
        playUrl.setParams(object.toString());
        if (fvideo.getPlayMUrl() != null)
            playUrl.setUrl(fvideo.getPlayMUrl().replace("alliance=2501", "malliance=0"));
        playUrl.setPlayType(1);// 全部跳转网页
        String firstOnLineValue =  detailSystemConfigService.getConfigValueByKey("first_online_versions",detailSystemId, versionCode);
        if( SystemConfigUtil.isFirstOnLine(firstOnLineValue, channel, versionCode)){
            // 首次上线跳转原生
            playUrl.setPlayType(2);// 原生跳转
        } else {
            playUrl.setPlayType(1);// 全部跳转网页
        }
        return playUrl;
    }
@@ -476,9 +501,9 @@
            if (vft != null && vft.getAid() != null) {// 按节目查找视频
                String aid = vft.getAid();
                FunTVAlbum album = funTVAlbumDao.get(aid);
                if (album == null) {
                    resourceVideoService.delete(videoid, FunTVUtil.RESOURCE_ID + "");
                }
//                if (album == null) {
//                    resourceVideoService.delete(videoid, FunTVUtil.RESOURCE_ID + "");
//                }
                final String type = album.getVideoType();
                Sort.Direction sort = Sort.Direction.ASC;
                if (type != null)
@@ -588,6 +613,7 @@
        // 查询出对应的VID与videoid
        final FunTVVideo video = getFunTVVideoByVid(vid);
        if (video != null) {
            funTVVideoDao.deleteByPrimaryKey(video.getVid());
            String videoId = (String) videoResourceDao.excute(new HibernateCallback<String>() {
                @SuppressWarnings("unchecked")
@@ -595,16 +621,8 @@
                    String videoid = null;
                    //TODO 处理
                    List<FunTVVideo> list = session
                            .createQuery("select m.video from FunTVAlbumVideoMap m where m.album.id=" + video.getId())
                            .list();
                    session.getTransaction().begin();
                    try {
                        for (FunTVVideo tv : list) {// 删除视频
                            session.delete(tv);
                        }
                        session.delete(video);// 删除专辑
                        List<VideoFunTV> ftlist = session
                                .createQuery(
                                        "from VideoFunTV vf where vf.vid=" + video.getVid())