|
@@ -1,9 +1,13 @@
|
|
|
package com.keao.edu.im.service.Impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.keao.edu.auth.api.client.SysUserFeignService;
|
|
|
import com.keao.edu.auth.api.entity.SysUser;
|
|
|
import com.keao.edu.common.enums.YesOrNoEnum;
|
|
|
import com.keao.edu.common.exception.BizException;
|
|
|
+import com.keao.edu.im.api.entity.MemberChangedMessage;
|
|
|
+import com.keao.edu.im.api.entity.PublishMessageDto;
|
|
|
+import com.keao.edu.im.api.entity.ReqUserData;
|
|
|
import com.keao.edu.im.common.ApiException;
|
|
|
import com.keao.edu.im.common.ErrorEnum;
|
|
|
import com.keao.edu.im.config.IMProperties;
|
|
@@ -21,6 +25,8 @@ import com.keao.edu.im.whiteboard.WhiteBoardHelper;
|
|
|
import com.keao.edu.user.api.client.EduUserFeignService;
|
|
|
import com.keao.edu.user.api.entity.ExamRoom;
|
|
|
import com.keao.edu.user.api.entity.ExamRoomStudentRelation;
|
|
|
+import com.keao.edu.user.api.enums.StudentExamResultApiDto;
|
|
|
+import com.keao.edu.util.date.DateUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -87,10 +93,109 @@ public class RoomServiceImpl implements RoomService {
|
|
|
imHelper.startRecord(sysUser.getId().toString(),roomId);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public RoomResult joinRecorded(Long examRegistrationId) throws Exception {
|
|
|
+ StudentExamResultApiDto examResult = eduUserFeignService.getExamResult(examRegistrationId);
|
|
|
+// String roomId = examResult.getRoomId();
|
|
|
+ String recordedRoomId = "recorded" + examResult.getRoomId();
|
|
|
+ CheckUtils.checkArgument(recordedRoomId != null, "joinRecorded roomId must't be null");
|
|
|
+
|
|
|
+ //是否超时
|
|
|
+ Integer isFinishedExam = examResult.getIsFinishedExam();
|
|
|
+ if(isFinishedExam == null || isFinishedExam == 1){
|
|
|
+ throw new BizException("加入失败,考试已结束");
|
|
|
+ }
|
|
|
+ Integer recordFlag = examResult.getRecordFlag();
|
|
|
+ if(recordFlag == null || recordFlag == 0){
|
|
|
+ throw new BizException("加入失败,当前考试不允许录制");
|
|
|
+ }
|
|
|
+ String recordStartTime = examResult.getRecordStartTime();
|
|
|
+ Date date = new Date();
|
|
|
+ if(recordStartTime != null){
|
|
|
+ Date startTime = DateUtil.stringToDate(recordStartTime, DateUtil.EXPANDED_DATE_TIME_FORMAT);
|
|
|
+ int minutesBetween = DateUtil.minutesBetween(startTime, date);
|
|
|
+ int record_minutes = Integer.parseInt(eduUserFeignService.getSysConfig("record_minutes"));
|
|
|
+ if(minutesBetween >= record_minutes){
|
|
|
+ throw new BizException("加入失败,录制超时");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
+ String userId = sysUser.getId().toString();
|
|
|
+ String realName = sysUser.getRealName();
|
|
|
+// ExamRoom examRoom = eduUserFeignService.getExamRoom(Integer.parseInt(roomId));
|
|
|
+ RoomResult roomResult = new RoomResult();
|
|
|
+ RoomResult.MemberResult userResult = new RoomResult.MemberResult();
|
|
|
+ List<RoomMember> memberList = roomMemberDao.findByRidAndUid(recordedRoomId, userId);
|
|
|
+
|
|
|
+ ExamRoomStudentRelation examRoomStudentRelation = eduUserFeignService.getExamRoomStudentRelation(examRegistrationId);
|
|
|
+ if(examRoomStudentRelation == null){
|
|
|
+ throw new BizException("学员考试数据异常");
|
|
|
+ }
|
|
|
+ if(examRoomStudentRelation.getClassroomSwitch() == YesOrNoEnum.NO){
|
|
|
+ throw new BizException("考级入口已关闭");
|
|
|
+ }
|
|
|
+ if (memberList.isEmpty()) {
|
|
|
+ saveRoomMember(userId,sysUser.getAvatar(), realName, recordedRoomId, Student.getValue(), true,true, date);
|
|
|
+ IMApiResultInfo resultInfo = imHelper.joinGroup(new String[]{userId}, recordedRoomId, recordedRoomId);
|
|
|
+ if (!resultInfo.isSuccess()) {
|
|
|
+ throw new ApiException(ErrorEnum.ERR_CREATE_ROOM_ERROR, resultInfo.getErrorMessage());
|
|
|
+ }
|
|
|
+ userResult.setMicrophone(true);
|
|
|
+ userResult.setCamera(true);
|
|
|
+ userResult.setHandUp(false);
|
|
|
+ userResult.setJoinTime(date);
|
|
|
+ log.info("joinRecorded user join the room: roomId={} , userId={}, roleEnum={}", recordedRoomId, userId, Student);
|
|
|
+ } else {
|
|
|
+ RoomMember roomMember = memberList.get(0);
|
|
|
+// roomMemberDao.updateCameraByRidAndUid(roomId, userId, !isDisableCamera);
|
|
|
+ userResult.setCamera(roomMember.isCamera());
|
|
|
+ userResult.setHandUp(roomMember.isHand());
|
|
|
+ userResult.setJoinTime(roomMember.getJoinDt());
|
|
|
+ log.info("joinRecorded user exist in the room: roomId={} , userId={}, use the last role={}", recordedRoomId, userId, Student);
|
|
|
+ }
|
|
|
+
|
|
|
+ MemberChangedMessage msg = new MemberChangedMessage(MemberChangedMessage.Action_Join, userId, Student.getValue());
|
|
|
+ msg.setTimestamp(date);
|
|
|
+ msg.setUserName(realName);
|
|
|
+ msg.setCamera(true);
|
|
|
+ imHelper.publishMessage(userId, recordedRoomId, msg);
|
|
|
+
|
|
|
+ List<UserInfo> userInfoList = userDao.findByUid(userId);
|
|
|
+ if (userInfoList.isEmpty()) {
|
|
|
+ UserInfo userInfo = new UserInfo();
|
|
|
+ userInfo.setUid(userId);
|
|
|
+ userInfo.setName(realName);
|
|
|
+ userInfo.setCreateDt(date);
|
|
|
+ userInfo.setUpdateDt(date);
|
|
|
+ userDao.save(userInfo);
|
|
|
+ } else {
|
|
|
+ UserInfo user = userInfoList.get(0);
|
|
|
+ user.setUpdateDt(date);
|
|
|
+ userDao.save(user);
|
|
|
+ }
|
|
|
+
|
|
|
+ userResult.setUserName(realName);
|
|
|
+ userResult.setUserId(userId);
|
|
|
+ userResult.setRole(Student.getValue());
|
|
|
+ roomResult.setUserInfo(userResult);
|
|
|
+ roomResult.setRoomId(recordedRoomId);
|
|
|
+
|
|
|
+ roomResult.setMembers(roomMemberDao.findByRid(recordedRoomId));
|
|
|
+ log.info("joinRecorded join success: roomId = {}, userId = {}, userName={}, role = {}", recordedRoomId, userId, Student);
|
|
|
+ return roomResult;
|
|
|
+ }
|
|
|
+
|
|
|
@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
@Override
|
|
|
- public RoomResult joinRoom(String roomId, boolean isAudience, boolean isDisableCamera,boolean isMusicMode) throws ApiException, Exception {
|
|
|
- CheckUtils.checkArgument(roomId != null, "roomId must't be null");
|
|
|
+ public RoomResult joinRoom(Long registrationId, boolean isAudience, boolean isDisableCamera,boolean isMusicMode) throws ApiException, Exception {
|
|
|
+ StudentExamResultApiDto examResult = eduUserFeignService.getExamResult(registrationId);
|
|
|
+ Integer recordFlag = examResult.getRecordFlag();
|
|
|
+ if(recordFlag != null && recordFlag == 1){
|
|
|
+ joinRecorded(registrationId);
|
|
|
+ }
|
|
|
+ String roomId = examResult.getRoomId();
|
|
|
+ CheckUtils.checkArgument(registrationId != null, "registrationId must't be null");
|
|
|
|
|
|
log.info("joinRoom: roomId={}, isAudience={}, isDisableCamera={},isMusicMode={}", roomId, isAudience, isDisableCamera,isMusicMode);
|
|
|
|
|
@@ -131,7 +236,7 @@ public class RoomServiceImpl implements RoomService {
|
|
|
}else if(isAssistant){
|
|
|
roleEnum = RoleEnum.AssistantTeacher;
|
|
|
}else {
|
|
|
- ExamRoomStudentRelation examRoomStudentRelation = eduUserFeignService.getExamRoomStudentRelation(examRoom.getExaminationBasicId().intValue(), roomId, sysUser.getId());
|
|
|
+ ExamRoomStudentRelation examRoomStudentRelation = eduUserFeignService.getExamRoomStudentRelation(registrationId);
|
|
|
if(examRoomStudentRelation == null){
|
|
|
throw new BizException("学员考试数据异常");
|
|
|
}
|
|
@@ -154,7 +259,7 @@ public class RoomServiceImpl implements RoomService {
|
|
|
RoomMember roomMember = memberList.get(0);
|
|
|
roleEnum = RoleEnum.getEnumByValue(roomMember.getRole());
|
|
|
if(roleEnum == Student){
|
|
|
- ExamRoomStudentRelation examRoomStudentRelation = eduUserFeignService.getExamRoomStudentRelation(examRoom.getExaminationBasicId().intValue(), roomId, sysUser.getId());
|
|
|
+ ExamRoomStudentRelation examRoomStudentRelation = eduUserFeignService.getExamRoomStudentRelation(registrationId);
|
|
|
if(examRoomStudentRelation == null){
|
|
|
throw new BizException("学员考试数据异常");
|
|
|
}
|
|
@@ -333,7 +438,10 @@ public class RoomServiceImpl implements RoomService {
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
@Override
|
|
|
- public Boolean leaveRoom(String roomId,String userId){
|
|
|
+ public Boolean leaveRoom(Long registrationId,String userId){
|
|
|
+ StudentExamResultApiDto examResult = eduUserFeignService.getExamResult(registrationId);
|
|
|
+ String roomId = examResult.getRoomId();
|
|
|
+
|
|
|
SysUser user = null;
|
|
|
if(StringUtils.isEmpty(userId)){
|
|
|
user = sysUserFeignService.queryUserInfo();
|
|
@@ -413,6 +521,72 @@ public class RoomServiceImpl implements RoomService {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
+ @Override
|
|
|
+ public Boolean levelRecorded(Long registrationId){
|
|
|
+ StudentExamResultApiDto examResult = eduUserFeignService.getExamResult(registrationId);
|
|
|
+ String roomId = "recorded" + examResult.getRoomId();
|
|
|
+ SysUser user = sysUserFeignService.queryUserInfo();
|
|
|
+ String userId = user.getId().toString();
|
|
|
+ log.info("levelRecorded: roomId={}, userId={}", roomId,userId);
|
|
|
+
|
|
|
+ CheckUtils.checkArgument(userId != null, "userId must't be null");
|
|
|
+ CheckUtils.checkArgument(roomId != null, "roomId must't be null");
|
|
|
+ List<Room> roomList = roomDao.findByRid(roomId);
|
|
|
+ if (roomList.size() == 0) {
|
|
|
+ log.error("levelRecorded room : {} not exist ", roomId);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ List<RoomMember> roomMemberList = roomMemberDao.findByRidAndUid(roomId, userId);
|
|
|
+ if (roomMemberList.size() == 0) {
|
|
|
+ log.error("levelRecorded {} not exist in room: {}", userId, roomId);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ int userRole = roomMemberList.get(0).getRole();
|
|
|
+ log.info("levelRecorded: roomId={}, role={}", roomId, RoleEnum.getEnumByValue(userRole));
|
|
|
+
|
|
|
+ if (roomMemberDao.countByRid(roomId) == 1) {
|
|
|
+ IMApiResultInfo apiResultInfo = null;
|
|
|
+ try {
|
|
|
+ apiResultInfo = imHelper.dismiss(userId, roomId);
|
|
|
+ if (apiResultInfo.getCode() == 200) {
|
|
|
+ roomMemberDao.deleteUserByRidAndUid(roomId, userId);
|
|
|
+ roomDao.deleteByRid(roomId);
|
|
|
+// deleteWhiteboardByUser(roomId, userId);
|
|
|
+ log.info("levelRecorded dismiss the room: {},userId: {}", roomId,userId);
|
|
|
+ } else {
|
|
|
+ log.error("levelRecorded {} exit {} room error: {}", userId, roomId, apiResultInfo.getErrorMessage());
|
|
|
+ throw new ApiException(ErrorEnum.ERR_EXIT_ROOM_ERROR, apiResultInfo.getErrorMessage());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("levelRecorded {} exit {} room error: {}", userId, roomId, e.getMessage());
|
|
|
+ throw new ApiException(ErrorEnum.ERR_EXIT_ROOM_ERROR, e.getMessage());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ IMApiResultInfo apiResultInfo = null;
|
|
|
+ try {
|
|
|
+ apiResultInfo = imHelper.quit(new String[]{userId}, roomId);
|
|
|
+ if (apiResultInfo.isSuccess()) {
|
|
|
+ roomMemberDao.deleteUserByRidAndUid(roomId, userId);
|
|
|
+ MemberChangedMessage msg = new MemberChangedMessage(MemberChangedMessage.Action_Leave, userId, userRole);
|
|
|
+ msg.setUserName(user.getUsername());
|
|
|
+ imHelper.publishMessage(userId, roomId, msg);
|
|
|
+ imHelper.quit(new String[]{userId}, roomId);
|
|
|
+ log.info("levelRecorded quit group: roomId={},userId: {}", roomId,userId);
|
|
|
+ } else {
|
|
|
+ throw new ApiException(ErrorEnum.ERR_EXIT_ROOM_ERROR, apiResultInfo.getErrorMessage());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("levelRecorded leave room error: roomId={}, {}", roomId, e.getMessage());
|
|
|
+ throw new ApiException(ErrorEnum.ERR_EXIT_ROOM_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ userDao.deleteByUid(userId);
|
|
|
+// this.signOut(Long.parseLong(roomId));
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
private void deleteWhiteboardByUser(String roomId, String userId) throws Exception {
|
|
|
List<Whiteboard> whiteboardList = whiteboardDao.findByRidAndCreator(roomId, userId);
|
|
|
if (!whiteboardList.isEmpty()) {
|
|
@@ -497,7 +671,10 @@ public class RoomServiceImpl implements RoomService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Boolean kickMember(String roomId) throws ApiException, Exception {
|
|
|
+ public Boolean kickMember(ReqUserData data) throws ApiException, Exception {
|
|
|
+ StudentExamResultApiDto examResult = eduUserFeignService.getExamResult(data.getRegistrationId());
|
|
|
+ String roomId = examResult.getRoomId();
|
|
|
+
|
|
|
SysUser authUser = sysUserFeignService.queryUserInfo();
|
|
|
String userId = authUser.getId().toString();
|
|
|
CheckUtils.checkArgument(userId != null, "userId must't be null");
|
|
@@ -514,6 +691,9 @@ public class RoomServiceImpl implements RoomService {
|
|
|
if (!userInfoList.isEmpty()) {
|
|
|
msg.setUserName(userInfoList.get(0).getName());
|
|
|
}
|
|
|
+ if("recorded".equals(data.getType())){
|
|
|
+ msg.setRoomId("recorded" + roomId);
|
|
|
+ }
|
|
|
IMApiResultInfo apiResultInfo = imHelper.publishMessage(userId, roomId, msg, 1);
|
|
|
if (!apiResultInfo.isSuccess()) {
|
|
|
throw new ApiException(ErrorEnum.ERR_MESSAGE_ERROR);
|
|
@@ -1340,6 +1520,14 @@ public class RoomServiceImpl implements RoomService {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void publishMessage(PublishMessageDto publishMessageDto) throws Exception {
|
|
|
+ IMApiResultInfo apiResultInfo = imHelper.publishMessage(publishMessageDto.getUserId(),
|
|
|
+ publishMessageDto.getRoomId(),
|
|
|
+ publishMessageDto.getMemberChangedMessage(),
|
|
|
+ publishMessageDto.getIncludeSender());
|
|
|
+ }
|
|
|
+
|
|
|
/*@Override
|
|
|
public void sendImPlayMidiMessage(PlayMidiMessageData playMidiMessageData) throws Exception {
|
|
|
SysUser sysUser = sysUserFeignService.queryUserInfo();
|