From f537abe9f3646c739beaf15076246a2f71a347e9 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期四, 20 二月 2025 16:57:55 +0800
Subject: [PATCH] IOS广告增加区域屏蔽

---
 src/main/java/com/yeshi/buwan/service/imp/juhe/FunTVService.java | 1170 ++++++++++++++++++++++++++++------------------------------
 1 files changed, 560 insertions(+), 610 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 f914345..9209ee8 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
@@ -1,713 +1,663 @@
 package com.yeshi.buwan.service.imp.juhe;
 
-import java.io.Serializable;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-
-import javax.annotation.Resource;
-
+import com.yeshi.buwan.dao.VideoInfoDao;
+import com.yeshi.buwan.dao.VideoResourceDao;
+import com.yeshi.buwan.dao.juhe.funtv.FunTVAlbumDao;
+import com.yeshi.buwan.dao.juhe.funtv.FunTVAlbumVideoMapDao;
+import com.yeshi.buwan.dao.juhe.funtv.FunTVVideoDao;
+import com.yeshi.buwan.dao.juhe.funtv.VideoFunTVNewDao;
+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;
+import com.yeshi.buwan.videos.funtv.entity.FunTVVideo;
+import com.yeshi.buwan.videos.funtv.entity.VideoFunTV;
+import com.yeshi.buwan.service.imp.*;
+import com.yeshi.buwan.service.imp.push.PushService;
+import com.yeshi.buwan.util.StringUtil;
+import net.sf.json.JSONObject;
 import org.apache.log4j.Logger;
 import org.hibernate.HibernateException;
 import org.hibernate.Session;
+import org.springframework.data.domain.Sort;
 import org.springframework.orm.hibernate4.HibernateCallback;
 import org.springframework.stereotype.Service;
 
