From 961da40d1eb3c6f70c3f762194085a09c39e57dd Mon Sep 17 00:00:00 2001
From: yn147 <2270338776@qq.com>
Date: 星期四, 26 十月 2023 16:36:13 +0800
Subject: [PATCH] 公开直播
---
src/main/java/com/qxueyou/scc/teach/live/service/impl/MediaLiveService.java | 166 ++++++++++++++++++++++++++++---------------------------
1 files changed, 85 insertions(+), 81 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 0c9195f..da26763 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
@@ -35,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 portalStatus) {
-
+
UserTeacher teacher = teacherService.getTeacherByUserId(ClientUtils.getUserId());
-
+
MediaVideoLive live = new MediaVideoLive();
TraceUtils.setCreateTrace(live);
@@ -69,7 +69,7 @@
live.setEndTime(endTime);
live.setPortalStatus(portalStatus);
live.setStatus(MediaVideoLive.STATUS_LIVE_DRAFT);
-
+
if(teacher!=null){
live.setAnchorId(teacher.getTeacherId());
live.setAnchor(teacher.getName());
@@ -77,31 +77,31 @@
live.setAnchorId(ClientUtils.getUserId());
live.setAnchor(ClientUtils.getUserName());
}
-
+
live.setSubjectId(subjectId);
live.setSubjectName(subjectName);
-
+
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);
@@ -109,18 +109,18 @@
live.setEndTime(endTime);
live.setSubjectId(subjectId);
live.setSubjectName(subjectName);
-
+
save(live);
-
+
//鏇存柊鐝骇璇剧▼鍏宠仈鍏崇郴
this.doClearAndAddLiveReClass(live.getVideoLiveId(), classIds!=null?classIds.toArray(new String[classIds.size()]):null);
-
-
+
+
// liveDao.saveLiveClasses(liveId, classIds);
-
+
return Result.SUCCESS;
}
-
+
/**
* 娓呯悊骞舵坊鍔犵洿鎾潈闄愮彮绾�
* @param liveId
@@ -128,22 +128,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) {
@@ -179,54 +179,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);
-
+ 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);
}
@@ -249,11 +249,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);
@@ -272,9 +272,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);
@@ -283,12 +283,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);
@@ -296,24 +296,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);
@@ -321,16 +321,16 @@
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);
}
@@ -345,16 +345,20 @@
@Override
public List<MediaVideoLive> listOfMine(String keyword,String portalStatus, Integer pageNum, Integer pageSize) {
-
- String hql = "from MediaVideoLive where deleteFlag is false and name like ? and portalStatus = ? order by createTime desc";
-
- return findList(hql, new Pager(pageSize, pageNum), CollectionUtils.newList(keyword + "%",portalStatus), MediaVideoLive.class);
+ 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);
+ }
+ 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()));
@@ -375,16 +379,16 @@
@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