From 0ad2f07a292895eeb3b9618eb1e275568c63a59e Mon Sep 17 00:00:00 2001 From: EricsHu <hrr145632> Date: 星期五, 24 十一月 2023 18:09:23 +0800 Subject: [PATCH] 优化直播、添加班级 --- src/main/java/com/qxueyou/scc/teach/live/service/impl/MediaLiveService.java | 246 ++++++++++++++++++++++++++++-------------------- 1 files changed, 144 insertions(+), 102 deletions(-) diff --git a/src/main/java/com/qxueyou/scc/teach/live/service/impl/MediaLiveService.java b/src/main/java/com/qxueyou/scc/teach/live/service/impl/MediaLiveService.java index 4bcd977..07e2c27 100644 --- a/src/main/java/com/qxueyou/scc/teach/live/service/impl/MediaLiveService.java +++ b/src/main/java/com/qxueyou/scc/teach/live/service/impl/MediaLiveService.java @@ -7,6 +7,7 @@ import java.util.List; import java.util.Map; +import com.qxueyou.scc.sdk.MTCloud; import io.swagger.models.auth.In; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -34,29 +35,29 @@ @Service public class MediaLiveService extends CommonAppService implements IMediaLiveService { - + @Autowired MediaLiveDAO liveDao; - + @Autowired SccConfig cfg; - + @Autowired IMsgInfoService msgInfoService; - + @Autowired ICacheService cacheService; - + @Autowired private ITeacherService teacherService; - - + + @Override public Result add(String name, String content, String teacherId, String teacherName , String subjectId, String subjectName, - String definition, String imgPath, Date startTime, Date endTime, Integer courseId, boolean record, List<String> classIds) { - + String definition, String imgPath, Date startTime, Date endTime, Integer courseId, boolean record, List<String> classIds,String portalStatus) { + UserTeacher teacher = teacherService.getTeacherByUserId(ClientUtils.getUserId()); - + MediaVideoLive live = new MediaVideoLive(); TraceUtils.setCreateTrace(live); @@ -66,8 +67,9 @@ live.setPreviewImgUrl(imgPath); live.setStartTime(startTime); live.setEndTime(endTime); + live.setPortalStatus(portalStatus); live.setStatus(MediaVideoLive.STATUS_LIVE_DRAFT); - + if(teacher!=null){ live.setAnchorId(teacher.getTeacherId()); live.setAnchor(teacher.getName()); @@ -75,31 +77,32 @@ live.setAnchorId(ClientUtils.getUserId()); live.setAnchor(ClientUtils.getUserName()); } - + live.setSubjectId(subjectId); live.setSubjectName(subjectName); - + live.setCreateId(teacher.getTeacherId()); + live.setCreateTime(new Date()); String uuid = UUIDUtils.UUID(); live.setWyLiveNumber(uuid); live.setPushUrl(cfg.getRtmpService().concat(uuid)); live.setHlsPullUrl(cfg.getHlsService().concat(uuid).concat(".m3u8")); - + save(live); - + //淇濆瓨鐩存挱鏉冮檺鐝骇 if(classIds!=null && classIds.size()>0){ this.doClearAndAddLiveReClass(live.getVideoLiveId(), classIds.toArray(new String[classIds.size()])); } - + return new Result(true,"",CollectionUtils.newObjectMap("videoLiveId",live.getVideoLiveId())); } @Override public Result update(String liveId, String name, String content,String teacherId,String teacherName , String subjectId,String subjectName, - String definition,String imgPath, Date startTime, Date endTime,boolean record, List<String> classIds) { + String definition,String imgPath, Date startTime, Date endTime,boolean record, List<String> classIds) { MediaVideoLive live = read(MediaVideoLive.class,liveId); TraceUtils.setUpdateTrace(live); - + live.setName(name); live.setRemark(content); live.setPreviewImgUrl(imgPath); @@ -107,18 +110,18 @@ live.setEndTime(endTime); live.setSubjectId(subjectId); live.setSubjectName(subjectName); - + live.setCreateTime(new Date()); save(live); - + //鏇存柊鐝骇璇剧▼鍏宠仈鍏崇郴 this.doClearAndAddLiveReClass(live.getVideoLiveId(), classIds!=null?classIds.toArray(new String[classIds.size()]):null); - - + + // liveDao.saveLiveClasses(liveId, classIds); - + return Result.SUCCESS; } - + /** * 娓呯悊骞舵坊鍔犵洿鎾潈闄愮彮绾� * @param liveId @@ -126,22 +129,22 @@ */ private void doClearAndAddLiveReClass(String liveId, String [] classIds) { List<String> reIdLst = this.find("select r.liveReClassId from MediaVideoLiveReClass r where r.liveId=?", - CollectionUtils.newList(liveId), String.class); + CollectionUtils.newList(liveId), String.class); //鍒犻櫎鍏宠仈鍏崇郴 if(reIdLst!=null && reIdLst.size()>0){ - this.bulkUpdateInLoop("delete from MediaVideoLiveReClass where liveReClassId=?", reIdLst.toArray()); + this.bulkUpdateInLoop("delete from MediaVideoLiveReClass where liveReClassId=?", reIdLst.toArray()); } if(classIds!=null && classIds.length>0){ for(String classId:classIds){ MediaVideoLiveReClass re = new MediaVideoLiveReClass(); - TraceUtils.setCreateTrace(re); - re.setClassId(classId); - re.setLiveId(liveId); - save(re); + TraceUtils.setCreateTrace(re); + re.setClassId(classId); + re.setLiveId(liveId); + save(re); } } - } + } @Override public List<String> getLiveClasses(String liveId) { @@ -157,14 +160,19 @@ save(live); return Result.SUCCESS; } - + @Override - public Result delete(String[] liveIds) { + public Result delete(String[] liveIds,String [] courseIds) throws Exception { for(String liveId:liveIds) { delete(liveId); + for(String courseId:courseIds) { + MTCloud client = new MTCloud(); + String s = client.courseDelete(courseId); + } } return Result.SUCCESS; } + @Override public Result doIssue(String liveId) { @@ -172,54 +180,54 @@ doSendMsg(liveId,MsgInfo.TYPE_LIVE,"鍙戝竷浜嗙洿鎾�"); return new Result(true); } - + private void doSendMsg(String liveId,short type,String msg){ MediaVideoLive liveInfo = this.read(liveId); //鏌ヨ鐩存挱鍏宠仈鐨勭彮绾� String hql = "select s.userId from MediaVideoLiveReClass m,StuStudent s where m.classId=s.classId and m.liveId=? and m.deleteFlag is false and s.deleteFlag is false"; - + List<String> lstUserIds = this.find(hql, CollectionUtils.newList(liveId),String.class); - + if(lstUserIds!=null && lstUserIds.size()>0){ Map<String,String> attrs = CollectionUtils.newStringMap("liveId",liveId,"liveName",liveInfo.getName(),"subjectId",liveInfo.getSubjectId(), "subjectName",liveInfo.getSubjectName(),"startTime",String.valueOf(liveInfo.getStartTime().getTime())); - + msgInfoService.doSendTextMsgToUsers(lstUserIds.toArray(new String[lstUserIds.size()]),type,msg,attrs); } } - - @Scheduled(cron = " 0 0/5 * * * ?") - protected void doTimer() { -// System.out.println("鎵ц鐩存挱鎻愰啋瀹氭椂鍣�"); - Calendar cal = Calendar.getInstance(); - cal.add(Calendar.HOUR, 1); - Date beginDate = cal.getTime(); - - cal.add(Calendar.MINUTE, 5); - Date endDate = cal.getTime(); - //鏌ヨ1灏忔椂鍐呭皢寮�濮嬬殑鐩存挱 - List<MediaVideoLive> lstLives = this.find("from MediaVideoLive where startTime>=? and startTime<? and status=? and deleteFlag is false ", - CollectionUtils.newList(beginDate,endDate,MediaVideoLive.STATUS_LIVE_REVIEW), MediaVideoLive.class); - - if(lstLives!=null && lstLives.size()>0){ - for(MediaVideoLive live:lstLives){ - this.doLiveRemindMsg(live.getVideoLiveId(),MsgInfo.TYPE_REMIND, "鐩存挱椹笂寮�濮嬩簡锛岃鍋氬ソ鐩存挱鍑嗗"); - } - } - } - +// @Scheduled(cron = " 0 0/5 * * * ?") +// protected void doTimer() { +//// System.out.println("鎵ц鐩存挱鎻愰啋瀹氭椂鍣�"); +// Calendar cal = Calendar.getInstance(); +// cal.add(Calendar.HOUR, 1); +// Date beginDate = cal.getTime(); +// +// cal.add(Calendar.MINUTE, 5); +// Date endDate = cal.getTime(); +// +// //鏌ヨ1灏忔椂鍐呭皢寮�濮嬬殑鐩存挱 +// List<MediaVideoLive> lstLives = this.find("from MediaVideoLive where startTime>=? and startTime<? and status=? and deleteFlag is false ", +// CollectionUtils.newList(beginDate,endDate,MediaVideoLive.STATUS_LIVE_REVIEW), MediaVideoLive.class); +// +// if(lstLives!=null && lstLives.size()>0){ +// for(MediaVideoLive live:lstLives){ +// this.doLiveRemindMsg(live.getVideoLiveId(),MsgInfo.TYPE_REMIND, "鐩存挱椹笂寮�濮嬩簡锛岃鍋氬ソ鐩存挱鍑嗗"); +// } +// } +// } + private void doLiveRemindMsg(String liveId,short type,String msg){ MediaVideoLive liveInfo = this.read(liveId); Map<String,String> attrs = CollectionUtils.newStringMap("liveId",liveId, - "liveName",liveInfo.getName(), - "remindType","live", - "status",String.valueOf(liveInfo.getStatus()), - "subjectId",liveInfo.getSubjectId(), - "subjectName",liveInfo.getSubjectName(), - "startTime",String.valueOf(liveInfo.getStartTime().getTime()), - "endTime",String.valueOf(liveInfo.getEndTime().getTime())); - + "liveName",liveInfo.getName(), + "remindType","live", + "status",String.valueOf(liveInfo.getStatus()), + "subjectId",liveInfo.getSubjectId(), + "subjectName",liveInfo.getSubjectName(), + "startTime",String.valueOf(liveInfo.getStartTime().getTime()), + "endTime",String.valueOf(liveInfo.getEndTime().getTime())); + msgInfoService.doSendTextMsgToUsers(new String[]{liveInfo.getCreateId()},type,msg,attrs); } @@ -242,11 +250,11 @@ public Result doStop(String liveId) { //鍙戦�佺敓鎴愬洖鏀炬秷鎭� cacheService.lstRightPush(MediaVideoLivePlayBackService.LIVE_PLAYBACK_LST, liveId); - + return status(liveId,MediaVideoLive.STATUS_LIVE_DOWNLOAD); - + } - + private Result status(String liveId,short status) { MediaVideoLive live = read(MediaVideoLive.class,liveId); TraceUtils.setUpdateTrace(live); @@ -265,9 +273,9 @@ StringBuffer hql = new StringBuffer(1000); Map<String,Object> params = new HashMap<String,Object>(); hql.append("from MediaVideoLive m left join fetch m.classes c left join fetch m.subject s where m.deleteFlag is false and m.name like :name "); - + params.put("name",keyword + "%"); - + if(classIds!=null && classIds.length>0){ hql.append(" and (c.classId in(:classIds) or s.type=:Type)"); params.put("classIds", classIds); @@ -276,12 +284,12 @@ hql.append(" and s.type=:subjectType"); params.put("subjectType", Subject.TYPE_PUBLIC_SUBJECT); } - + if(!StringUtils.isEmpty(subjectId)){ - hql.append(" and m.subjectId=:subjectId"); - params.put("subjectId", subjectId); + hql.append(" and m.subjectId=:subjectId"); + params.put("subjectId", subjectId); } - + if(status!=null){ hql.append(" and m.status=:status"); params.put("status", status); @@ -289,24 +297,24 @@ hql.append(" and m.status!=:status"); params.put("status",MediaVideoLive.STATUS_LIVE_DRAFT); } - + hql.append(" order by m.createTime desc"); - + return this.findByComplexHql(hql.toString(),new Pager(pageSize,pageNum),params,MediaVideoLive.class); - } - + } + @Override public int listCount(String keyword,String [] classIds,String subjectId,Short status) { StringBuffer hql = new StringBuffer(1000); Map<String,Object> params = new HashMap<String,Object>(); hql.append("from MediaVideoLive m left join m.subject s where m.deleteFlag is false and m.name like :name "); params.put("name","%" + keyword + "%"); - + if(!StringUtils.isEmpty(subjectId)){ - hql.append(" and m.subjectId=:subjectId"); - params.put("subjectId", subjectId); + hql.append(" and m.subjectId=:subjectId"); + params.put("subjectId", subjectId); } - + if(status!=null){ hql.append(" and m.status=:status"); params.put("status", status); @@ -314,30 +322,57 @@ hql.append(" and m.status!=:status"); params.put("status",MediaVideoLive.STATUS_LIVE_DRAFT); } - + if(classIds!=null && classIds.length>0){ - hql.append(" and ( exists (select 1 from MediaVideoLiveReClass r where r.deleteFlag is false and r.liveId= m.videoLiveId and r.classId in (:classIds) ) or s.type=:subjectType )"); - params.put("classIds", classIds); - params.put("subjectType", Subject.TYPE_PUBLIC_SUBJECT); + hql.append(" and ( exists (select 1 from MediaVideoLiveReClass r where r.deleteFlag is false and r.liveId= m.videoLiveId and r.classId in (:classIds) ) or s.type=:subjectType )"); + params.put("classIds", classIds); + params.put("subjectType", Subject.TYPE_PUBLIC_SUBJECT); }else{ - hql.append(" and s.type=:subjectType "); - params.put("subjectType", Subject.TYPE_PUBLIC_SUBJECT); + hql.append(" and s.type=:subjectType "); + params.put("subjectType", Subject.TYPE_PUBLIC_SUBJECT); } - + return this.findCountByComplexHql(hql.toString(), params); } - - @Override - public List<MediaVideoLive> listOfMine(String keyword, Integer pageNum, Integer pageSize) { - - String hql = "from MediaVideoLive where deleteFlag is false and name like ? and createId=? order by createTime desc"; - return findList(hql, new Pager(pageSize, pageNum), CollectionUtils.newList(keyword + "%",ClientUtils.getUserId()), MediaVideoLive.class); + @Override + public List<MediaVideoLive> listvideo(String status) { + //鏄惁鏄�佸笀 + String teacherId = ClientUtils.isAdmin() ? null : teacherService.getTeacherIdByUserId(ClientUtils.getUserId()); + String hql = "from MediaVideoLive where deleteFlag is false and status=? "; + List<Object> args =CollectionUtils.newList(status); + if (StringUtils.isNotBlank(teacherId)) { + hql.concat(" and createId=?"); + args.add(teacherId); + } + hql.concat(" order by createTime desc"); + + + + return find(hql, args, MediaVideoLive.class); } - + + @Override + public List<MediaVideoLive> listOfMine(String keyword,String portalStatus, Integer pageNum, Integer pageSize) { + //鏄惁鏄�佸笀 + String teacherId = ClientUtils.isAdmin() ? null : teacherService.getTeacherIdByUserId(ClientUtils.getUserId()); + StringBuffer hql = new StringBuffer("from MediaVideoLive where deleteFlag is false and name like ? "); + List<Object> args =CollectionUtils.newList(keyword + "%"); + if(portalStatus != ""){ + hql.append(" and portalStatus = ?"); + args.add(portalStatus); + } + if (StringUtils.isNotBlank(teacherId)) { + hql.append(" and createId=?"); + args.add(teacherId); + } + hql.append(" order by createTime desc"); + return findList(hql.toString(), new Pager(pageSize, pageNum),args , MediaVideoLive.class); + } + @Override public int listCountOfMine(String keyword) { - + String hql = "from MediaVideoLive where deleteFlag is false and name like ? and createId=? order by createTime desc"; return findCount(hql, CollectionUtils.newList(keyword + "%",ClientUtils.getUserId())); @@ -347,20 +382,27 @@ public MediaVideoLive read(String liveId) { return read(MediaVideoLive.class,liveId); } - + + @Override + public MediaVideoLive revamp(int courseId) { + String hql = "from MediaVideoLive where deleteFlag is false and courseId=?"; + MediaVideoLive unique = findUnique(hql, CollectionUtils.newList(courseId), MediaVideoLive.class); + return unique ; + } + @SuppressWarnings("unchecked") @Override public List<MediaVideoLive> readByStatus(List<String> liveIdLst,short[] status) { - + if(liveIdLst.isEmpty()) { return Collections.EMPTY_LIST; } - + Object[] _status = new Object[status.length]; for(int i=0;i<status.length;i++) { _status[i]=status[i]; } - + String hql = "from MediaVideoLive where deleteFlag is false and videoLiveId in (:liveId) and status in (:status)"; return findByComplexHql(hql, CollectionUtils.newObjectMap("liveId",liveIdLst,"status",_status), MediaVideoLive.class); } -- Gitblit v1.8.0