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 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 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 lstOrgIds0 = Arrays.asList(orgIds); List lstOrgIds = new ArrayList(); lstOrgIds.addAll(lstOrgIds0); lstOrgIds.add(ClientUtils.getOrgId()); Map videoOrgCourseMap = new HashMap(); Map args = new HashMap(); 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 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 videoOrgCourseMap){ Map args = new HashMap(); Map videoCourseMap = new HashMap(); String hql = " from MediaVideoReCourse where videoId in (:videoIds) and deleteFlag is false"; args.put("videoIds", videoIds); List 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 videoOrgCourseMap){ Map args = new HashMap(); List lstOriginVideoIds = new ArrayList(); List lstSubjectIds = new ArrayList(); Map videoMap = new HashMap(); Map originVideoMap = new HashMap(); Map origSubjectMap = new HashMap(); //Õ½Úid List lstCharpteIds = new ArrayList(); Map origChapterMap = new HashMap(); List keys = new ArrayList(); String hql = " from MediaVideo where videoId in (:videoIds) and deleteFlag is false"; args.put("videoIds", videoIds); List 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(); args.put("originVideoIds", lstOriginVideoIds.toArray()); args.put("classIds",classIds); List 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(); args.put("classIds", classIds); args.put("origSubjectIds", lstSubjectIds.toArray()); List subjects = findByComplexHql(hql, args, SchClassSubject.class); for (SchClassSubject schClassSubject : subjects) { origSubjectMap.put(schClassSubject.getClassId()+schClassSubject.getOrigSubjectId(), schClassSubject); } Map 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 lst = new ArrayList(); 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 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 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 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 orgIds = this.findBySql(sql, CollectionUtils.newList(currOrgId)); String hql = " from MediaVideoReCourse where videoId = :videoId and deleteFlag is false and orgId in (:orgIds)"; Map map = new HashMap(); map.put("videoId", videoId); map.put("orgIds", orgIds.toArray()); List 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(); map.put("orgIds", orgIds.toArray()); List 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(); map.put("originVideoId", video.getOriginVideoId()); map.put("classIds", clsIds.toArray()); List 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 args = new HashMap(); // ɾ³ýÐèÒª»Ø³·µÄ»ú¹¹ÊÓÆµ 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 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(); args.put("videoId", videoId); args.put("classIds", classIds); String hql = " from MediaVideo where originVideoId = :videoId and deleteFlag is false and classId in (:classIds)"; List 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 queryLessonList(Date monthFirst, Date monthLast) { return queryLessonList(ClientUtils.getClassId(), monthFirst, monthLast); } @Override public List queryAppLessonList(final String hql, final Pager page, final List args) { return lessonDAO.queryAppLessonList(hql, page, args); } @Override public List 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 arrs = new ArrayList(); 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 queryClassesByTeacher(String orgTeacherId) { return lessonDAO.queryClassesByTeacher(orgTeacherId); } /** * ¸ù¾ÝÖ±²¥²éѯ½²Ê¦ * * @param orgTeacherId * @return */ public List 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 classScheduleLst = find(hql, CollectionUtils.newList(classId), SchClassSchedule.class); // ×é×°¿Î±íÐÅÏ¢ÄÚÈÝ Map nowLesson = new HashMap(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> lstMap = new ArrayList>(); Map 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(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); } }