|
@@ -1,5 +1,6 @@
|
|
|
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.exception.BizException;
|
|
@@ -32,6 +33,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Isolation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -75,7 +77,27 @@ public class RoomServiceImpl implements RoomService {
|
|
|
return baseResponse;
|
|
|
}
|
|
|
|
|
|
- @Transactional(rollbackFor = Exception.class, isolation = Isolation.SERIALIZABLE)
|
|
|
+ public void exitRoom(String roomId,String userId){
|
|
|
+ List<RoomMember> byRidAndRole = roomMemberDao.findByRidAndRole(roomId, 3);
|
|
|
+ if(byRidAndRole != null && byRidAndRole.size() > 0){
|
|
|
+ log.info("学员加入时,将其他学员退出房间 byRidAndRole{}",byRidAndRole);
|
|
|
+ for (RoomMember e: byRidAndRole) {
|
|
|
+ if(e.getUid().equals(userId)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ roomMemberDao.deleteUserByRidAndUid(roomId, e.getUid());
|
|
|
+ MemberChangedMessage msg = new MemberChangedMessage(MemberChangedMessage.Action_Leave, userId, 3);
|
|
|
+ msg.setUserName(e.getName());
|
|
|
+ userDao.deleteByUid(userId);
|
|
|
+ try {
|
|
|
+ imHelper.publishMessage(userId, roomId, msg);
|
|
|
+ } catch (Exception e1) {
|
|
|
+ e1.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void joinRoomSuccess(Long registrationId,String roomId,String userId) throws Exception {
|
|
|
StudentExamResultApiDto examResult = null;
|
|
|
log.info("joinRoomSuccess: roomId={}, isAudience={}, isDisableCamera={},isMusicMode={}", roomId);
|
|
@@ -85,21 +107,6 @@ public class RoomServiceImpl implements RoomService {
|
|
|
if(registrationId != null){
|
|
|
examResult = eduUserFeignService.getExamResult(registrationId);
|
|
|
roomId = examResult.getRoomId();
|
|
|
- List<RoomMember> byRidAndRole = roomMemberDao.findByRidAndRole(roomId, 3);
|
|
|
- if(byRidAndRole != null && byRidAndRole.size() > 0){
|
|
|
- log.info("学员加入时,将其他学员退出房间 byRidAndRole{}",byRidAndRole);
|
|
|
- for (RoomMember e: byRidAndRole) {
|
|
|
- if(e.getUid().equals(userId)){
|
|
|
- continue;
|
|
|
- }
|
|
|
- roomMemberDao.deleteUserByRidAndUid(roomId, e.getUid());
|
|
|
- MemberChangedMessage msg = new MemberChangedMessage(MemberChangedMessage.Action_Leave, userId, 3);
|
|
|
- msg.setUserName(e.getName());
|
|
|
- userDao.deleteByUid(userId);
|
|
|
- imHelper.publishMessage(userId, roomId, msg);
|
|
|
-// leaveRoom(e.getExamRegistrationId(),roomId,userId);
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
CheckUtils.checkArgument(roomId != null, "roomId must't be null");
|
|
@@ -113,8 +120,8 @@ public class RoomServiceImpl implements RoomService {
|
|
|
}
|
|
|
}
|
|
|
Date curTime = DateTimeUtils.currentUTC();
|
|
|
- List<Room> roomList = roomDao.findByRid(roomId);
|
|
|
- if (roomList.isEmpty()) {
|
|
|
+ Room room = roomDao.findByRid(roomId);
|
|
|
+ if (room == null) {
|
|
|
saveRoom(roomId, roomId, curTime, null);
|
|
|
}
|
|
|
RoleEnum roleEnum;
|
|
@@ -138,20 +145,18 @@ public class RoomServiceImpl implements RoomService {
|
|
|
msg.setCamera(true);
|
|
|
imHelper.publishMessage(userId, roomId, msg);
|
|
|
|
|
|
- List<UserInfo> userInfoList = userDao.findByUid(userId);
|
|
|
- if (userInfoList.isEmpty()) {
|
|
|
- UserInfo userInfo = new UserInfo();
|
|
|
+ UserInfo userInfo = userDao.findByUid(userId);
|
|
|
+ if (userInfo == null) {
|
|
|
+ userInfo = new UserInfo();
|
|
|
userInfo.setUid(userId);
|
|
|
userInfo.setName(realName);
|
|
|
userInfo.setCreateDt(curTime);
|
|
|
userInfo.setUpdateDt(curTime);
|
|
|
userDao.save(userInfo);
|
|
|
} else {
|
|
|
- UserInfo user = userInfoList.get(0);
|
|
|
- user.setUpdateDt(curTime);
|
|
|
- userDao.save(user);
|
|
|
+ userInfo.setUpdateDt(curTime);
|
|
|
+ userDao.save(userInfo);
|
|
|
}
|
|
|
- List<RoomMember> roomMembers = roomMemberDao.findByRid(roomId);
|
|
|
log.info("join success: roomId = {}, userId = {}, userName={}, role = {}", roomId, userId, roleEnum);
|
|
|
if(registrationId != null){
|
|
|
if(examResult.getIsFinishedExam() == 1){
|
|
@@ -159,10 +164,11 @@ public class RoomServiceImpl implements RoomService {
|
|
|
}
|
|
|
this.publishMessage(eduUserFeignService.getPublishMessage(registrationId));
|
|
|
eduUserFeignService.upsetStudentAttendance(registrationId,0);
|
|
|
- imHelper.startRecord(roomId, registrationId,roomMembers);
|
|
|
+ imHelper.startRecord(roomId, registrationId);
|
|
|
+// exitRoom(roomId,userId);
|
|
|
}else {
|
|
|
eduUserFeignService.upsetTeacherAttendance(examRoom.getId(),sysUser.getId(),0);
|
|
|
- imHelper.configRecord(roomId,roomMembers);
|
|
|
+ imHelper.configRecord(roomId);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -192,8 +198,8 @@ public class RoomServiceImpl implements RoomService {
|
|
|
}
|
|
|
}
|
|
|
Date curTime = DateTimeUtils.currentUTC();
|
|
|
- List<Room> roomList = roomDao.findByRid(roomId);
|
|
|
- if (roomList.isEmpty()) {
|
|
|
+ Room room = roomDao.findByRid(roomId);
|
|
|
+ if (room == null) {
|
|
|
saveRoom(roomId, roomId, curTime, null);
|
|
|
}
|
|
|
RoleEnum roleEnum;
|
|
@@ -281,10 +287,12 @@ public class RoomServiceImpl implements RoomService {
|
|
|
roomMember.setJoinDt(joinTime);
|
|
|
roomMember.setHeadUrl(headUrl);
|
|
|
roomMember.setExamRegistrationId(examRegistrationId);
|
|
|
+ if(examRegistrationId != null){
|
|
|
+ roomMember.setMsidFlag(true);
|
|
|
+ }
|
|
|
roomMemberDao.save(roomMember);
|
|
|
}
|
|
|
|
|
|
- @Transactional(rollbackFor = Exception.class, isolation = Isolation.SERIALIZABLE)
|
|
|
public void leaveRoomSuccess(Long registrationId,String roomId,String userId) throws Exception {
|
|
|
if(registrationId != null){
|
|
|
StudentExamResultApiDto examResult = eduUserFeignService.getExamResult(registrationId);
|
|
@@ -297,8 +305,8 @@ public class RoomServiceImpl implements RoomService {
|
|
|
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) {
|
|
|
+ Room room = roomDao.findByRid(roomId);
|
|
|
+ if (room == null) {
|
|
|
log.error("room : {} not exist ", roomId);
|
|
|
return;
|
|
|
}
|
|
@@ -326,7 +334,7 @@ public class RoomServiceImpl implements RoomService {
|
|
|
imHelper.stopRecord(roomId);
|
|
|
}else {
|
|
|
eduUserFeignService.upsetTeacherAttendance(Long.parseLong(roomId),Integer.parseInt(userId),1);
|
|
|
- imHelper.configRecord(roomId,roomMemberDao.findByRid(roomId));
|
|
|
+ imHelper.configRecord(roomId);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -353,11 +361,6 @@ public class RoomServiceImpl implements RoomService {
|
|
|
imHelper.dismiss(userId,groupId);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void joinFailure(String roomId, String userId) {
|
|
|
- roomMemberDao.deleteUserByRidAndUid(roomId, userId);
|
|
|
- }
|
|
|
-
|
|
|
private void deleteWhiteboardByUser(String roomId, String userId) throws Exception {
|
|
|
List<Whiteboard> whiteboardList = whiteboardDao.findByRidAndCreator(roomId, userId);
|
|
|
if (!whiteboardList.isEmpty()) {
|
|
@@ -373,8 +376,8 @@ public class RoomServiceImpl implements RoomService {
|
|
|
public void destroyRoom(String roomId) {
|
|
|
roomDao.deleteByRid(roomId);
|
|
|
whiteboardDao.deleteByRid(roomId);
|
|
|
- List<Room> roomList = roomDao.findByRid(roomId);
|
|
|
- if (roomList.isEmpty()) {
|
|
|
+ Room room = roomDao.findByRid(roomId);
|
|
|
+ if (room == null) {
|
|
|
List<RoomMember> list = roomMemberDao.findByRid(roomId);
|
|
|
if (!list.isEmpty()) {
|
|
|
try {
|
|
@@ -389,15 +392,15 @@ public class RoomServiceImpl implements RoomService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Transactional
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
- public Boolean downgrade(String roomId, List<ReqChangeUserRoleData.ChangedUser> users) throws ApiException, Exception {
|
|
|
+ public Boolean downgrade(String roomId, List<ReqChangeUserRoleData.ChangedUser> users) throws Exception {
|
|
|
CheckUtils.checkArgument(roomId != null, "roomId must't be null");
|
|
|
CheckUtils.checkArgument(users.size() > 0, "the changed user list must't be null");
|
|
|
SysUser authUser = sysUserFeignService.queryUserInfo();
|
|
|
String userId = authUser.getId().toString();
|
|
|
- List<Room> roomList = roomDao.findByRid(roomId);
|
|
|
- if (roomList.isEmpty()) {
|
|
|
+ Room room = roomDao.findByRid(roomId);
|
|
|
+ if (room == null) {
|
|
|
throw new ApiException(ErrorEnum.ERR_ROOM_NOT_EXIST);
|
|
|
}
|
|
|
|
|
@@ -412,21 +415,10 @@ public class RoomServiceImpl implements RoomService {
|
|
|
} else {
|
|
|
RoomMember roomMember = roomMemberDao.findByRidAndUid(roomId, changedUserId);
|
|
|
if (roomMember != null) {
|
|
|
- /*if (changedRole.equals(RoleEnum.RoleAudience)) {
|
|
|
- int r = roomMemberDao.updateRoleByRidAndUid(roomId, changedUserId, changedRole.getValue());
|
|
|
- RoleChangedMessage.ChangedUser u = new RoleChangedMessage.ChangedUser(changedUserId, changedRole.getValue());
|
|
|
- List<UserInfo> userInfoList = userDao.findByUid(changedUserId);
|
|
|
- if (!userInfoList.isEmpty()) {
|
|
|
- u.setUserName(userInfoList.get(0).getName());
|
|
|
- }
|
|
|
- changedUsers.add(u);
|
|
|
- log.info("change the role: {}, {}, {}, result: {}", roomId, userId, changedRole, r);
|
|
|
- result = true;
|
|
|
- }*/
|
|
|
- if (roomMember.getRole() != Student.getValue() && isUserDisplay(roomList.get(0), roomMember.getUid())) {
|
|
|
+ if (roomMember.getRole() != Student.getValue() && isUserDisplay(room, roomMember.getUid())) {
|
|
|
updateDisplay(roomId, userId, "", 1);
|
|
|
} else {
|
|
|
- log.info("don't update display: room={}, userRole={}", roomList.get(0), RoleEnum.getEnumByValue(roomMember.getRole()));
|
|
|
+ log.info("don't update display: room={}, userRole={}", room, RoleEnum.getEnumByValue(roomMember.getRole()));
|
|
|
}
|
|
|
} else {
|
|
|
log.info("role changed fail, not exist: {} - {} - {}", roomId, userId, changedRole);
|
|
@@ -442,7 +434,7 @@ public class RoomServiceImpl implements RoomService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Transactional(rollbackFor = Exception.class,isolation = Isolation.SERIALIZABLE)
|
|
|
public void destroyRoom(Long roomId,String userId) throws Exception {
|
|
|
|
|
|
CheckUtils.checkArgument(roomId != null, "destroyRoom roomId must't be null");
|
|
@@ -450,9 +442,9 @@ public class RoomServiceImpl implements RoomService {
|
|
|
if(roomMembers != null && roomMembers.size() > 0){
|
|
|
roomMembers.forEach(e->{
|
|
|
MemberChangedMessage msg = new MemberChangedMessage(MemberChangedMessage.Action_Kick, e.getUid(), e.getRole());
|
|
|
- List<UserInfo> userInfoList = userDao.findByUid(e.getUid());
|
|
|
- if (!userInfoList.isEmpty()) {
|
|
|
- msg.setUserName(userInfoList.get(0).getName());
|
|
|
+ UserInfo userInfo = userDao.findByUid(e.getUid());
|
|
|
+ if (userInfo != null) {
|
|
|
+ msg.setUserName(userInfo.getName());
|
|
|
}
|
|
|
try {
|
|
|
imHelper.publishMessage(userId, e.getRid(), msg, 1);
|
|
@@ -479,8 +471,8 @@ public class RoomServiceImpl implements RoomService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public Boolean kickMember(ReqUserData data) throws ApiException, Exception {
|
|
|
+ @Transactional(rollbackFor = Exception.class,isolation = Isolation.SERIALIZABLE)
|
|
|
+ public Boolean kickMember(ReqUserData data) throws Exception {
|
|
|
StudentExamResultApiDto examResult = eduUserFeignService.getExamResult(data.getRegistrationId());
|
|
|
String roomId = examResult.getRoomId();
|
|
|
|
|
@@ -496,33 +488,19 @@ public class RoomServiceImpl implements RoomService {
|
|
|
throw new ApiException(ErrorEnum.ERR_USER_NOT_EXIST_IN_ROOM);
|
|
|
} else {
|
|
|
MemberChangedMessage msg = new MemberChangedMessage(MemberChangedMessage.Action_Kick, data.getUserId(), roomMember.getRole());
|
|
|
- List<UserInfo> userInfoList = userDao.findByUid(data.getUserId());
|
|
|
- if (!userInfoList.isEmpty()) {
|
|
|
- msg.setUserName(userInfoList.get(0).getName());
|
|
|
- }/*
|
|
|
- if("recorded".equals(data.getType())){
|
|
|
- msg.setRoomId("recorded" + roomId);
|
|
|
- }*/
|
|
|
- imHelper.stopRecord(roomId);
|
|
|
+ UserInfo userInfo = userDao.findByUid(data.getUserId());
|
|
|
+ if (userInfo != null) {
|
|
|
+ msg.setUserName(userInfo.getName());
|
|
|
+ }
|
|
|
IMApiResultInfo apiResultInfo = imHelper.publishMessage(userId, roomId, msg, 1);
|
|
|
if (!apiResultInfo.isSuccess()) {
|
|
|
throw new ApiException(ErrorEnum.ERR_MESSAGE_ERROR);
|
|
|
}
|
|
|
-// Thread.sleep(50);
|
|
|
log.info("published msg: msg={}", msg);
|
|
|
- /*List<Room> roomList = roomDao.findByRid(roomId);
|
|
|
- if (kickedUsers.get(0).getRole() != Student.getValue() && isUserDisplay(roomList.get(0), userId)) {
|
|
|
- updateDisplay(roomId, userId, "", 1);
|
|
|
- } else {
|
|
|
- log.info("don't update display: room={}, userRole={}", roomId, RoleEnum.getEnumByValue(kickedUsers.get(0).getRole()));
|
|
|
- }*/
|
|
|
eduUserFeignService.upsetStudentAttendance(data.getRegistrationId(),1);
|
|
|
+ imHelper.stopRecord(roomId);
|
|
|
}
|
|
|
userDao.deleteByUid(data.getUserId());
|
|
|
- /*IMApiResultInfo apiResultInfo = imHelper.quit(new String[]{data.getUserId()}, roomId);
|
|
|
- if (!apiResultInfo.isSuccess()) {
|
|
|
- throw new ApiException(ErrorEnum.ERR_EXIT_ROOM_ERROR, apiResultInfo.getErrorMessage());
|
|
|
- }*/
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -603,8 +581,8 @@ public class RoomServiceImpl implements RoomService {
|
|
|
if (resultInfo.isSuccess()) {
|
|
|
String wbId = resultInfo.getData();
|
|
|
Date date = DateTimeUtils.currentUTC();
|
|
|
- List<Room> roomList = roomDao.findByRid(roomId);
|
|
|
- int whiteboardNameIndex = roomList.get(0).getWhiteboardNameIndex() + 1;
|
|
|
+ Room room = roomDao.findByRid(roomId);
|
|
|
+ int whiteboardNameIndex = room.getWhiteboardNameIndex() + 1;
|
|
|
String name = "白板" + whiteboardNameIndex;
|
|
|
roomDao.updateWhiteboardNameIndexByRid(roomId, whiteboardNameIndex);
|
|
|
Whiteboard wb = new Whiteboard();
|
|
@@ -632,7 +610,7 @@ public class RoomServiceImpl implements RoomService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Boolean deleteWhiteboard(String roomId, String whiteBoardId) throws ApiException, Exception {
|
|
|
+ public Boolean deleteWhiteboard(String roomId, String whiteBoardId) throws Exception {
|
|
|
CheckUtils.checkArgument(roomId != null, "roomId must't be null");
|
|
|
CheckUtils.checkArgument(whiteBoardId != null, "whiteBoardId must't be null");
|
|
|
SysUser authUser = sysUserFeignService.queryUserInfo();
|
|
@@ -641,19 +619,19 @@ public class RoomServiceImpl implements RoomService {
|
|
|
List<Whiteboard> whiteboardList = whiteboardDao.findByRidAndWbid(roomId, whiteBoardId);
|
|
|
CheckUtils.checkArgument(whiteboardList.size() > 0, "whiteboard not exist");
|
|
|
|
|
|
- List<Room> roomList = roomDao.findByRid(roomId);
|
|
|
- CheckUtils.checkArgument(!roomList.isEmpty(), "room not exist");
|
|
|
+ Room room = roomDao.findByRid(roomId);
|
|
|
+ CheckUtils.checkArgument(room != null, "room not exist");
|
|
|
|
|
|
- log.info("deleteWhiteboard: room={}, whiteBoardId={}", roomList.get(0), whiteBoardId);
|
|
|
+ log.info("deleteWhiteboard: room={}, whiteBoardId={}", room, whiteBoardId);
|
|
|
|
|
|
- String display = roomList.get(0).getDisplay();
|
|
|
+ String display = room.getDisplay();
|
|
|
if (display.contains("uri=" + whiteBoardId)) {
|
|
|
int result = roomDao.updateDisplayByRid(roomId, "");
|
|
|
log.info("clear room display, room: {}, result: {}", roomId, result);
|
|
|
DisplayMessage displayMessage = new DisplayMessage("");
|
|
|
imHelper.publishMessage(userId, roomId, displayMessage, 1);
|
|
|
} else {
|
|
|
- log.info("no display to clean: room={}", roomList.get(0));
|
|
|
+ log.info("no display to clean: room={}", room);
|
|
|
}
|
|
|
|
|
|
String wbRoom = whiteboardList.get(0).getWbRoom();
|
|
@@ -671,7 +649,7 @@ public class RoomServiceImpl implements RoomService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<RoomResult.WhiteboardResult> getWhiteboard(String roomId) throws ApiException, Exception {
|
|
|
+ public List<RoomResult.WhiteboardResult> getWhiteboard(String roomId){
|
|
|
CheckUtils.checkArgument(roomId != null, "roomId must't be null");
|
|
|
CheckUtils.checkArgument(roomDao.existsByRid(roomId), "room not exist");
|
|
|
|
|
@@ -688,13 +666,13 @@ public class RoomServiceImpl implements RoomService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Boolean turnWhiteBoardPage(String roomId, String whiteBoardId, int page) throws ApiException, Exception {
|
|
|
+ public Boolean turnWhiteBoardPage(String roomId, String whiteBoardId, int page) throws Exception {
|
|
|
CheckUtils.checkArgument(roomId != null, "roomId must't be null");
|
|
|
CheckUtils.checkArgument(whiteBoardId != null, "whiteBoardId must't be null");
|
|
|
SysUser authUser = sysUserFeignService.queryUserInfo();
|
|
|
String userId = authUser.getId().toString();
|
|
|
- List<Room> roomList = roomDao.findByRid(roomId);
|
|
|
- CheckUtils.checkArgument(!roomList.isEmpty(), "room not exist");
|
|
|
+ Room room = roomDao.findByRid(roomId);
|
|
|
+ CheckUtils.checkArgument(room != null, "room not exist");
|
|
|
|
|
|
int result = whiteboardDao.updatePageByRidAndWbid(roomId, whiteBoardId, page);
|
|
|
log.info("turn page to: {}, room: {}, wb : {}; r: {}", page, roomId, whiteBoardId, result);
|
|
@@ -705,7 +683,8 @@ public class RoomServiceImpl implements RoomService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Boolean controlDevice(String roomId, String userId, DeviceTypeEnum typeEnum, boolean enable) throws ApiException, Exception {
|
|
|
+ @Transactional(rollbackFor = Exception.class,isolation = Isolation.SERIALIZABLE)
|
|
|
+ public Boolean controlDevice(String roomId, String userId, DeviceTypeEnum typeEnum, boolean enable) throws Exception {
|
|
|
CheckUtils.checkArgument(roomId != null, "roomId must't be null");
|
|
|
CheckUtils.checkArgument(userId != null, "userId must't be null");
|
|
|
CheckUtils.checkArgument(roomDao.existsByRid(roomId), "room not exist");
|
|
@@ -739,9 +718,9 @@ public class RoomServiceImpl implements RoomService {
|
|
|
}
|
|
|
DeviceStateChangedMessage deviceResourceMessage = new DeviceStateChangedMessage(typeEnum.ordinal(), false);
|
|
|
deviceResourceMessage.setUserId(userId);
|
|
|
- List<UserInfo> userInfoList = userDao.findByUid(userId);
|
|
|
- if (!userInfoList.isEmpty()) {
|
|
|
- deviceResourceMessage.setUserName(userInfoList.get(0).getName());
|
|
|
+ UserInfo userInfo = userDao.findByUid(userId);
|
|
|
+ if (userInfo != null) {
|
|
|
+ deviceResourceMessage.setUserName(userInfo.getName());
|
|
|
}
|
|
|
imHelper.publishMessage(authUser.getId().toString(), roomId, deviceResourceMessage, 1);
|
|
|
}
|
|
@@ -784,7 +763,7 @@ public class RoomServiceImpl implements RoomService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Boolean approveControlDevice(String roomId, String ticket) throws ApiException, Exception {
|
|
|
+ public Boolean approveControlDevice(String roomId, String ticket) throws Exception {
|
|
|
CheckUtils.checkArgument(ticket != null, "ticket must't be null");
|
|
|
SysUser authUser = sysUserFeignService.queryUserInfo();
|
|
|
String userId = authUser.getId().toString();
|
|
@@ -808,7 +787,7 @@ public class RoomServiceImpl implements RoomService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Boolean rejectControlDevice(String roomId, String ticket) throws ApiException, Exception {
|
|
|
+ public Boolean rejectControlDevice(String roomId, String ticket) throws Exception {
|
|
|
CheckUtils.checkArgument(ticket != null, "ticket must't be null");
|
|
|
SysUser authUser = sysUserFeignService.queryUserInfo();
|
|
|
String userId = authUser.getId().toString();
|
|
@@ -824,8 +803,8 @@ public class RoomServiceImpl implements RoomService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public Boolean syncDeviceState(String roomId, DeviceTypeEnum type, boolean enable) throws ApiException, Exception {
|
|
|
+ @Transactional(rollbackFor = Exception.class,isolation = Isolation.SERIALIZABLE)
|
|
|
+ public Boolean syncDeviceState(String roomId, DeviceTypeEnum type, boolean enable) throws Exception {
|
|
|
CheckUtils.checkArgument(roomId != null, "roomId must't be null");
|
|
|
CheckUtils.checkArgument(roomDao.existsByRid(roomId), "room not exist");
|
|
|
SysUser authUser = sysUserFeignService.queryUserInfo();
|
|
@@ -850,7 +829,7 @@ public class RoomServiceImpl implements RoomService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<RoomResult.MemberResult> getMembers(String roomId) throws ApiException, Exception {
|
|
|
+ public List<RoomResult.MemberResult> getMembers(String roomId){
|
|
|
CheckUtils.checkArgument(roomId != null, "roomId must't be null");
|
|
|
List<RoomMember> roomMemberList = roomMemberDao.findByRid(roomId);
|
|
|
if(roomMemberList != null && roomMemberList.size() > 0){
|
|
@@ -897,7 +876,8 @@ public class RoomServiceImpl implements RoomService {
|
|
|
}*/
|
|
|
|
|
|
@Override
|
|
|
- public Boolean approveSpeech(String roomId, String ticket) throws ApiException, Exception {
|
|
|
+ @Transactional(rollbackFor = Exception.class, isolation = Isolation.SERIALIZABLE)
|
|
|
+ public Boolean approveSpeech(String roomId, String ticket) throws Exception {
|
|
|
CheckUtils.checkArgument(roomId != null, "roomId must't be null");
|
|
|
CheckUtils.checkArgument(roomDao.existsByRid(roomId), "room not exist");
|
|
|
SysUser authUser = sysUserFeignService.queryUserInfo();
|
|
@@ -914,12 +894,12 @@ public class RoomServiceImpl implements RoomService {
|
|
|
roomMemberDao.updateRoleByRidAndUid(roomId, taskInfo.getApplyUserId(), Student.getValue());
|
|
|
|
|
|
SpeechResultMessage msg = new SpeechResultMessage(SpeechResultMessage.Action_Approve);
|
|
|
- List<UserInfo> userInfoList = userDao.findByUid(taskInfo.getApplyUserId());
|
|
|
+ UserInfo userInfo = userDao.findByUid(taskInfo.getApplyUserId());
|
|
|
msg.setOpUserId(userId);
|
|
|
msg.setOpUserName(authUser.getRealName());
|
|
|
msg.setReqUserId(taskInfo.getApplyUserId());
|
|
|
- if (!userInfoList.isEmpty()) {
|
|
|
- msg.setReqUserName(userInfoList.get(0).getName());
|
|
|
+ if (userInfo != null) {
|
|
|
+ msg.setReqUserName(userInfo.getName());
|
|
|
}
|
|
|
msg.setRole(Student.getValue());
|
|
|
IMApiResultInfo resultInfo = imHelper.publishMessage(userId, taskInfo.getApplyUserId(), roomId, msg);
|
|
@@ -930,8 +910,8 @@ public class RoomServiceImpl implements RoomService {
|
|
|
RoleChangedMessage rcMsg = new RoleChangedMessage(userId);
|
|
|
List<RoleChangedMessage.ChangedUser> changedUserList = new ArrayList<>();
|
|
|
RoleChangedMessage.ChangedUser user = new RoleChangedMessage.ChangedUser(taskInfo.getApplyUserId(), Student.getValue());
|
|
|
- if (!userInfoList.isEmpty()) {
|
|
|
- user.setUserName(userInfoList.get(0).getName());
|
|
|
+ if (userInfo != null) {
|
|
|
+ msg.setReqUserName(userInfo.getName());
|
|
|
}
|
|
|
changedUserList.add(user);
|
|
|
rcMsg.setUsers(changedUserList);
|
|
@@ -941,7 +921,7 @@ public class RoomServiceImpl implements RoomService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Boolean rejectSpeech(String roomId, String ticket) throws ApiException, Exception {
|
|
|
+ public Boolean rejectSpeech(String roomId, String ticket) throws Exception {
|
|
|
CheckUtils.checkArgument(roomId != null, "roomId must't be null");
|
|
|
CheckUtils.checkArgument(roomDao.existsByRid(roomId), "room not exist");
|
|
|
SysUser authUser = sysUserFeignService.queryUserInfo();
|
|
@@ -974,7 +954,7 @@ public class RoomServiceImpl implements RoomService {
|
|
|
}*/
|
|
|
|
|
|
@Override
|
|
|
- public Boolean transfer(String roomId, String userId) throws ApiException, Exception {
|
|
|
+ public Boolean transfer(String roomId, String userId) throws Exception {
|
|
|
CheckUtils.checkArgument(roomId != null, "roomId must't be null");
|
|
|
CheckUtils.checkArgument(userId != null, "userId must't be null");
|
|
|
CheckUtils.checkArgument(!userId.equals(userId), "can't set self role");
|
|
@@ -986,20 +966,19 @@ public class RoomServiceImpl implements RoomService {
|
|
|
throw new ApiException(ErrorEnum.ERR_USER_NOT_EXIST_IN_ROOM);
|
|
|
}
|
|
|
|
|
|
- List<Room> roomList = roomDao.findByRid(roomId);
|
|
|
- if (roomList.size() == 0) {
|
|
|
+ Room room = roomDao.findByRid(roomId);
|
|
|
+ if (room == null) {
|
|
|
log.error("assistant transfer error: {} toUser = {}, opUser={}", roomId, userId, userId);
|
|
|
throw new ApiException(ErrorEnum.ERR_ROOM_NOT_EXIST);
|
|
|
}
|
|
|
|
|
|
- if (isUserDisplay(roomList.get(0), userId) || isUserDisplay(roomList.get(0), userId)) {
|
|
|
+ if (isUserDisplay(room, userId) || isUserDisplay(room, userId)) {
|
|
|
updateDisplay(roomId, userId, "", 1);
|
|
|
} else {
|
|
|
- log.info("don't update display: room={}", roomList.get(0));
|
|
|
+ log.info("don't update display: room={}", room);
|
|
|
}
|
|
|
|
|
|
roomMemberDao.updateRoleByRidAndUid(roomId, userId, Student.getValue());
|
|
|
-// roomMemberDao.updateRoleByRidAndUid(roomId, userId, RoleEnum.RoleAssistant.getValue());
|
|
|
|
|
|
AssistantTransferMessage msg = new AssistantTransferMessage();
|
|
|
msg.setOpUserId(userId);
|
|
@@ -1013,7 +992,7 @@ public class RoomServiceImpl implements RoomService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Boolean inviteUpgradeRole(String roomId, String targetUserId, int targetRole) throws ApiException, Exception {
|
|
|
+ public Boolean inviteUpgradeRole(String roomId, String targetUserId, int targetRole) throws Exception {
|
|
|
CheckUtils.checkArgument(roomId != null, "roomId must't be null");
|
|
|
CheckUtils.checkArgument(targetUserId != null, "userId must't be null");
|
|
|
CheckUtils.checkArgument(roomMemberDao.existsByRidAndUid(roomId, targetUserId), "room member not exist");
|
|
@@ -1026,8 +1005,6 @@ public class RoomServiceImpl implements RoomService {
|
|
|
throw new ApiException(ErrorEnum.ERR_USER_NOT_EXIST_IN_ROOM);
|
|
|
}
|
|
|
|
|
|
-// checkOverMax(roomId, targetUser.get(0), targetRole);
|
|
|
-
|
|
|
String ticket = IdentifierUtils.uuid();
|
|
|
|
|
|
UpgradeRoleTaskInfo taskInfo = new UpgradeRoleTaskInfo();
|
|
@@ -1052,7 +1029,7 @@ public class RoomServiceImpl implements RoomService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Boolean approveUpgradeRole(String roomId, String ticket) throws ApiException, Exception {
|
|
|
+ public Boolean approveUpgradeRole(String roomId, String ticket) throws Exception {
|
|
|
CheckUtils.checkArgument(roomId != null, "roomId must't be null");
|
|
|
CheckUtils.checkArgument(ticket != null, "ticket must't be null");
|
|
|
CheckUtils.checkArgument(roomDao.existsByRid(roomId), "room not exist");
|
|
@@ -1094,7 +1071,7 @@ public class RoomServiceImpl implements RoomService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Boolean rejectUpgradeRole(String roomId, String ticket) throws ApiException, Exception {
|
|
|
+ public Boolean rejectUpgradeRole(String roomId, String ticket) throws Exception {
|
|
|
CheckUtils.checkArgument(roomId != null, "roomId must't be null");
|
|
|
CheckUtils.checkArgument(ticket != null, "ticket must't be null");
|
|
|
CheckUtils.checkArgument(roomDao.existsByRid(roomId), "room not exist");
|
|
@@ -1114,7 +1091,8 @@ public class RoomServiceImpl implements RoomService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Boolean changeRole(String roomId, String targetUserId, int targetRole) throws ApiException, Exception {
|
|
|
+ @Transactional(rollbackFor = Exception.class, isolation = Isolation.SERIALIZABLE)
|
|
|
+ public Boolean changeRole(String roomId, String targetUserId, int targetRole) throws Exception {
|
|
|
|
|
|
CheckUtils.checkArgument(roomId != null, "roomId must't be null");
|
|
|
CheckUtils.checkArgument(targetUserId != null, "userId must't be null");
|
|
@@ -1142,9 +1120,9 @@ public class RoomServiceImpl implements RoomService {
|
|
|
if (!teachers.isEmpty()) {
|
|
|
roomMemberDao.updateRoleByRidAndUid(roomId, teachers.get(0).getUid(), Student.getValue());
|
|
|
RoleChangedMessage.ChangedUser user = new RoleChangedMessage.ChangedUser(teachers.get(0).getUid(), Student.getValue());
|
|
|
- List<UserInfo> userInfoList = userDao.findByUid(teachers.get(0).getUid());
|
|
|
- if (!userInfoList.isEmpty()) {
|
|
|
- user.setUserName(userInfoList.get(0).getName());
|
|
|
+ UserInfo userInfo = userDao.findByUid(teachers.get(0).getUid());
|
|
|
+ if (userInfo != null) {
|
|
|
+ user.setUserName(userInfo.getName());
|
|
|
}
|
|
|
changedUserList.add(user);
|
|
|
} else {
|
|
@@ -1153,9 +1131,9 @@ public class RoomServiceImpl implements RoomService {
|
|
|
|
|
|
roomMemberDao.updateRoleByRidAndUid(roomId, targetUserId, targetRole);
|
|
|
RoleChangedMessage.ChangedUser user = new RoleChangedMessage.ChangedUser(targetUserId, targetRole);
|
|
|
- List<UserInfo> userInfoList = userDao.findByUid(targetUserId);
|
|
|
- if (!userInfoList.isEmpty()) {
|
|
|
- user.setUserName(userInfoList.get(0).getName());
|
|
|
+ UserInfo userInfo = userDao.findByUid(targetUserId);
|
|
|
+ if (userInfo != null) {
|
|
|
+ user.setUserName(userInfo.getName());
|
|
|
}
|
|
|
changedUserList.add(user);
|
|
|
msg.setUsers(changedUserList);
|
|
@@ -1199,6 +1177,7 @@ public class RoomServiceImpl implements RoomService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class,isolation = Isolation.SERIALIZABLE)
|
|
|
public void userIMOfflineKick(String userId) {
|
|
|
List<RoomMember> members = roomMemberDao.findByUid(userId);
|
|
|
for (RoomMember member : members) {
|
|
@@ -1206,11 +1185,11 @@ public class RoomServiceImpl implements RoomService {
|
|
|
log.info("userIMOfflineKick: roomId={}, {}, role={}", member.getRid(), userId, RoleEnum.getEnumByValue(userRole));
|
|
|
try {
|
|
|
if (userRole == RoleEnum.MainTeacher.getValue() || userRole == RoleEnum.AssistantTeacher.getValue()) {
|
|
|
- List<Room> rooms = roomDao.findByRid(member.getRid());
|
|
|
- if (rooms.isEmpty()) {
|
|
|
+ Room room = roomDao.findByRid(member.getRid());
|
|
|
+ if (room ==null) {
|
|
|
break;
|
|
|
}
|
|
|
- if (isUserDisplay(rooms.get(0), member.getUid())) {
|
|
|
+ if (isUserDisplay(room, member.getUid())) {
|
|
|
updateDisplay(member.getRid(), member.getUid(), "", 0);
|
|
|
log.info("memberOnlineStatus offline: roomId={}, {}", member.getRid(), member.getUid());
|
|
|
}
|
|
@@ -1220,35 +1199,11 @@ public class RoomServiceImpl implements RoomService {
|
|
|
roomDao.deleteByRid(member.getRid());
|
|
|
deleteWhiteboardByUser(member.getRid(), member.getUid());
|
|
|
log.info("dismiss the room: {},userId: {}", member.getRid(),userId);
|
|
|
-
|
|
|
- /*IMApiResultInfo apiResultInfo = null;
|
|
|
- apiResultInfo = imHelper.dismiss(member.getUid(), member.getRid());
|
|
|
- if (apiResultInfo.getCode() == 200) {
|
|
|
- roomMemberDao.deleteUserByRidAndUid(member.getRid(), member.getUid());
|
|
|
- roomDao.deleteByRid(member.getRid());
|
|
|
- deleteWhiteboardByUser(member.getRid(), member.getUid());
|
|
|
- log.info("dismiss the room: {},userId: {}", member.getRid(),userId);
|
|
|
- } else {
|
|
|
- log.error("{} exit {} room error: {}", member.getUid(), member.getRid(), apiResultInfo.getErrorMessage());
|
|
|
- }*/
|
|
|
} else {
|
|
|
roomMemberDao.deleteUserByRidAndUid(member.getRid(), member.getUid());
|
|
|
MemberChangedMessage msg = new MemberChangedMessage(MemberChangedMessage.Action_Leave, member.getUid(), userRole);
|
|
|
msg.setUserName(member.getName());
|
|
|
imHelper.publishMessage(member.getUid(), member.getRid(), msg);
|
|
|
-
|
|
|
- /*IMApiResultInfo apiResultInfo = null;
|
|
|
- apiResultInfo = imHelper.quit(new String[]{member.getUid()}, member.getRid());
|
|
|
- if (apiResultInfo.isSuccess()) {
|
|
|
- roomMemberDao.deleteUserByRidAndUid(member.getRid(), member.getUid());
|
|
|
- MemberChangedMessage msg = new MemberChangedMessage(MemberChangedMessage.Action_Leave, member.getUid(), userRole);
|
|
|
- msg.setUserName(member.getName());
|
|
|
- imHelper.publishMessage(member.getUid(), member.getRid(), msg);
|
|
|
- imHelper.quit(new String[]{member.getUid()}, member.getRid());
|
|
|
- log.info("quit group: roomId={},userId: {}", member.getRid(), member.getUid());
|
|
|
- } else {
|
|
|
- log.error("{} exit {} room error: {}", member.getUid(), member.getRid(), apiResultInfo.getErrorMessage());
|
|
|
- }*/
|
|
|
}
|
|
|
userDao.deleteByUid(member.getUid());
|
|
|
} catch (Exception e) {
|
|
@@ -1258,13 +1213,14 @@ public class RoomServiceImpl implements RoomService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
+ @Transactional(rollbackFor = Exception.class, isolation = Isolation.SERIALIZABLE)
|
|
|
public boolean statusSync(ChannelStateNotify notify) throws Exception {
|
|
|
- log.info("statusSync notify:{}",notify);
|
|
|
String roomId = notify.getChannelId();
|
|
|
String userId = notify.getUserId();
|
|
|
+
|
|
|
RoomMember roomMember = roomMemberDao.findByRidAndUid(roomId, userId);
|
|
|
log.info("statusSync roomMember:{}",roomMember);
|
|
|
+
|
|
|
if(roomMember == null){
|
|
|
return false;
|
|
|
}
|
|
@@ -1273,15 +1229,50 @@ public class RoomServiceImpl implements RoomService {
|
|
|
}else if(notify.getEvent() == 2){
|
|
|
//房间创建
|
|
|
}else if(notify.getEvent() == 3){
|
|
|
- //房间销毁
|
|
|
+ log.info("房间销毁 roomId: {}, userId: {}",roomId, userId);
|
|
|
+ //房间销毁(删除缓存的sessionId)
|
|
|
+ redisTemplate.delete("sessionId:" + roomId);
|
|
|
}else if(notify.getEvent() == 11){
|
|
|
//成员加入
|
|
|
+ log.info("成员加入 roomId: {}, userId: {}",roomId, userId);
|
|
|
+// roomMemberDao.updateMsidByRidAndUid(roomId,userId,msidFlag);
|
|
|
joinRoomSuccess(roomMember.getExamRegistrationId(),roomId,userId);
|
|
|
}else if(notify.getEvent() == 12){
|
|
|
//成员退出
|
|
|
+ log.info("成员退出 roomId: {}, userId: {}",roomId, userId);
|
|
|
+// roomMemberDao.updateMsidByRidAndUid(roomId,userId,msidFlag);
|
|
|
leaveRoomSuccess(roomMember.getExamRegistrationId(),roomId,userId);
|
|
|
}else if(notify.getEvent() == 20){
|
|
|
+ log.info("资源变动 roomId: {}, userId: {}",roomId, userId);
|
|
|
+ boolean msidFlag = false;
|
|
|
+ Integer state = null;
|
|
|
+ List<Member> members = notify.getMembers();
|
|
|
+ if(members != null && members.size() != 0){
|
|
|
+ Object uris = JSONObject.parseObject(members.get(0).getData().toJSONString()).get("uris");
|
|
|
+ if(uris != null){
|
|
|
+ List<UrisDto> jsonArray = JSONObject.parseArray(uris.toString(),UrisDto.class);
|
|
|
+ for (UrisDto urisDto : jsonArray) {
|
|
|
+ //视频流
|
|
|
+ if(urisDto.getMediaType() == 1){
|
|
|
+ state = urisDto.getState();
|
|
|
+ if(state == 1){
|
|
|
+ msidFlag = true;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }else {
|
|
|
+ //音频流
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //同步录制资源
|
|
|
//资源发生变动
|
|
|
+ if(roomMember.isMsidFlag() != msidFlag){
|
|
|
+ roomMemberDao.updateMsidFlagByRidAndUid(roomId,userId,state);
|
|
|
+ if(roomMember.getExamRegistrationId() == null){
|
|
|
+ imHelper.configRecord(roomId);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
return true;
|
|
|
}
|