-import com.yeshi.buwan.dao.VideoInfoDao;
-import com.yeshi.buwan.dao.VideoResourceDao;
-import com.yeshi.buwan.dao.juhe.FunTVAlbumDao;
-import com.yeshi.buwan.dao.juhe.FunTVAlbumVideoMapDao;
-import com.yeshi.buwan.dao.juhe.FunTVVideoDao;
-import com.yeshi.buwan.dao.juhe.VideoFunTVDao;
-import com.yeshi.buwan.domain.CategoryVideo;
-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.VideoType;
-import com.yeshi.buwan.domain.VideoUrl;
-import com.yeshi.buwan.domain.entity.PlayUrl;
-import com.yeshi.buwan.domain.push.VideoPushHistory;
-import com.yeshi.buwan.funtv.FunTVUtil;
-import com.yeshi.buwan.funtv.entity.FunTVAlbum;
-import com.yeshi.buwan.funtv.entity.FunTVAlbumVideoMap;
-import com.yeshi.buwan.funtv.entity.FunTVVideo;
-import com.yeshi.buwan.funtv.entity.VideoFunTV;
-import com.yeshi.buwan.service.imp.BanQuanService;
-import com.yeshi.buwan.service.imp.StatisticsService;
-import com.yeshi.buwan.service.imp.VideoManager;
-import com.yeshi.buwan.service.imp.VideoResourceService;
-import com.yeshi.buwan.service.imp.VideoService;
-import com.yeshi.buwan.service.imp.push.PushService;
-import com.yeshi.buwan.util.StringUtil;
-
-import net.sf.json.JSONObject;
+import javax.annotation.Resource;
+import java.io.Serializable;
+import java.math.BigInteger;
+import java.util.*;
 
 @Service
 public class FunTVService implements IVideoDetail {
-	Logger log = Logger.getLogger(FunTVService.class);
-	@Resource
-	private VideoFunTVDao videoFunTVDao;
-	@Resource
-	private FunTVVideoDao funTVVideoDao;
-	@Resource
-	private FunTVAlbumDao funTVAlbumDao;
-	@Resource
-	private FunTVAlbumVideoMapDao funTVAlbumVideoMapDao;
+    @Resource
+    private VideoFunTVNewDao videoFunTVNewDao;
 
-	@Resource
-	private StatisticsService statisticsService;
-	@Resource
-	private PushService pushService;
+    @Resource
+    private FunTVVideoDao funTVVideoDao;
 
-	@Resource
-	private VideoService videoService;
-	@Resource
-	private VideoResourceService videoResourceService;
-	@Resource
-	private BanQuanService banQuanService;
+    @Resource
+    private FunTVAlbumDao funTVAlbumDao;
 
-	@Resource
-	private VideoInfoDao videoInfoDao;
+    @Resource
+    private FunTVAlbumVideoMapDao funTVAlbumVideoMapDao;
 
-	@Resource
-	private VideoResourceDao videoResourceDao;
+    @Resource
+    private StatisticsService statisticsService;
+    @Resource
+    private PushService pushService;
 
-	@Resource
-	private VideoManager videoManager;
+    @Resource
+    private VideoService videoService;
+    @Resource
+    private VideoResourceService videoResourceService;
+    @Resource
+    private BanQuanService banQuanService;
 
-	static Logger logger = Logger.getLogger(FunTVService.class);
+    @Resource
+    private VideoInfoDao videoInfoDao;
 
-	public FunTVVideo getFunTVVideo(long id) {
-		return funTVVideoDao.find(FunTVVideo.class, id);
-	}
+    @Resource
+    private VideoResourceDao videoResourceDao;
 
-	public Serializable saveSigleAlbum(FunTVAlbum pm) {
-		return funTVAlbumDao.save(pm);
-	}
+    @Resource
+    private VideoManager videoManager;
 
-	public Serializable saveFunTVVideo(FunTVVideo pv) {
-		return funTVVideoDao.save(pv);
-	}
+    @Resource
+    private ResourceVideoService resourceVideoService;
 
-	public void saveFunTVVideoMap(FunTVAlbumVideoMap pvm) {
-		funTVAlbumVideoMapDao.create(pvm);
-	}
+    @Resource
+    private DetailSystemConfigService detailSystemConfigService;
 
-	public FunTVAlbum getAlbumByAid(String aid) {
-		List<FunTVAlbum> list = funTVAlbumDao.list("from FunTVAlbum a where a.aid=" + aid);
-		if (list != null && list.size() > 0)
-			return list.get(0);
-		else
-			return null;
-	}
+    static Logger logger = Logger.getLogger(FunTVService.class);
 
-	public FunTVVideo getFunTVVideoByVid(String vid) {
-		List<FunTVVideo> list = funTVVideoDao.list("from FunTVVideo a where a.vid=" + vid);
-		if (list != null && list.size() > 0)
-			return list.get(0);
-		else
-			return null;
-	}
+    //TODO 杩佺Щ璧�
+    public FunTVAlbum getAlbumByAid(String aid) {
+        FunTVAlbum album = funTVAlbumDao.get(aid);
+        return album;
+    }
 
-	public void saveFunTVAlbum(FunTVAlbum pm, List<FunTVVideo> videoList) {
-		try {
-			FunTVAlbum dpm = getAlbumByAid(pm.getAid());
-			if (dpm == null) {
-				Serializable pid = saveSigleAlbum(pm);
-				if (pid != null)
-					pm.setId(Long.parseLong(pid + ""));
-			} else {
-				pm.setId(dpm.getId());
-			}
+    public FunTVVideo getFunTVVideoByVid(String vid) {
+        FunTVVideo video = funTVVideoDao.get(vid);
+        return video;
+    }
 
-		} catch (Exception e) {
-			if (!e.getMessage().contains("Duplicate")) {
-				log.error(e.getMessage());
-			}
-		}
+    public void saveAlbum(FunTVAlbum album) {
+        if (album.getUpdatetime() == null)
+            album.setUpdatetime(new Date());
+        funTVAlbumDao.save(album);
+    }
 
-		for (FunTVVideo pv : videoList) {
-			try {
-				FunTVVideo dpv = getFunTVVideoByVid(pv.getVid());
+    public void saveVideo(FunTVVideo video) {
+        funTVVideoDao.save(video);
+    }
 
-				if (dpv == null) {
-					Serializable id = saveFunTVVideo(pv);
-					pv.setId(Long.parseLong(id + ""));
-				} else
-					pv.setId(dpv.getId());
-			} catch (Exception e) {
-				if (!e.getMessage().contains("Duplicate")) {
-					log.error(e.getMessage());
-				}
-			}
+    public void saveFunTVAlbum(FunTVAlbum pm, List<FunTVVideo> videoList) {
+        FunTVAlbum dpm = getAlbumByAid(pm.getAid());
+        if (dpm == null) {
+            saveAlbum(pm);
+        }
 
-			FunTVAlbumVideoMap pvm = new FunTVAlbumVideoMap();
-			pvm.setAlbum(pm);
-			pvm.setVideo(pv);
-			try {
-				saveFunTVVideoMap(pvm);
-			} catch (Exception e) {
-				if (!e.getMessage().contains("Duplicate")) {
-					log.error(e.getMessage());
-				}
-			}
-		}
-	}
+        for (FunTVVideo pv : videoList) {
+            FunTVVideo dpv = getFunTVVideoByVid(pv.getVid());
+            if (dpv == null) {
+                saveVideo(pv);
+            }
 
-	public void saveVideo(FunTVVideo video) {
-		try {
-			if (funTVVideoDao.find(FunTVVideo.class, video.getId()) == null)
-				saveFunTVVideo(video);
-		} catch (Exception e) {
-			if (!e.getMessage().contains("Duplicate")) {
-				log.error(e.getMessage());
-			}
-		}
-	}
+            FunTVAlbumVideoMap pvm = new FunTVAlbumVideoMap(pm.getAid(), pv.getVid());
+            funTVAlbumVideoMapDao.save(pvm);
+        }
+    }
 
-	@SuppressWarnings("unchecked")
-	public void updateVideoInfo(final VideoInfo info, final VideoInfo video, final FunTVAlbum p,
-			final boolean isUpdate) {
-		final VideoInfo vi = video;
-		videoFunTVDao.excute(new HibernateCallback() {
-			public Object doInHibernate(Session session) throws HibernateException {
 
-				vi.setTag(info.getTag());
-				vi.setVideocount(p.getVideoList() != null ? p.getVideoList().size() : 1);
-				vi.setLatestHpicture(info.getLatestHpicture());
-				vi.setLatestVpicture(info.getLatestVpicture());
-				try {
-					session.getTransaction().begin();
+    @SuppressWarnings("unchecked")
+    public void updateVideoInfo(final VideoInfo info, final VideoInfo video, final FunTVAlbum p,
+                                final boolean isUpdate) {
+        final VideoInfo vi = video;
+        videoResourceDao.excute(new HibernateCallback() {
+            public Object doInHibernate(Session session) throws HibernateException {
 
-					if (isUpdate)
-						vi.setUpdatetime(System.currentTimeMillis() + "");
-					session.update(vi);
+                vi.setTag(info.getTag());
+                vi.setVideocount(p.getVideoList() != null ? p.getVideoList().size() : 1);
+                vi.setLatestHpicture(info.getLatestHpicture());
+                vi.setLatestVpicture(info.getLatestVpicture());
+                try {
+                    session.getTransaction().begin();
 
-					VideoFunTV vft = new VideoFunTV();
-					vft.setAlbum(new FunTVAlbum(p.getId()));
-					vft.setVideo(new VideoInfo(vi.getId()));
-					vft.setTvVideo(null);
-					Object obj = session
-							.createQuery("select count(*)  from VideoFunTV vyk where vyk.video.id=? and vyk.album.id=?")
-							.setParameter(0, vi.getId()).setParameter(1, p.getId()).uniqueResult();
-					if (Integer.parseInt(obj + "") <= 0) {// 鍔犲叆
-						// session.persist(vyk);
-						session.createSQLQuery(
-								String.format("insert into wk_video_funtv (videoid, albumid) values (%s, '%s')",
-										vft.getVideo().getId(), vft.getAlbum().getId()))
-								.executeUpdate();
-					}
+                    if (isUpdate)
+                        vi.setUpdatetime(System.currentTimeMillis() + "");
+                    session.update(vi);
 
-					obj = session.createSQLQuery(String.format(
-							"select count(*) from wk_resource_video rv where rv.videoid=%s and rv.resourceid=%s",
-							vi.getId(), 19 + "")).uniqueResult();
-					if (Integer.parseInt(obj + "") <= 0) {// 鍔犲叆
+                    VideoFunTV vft = new VideoFunTV();
+                    vft.setAid(p.getAid());
+                    vft.setVideoId(Long.parseLong(vi.getId()));
+                    vft.setVid(null);
+                    vft.setId(vft.createId());
 
-						session.createSQLQuery(String.format(
-								"insert into wk_resource_video(videoid,resourceid) values(%s,%s)", vi.getId(), 19 + ""))
-								.executeUpdate();
-					}
 
-					// 鑾峰彇鏈�鏂颁竴闆嗙殑淇℃伅
-					List<FunTVVideo> plist = session
-							.createQuery(
-									"select map.video from FunTVAlbumVideoMap map where map.album.id=? order by map.video.num  desc")
-							.setParameter(0, p.getId()).setFirstResult(0).setMaxResults(1).list();
-					if (plist.size() > 0) {
-						List<VideoDetailInfo> detailList = new ArrayList<VideoDetailInfo>();
-						detailList.add(FunTVUtil.convertFunTVVideoToVideoDetail(plist.get(0), p));
-						vi.setVideoDetailList(detailList);
-					}
-					session.flush();
-					session.getTransaction().commit();
-				} catch (Exception e) {
-					session.getTransaction().rollback();
-					System.out.println("鍑洪敊:" + e.getMessage());
-				}
+                    long count = videoFunTVNewDao.countByVideoIdAndAid(Long.parseLong(vi.getId()), p.getAid());
+                    if (count <= 0L) {// 鍔犲叆
+                        VideoFunTV ftv = new VideoFunTV();
+                        ftv.setVideoId(Long.parseLong(vi.getId()));
+                        ftv.setAid(p.getAid());
+                        ftv.setId(ftv.createId());
+                        videoFunTVNewDao.save(ftv);
+                    }
 
-				return null;
-			}
-		});
-		if (isUpdate) {
-			if (vi.getVideoDetailList() != null && vi.getVideoDetailList().size() > 0) {
-				VideoPushHistory vh = new VideoPushHistory();
-				vh.setCreatetime(System.currentTimeMillis() + "");
-				vh.setDetailId(vi.getVideoDetailList().get(0).getExtraId());
-				vh.setResourceId(19 + "");
-				vh.setTag(vi.getTag());
-				vh.setType(vi.getVideoDetailList().get(0).getType());
-				vh.setVideoInfo(vi);
-				pushService.addVideoPushHistory(vh);
-			}
-		}
-	}
+                    Object obj = session.createSQLQuery(String.format(
+                            "select count(*) from wk_resource_video rv where rv.videoid=%s and rv.resourceid=%s",
+                            vi.getId(), 19 + "")).uniqueResult();
+                    if (Integer.parseInt(obj + "") <= 0) {// 鍔犲叆
+                        session.createSQLQuery(String.format(
+                                "insert into wk_resource_video(videoid,resourceid) values(%s,%s)", vi.getId(), 19 + ""))
+                                .executeUpdate();
+                    }
 
-	// 娣诲姞鍗曚釜瑙嗛杩涘叆
-	@SuppressWarnings("unchecked")
-	public void updateVideoInfo(final VideoInfo info, final VideoInfo video, final FunTVVideo p, final String genre) {
-		final VideoInfo vi = video;
-		videoFunTVDao.excute(new HibernateCallback() {
-			public Object doInHibernate(Session session) throws HibernateException {
+                    // 鑾峰彇鏈�鏂颁竴闆嗙殑淇℃伅
+                    List<FunTVVideo> plist = funTVVideoDao.listByAid(p.getAid(), "num", Sort.Direction.DESC, 0, 1);
+                    if (plist.size() > 0) {
+                        List<VideoDetailInfo> detailList = new ArrayList<>();
+                        detailList.add(FunTVUtil.convertFunTVVideoToVideoDetail(plist.get(0), p));
+                        vi.setVideoDetailList(detailList);
+                    }
+                    session.flush();
+                    session.getTransaction().commit();
+                } catch (Exception e) {
+                    session.getTransaction().rollback();
+                    System.out.println("鍑洪敊:" + e.getMessage());
+                }
 
-				vi.setTag(info.getTag());
-				vi.setLatestHpicture(info.getLatestHpicture());
-				vi.setLatestVpicture(info.getLatestVpicture());
-				try {
-					session.getTransaction().begin();
-					session.update(vi);
-					VideoFunTV vft = new VideoFunTV();
-					vft.setAlbum(null);
-					vft.setVideo(new VideoInfo(vi.getId()));
-					vft.setTvVideo(new FunTVVideo(p.getId()));
-					Object obj = session
-							.createQuery(
-									"select count(*)  from VideoFunTV vft where vft.video.id=? and vft.tvVideo.id=?")
-							.setParameter(0, vi.getId()).setParameter(1, p.getId()).uniqueResult();
-					if (Integer.parseInt(obj + "") <= 0) {// 鍔犲叆
-						session.createSQLQuery(
-								String.format("insert into wk_video_funtv (videoid, tvvideoid) values (%s, '%s')",
-										vft.getVideo().getId(), vft.getTvVideo().getId()))
-								.executeUpdate();
-					}
+                return null;
+            }
+        });
+        if (isUpdate) {
+            if (vi.getVideoDetailList() != null && vi.getVideoDetailList().size() > 0) {
+                VideoPushHistory vh = new VideoPushHistory();
+                vh.setCreatetime(System.currentTimeMillis() + "");
+                vh.setDetailId(vi.getVideoDetailList().get(0).getExtraId());
+                vh.setResourceId(19 + "");
+                vh.setTag(vi.getTag());
+                vh.setType(vi.getVideoDetailList().get(0).getType());
+                vh.setVideoInfo(vi);
+                pushService.addVideoPushHistory(vh);
+            }
+        }
+    }
 
-					List<Integer> typeList = FunTVUtil.getShortVideoType(p, p.getCate(), p.getSubCate());
-					if (typeList != null)
-						for (Integer ty : typeList) {
-							CategoryVideo cv = new CategoryVideo();
-							cv.setVideo(new VideoInfo(vi.getId()));
-							cv.setVideoType(new VideoType(ty));
-							obj = session
-									.createQuery(
-											"select count(*)  from CategoryVideo cv where cv.videoType.id=? and cv.video.id=?")
-									.setParameter(0, (long) ty).setParameter(1, vi.getId()).uniqueResult();
-							if (Integer.parseInt(obj + "") <= 0)
-								videoService.addCategoryVideo(cv);
-						}
+    // 娣诲姞鍗曚釜瑙嗛杩涘叆
+    @SuppressWarnings("unchecked")
+    public void updateVideoInfo(final VideoInfo info, final VideoInfo video, final FunTVVideo p, final String genre) {
+        final VideoInfo vi = video;
+        videoResourceDao.excute(new HibernateCallback() {
+            public Object doInHibernate(Session session) throws HibernateException {
 
-					obj = session.createQuery(String.format(
-							"select count(*) from ResourceVideo rv where rv.video.id=%s and rv.resource.id=%s",
-							vi.getId(), 19 + "")).uniqueResult();
-					if (Integer.parseInt(obj + "") <= 0) {// 鍔犲叆
-						ResourceVideo rv = new ResourceVideo();
-						rv.setResource(new VideoResource(19 + ""));
-						rv.setVideo(new VideoInfo(vi.getId()));
-						session.createSQLQuery(String.format(
-								"insert into wk_resource_video(videoid,resourceid) values(%s,%s)", vi.getId(), 19 + ""))
-								.executeUpdate();
-					}
-					session.flush();
-					session.getTransaction().commit();
-				} catch (Exception e) {
-					System.out.println("鍑洪敊:" + e.getMessage());
-				}
+                vi.setTag(info.getTag());
+                vi.setLatestHpicture(info.getLatestHpicture());
+                vi.setLatestVpicture(info.getLatestVpicture());
+                try {
+                    session.getTransaction().begin();
+                    session.update(vi);
+                    VideoFunTV vft = new VideoFunTV();
+                    vft.setAid(null);
+                    vft.setVideoId(Long.parseLong(vi.getId()));
+                    vft.setVid(p.getVid());
+                    vft.setId(vft.createId());
 
-				return null;
-			}
-		});
+                    long count = videoFunTVNewDao.countByVideoIdAndVid(Long.parseLong(vi.getId()), p.getVid());
 
-	}
+                    if (count <= 0) {// 鍔犲叆
+                        VideoFunTV ftv = new VideoFunTV();
+                        ftv.setVideoId(vft.getVideoId());
+                        ftv.setVid(vft.getVid());
+                        ftv.setId(ftv.createId());
+                        videoFunTVNewDao.save(ftv);
+                    }
 
-	public Serializable addVideoInfo(VideoInfo info, FunTVAlbum p) {
-		Serializable id = videoInfoDao.save(info);
-		return id;
-	}
+                    Object obj = null;
 
-	public Serializable addVideoInfo(VideoInfo info, FunTVVideo p) {
-		Serializable id = videoInfoDao.save(info);
-		return id;
-	}
+                    List<Integer> typeList = FunTVUtil.getShortVideoType(p, p.getCate(), p.getSubCate());
+                    if (typeList != null)
+                        for (Integer ty : typeList) {
+                            CategoryVideo cv = new CategoryVideo();
+                            cv.setVideo(new VideoInfo(vi.getId()));
+                            cv.setVideoType(new VideoType(ty));
+                            obj = session
+                                    .createQuery(
+                                            "select count(*)  from CategoryVideo cv where cv.videoType.id=? and cv.video.id=?")
+                                    .setParameter(0, (long) ty).setParameter(1, vi.getId()).uniqueResult();
+                            if (Integer.parseInt(obj + "") <= 0)
+                                videoService.addCategoryVideo(cv);
+                        }
 
-	public void saveVideoFunTV(VideoFunTV vyk) {
-		try {
-			videoFunTVDao.save(vyk);
-		} catch (Exception e) {
+                    obj = session.createQuery(String.format(
+                            "select count(*) from ResourceVideo rv where rv.video.id=%s and rv.resource.id=%s",
+                            vi.getId(), 19 + "")).uniqueResult();
+                    if (Integer.parseInt(obj + "") <= 0) {// 鍔犲叆
+                        ResourceVideo rv = new ResourceVideo();
+                        rv.setResource(new VideoResource(19 + ""));
+                        rv.setVideo(new VideoInfo(vi.getId()));
+                        session.createSQLQuery(String.format(
+                                "insert into wk_resource_video(videoid,resourceid) values(%s,%s)", vi.getId(), 19 + ""))
+                                .executeUpdate();
+                    }
+                    session.flush();
+                    session.getTransaction().commit();
+                } catch (Exception e) {
+                    System.out.println("鍑洪敊:" + e.getMessage());
+                }
 
-		}
+                return null;
+            }
+        });
 
-	}
+    }
 
-	// 閿欒
-	public void addPlayStatistics(String detailSystemId, String vid) {
-		List list = videoFunTVDao.sqlList(
-				"SELECT vy.`videoid` FROM wk_funtv_album_video pv LEFT JOIN wk_funtv_album p ON p.`id`=pv.`aid` LEFT JOIN wk_video_youku vy ON vy.`programid`=p.`id` WHERE pv.`videoid`=?",
-				new Serializable[] { vid });
-		if (list != null && list.size() > 0) {
-			statisticsService.addStatistics(detailSystemId, list.get(0) + "");
-		} else {
-			list = videoFunTVDao.sqlList("select y.videoid from wk_video_funtv y where y.funvideoid=?",
-					new Serializable[] { vid });
-			if (list != null && list.size() > 0)
-				statisticsService.addStatistics(detailSystemId, list.get(0) + "");
-		}
-	}
+    public Serializable addVideoInfo(VideoInfo info, FunTVAlbum p) {
+        Serializable id = videoInfoDao.save(info);
+        return id;
+    }
 
-	public long getFunTVVideoCount(String pid) {
-		return videoFunTVDao.getCount("select count(*) from VideoFunTV m where m.album.id=?",
-				new Serializable[] { pid });
-	}
+    public Serializable addVideoInfo(VideoInfo info, FunTVVideo p) {
+        Serializable id = videoInfoDao.save(info);
+        return id;
+    }
 
-	public VideoDetailInfo getLatestVideoDetail(String videoid) {
+    public void saveVideoFunTV(VideoFunTV vyk) {
+        try {
+            if (vyk.getId() == null)
+                vyk.setId(vyk.createId());
+            videoFunTVNewDao.save(vyk);
+        } catch (Exception e) {
 
-		List<VideoFunTV> list = videoFunTVDao.list("from VideoFunTV vy where vy.video.id=?", new String[] { videoid });
-		if (list != null && list.size() > 0) {
-			final VideoFunTV vft = list.get(0);
-			if (vft.getAlbum() != null) {// 鎸夎妭鐩煡鎵捐棰�
-				List<FunTVVideo> videoList = funTVVideoDao.list(
-						"select map.video from FunTVAlbumVideoMap map where map.album.id=? order by map.video.num desc",
-						0, 1, new Serializable[] { vft.getAlbum().getId() });
-				List<VideoDetailInfo> detailList = new ArrayList<VideoDetailInfo>();
-				for (FunTVVideo pv : videoList)
-					detailList.add(FunTVUtil.convertFunTVVideoToVideoDetail(pv, vft.getAlbum()));
-				return detailList.get(0);
-			} else if (vft.getTvVideo() != null) {// 鍗曚釜瑙嗛----寰呭畾
-				funTVAlbumDao.list("");
-			}
-		}
+        }
 
-		return null;
-	}
+    }
 
-	@SuppressWarnings("unchecked")
-	public void addFunTVAlbumToVideoInfo(final FunTVAlbum p, final boolean isUpdate) {
+    // 閿欒
+    public void addPlayStatistics(String detailSystemId, String id) {
+        List<VideoFunTV> list = videoFunTVNewDao.listByVid(id);
+        if (list != null && list.size() > 0) {
+            statisticsService.addStatistics(detailSystemId, list.get(0).getVideoId() + "");
+        } else {
+            list = videoFunTVNewDao.listByAid(id);
+            if (list != null && list.size() > 0)
+                statisticsService.addStatistics(detailSystemId, list.get(0).getVideoId() + "");
+        }
+    }
 
-		final VideoInfo info = FunTVUtil.convertFunTVAlbumToVideoInfo(p);
-		// 绫诲瀷璁$畻
-		final List<Integer> typeList = new ArrayList<Integer>();
 
-		int type = FunTVUtil.getFunTVAlbumType(p);
-		boolean exist = false;
-		for (Integer i : typeList)
-			if (i == type)
-				exist = true;
-		if (!exist && type > 0)
-			typeList.add(type);
+    public VideoDetailInfo getLatestVideoDetail(String videoid) {
+        List<VideoFunTV> list = videoFunTVNewDao.listByVideoId(Long.parseLong(videoid));
+        if (list != null && list.size() > 0) {
+            final VideoFunTV vft = list.get(0);
+            if (vft.getAid() != null) {// 鎸夎妭鐩煡鎵捐棰�
+                List<FunTVVideo> videoList = funTVVideoDao.listByAid(vft.getAid(), "num", Sort.Direction.DESC, 0, 1);
+                List<VideoDetailInfo> detailList = new ArrayList<>();
+                for (FunTVVideo pv : videoList) {
+                    FunTVAlbum album = funTVAlbumDao.get(pv.getAid());
+                    detailList.add(FunTVUtil.convertFunTVVideoToVideoDetail(pv, album));
+                }
+                return detailList.get(0);
+            } else if (vft.getVid() != null) {// 鍗曚釜瑙嗛----寰呭畾
+            }
+        }
 
-		if (typeList.size() == 0)
-			typeList.add(299);
+        return null;
+    }
 
-		try {
-			List<VideoInfo> infoList = videoInfoDao.list("from VideoInfo vi where vi.name=?",
-					new Serializable[] { p.getTitle() });
-			boolean isSame = false;
-			VideoInfo video = null;
-			for (VideoInfo vi : infoList) {
-				final VideoInfo newVi = vi;
-				boolean issame = (Boolean) videoInfoDao.excute(new HibernateCallback<Boolean>() {
-					public Boolean doInHibernate(Session session) throws HibernateException {
-						return FunTVUtil.isSameVideo(typeList, p, newVi, session);
-					}
-				});
-				if (issame) {
-					isSame = true;
-					video = vi;
-					break;
-				}
-			}
+    @SuppressWarnings("unchecked")
+    public void addFunTVAlbumToVideoInfo(final FunTVAlbum p, final boolean isUpdate) {
 
-			if (infoList != null && infoList.size() > 0 && isSame) {// 鏃犻渶鍔犲叆
-				updateVideoInfo(info, video, p, isUpdate);
-			} else {// 闇�瑕佹柊鍔犲叆videoinfo
-				Serializable id = addVideoInfo(info, p);
+        final VideoInfo info = FunTVUtil.convertFunTVAlbumToVideoInfo(p);
+        // 绫诲瀷璁$畻
+        final List<Integer> typeList = new ArrayList<>();
+
+        int type = FunTVUtil.getFunTVAlbumType(p);
+        boolean exist = false;
+        for (Integer i : typeList)
+            if (i == type)
+                exist = true;
+        if (!exist && type > 0)
+            typeList.add(type);
 
-				if (id != null) {
-					info.setId(id.toString());
+        if (typeList.size() == 0)
+            typeList.add(299);
 
-					for (Integer ty : typeList) {
-						CategoryVideo cv = new CategoryVideo();
-						cv.setVideo(new VideoInfo(info.getId()));
-						cv.setVideoType(new VideoType(ty));
-						videoService.addCategoryVideo(cv);
-					}
+        try {
+            List<VideoInfo> infoList = videoInfoDao.list("from VideoInfo vi where vi.name=?",
+                    new Serializable[]{p.getTitle()});
+            boolean isSame = false;
+            VideoInfo video = null;
+            for (VideoInfo vi : infoList) {
+                final VideoInfo newVi = vi;
+                boolean issame = (Boolean) videoInfoDao.excute(new HibernateCallback<Boolean>() {
+                    public Boolean doInHibernate(Session session) throws HibernateException {
+                        return FunTVUtil.isSameVideo(typeList, p, newVi, session);
+                    }
+                });
+                if (issame) {
+                    isSame = true;
+                    video = vi;
+                    break;
+                }
+            }
 
-					VideoFunTV vft = new VideoFunTV();
-					vft.setAlbum(new FunTVAlbum(p.getId()));
-					vft.setVideo(new VideoInfo(info.getId()));
-					vft.setTvVideo(null);
-					saveVideoFunTV(vft);
+            Serializable videoId = null;
 
-					videoResourceService.excuteSQL(String.format(
-							"insert into wk_resource_video(videoid,resourceid) values(%s,%s)", info.getId(), 19 + ""));
-				}
-			}
+            if (infoList != null && infoList.size() > 0 && isSame) {// 鏃犻渶鍔犲叆
+                updateVideoInfo(info, video, p, isUpdate);
+                videoId = video.getId();
+            } else {// 闇�瑕佹柊鍔犲叆videoinfo
+                videoId = addVideoInfo(info, p);
+            }
 
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
+            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){
 
-	}
+                }
 
-	public void addVideoToVideoInfo(final FunTVVideo p) {
-		VideoInfo info = FunTVUtil.convertVideoToVideoInfo(p);
-		try {
-			synchronized (p.getTitle().intern()) { // 鍙戠幇浜嗘湁閲嶅鐢熸垚VideoInfo.鎵�鏈夋牴鎹悕绉板姞涓攣锛堜竴瀹氳鍔爄ntern()锛塩xx
+                VideoFunTV vft = new VideoFunTV();
+                vft.setAid(p.getAid());
+                vft.setVideoId(Long.parseLong(info.getId()));
+                vft.setVid(null);
+                vft.setId(vft.createId());
+                saveVideoFunTV(vft);
 
-				List<VideoInfo> infoList = videoInfoDao.list("from VideoInfo vi where vi.name=?",
-						new Serializable[] { p.getTitle() });
-				if (infoList != null && infoList.size() > 0) {// 鏃犻渶鍔犲叆
-					// updateVideoInfo(info, infoList.get(0), p, genre);
-					return;
-				} else {// 闇�瑕佹柊鍔犲叆videoinfo
-					Serializable id = addVideoInfo(info, p);
-					List<Integer> typeList = new ArrayList<Integer>();
-					typeList = FunTVUtil.getShortVideoType(p, p.getCate(), p.getSubCate());
+                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 + ""));
+            }
 
-					if (typeList == null || typeList.size() <= 0)
-						return;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
 
-					if (id != null) {
-						info.setId(id.toString());
+    }
 
-						for (Integer ty : typeList) {
-							CategoryVideo cv = new CategoryVideo();
-							cv.setVideo(new VideoInfo(info.getId()));
-							cv.setVideoType(new VideoType(ty));
-							videoService.addCategoryVideo(cv);
-						}
+    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[]{info.getName()});
+                if (infoList != null && infoList.size() > 0) {// 鏃犻渶鍔犲叆
+                    // updateVideoInfo(info, infoList.get(0), p, genre);
+                    return;
+                } else {// 闇�瑕佹柊鍔犲叆videoinfo
+                    Serializable id = addVideoInfo(info, p);
+                    List<Integer> typeList = new ArrayList<>();
+                    typeList = FunTVUtil.getShortVideoType(p, p.getCate(), p.getSubCate());
 
-						VideoFunTV vft = new VideoFunTV();
-						vft.setAlbum(null);
-						vft.setVideo(new VideoInfo(info.getId()));
-						vft.setTvVideo(p);
-						saveVideoFunTV(vft);
-						videoResourceService.excuteSQL(
-								String.format("insert into wk_resource_video(videoid,resourceid) values(%s,%s)",
-										info.getId(), 19 + ""));
-					}
-				}
-			}
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
+                    if (typeList == null || typeList.size() <= 0)
+                        return;
 
-	}
+                    if (id != null) {
+                        info.setId(id.toString());
 
-	public int getShowType(String vid) {
-		List<FunTVAlbum> list = funTVAlbumDao.list("select vs.album From VideoFunTV vs where vs.video.id=?",
-				new Serializable[] { vid });
-		if (list != null && list.size() > 0) {
-			if (list.get(0) != null) {
-				if (list.get(0).getVideoType().contains("鐢佃鍓�") || list.get(0).getVideoType().contains("鍔ㄦ极"))
-					return 2;
-			} else {
-				return 1;
-			}
-		}
+                        for (Integer ty : typeList) {
+                            CategoryVideo cv = new CategoryVideo();
+                            cv.setVideo(new VideoInfo(info.getId()));
+                            cv.setVideoType(new VideoType(ty));
+                            videoService.addCategoryVideo(cv);
+                        }
 
-		return 1;
-	}
+                        VideoFunTV vft = new VideoFunTV();
+                        vft.setAid(null);
+                        vft.setVideoId(Long.parseLong(info.getId()));
+                        vft.setVid(p.getVid());
+                        vft.setId(vft.createId());
+                        saveVideoFunTV(vft);
+                        videoResourceService.excuteSQL(
+                                String.format("insert into wk_resource_video(videoid,resourceid) values(%s,%s)",
+                                        info.getId(), 19 + ""));
+                    }
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
 
