package com.newvideo.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 org.apache.log4j.Logger;
|
import org.hibernate.HibernateException;
|
import org.hibernate.Session;
|
import org.springframework.orm.hibernate4.HibernateCallback;
|
import org.springframework.stereotype.Service;
|
|
import com.newvideo.dao.VideoInfoDao;
|
import com.newvideo.dao.VideoResourceDao;
|
import com.newvideo.dao.juhe.FunTVAlbumDao;
|
import com.newvideo.dao.juhe.FunTVAlbumVideoMapDao;
|
import com.newvideo.dao.juhe.FunTVVideoDao;
|
import com.newvideo.dao.juhe.VideoFunTVDao;
|
import com.newvideo.domain.CategoryVideo;
|
import com.newvideo.domain.ResourceVideo;
|
import com.newvideo.domain.VideoDetailInfo;
|
import com.newvideo.domain.VideoInfo;
|
import com.newvideo.domain.VideoResource;
|
import com.newvideo.domain.VideoType;
|
import com.newvideo.domain.VideoUrl;
|
import com.newvideo.domain.entity.PlayUrl;
|
import com.newvideo.domain.push.VideoPushHistory;
|
import com.newvideo.funtv.FunTVUtil;
|
import com.newvideo.funtv.entity.FunTVAlbum;
|
import com.newvideo.funtv.entity.FunTVAlbumVideoMap;
|
import com.newvideo.funtv.entity.FunTVVideo;
|
import com.newvideo.funtv.entity.VideoFunTV;
|
import com.newvideo.service.imp.BanQuanService;
|
import com.newvideo.service.imp.StatisticsService;
|
import com.newvideo.service.imp.VideoManager;
|
import com.newvideo.service.imp.VideoResourceService;
|
import com.newvideo.service.imp.VideoService;
|
import com.newvideo.service.imp.push.PushService;
|
import com.newvideo.util.StringUtil;
|
|
import net.sf.json.JSONObject;
|
|
@Service
|
public class FunTVService {
|
Logger log = Logger.getLogger(FunTVService.class);
|
@Resource
|
private VideoFunTVDao videoFunTVDao;
|
@Resource
|
private FunTVVideoDao funTVVideoDao;
|
@Resource
|
private FunTVAlbumDao funTVAlbumDao;
|
@Resource
|
private FunTVAlbumVideoMapDao funTVAlbumVideoMapDao;
|
|
@Resource
|
private StatisticsService statisticsService;
|
@Resource
|
private PushService pushService;
|
|
@Resource
|
private VideoService videoService;
|
@Resource
|
private VideoResourceService videoResourceService;
|
@Resource
|
private BanQuanService banQuanService;
|
|
@Resource
|
private VideoInfoDao videoInfoDao;
|
|
@Resource
|
private VideoResourceDao videoResourceDao;
|
|
@Resource
|
private VideoManager videoManager;
|
|
static Logger logger = Logger.getLogger(FunTVService.class);
|
|
public FunTVVideo getFunTVVideo(long id) {
|
return funTVVideoDao.find(FunTVVideo.class, id);
|
}
|
|
public Serializable saveSigleAlbum(FunTVAlbum pm) {
|
return funTVAlbumDao.save(pm);
|
}
|
|
public Serializable saveFunTVVideo(FunTVVideo pv) {
|
return funTVVideoDao.save(pv);
|
}
|
|
public void saveFunTVVideoMap(FunTVAlbumVideoMap pvm) {
|
funTVAlbumVideoMapDao.create(pvm);
|
}
|
|
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;
|
}
|
|
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;
|
}
|
|
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());
|
}
|
|
} catch (Exception e) {
|
if (!e.getMessage().contains("Duplicate")) {
|
log.error(e.getMessage());
|
}
|
}
|
|
for (FunTVVideo pv : videoList) {
|
try {
|
FunTVVideo dpv = getFunTVVideoByVid(pv.getVid());
|
|
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());
|
}
|
}
|
|
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());
|
}
|
}
|
}
|
}
|
|
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());
|
}
|
}
|
}
|
|
@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();
|
|
if (isUpdate)
|
vi.setUpdatetime(System.currentTimeMillis() + "");
|
session.update(vi);
|
|
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();
|
}
|
|
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();
|
}
|
|
// 获取最新一集的信息
|
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());
|
}
|
|
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);
|
}
|
}
|
}
|
|
// 添加单个视频进入
|
@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 {
|
|
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();
|
}
|
|
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);
|
}
|
|
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 Serializable addVideoInfo(VideoInfo info, FunTVAlbum p) {
|
Serializable id = videoInfoDao.save(info);
|
return id;
|
}
|
|
public Serializable addVideoInfo(VideoInfo info, FunTVVideo p) {
|
Serializable id = videoInfoDao.save(info);
|
return id;
|
}
|
|
public void saveVideoFunTV(VideoFunTV vyk) {
|
try {
|
videoFunTVDao.save(vyk);
|
} catch (Exception e) {
|
|
}
|
|
}
|
|
// 错误
|
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 long getFunTVVideoCount(String pid) {
|
return videoFunTVDao.getCount("select count(*) from VideoFunTV m where m.album.id=?",
|
new Serializable[] { pid });
|
}
|
|
public VideoDetailInfo getLatestVideoDetail(String videoid) {
|
|
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 String[] { 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) {
|
|
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);
|
|
if (typeList.size() == 0)
|
typeList.add(299);
|
|
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;
|
}
|
}
|
|
if (infoList != null && infoList.size() > 0 && isSame) {// 无需加入
|
updateVideoInfo(info, video, p, isUpdate);
|
} else {// 需要新加入videoinfo
|
Serializable id = addVideoInfo(info, p);
|
|
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);
|
}
|
|
VideoFunTV vft = new VideoFunTV();
|
vft.setAlbum(new FunTVAlbum(p.getId()));
|
vft.setVideo(new VideoInfo(info.getId()));
|
vft.setTvVideo(null);
|
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 void addVideoToVideoInfo(final FunTVVideo p) {
|
VideoInfo info = FunTVUtil.convertVideoToVideoInfo(p);
|
try {
|
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);
|
;
|
} else {// 需要新加入videoinfo
|
Serializable id = addVideoInfo(info, p);
|
List<Integer> typeList = new ArrayList<Integer>();
|
typeList = FunTVUtil.getShortVideoType(p, p.getCate(), p.getSubCate());
|
|
if (typeList == null || typeList.size() <= 0)
|
return;
|
|
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);
|
}
|
|
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();
|
}
|
|
}
|
|
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;
|
}
|
}
|
|
return 1;
|
}
|
|
@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);
|
}
|
}
|
|
FunTVVideo fvideo = getFunTVVideo(Long.parseLong(id));
|
|
JSONObject object = new JSONObject();
|
object.put("vid", fvideo.getVid());
|
playUrl.setParams(object.toString());
|
playUrl.setUrl(fvideo.getPlayMUrl());
|
if (fvideo.getPlayMUrl() != null)
|
playUrl.setUrl(fvideo.getPlayMUrl().replace("malliance=2501", "malliance=0"));
|
playUrl.setPlayType(1);// 全部跳转网页
|
return playUrl;
|
}
|
|
public List<VideoDetailInfo> getVideoDetailList(String videoid) {
|
|
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 != 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) {
|
|
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);
|
|
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;
|
}
|
}
|
|
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;
|
}
|
|
public void deleteVideoByAid(String aid) {
|
// 查询出对应的VID与videoid
|
final FunTVAlbum album = new FunTVAlbum(0); // getAlbumByAid(aid);
|
|
if (album != null) {
|
String videoId = (String) funTVVideoDao.excute(new HibernateCallback<String>() {
|
|
@SuppressWarnings("unchecked")
|
public String doInHibernate(Session session) throws HibernateException {
|
String videoid = null;
|
|
List<FunTVVideo> list = session
|
.createQuery("select m.video from FunTVAlbumVideoMap m where m.album.id=" + album.getId())
|
.list();
|
session.getTransaction().begin();
|
try {
|
|
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 (videoId != null) {// 可以删除视频
|
videoManager.deleteVideo(videoId);
|
}
|
|
}
|
|
}
|
|
public void deleteVideoByVid(String vid) {
|
// 查询出对应的VID与videoid
|
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;
|
|
List<FunTVVideo> list = session
|
.createQuery("select m.video from FunTVAlbumVideoMap m where m.album.id=" + video.getId())
|
.list();
|
session.getTransaction().begin();
|
try {
|
|
for (FunTVVideo tv : list) {// 删除视频
|
session.delete(tv);
|
}
|
session.delete(video);// 删除专辑
|
List<VideoFunTV> ftlist = session
|
.createQuery(
|
"from VideoFunTV vf where vf.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;
|
}
|
});
|
|
if (videoId != null) {// 可以删除视频
|
videoManager.deleteVideo(videoId);
|
}
|
|
}
|
|
}
|
|
}
|