package com.qxueyou.scc.school.service.impl;
|
|
import java.util.ArrayList;
|
import java.util.Arrays;
|
import java.util.Calendar;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
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.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.stereotype.Service;
|
import org.springframework.web.servlet.ModelAndView;
|
|
import com.qxueyou.scc.admin.classes.model.ClsClass;
|
import com.qxueyou.scc.base.dao.CommonDAO;
|
import com.qxueyou.scc.base.model.Pager;
|
import com.qxueyou.scc.base.model.Result;
|
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.DateTimeUtils;
|
import com.qxueyou.scc.base.util.TraceUtils;
|
import com.qxueyou.scc.media.model.MediaVideo;
|
import com.qxueyou.scc.media.model.MediaVideoReCourse;
|
import com.qxueyou.scc.media.service.IMediaVideoService;
|
import com.qxueyou.scc.org.model.OrgText;
|
import com.qxueyou.scc.org.service.IOrgTextService;
|
import com.qxueyou.scc.school.dao.LessonDAO;
|
import com.qxueyou.scc.school.model.SchClassSchedule;
|
import com.qxueyou.scc.school.model.SchClassSubject;
|
import com.qxueyou.scc.school.model.SchReLessonVideo;
|
import com.qxueyou.scc.school.service.ICourseWareService;
|
import com.qxueyou.scc.school.service.ILessonService;
|
import com.qxueyou.scc.teach.subject.model.SubjectChapter;
|
|
/**
|
* 课程服务
|
*
|
* @author 德虎
|
*
|
*/
|
@Service
|
public class LessonService extends CommonAppService implements ILessonService {
|
|
@Autowired
|
CommonDAO dao;
|
|
|
|
@Autowired
|
IMediaVideoService mediaVideoService;
|
|
|
|
@Autowired
|
IOrgTextService orgTextService;
|
|
|
private LessonDAO lessonDAO;
|
|
@Autowired
|
private ICourseWareService courseWareService;
|
|
private static Logger log = LogManager.getLogger("LessonService");
|
|
private static final String OPERATE_TYPE_ISSUE = "Issue";
|
|
private static final String OPERATE_TYPE_STOP = "Stop";
|
|
/**
|
* 依赖注入
|
*
|
* @param lessonDAO
|
*/
|
@Autowired(required = false)
|
public void setLessonDAO(@Qualifier("lessonDAO") LessonDAO lessonDAO) {
|
this.lessonDAO = lessonDAO;
|
}
|
|
public LessonDAO getLessonDAO() {
|
return lessonDAO;
|
}
|
|
/**
|
* 定时发布、停用
|
*/
|
@Override
|
public Result doVideoIssueStop() {
|
|
doVideoIssue(); // 发布未发布的视频
|
//doVideoStop(); // 停用已过期的视频
|
|
return new Result(true);
|
}
|
|
/**
|
* 定时发布
|
*/
|
@SuppressWarnings("unused")
|
public Result doVideoIssue() {
|
|
Date now = new Date();
|
|
// 查询未发布的视频 ---- 只有草稿状态的视频才能发布
|
String hql = "from MediaVideo where deleteFlag is false and status = ? and startTime <= ? and endTime > ? ";
|
List<MediaVideo> mediaLst = this.find(hql, CollectionUtils.newList(MediaVideo.STATUS_DRAFT,now,now), MediaVideo.class);
|
|
// for (MediaVideo mediaVideo : mediaLst) {
|
// // 发送消息 发布视频
|
// sendMsgVideoIssueStop(OPERATE_TYPE_ISSUE, mediaVideo.getVideoId());
|
// }
|
//
|
return new Result(true);
|
}
|
|
@SuppressWarnings("unused")
|
public Result doVideoStop() {
|
|
Date now = new Date();
|
|
// 查询已过期的视频 ---- 只有已发布的视频才能停用
|
String hql = "from MediaVideo where deleteFlag is false and status = ? and endTime <= ?";
|
List<MediaVideo> mediaLst = this.find(hql, CollectionUtils.newList(MediaVideo.STATUS_PUBLISHED,now), MediaVideo.class);
|
|
// for (MediaVideo mediaVideo : mediaLst) {
|
// // 发送消息 停用视频
|
// sendMsgVideoIssueStop(OPERATE_TYPE_STOP, mediaVideo.getVideoId());
|
// }
|
return new Result(true);
|
}
|
|
|
|
/**
|
* 单个处理视频发布与上传
|
*/
|
@SuppressWarnings("unused")
|
@Override
|
public Result doSingleVideoIssueStop(String videoId,String operateType) {
|
|
MediaVideo video = read(MediaVideo.class, videoId);
|
if(OPERATE_TYPE_ISSUE.equals(operateType)){ // 发布
|
log.info("发布");
|
bulkUpdateInLoop("update MediaVideo set status = " + MediaVideo.STATUS_PUBLISHED + " where videoId = ? " ,new Object[] { videoId });
|
bulkUpdateInLoop("update SchCourseware set status = " + MediaVideo.STATUS_PUBLISHED + " where id = ? " ,new Object[] { videoId });
|
|
// ONSMsg msg = new ONSMsg(onsProducer.getTopic());
|
// msg.put("msgType", "VIDEO_PUBLISH");
|
// msg.put("videoIds", video.getVideoId());
|
// msg.put("classId", video.getClassId());
|
// try {
|
// onsProducer.sendMsg(msg);
|
// } catch (Exception e) {
|
// log.error("Lesson.sendMsg.videoId: " + video.getVideoId(), e);
|
// }
|
|
}else if(OPERATE_TYPE_STOP.equals(operateType)){ // 停用
|
log.info("停用");
|
bulkUpdateInLoop("update MediaVideo set status = " + MediaVideo.STATUS_TAKEOFF + " where videoId = ? " ,new Object[] { videoId });
|
}
|
|
return new Result(true);
|
}
|
|
/**
|
* 添加视频
|
*/
|
@Override
|
public Result insertVideo(MediaVideo video, String lessonId, boolean isCopy) {
|
|
this.insertVideoSingle(video, lessonId, isCopy);
|
|
// 将数据插入转码队列
|
mediaVideoService.insertVideoConverTask(video);
|
|
// 调用本地转码服务
|
//mediaVideoService.doFfmpegMediaTrascode(video.getVideoId(), video.getName());
|
|
return new Result(true, video.getVideoId());
|
}
|
|
/**
|
* 添加视频,不调用转码
|
*/
|
@Override
|
public Result insertVideoSingle(MediaVideo video, String lessonId, boolean isCopy) {
|
video.setVideoId(null);
|
TraceUtils.setCreateTrace(video);
|
video.setClassId(ClientUtils.getClassId());
|
video.setDeleteFlag(false);
|
video.setSubmitor(ClientUtils.getUserName());
|
video.setSubmitorId(ClientUtils.getUserId());
|
video.setPlayTimes(0);
|
if(isCopy){
|
video.setStatus(video.getStatus() == MediaVideo.STATUS_PUBLISHED ?MediaVideo.STATUS_DRAFT: video.getStatus());
|
}else{
|
//jgw 暂时直接修改为
|
// video.setStatus(MediaVideo.STATUS_LINEUP);
|
video.setStatus(MediaVideo.STATUS_PUBLISHED);
|
}
|
|
// 序号
|
String hql = "select MAX(c.videoOrder) from MediaVideo c where c.deleteFlag is false and c.classId = ? ";
|
Integer iMax = this.findUnique(hql, CollectionUtils.newList(ClientUtils.getClassId()), Integer.class);
|
|
if (iMax == null || iMax == 0) {
|
iMax = 1;
|
} else {
|
iMax = iMax + 1;
|
}
|
video.setVideoOrder(iMax);
|
|
this.mediaVideoService.saveVideo(video);
|
|
// 保存OrgText —— 视频详情
|
orgTextService.doSaveOrgText(video.getVideoId(), OrgText.TABLE_NAME_VIDEO, video.getRemark());
|
|
if(StringUtils.isNotBlank(lessonId)){
|
SchReLessonVideo re = new SchReLessonVideo();
|
TraceUtils.setCreateTrace(re);
|
re.setDeleteFlag(false);
|
re.setClassScheduleId(lessonId);
|
re.setVideoId(video.getVideoId());
|
this.save(re);
|
}
|
|
//标记班级有视频
|
ClsClass cls = read(ClsClass.class, ClientUtils.getClassId());
|
if(cls!=null&&cls.getHaveVideo()==ClsClass.NOT_HAVE_VIDEO){
|
cls.setHaveVideo(ClsClass.HAVE_VIDEO);
|
save(cls);
|
}
|
|
return new Result(true, video.getVideoId());
|
}
|
|
/**
|
* 批量发布视频
|
*/
|
@Override
|
public Result doStartVideos(String videoIds) {
|
|
if(StringUtils.isEmpty(videoIds)){
|
return new Result(false, "参数错误");
|
}
|
String[] ids = videoIds.split(",");
|
boolean resultFlag = false;
|
for (String videoId : ids) {
|
Result result = doStartVideo(videoId);
|
if(result.isSuccess()){
|
resultFlag = true;
|
}
|
}
|
|
// // 发送消息
|
// ONSMsg msg = new ONSMsg(onsProducer.getTopic());
|
// msg.put("msgType", "VIDEO_PUBLISH");
|
// msg.put("videoIds", videoIds);
|
// msg.put("classId", ClientUtils.getClassId());
|
// try {
|
// onsProducer.sendMsg(msg);
|
// } catch (Exception e) {
|
// log.error("Lesson.sendMsg.videoId: " + videoIds, e);
|
// }
|
|
return new Result(resultFlag);
|
}
|
|
/**
|
* 发布视频
|
*/
|
public Result doStartVideo(String videoId) {
|
|
MediaVideo video = read(MediaVideo.class, videoId);
|
|
if( video.getStatus() == MediaVideo.STATUS_DRAFT || video.getStatus() == MediaVideo.STATUS_TAKEOFF || video.getStatus() == MediaVideo.STATUS_PUBLISHED){ // 草稿、已下架
|
|
TraceUtils.setUpdateTrace(video);
|
video.setStatus(MediaVideo.STATUS_PUBLISHED);
|
|
return mediaVideoService.saveVideo(video);
|
|
}else{
|
|
return new Result(false);
|
}
|
|
}
|
|
/**
|
* 批量停用视频
|
*/
|
@Override
|
public Result doStopVideos(String videoIds) {
|
if(StringUtils.isEmpty(videoIds)){
|
return new Result(false, "参数错误");
|
}
|
boolean resultFlag = false;
|
|
String[] ids = videoIds.split(",");
|
for (String videoId : ids) {
|
|
Result result = doStopVideo(videoId);
|
if(result.isSuccess()){
|
resultFlag = true;
|
}
|
}
|
|
return new Result(resultFlag);
|
}
|
|
/**
|
* 停用视频
|
*/
|
public Result doStopVideo(String videoId) {
|
|
MediaVideo video = read(MediaVideo.class, videoId);
|
|
if(video.getStatus() == MediaVideo.STATUS_PUBLISHED){ // 已发布
|
|
TraceUtils.setUpdateTrace(video);
|
video.setStatus(MediaVideo.STATUS_TAKEOFF);
|
|
mediaVideoService.saveVideo(video);
|
|
return new Result(true);
|
}else{
|
|
return new Result(false,"视频已发布状态才能停用视频");
|
}
|
}
|
|
/**
|
* 添加视频
|
*/
|
@Override
|
public Result insertOrgVideo(MediaVideo video, String collegeCourseId, boolean isCopy) {
|
String hql = " from MediaVideoReCourse where collegeCourseId = ? and deleteFlag is false";
|
int count = findCount(hql, CollectionUtils.newList(collegeCourseId));
|
TraceUtils.setCreateTrace(video);
|
video.setDeleteFlag(false);
|
video.setSubmitor(ClientUtils.getUserName());
|
video.setSubmitorId(ClientUtils.getUserId());
|
|
|
video.setPlayTimes(0);
|
if(isCopy){
|
video.setStatus(video.getStatus() == MediaVideo.STATUS_PUBLISHED ?MediaVideo.STATUS_LINEUP: video.getStatus());
|
}else{
|
video.setStatus(MediaVideo.STATUS_LINEUP);
|
}
|
|
|
mediaVideoService.saveVideo(video);
|
video.setOriginVideoId(video.getVideoId());
|
mediaVideoService.saveVideo(video);
|
|
// 保存OrgText —— 视频详情
|
orgTextService.doSaveOrgText(video.getVideoId(), OrgText.TABLE_NAME_VIDEO, video.getRemark());
|
|
// 序号
|
hql = "select MAX(c.videoOrder) from MediaVideoReCourse c where c.deleteFlag is false and c.collegeCourseId = ? ";
|
Integer iMax = this.findUnique(hql, CollectionUtils.newList(collegeCourseId), Integer.class);
|
|
if (iMax == null || iMax == 0) {
|
iMax = 1;
|
} else {
|
iMax = iMax + 1;
|
}
|
|
MediaVideoReCourse course = new MediaVideoReCourse();
|
course.setCollegeCourseId(collegeCourseId);
|
course.setDeleteFlag(false);
|
course.setVideoId(video.getVideoId());
|
course.setOrgId(ClientUtils.getOrgId());
|
course.setVideoOrder(iMax);
|
TraceUtils.setCreateTrace(course);
|
save(course);
|
|
//mediaVideoService.doFfmpegMediaTrascode(video.getVideoId(), video.getName());
|
// 将数据插入转码队列
|
mediaVideoService.insertVideoConverTask(video);
|
|
// TODO 不自动指定给自己
|
// insertAppointSelfOrg(video.getVideoId(), ClientUtils.getOrgId(),collegeCourseId);
|
Result result = new Result(true,video.getVideoId());
|
result.addData("count", count+1);
|
return result;
|
}
|
|
public Result insertAppointOrgVideo(String videoIds[], String orgIds[], String classIds[]) {
|
if(videoIds.length == 0){
|
return new Result(false,"参数错误");
|
}
|
//预先按videoId和OrgId查询mediavideoreCourse表,需要把当前机构ID也放进lstOrgIds一起查
|
List<String> lstOrgIds0 = Arrays.asList(orgIds);
|
List<String> lstOrgIds = new ArrayList<String>();
|
lstOrgIds.addAll(lstOrgIds0);
|
lstOrgIds.add(ClientUtils.getOrgId());
|
Map<String,MediaVideoReCourse> videoOrgCourseMap = new HashMap<String, MediaVideoReCourse>();
|
Map<String,Object> args = new HashMap<String, Object>();
|
String hql = " from MediaVideoReCourse where videoId in (:videoIds) and deleteFlag is false and orgId in (:orgIds)";
|
args.put("videoIds", videoIds);
|
args.put("orgIds", lstOrgIds.toArray());
|
List<MediaVideoReCourse> lstMediaCourse = findByComplexHql(hql, args, MediaVideoReCourse.class);
|
for (MediaVideoReCourse mediaVideoReCourse : lstMediaCourse) {
|
videoOrgCourseMap.put(mediaVideoReCourse.getVideoId()+mediaVideoReCourse.getOrgId(), mediaVideoReCourse);
|
}
|
if(orgIds.length!=0){ // 添加管理员视频
|
insertOrgVideo(videoIds,orgIds,videoOrgCourseMap);
|
}
|
if(classIds.length!=0){ // 添加班级视频
|
insertClassVideo(videoIds,classIds,ClientUtils.getOrgId(),videoOrgCourseMap);
|
}
|
|
return new Result(true);
|
}
|
|
private void insertOrgVideo(String videoIds[], String orgIds[],Map<String,MediaVideoReCourse> videoOrgCourseMap){
|
Map<String,Object> args = new HashMap<String, Object>();
|
Map<String,MediaVideoReCourse> videoCourseMap = new HashMap<String, MediaVideoReCourse>();
|
String hql = " from MediaVideoReCourse where videoId in (:videoIds) and deleteFlag is false";
|
args.put("videoIds", videoIds);
|
List<MediaVideoReCourse> lstCourse = findByComplexHql(hql, args, MediaVideoReCourse.class);
|
for (MediaVideoReCourse mediaVideoReCourse : lstCourse) {
|
videoCourseMap.put(mediaVideoReCourse.getVideoId(), mediaVideoReCourse);
|
}
|
|
for (String orgId : orgIds) {
|
for (String videoId : videoIds) {
|
|
//String hql = " from MediaVideoReCourse where videoId = ? and deleteFlag is false and orgId = ?";
|
|
MediaVideoReCourse mvrc = videoOrgCourseMap.get(videoId+orgId);
|
if (mvrc == null) {
|
//String hql = " from MediaVideoReCourse where videoId = ? and deleteFlag is false";
|
MediaVideoReCourse mvr = videoCourseMap.get(videoId);
|
mvrc = new MediaVideoReCourse();
|
mvrc.setCollegeCourseId(mvr.getCollegeCourseId());
|
mvrc.setDeleteFlag(false);
|
mvrc.setVideoId(videoId);
|
mvrc.setOrgId(orgId);
|
mvrc.setVideoOrder(mvr.getVideoOrder());
|
TraceUtils.setCreateTrace(mvrc);
|
save(mvrc);
|
|
this.courseWareService.insertOrgCourseware(videoId, ClientUtils.getOrgId(), orgId, mvr.getCollegeCourseId());
|
}
|
}
|
}
|
}
|
private void insertClassVideo(String videoIds[],String classIds[],String currOrgId,Map<String,MediaVideoReCourse> videoOrgCourseMap){
|
Map<String,Object> args = new HashMap<String, Object>();
|
List<String> lstOriginVideoIds = new ArrayList<String>();
|
List<String> lstSubjectIds = new ArrayList<String>();
|
Map<String,MediaVideo> videoMap = new HashMap<String, MediaVideo>();
|
Map<String,MediaVideo> originVideoMap = new HashMap<String, MediaVideo>();
|
Map<String,SchClassSubject> origSubjectMap = new HashMap<String, SchClassSubject>();
|
//章节id
|
List<String> lstCharpteIds = new ArrayList<String>();
|
Map<String,SubjectChapter> origChapterMap = new HashMap<String, SubjectChapter>();
|
List<String> keys = new ArrayList<String>();
|
String hql = " from MediaVideo where videoId in (:videoIds) and deleteFlag is false";
|
args.put("videoIds", videoIds);
|
List<MediaVideo> lstVideo = findByComplexHql(hql, args, MediaVideo.class);
|
for (MediaVideo mediaVideo : lstVideo) {
|
videoMap.put(mediaVideo.getVideoId(), mediaVideo);
|
lstOriginVideoIds.add(mediaVideo.getOriginVideoId());
|
lstSubjectIds.add(mediaVideo.getSubjectId());
|
if(StringUtils.isNotEmpty(mediaVideo.getChapterId())){
|
lstCharpteIds.add(mediaVideo.getChapterId());
|
}
|
keys.add(mediaVideo.getVideoId());
|
}
|
//查询所有originVideoId对应的mediaVideo
|
hql = " from MediaVideo where originVideoId in (:originVideoIds) and deleteFlag is false and classId in (:classIds)";
|
args = new HashMap<String, Object>();
|
args.put("originVideoIds", lstOriginVideoIds.toArray());
|
args.put("classIds",classIds);
|
List<MediaVideo> lstOriginVideo = findByComplexHql(hql, args, MediaVideo.class);
|
for (MediaVideo mediaVideo : lstOriginVideo) {
|
originVideoMap.put(mediaVideo.getOriginVideoId() + mediaVideo.getClassId(), mediaVideo);
|
}
|
|
hql = " from SchClassSubject where classId in (:classIds) and origSubjectId in (:origSubjectIds)";
|
args = new HashMap<String, Object>();
|
args.put("classIds", classIds);
|
args.put("origSubjectIds", lstSubjectIds.toArray());
|
List<SchClassSubject> subjects = findByComplexHql(hql, args, SchClassSubject.class);
|
for (SchClassSubject schClassSubject : subjects) {
|
origSubjectMap.put(schClassSubject.getClassId()+schClassSubject.getOrigSubjectId(), schClassSubject);
|
}
|
|
Map<String, Object> orgTextMap = orgTextService.getOrgTextMap(keys, OrgText.TABLE_NAME_VIDEO);
|
|
for (String clsId : classIds) {
|
for (String videoId : videoIds) {
|
MediaVideo video = videoMap.get(videoId);
|
MediaVideo mv = originVideoMap.get(video.getOriginVideoId()+clsId); // 判断当前班级有没有这个视频
|
if (mv == null) {
|
SchClassSubject clsSubject = origSubjectMap.get(clsId+video.getSubjectId());
|
mv = new MediaVideo();
|
MediaVideoReCourse videoCourse = videoOrgCourseMap.get(videoId+currOrgId);
|
try {
|
BeanUtils.copyProperties(mv, video);
|
mv.setVideoId(null);
|
mv.setClassId(clsId);
|
mv.setVideoOrder(videoCourse.getVideoOrder());
|
if(clsSubject == null){
|
mv.setSubjectId(null);
|
mv.setSubjectName(null);
|
mv.setCollegeCourseId(this.read(ClsClass.class, clsId).getCollegeCourseId());
|
}else{
|
mv.setSubjectId(clsSubject.getClassSubjectId());
|
mv.setSubjectName(clsSubject.getName());
|
mv.setCollegeCourseId(clsSubject.getCourseId());
|
}
|
if(null != origChapterMap.get(video.getOriginVideoId()+clsId)){
|
mv.setChapterId(origChapterMap.get(video.getOriginVideoId()+clsId).getChapterId());
|
}else{
|
mv.setChapterId(null);
|
}
|
} catch (Exception e) {
|
log.error("视频下发到班级BeanUtils.copyProperties()方法copy失败", e);
|
}
|
TraceUtils.setCreateTrace(mv);
|
this.mediaVideoService.saveVideo(mv);
|
|
OrgText oldOrgText = (OrgText) orgTextMap.get(video.getVideoId()); // 插入OrgText
|
orgTextService.doInsertOrgText(mv.getVideoId(), OrgText.TABLE_NAME_VIDEO, oldOrgText != null ? oldOrgText.getContent() : video.getRemark());
|
}
|
}
|
//标记班级有视频
|
ClsClass cls = read(ClsClass.class, clsId);
|
if(cls!=null&&cls.getHaveVideo()==ClsClass.NOT_HAVE_VIDEO){
|
cls.setHaveVideo(ClsClass.HAVE_VIDEO);
|
save(cls);
|
}
|
}
|
}
|
|
@Override
|
public Result deleteVideos(String videoIds) {
|
if(StringUtils.isEmpty(videoIds)){
|
return new Result(false, "参数错误");
|
}
|
|
String[] ids = videoIds.split(",");
|
List<String> lst = new ArrayList<String>();
|
for (String videoId : ids) {
|
Result result = deleteVideo(videoId);
|
if (result.isSuccess()) {
|
lst.add(videoId);
|
}
|
}
|
|
// 转码记录
|
bulkUpdateInLoop("update MediaVideoTrans set deleteFlag = true where videoId = ?", lst.toArray());
|
this.bulkUpdateInLoop("update SchCourseware set deleteFlag=1 where id=?", lst.toArray());
|
|
return new Result(true);
|
}
|
|
public Result deleteVideo(String videoId) {
|
String hql = " from MediaVideoReCourse where videoId = ? and deleteFlag is false and orgId=?";
|
MediaVideoReCourse mvr = findUnique(hql, CollectionUtils.newList(videoId, ClientUtils.getOrgId()), MediaVideoReCourse.class);
|
if (mvr == null) {
|
MediaVideo video = read(MediaVideo.class, videoId);
|
TraceUtils.setUpdateTrace(video);
|
video.setDeleteFlag(true);
|
|
mediaVideoService.saveVideo(video);
|
return new Result(true);
|
}
|
|
hql = " from SchReLessonVideo where classScheduleId in" + "(select classScheduleId from SchClassSchedule where classId =? and deleteFlag is false)" + " and deleteFlag is false and videoId=?";
|
List<SchReLessonVideo> lstVideo = find(hql, CollectionUtils.newList(ClientUtils.getClassId(), videoId), SchReLessonVideo.class);
|
for (SchReLessonVideo schReLessonVideo : lstVideo) {
|
schReLessonVideo.setDeleteFlag(true);
|
TraceUtils.setUpdateTrace(schReLessonVideo);
|
save(schReLessonVideo);
|
}
|
|
return new Result(false);
|
}
|
|
public Result updateMediaVideo(MediaVideo video){
|
MediaVideo v = read(MediaVideo.class, video.getVideoId());
|
|
if(MediaVideo.STATUS_TAKEOFF == v.getStatus()){
|
if(null != video.getStartTime() && video.getStartTime().before(new Date())
|
&& null != video.getEndTime() && !video.getEndTime().before(new Date())){ // video.getStartTime()在new Date()之前返回true,否则返回false
|
|
v.setStatus(MediaVideo.STATUS_PUBLISHED);
|
}
|
|
if( null != video.getStartTime() && !video.getStartTime().before(new Date())){
|
|
v.setStatus(MediaVideo.STATUS_DRAFT);
|
}
|
}
|
|
if(MediaVideo.STATUS_PUBLISHED == v.getStatus()&&null != video.getEndTime() && video.getEndTime().before(new Date())
|
&& null != video.getStartTime() && video.getStartTime().before(new Date())){
|
// video.getEndTime()在new Date()之前
|
v.setStatus(MediaVideo.STATUS_TAKEOFF);
|
|
}
|
|
v.setCoverPageUrl(video.getCoverPageUrl());
|
//v.setSubjectId(video.getSubjectId());
|
//v.setSubjectName(video.getSubjectName());
|
v.setStartTime(video.getStartTime());
|
v.setEndTime(video.getEndTime());
|
v.setValidity(video.getValidity());
|
v.setName(video.getName());
|
v.setRemark(video.getRemark());
|
v.setTeacherName(video.getTeacherName());
|
this.mediaVideoService.saveVideo(v);
|
|
// 保存OrgText —— 视频详情
|
orgTextService.doSaveOrgText(v.getVideoId(), OrgText.TABLE_NAME_VIDEO, video.getRemark());
|
|
String hql = " from MediaVideo where videoId!=? and deleteFlag is false and originVideoId = ?";
|
List<MediaVideo> lstVideo = find(hql, CollectionUtils.newList(video.getVideoId(),video.getVideoId()), MediaVideo.class);
|
for (MediaVideo mediaVideo : lstVideo) {
|
hql = " from SchClassSubject where deleteFlag is false and classId = ? and origSubjectId = ?";
|
|
SchClassSubject scs = findUnique(hql, CollectionUtils.newList(mediaVideo.getClassId(),video.getSubjectId()), SchClassSubject.class);
|
if(scs==null){
|
continue;
|
}
|
mediaVideo.setSubjectId(scs.getClassSubjectId());
|
mediaVideo.setSubjectName(scs.getName());
|
this.mediaVideoService.saveVideo(mediaVideo);
|
}
|
return new Result(true);
|
}
|
|
public Result deleteOrgVideo(String videoId, Integer delAll, String orgIds[], String classIds[]) {
|
if ((orgIds != null && orgIds.length != 0) || (classIds != null && classIds.length != 0)) {
|
// 删除需要回撤的视频
|
return deleteAppoint(videoId, orgIds, classIds);
|
}
|
|
String hql = " from MediaVideoReCourse where videoId = ? and deleteFlag is false and orgId = ?";
|
List<MediaVideoReCourse> lstMvr = find(hql, CollectionUtils.newList(videoId,ClientUtils.getOrgId()), MediaVideoReCourse.class);
|
for (MediaVideoReCourse mediaVideoReCourse : lstMvr) {
|
TraceUtils.setUpdateTrace(mediaVideoReCourse);
|
mediaVideoReCourse.setDeleteFlag(true);
|
save(mediaVideoReCourse);
|
|
this.courseWareService.deleteOrgCourseware(videoId, ClientUtils.getOrgId());
|
}
|
/*
|
MediaVideo video = this.read(MediaVideo.class, videoId);
|
if(video != null){
|
TraceUtils.setUpdateTrace(video);
|
video.setDeleteFlag(true);
|
this.mediaVideoService.saveVideo(video);
|
}*/
|
// 用户选择同时删除下级视频
|
if (delAll == 1) {
|
deleteSub(videoId,ClientUtils.getOrgId());
|
|
}
|
return new Result(true);
|
}
|
|
@SuppressWarnings("unchecked")
|
private void deleteSub(String videoId,String currOrgId) {
|
// 机构层级视频是没有重新new ,查询出机构下级ID再删关联表
|
String sql = " select oa.organization_id from organization as oa,organization ob " +
|
" where " +
|
" ob.ORGANIZATION_ID = ? " +
|
" and " +
|
" oa.org_code like CONCAT(ob.org_code,'%' ) " +
|
" and oa.delete_flag is false and ob.delete_flag is false "+
|
" order by oa.level,oa.org_code asc " ;
|
|
List<String> orgIds = this.findBySql(sql, CollectionUtils.newList(currOrgId));
|
String hql = " from MediaVideoReCourse where videoId = :videoId and deleteFlag is false and orgId in (:orgIds)";
|
Map<String,Object> map = new HashMap<String, Object>();
|
map.put("videoId", videoId);
|
map.put("orgIds", orgIds.toArray());
|
List<MediaVideoReCourse> lstMvr = findByComplexHql(hql, map, MediaVideoReCourse.class);
|
|
for (MediaVideoReCourse mediaVideoReCourse : lstMvr) {
|
TraceUtils.setUpdateTrace(mediaVideoReCourse);
|
mediaVideoReCourse.setDeleteFlag(true);
|
save(mediaVideoReCourse);
|
}
|
|
MediaVideo video = read(MediaVideo.class, videoId);
|
// 班主任层面视频指定过后都是new 出来的,通过originVideoId 可以查出所有指定过去的视频
|
hql = "select classId from ClsClass where orgId in (:orgIds) and deleteFlag is false";
|
map = new HashMap<String, Object>();
|
map.put("orgIds", orgIds.toArray());
|
List<String> clsIds = findByComplexHql(hql, map, String.class);
|
if(!clsIds.isEmpty()){
|
hql = " from MediaVideo where originVideoId = :originVideoId and deleteFlag is false and videoId !=originVideoId and classId in (:classIds)";
|
map = new HashMap<String, Object>();
|
map.put("originVideoId", video.getOriginVideoId());
|
map.put("classIds", clsIds.toArray());
|
List<MediaVideo> videos = findByComplexHql(hql, map, MediaVideo.class);
|
for (MediaVideo mediaVideo : videos) {
|
TraceUtils.setUpdateTrace(mediaVideo);
|
mediaVideo.setDeleteFlag(true);
|
|
this.mediaVideoService.saveVideo(mediaVideo);
|
}
|
}
|
|
}
|
|
/**
|
* 删除需要回撤的视频
|
*
|
* @param videoId
|
* @param orgIds
|
* @param classIds
|
* @return
|
*/
|
private Result deleteAppoint(String videoId, String orgIds[], String classIds[]) {
|
Map<String, Object> args = new HashMap<String, Object>();
|
// 删除需要回撤的机构视频
|
if (orgIds.length != 0) {
|
|
String hql = " from MediaVideoReCourse where videoId = :videoId and deleteFlag is false and orgId in (:orgIds) and orgId != :currOrgId";
|
|
args.put("videoId", videoId);
|
args.put("orgIds", orgIds);
|
args.put("currOrgId", ClientUtils.getOrgId());
|
List<MediaVideoReCourse> courses = findByComplexHql(hql, args, MediaVideoReCourse.class);
|
for (MediaVideoReCourse mediaVideoReCourse : courses) {
|
TraceUtils.setUpdateTrace(mediaVideoReCourse);
|
mediaVideoReCourse.setDeleteFlag(true);
|
save(mediaVideoReCourse);
|
|
this.courseWareService.deleteOrgCourseware(mediaVideoReCourse.getVideoId(), mediaVideoReCourse.getOrgId());
|
}
|
}
|
|
// 删除需要回撤的班主任视频
|
if (classIds.length != 0) {
|
args = new HashMap<String, Object>();
|
args.put("videoId", videoId);
|
args.put("classIds", classIds);
|
String hql = " from MediaVideo where originVideoId = :videoId and deleteFlag is false and classId in (:classIds)";
|
List<MediaVideo> videos = findByComplexHql(hql, args, MediaVideo.class);
|
for (MediaVideo mediaVideo : videos) {
|
TraceUtils.setUpdateTrace(mediaVideo);
|
mediaVideo.setDeleteFlag(true);
|
|
this.mediaVideoService.saveVideo(mediaVideo);
|
}
|
|
}
|
|
return new Result(true);
|
}
|
|
/**
|
* 课程表列表
|
*
|
* @return
|
*/
|
public List<SchClassSchedule> queryLessonList(Date monthFirst, Date monthLast) {
|
|
return queryLessonList(ClientUtils.getClassId(), monthFirst, monthLast);
|
|
}
|
|
@Override
|
public List<SchClassSchedule> queryAppLessonList(final String hql, final Pager page, final List<Object> args) {
|
return lessonDAO.queryAppLessonList(hql, page, args);
|
}
|
|
@Override
|
public List<SchClassSchedule> queryLessonList(String classId, Date monthFirst, Date monthLast) {
|
|
String sql = " select s.class_schedule_id as classScheduleId ,s.name, s.content, "
|
+ " s.teacher,s.address,s.start_time as startTime, s.end_time as endTime,s.status "
|
+ " from sch_class_schedule s where s.delete_flag = 0 and s.class_id = ? ";
|
|
List<Object> arrs = new ArrayList<Object>();
|
arrs.add(classId);
|
if (monthFirst != null && monthLast != null) {
|
sql = sql.concat("and s.start_time >= ? and s.start_time <= ?");
|
arrs.add(monthFirst);
|
arrs.add(monthLast);
|
}
|
sql = sql.concat(" order by s.create_time desc ");
|
|
return lessonDAO.queryLessonList(sql, arrs);
|
}
|
|
@Override
|
public List<String> queryClassesByTeacher(String orgTeacherId) {
|
return lessonDAO.queryClassesByTeacher(orgTeacherId);
|
}
|
|
/**
|
* 根据直播查询讲师
|
*
|
* @param orgTeacherId
|
* @return
|
*/
|
public List<String> queryClassesByLive(String orgTeacherId) {
|
return lessonDAO.queryClassesByLive(orgTeacherId);
|
}
|
|
/**
|
* 分享课程页面的全部课程表
|
*
|
* @param classId
|
* @return
|
*/
|
@Override
|
public Result queryScheduleList(String classId, ModelAndView mv, ClsClass cls) {
|
String hql = " from SchClassSchedule where deleteFlag is false and classId = ? order by startTime";
|
List<SchClassSchedule> classScheduleLst = find(hql, CollectionUtils.newList(classId), SchClassSchedule.class);
|
|
// 组装课表信息内容
|
Map<String, Object> nowLesson = new HashMap<String, Object>(5);
|
nowLesson.put("beginWeek", "");
|
nowLesson.put("lessonCount", classScheduleLst.size());
|
nowLesson.put("startTime", cls.getStartTime());
|
nowLesson.put("endTime", cls.getEndTime());
|
|
if (!classScheduleLst.isEmpty()) {
|
// 班级开始时间在课程开始时间之后
|
if (cls.getStartTime().compareTo(classScheduleLst.get(0).getStartTime()) > 0) {
|
nowLesson.put("startTime", classScheduleLst.get(0).getStartTime());
|
}
|
// 班级结束时间在课程结束时间之前
|
if (cls.getEndTime().compareTo(classScheduleLst.get(classScheduleLst.size() - 1).getEndTime()) < 0) {
|
nowLesson.put("endTime", classScheduleLst.get(classScheduleLst.size() - 1).getEndTime());
|
}
|
}
|
|
List<Map<String, Object>> lstMap = new ArrayList<Map<String, Object>>();
|
Map<String, Object> map = null;
|
int index = 0;
|
int faceToface = 0;
|
int newwork = 0;
|
|
for (SchClassSchedule schedule : classScheduleLst) {
|
if(SchClassSchedule.SCH_NETWORK.equals(schedule.getMode())){
|
newwork++;
|
}else{
|
faceToface ++;
|
}
|
map = new HashMap<String, Object>(6);
|
map.put("name", schedule.getName());
|
map.put("startTime", schedule.getStartTime());
|
map.put("endTime", schedule.getEndTime());
|
map.put("address", schedule.getAddress());
|
map.put("teacher", schedule.getTeacher());
|
map.put("mode", schedule.getMode());
|
|
if (new Date().compareTo(schedule.getEndTime()) > 0) { // 当前时间在结束时间之后 - 已经上过的课
|
|
map.put("classStyle", "go-out");
|
} else { // 正在上或还没上的课
|
if (index == 0) { // 正在上的课
|
map.put("classStyle", "now");
|
index++;
|
|
// 组装课表信息内容
|
Calendar cal = Calendar.getInstance();
|
cal.setTime(schedule.getStartTime());
|
int begin_week = cal.get(Calendar.DAY_OF_WEEK);
|
String str_begin_week = DateTimeUtils.getWeek(begin_week);
|
nowLesson.put("beginWeek", str_begin_week);
|
nowLesson.put("beginTime", schedule.getStartTime());
|
|
} else { // 还没上的课
|
map.put("classStyle", "future");
|
}
|
}
|
lstMap.add(map);
|
}
|
mv.addObject("nowLesson", nowLesson);
|
mv.addObject("lessons", lstMap);
|
mv.addObject("mode", newwork>0&&faceToface>0?"线上、线下":newwork>0&&faceToface==0?"线上":"线下");
|
return new Result(true);
|
}
|
}
|