From ab35ac8b769b2d9816dffb33a64f2c6f7bd5dd6e Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期四, 05 九月 2024 17:05:55 +0800
Subject: [PATCH] 风行网页版爬虫

---
 src/main/java/com/yeshi/buwan/service/imp/juhe/FunTVService.java |   74 +++++++++++++++++++++++--------------
 1 files changed, 46 insertions(+), 28 deletions(-)

diff --git a/src/main/java/com/yeshi/buwan/service/imp/juhe/FunTVService.java b/src/main/java/com/yeshi/buwan/service/imp/juhe/FunTVService.java
index 327e301..b7851ad 100644
--- a/src/main/java/com/yeshi/buwan/service/imp/juhe/FunTVService.java
+++ b/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) {
+        // 灏嗘暟鎹浆涓篤ideoInfo瀵硅薄
         VideoInfo info = FunTVUtil.convertVideoToVideoInfo(p);
         try {
             synchronized (p.getTitle().intern()) { // 鍙戠幇浜嗘湁閲嶅鐢熸垚VideoInfo.鎵�鏈夋牴鎹悕绉板姞涓攣锛堜竴瀹氳鍔爄ntern()锛塩xx
-
+                // 鏍规嵁鍚嶇О/绫诲瀷/骞翠唬鏌ヨ
                 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涓巚ideoid
         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())

--
Gitblit v1.8.0