-	@SuppressWarnings("unchecked")
-	public PlayUrl getPlayUrl(String detailSystemId, String id, String type, int resourceid, String videoId) {
-		logger.info(String.format("%s#%s#%s#%s", detailSystemId, resourceid, type, id));
-		PlayUrl playUrl = new PlayUrl();
+    }
 
-		List<VideoResource> list = videoResourceDao.list("from VideoResource vr where vr.id=" + resourceid);
-		if (list != null && list.size() > 0)
-			playUrl.setResource(list.get(0));
-		if (StringUtil.isNullOrEmpty(videoId))
-			addPlayStatistics(detailSystemId, id);
-		else
-			statisticsService.addStatistics(detailSystemId, videoId);
-		if (!type.equalsIgnoreCase("funtvvideo")) {
-			List<BigInteger> idList = (List<BigInteger>) videoResourceDao.sqlList(
-					"SELECT yk.`videoid` FROM wk_video_funtv yk WHERE yk.`albumid`= ( SELECT p.`aid` FROM wk_funtv_video v LEFT JOIN wk_funtv_album_video_map p ON p.`funvideoid`=v.`id`  WHERE v.`id`=?)",
-					new Serializable[] { id });
-			if (idList != null && idList.size() > 0) {
-				boolean isNeedWeb = banQuanService.isNeedWebPlay(detailSystemId, idList.get(0) + "");
-				if (isNeedWeb)
-					playUrl.setPlayType(1);
-			}
-		}
+    public int getShowType(String videoId) {
+        List<VideoFunTV> list = videoFunTVNewDao.listByVideoId(Long.parseLong(videoId));
+        if (list != null && list.size() > 0) {
+            if (list.get(0) != null) {
+                FunTVAlbum album = funTVAlbumDao.get(list.get(0).getAid());
 
-		FunTVVideo fvideo = getFunTVVideo(Long.parseLong(id));
+                if (album.getVideoType().contains("鐢佃鍓�") || album.getVideoType().contains("鍔ㄦ极"))
+                    return 2;
+            } else {
+                return 1;
+            }
+        }
 
-		JSONObject object = new JSONObject();
-		object.put("vid", fvideo.getVid());
-		playUrl.setParams(object.toString());
-		if (fvideo.getPlayMUrl() != null)
-			playUrl.setUrl(fvideo.getPlayMUrl().replace("alliance=2501", "malliance=0"));
-		playUrl.setPlayType(1);// 鍏ㄩ儴璺宠浆缃戦〉
-		return playUrl;
-	}
+        return 1;
+    }
 
