admin
2021-03-13 7becc97c5bfdd827b9a999c26746bb8e8bc3e25c
src/main/java/com/yeshi/buwan/service/imp/VideoManager.java
@@ -7,6 +7,9 @@
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import com.yeshi.buwan.domain.video.AlbumVideoMap;
import com.yeshi.buwan.service.inter.juhe.AlbumVideoMapService;
import com.yeshi.buwan.util.mq.CMQManager;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate4.HibernateCallback;
@@ -34,596 +37,527 @@
@Service
public class VideoManager {
   @Resource
   private VideoInfoDao videoInfoDao;
   @Resource
   private VideoTypeDao videoTypeDao;
   @Resource
   private VideoDetailInfoDao videoDetailInfoDao;
    @Resource
    private VideoInfoDao videoInfoDao;
    @Resource
    private VideoTypeDao videoTypeDao;
    @Resource
    private VideoDetailInfoDao videoDetailInfoDao;
   /**
    * 主键查询某一个视频的信息
    *
    * @param id
    * @return
    */
   public VideoInfo getVideoInfo(String id) {
      VideoInfo info = videoInfoDao.find(VideoInfo.class, id);
      info.setVideoDetailList(getVideoDetail(info.getId()));
      return info;
   }
    @Resource
    private ClearService clearService;
   /**
    * 添加一个视频信息
    *
    * @param info
    * @return
    */
   public VideoInfo addVideoInfo(VideoInfo info) {
      info.setUpdatetime(System.currentTimeMillis() + "");
    /**
     * 主键查询某一个视频的信息
     *
     * @param id
     * @return
     */
    public VideoInfo getVideoInfo(String id) {
        VideoInfo info = videoInfoDao.find(VideoInfo.class, id);
        info.setVideoDetailList(getVideoDetail(info.getId()));
        return info;
    }
      videoInfoDao.save(info);
      List<VideoInfo> list = videoInfoDao.list("from VideoInfo v where v.createtime=? and v.name=?",
            new String[] { info.getCreatetime() + "", info.getName() });
      return list.get(0);
   }
    /**
     * 添加一个视频信息
     *
     * @param info
     * @return
     */
    public VideoInfo addVideoInfo(VideoInfo info) {
        info.setUpdatetime(System.currentTimeMillis() + "");
   String[] sts = { "彼得兔", "铁扇公主", "过猴山", "骄傲的将军", "夸口的青蛙", "小猫钓鱼", "好朋友", "神笔马良", "木头公主", "猪八戒吃西瓜", "小鲤鱼", "我知道",
         "老小阿凡提", "阿狸通话日记" };
        videoInfoDao.save(info);
        List<VideoInfo> list = videoInfoDao.list("from VideoInfo v where v.createtime=? and v.name=?",
                new String[]{info.getCreatetime() + "", info.getName()});
        return list.get(0);
    }
   boolean isContains(String st) {
      for (String s : sts) {
         if (st.contains(s)) {
            return true;
         }
      }
      return false;
   }
    String[] sts = {"彼得兔", "铁扇公主", "过猴山", "骄傲的将军", "夸口的青蛙", "小猫钓鱼", "好朋友", "神笔马良", "木头公主", "猪八戒吃西瓜", "小鲤鱼", "我知道",
            "老小阿凡提", "阿狸通话日记"};
   // 获取大分类
   public String getRootType(long id) {
      VideoType type = videoTypeDao.find(VideoType.class, id);
      while (type.getParent() != null)
         type = type.getParent();
      return type.getId() + "";
   }
    boolean isContains(String st) {
        for (String s : sts) {
            if (st.contains(s)) {
                return true;
            }
        }
        return false;
    }
   // 添加视频
   @SuppressWarnings("unchecked")
   public void addVideoInfo(List<VideoInfo> list) {
      for (VideoInfo in : list) {
         final VideoInfo info = in;
         LogUtil.i("视频名称:" + info.getName());
         // if (!info.getName().contains("三个奶爸")) continue;
         final String parentId = getRootType(info.getVideoType().getId());
         videoInfoDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
               try {
                  List<VideoInfo> vList = session
                        .createQuery("from VideoInfo v where v.name=? and v.show=1 and (v.videoType.id="
                              + parentId + " or v.videoType.parent.id=" + parentId + ")")
                        .setParameter(0, info.getName()).list();
                  session.getTransaction().begin();
                  if (vList.size() <= 0) {// 不存在视频--可以添加进去
                     info.setUpdatetime(System.currentTimeMillis() + "");
                     session.persist(info);
                     List<VideoInfo> viList = session
                           .createQuery("from VideoInfo v where v.name=? and v.createtime=?")
                           .setParameter(0, info.getName()).setParameter(1, info.getCreatetime()).list();// 查询出刚刚添加的视频
                     if (viList != null && viList.size() > 0) {
                        VideoInfo newVideo = new VideoInfo(viList.get(0).getId());
                        LogUtil.i("查出的VideoId为:" + newVideo.getId());
                        for (int i = 0; i < info.getVideoDetailList().size(); i++) {
                           VideoDetailInfo detail = info.getVideoDetailList().get(i);
                           detail.setVideo(newVideo);
                           session.persist(detail);
                           session.createSQLQuery(
                                 "update wk_video_video_detail d set d.videoid=? where d.name=? and d.tag=? and d.createtime=?")
                                 .setParameter(0, newVideo.getId()).setParameter(1, detail.getName())
                                 .setParameter(2, detail.getTag()).setParameter(3, detail.getCreatetime())
                                 .executeUpdate();
                        }
                     } else {
                        LogUtil.i("videoId没有查出来");
                     }
    // 获取大分类
    public String getRootType(long id) {
        VideoType type = videoTypeDao.find(VideoType.class, id);
        while (type.getParent() != null)
            type = type.getParent();
        return type.getId() + "";
    }
                  } else {// 存在的视频,添加进UrlList
                     // 获取videoDetail;
                     vList.get(0).setTag(info.getTag());
                     session.update(vList.get(0));
                     vList.get(0).setNowNumber(info.getNowNumber());
                     vList.get(0).setTotalNumber(info.getTotalNumber());
    // 添加视频
    @SuppressWarnings("unchecked")
    public void addVideoInfo(List<VideoInfo> list) {
        for (VideoInfo in : list) {
            final VideoInfo info = in;
            LogUtil.i("视频名称:" + info.getName());
            // if (!info.getName().contains("三个奶爸")) continue;
            final String parentId = getRootType(info.getVideoType().getId());
            videoInfoDao.excute(new HibernateCallback() {
                public Object doInHibernate(Session session) throws HibernateException {
                    try {
                        List<VideoInfo> vList = session
                                .createQuery("from VideoInfo v where v.name=? and v.show=1 and (v.videoType.id="
                                        + parentId + " or v.videoType.parent.id=" + parentId + ")")
                                .setParameter(0, info.getName()).list();
                        session.getTransaction().begin();
                        if (vList.size() <= 0) {// 不存在视频--可以添加进去
                            info.setUpdatetime(System.currentTimeMillis() + "");
                            session.persist(info);
                            List<VideoInfo> viList = session
                                    .createQuery("from VideoInfo v where v.name=? and v.createtime=?")
                                    .setParameter(0, info.getName()).setParameter(1, info.getCreatetime()).list();// 查询出刚刚添加的视频
                            if (viList != null && viList.size() > 0) {
                                VideoInfo newVideo = new VideoInfo(viList.get(0).getId());
                                LogUtil.i("查出的VideoId为:" + newVideo.getId());
                                for (int i = 0; i < info.getVideoDetailList().size(); i++) {
                                    VideoDetailInfo detail = info.getVideoDetailList().get(i);
                                    detail.setVideo(newVideo);
                                    session.persist(detail);
                                    session.createSQLQuery(
                                            "update wk_video_video_detail d set d.videoid=? where d.name=? and d.tag=? and d.createtime=?")
                                            .setParameter(0, newVideo.getId()).setParameter(1, detail.getName())
                                            .setParameter(2, detail.getTag()).setParameter(3, detail.getCreatetime())
                                            .executeUpdate();
                                }
                            } else {
                                LogUtil.i("videoId没有查出来");
                            }
                     List<VideoDetailInfo> detailList = getVideoDetail(session, vList.get(0).getId());// 获取原来的detailList
                     for (int n = 0; n < info.getVideoDetailList().size(); n++) {
                        if (n + 1 > detailList.size()) {// 原来不存在这一集
                           VideoInfo newVideo = vList.get(0);
                           // 保存详情
                           VideoDetailInfo detail = info.getVideoDetailList().get(n);
                           detail.setVideo(newVideo);
                           session.persist(detail);
                           session.createSQLQuery(
                                 "update wk_video_video_detail d set d.videoid=? where d.name=? and d.tag=? and d.createtime=?")
                                 .setParameter(0, newVideo.getId()).setParameter(1, detail.getName())
                                 .setParameter(2, detail.getTag()).setParameter(3, detail.getCreatetime())
                                 .executeUpdate();
                        } else {// 存在的视频,添加进UrlList
                            // 获取videoDetail;
                            vList.get(0).setTag(info.getTag());
                            session.update(vList.get(0));
                            vList.get(0).setNowNumber(info.getNowNumber());
                            vList.get(0).setTotalNumber(info.getTotalNumber());
                        } else {// 原来存在这个detail
                           VideoDetailInfo detail = detailList.get(n);// 获取原来那个url
                           List<VideoUrl> urlList = detail.getUrls();
                           VideoUrl vurl = null;
                            List<VideoDetailInfo> detailList = getVideoDetail(session, vList.get(0).getId());// 获取原来的detailList
                            for (int n = 0; n < info.getVideoDetailList().size(); n++) {
                                if (n + 1 > detailList.size()) {// 原来不存在这一集
                                    VideoInfo newVideo = vList.get(0);
                                    // 保存详情
                                    VideoDetailInfo detail = info.getVideoDetailList().get(n);
                                    detail.setVideo(newVideo);
                                    session.persist(detail);
                                    session.createSQLQuery(
                                            "update wk_video_video_detail d set d.videoid=? where d.name=? and d.tag=? and d.createtime=?")
                                            .setParameter(0, newVideo.getId()).setParameter(1, detail.getName())
                                            .setParameter(2, detail.getTag()).setParameter(3, detail.getCreatetime())
                                            .executeUpdate();
                           for (VideoUrl videoUrl : urlList) {
                              if (videoUrl.getResource().getId().equalsIgnoreCase(info.getVideoDetailList()
                                    .get(n).getUrls().get(0).getResource().getId())) {// 存在
                                 vurl = videoUrl;
                              }
                           }
                                } else {// 原来存在这个detail
                                    VideoDetailInfo detail = detailList.get(n);// 获取原来那个url
                                    List<VideoUrl> urlList = detail.getUrls();
                                    VideoUrl vurl = null;
                           if (vurl == null) {// 不存在--往里面添加
                              VideoUrl vu = null;
                              try {
                                 vu = info.getVideoDetailList().get(n).getUrls().get(0);
                              } catch (Exception e) {
                                 vu = info.getVideoDetailList().get(n).getUrls().get(0);
                              }
                              vu.setVideoDetail(detail);
                              // 更新url
                              session.createSQLQuery(
                                    "insert into wk_video_video_url  (videodetailid,resourceid,vdetailurl,createtime,adminid,beizhu,baseurl) values(?,?,?,?,?,?,?)")
                                    .setParameter(0, detail.getId())
                                    .setParameter(1, vu.getResource().getId()).setParameter(2, vu.getUrl())
                                    .setParameter(3, vu.getCreatetime())
                                    .setParameter(4, vu.getAdmin().getId()).setParameter(5, vu.getBeizhu())
                                    .setParameter(6, vu.getBaseUrl()).executeUpdate();
                           } else {// 原来存在该URL
                              VideoUrl newUrl = info.getVideoDetailList().get(n).getUrls().get(0);
                              if (!newUrl.getUrl().equals(vurl.getUrl())) {
                                 vurl.setUrl(newUrl.getUrl());
                                 session.update(vurl);
                                 detail.setTag(info.getVideoDetailList().get(n).getTag());
                                 session.update(detail);
                              }
                           }
                        }
                     }
                  }
                  session.flush();
                  session.getTransaction().commit();
               } catch (Exception e) {
                  LogUtil.i("视频名称:" + info.getName());
                  e.printStackTrace();
                  session.getTransaction().rollback();
               }
                                    for (VideoUrl videoUrl : urlList) {
                                        if (videoUrl.getResource().getId().equalsIgnoreCase(info.getVideoDetailList()
                                                .get(n).getUrls().get(0).getResource().getId())) {// 存在
                                            vurl = videoUrl;
                                        }
                                    }
               return null;
            }
         });
                                    if (vurl == null) {// 不存在--往里面添加
                                        VideoUrl vu = null;
                                        try {
                                            vu = info.getVideoDetailList().get(n).getUrls().get(0);
                                        } catch (Exception e) {
                                            vu = info.getVideoDetailList().get(n).getUrls().get(0);
                                        }
                                        vu.setVideoDetail(detail);
                                        // 更新url
                                        session.createSQLQuery(
                                                "insert into wk_video_video_url  (videodetailid,resourceid,vdetailurl,createtime,adminid,beizhu,baseurl) values(?,?,?,?,?,?,?)")
                                                .setParameter(0, detail.getId())
                                                .setParameter(1, vu.getResource().getId()).setParameter(2, vu.getUrl())
                                                .setParameter(3, vu.getCreatetime())
                                                .setParameter(4, vu.getAdmin().getId()).setParameter(5, vu.getBeizhu())
                                                .setParameter(6, vu.getBaseUrl()).executeUpdate();
                                    } else {// 原来存在该URL
                                        VideoUrl newUrl = info.getVideoDetailList().get(n).getUrls().get(0);
                                        if (!newUrl.getUrl().equals(vurl.getUrl())) {
                                            vurl.setUrl(newUrl.getUrl());
                                            session.update(vurl);
                                            detail.setTag(info.getVideoDetailList().get(n).getTag());
                                            session.update(detail);
                                        }
                                    }
                                }
                            }
                        }
                        session.flush();
                        session.getTransaction().commit();
                    } catch (Exception e) {
                        LogUtil.i("视频名称:" + info.getName());
                        e.printStackTrace();
                        session.getTransaction().rollback();
                    }
      }
   }
                    return null;
                }
            });
   public void updateVideoInfo(VideoInfo info) {
      videoInfoDao.update(info);
   }
        }
    }
   public void updateVideoInfo(List<VideoInfo> list) {
      for (VideoInfo vi : list)
         videoInfoDao.update(vi);
   }
    public void updateVideoInfo(VideoInfo info) {
        videoInfoDao.update(info);
    }
   @ManyToOne
   private AdminInfo getAdmin() {
      AdminInfo info = new AdminInfo();
      info.setId("1");
      return info;
   }
    public void updateVideoInfo(List<VideoInfo> list) {
        for (VideoInfo vi : list)
            videoInfoDao.update(vi);
    }
   /**
    * 添加视频详情
    *
    * @param list
    */
   public void addVideoDetail(final VideoInfo info, final List<VideoDetailInfo> list) {
      videoInfoDao.excute(new HibernateCallback() {
         public Object doInHibernate(Session session) throws HibernateException {
            try {
               session.getTransaction().begin();
               for (int i = 0; i < list.size(); i++) {
                  VideoInfo video = new VideoInfo(info.getId());
                  list.get(i).setVideo(video);
                  session.persist(list.get(i));
               }
               session.flush();
               session.getTransaction().commit();
            } catch (Exception e) {
               e.printStackTrace();
               session.getTransaction().rollback();
            }
            return null;
         }
      });
    @ManyToOne
    private AdminInfo getAdmin() {
        AdminInfo info = new AdminInfo();
        info.setId("1");
        return info;
    }
   }
    /**
     * 添加视频详情
     *
     * @param list
     */
    public void addVideoDetail(final VideoInfo info, final List<VideoDetailInfo> list) {
        videoInfoDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                try {
                    session.getTransaction().begin();
                    for (int i = 0; i < list.size(); i++) {
                        VideoInfo video = new VideoInfo(info.getId());
                        list.get(i).setVideo(video);
                        session.persist(list.get(i));
                    }
                    session.flush();
                    session.getTransaction().commit();
                } catch (Exception e) {
                    e.printStackTrace();
                    session.getTransaction().rollback();
                }
                return null;
            }
        });
   /**
    * 添加视频详情
    *
    * @param list
    */
   public void addVideoDetail(final List<VideoDetailInfo> list) {
      videoInfoDao.excute(new HibernateCallback() {
         public Object doInHibernate(Session session) throws HibernateException {
            try {
               session.getTransaction().begin();
               for (int i = 0; i < list.size(); i++) {
                  session.persist(list.get(i));
               }
               session.flush();
               session.getTransaction().commit();
            } catch (Exception e) {
               e.printStackTrace();
               session.getTransaction().rollback();
            }
            return null;
         }
      });
    }
   }
    /**
     * 添加视频详情
     *
     * @param list
     */
    public void addVideoDetail(final List<VideoDetailInfo> list) {
        videoInfoDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                try {
                    session.getTransaction().begin();
                    for (int i = 0; i < list.size(); i++) {
                        session.persist(list.get(i));
                    }
                    session.flush();
                    session.getTransaction().commit();
                } catch (Exception e) {
                    e.printStackTrace();
                    session.getTransaction().rollback();
                }
                return null;
            }
        });
   public VideoDetailInfo addVideoDetail(final VideoDetailInfo detail) {
      videoInfoDao.excute(new HibernateCallback() {
         public Object doInHibernate(Session session) throws HibernateException {
            try {
               session.getTransaction().begin();
               session.persist(detail);
               session.flush();
               session.getTransaction().commit();
            } catch (Exception e) {
               e.printStackTrace();
            }
            return null;
         }
      });
    }
      List<VideoDetailInfo> list = getVideoDetail(detail.getVideo().getId());
      if (list != null && list.size() > 0)
         return list.get(0);
      else
         return null;
   }
    public VideoDetailInfo addVideoDetail(final VideoDetailInfo detail) {
        videoInfoDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                try {
                    session.getTransaction().begin();
                    session.persist(detail);
                    session.flush();
                    session.getTransaction().commit();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return null;
            }
        });
   public List<VideoDetailInfo> getVideoDetail(String videoId) {
      LogUtil.i("请求开始:" + System.currentTimeMillis());
      List<VideoDetailInfo> list = videoDetailInfoDao.list("from VideoDetailInfo d where d.video.id=?",
            new String[] { videoId });
      LogUtil.i("请求结束:" + System.currentTimeMillis());
      return list;
   }
        List<VideoDetailInfo> list = getVideoDetail(detail.getVideo().getId());
        if (list != null && list.size() > 0)
            return list.get(0);
        else
            return null;
    }
   public VideoDetailInfo getVideoDetailById(long videoDetailId) {
      return videoDetailInfoDao.find(VideoDetailInfo.class, videoDetailId);
   }
    public List<VideoDetailInfo> getVideoDetail(String videoId) {
        LogUtil.i("请求开始:" + System.currentTimeMillis());
        List<VideoDetailInfo> list = videoDetailInfoDao.list("from VideoDetailInfo d where d.video.id=?",
                new String[]{videoId});
        LogUtil.i("请求结束:" + System.currentTimeMillis());
        return list;
    }
   public List<VideoDetailInfo> getVideoDetailByVideoName(String name) {
      LogUtil.i("请求开始:" + System.currentTimeMillis());
    public VideoDetailInfo getVideoDetailById(long videoDetailId) {
        return videoDetailInfoDao.find(VideoDetailInfo.class, videoDetailId);
    }
      List<VideoDetailInfo> list = videoDetailInfoDao.list("from VideoDetailInfo d where d.name=?",
            new String[] { name });
      LogUtil.i("请求结束:" + System.currentTimeMillis());
      return list;
   }
    public List<VideoDetailInfo> getVideoDetailByVideoName(String name) {
        LogUtil.i("请求开始:" + System.currentTimeMillis());
   public List<VideoDetailInfo> getVideoDetail(Session session, String videoId) {
      @SuppressWarnings("unchecked")
      List<VideoDetailInfo> list = session.createQuery("from VideoDetailInfo d where d.video.id=?")
            .setParameter(0, videoId).list();
      LogUtil.i("请求结束:" + System.currentTimeMillis());
      return list;
   }
        List<VideoDetailInfo> list = videoDetailInfoDao.list("from VideoDetailInfo d where d.name=?",
                new String[]{name});
        LogUtil.i("请求结束:" + System.currentTimeMillis());
        return list;
    }
   /**
    * 更新视频的详情
    *
    * @param list
    */
   public void updateVideoDetail(final List<VideoDetailInfo> list) {
    public List<VideoDetailInfo> getVideoDetail(Session session, String videoId) {
        @SuppressWarnings("unchecked")
        List<VideoDetailInfo> list = session.createQuery("from VideoDetailInfo d where d.video.id=?")
                .setParameter(0, videoId).list();
        LogUtil.i("请求结束:" + System.currentTimeMillis());
        return list;
    }
      videoInfoDao.excute(new HibernateCallback() {
         public Object doInHibernate(Session session) throws HibernateException {
            try {
    /**
     * 更新视频的详情
     *
     * @param list
     */
    public void updateVideoDetail(final List<VideoDetailInfo> list) {
               // BaseDao<VideoDetailInfo> dao = new
               // BaseDao<VideoDetailInfo>();
               // /BaseDao<VideoUrl> urlDao = new BaseDao<VideoUrl>();
               // BaseDao<VideoDetailInfo> dao = new
               // BaseDao<VideoDetailInfo>();
               session.getTransaction().begin();
               for (int i = 0; i < list.size(); i++) {
                  for (int j = 0; j < list.get(i).getUrls().size(); j++) {
                     session.createSQLQuery("update wk_video_video_url set vdetailurl=? where id=?")
                           .setParameter(0, list.get(i).getUrls().get(j).getUrl())
                           .setParameter(1, list.get(i).getUrls().get(j).getId() + "").executeUpdate();
                  }
               }
               session.flush();
               session.getTransaction().commit();
            } catch (Exception e) {
               e.printStackTrace();
               session.getTransaction().rollback();
            }
            return null;
         }
      });
        videoInfoDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                try {
   }
                    // BaseDao<VideoDetailInfo> dao = new
                    // BaseDao<VideoDetailInfo>();
                    // /BaseDao<VideoUrl> urlDao = new BaseDao<VideoUrl>();
                    // BaseDao<VideoDetailInfo> dao = new
                    // BaseDao<VideoDetailInfo>();
                    session.getTransaction().begin();
                    for (int i = 0; i < list.size(); i++) {
                        for (int j = 0; j < list.get(i).getUrls().size(); j++) {
                            session.createSQLQuery("update wk_video_video_url set vdetailurl=? where id=?")
                                    .setParameter(0, list.get(i).getUrls().get(j).getUrl())
                                    .setParameter(1, list.get(i).getUrls().get(j).getId() + "").executeUpdate();
                        }
                    }
                    session.flush();
                    session.getTransaction().commit();
                } catch (Exception e) {
                    e.printStackTrace();
                    session.getTransaction().rollback();
                }
                return null;
            }
        });
   public void updateVideoDetail(final VideoDetailInfo detail) {
      if (detail.getUrls() == null || detail.getUrls().size() < 1)
         return;
    }
      videoInfoDao.excute(new HibernateCallback() {
         public Object doInHibernate(Session session) throws HibernateException {
            try {
               session.getTransaction().begin();
               session.createQuery("delete from VideoUrl vu where vu.videoDetail.id=?")
                     .setParameter(0, detail.getId()).executeUpdate();
               for (VideoUrl vu : detail.getUrls())
                  session.save(vu);
               session.update(detail);
               session.flush();
               session.getTransaction().commit();
            } catch (Exception e) {
               e.printStackTrace();
               session.getTransaction().rollback();
            }
            return null;
         }
      });
    public void updateVideoDetail(final VideoDetailInfo detail) {
        if (detail.getUrls() == null || detail.getUrls().size() < 1)
            return;
   }
        videoInfoDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                try {
                    session.getTransaction().begin();
                    session.createQuery("delete from VideoUrl vu where vu.videoDetail.id=?")
                            .setParameter(0, detail.getId()).executeUpdate();
                    for (VideoUrl vu : detail.getUrls())
                        session.save(vu);
                    session.update(detail);
                    session.flush();
                    session.getTransaction().commit();
                } catch (Exception e) {
                    e.printStackTrace();
                    session.getTransaction().rollback();
                }
                return null;
            }
        });
   public void deleteVideoDetail(VideoDetailInfo detail) {
      videoDetailInfoDao.delete(detail);
   }
    }
   /**
    * 更新视频的详情
    *
    * @param list
    */
   public void updateVideoDetailByAdmin(final List<VideoDetailInfo> list) {
      videoInfoDao.excute(new HibernateCallback() {
         public Object doInHibernate(Session session) throws HibernateException {
            try {
               session.getTransaction().begin();
               for (int i = 0; i < list.size(); i++) {
                  try {
                     session.persist(list.get(i));
                  } catch (Exception e) {
                     session.update(list.get(i));
                  }
               }
               session.flush();
               session.getTransaction().commit();
            } catch (Exception e) {
               e.printStackTrace();
               LogUtil.i("事物回滚");
               session.getTransaction().rollback();
            }
            return null;
         }
      });
    public void deleteVideoDetail(VideoDetailInfo detail) {
        videoDetailInfoDao.delete(detail);
    }
   }
    /**
     * 更新视频的详情
     *
     * @param list
     */
    public void updateVideoDetailByAdmin(final List<VideoDetailInfo> list) {
        videoInfoDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                try {
                    session.getTransaction().begin();
                    for (int i = 0; i < list.size(); i++) {
                        try {
                            session.persist(list.get(i));
                        } catch (Exception e) {
                            session.update(list.get(i));
                        }
                    }
                    session.flush();
                    session.getTransaction().commit();
                } catch (Exception e) {
                    e.printStackTrace();
                    LogUtil.i("事物回滚");
                    session.getTransaction().rollback();
                }
                return null;
            }
        });
   @SuppressWarnings("unchecked")
   public void deleteVideo(final String videoId) {
      try {
         videoInfoDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
               try {
                  List<HomeVideo> hlist = session.createQuery("from HomeVideo v where v.video.id=?")
                        .setParameter(0, videoId).list();
                  session.getTransaction().begin();
                  JuheVideoUtil.clearData(session, videoId);
                  if (hlist != null && hlist.size() > 0) {
                     for (HomeVideo hv : hlist) {
                        session.delete(hv);
                     }
                  }
                  // 删除收藏
                  session.createSQLQuery("delete from wk_video_collection where videoid=" + videoId)
                        .executeUpdate();
    }
                  List<VideoBanQuanVideo> qlist = session
                        .createQuery("from VideoBanQuanVideo c where c.info.id=?").setParameter(0, videoId)
                        .list();
                  if (qlist != null && qlist.size() > 0) {
                     for (VideoBanQuanVideo c : qlist)
                        session.delete(c);
                  }
                  List<HomeAd> hdList = session
                        .createQuery("from HomeAd ha where ha.linkType=1 and ha.video.id=?")
                        .setParameter(0, videoId).list();
    @Resource
    private AlbumVideoMapService albumVideoMapService;
                  for (HomeAd had : hdList) {
                     List<SuperHomeAd> shadL = session
                           .createQuery("from SuperHomeAd shad where shad.homeAd.id=?")
                           .setParameter(0, had.getId()).list();
                     for (SuperHomeAd shad : shadL)
                        session.delete(shad);
                     session.delete(had);
                  }
    /**
     * 删除视频
     *
     * @param videoId
     */
    public void deleteVideo(final String videoId) {
        //清除sql数据表相关依赖
        clearService.clearDependVideo(videoId);
        //清除MongoDB相关依赖
        albumVideoMapService.deleteByVideoId(videoId);
        //更新搜索引擎数据
        CMQManager.getInstance().addSolrMsg(videoId);
        videoInfoDao.delete(new VideoInfo(videoId));
    }
                  // 专题视频删除
                  List<SpecialVideo> svList = session.createQuery("from SpecialVideo ha where ha.video.id=?")
                        .setParameter(0, videoId).list();
    // 更新视频的观看数
    public void updateVideoWatchCount(final String videoId) {
        videoInfoDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                try {
                    session.getTransaction().begin();
                    session.createSQLQuery("update wk_video_video set watchcount=(watchcount+1) where id=" + videoId)
                            .executeUpdate();
                    session.flush();
                    session.getTransaction().commit();
                } catch (Exception e) {
                    e.printStackTrace();
                    session.getTransaction().rollback();
                }
                return null;
            }
        });
                  for (SpecialVideo sv : svList) {
                     List<SuperSpecial> shadL = session
                           .createQuery("from SuperSpecial shad where shad.special.id=?")
                           .setParameter(0, sv.getSpecial().getId()).list();
                     for (SuperSpecial shad : shadL)
                        session.delete(shad);
                     session.delete(sv);
                  }
    }
                  // 合集视频删除
                  List<VideoIntersectionVideo> viList = session
                        .createQuery("from VideoIntersectionVideo ha where ha.video.id=?")
                        .setParameter(0, videoId).list();
                  for (VideoIntersectionVideo sv : viList) {
                     session.delete(sv);
                  }
    @OneToMany
    private List<VideoDetailInfo> getVideoDetailList() {
        List<VideoDetailInfo> list = new ArrayList<VideoDetailInfo>();
        VideoDetailInfo info = new VideoDetailInfo();
        info.setAdmin(getAdmin());
        info.setBeizhu("测试信息");
        info.setCreatetime(System.currentTimeMillis() + "");
        info.setName("功夫");
        info.setTag("");
        List<VideoUrl> urlList = info.getUrls();
        VideoUrl url = new VideoUrl();
        url.setAdmin(getAdmin());
        url.setBeizhu("测试");
        url.setCreatetime(System.currentTimeMillis() + "");
        VideoResource resource = new VideoResource();
        resource.setId("1");
        url.setResource(resource);
        url.setUrl("http://123333.mp4");
        urlList.add(url);
        info.setUrls(urlList);
        list.add(info);
        return list;
    }
                  // 视频删除
                  List<VideoDetailInfo> list = session.createQuery("from VideoDetailInfo v where v.video.id=?")
                        .setParameter(0, videoId).list();
                  // 删除视频的详细信息
                  for (VideoDetailInfo object : list) {
                     // 删除链接信息
                     for (VideoUrl vu : object.getUrls())
                        session.delete(vu);
                     // 删除详情
                     session.delete(object);
                  }
    @SuppressWarnings("finally")
    public boolean changeVideoShow(final VideoInfo info) {
        return (Boolean) videoInfoDao.excute(new HibernateCallback<Boolean>() {
            public Boolean doInHibernate(Session session) throws HibernateException {
                int result = 0;
                try {
                    session.getTransaction().begin();
                    result = session.createSQLQuery("update wk_video_video set `show`=? where `id`=?")
                            .setParameter(0, info.getShow()).setParameter(1, info.getId()).executeUpdate();
                    session.flush();
                    session.getTransaction().commit();
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    if (result > 0)
                        return true;
                    else
                        return false;
                }
                  // 删除视频源信息
                  session.createSQLQuery("delete  from wk_video_video where id=?").setParameter(0, videoId)
                        .executeUpdate();
                  session.flush();
                  session.getTransaction().commit();
               } catch (Exception e) {
                  e.printStackTrace();
                  session.getTransaction().rollback();
               }
               return null;
            }
         });
      } catch (Exception e) {
         e.printStackTrace();
      }
            }
        });
   }
    }
   // 更新视频的观看数
   public void updateVideoWatchCount(final String videoId) {
      videoInfoDao.excute(new HibernateCallback() {
         public Object doInHibernate(Session session) throws HibernateException {
            try {
               session.getTransaction().begin();
               session.createSQLQuery("update wk_video_video set watchcount=(watchcount+1) where id=" + videoId)
                     .executeUpdate();
               session.flush();
               session.getTransaction().commit();
            } catch (Exception e) {
               e.printStackTrace();
               session.getTransaction().rollback();
            }
            return null;
         }
      });
    /**
     * 生成视频的名称--唯一
     *
     * @return
     */
    public String getVideoPathName(String type, String oldName) {
        String src = (long) (Math.random() * 100000000)
                + StringUtil.Md5(System.currentTimeMillis() + (long) (Math.random() * 100000000) + "");
        return StringUtil.getBase64(src) + "_" + StringUtil.getBase64(oldName) + "." + type;
    }
   }
    @ManyToOne
    private VideoType getVideoType() {
        VideoType type = new VideoType();
        type.setId(1);
        return type;
    }
   @OneToMany
   private List<VideoDetailInfo> getVideoDetailList() {
      List<VideoDetailInfo> list = new ArrayList<VideoDetailInfo>();
      VideoDetailInfo info = new VideoDetailInfo();
      info.setAdmin(getAdmin());
      info.setBeizhu("测试信息");
      info.setCreatetime(System.currentTimeMillis() + "");
      info.setName("功夫");
      info.setTag("");
      List<VideoUrl> urlList = info.getUrls();
      VideoUrl url = new VideoUrl();
      url.setAdmin(getAdmin());
      url.setBeizhu("测试");
      url.setCreatetime(System.currentTimeMillis() + "");
      VideoResource resource = new VideoResource();
      resource.setId("1");
      url.setResource(resource);
      url.setUrl("http://123333.mp4");
      urlList.add(url);
      info.setUrls(urlList);
      list.add(info);
      return list;
   }
    // 隐藏视频
    public void setVideoHidden(final String urlKey) {
   @SuppressWarnings("finally")
   public boolean changeVideoShow(final VideoInfo info) {
      return (Boolean) videoInfoDao.excute(new HibernateCallback<Boolean>() {
         public Boolean doInHibernate(Session session) throws HibernateException {
            int result = 0;
            try {
               session.getTransaction().begin();
               result = session.createSQLQuery("update wk_video_video set `show`=? where `id`=?")
                     .setParameter(0, info.getShow()).setParameter(1, info.getId()).executeUpdate();
               session.flush();
               session.getTransaction().commit();
            } catch (Exception e) {
               e.printStackTrace();
            } finally {
               if (result > 0)
                  return true;
               else
                  return false;
            }
        videoInfoDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                List<String> listSt = new ArrayList<String>();
                try {
                    List list = session
                            .createSQLQuery(
                                    "select d.videoid from wk_video_video_url u left join wk_video_video_detail d on d.id=u.videodetailid where vdetailurl like ?")
                            .setParameter(0, "%" + urlKey + "%").list();
                    for (int i = 0; i < list.size(); i++) {
                        Object obj = (Object) list.get(i);
                        listSt.add(obj.toString());
                        LogUtil.i(obj.toString());
                    }
                    LogUtil.i(list.size());
                    for (int j = 0; j < listSt.size(); j++) {
                        VideoInfo vi = videoInfoDao.find(VideoInfo.class, listSt.get(j));
                        vi.setShow("0");
                        videoInfoDao.update(vi);
                    }
         }
      });
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return null;
            }
        });
   }
   /**
    * 生成视频的名称--唯一
    *
    * @return
    */
   public String getVideoPathName(String type, String oldName) {
      String src = (long) (Math.random() * 100000000)
            + StringUtil.Md5(System.currentTimeMillis() + (long) (Math.random() * 100000000) + "");
      return StringUtil.getBase64(src) + "_" + StringUtil.getBase64(oldName) + "." + type;
   }
   @ManyToOne
   private VideoType getVideoType() {
      VideoType type = new VideoType();
      type.setId(1);
      return type;
   }
   // 隐藏视频
   public void setVideoHidden(final String urlKey) {
      videoInfoDao.excute(new HibernateCallback() {
         public Object doInHibernate(Session session) throws HibernateException {
            List<String> listSt = new ArrayList<String>();
            try {
               List list = session
                     .createSQLQuery(
                           "select d.videoid from wk_video_video_url u left join wk_video_video_detail d on d.id=u.videodetailid where vdetailurl like ?")
                     .setParameter(0, "%" + urlKey + "%").list();
               for (int i = 0; i < list.size(); i++) {
                  Object obj = (Object) list.get(i);
                  listSt.add(obj.toString());
                  LogUtil.i(obj.toString());
               }
               LogUtil.i(list.size());
               for (int j = 0; j < listSt.size(); j++) {
                  VideoInfo vi = videoInfoDao.find(VideoInfo.class, listSt.get(j));
                  vi.setShow("0");
                  videoInfoDao.update(vi);
               }
            } catch (Exception e) {
               e.printStackTrace();
            }
            return null;
         }
      });
   }
    }
}