Browse Source

Merge remote-tracking branch 'origin/feature/1020-tencent-im' into feature/1020-tencent-im

Eric 1 year ago
parent
commit
af03a193cf

+ 28 - 2
mec-application/src/main/java/com/ym/mec/web/controller/TaskController.java

@@ -18,6 +18,7 @@ import com.ym.mec.im.ImFeignService;
 import com.ym.mec.util.date.DateUtil;
 import com.yonge.log.service.HistoryMessageService;
 import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -36,6 +37,7 @@ import java.util.concurrent.TimeUnit;
 
 @RequestMapping("${app-config.url.web:}/task")
 @RestController
+@Slf4j
 public class TaskController extends BaseController {
 
 	@Autowired
@@ -654,7 +656,21 @@ public class TaskController extends BaseController {
     @ApiOperation("每分钟-查询是否有直播间需要创建")
     @GetMapping(value = "/createLiveRoom")
     public void createLiveRoom(){
-        imLiveBroadcastRoomService.createLiveRoom();
+        try {
+            imLiveBroadcastRoomService.createLiveRoom();
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error("创建直播间失败",e);
+        }
+
+        // 网络教室
+        try {
+
+            courseScheduleService.rtcRoomCreate();
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error("创建网络教室失败",e);
+        }
     }
 
     @ApiOperation("每分钟-查询是否有直播间需要销毁")
@@ -691,7 +707,17 @@ public class TaskController extends BaseController {
 	@ApiOperation("每天凌晨2点钟-直播间销毁定时任务")
 	@GetMapping("/destroyLiveRoom")
 	public Object destroyLiveRoom() {
-		imLiveBroadcastRoomService.destroyLiveRoom();
+        try {
+            imLiveBroadcastRoomService.destroyLiveRoom();
+        } catch (Exception e) {
+            log.error("销毁直播间失败",e);
+        }
+
+        try {
+            courseScheduleService.destroyRtcRoom();
+        } catch (Exception e) {
+            log.error("销毁网络教室失败",e);
+        }
 		return succeed();
 	}
 

+ 4 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/CourseScheduleDao.java

@@ -2090,4 +2090,8 @@ public interface CourseScheduleDao extends BaseDAO<Long, CourseSchedule> {
     CourseSchedule findByRoomUid(@Param("roomUid") String roomUid, @Param("type") GroupType type);
 
     List<ExportCourseIncomeDto> exportCourseIncome(@Param("month") String month);
+
+    List<CourseSchedule> getNotStartOnlineNoLive(@Param("beforeTime") Integer beforeTime, @Param("tenantInfoId") Integer tenantInfoId);
+
+    List<CourseSchedule> getEndTimeBetweenYesterdayAndNow();
 }

+ 4 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/CourseScheduleService.java

@@ -857,4 +857,8 @@ public interface CourseScheduleService extends BaseService<Long, CourseSchedule>
 	void sendChatRoomMessage(List<CourseSchedule> courseSchedules);
 
     List<ExportCourseIncomeDto> exportCourseIncome(String month);
+
+    void rtcRoomCreate();
+
+    void destroyRtcRoom();
 }

+ 94 - 5
mec-biz/src/main/java/com/ym/mec/biz/service/impl/CourseScheduleServiceImpl.java

@@ -8,6 +8,9 @@ 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.microsvc.toolkit.middleware.rtc.RTCRoomPluginContext;
+import com.microsvc.toolkit.middleware.rtc.RTCRoomPluginService;
+import com.microsvc.toolkit.middleware.rtc.impl.TencentCloudRTCPlugin;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dao.*;
 import com.ym.mec.biz.dal.dto.*;
@@ -36,6 +39,7 @@ import com.ym.mec.common.page.QueryInfo;
 import com.ym.mec.common.page.WrapperUtil;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.common.tenant.TenantContextHolder;
+import com.ym.mec.im.ImFeignService;
 import com.ym.mec.thirdparty.message.MessageSenderPluginContext.MessageSender;
 import com.ym.mec.util.collection.ListUtil;
 import com.ym.mec.util.collection.MapUtil;
@@ -47,7 +51,6 @@ import org.apache.commons.collections.CollectionUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections.ListUtils;
 import org.apache.commons.collections.MapUtils;
-import org.apache.commons.lang3.SerializationUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.jetbrains.annotations.Nullable;
 import org.joda.time.DateTime;
@@ -59,7 +62,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.http.HttpStatus;
 import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.interceptor.TransactionAspectSupport;
 import java.lang.reflect.InvocationTargetException;
@@ -70,9 +72,6 @@ import java.time.*;
 import java.time.format.DateTimeFormatter;
 import java.time.temporal.TemporalAdjusters;
 import java.util.*;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
 import java.util.stream.Collectors;
 
 import static com.ym.mec.biz.dal.entity.CourseSchedule.CourseScheduleType.MUSIC_NETWORK;
@@ -207,11 +206,16 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
     private ImLiveRoomVideoService imLiveRoomVideoService;
 
     @Autowired
+    private RTCRoomPluginContext rtcRoomPluginContext;
+    @Autowired
     private ImLiveRoomVideoDao imLiveRoomVideoDao;
 
     @Autowired
     private LiveGroupPlusMapper liveGroupPlusMapper;
 
+    @Autowired
+    private TenantInfoService tenantInfoService;
+
     private final Logger businessLogger = LoggerFactory
             .getLogger(this.getClass());
 
@@ -6206,6 +6210,91 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
     }
 
     @Override
+    public void rtcRoomCreate() {
+
+        List<TenantInfo> list = tenantInfoService.list();
+        if (CollectionUtils.isEmpty(list)) {
+            return;
+        }
+
+        for (TenantInfo tenantInfo : list) {
+            //是否提前进入教室
+            String courseBeforeBufferTime = sysTenantConfigService.getTenantConfigValue(SysConfigService.COURSE_BEFORE_BUFFER_TIME, tenantInfo.getId());
+            if (StringUtils.isEmpty(courseBeforeBufferTime)) {
+                courseBeforeBufferTime = "5";
+            }
+            Integer beforeTime = Integer.parseInt(courseBeforeBufferTime) + 5;
+
+            List<CourseSchedule> scheduleList = courseScheduleDao.getNotStartOnlineNoLive(beforeTime, tenantInfo.getId());
+            if (CollectionUtils.isEmpty(scheduleList)) {
+                continue;
+            }
+            for (CourseSchedule courseSchedule : scheduleList) {
+                try {
+                    RTCRoomPluginService pluginService = rtcRoomPluginContext.getPluginService(courseSchedule.getServiceProvider());
+                    // 群组帐号注册
+                    Teacher teacher = teacherDao.get(courseSchedule.getTeacherId());
+                    if (Objects.nonNull(teacher)) {
+                        try {
+                            pluginService.register(courseSchedule.getTeacherId().toString(), teacher.getRealName(), teacher.getAvatar());
+                        } catch (Exception e) {
+                            log.error("直播房间群主注册失败: userId={}", courseSchedule.getTeacherId(), e);
+                        }
+                    }
+
+                    //记录用户实际选择的房间
+                    String roomId = courseSchedule.getId().toString();
+                    if (courseSchedule.getGroupType() == GroupType.COMM) {
+                        roomId = "I" + roomId;
+                    } else {
+                        roomId = "S" + roomId;
+                    }
+
+                    // 生成群组
+                    pluginService.chatRoomCreate(roomId, courseSchedule.getName(), courseSchedule.getTeacherId().toString());
+                    courseScheduleDao.updateLiveRemind(courseSchedule.getId(),1);
+                } catch (Exception e) {
+                    log.error("创建rtc房间失败", e);
+                }
+            }
+        }
+        
+
+    }
+
+    @Override
+    public void destroyRtcRoom() {
+
+        // 查询结束时间在昨天到现在的课程
+        List<CourseSchedule> scheduleList = courseScheduleDao.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();
+                    if (courseSchedule.getGroupType() == GroupType.COMM) {
+                        roomId = "I" + roomId;
+                    } else {
+                        roomId = "S" + roomId;
+                    }
+                    pluginService.chatRoomDestroy(roomId);
+                }
+            } catch (Exception e) {
+                log.error("销毁rtc房间失败", e);
+            }
+        }
+    }
+
+    @Override
     public List<CourseScheduleStudentDto> queryDetailList(CourseDetailQueryInfo courseDetailQueryInfo) {
 
 

+ 14 - 0
mec-biz/src/main/resources/config/mybatis/CourseScheduleMapper.xml

@@ -4504,4 +4504,18 @@
           AND cs.tenant_id_ = 1
         group by cs.id_ order by cs.organ_id_;
     </select>
+
+    <select id="getNotStartOnlineNoLive" resultMap="CourseSchedule">
+        select * from course_schedule where status_ = 'NOT_START' and teach_mode_ = 'ONLINE' and type_ != 'LIVE'
+        and CONCAT(class_date_,' ',start_class_time_) &lt;= date_format(date_add(now(),interval #{beforeTime} minute),'%Y-%m-%d %H:%i:%s')
+
+        and live_remind_ = 0
+        and tenant_id_ = #{tenantInfoId}
+    </select>
+
+    <select id="getEndTimeBetweenYesterdayAndNow" resultMap="CourseSchedule">
+        select * from course_schedule where status_ = 'OVER' and teach_mode_ = 'ONLINE' and type_ != 'LIVE'
+        and CONCAT(class_date_,' ',end_class_time_) &gt;= date_format(date_add(now(),interval -1 day),'%Y-%m-%d')
+        and CONCAT(class_date_,' ',end_class_time_) &lt;= date_format(now(),'%Y-%m-%d %H:%i:%s')
+    </select>
 </mapper>

+ 8 - 0
mec-im/src/main/java/com/ym/controller/RoomController.java

@@ -374,4 +374,12 @@ public class RoomController{
         Boolean result = roomService.memberOnlineStatus(statusList, nonce, timestamp, signature);
         return new BaseResponse<>(result);
     }
+
+
+    @RequestMapping(value = "createRtcRoom", method = RequestMethod.GET)
+    public Object createRtcRoom(@RequestParam Long courseScheduleId)
+            throws Exception {
+        roomService.createRtcGroup(courseScheduleId);
+        return new BaseResponse<>();
+    }
 }

+ 37 - 16
mec-im/src/main/java/com/ym/service/Impl/RoomServiceImpl.java

@@ -60,7 +60,6 @@ import org.joda.time.format.DateTimeFormat;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Isolation;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -683,21 +682,8 @@ public class RoomServiceImpl implements RoomService {
                 log.info("createImGroup: roomId = {}, userId = {}", roomId, actualTeacherId);
                 if (TencentCloudRTCPlugin.PLUGIN_NAME.equals(pluginService.pluginName())) {
 
-                    // 群组帐号注册
-                    Teacher teacher = teacherDao.get(courseSchedule.getTeacherId());
-                    if (Objects.nonNull(teacher)) {
-                        try {
-                            pluginService.register(courseSchedule.getTeacherId().toString(), teacher.getRealName(), teacher.getAvatar());
-                        } catch (Exception e) {
-                            log.error("直播房间群主注册失败: userId={}", courseSchedule.getTeacherId(), e);
-                        }
-                    }
 
-                    // 生成群组
-                    pluginService.chatRoomCreate(roomId, courseSchedule.getName(), courseSchedule.getTeacherId().toString());
-
-                    // 更新群自定义字段
-                    updateChatRoomGroupData(roomId, courseSchedule, pluginService);
+                    createRtcGroup(courseSchedule.getId());
 
                     // 群组老师信息
                     List<ImGroupMemberWrapper.ImGroupMember> groupMembers = Lists.newArrayList(ImGroupMemberWrapper.ImGroupMember
@@ -742,6 +728,41 @@ public class RoomServiceImpl implements RoomService {
         }
     }
 
+    @Override
+    public void createRtcGroup(Long courseScheduleId) throws Exception {
+
+        CourseSchedule courseSchedule = courseScheduleDao.get(courseScheduleId);
+        if (Objects.isNull(courseSchedule)) {
+            log.warn("createRtcGroup courseSchedule is null: courseScheduleId = {}", courseScheduleId);
+            return;
+        }
+
+        RTCRoomPluginService pluginService = rtcRoomPluginContext.getPluginService(courseSchedule.getServiceProvider());
+        // 群组帐号注册
+        Teacher teacher = teacherDao.get(courseSchedule.getTeacherId());
+        if (Objects.nonNull(teacher)) {
+            try {
+                pluginService.register(courseSchedule.getTeacherId().toString(), teacher.getRealName(), teacher.getAvatar());
+            } catch (Exception e) {
+                log.error("直播房间群主注册失败: userId={}", courseSchedule.getTeacherId(), e);
+            }
+        }
+
+        //记录用户实际选择的房间
+        String roomId = "";
+        if (courseSchedule.getGroupType() == GroupType.COMM) {
+            roomId = "I" + roomId;
+        } else {
+            roomId = "S" + roomId;
+        }
+
+        // 生成群组
+        pluginService.chatRoomCreate(roomId, courseSchedule.getName(), courseSchedule.getTeacherId().toString());
+
+        // 更新群自定义字段
+        updateChatRoomGroupData(roomId, courseSchedule, pluginService);
+    }
+
     /**
      * 更新群自定义字段
      * @param roomId 群ID
@@ -783,7 +804,7 @@ public class RoomServiceImpl implements RoomService {
         RTCRoomPluginService pluginService = rtcRoomPluginContext.getPluginService(serviceProvider);
         if (TencentCloudRTCPlugin.PLUGIN_NAME.equals(pluginService.pluginName())) {
             // 腾讯云群销毁
-            pluginService.chatRoomDestroy(roomId);
+//            pluginService.chatRoomDestroy(roomId);
         } else {
             // 融云群销毁
             // 销毁群组

+ 2 - 0
mec-im/src/main/java/com/ym/service/RoomService.java

@@ -112,6 +112,8 @@ public interface RoomService {
      */
     void adjustMusicScore(MusicScoreData musicScoreData) throws Exception;
 
+    void createRtcGroup(Long courseScheduleId) throws Exception;
+
     /**
      * 移动端用户加入房间失败
      * @author zouxuan