-	public List<VideoDetailInfo> getVideoDetailList(String videoid) {
+    @SuppressWarnings("unchecked")
+    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();
 
-		List<VideoFunTV> list = videoFunTVDao.list("from VideoFunTV vy where vy.video.id=?", new String[] { videoid });
-		if (list != null && list.size() > 0) {
-			final VideoFunTV vft = list.get(0);
+        List<VideoResource> list = videoResourceDao.list("from VideoResource vr where vr.id=" + resourceid);
+        if (list != null && list.size() > 0)
+            playUrl.setResource(list.get(0));
+        if (StringUtil.isNullOrEmpty(videoId))
+            addPlayStatistics(detailSystemId, id);
+        else
+            statisticsService.addStatistics(detailSystemId, videoId);
+        if (!type.equalsIgnoreCase("funtvvideo")) {
+            List<BigInteger> idList = (List<BigInteger>) videoResourceDao.sqlList(
+                    "SELECT yk.`videoid` FROM wk_video_funtv yk WHERE yk.`albumid`= ( SELECT p.`aid` FROM wk_funtv_video v LEFT JOIN wk_funtv_album_video_map p ON p.`funvideoid`=v.`id`  WHERE v.`id`=?)",
+                    new Serializable[]{id});
+            if (idList != null && idList.size() > 0) {
+                boolean isNeedWeb = banQuanService.isNeedWebPlay(detailSystemId, idList.get(0) + "");
+                if (isNeedWeb)
+                    playUrl.setPlayType(1);
+            }
+        }
 
-			if (vft != null && vft.getAlbum() != null) {// 鎸夎妭鐩煡鎵捐棰�
-				List<FunTVVideo> videoList = funTVVideoDao.list(
-						"select map.video from FunTVAlbumVideoMap map where map.album.id=" + vft.getAlbum().getId());
-				Comparator<FunTVVideo> cp = new Comparator<FunTVVideo>() {
-					public int compare(FunTVVideo o1, FunTVVideo o2) {
+        FunTVVideo fvideo = funTVVideoDao.get(id);
+        JSONObject object = new JSONObject();
+        object.put("vid", fvideo.getVid());
+        playUrl.setParams(object.toString());
+        if (fvideo.getPlayMUrl() != null)
+            playUrl.setUrl(fvideo.getPlayMUrl().replace("alliance=2501", "malliance=0"));
 
-						long t1 = o1.getNum();
-						long t2 = o2.getNum();
-						if (vft.getAlbum().getVideoType().contains("鐢靛奖")) {
-							return (int) (t2 - t1);
-						} else if (vft.getAlbum().getVideoType().contains("鐢佃鍓�")) {
-							return (int) (t1 - t2);
-						} else if (vft.getAlbum().getVideoType().contains("缁艰壓")) {
-							return (int) (t2 - t1);
-						} else if (vft.getAlbum().getVideoType().contains("鍔ㄦ极")) {
-							return (int) (t1 - t2);
-						} else
-							return (int) (t2 - t1);
-					}
-				};
-				Collections.sort(videoList, cp);
+        String firstOnLineValue =  detailSystemConfigService.getConfigValueByKey("first_online_versions",detailSystemId, versionCode);
+        if( Constant.IS_HAVE_FIRST_ONLINE && SystemConfigUtil.isFirstOnLine(firstOnLineValue, channel, versionCode)){
+            // 棣栨涓婄嚎璺宠浆鍘熺敓
+            playUrl.setPlayType(2);// 鍘熺敓璺宠浆
+        } else {
+            playUrl.setPlayType(1);// 鍏ㄩ儴璺宠浆缃戦〉
+        }
+        return playUrl;
+    }
 
-				List<VideoDetailInfo> detailList = new ArrayList<VideoDetailInfo>();
-				for (FunTVVideo pv : videoList)
-					detailList.add(FunTVUtil.convertFunTVVideoToVideoDetail(pv, vft.getAlbum()));
-				return detailList;
-			} else if (vft.getTvVideo() != null) {// 鍗曚釜瑙嗛
-				FunTVVideo pv = vft.getTvVideo();
-				List<VideoDetailInfo> detailList = new ArrayList<VideoDetailInfo>();
-				VideoDetailInfo detail = new VideoDetailInfo();
-				detail.setId(pv.getId());
-				detail.setExtraId(pv.getId() + "");
-				detail.setName(pv.getTitle());
-				detail.setTag(pv.getDesc());
-				detail.setType("funtvvideo");
-				List<VideoUrl> urlList = new ArrayList<VideoUrl>();
-				VideoUrl vu = new VideoUrl();
-				vu.setAdmin(null);
-				vu.setBaseUrl(pv.getPlayUrl());
-				vu.setInvalid(0 + "");
-				vu.setResource(new VideoResource("19"));
-				vu.setUrl(pv.getPlayMUrl());
-				urlList.add(vu);
-				detail.setUrls(urlList);
-				detailList.add(detail);
-				return detailList;
-			}
-		}
+    public List<VideoDetailInfo> getVideoDetailList(String videoid, int page, int pageSize) {
+        List<VideoFunTV> list = videoFunTVNewDao.listByVideoId(Long.parseLong(videoid));
+        if (list != null && list.size() > 0) {
+            final VideoFunTV vft = list.get(0);
+            if (vft != null && vft.getAid() != null) {// 鎸夎妭鐩煡鎵捐棰�
+                String aid = vft.getAid();
+                FunTVAlbum album = funTVAlbumDao.get(aid);
+//                if (album == null) {
+//                    resourceVideoService.delete(videoid, FunTVUtil.RESOURCE_ID + "");
+//                }
+                final String type = album.getVideoType();
+                Sort.Direction sort = Sort.Direction.ASC;
+                if (type != null)
+                    if (type.contains("鐢靛奖")) {
+                        sort = Sort.Direction.DESC;
+                    } else if (type.contains("鐢佃鍓�")) {
+                        sort = Sort.Direction.ASC;
+                    } else if (type.contains("缁艰壓")) {
+                        sort = Sort.Direction.DESC;
+                    } else if (type.contains("鍔ㄦ极")) {
+                        sort = Sort.Direction.ASC;
+                    } else
+                        sort = Sort.Direction.DESC;
 
-		return null;
-	}
 
-	public FunTVVideo getLatestFunTVVideo(String programid) {
-		List<FunTVVideo> videoList = funTVVideoDao.list(String.format(
-				"select map.video from FunTVAlbumVideoMap map where map.album.aid=%s order by map.video.num  desc",
-				programid), 0, 1, null);
-		if (videoList != null && videoList.size() > 0)
-			return videoList.get(0);
-		return null;
-	}
+                List<FunTVVideo> videoList = funTVVideoDao.listByAid(aid, "num", sort, (page - 1) * pageSize, pageSize);
+                if (album == null && videoList.size() > 0) {//澶勭悊鐢靛奖
+                    album = new FunTVAlbum();
+                    album.setTitle(videoList.get(0).getTitle());
+                    album.setVideoType(videoList.get(0).getCate());
+                }
 
-	public void deleteVideoByAid(String aid) {
-		// 鏌ヨ鍑哄搴旂殑VID涓巚ideoid
-		final FunTVAlbum album = getAlbumByAid(aid);
+                List<VideoDetailInfo> detailList = new ArrayList<>();
+                for (FunTVVideo pv : videoList)
+                    detailList.add(FunTVUtil.convertFunTVVideoToVideoDetail(pv, album));
+                return detailList;
+            } else if (vft.getVid() != null) {// 鍗曚釜瑙嗛
+                FunTVVideo pv = funTVVideoDao.get(vft.getVid());
+                List<VideoDetailInfo> detailList = new ArrayList<>();
+                VideoDetailInfo detail = new VideoDetailInfo();
+                detail.setId(Long.parseLong(pv.getVid()));
+                detail.setExtraId(pv.getId() + "");
+                detail.setName(pv.getTitle());
+                detail.setTag(pv.getDesc());
+                detail.setType("funtvvideo");
+                List<VideoUrl> urlList = new ArrayList<>();
+                VideoUrl vu = new VideoUrl();
+                vu.setAdmin(null);
+                vu.setBaseUrl(pv.getPlayUrl());
+                vu.setInvalid(0 + "");
+                vu.setResource(new VideoResource("19"));
+                vu.setUrl(pv.getPlayMUrl());
+                urlList.add(vu);
+                detail.setUrls(urlList);
+                detailList.add(detail);
+                return detailList;
+            }
+        }else{//鍒犻櫎鏉ユ簮
+            resourceVideoService.delete(videoid,FunTVUtil.RESOURCE_ID+"");
+        }
 
-		if (album != null) {
-			String videoId = (String) funTVVideoDao.excute(new HibernateCallback<String>() {
+        return null;
+    }
 
-				@SuppressWarnings("unchecked")
-				public String doInHibernate(Session session) throws HibernateException {
-					String videoid = null;
+    public FunTVVideo getLatestFunTVVideo(String programid) {
+        FunTVVideo video = funTVVideoDao.getLatestVideo(programid);
+        return video;
+    }
 
-					List<FunTVVideo> list = session
-							.createQuery("select m.video from FunTVAlbumVideoMap m where m.album.id=" + album.getId())
-							.list();
-					session.getTransaction().begin();
-					try {
+    public void deleteVideoByAid(String aid) {
+        // 鏌ヨ鍑哄搴旂殑VID涓巚ideoid
+        final FunTVAlbum album = getAlbumByAid(aid);
 
-						for (FunTVVideo tv : list) {// 鍒犻櫎瑙嗛
-							session.delete(tv);
-						}
-						session.delete(album);// 鍒犻櫎涓撹緫
-						List<VideoFunTV> ftlist = session
-								.createQuery("from VideoFunTV vf where vf.album!=null and vf.album.id=" + album.getId())
-								.list();
-						if (ftlist.size() > 0) {
-							Object obj = session.createQuery(
-									"select count(*) from ResourceVideo rv where rv.resource.id!=19 and rv.video.id="
-											+ ftlist.get(0).getVideo().getId())
-									.uniqueResult();
-							if (Integer.parseInt(obj + "") <= 0) {
-								videoid = ftlist.get(0).getVideo().getId();
-							}
-						}
-						session.createQuery(
-								"delete from VideoFunTV vf where vf.album!=null and vf.album.id=" + album.getId())
-								.executeUpdate();
-						session.flush();
-						session.getTransaction().commit();
-					} catch (Exception e) {
-						session.getTransaction().rollback();
-					}
-					return videoid;
-				}
-			});
+        if (album != null) {
+            String videoId = (String) videoResourceDao.excute(new HibernateCallback<String>() {
+                @SuppressWarnings("unchecked")
+                public String doInHibernate(Session session) throws HibernateException {
+                    String videoid = null;
+                    List<FunTVVideo> list = funTVVideoDao.listByAid(album.getAid(), 0, 1000);
+                    session.getTransaction().begin();
+                    try {
+                        for (FunTVVideo tv : list) {// 鍒犻櫎瑙嗛
+                            funTVVideoDao.delete(tv.getVid());
+                        }
+                        funTVAlbumDao.delete(album.getAid());// 鍒犻櫎涓撹緫
+                        List<VideoFunTV> ftlist = videoFunTVNewDao.listByAid(album.getAid());
 
-			if (videoId != null) {// 鍙互鍒犻櫎瑙嗛
-				videoManager.deleteVideo(videoId);
-			}
+                        if (ftlist.size() > 0) {
+                            Object obj = session.createQuery(
+                                    "select count(*) from ResourceVideo rv where rv.resource.id!=19 and rv.video.id="
+                                            + ftlist.get(0).getVideoId())
+                                    .uniqueResult();
+                            if (Integer.parseInt(obj + "") <= 0) {
+                                videoid = ftlist.get(0).getVideoId() + "";
+                            }
+                        }
+                        for (VideoFunTV funTV : ftlist)
+                            videoFunTVNewDao.delete(funTV.getId());
+                        session.flush();
+                        session.getTransaction().commit();
+                    } catch (Exception e) {
+                        session.getTransaction().rollback();
+                    }
+                    return videoid;
+                }
+            });
 
-		}
+            if (videoId != null) {// 鍙互鍒犻櫎瑙嗛
+                videoManager.deleteVideo(videoId);
+            }
 
-	}
+        }
 
