/******************************************************************************
|
. * Copyright (C) 2015 Shenzhen Penguin Network Technology Co., Ltd
|
* All Rights Reserved.
|
* ±¾Èí¼þΪÉîÛÚÊÐÆó¶ìÍøÂç¿Æ¼¼ÓÐÏÞ¹«Ë¾¿ª·¢ÑÐÖÆ¡£Î´¾±¾¹«Ë¾ÕýʽÊéÃæÍ¬Ò⣬ÆäËûÈκθöÈË¡¢ÍÅÌå
|
* ²»µÃʹÓᢸ´ÖÆ¡¢Ð޸Ļò·¢²¼±¾Èí¼þ.
|
*****************************************************************************/
|
|
package com.qxueyou.scc.media.service.impl;
|
|
import java.io.File;
|
import java.lang.reflect.InvocationTargetException;
|
import java.math.BigDecimal;
|
import java.text.SimpleDateFormat;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.HashSet;
|
import java.util.Iterator;
|
import java.util.List;
|
import java.util.Locale;
|
import java.util.Map;
|
import java.util.Map.Entry;
|
import java.util.regex.Matcher;
|
import java.util.regex.Pattern;
|
|
import org.apache.commons.beanutils.BeanUtils;
|
import org.apache.commons.lang3.StringUtils;
|
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.Logger;
|
import org.hibernate.SQLQuery;
|
import org.hibernate.Session;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.stereotype.Service;
|
|
import com.qxueyou.scc.admin.classes.model.ClsClass;
|
import com.qxueyou.scc.base.dao.CommonDAO;
|
import com.qxueyou.scc.base.model.Constants;
|
import com.qxueyou.scc.base.model.FilePathConstants;
|
import com.qxueyou.scc.base.model.Pager;
|
import com.qxueyou.scc.base.model.Result;
|
import com.qxueyou.scc.base.model.UserInfoWrapper;
|
import com.qxueyou.scc.base.service.impl.CommonAppService;
|
import com.qxueyou.scc.base.util.ClientUtils;
|
import com.qxueyou.scc.base.util.CollectionUtils;
|
import com.qxueyou.scc.base.util.RequestClientUtils;
|
import com.qxueyou.scc.base.util.TraceUtils;
|
import com.qxueyou.scc.config.AliOssConfig;
|
import com.qxueyou.scc.media.dao.MediaVideoDAO;
|
import com.qxueyou.scc.media.model.MediaVideo;
|
import com.qxueyou.scc.media.model.MediaVideoCache;
|
import com.qxueyou.scc.media.model.MediaVideoReCourse;
|
import com.qxueyou.scc.media.model.MediaVideoRecord;
|
import com.qxueyou.scc.media.model.MediaVideoStatistic;
|
import com.qxueyou.scc.media.model.MediaVideoTrans;
|
import com.qxueyou.scc.media.model.MediaVideoViewVO;
|
import com.qxueyou.scc.media.model.VideoConverTask;
|
import com.qxueyou.scc.media.service.IMediaVideoService;
|
import com.qxueyou.scc.org.model.OrgCollegeCourse;
|
import com.qxueyou.scc.org.model.Organization;
|
import com.qxueyou.scc.school.model.SchClassSchedule;
|
import com.qxueyou.scc.school.model.SchClassSubject;
|
import com.qxueyou.scc.school.model.SchCourseware;
|
import com.qxueyou.scc.school.model.SchReLessonVideo;
|
import com.qxueyou.scc.statistic.model.SchFlowStatisticDetail;
|
import com.qxueyou.scc.sys.model.SysLog;
|
import com.qxueyou.scc.sys.service.IOssService;
|
import com.qxueyou.scc.sys.service.IOssVideoService;
|
import com.qxueyou.scc.teach.subject.model.Subject;
|
import com.qxueyou.scc.teach.subject.model.SubjectChapter;
|
|
/**
|
*
|
* @author cyq
|
*
|
*/
|
|
@Service
|
@EnableConfigurationProperties(AliOssConfig.class)
|
public class MediaVideoService extends CommonAppService implements IMediaVideoService{
|
|
/**
|
* ʵÀý»¯log
|
*/
|
private final Logger log = LogManager.getLogger(MediaVideoService.class);
|
|
/**
|
* oss·þÎñ
|
*/
|
@Autowired
|
IOssService ossService;
|
|
@Autowired
|
private AliOssConfig aliOssConfig;
|
|
/**
|
* ossÊÓÆµ·þÎñ
|
*/
|
@Autowired
|
IOssVideoService ossVideoService ;
|
|
/**
|
* ÊÓÆµDAO
|
*/
|
private MediaVideoDAO mediaVideoDAO;
|
|
/**
|
* ĬÈÏÈÕÆÚʱ¼ä¸ñʽ
|
*/
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINESE);
|
/**
|
* ¹«¹²¿Î³ÌÃû³Æ
|
*/
|
private final static String publicSubjectName = "¹«¹²¿Î³Ì";
|
|
/**
|
* m3u8Îļþºó׺Ãû
|
*/
|
private final static String m3u8Suffix = ".m3u8";
|
/**
|
* ÊÓÆµÄ¿Â¼·Ö¸î±ê¼Ç
|
*/
|
private final static String videoDirFlag = "com/video";
|
|
/**
|
*
|
* @return
|
*/
|
public MediaVideoDAO getMediaVideoDAO() {
|
return mediaVideoDAO;
|
}
|
|
/**
|
* ÒÀÀµ×¢Èë
|
* @param exerDAO
|
*/
|
@Autowired(required = false)
|
public void setMediaVideoDAO(@Qualifier("mediaVideoDAO") MediaVideoDAO mediaVideoDAO) {
|
this.mediaVideoDAO = mediaVideoDAO;
|
}
|
|
/**
|
* APP»ñÈ¡ÊÓÆµÁбí
|
* @param sql ²éѯÓï¾ä
|
* @param args ²ÎÊý
|
* @return
|
*/
|
@SuppressWarnings("unchecked")
|
public List<MediaVideoViewVO> queryMediaVideoList(String sql,List<Object> args,Pager pager){
|
|
List<Object[]> lst = this.findByPageSql(sql, args, pager);
|
|
List<MediaVideoViewVO> resultLst = new ArrayList<MediaVideoViewVO>(lst.size());
|
MediaVideoViewVO vo = null ;
|
for (Object[] obj : lst) {
|
|
vo = new MediaVideoViewVO();
|
vo.setVideoId(String.valueOf(obj[0]));
|
vo.setName(String.valueOf(obj[1]));
|
|
vo.setUrl("");
|
vo.setOrigUrl("");
|
|
vo.setSize(checkIntegerObject(obj[4]));
|
vo.setPlayTime(checkIntegerObject(obj[5]));
|
|
vo.setCoverPageUrl( obj[6] == null || StringUtils.isBlank(String.valueOf(obj[6]))
|
? FilePathConstants.VIDEO_DEFAULT_IMG : String.valueOf(obj[6]) );
|
|
vo.setPlayTimes(checkIntegerObject(obj[7]));
|
vo.setRemark(String.valueOf(obj[8]));
|
vo.setFormat(String.valueOf(obj[9]));
|
|
vo.setAndroidHD(String.valueOf(obj[10]));
|
vo.setAndroidSD(String.valueOf(obj[11]));
|
vo.setAndroidLD(String.valueOf(obj[12]));
|
vo.setIosHD(String.valueOf(obj[13]));
|
vo.setIosSD(String.valueOf(obj[14]));
|
vo.setIosLD(String.valueOf(obj[15]));
|
|
// obj[3] internal use obj[2]
|
if( null==obj[10] && null==obj[11] && null==obj[12] ){
|
vo.setAndroidLD(String.valueOf(obj[2]));
|
}
|
if( null==obj[13] && null==obj[14] && null==obj[15] ){
|
vo.setIosLD(String.valueOf(obj[2]));
|
}
|
|
vo.setTeacherName(String.valueOf(obj[16]));
|
|
vo.setCacheFlag(false);
|
vo.setDownloadFlag(false);
|
|
// Ôö¼Ó·µ»Ø×ÊÔ´ID
|
vo.setObjectFlag(null!=obj[17] || null!=obj[18] || null!=obj[19]);
|
|
vo.setObjectHd(checkStringObject(obj[17]));
|
vo.setObjectSd(checkStringObject(obj[18]));
|
vo.setObjectLd(checkStringObject(obj[19]));
|
vo.setCreateTime(obj[20]);
|
vo.setUpdateTime(obj[21]);
|
vo.setSubjectId(checkStringObject(obj[22]));
|
vo.setSubjectName(checkStringObject(obj[23]));
|
resultLst.add(vo);
|
}
|
|
return resultLst ;
|
}
|
private String checkStringObject(Object obj) {
|
return null != obj ? String.valueOf(obj) : null;
|
}
|
private int checkIntegerObject(Object obj) {
|
if (null != obj && StringUtils.isNotEmpty(String.valueOf(obj))) {
|
return Integer.valueOf(String.valueOf(obj));
|
}
|
return 0;
|
}
|
|
/**
|
* APPÌá½»»º³åÊÓÆµ
|
*
|
* @param videoId videoId£¬¶à¸öÒÔ¡°£¬¡±·Ö¸ô
|
* @return result trueΪ³É¹¦£¬falseʱ£¬msgΪ´íÎóÃèÊö
|
*/
|
public Result doSubmitCacheVideo(MediaVideoCache cache){
|
List<MediaVideoCache> lstCacheVO = new ArrayList<MediaVideoCache>(2);
|
TraceUtils.setCreateActiveTrace(cache);
|
cache.setOrgId(ClientUtils.getOrgId());
|
cache.setClassId(ClientUtils.getClassId());
|
cache.setCachedUserId(ClientUtils.getUserId());
|
cache.setCachedFlag(true);
|
cache.setCachedTime(0);
|
cache.setCachedUserId(ClientUtils.getUserId());
|
cache.setSubmitTime(new Date(System.currentTimeMillis()));
|
|
lstCacheVO.add(cache);
|
|
if(!lstCacheVO.isEmpty()){
|
this.saveOrUpdateAll(lstCacheVO);
|
}
|
return new Result(true);
|
}
|
|
/**
|
* APPÌá½»²¥·ÅÊÓÆµ
|
*
|
* @param videoId videoId£¬¶à¸öÒÔ¡°£¬¡±·Ö¸ô
|
* @return result trueΪ³É¹¦£¬falseʱ£¬msgΪ´íÎóÃèÊö
|
*/
|
public Result doSubmitPlayVideo(MediaVideoRecord mvr){
|
|
MediaVideo videoVO = this.read(MediaVideo.class, mvr.getVideoId());
|
|
if(null != videoVO){
|
mvr.setVideoTime(videoVO.getPlayTime()==0?mvr.getVideoTime():videoVO.getPlayTime());
|
mvr.setDeleteFlag(false);
|
mvr.setPlayTime(new Date(System.currentTimeMillis()));
|
mvr.setOrgId(ClientUtils.getOrgId());
|
mvr.setClassId(ClientUtils.getClassId());
|
mvr.setUserId(ClientUtils.getUserId());
|
|
mvr.setWatchTime(0);
|
TraceUtils.setCreateTrace(mvr);
|
save(mvr);
|
|
videoVO.setPlayTimes(videoVO.getPlayTimes() + 1) ;
|
//²»È¡APP·¢Ë͹ýÀ´µÄÊÓÆµÊ±³¤
|
//videoVO.setPlayTime(videoVO.getPlayTime()==0?mvr.getVideoTime():videoVO.getPlayTime());
|
TraceUtils.setUpdateTrace(videoVO);
|
this.saveVideo(videoVO);
|
|
return new Result(true,mvr.getVideoRecordId());
|
}
|
|
return new Result(false,"Ìá½»²ÎÊý²»ÕýÈ·");
|
}
|
|
|
/**
|
* APP²¥·ÅÍê³É
|
*
|
* @param
|
* @return result trueΪ³É¹¦£¬falseʱ£¬msgΪ´íÎóÃèÊö
|
*/
|
public Result doSubmitPlayFinish(MediaVideoRecord mvr){
|
MediaVideoRecord mv = read(MediaVideoRecord.class, mvr.getVideoRecordId());
|
/*if(mv==null){
|
mv = read(MediaVideoRecord.class, mvr.getVideoId());
|
}*/
|
mv.setLeaveTime(new Date(System.currentTimeMillis()));
|
mv.setWatchTime(mvr.getWatchTime());
|
TraceUtils.setUpdateTrace(mv);
|
save(mv);
|
return new Result(true);
|
}
|
|
/**
|
* ͳ¼ÆÊÓÆµµÄ½ø¶È
|
*
|
* @param userId
|
* @param videoId
|
*/
|
public void statisticCompDegree(String userId, String videoId){
|
//»ñÈ¡ÊÓÆµµÄ²¥·Å¼Ç¼,¹ýÂËÏÂÔØÊÓÆµµÄʱ³¤
|
List<SchFlowStatisticDetail> lstSchFlowStatisticDetail = this.find("from SchFlowStatisticDetail d where d.videoId = ? and d.userId = ? and d.businessType <> ?",
|
CollectionUtils.newList(videoId, userId, SchFlowStatisticDetail.BUSINESS_TYPE_VIDEO_DOWNLOAD), SchFlowStatisticDetail.class);
|
if(lstSchFlowStatisticDetail == null || lstSchFlowStatisticDetail.isEmpty()){
|
return;
|
}
|
Map<Integer, Boolean> map = new HashMap<Integer, Boolean>();
|
for(SchFlowStatisticDetail objSchFlowStatisticDetail : lstSchFlowStatisticDetail){
|
Integer startTime = objSchFlowStatisticDetail.getVideoStartTime();
|
Integer endTime = objSchFlowStatisticDetail.getVideoEndTime();
|
for(int i=startTime;i<endTime;i++){
|
map.put(i, true);
|
}
|
}
|
MediaVideo objMediaVideo = this.read(MediaVideo.class, videoId);
|
BigDecimal compDegree = objMediaVideo.getPlayTime() == 0?BigDecimal.ZERO:BigDecimal.valueOf(Double.valueOf(map.size())/objMediaVideo.getPlayTime());
|
if(compDegree.compareTo(BigDecimal.ONE) == 1){
|
compDegree = BigDecimal.ONE;
|
}
|
String hql = " from MediaVideoStatistic where userId =? and videoId=?";
|
MediaVideoStatistic mvs = findUnique(hql, CollectionUtils.newList(userId,videoId), MediaVideoStatistic.class);
|
if(null==mvs){
|
mvs = new MediaVideoStatistic();
|
mvs.setClassId(objMediaVideo.getClassId());
|
mvs.setDeleteFlag(false);
|
mvs.setUserId(userId);
|
mvs.setVideoId(videoId);
|
|
mvs.setVideoName(objMediaVideo.getName());
|
mvs.setCompDegree(compDegree);
|
TraceUtils.setCreateTrace(mvs);
|
save(mvs);
|
}else{
|
this.bulkUpdate("update MediaVideoStatistic set compDegree = ? where userId = ? and videoId = ? and compDegree < ?", new Object[]{compDegree, userId, videoId, compDegree});
|
}
|
}
|
|
|
|
/**
|
* ´´½¨×ªÂë¼Ç¼
|
*
|
* @param videoId
|
*/
|
public void saveMediaVideoTrans(String videoId){
|
MediaVideo video = this.read(MediaVideo.class, videoId);
|
|
// 1.±£´æ×ªÂë¼Ç¼
|
MediaVideoTrans trans = new MediaVideoTrans();
|
TraceUtils.setCreateTrace(trans);
|
trans.setDeleteFlag(false);
|
trans.setOrgId(ClientUtils.getOrgId());
|
trans.setClassId(ClientUtils.getClassId());
|
trans.setVideoId(videoId);
|
trans.setVideoName(video.getName());
|
trans.setProcess(MediaVideoTrans.TRANS_PROCESS_UPLOAD_SUCCESS);
|
trans.setResult((short)0);
|
trans.setTransTimes((short)1);
|
|
Date nowTime=new Date() ;
|
trans.setRemark(format.format(nowTime) + ":1.ÉÏ´«µ½oss·þÎñÆ÷;") ;
|
trans.setUploadTime(nowTime);
|
|
String ip = getConfusionIp() ;
|
trans.setUploadServer(ip);
|
|
this.save(trans);
|
}
|
|
|
|
|
@SuppressWarnings("unused")
|
private File getOssVideo(MediaVideo video, MediaVideoTrans trans, String uuid, String ip){
|
// Ôö¼ÓÒ»´Îµ÷Óô洢¹ý³Ì
|
Date startTime=new Date() ;
|
trans.setDownloadTime(startTime);
|
trans.setRemark(trans.getRemark() + format.format(startTime) + ":2.0:¿ªÊ¼ÏÂÔØÊÓÆµ;ÊÓÆµÏÂÔØÖÐ>>>") ;
|
doUpdateTransCodeProcess(trans);
|
|
// 3.2.internal hangzhou
|
File origVideo = ossVideoService.getObject(
|
video.getOrigUrl().substring(video.getOrigUrl().indexOf(videoDirFlag) + 3 ), Constants.FFMPEG_VIDEO_FILE_DIR + uuid + "/origVideo"
|
+ video.getOrigUrl().substring(video.getOrigUrl().lastIndexOf(".")) );
|
|
// µÚÒ»´Îµ÷Óô洢¹ý³Ì
|
Date downloadTime=new Date() ;
|
trans.setTransServer(ip);
|
trans.setDownloadTime(downloadTime);
|
trans.setRemark(trans.getRemark() + format.format(downloadTime) + ":2.ÏÂÔØÎļþ³É¹¦;") ;
|
|
doUpdateTransCodeProcess(trans);
|
return origVideo;
|
}
|
|
/**
|
* ¸´ÖƵÄÊÓÆµÐÞ¸Ä״̬
|
* @param video
|
* @return
|
*/
|
@SuppressWarnings("unused")
|
private Result doSaveCopyVideoTranscode(MediaVideo video){
|
|
String hql = " from MediaVideo where originVideoId = ? and deleteFlag is false";
|
List<MediaVideo> originVideo = find(hql, CollectionUtils.newList(video.getVideoId()), MediaVideo.class);
|
|
if(video.getStatus()== MediaVideo.STATUS_PUBLISHED){
|
//ÐÞ¸ÄËùÓÐÖ¸¶¨Êý¾ÝµÄÊÓÆµ×´Ì¬
|
for (MediaVideo mediaVideo : originVideo) {
|
mediaVideo.setCoverPageUrl(video.getCoverPageUrl());
|
mediaVideo.setAndroidSD(video.getAndroidSD());
|
mediaVideo.setUrl(video.getUrl());
|
mediaVideo.setIosSD(video.getIosSD());
|
mediaVideo.setObjectSd(video.getObjectSd());
|
mediaVideo.setStatus(MediaVideo.STATUS_PUBLISHED);
|
this.saveVideo(mediaVideo);
|
}
|
}else if(video.getStatus()==MediaVideo.STATUS_TRANSFAILED){
|
//ÐÞ¸ÄËùÓÐÖ¸¶¨Êý¾ÝµÄÊÓÆµ×´Ì¬
|
for (MediaVideo mediaVideo : originVideo) {
|
mediaVideo.setCoverPageUrl(video.getCoverPageUrl());
|
mediaVideo.setAndroidSD(video.getAndroidSD());
|
mediaVideo.setUrl(video.getUrl());
|
mediaVideo.setIosSD(video.getIosSD());
|
mediaVideo.setObjectSd(video.getObjectSd());
|
mediaVideo.setStatus(MediaVideo.STATUS_TRANSFAILED);
|
this.saveVideo(mediaVideo);
|
}
|
}
|
|
return new Result(true);
|
}
|
|
|
/**
|
* ʹÓô洢¹ý³Ì´¦ÀíµÄÔÒò£ºservice½ÓÊÕ¶ÓÁеÄתÂëÏûÏ¢ºó£¬Í¨¹ý´æ´¢¹ý³ÌʵÏÖÒ»¸öserverceÖУ¬ÊµÊ±¸üÐÂ״̬£¬¶ø·ÇÒ»¸öserviceÒ»¸öÕûÌå
|
*
|
* @param trans
|
*/
|
private void doUpdateTransCodeProcess( MediaVideoTrans trans ){
|
|
String remark = StringUtils.isNotBlank(trans.getRemark()) && trans.getRemark().length() >= 1024
|
? trans.getRemark().substring(1000) : trans.getRemark();
|
|
//¸ÄÓô洢¹ý³Ì
|
Session session = getCommonDAO().getSessionFactory().getCurrentSession();
|
SQLQuery query = session.createSQLQuery("{call INSERT_FFMPEG_TRANSCODE_PROCESS(?,?,?,?,?,?,?,?,?,?,?,?,?)}");
|
query.setString(0, trans.getVideoTranscodeId());
|
query.setString(1, trans.getTransServer());
|
query.setString(2, remark );
|
query.setInteger(3, trans.getProcess() );
|
|
query.setTimestamp(4, trans.getUploadTime());
|
query.setTimestamp(5, trans.getDownloadTime());
|
query.setTimestamp(6, trans.getMediaInfoTime());
|
query.setTimestamp(7, trans.getSnapshotTime());
|
query.setTimestamp(8, trans.getAndroidSdTime());
|
query.setTimestamp(9, trans.getIosSdTime());
|
query.setTimestamp(10, trans.getResultTime());
|
|
query.setShort(11, trans.getResult());
|
query.setShort(12, trans.getTransTimes());
|
|
//Ö´ÐÐ
|
query.executeUpdate();
|
|
log.debug("¸üÐÂתÂë¹ý³Ì£ºparams:transCodeId=" + trans.getVideoTranscodeId() + ";process=" + trans.getProcess() + ";transRemark=" + trans.getRemark() ) ;
|
|
}
|
|
/**
|
* »ñÈ¡»ìÏýIP
|
*/
|
public String getConfusionIp(){
|
|
String origIp = RequestClientUtils.getLocalIP();
|
|
String ip = origIp.substring(origIp.indexOf('.')+1) + '.' + origIp.substring(0,origIp.indexOf('.'));
|
|
return ip ;
|
}
|
|
/**
|
* ²éѯתÂë½á¹û
|
* @param hql
|
* @param args
|
* @return
|
*/
|
public List<MediaVideoTrans> queryTransItem(String hql,List<Object> args){
|
return mediaVideoDAO.queryTransItem(hql, args);
|
}
|
/******ffmpegתÂë´úÂë½áÊø*******/
|
|
/**
|
* ÐÞ¸ÄÊÓÆµ
|
* @param video
|
* @return
|
*/
|
public Result doSaveUpdateMedia( MediaVideo video ,String classScheduleId){
|
|
if(null == video || StringUtils.isBlank(video.getVideoId()) || StringUtils.isBlank(classScheduleId) ){
|
return new Result(false,"²ÎÊý²»ÕýÈ·");
|
}
|
|
MediaVideo v = this.read(MediaVideo.class, video.getVideoId());
|
|
if( null == v ){
|
return new Result(false,"²ÎÊý²»ÕýÈ·");
|
}
|
|
v.setCoverPageUrl(video.getCoverPageUrl());
|
v.setName(video.getName());
|
v.setRemark(video.getRemark());
|
v.setTeacherName(video.getTeacherName());
|
v.setStartTime(video.getStartTime());
|
v.setEndTime(video.getEndTime());
|
v.setValidity(video.getValidity());
|
|
this.save(v);
|
|
//¹ØÁª¿Î³ÌÐÅÏ¢
|
String hql = "select l from SchReLessonVideo l, SchClassSchedule s where l.classScheduleId = s.classScheduleId and s.deleteFlag is false and l.videoId = ? and s.classId = ? and l.deleteFlag is false ";
|
List<SchReLessonVideo> res = this.find(hql, CollectionUtils.newList(v.getVideoId(),ClientUtils.getClassId()) , SchReLessonVideo.class);
|
|
|
// Èç¹ûÓÐÀ¬»øÊý¾Ý
|
if(!res.isEmpty() && res.size() > 1 ){
|
|
for(int i=1 ; i < res.size() ; i++ ){
|
res.get(i).setDeleteFlag(true);
|
}
|
|
}
|
|
SchReLessonVideo rel = res.get(0);
|
|
this.saveOrUpdateAll(res);
|
|
// ÐèÒªÐÞ¸Ä
|
if(null == rel || !classScheduleId.equals(rel.getClassScheduleId()) ){
|
|
SchReLessonVideo re = new SchReLessonVideo();
|
TraceUtils.setCreateTrace(re);
|
re.setDeleteFlag(false);
|
re.setClassScheduleId(classScheduleId);
|
re.setVideoId(v.getVideoId());
|
this.save(re);
|
|
if(null != rel){
|
rel.setDeleteFlag(true);
|
this.save(rel);
|
}
|
|
}
|
|
return new Result(true);
|
|
}
|
|
/**
|
* ²éѯ°àÖ÷ÈÎϵÄpc¶ËÊÓÆµÁбí
|
* @param hql
|
* @param args
|
* @return
|
*/
|
public List<MediaVideo> queryVideoItem(String hql,List<Object> args){
|
|
return this.mediaVideoDAO.queryVideoItem(hql, args);
|
|
}
|
|
/**
|
* ½«ÊÓÆµ´Ó°àÖ÷ÈÎÄõ½×îÉϲã»ú¹¹£¬È»ºó»ú¹¹Ö¸¶¨µ½¸÷¸ö²ã¼¶Ö®ºó£¬Ð½¨°à¼¶£¬ËùÓÐÊÓÆµ¶¼³öÏÖÔÚ¹«¹²¿Î³Ì£¬ÕâÀïÒª³õʼ»¯³É×ʼµÄ ¿Î³Ì-ÊÓÆµ ½á¹¹
|
* @param collegeCourse
|
* @return
|
* @throws InvocationTargetException
|
* @throws IllegalAccessException
|
*/
|
public Result doInitClassOrgVideo(OrgCollegeCourse collegeCourse){
|
|
Map<String,SchClassSchedule> map = new HashMap<String,SchClassSchedule>();
|
|
// 1.³õʼ»¯¸Ã¿ÆÄ¿Ï£¨°àÖ÷ÈνÇÉ«ÉÏ´«µÄÊÓÆµ£¬·ÇÖ¸¶¨¹ýÈ¥µÄÊÓÆµ£©£»ÊÓÆµÁ´½Ó£ºÊÓÆµ¿Î³Ì map¶ÔÏó
|
doInitClassVideoScheduleMap(collegeCourse,map);
|
|
|
// 2.¶Ôÿһ¸öÊÓÆµÁ´½Ó£¬²é³öÀ´ËùÓÐÖ¸¶¨µ½°àÖ÷ÈνÇÉ«µÄ¹ØÁª
|
|
// classId + scheduleName À´±£Ö¤Ã¿¸ö°à¼¶ÏÂÃæµÄ¿Î³Ì²»Öظ´Ìí¼Ó
|
//Map<String,SchClassSchedule> repeatScheduleMap = new HashMap<String,SchClassSchedule>();
|
Map<String,String> repeatScheduleMap = new HashMap<String,String>();
|
|
Entry<String,SchClassSchedule> entry;
|
for(Iterator<Entry<String, SchClassSchedule>> iterator = map.entrySet().iterator(); iterator.hasNext();) {
|
entry = (Entry<String,SchClassSchedule>)iterator.next();
|
|
String origUrl = entry.getKey();
|
// Ôʼ°àÖ÷ÈÎÊÓÆµµÄ¿Î³Ì
|
SchClassSchedule origSchedule = entry.getValue();
|
|
Map<SchReLessonVideo,MediaVideo> reMap = new HashMap<SchReLessonVideo,MediaVideo>();
|
Map<SchReLessonVideo,SchClassSchedule> scheMap = new HashMap<SchReLessonVideo,SchClassSchedule>();
|
|
//µÚÒ»²¿·Ö£¬Ö¸¶¨ÊÓÆµµ½°à¼¶Éú³ÉµÄÊý¾Ý£¬Ö»Éú³É¹ØÁª new SchReLessonVideo
|
String hql = "select v,r,s from MediaVideo v , SchReLessonVideo r ,SchClassSchedule s " +
|
"where v.videoId = r.videoId " +
|
"and s.classScheduleId = r.classScheduleId " +
|
"and v.origUrl = ? " +
|
"and s.deleteFlag is false " +
|
"and v.deleteFlag is false " +
|
"and r.deleteFlag is false " +
|
"and v.classId is null " ;
|
|
this.mediaVideoDAO.queryInitDoubleMap(hql, CollectionUtils.newList(origUrl), reMap, scheMap);
|
|
if(!reMap.isEmpty() ){
|
|
SchReLessonVideo reKey = null ;
|
for (Object obj : reMap.keySet()) {
|
reKey = (SchReLessonVideo) obj;
|
if(null != reKey ){
|
break ;
|
}
|
}
|
|
if(null != reKey ){
|
|
//µÚ¶þ²¿·Ö£¬ÐÂÔö°à¼¶Ö±½ÓÐÂÔöµÄÊý¾Ý,Ê×ÏÈÒªÕÒµ½ new mediaVideo
|
String hql0 = "select v,r,s from MediaVideo v , SchReLessonVideo r ,SchClassSchedule s " +
|
"where v.videoId = r.videoId " +
|
"and s.classScheduleId = r.classScheduleId " +
|
"and v.origUrl = ? " +
|
"and s.deleteFlag is false " +
|
"and v.deleteFlag is false " +
|
"and r.deleteFlag is false " +
|
"and v.originVideoId = ? " ;
|
|
this.mediaVideoDAO.queryInitDoubleMap(hql0, CollectionUtils.newList(origUrl,reKey.getVideoId()), reMap, scheMap);
|
}
|
|
}
|
|
// Ñ»·Ã¿Ò»¸öÊÓÆµ-¹ØÁª-¿Î³Ì£¬Ð޸ĹØÁªµÄ¿Î±íÐÅÏ¢
|
Entry<SchReLessonVideo,MediaVideo> reEntry;
|
for(Iterator<Entry<SchReLessonVideo, MediaVideo>> reIterator = reMap.entrySet().iterator(); reIterator.hasNext();) {
|
reEntry = (Entry<SchReLessonVideo,MediaVideo>)reIterator.next();
|
|
SchReLessonVideo CurrRe = reEntry.getKey();
|
MediaVideo currVideo = reEntry.getValue();
|
SchClassSchedule currSchedule = scheMap.get(CurrRe);
|
|
doInsertRegLog("²éѯÊÓÆµ videoId ClassScheduleId ",CurrRe.getVideoId(), CurrRe.getClassScheduleId());
|
|
String flag = currSchedule.getClassId().concat(origSchedule.getName());
|
//SchClassSchedule newSchedule = new SchClassSchedule() ;
|
|
String currScheduleClassId = null ;
|
|
// ûÓÐ
|
if(!repeatScheduleMap.containsValue(flag)){
|
|
doInsertRegLog("MapÖÐÎÞÊý¾Ý videoId ClassScheduleId " + flag ,CurrRe.getVideoId(), CurrRe.getClassScheduleId());
|
|
// Ê×ÏȲéѯµ±Ç°°à¼¶ÏÂÓÐÎÞ ºÍÔʼÊÓÆµ¿Î³ÌͬÃûµÄ¿Î³Ì
|
String hql0 = "from SchClassSchedule s where s.deleteFlag is false and s.classId = ? and s.name = ? ";
|
SchClassSchedule querySch = this.findUnique(hql0, CollectionUtils.newList(currSchedule.getClassId(),origSchedule.getName()), SchClassSchedule.class);
|
|
if( null != querySch ){
|
|
doInsertRegLog("MapÖÐÎÞÊý¾Ýµ«ÊÇsqlÖÐÓÐÊý¾Ý videoId ClassScheduleId " + flag ,CurrRe.getVideoId(), CurrRe.getClassScheduleId());
|
|
currScheduleClassId = querySch.getClassScheduleId() ;
|
repeatScheduleMap.put(flag, currScheduleClassId);
|
}else{
|
|
doInsertRegLog("MapÖÐÎÞÊý¾Ýµ«ÊÇsqlÖÐÎÞÊý¾Ý videoId ClassScheduleId " + flag ,CurrRe.getVideoId(), CurrRe.getClassScheduleId());
|
|
// ûÓвéѯµ½µÄ»°£¬µÚÒ»´ÎÐèÒª±£´æ½øÈ¥
|
SchClassSchedule newSchedule = new SchClassSchedule() ;
|
|
newSchedule.setClassId(currSchedule.getClassId());
|
newSchedule.setCollegeCourseId(currSchedule.getCollegeCourseId());
|
newSchedule.setDeleteFlag(false);
|
newSchedule.setTeacher(currSchedule.getTeacher());
|
newSchedule.setTeacherId(currSchedule.getTeacherId());
|
|
newSchedule.setEndTime(origSchedule.getEndTime());
|
newSchedule.setImgPath(origSchedule.getImgPath());
|
newSchedule.setStartTime(origSchedule.getStartTime());
|
newSchedule.setStatus(origSchedule.getStatus());
|
newSchedule.setType(origSchedule.getType());
|
|
TraceUtils.setCreateTrace(newSchedule);
|
newSchedule.setClassScheduleId(null);
|
newSchedule.setName(origSchedule.getName());
|
|
this.save(newSchedule);
|
|
|
currScheduleClassId = newSchedule.getClassScheduleId() ;
|
repeatScheduleMap.put(flag, newSchedule.getClassScheduleId());
|
}
|
|
}else{
|
|
doInsertRegLog("MapÖÐÓÐÊý¾Ý videoId ClassScheduleId " + flag ,CurrRe.getVideoId(), CurrRe.getClassScheduleId());
|
|
// ´ÓmapÖÐÄÃ
|
currScheduleClassId = repeatScheduleMap.get(flag);
|
|
}
|
|
// Ð޸ĹØÁª¹ØÏµ,½«ÒÔǰµÄ¹ØÁª¼Ç¼ɾ³ý£¬ÐÂÔö¹ØÁª¼Ç¼
|
String hql2 = "select r from SchReLessonVideo r,SchClassSchedule s where " +
|
" s.deleteFlag is false " +
|
" and r.classScheduleId = s.classScheduleId " +
|
" and r.videoId = ? and s.classId = ? ";
|
List<SchReLessonVideo> lstRes = this.find(hql2, CollectionUtils.newList(CurrRe.getVideoId(),currSchedule.getClassId()), SchReLessonVideo.class);
|
for(SchReLessonVideo re: lstRes){
|
re.setDeleteFlag(true);
|
}
|
this.saveOrUpdateAll(lstRes);
|
|
SchReLessonVideo newRe = new SchReLessonVideo();
|
TraceUtils.setCreateTrace(newRe);
|
|
newRe.setDeleteFlag(false);
|
newRe.setVideoId(currVideo.getVideoId());
|
newRe.setClassScheduleId(currScheduleClassId);
|
|
this.save(newRe);
|
|
}
|
|
}
|
|
return new Result(true);
|
}
|
|
/**
|
* ³õʼ»¯¸Ã¿ÆÄ¿Ï£¨°àÖ÷ÈνÇÉ«ÉÏ´«µÄÊÓÆµ£¬·ÇÖ¸¶¨¹ýÈ¥µÄÊÓÆµ£©£»ÊÓÆµÁ´½Ó£ºÊÓÆµ¿Î³Ì map¶ÔÏó
|
* @param collegeCourse
|
* @param map
|
* @return
|
*/
|
|
private boolean doInitClassVideoScheduleMap(OrgCollegeCourse collegeCourse,Map<String,SchClassSchedule> map){
|
|
// µ±Ç°¿ÆÄ¿¶ÔÓ¦µÄ°à¼¶
|
String hql0 = "from ClsClass o where o.deleteFlag is false and o.collegeCourseId = ? ";
|
|
List<ClsClass> myList = this.find(hql0, CollectionUtils.newList(collegeCourse.getCollegeCourseId()), ClsClass.class);
|
|
if(myList.isEmpty()){
|
return false ;
|
}
|
|
String hql = "select v.origUrl,v.classId,l from MediaVideo v,SchReLessonVideo r,SchClassSchedule l " +
|
"where l.deleteFlag is false " +
|
"and r.classScheduleId=l.classScheduleId " +
|
"and r.videoId=v.videoId " +
|
"and v.deleteFlag is false " +
|
"and v.classId is not null " +
|
"and v.classId <> '' " +
|
"and v.originVideoId = null " +
|
"and l.classId in ( ";
|
|
List<Object> lstParams = new ArrayList<Object>();
|
|
for(int i = 0 ; i < ( myList.size()-1 ) ; i++){
|
|
hql = hql.concat("? , ") ;
|
lstParams.add(myList.get(i).getClassId());
|
|
doInsertRegLog("0²éѯ°à¼¶ classID CollegeCourseId ",myList.get(i).getClassId(),collegeCourse.getCollegeCourseId());
|
|
}
|
|
hql = hql.concat(" ? ) ") ;
|
lstParams.add(myList.get(myList.size()-1).getClassId());
|
|
doInsertRegLog("1²éѯ°à¼¶ classID CollegeCourseId",myList.get(myList.size()-1).getClassId(),collegeCourse.getCollegeCourseId());
|
|
Map<String,SchClassSchedule> resultMap = this.mediaVideoDAO.queryInitMap(hql, lstParams);
|
|
Entry<String,SchClassSchedule> entry;
|
for(Iterator<Entry<String, SchClassSchedule>> iterator = resultMap.entrySet().iterator(); iterator.hasNext();) {
|
entry = (Entry<String,SchClassSchedule>)iterator.next();
|
map.put(entry.getKey(), entry.getValue());
|
|
}
|
|
return true ;
|
}
|
|
/**
|
* ³õʼ»¯¸Ã¿ÆÄ¿Ï£¨°àÖ÷ÈνÇÉ«ÉÏ´«µÄÊÓÆµ£¬·ÇÖ¸¶¨¹ýÈ¥µÄÊÓÆµ£©£»ÊÓÆµÁ´½Ó£ºÊÓÆµ¿Î³Ì map¶ÔÏó
|
* @param collegeCourse
|
* @param map
|
* @return
|
*/
|
public Result doInitVideoObject(MediaVideo video){
|
|
// m3u8ǰ׺
|
String prefixVideoPath = aliOssConfig.getVideoOssAddress() + "/" +aliOssConfig.getVideoOssDomain()+ "/" ;
|
|
if(StringUtils.isNotBlank(video.getIosHD()) &&
|
video.getIosHD().startsWith(prefixVideoPath) &&
|
video.getIosHD().endsWith(m3u8Suffix) ){
|
video.setObjectHd(video.getIosHD().substring(prefixVideoPath.length()));
|
}
|
|
if(StringUtils.isNotBlank(video.getIosSD()) &&
|
video.getIosSD().startsWith(prefixVideoPath) &&
|
video.getIosSD().endsWith(m3u8Suffix) ){
|
video.setObjectSd(video.getIosSD().substring(prefixVideoPath.length()));
|
}
|
|
if(StringUtils.isNotBlank(video.getIosLD()) &&
|
video.getIosLD().startsWith(prefixVideoPath) &&
|
video.getIosLD().endsWith(m3u8Suffix) ){
|
video.setObjectLd(video.getIosLD().substring(prefixVideoPath.length()));
|
}
|
|
TraceUtils.setCreateTrace(video);
|
this.saveVideo(video);
|
|
return new Result(true) ;
|
}
|
|
/**
|
* ÈÕÖ¾¼Ç¼
|
* @param operator
|
* @param classId
|
* @param collegeCourseId
|
* @return
|
*/
|
private Result doInsertRegLog(String operator,String classId,String collegeCourseId ){
|
|
SysLog lg = new SysLog();
|
|
TraceUtils.setCreateActiveTrace(lg);
|
lg.setDeleteFlag(false);
|
lg.setContent(operator + ":" + classId );
|
lg.setDesp(collegeCourseId);
|
lg.setModule("ORG_VIDEO_SCHEULE_INIT");
|
lg.setType(SysLog.LOG_TYPE_BUSINESS);
|
|
|
if( null != ClientUtils.getUserInfo()){
|
lg.setUserId(ClientUtils.getUserId());
|
lg.setUserName(ClientUtils.getUserName());
|
}else{
|
lg.setUserId("admin");
|
lg.setUserName("admin");
|
}
|
|
save(lg);
|
|
return new Result(true);
|
|
}
|
/**
|
* Ìí¼Ó²¥·Å´ÎÊý
|
*/
|
@Override
|
public boolean addPlayTimes(String videoId) {
|
return mediaVideoDAO.addPlayTimes(videoId);
|
}
|
|
/**
|
* ±àÅÅÊý¾Ý
|
* @param data ÐèÒª±àÅŵÄÊý¾Ý
|
*/
|
public Result doReOrderVideo(List<String> ids, List<Integer> index){
|
// Ñ»·ÐÞ¸Äorder
|
CommonDAO commonDAO = this.getCommonDAO();
|
for( int i=0;i< ids.size();i++){
|
String videoId = ids.get(i);
|
if(UserInfoWrapper.ROLE_TEACHER.equals(ClientUtils.getCurrentRole()) || UserInfoWrapper.ROLE_CHARGER.equals(ClientUtils.getCurrentRole())){
|
commonDAO.bulkUpdate("update MediaVideo set videoOrder = " + index.get(i) + " where videoId = ?", new Object[] { videoId });
|
}else{
|
commonDAO.bulkUpdate("update MediaVideoReCourse set videoOrder = " + index.get(i) + " where videoId = ?", new Object[] { videoId });
|
}
|
commonDAO.bulkUpdate("update SchCourseware set orderNum = " + index.get(i) + " where id = ?", new Object[] { videoId });
|
}
|
return new Result(true);
|
}
|
|
/**
|
* ÅжÏÊÇ·ñÊý×Ö
|
* @param str
|
* @return
|
*/
|
public boolean isNumeric(String str){
|
Pattern pattern = Pattern.compile("[0-9]*");
|
Matcher isNum = pattern.matcher(str);
|
return isNum.matches();
|
}
|
|
|
|
/**************************** ³õʼ»¯Êý¾ÝµÄ·½·¨¿ªÊ¼ ******************/
|
@Override
|
public Result doInitCourseReVideoOrder(Organization org){
|
|
// »ñȡÿ¸ö»ú¹¹ÏÂÓÐÄÄЩ¿ÆÄ¿
|
String hql = "select distinct r.collegeCourseId from MediaVideoReCourse r where r.deleteFlag is false and r.orgId = ? ";
|
List<String> re = this.find(hql, CollectionUtils.newList(org.getOrganizationId()), String.class);
|
|
if(re.isEmpty()){
|
return new Result(true);
|
}
|
|
// Ñ»·»ú¹¹£¬¿ÆÄ¿ÏµÄÊÓÆµ ±àÅÅÐòºÅ,Á½²ãÑ»·Âß¼ÇåÎú
|
for( String collegeCourseId : re ){
|
this.doInitCourseReVideoOrder(org.getOrganizationId(),collegeCourseId);
|
}
|
|
return new Result(true);
|
}
|
|
private Result doInitCourseReVideoOrder(String orgId, String collegeCourseId){
|
|
String hql = "from MediaVideoReCourse r where r.deleteFlag is false and r.orgId = ? and r.collegeCourseId = ? ";
|
List<MediaVideoReCourse> lstMediaVideoReCourse = this.find(hql, CollectionUtils.newList(orgId,collegeCourseId), MediaVideoReCourse.class);
|
|
if(lstMediaVideoReCourse.isEmpty()){
|
return new Result(true);
|
}
|
|
int iOrder = 1;
|
for(MediaVideoReCourse obj : lstMediaVideoReCourse){
|
obj.setVideoOrder(iOrder);
|
iOrder++;
|
}
|
|
this.saveOrUpdateAll(lstMediaVideoReCourse);
|
|
return new Result(true);
|
}
|
/**
|
* ³õʼ»¯°à¼¶¿Î³Ì
|
*/
|
@Override
|
public Result doInitClassSubject(ClsClass cls){
|
|
// 1. init SchClassSubject
|
Map<String,String> map = this.doInitClassSubject(cls.getClassId(),cls.getCollegeCourseId());
|
|
// 2. init mediavideo µÄ subjectId£¬ subjectName
|
if(null == map || map.isEmpty()){
|
return new Result(true);
|
}
|
|
doInitMediaSubject(map,cls.getClassId());
|
|
|
return new Result(true);
|
|
}
|
|
private Map<String,String> doInitClassSubject(String classId,String collegeCourseId){
|
// ÄÃÓÐÊÓÆµµÄ¿Î³Ì
|
String videoHql = "select distinct s.name from SchClassSchedule s, SchReLessonVideo r, MediaVideo v where " +
|
"s.deleteFlag is false and r.deleteFlag is false and v.deleteFlag is false " +
|
"and s.classScheduleId = r.classScheduleId and r.videoId = v.videoId " +
|
"and s.classId = ? " ;
|
|
// ÄÃÓн²ÒåµÄ¿Î³Ì
|
String handoutHql = "select distinct s.name from SchHandout h,SchClassSchedule s " +
|
"where s.deleteFlag is false and h.deleteFlag is false " +
|
"and s.classScheduleId = h.classScheduleId " +
|
"and s.classId = ? ";
|
|
List<String> videoNames = this.find(videoHql, CollectionUtils.newList(classId), String.class);
|
List<String> handoutNames = this.find(handoutHql, CollectionUtils.newList(classId), String.class);
|
|
// È¥ÖØ
|
HashSet<String> nameSet =new HashSet<String>();
|
for(String video : videoNames){
|
nameSet.add(video);
|
}
|
for(String video : handoutNames){
|
nameSet.add(video);
|
}
|
|
if(nameSet.isEmpty()){
|
return null ;
|
}
|
|
// ¹¹Ôì SchClassSubject µÄ List
|
List<SchClassSubject> lstSubjects = new ArrayList<SchClassSubject>(nameSet.size());
|
SchClassSubject classSubject ;
|
for (String name : nameSet) {
|
|
classSubject = new SchClassSubject();
|
TraceUtils.setCreateTrace(classSubject);
|
classSubject.setClassId(classId);
|
classSubject.setCourseId(collegeCourseId);
|
classSubject.setName(name);
|
|
lstSubjects.add(classSubject);
|
|
}
|
|
if(!lstSubjects.isEmpty()){
|
this.saveOrUpdateAll(lstSubjects);
|
|
Map<String,String> map = new HashMap<String,String>();
|
for(SchClassSubject subject : lstSubjects){
|
map.put(subject.getName(), subject.getClassSubjectId());
|
}
|
|
return map;
|
}
|
|
return null ;
|
}
|
|
private Result doInitMediaSubject(Map<String,String> map,String classId){
|
|
String hql = "select v,s.name,s.classScheduleId from SchClassSchedule s, SchReLessonVideo r, MediaVideo v where " +
|
"s.deleteFlag is false and r.deleteFlag is false and v.deleteFlag is false " +
|
"and s.classScheduleId = r.classScheduleId and r.videoId = v.videoId " +
|
"and s.classId = ? " ;
|
List<MediaVideo> lstVideos = mediaVideoDAO.queryVideoItem(hql,CollectionUtils.newList(classId));
|
|
if(lstVideos.isEmpty()){
|
return new Result(true);
|
}
|
|
for( MediaVideo video : lstVideos ){
|
video.setSubjectId(map.get(video.getClassScheduleName()));
|
video.setSubjectName(video.getClassScheduleName());
|
|
this.saveVideo(video);
|
}
|
|
//this.saveOrUpdateAll(lstVideos);
|
|
return new Result(true);
|
}
|
/**
|
* ³õʼ»¯°à¼¶Ã½ÌåÐÅÏ¢
|
*/
|
@Override
|
public Result doInitClassMediaInfo(ClsClass cls){
|
|
String hql = "select v,s.teacher,s.classScheduleId from SchClassSchedule s, SchReLessonVideo r, MediaVideo v where " +
|
"s.deleteFlag is false and r.deleteFlag is false and v.deleteFlag is false " +
|
"and s.classScheduleId = r.classScheduleId and r.videoId = v.videoId " +
|
"and s.classId = ? " +
|
"order by v.subjectId " ;
|
|
List<MediaVideo> lstVideos = mediaVideoDAO.queryVideoItem(hql, CollectionUtils.newList(cls.getClassId()));
|
|
if(lstVideos.isEmpty()){
|
return new Result(true);
|
}
|
|
int index = 1;
|
for( MediaVideo video : lstVideos ){
|
|
video.setClassId(cls.getClassId());
|
if(StringUtils.isBlank(video.getTeacherName())){
|
video.setTeacherName(video.getClassScheduleName());
|
}
|
video.setVideoOrder(index);
|
index++;
|
|
this.saveVideo(video);
|
}
|
|
//this.saveOrUpdateAll(lstVideos);
|
|
return new Result(true);
|
}
|
/**
|
* ³õʼ»¯°à¼¶¿Î³Ì
|
*/
|
@Override
|
public Result doInitSubjectClass(ClsClass cls){
|
|
String hql = "from SchClassSchedule s where s.deleteFlag is false and s.classId = ? ";
|
List<SchClassSchedule> lstSchedules = this.find(hql, CollectionUtils.newList(cls.getClassId()), SchClassSchedule.class);
|
|
if(lstSchedules.isEmpty()){
|
return new Result(true);
|
}
|
|
String hql0 = "from SchClassSubject s where s.deleteFlag is false and s.classId = ? ";
|
List<SchClassSubject> lstSubjects = this.find(hql0, CollectionUtils.newList(cls.getClassId()), SchClassSubject.class);
|
|
Map<String,String> map = new HashMap<String,String>(lstSubjects.size());
|
//×é×°map£¬°´ÕÕÃû×ÖÆ¥Åä
|
for(SchClassSubject subject : lstSubjects){
|
map.put(subject.getName(), subject.getClassSubjectId());
|
}
|
|
for(SchClassSchedule schedule : lstSchedules ){
|
schedule.setClassSubjectId(map.get(schedule.getName()));
|
}
|
|
this.saveOrUpdateAll(lstSchedules);
|
|
return new Result(true);
|
}
|
/**
|
* ³õʼ»¯»ú¹¹¿Î³ÌÊÓÆµ
|
*/
|
@Override
|
public Result doInitOrgVideoSubject(Organization org){
|
|
// ËùÓпÆÄ¿
|
String hql = "from OrgCollegeCourse where deleteFlag is false and topOrgId = ? ";
|
List<OrgCollegeCourse> lstCourses = this.find(hql, CollectionUtils.newList(org.getOrganizationId()), OrgCollegeCourse.class);
|
|
// ÿһ¸ö¿ÆÄ¿ÊÇ·ñÐèÒªÔö¼Ó¿Î³Ì£¬Ôö¼Ó¿Î³ÌµÄ»°£¬Ôö¼Ó¿Î³ÌÊÓÆµ¹ØÁª
|
if(lstCourses.isEmpty()){
|
return new Result(true);
|
}
|
|
for(OrgCollegeCourse course : lstCourses){
|
doInitOrgVideoSubject(course);
|
}
|
|
return new Result(true);
|
}
|
|
private Result doInitOrgVideoSubject(OrgCollegeCourse course){
|
|
String hql = "from MediaVideoReCourse c where c.deleteFlag is false and collegeCourseId = ? ";
|
int iCount = this.findCount(hql, CollectionUtils.newList(course.getCollegeCourseId()));
|
|
if(iCount <= 0){
|
return new Result(true);
|
}
|
|
// ÐèÒª²åÈ빫¹²¿Î³Ì
|
Subject subject = new Subject();
|
subject.setCourseId(course.getCollegeCourseId());
|
subject.setName(publicSubjectName);
|
TraceUtils.setCreateTrace(subject);
|
save(subject);
|
|
// ά»¤µ½ÊÓÆµ
|
String hql0 = "select distinct v from MediaVideoReCourse c,MediaVideo v where " +
|
"c.deleteFlag is false and v.deleteFlag is false " +
|
"and c.collegeCourseId = ? " +
|
"and c.videoId = v.videoId ";
|
List<MediaVideo> lstVideos = this.find(hql0, CollectionUtils.newList(course.getCollegeCourseId()), MediaVideo.class);
|
|
if(lstVideos.isEmpty()){
|
return new Result(true);
|
}
|
|
for(MediaVideo video : lstVideos){
|
video.setSubjectId(subject.getSubjectId());
|
video.setSubjectName(subject.getName());
|
|
this.saveVideo(video);
|
}
|
|
//this.saveOrUpdateAll(lstVideos);
|
|
// ά»¤µ½°à¼¶
|
String hql1 = "from ClsClass s where s.deleteFlag is false and s.collegeCourseId = ? ";
|
List<ClsClass> lstCls = this.find(hql1, CollectionUtils.newList(course.getCollegeCourseId()), ClsClass.class);
|
|
if(lstCls.isEmpty()){
|
return new Result(true);
|
}
|
|
List<SchClassSubject> lstSubjects = new ArrayList<SchClassSubject>(lstCls.size());
|
SchClassSubject classSubject ;
|
|
for(ClsClass cls : lstCls){
|
|
//Èç¹ûÒѾ³õʼ»¯¹ý¹«¹²¿Î³Ì£¬Ö±½Ó½«°à¼¶µÄ¹«¹²¿Î³ÌºÍ¹ÜÀíÔ±µÄ¹«¹²¿Î³Ì¹ØÁªÆðÀ´
|
String hql3 = "from SchClassSubject s where s.deleteFlag is false and s.name=? and s.classId = ? ";
|
SchClassSubject sub3 = this.findUnique(hql3, CollectionUtils.newList(publicSubjectName,cls.getClassId()), SchClassSubject.class);
|
if(null != sub3){
|
sub3.setOrigSubjectId(subject.getSubjectId());
|
|
lstSubjects.add(sub3);
|
|
}else{
|
// ÐÂÔö¹«¹²¿Î³Ì
|
classSubject = new SchClassSubject();
|
|
TraceUtils.setCreateTrace(classSubject);
|
|
classSubject.setName(publicSubjectName);
|
classSubject.setClassId(cls.getClassId());
|
classSubject.setOrigSubjectId(subject.getSubjectId());
|
classSubject.setCourseId(course.getCollegeCourseId());
|
|
lstSubjects.add(classSubject);
|
|
}
|
}
|
|
this.saveOrUpdateAll(lstSubjects);
|
|
return new Result(true);
|
}
|
|
/**
|
* ³õʼ»¯»ú¹¹ÊÓÆµ
|
*/
|
public Result doInitOrgVideoLeft(MediaVideo video){
|
|
// µÃµ½¿ÆÄ¿¹ØÁª
|
String hql = "select c from MediaVideoReCourse r ,OrgCollegeCourse c where r.deleteFlag is false and c.deleteFlag is false and r.collegeCourseId = c.collegeCourseId and r.videoId = ? ";
|
OrgCollegeCourse course = this.findUnique(hql, CollectionUtils.newList(video.getVideoId()), OrgCollegeCourse.class);
|
|
if( null == course ){
|
return new Result(true);
|
}
|
|
// ÅжÏÊÇ·ñÓÐ ¹«¹²¿Î³Ì
|
String hql1 = "select s from SchSubject s where s.deleteFlag is false and s.name = ? and s.courseId = ? ";
|
Subject subject = this.findUnique(hql1, CollectionUtils.newList(publicSubjectName,course.getCollegeCourseId()), Subject.class);
|
|
// ²»´æÔÚ¹«¹²¿Î³Ì
|
if( null == subject ){
|
|
subject = new Subject();
|
subject.setCourseId(course.getCollegeCourseId());
|
subject.setName(publicSubjectName);
|
TraceUtils.setCreateTrace(subject);
|
save(subject);
|
|
}
|
|
video.setSubjectId(subject.getSubjectId());
|
video.setSubjectName(subject.getName());
|
|
return new Result(true);
|
}
|
|
/**
|
* ³õʼ»¯°à¼¶ÊÓÆµ
|
*/
|
public Result doInitClassVideoLeft(MediaVideo video){
|
|
String hql = "select s from SchClassSchedule s, SchReLessonVideo r, MediaVideo v where " +
|
"s.deleteFlag is false and r.deleteFlag is false and v.deleteFlag is false " +
|
"and s.classScheduleId = r.classScheduleId and r.videoId = v.videoId " +
|
"and v.videoId = ? " ;
|
|
SchClassSchedule schedule = this.findUnique(hql, CollectionUtils.newList(video.getVideoId()), SchClassSchedule.class);
|
|
if(null == schedule ){
|
return new Result(true);
|
}
|
|
// ²éÕҿδÎÃû ÊÇ·ñ ´æÔڿγÌÃû³Æ
|
String hql1 = "from SchClassSubject s where s.deleteFlag is false and s.name = ? and s.classId = ? ";
|
SchClassSubject classSubject = this.findUnique(hql1, CollectionUtils.newList(schedule.getName(),schedule.getClassId()), SchClassSubject.class);
|
|
if(null == classSubject){
|
|
classSubject = new SchClassSubject();
|
TraceUtils.setCreateTrace(classSubject);
|
|
classSubject.setName(schedule.getName());
|
classSubject.setClassId(schedule.getClassId());
|
classSubject.setCourseId(schedule.getCollegeCourseId());
|
|
// ÅжϸÿÆÄ¿ÏÂÊÇ·ñÓÐ¸Ã¿Î³Ì Óеϰ Ôö¼Ó¹ØÁª
|
String hql2 = "select s from SchSubject s where s.deleteFlag is false and s.name = ? and s.courseId = ? ";
|
Subject subject = this.findUnique(hql2, CollectionUtils.newList(schedule.getName(),schedule.getCollegeCourseId()), Subject.class);
|
|
if( null != subject ){
|
classSubject.setOrigSubjectId(subject.getSubjectId());
|
}
|
|
this.save(classSubject);
|
|
}
|
|
// ±£´æ£º¿Î´Î -- ¿Î³Ì ¹ØÁª
|
if(StringUtils.isBlank(schedule.getSubjectId())){
|
schedule.setSubjectId(classSubject.getClassSubjectId());
|
TraceUtils.setUpdateTrace(schedule);
|
this.save(schedule);
|
}
|
|
// ±£´æ£º order
|
String hql3 = "select MAX(v.videoOrder) from MediaVideo v where v.deleteFlag is false and v.classId = ? ";
|
Integer max = this.findUnique(hql3, CollectionUtils.newList(schedule.getClassId()), Integer.class);
|
|
if(null == max ){
|
max = 0 ;
|
}
|
|
// ±£´æ ÊÓÆµ¡¢¿Î³Ì
|
TraceUtils.setUpdateTrace(video);
|
video.setSubjectId(classSubject.getClassSubjectId());
|
video.setSubjectName(classSubject.getName());
|
video.setVideoOrder(max+1);
|
|
this.saveVideo(video);
|
|
|
return new Result(true);
|
}
|
/**
|
* ³õʼ»¯°à¼¶¿Î³Ì
|
*/
|
@Override
|
public Result doInitClassOrgSubject(OrgCollegeCourse course){
|
|
String hql = "from ClsClass s where s.deleteFlag is false and s.collegeCourseId = ? ";
|
List<ClsClass> lstClses = this.find(hql, CollectionUtils.newList(course.getCollegeCourseId()), ClsClass.class);
|
|
if(lstClses.isEmpty()){
|
return new Result(true);
|
}
|
|
//ÏÂÃæÓа༶£¬»ñÈ¡¿ÆÄ¿ID
|
String hql0 = "from SchSubject s where s.deleteFlag is false and s.courseId = ? and s.name = ? ";
|
Subject subject = this.findUnique(hql0, CollectionUtils.newList(course.getCollegeCourseId(),publicSubjectName), Subject.class);
|
|
if(null == subject ){
|
return new Result(true);
|
}
|
|
// °àÖ÷ÈΣº¸Ã¿ÆÄ¿ ¹«¹²¿Î³Ì ϵÄÊÓÆµ
|
String hql1 = " select m from MediaVideo m where m.deleteFlag is false and m.originVideoId in ( select videoId from MediaVideo v where v.deleteFlag is false and v.subjectId = ? ) and m.subjectId is null ";
|
List<MediaVideo> lstVideos = this.find(hql1, CollectionUtils.newList(subject.getSubjectId()), MediaVideo.class);
|
|
Map<String,List<MediaVideo>> map = new HashMap<String,List<MediaVideo>>(5);
|
for( MediaVideo video : lstVideos ){
|
|
// °üº¬
|
if(map.containsKey(video.getClassId())){
|
map.get(video.getClassId()).add(video);
|
}else{
|
List<MediaVideo> lstTemps = new ArrayList<MediaVideo>(5);
|
lstTemps.add(video);
|
map.put(video.getClassId(), lstTemps);
|
}
|
}
|
|
// Ñ»·´¦Àí°à¼¶µÄ ¹«¹²¿Î³Ì¹ØÁª
|
for(ClsClass cls : lstClses){
|
String schSubjectId = doInitClassOrgSubject(cls.getClassId(), subject.getSubjectId(), course.getCollegeCourseId());
|
|
if(StringUtils.isNotBlank(schSubjectId) && null != map.get(cls.getClassId())){
|
for( MediaVideo video : map.get(cls.getClassId()) ){
|
video.setSubjectId(schSubjectId);
|
}
|
|
this.saveOrUpdateAll(map.get(cls.getClassId()));
|
}
|
}
|
|
return new Result(true);
|
}
|
|
private String doInitClassOrgSubject(String classId, String subjectId,String collegeCourseId){
|
|
String hql = "from SchClassSubject s where s.classId = ? and s.deleteFlag is false and s.origSubjectId = ? ";
|
SchClassSubject subject = this.findUnique(hql, CollectionUtils.newList(classId,subjectId), SchClassSubject.class);
|
|
// 1. ´æÔÚ¹«¹²¿Î³ÌµÄ¹ØÁª£¬Ö±½Ó·µ»Ø
|
if(null != subject){
|
return subject.getClassSubjectId();
|
}
|
|
// 2. ²»´æÔÚ¹«¹²¿Î³Ì¹ØÁª£¬µ«ÊÇ´æÔÚ¹«¹²¿Î³Ì
|
String hql0 = "from SchClassSubject s where s.classId = ? and s.deleteFlag is false and s.name = ? and s.origSubjectId is null ";
|
SchClassSubject classSubject = this.findUnique(hql0, CollectionUtils.newList(classId,publicSubjectName), SchClassSubject.class);
|
|
if(null != classSubject){
|
TraceUtils.setUpdateTrace(classSubject);
|
classSubject.setOrigSubjectId(subjectId);
|
save(classSubject);
|
|
return classSubject.getClassSubjectId();
|
}
|
|
// 3. ûÓй«¹²¿Î³Ì£¬Ôö¼Ó¹ØÁª
|
classSubject = new SchClassSubject();
|
TraceUtils.setCreateTrace(classSubject);
|
|
classSubject.setName(publicSubjectName);
|
classSubject.setClassId(classId);
|
classSubject.setOrigSubjectId(subjectId);
|
classSubject.setCourseId(collegeCourseId);
|
|
save(classSubject);
|
|
return classSubject.getClassSubjectId();
|
}
|
|
/*************³õʼ»¯Êý¾ÝµÄ·½·¨½áÊø*******/
|
|
/**
|
* ÐèҪתÂëµÄÊÓÆµ£¬²åÈëתÂë¶ÓÁмǼ±í
|
* @param video
|
* @return
|
*/
|
public Result insertVideoConverTask(MediaVideo video){
|
//mp3Îļþ²»×ªÂë
|
// if(video.getUrl().indexOf(".mp3") > 0 || video.getUrl().indexOf(".MP3") > 0){
|
// this.bulkUpdate("update MediaVideo v set v.status = ? where v.videoId = ?", new Object[]{MediaVideo.STATUS_DRAFT, video.getVideoId()} );
|
// return new Result(true);
|
// }
|
VideoConverTask task = new VideoConverTask();
|
task.setType(video.getType());
|
task.setVideoId(video.getVideoId());
|
task.setCreateTime(new Date(System.currentTimeMillis()));
|
int iSnapshot = 1 ;
|
if(StringUtils.isNotBlank(video.getCoverPageUrl()) && !FilePathConstants.VIDEO_DEFAULT_IMG.equals(video.getCoverPageUrl())){
|
iSnapshot = 0 ;
|
}
|
task.setNeedSnapshot(iSnapshot);
|
task.setVideoUrl(video.getUrl());
|
// ÓÅÏȼ¶±ÈĬÈÏÉÏ´«¸ß
|
task.setPriority(5);
|
this.save(task);
|
|
|
|
return new Result(true);
|
}
|
|
/**
|
* Ñ¡ÔñÀúÊ·ÊÓÆµ
|
*
|
*/
|
public Result insertChooseVideo(String subjectId, String subjectName, String videoId, String chapterId){
|
MediaVideo objMediaVideo = this.read(MediaVideo.class, videoId);
|
|
MediaVideo newMediaVideo = new MediaVideo();
|
try {
|
//¿½±´ÊôÐÔµ½Ð¶ÔÏó
|
BeanUtils.copyProperties(newMediaVideo, objMediaVideo);
|
newMediaVideo.setVideoId(null);
|
newMediaVideo.setSubjectId(subjectId);
|
newMediaVideo.setSubjectName(subjectName);
|
newMediaVideo.setClassId(ClientUtils.getClassId());
|
newMediaVideo.setChapterId(chapterId);
|
newMediaVideo.setCollegeCourseId(ClientUtils.getCourseId());
|
newMediaVideo.setStatus(objMediaVideo.getStatus() == MediaVideo.STATUS_PUBLISHED?MediaVideo.STATUS_DRAFT:objMediaVideo.getStatus());
|
|
TraceUtils.setCreateTrace(newMediaVideo);
|
|
this.saveVideo(newMediaVideo);
|
} catch (Exception e) {
|
this.log.error(e);
|
}
|
|
return new Result(true);
|
}
|
|
|
/**
|
* תÂë¶ÓÁÐ
|
*
|
* @return
|
*/
|
public List<VideoConverTask> getVideoConverTaskList(){
|
|
StringBuffer hql = new StringBuffer(256);
|
hql.append(" FROM ");
|
hql.append(" VideoConverTask ");
|
hql.append(" WHERE ");
|
hql.append(" status = 0 ");
|
hql.append(" AND deleteFlag = 0 ");
|
hql.append(" AND ( ");
|
hql.append(" converLdLock IS NULL ");
|
hql.append(" OR converLdLock = '' ");
|
hql.append(" ) ");
|
hql.append(" ORDER BY priority, createTime ASC ");
|
|
return this.find(hql.toString(), CollectionUtils.newList(), VideoConverTask.class);
|
}
|
|
/**
|
* ±£´æÊÓÆµ½Ó¿Ú
|
*
|
* @param video
|
* @return
|
*/
|
public Result saveVideo(MediaVideo video){
|
Result result = new Result(false);
|
result = this.save(video);
|
if(!"live".equals(video.getVideoSource())){
|
String parentChapterId = null;
|
if(StringUtils.isNotEmpty(video.getChapterId())){
|
SubjectChapter chapter = this.read(SubjectChapter.class, video.getChapterId());
|
parentChapterId = chapter == null?null : chapter.getParentChapterId();
|
}
|
boolean isClass = StringUtils.isNotEmpty(ClientUtils.getClassId()) || StringUtils.isNotEmpty(video.getClassId());
|
SchCourseware courseware = null;
|
if(isClass){
|
courseware = this.findUnique("from SchCourseware where id = ? and classId = ? and deleteFlag is false",
|
CollectionUtils.newList(video.getVideoId(), video.getClassId()), SchCourseware.class);
|
}else{
|
courseware = this.findUnique("from SchCourseware where id = ? and classId is null and deleteFlag is false",
|
CollectionUtils.newList(video.getVideoId()), SchCourseware.class);
|
}
|
|
if(courseware == null){
|
courseware = new SchCourseware();
|
courseware.setChapterId(video.getChapterId());
|
courseware.setId(video.getVideoId());
|
courseware.setCollegeCourseId(video.getCollegeCourseId());
|
courseware.setcType(-1);
|
courseware.setType(SchCourseware.COURSEWARE_TYPE_VIDEO);
|
courseware.setName(video.getName());
|
courseware.setRemark(String.valueOf(video.getPlayTime()));
|
courseware.setDeleteFlag(video.getDeleteFlag());
|
courseware.setOrderNum(video.getVideoOrder() == null?1000:video.getVideoOrder());
|
courseware.setSubjectId(video.getSubjectId());
|
courseware.setStatus(video.getStatus());
|
courseware.setOrgId(ClientUtils.getOrgId());
|
courseware.setClassId(video.getClassId());
|
courseware.setParentChapterId(parentChapterId);
|
courseware.setScoreValue(new BigDecimal(0.0));
|
|
TraceUtils.setCreateTrace(courseware);
|
}else{
|
courseware.setChapterId(video.getChapterId());
|
//courseware.setCollegeCourseId(video.getCollegeCourseId());
|
courseware.setcType(-1);
|
courseware.setName(video.getName());
|
courseware.setRemark(String.valueOf(video.getPlayTime()));
|
courseware.setDeleteFlag(video.getDeleteFlag());
|
courseware.setOrderNum(video.getVideoOrder() == null?1000:video.getVideoOrder());
|
courseware.setSubjectId(video.getSubjectId());
|
courseware.setStatus(video.getStatus());
|
courseware.setParentChapterId(parentChapterId);
|
courseware.setScoreValue(new BigDecimal(0.0));
|
TraceUtils.setUpdateTrace(courseware);
|
}
|
|
this.save(courseware);
|
}
|
return result;
|
}
|
|
@Override
|
public Result doFfmpegMediaTrascode(String videoId, String videoName) {
|
// TODO Auto-generated method stub
|
return null;
|
}
|
|
}
|