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.VideoYouKuDao;
|
import com.newvideo.dao.juhe.ProgramDao;
|
import com.newvideo.dao.juhe.ProgramVideoDao;
|
import com.newvideo.dao.juhe.ProgramVideoMapDao;
|
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.entity.PlayUrl;
|
import com.newvideo.domain.push.VideoPushHistory;
|
import com.newvideo.service.imp.BanQuanService;
|
import com.newvideo.service.imp.StatisticsService;
|
import com.newvideo.service.imp.VideoResourceService;
|
import com.newvideo.service.imp.VideoService;
|
import com.newvideo.service.imp.push.PushService;
|
import com.newvideo.util.Constant;
|
import com.newvideo.util.StringUtil;
|
import com.newvideo.youku.YouKuApi;
|
import com.newvideo.youku.YouKuUtil;
|
import com.newvideo.youku.entity.Program;
|
import com.newvideo.youku.entity.ProgramVideo;
|
import com.newvideo.youku.entity.ProgramVideoMap;
|
import com.newvideo.youku.entity.VideoYouKu;
|
|
import net.sf.json.JSONObject;
|
|
@Service
|
public class YouKuService {
|
Logger log = Logger.getLogger(YouKuService.class);
|
@Resource
|
private VideoYouKuDao videoYouKuDao;
|
@Resource
|
private StatisticsService statisticsService;
|
@Resource
|
private PushService pushService;
|
@Resource
|
private ProgramDao programDao;
|
@Resource
|
private ProgramVideoDao programVideoDao;
|
@Resource
|
private VideoService videoService;
|
@Resource
|
private VideoResourceService videoResourceService;
|
@Resource
|
private BanQuanService banQuanService;
|
@Resource
|
private ProgramVideoMapDao programVideoMapDao;
|
|
@Resource
|
private VideoInfoDao videoInfoDao;
|
|
@Resource
|
private VideoResourceDao videoResourceDao;
|
|
static Logger logger = Logger.getLogger(YouKuService.class);
|
|
public VideoService getVideoService() {
|
return videoService;
|
}
|
|
public void setVideoService(VideoService videoService) {
|
this.videoService = videoService;
|
}
|
|
public VideoResourceService getVideoResourceService() {
|
return videoResourceService;
|
}
|
|
public void setVideoResourceService(VideoResourceService videoResourceService) {
|
this.videoResourceService = videoResourceService;
|
}
|
|
public ProgramVideoDao getProgramVideoDao() {
|
return programVideoDao;
|
}
|
|
public void setProgramVideoDao(ProgramVideoDao programVideoDao) {
|
this.programVideoDao = programVideoDao;
|
}
|
|
public ProgramDao getProgramDao() {
|
return programDao;
|
}
|
|
public void setProgramDao(ProgramDao programDao) {
|
this.programDao = programDao;
|
}
|
|
public PushService getPushService() {
|
return pushService;
|
}
|
|
public void setPushService(PushService pushService) {
|
this.pushService = pushService;
|
}
|
|
public StatisticsService getStatisticsService() {
|
return statisticsService;
|
}
|
|
public void setStatisticsService(StatisticsService statisticsService) {
|
this.statisticsService = statisticsService;
|
}
|
|
public VideoYouKuDao getVideoYouKuDao() {
|
return videoYouKuDao;
|
}
|
|
public void setVideoYouKuDao(VideoYouKuDao videoYouKuDao) {
|
this.videoYouKuDao = videoYouKuDao;
|
}
|
|
public void saveSigleProgram(Program pm) {
|
programDao.create(pm);
|
}
|
|
public void saveProgramVideo(ProgramVideo pv) {
|
programVideoDao.create(pv);
|
|
}
|
|
public void saveProgramVideoMap(ProgramVideoMap pvm) {
|
|
programVideoMapDao.create(pvm);
|
|
}
|
|
public void saveProgram(Program pm, List<ProgramVideo> videoList) {
|
try {
|
if (programDao.find(Program.class, pm.getId()) == null)
|
saveSigleProgram(pm);
|
} catch (Exception e) {
|
if (!e.getMessage().contains("Duplicate")) {
|
log.error(e.getMessage());
|
}
|
}
|
|
for (ProgramVideo pv : videoList) {
|
try {
|
if (programVideoDao.find(ProgramVideo.class, pv.getId()) == null) {
|
ProgramVideo v = YouKuApi.getVideoDetail(pv.getId());
|
if (v != null) {
|
pv.setOperationLimit(v.getOperationLimit());
|
pv.setCopyright_type(v.getCopyright_type());
|
pv.setPublic_type(v.getPublic_type());
|
}
|
saveProgramVideo(pv);
|
}
|
} catch (Exception e) {
|
if (!e.getMessage().contains("Duplicate")) {
|
log.error(e.getMessage());
|
}
|
}
|
|
ProgramVideoMap pvm = new ProgramVideoMap();
|
pvm.setProgram(pm);
|
pvm.setProgramVideo(pv);
|
try {
|
saveProgramVideoMap(pvm);
|
} catch (Exception e) {
|
if (!e.getMessage().contains("Duplicate")) {
|
log.error(e.getMessage());
|
}
|
}
|
}
|
}
|
|
public void saveVideo(ProgramVideo video) {
|
try {
|
if (programVideoDao.find(ProgramVideo.class, video.getId()) == null)
|
saveProgramVideo(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 Program p, final boolean isUpdate) {
|
final VideoInfo vi = video;
|
videoYouKuDao.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);
|
|
VideoYouKu vyk = new VideoYouKu();
|
vyk.setProgram(new Program(p.getId()));
|
vyk.setVideo(new VideoInfo(vi.getId()));
|
vyk.setYvideo(null);
|
Object obj = session
|
.createQuery(
|
"select count(*) from VideoYouKu vyk where vyk.video.id=? and vyk.program.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_youku (videoid, programid) values (%s, '%s')",
|
vyk.getVideo().getId(), vyk.getProgram().getId()))
|
.executeUpdate();
|
}
|
|
obj = session.createQuery(String.format(
|
"select count(*) from ResourceVideo rv where rv.video.id=%s and rv.resource.id=%s",
|
vi.getId(), 15 + "")).uniqueResult();
|
if (Integer.parseInt(obj + "") <= 0) {// 加入
|
ResourceVideo rv = new ResourceVideo();
|
rv.setResource(new VideoResource(15 + ""));
|
rv.setVideo(new VideoInfo(vi.getId()));
|
session.createSQLQuery(String.format(
|
"insert into wk_resource_video(videoid,resourceid) values(%s,%s)", vi.getId(), 15 + ""))
|
.executeUpdate();
|
}
|
|
// 获取最新一集的信息
|
List<ProgramVideo> plist = session
|
.createQuery(
|
"select map.programVideo from ProgramVideoMap map where map.program.id=? order by CAST(map.programVideo.stage as integer) desc")
|
.setParameter(0, p.getId()).setFirstResult(0).setMaxResults(1).list();
|
if (plist.size() > 0) {
|
List<VideoDetailInfo> detailList = new ArrayList<VideoDetailInfo>();
|
detailList.add(YouKuUtil.convertProgramVideoToVideoDetail(plist.get(0), p));
|
vi.setVideoDetailList(detailList);
|
}
|
session.flush();
|
session.getTransaction().commit();
|
} catch (Exception e) {
|
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(15 + "");
|
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 ProgramVideo p, final String genre) {
|
final VideoInfo vi = video;
|
videoYouKuDao.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);
|
VideoYouKu vyk = new VideoYouKu();
|
vyk.setProgram(null);
|
vyk.setVideo(new VideoInfo(vi.getId()));
|
vyk.setYvideo(new ProgramVideo(p.getId()));
|
Object obj = session
|
.createQuery(
|
"select count(*) from VideoYouKu vyk where vyk.video.id=? and vyk.yvideo.id=?")
|
.setParameter(0, vi.getId()).setParameter(1, p.getId()).uniqueResult();
|
if (Integer.parseInt(obj + "") <= 0) {// 加入
|
session.createSQLQuery(
|
String.format("insert into wk_video_youku (videoid, yvideoid) values (%s, '%s')",
|
vyk.getVideo().getId(), vyk.getYvideo().getId()))
|
.executeUpdate();
|
}
|
|
List<Integer> typeList = YouKuUtil.getProgramVideoType(p, genre);
|
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(), 15 + "")).uniqueResult();
|
if (Integer.parseInt(obj + "") <= 0) {// 加入
|
ResourceVideo rv = new ResourceVideo();
|
rv.setResource(new VideoResource(15 + ""));
|
rv.setVideo(new VideoInfo(vi.getId()));
|
session.createSQLQuery(String.format(
|
"insert into wk_resource_video(videoid,resourceid) values(%s,%s)", vi.getId(), 15 + ""))
|
.executeUpdate();
|
}
|
session.flush();
|
session.getTransaction().commit();
|
} catch (Exception e) {
|
System.out.println("出错:" + e.getMessage());
|
}
|
|
return null;
|
}
|
});
|
|
}
|
|
public Serializable addVideoInfo(VideoInfo info, Program p) {
|
Serializable id = videoInfoDao.save(info);
|
return id;
|
}
|
|
public Serializable addVideoInfo(VideoInfo info, ProgramVideo p) {
|
Serializable id = videoInfoDao.save(info);
|
return id;
|
}
|
|
public void saveVideoYouKu(VideoYouKu vyk) {
|
try {
|
videoYouKuDao.save(vyk);
|
} catch (Exception e) {
|
|
}
|
|
}
|
|
public void addPlayStatistics(String detailSystemId, String vid) {
|
List list = videoYouKuDao.sqlList(
|
"SELECT vy.`videoid` FROM wk_youku_program_video pv LEFT JOIN wk_youku_program p ON p.`id`=pv.`programid` 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 = videoYouKuDao.sqlList("select y.videoid from wk_video_youku y where y.yvideoid=?",
|
new Serializable[] { vid });
|
if (list != null && list.size() > 0)
|
statisticsService.addStatistics(detailSystemId, list.get(0) + "");
|
}
|
}
|
|
public long getProgramVideoCount(String pid) {
|
return videoYouKuDao.getCount("select count(*) from ProgramVideoMap m where m.program.id=?",
|
new Serializable[] { pid });
|
}
|
|
public VideoDetailInfo getLatestVideoDetail(String videoid) {
|
|
List<VideoYouKu> list = videoYouKuDao.list("from VideoYouKu vy where vy.video.id=?", new String[] { videoid });
|
if (list != null && list.size() > 0) {
|
final VideoYouKu vyk = list.get(0);
|
if (vyk.getProgram() != null) {// 按节目查找视频
|
List<ProgramVideo> videoList = programVideoDao.list(
|
"select map.programVideo from ProgramVideoMap map where map.program.id=? order by CAST(map.programVideo.stage as integer) desc",
|
0, 1, new String[] { vyk.getProgram().getId() });
|
|
List<VideoDetailInfo> detailList = new ArrayList<VideoDetailInfo>();
|
for (ProgramVideo pv : videoList)
|
detailList.add(YouKuUtil.convertProgramVideoToVideoDetail(pv, vyk.getProgram()));
|
return detailList.get(0);
|
} else if (vyk.getYvideo() != null) {// 单个视频----待定
|
programDao.list("");
|
}
|
}
|
|
return null;
|
}
|
|
@SuppressWarnings("unchecked")
|
public void addProgramToVideoInfo(final Program p, final boolean isUpdate) {
|
|
final VideoInfo info = YouKuUtil.convertProgramToVideoInfo(p);
|
// 类型计算
|
final List<Integer> typeList = new ArrayList<Integer>();
|
String[] gs = p.getGenre().split(",");
|
for (String g : gs) {
|
int type = YouKuUtil.getProgramType(p, g);
|
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.getName() });
|
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 YouKuUtil.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);
|
}
|
|
VideoYouKu vyk = new VideoYouKu();
|
vyk.setProgram(new Program(p.getId()));
|
vyk.setVideo(new VideoInfo(info.getId()));
|
vyk.setYvideo(null);
|
saveVideoYouKu(vyk);
|
|
videoResourceService.excuteSQL(String.format(
|
"insert into wk_resource_video(videoid,resourceid) values(%s,%s)", info.getId(), 15 + ""));
|
|
// ResourceVideo rv = new ResourceVideo();
|
// rv.setResource(new VideoResource(15 + ""));
|
// rv.setVideo(new VideoInfo(info.getId()));
|
// session.persist(rv);
|
}
|
}
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
}
|
|
@SuppressWarnings("unchecked")
|
public void addVideoToVideoInfo(final ProgramVideo p, String genre) {
|
|
VideoInfo info = YouKuUtil.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 = YouKuUtil.getProgramVideoType(p, genre);
|
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);
|
}
|
|
VideoYouKu vyk = new VideoYouKu();
|
vyk.setProgram(null);
|
vyk.setVideo(new VideoInfo(info.getId()));
|
vyk.setYvideo(p);
|
saveVideoYouKu(vyk);
|
|
videoResourceService.excuteSQL(String.format(
|
"insert into wk_resource_video(videoid,resourceid) values(%s,%s)", info.getId(), 15 + ""));
|
}
|
}
|
|
} catch (
|
|
Exception e)
|
|
{
|
e.printStackTrace();
|
}
|
|
}
|
|
public int getShowType(String vid) {
|
List<Program> list = programDao.list("select vs.program From VideoYouKu vs where vs.video.id=?",
|
new Serializable[] { vid });
|
if (list != null && list.size() > 0) {
|
if (list.get(0) != null) {
|
if (list.get(0).getCategory().contains("电视剧") || list.get(0).getCategory().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();
|
playUrl.setPlayType(2);
|
|
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("youkuvideo")) {
|
List<BigInteger> idList = (List<BigInteger>) videoResourceDao.sqlList(
|
"SELECT yk.`videoid` FROM wk_video_youku yk WHERE yk.`programid`= ( SELECT p.`programid` FROM wk_youku_video v LEFT JOIN wk_youku_program_video p ON p.`videoid`=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 (!type.equalsIgnoreCase("youkuvideo")) {
|
ProgramVideo pv = YouKuApi.getVideoDetail(id);
|
if ("original".equalsIgnoreCase(pv.getCopyright_type()))
|
playUrl.setPlayType(1);
|
} else if ("43".equalsIgnoreCase(detailSystemId)) {
|
ProgramVideo pv = YouKuApi.getVideoDetail(id);
|
if ("original".equalsIgnoreCase(pv.getCopyright_type()))
|
playUrl.setPlayType(1);
|
}
|
// else {//小视频暂时不设置权限
|
// List<BigInteger> idList = (List<BigInteger>)
|
// videoResourceDao.sqlList(
|
// "SELECT yk.`videoid` FROM wk_video_youku yk WHERE yk.`yvideoid`= ?",
|
// new Serializable[] { id });
|
// if (idList != null && idList.size() > 0) {
|
// boolean isNeedWeb = banQuanService.isNeedWebPlay(detailSystemId,
|
// idList.get(0) + "");
|
// if (isNeedWeb)
|
// playUrl.setPlayType(1);
|
// }
|
// }
|
|
JSONObject object = new JSONObject();
|
object.put("vid", id);
|
playUrl.setParams(object.toString());
|
playUrl.setUrl(String.format("http://v.youku.com/v_show/id_%s.html", id));
|
playUrl.setPlayType(1);//全部跳转网页
|
return playUrl;
|
}
|
|
public List<VideoDetailInfo> getVideoDetailList(String videoid) {
|
|
List<VideoYouKu> list = videoYouKuDao.list("from VideoYouKu vy where vy.video.id=?", new String[] { videoid });
|
if (list != null && list.size() > 0) {
|
final VideoYouKu vyk = list.get(0);
|
if (vyk.getProgram() != null) {// 按节目查找视频
|
List<ProgramVideo> videoList = programVideoDao.list(
|
"select map.programVideo from ProgramVideoMap map where map.program.id=?",
|
new String[] { vyk.getProgram().getId() });
|
Comparator<ProgramVideo> cp = new Comparator<ProgramVideo>() {
|
public int compare(ProgramVideo o1, ProgramVideo o2) {
|
if (StringUtil.isNullOrEmpty(o1.getStage()) || StringUtil.isNullOrEmpty(o2.getStage()))
|
System.out.println("空值");
|
long t1 = Long.parseLong(StringUtil.isNullOrEmpty(o1.getStage()) ? "0" : o1.getStage());
|
long t2 = Long.parseLong(StringUtil.isNullOrEmpty(o2.getStage()) ? "0" : o2.getStage());
|
if (vyk.getProgram().getCategory().contains("电影")) {
|
return (int) (t2 - t1);
|
} else if (vyk.getProgram().getCategory().contains("电视剧")) {
|
return (int) (t1 - t2);
|
} else if (vyk.getProgram().getCategory().contains("综艺")) {
|
return (int) (t2 - t1);
|
} else if (vyk.getProgram().getCategory().contains("动漫")) {
|
return (int) (t1 - t2);
|
} else
|
return (int) (t2 - t1);
|
}
|
};
|
Collections.sort(videoList, cp);
|
// int freeCount =
|
// YouKuApi.getProgramNotPayCount(vyk.getProgram().getId());
|
// if (videoList.size() > freeCount) {
|
// videoList = videoList.subList(0, freeCount);
|
// }
|
|
List<VideoDetailInfo> detailList = new ArrayList<VideoDetailInfo>();
|
for (ProgramVideo pv : videoList)
|
detailList.add(YouKuUtil.convertProgramVideoToVideoDetail(pv, vyk.getProgram()));
|
return detailList;
|
} else if (vyk.getYvideo() != null) {// 单个视频
|
ProgramVideo pv = vyk.getYvideo();
|
List<VideoDetailInfo> detailList = new ArrayList<VideoDetailInfo>();
|
VideoDetailInfo detail = new VideoDetailInfo();
|
detail.setExtraId(pv.getId());
|
detail.setName(pv.getTitle());
|
detail.setTag(pv.getTitle());
|
detail.setType("youkuvideo");
|
detailList.add(detail);
|
return detailList;
|
}
|
}
|
|
return null;
|
}
|
|
public void addProgramToVideoInfo(int page) {
|
List<Program> pList = programDao.list("from Program p where p.category='动漫'", (page - 1) * Constant.pageCount,
|
Constant.pageCount, new String[] {});
|
for (Program p : pList) {
|
List<ProgramVideo> list = programVideoDao.list(
|
"select m.programVideo from ProgramVideoMap m where m.program.id=?", new String[] { p.getId() });
|
if (list != null && list.size() > 0) {
|
System.out.println(p.getName());
|
p.setVideoList(list);
|
addProgramToVideoInfo(p, false);
|
}
|
}
|
}
|
|
public ProgramVideo getLatestProgramVideo(String programid) {
|
List<ProgramVideo> videoList = programVideoDao.list(
|
"select map.programVideo from ProgramVideoMap map where map.program.id=? order by CAST(map.programVideo.stage as integer) desc",
|
0, 1, new String[] { programid });
|
if (videoList != null && videoList.size() > 0)
|
return videoList.get(0);
|
return null;
|
}
|
|
public void hiddenOriginalVideo() {
|
|
programDao.excute(new HibernateCallback() {
|
@SuppressWarnings("unchecked")
|
public Object doInHibernate(Session session) throws HibernateException {
|
List list = session
|
.createSQLQuery(
|
"SELECT pv.`programid` FROM wk_youku_program_video pv LEFT JOIN wk_youku_video v ON v.`id`=pv.`videoid` WHERE v.`copyright_type`='original' GROUP BY pv.`programid`")
|
.list();
|
|
for (int i = 0; i < list.size(); i++) {
|
List<VideoInfo> videoList = (List<VideoInfo>) session
|
.createQuery(
|
"select yk.video from VideoYouKu yk where yk.program!=null and yk.program.id=?")
|
.setParameter(0, list.get(i) + "").list();
|
session.getTransaction().begin();
|
for (VideoInfo video : videoList) {
|
List<ResourceVideo> rvList = (List<ResourceVideo>) session
|
.createQuery("from ResourceVideo rv where rv.video.id=?").setParameter(0, video.getId())
|
.list();
|
if (rvList != null && rvList.size() > 1) {
|
for (ResourceVideo rv : rvList) {
|
if (rv.getResource().getId().equalsIgnoreCase("15")) {
|
session.delete(rv);
|
}
|
}
|
} else {
|
video.setShow("0");
|
session.update(video);
|
}
|
}
|
session.flush();
|
session.getTransaction().commit();
|
}
|
|
return null;
|
}
|
});
|
|
}
|
|
}
|