-	public void deleteVideoByVid(String vid) {
-		// 鏌ヨ鍑哄搴旂殑VID涓巚ideoid
-		final FunTVVideo video = getFunTVVideoByVid(vid);
-		if (video != null) {
-			String videoId = (String) funTVVideoDao.excute(new HibernateCallback<String>() {
+    }
 
-				@SuppressWarnings("unchecked")
-				public String doInHibernate(Session session) throws HibernateException {
-					String videoid = null;
+    public void deleteVideoByVid(String vid) {
+        // 鏌ヨ鍑哄搴旂殑VID涓巚ideoid
+        final FunTVVideo video = getFunTVVideoByVid(vid);
+        if (video != null) {
+            funTVVideoDao.deleteByPrimaryKey(video.getVid());
+            String videoId = (String) videoResourceDao.excute(new HibernateCallback<String>() {
 
-					List<FunTVVideo> list = session
-							.createQuery("select m.video from FunTVAlbumVideoMap m where m.album.id=" + video.getId())
-							.list();
-					session.getTransaction().begin();
-					try {
+                @SuppressWarnings("unchecked")
+                public String doInHibernate(Session session) throws HibernateException {
+                    String videoid = null;
 
-						for (FunTVVideo tv : list) {// 鍒犻櫎瑙嗛
-							session.delete(tv);
-						}
-						session.delete(video);// 鍒犻櫎涓撹緫
-						List<VideoFunTV> ftlist = session
-								.createQuery(
-										"from VideoFunTV vf where vf.tvVideo!=null and vf.tvVideo.id=" + video.getId())
-								.list();
-						if (ftlist.size() > 0) {
-							Object obj = session.createQuery(
-									"select count(*) from ResourceVideo rv where rv.resource.id!=19 and rv.video.id="
-											+ ftlist.get(0).getVideo().getId())
-									.uniqueResult();
-							if (Integer.parseInt(obj + "") <= 0) {
-								videoid = ftlist.get(0).getVideo().getId();
-							}
-						}
-						session.createQuery(
-								"delete from VideoFunTV vf where vf.tvVideo!=null and vf.tvVideo.id=" + video.getId())
-								.executeUpdate();
-						session.flush();
-						session.getTransaction().commit();
-					} catch (Exception e) {
-						session.getTransaction().rollback();
-					}
-					return videoid;
-				}
-			});
+                    //TODO 澶勭悊
+                    session.getTransaction().begin();
+                    try {
+                        List<VideoFunTV> ftlist = session
+                                .createQuery(
+                                        "from VideoFunTV vf where vf.vid=" + video.getVid())
+                                .list();
+                        if (ftlist.size() > 0) {
+                            Object obj = session.createQuery(
+                                    "select count(*) from ResourceVideo rv where rv.resource.id!=19 and rv.video.id="
+                                            + ftlist.get(0).getVideoId())
+                                    .uniqueResult();
+                            if (Integer.parseInt(obj + "") <= 0) {
+                                videoid = ftlist.get(0).getVideoId() + "";
+                            }
+                        }
+                        for (VideoFunTV funTV : ftlist) {
+                            videoFunTVNewDao.delete(funTV.getId());
+                        }
+                        session.flush();
+                        session.getTransaction().commit();
+                    } catch (Exception e) {
+                        session.getTransaction().rollback();
+                    }
+                    return videoid;
+                }
+            });
 
-			if (videoId != null) {// 鍙互鍒犻櫎瑙嗛
-				videoManager.deleteVideo(videoId);
-			}
+            if (videoId != null) {// 鍙互鍒犻櫎瑙嗛
+                videoManager.deleteVideo(videoId);
+            }
 
-		}
+        }
 
-	}
+    }
 
-	public PlayUrl getPlayUrl(String detailSystemId, String resourceid, String type, String id) {
-		return null;
-	}
+    public PlayUrl getPlayUrl(String detailSystemId, String resourceid, String type, String id) {
+        return null;
+    }
 
 }

--
Gitblit v1.8.0