Преглед на файлове

Merge branch 'local/1103_rtc' into test

liujc преди 1 година
родител
ревизия
1c8b78d51e

+ 12 - 1
cooleshow-app/src/main/java/com/yonge/cooleshow/admin/task/TaskController.java

@@ -6,6 +6,7 @@ import com.yonge.cooleshow.common.constant.SysConfigConstant;
 import com.yonge.cooleshow.common.controller.BaseController;
 import com.yonge.cooleshow.common.entity.HttpResponseResult;
 import com.yonge.toolset.utils.date.DateUtil;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.redisson.api.RBucket;
@@ -30,6 +31,7 @@ import java.util.Date;
 @RestController
 @RequestMapping("${app-config.url.admin:}/task")
 @ApiIgnore
+@Slf4j
 public class TaskController extends BaseController {
     @Autowired
     private UserOrderService userOrderService;
@@ -199,8 +201,17 @@ public class TaskController extends BaseController {
     public HttpResponseResult<Object> destroyLiveRoom() {
 
         // 群发消息定时
-        liveRoomService.destroyLiveRoom();
+        try {
+            liveRoomService.destroyLiveRoom();
+        } catch (Exception e) {
+            log.error("销毁直播间失败",e);
+        }
 
+        try {
+            courseScheduleService.destroyRtcRoom();
+        } catch (Exception e) {
+            log.error("销毁网络教室失败",e);
+        }
         return HttpResponseResult.succeed();
     }
 

+ 17 - 1
cooleshow-app/src/main/java/com/yonge/cooleshow/teacher/task/TaskController.java

@@ -5,6 +5,7 @@ import com.yonge.cooleshow.biz.dal.service.*;
 import com.yonge.cooleshow.common.controller.BaseController;
 import com.yonge.cooleshow.common.entity.HttpResponseResult;
 import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -20,6 +21,7 @@ import java.util.List;
 @RestController
 @RequestMapping("${app-config.url.teacher:}/task")
 @ApiIgnore
+@Slf4j
 public class TaskController extends BaseController {
     @Autowired
     private TeacherTotalService teacherTotalService;
@@ -33,6 +35,7 @@ public class TaskController extends BaseController {
     @Autowired
     private DivBackRecordService divBackRecordService;
 
+
     /***
      * 查询所有老师统计数据
      * @author liweifan
@@ -63,7 +66,20 @@ public class TaskController extends BaseController {
     @ApiOperation("定时任务-创建房间-直播间")
     @GetMapping("/createCourseLiveRoom")
     public void createCourseLiveRoom() {
-        liveRoomService.createCourseLiveRoom();
+        try {
+            liveRoomService.createCourseLiveRoom();
+
+        } catch (Exception e) {
+            log.error("定时任务-创建房间-直播间异常", e);
+        }
+        // 网络教室
+        try {
+
+            scheduleService.rtcRoomCreate();
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error("创建网络教室失败",e);
+        }
     }
 
     @GetMapping("/getRedisValueByKey")

+ 5 - 0
cooleshow-gateway/gateway-web/pom.xml

@@ -26,6 +26,11 @@
 			</dependency> -->
 
 		<dependency>
+			<groupId>com.plumelog</groupId>
+			<artifactId>plumelog-logback</artifactId>
+			<version>3.5.3</version>
+		</dependency>
+		<dependency>
 			<groupId>com.alibaba.cloud</groupId>
 			<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
 		</dependency>

+ 4 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/dao/CourseScheduleDao.java

@@ -250,4 +250,8 @@ public interface CourseScheduleDao extends BaseMapper<CourseSchedule> {
      */
     IPage<UserBindingCourseWrapper> selectBindingUserCoursePage(@Param(
             "page") IPage<UserBindingCourseWrapper> page, @Param("query") TeacherBindingUserQueryInfo.BindingStudentCourseQuery query);
+
+    List<CourseSchedule> getNotStartRtc(@Param("beforeTime") Integer beforeTime);
+
+    List<CourseSchedule> getEndTimeBetweenYesterdayAndNow();
 }

+ 6 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/entity/CourseSchedule.java

@@ -107,5 +107,11 @@ public class CourseSchedule implements Serializable {
     @TableField("cancel_mute_flag_")
     private Boolean cancelMuteFlag = true;
 
+
+    @ApiModelProperty(value = "标记")
+    @TableField("live_remind_")
+    private Integer liveRemind;
+
+
 }
 

+ 4 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/CourseScheduleService.java

@@ -275,5 +275,9 @@ public interface CourseScheduleService extends IService<CourseSchedule> {
      *
      */
     void buyPracticeCourse(UserPaymentOrderWrapper.OrderGoodsInfo orderGoodsInfo);
+
+    void rtcRoomCreate();
+
+    void destroyRtcRoom();
 }
 

+ 83 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/CourseScheduleServiceImpl.java

@@ -10,6 +10,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.google.common.collect.Lists;
+import com.microsvc.toolkit.middleware.rtc.RTCRoomPluginContext;
+import com.microsvc.toolkit.middleware.rtc.RTCRoomPluginService;
+import com.microsvc.toolkit.middleware.rtc.impl.TencentCloudRTCPlugin;
 import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
 import com.yonge.cooleshow.auth.api.entity.SysUser;
 import com.yonge.cooleshow.biz.dal.dao.*;
@@ -142,6 +145,8 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
     @Autowired
     private RedisCacheService redisCacheService;
 
+    @Autowired
+    private RTCRoomPluginContext rtcRoomPluginContext;
     @Override
     public CourseScheduleDao getDao() {
         return this.baseMapper;
@@ -2513,6 +2518,57 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
 
     }
 
+
+    @Override
+    public void rtcRoomCreate() {
+
+        //是否提前进入教室
+        String courseBeforeBufferTime = sysConfigService.findConfigValue(SysConfigConstant.PRE_CREATE_PRACTICE_ROOM_MINUTE);
+        if (StringUtils.isEmpty(courseBeforeBufferTime)) {
+            courseBeforeBufferTime = "5";
+        }
+        Integer beforeTime = Integer.parseInt(courseBeforeBufferTime) + 5;
+
+        List<CourseSchedule> scheduleList = baseMapper.getNotStartRtc(beforeTime);
+        if (CollectionUtils.isEmpty(scheduleList)) {
+            return;
+        }
+        for (CourseSchedule courseSchedule : scheduleList) {
+            try {
+                RTCRoomPluginService pluginService;
+                if (StringUtils.isBlank(courseSchedule.getServiceProvider())) {
+                    pluginService = rtcRoomPluginContext.getPluginService();
+                } else {
+                    pluginService = rtcRoomPluginContext.getPluginService(courseSchedule.getServiceProvider());
+                }
+                // 群组帐号注册
+                SysUser sysUser = getSysUser();
+                if (Objects.nonNull(sysUser)) {
+                    try {
+                        pluginService.register(courseSchedule.getTeacherId().toString(), sysUser.getRealName(), sysUser.getAvatar());
+                    } catch (Exception e) {
+                        log.error("直播房间群主注册失败: userId={}", courseSchedule.getTeacherId(), e);
+                    }
+                }
+
+                //记录用户实际选择的房间
+                String roomId = courseSchedule.getId().toString();
+
+                // 生成群组
+                pluginService.chatRoomCreate(roomId, roomId, courseSchedule.getTeacherId().toString());
+                this.lambdaUpdate()
+                    .eq(CourseSchedule::getId, courseSchedule.getId())
+                    .set(CourseSchedule::getLiveRemind,1)
+                    .update();
+            } catch (Exception e) {
+                log.error("创建rtc房间失败", e);
+            }
+        }
+
+
+    }
+
+
     private UserOrderDetail buyPracticeCourseTranV2(UserPaymentOrderWrapper.OrderGoodsInfo orderGoodsInfo) {
         log.info("buyPracticeCourse  param:{}", JSON.toJSONString(orderGoodsInfo));
         Long studentId = orderGoodsInfo.getUserId();
@@ -2651,4 +2707,31 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
 
         return liveRoomTime;
     }
+
+    @Override
+    public void destroyRtcRoom() {
+
+        // 查询结束时间在昨天到现在的课程
+        List<CourseSchedule> scheduleList = baseMapper.getEndTimeBetweenYesterdayAndNow();
+        if (CollectionUtils.isEmpty(scheduleList)) {
+            return;
+        }
+        for (CourseSchedule courseSchedule : scheduleList) {
+            try {
+                RTCRoomPluginService pluginService;
+                if (StringUtils.isBlank(courseSchedule.getServiceProvider())) {
+                    pluginService = rtcRoomPluginContext.getPluginService();
+                } else {
+                    pluginService = rtcRoomPluginContext.getPluginService(courseSchedule.getServiceProvider());
+                }
+                if (TencentCloudRTCPlugin.PLUGIN_NAME.equals(pluginService.pluginName())) {
+                    // 腾讯云群销毁
+                    String roomId = courseSchedule.getId().toString();
+                    pluginService.chatRoomDestroy(roomId);
+                }
+            } catch (Exception e) {
+                log.error("销毁rtc房间失败", e);
+            }
+        }
+    }
 }

+ 1 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/RoomServiceImpl.java

@@ -116,7 +116,7 @@ public class RoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNetworkRoom
         if (memberNum <= 1) {
             RTCRoomPluginService pluginService = rtcRoomPluginContext.getPluginService(serviceProvider);
             redisTemplate.delete("joinImGroup:" + roomId);
-            pluginService.chatRoomDestroy(roomId);
+//            pluginService.chatRoomDestroy(roomId);
             //删除房间
             this.removeById(room.getId());
             //删除房间用户

+ 15 - 0
cooleshow-user/user-biz/src/main/resources/config/mybatis/CourseScheduleMapper.xml

@@ -991,4 +991,19 @@
             and cssp.user_id_ =#{query.studentId}
         </where>
     </select>
+
+    <select id="getNotStartRtc" resultMap="BaseResultMap">
+
+            select * from course_schedule where status_ = 'NOT_START' and type_ in ('PRACTICE','PIANO_ROOM_CLASS')
+            and start_time_ &lt;= date_format(date_add(now(),interval #{beforeTime} minute),'%Y-%m-%d %H:%i:%s')
+
+            and live_remind_ = 0
+    </select>
+
+
+    <select id="getEndTimeBetweenYesterdayAndNow" resultMap="BaseResultMap">
+        select * from course_schedule where status_ = 'COMPLETE' and type_ in ('PRACTICE','PIANO_ROOM_CLASS')
+        and end_time_ &gt;= date_format(date_add(now(),interval -1 day),'%Y-%m-%d')
+        and end_time_&lt;= date_format(now(),'%Y-%m-%d %H:%i:%s')
+    </select>
 </mapper>