Forráskód Böngészése

Merge branch 'feature/0529-live' of http://git.dayaedu.com/yonge/mec into feature/0529-live

liujc 2 éve
szülő
commit
8accebfdca

+ 63 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/impl/CourseScheduleServiceImpl.java

@@ -5,6 +5,9 @@ import com.alibaba.fastjson.JSONObject;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.microsvc.toolkit.middleware.live.LivePluginContext;
+import com.microsvc.toolkit.middleware.live.LivePluginService;
+import com.microsvc.toolkit.middleware.live.message.LiveRoomMessage;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dao.*;
 import com.ym.mec.biz.dal.dto.*;
@@ -195,7 +198,8 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
     private LessonExaminationService lessonExaminationService;
 	@Autowired
 	private ImLiveBroadcastRoomService imLiveBroadcastRoomService;
-
+	@Autowired
+	private LivePluginContext livePluginContext;
     @Autowired
     private ImLiveRoomVideoService imLiveRoomVideoService;
 
@@ -3032,6 +3036,7 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
 
 		Map<Long, CourseSchedule> oldCourseScheduleMap = oldCourseScheduleList.stream().collect(Collectors.toMap(CourseSchedule::getId, c -> c));
 
+		List<CourseSchedule> liveCourseSchedules = Lists.newArrayList();
         for(CourseSchedule newCourseSchedule : newCourseSchedules){
 
         	//获取数据库中的记录
@@ -3087,6 +3092,17 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
 				}
 			}
 
+			// 直播课发送推送消息
+			if (LIVE.equals(oldCourseSchedule.getGroupType()) && StringUtils.isNotBlank(oldCourseSchedule.getLiveRoomId())) {
+				// 日期,时间,时长,主教老师不一致时,发送消息
+				if (newCourseSchedule.getClassDate() != oldCourseSchedule.getClassDate()
+						|| newCourseSchedule.getStartClassTime() != oldCourseSchedule.getStartClassTime()
+						|| newCourseSchedule.getEndClassTime() != oldCourseSchedule.getEndClassTime()
+						|| newCourseSchedule.getActualTeacherId() != oldCourseSchedule.getActualTeacherId().intValue()) {
+					liveCourseSchedules.add(oldCourseSchedule);
+				}
+			}
+
             if(!CollectionUtils.isEmpty(newCourseSchedule.getTeachingTeacherIdList())){
                 if (newCourseSchedule.getTeachingTeacherIdList().contains(newCourseSchedule.getActualTeacherId())){
                     throw new BizException("主教和助教不可重复");
@@ -3529,6 +3545,46 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
 		} catch (Exception e) {
 			e.printStackTrace();
 		}
+
+		// 直播课消息推送
+		if (CollectionUtils.isNotEmpty(liveCourseSchedules)) {
+
+			liveCourseSchedules.parallelStream().forEach(item -> {
+
+				ImLiveBroadcastRoom liveRoom = imLiveBroadcastRoomService.getByRoomUid(item.getLiveRoomId());
+				if (Objects.isNull(liveRoom)) {
+					log.warn("liveRoom is null, liveRoomId:{}", item.getLiveRoomId());
+					return;
+				}
+
+				try {
+					LivePluginService pluginService = livePluginContext.getPluginService(liveRoom.getServiceProvider());
+
+					LiveRoomMessage message = new LiveRoomMessage();
+					message.setIsIncludeSender(1);
+					message.setFromUserId(item.getActualTeacherId().toString());
+					message.setToChatRoomId(item.getLiveRoomId());
+					message.setObjectName(LiveRoomMessage.LIVE_STATUS_CHANGE);
+
+					// 发送用户信息
+					LiveRoomMessage.MessageUser messageUser = LiveRoomMessage.MessageUser.builder()
+							.sendUserId("")
+							.sendUserName("")
+							.avatarUrl("")
+							.build();
+
+					message.setContent(LiveRoomMessage.MessageContent.builder()
+							.reason("课程信息已变更")
+							.targetIds(Lists.newArrayList())
+							.sendUserInfo(messageUser).build());
+
+					pluginService.sendChatRoomMessage(message);
+				} catch (Exception e) {
+					log.error("liveRoom error", e);
+				}
+			});
+
+		}
 		return BaseController.succeed();
     }
 
@@ -6218,7 +6274,12 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
 		}
 
 		// 定时任务更新课程状态为进行中,判断当前课程状态是否匹配
-		if (CourseStatusEnum.NOT_START == courseSchedule.getStatus()) {
+		int studentRemindTime = Integer.parseInt(sysConfigService.findByParamName(SysConfigService.LIVE_CLASS_START_REMIND_TIME).getParanValue());
+
+		Date date = DateUtil.startDateAndEndTime(courseSchedule.getClassDate(), courseSchedule.getStartClassTime());
+		date = DateUtil.addMinutes(date, -studentRemindTime);
+		// 课程是否开始
+		if(CourseStatusEnum.NOT_START.equals(courseSchedule.getStatus()) && date.after(new Date())) {
 			throw new BizException("直播课暂未开启,请稍后重试");
 		}
 		if (CourseStatusEnum.OVER == courseSchedule.getStatus()) {

+ 8 - 1
mec-im/src/main/java/com/ym/service/Impl/RoomServiceImpl.java

@@ -130,6 +130,8 @@ public class RoomServiceImpl implements RoomService {
     private VipGroupDao vipGroupDao;
     @Autowired
     private ImLiveBroadcastRoomService imLiveBroadcastRoomService;
+    @Autowired
+    private SysConfigService sysConfigService;
 
     @Override
     public Integer getCurrentCourseId(String roomId) {
@@ -277,7 +279,12 @@ public class RoomServiceImpl implements RoomService {
             }
 
             // 直播课已结束
-            if (CourseStatusEnum.NOT_START == courseSchedule.getStatus()) {
+            int studentRemindTime = Integer.parseInt(sysConfigService.findByParamName(SysConfigService.LIVE_CLASS_START_REMIND_TIME).getParanValue());
+
+            Date date = DateUtil.startDateAndEndTime(courseSchedule.getClassDate(), courseSchedule.getStartClassTime());
+            date = DateUtil.addMinutes(date, -studentRemindTime);
+            // 课程是否开始
+            if(CourseStatusEnum.NOT_START.equals(courseSchedule.getStatus()) && date.after(new Date())) {
                 throw new BizException("直播课未开始");
             }
 

+ 9 - 0
mec-web/src/main/java/com/ym/mec/web/controller/CourseScheduleController.java

@@ -186,6 +186,15 @@ public class CourseScheduleController extends BaseController {
                     &&!VipGroupStatusEnum.FINISHED.equals(vipGroup.getStatus())){
                 throw new BizException("非进行中课程组不允许进行此操作");
             }
+
+            // 直播课
+            if (GroupType.LIVE.equals(oldCourseSchedule.getGroupType())
+                    && org.apache.commons.lang3.StringUtils.isNotBlank(oldCourseSchedule.getLiveRoomId())) {
+                // 重置连堂课,关联直播间,消息推送状态
+                courseSchedule.setLiveRemind(0);
+                courseSchedule.setContinuousCourse(false);
+                courseSchedule.setLiveRoomId("");
+            }
         }
         if(Objects.isNull(courseSchedule.getClassGroupId())){
             courseSchedule.setClassGroupId(oldCourseSchedule.getClassGroupId());