Browse Source

网络教室新增移动端用户加入房间状态回调接口

zouxuan 4 years ago
parent
commit
d83b13b3d2

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

@@ -9,6 +9,7 @@ import com.ym.service.MessageService;
 import com.ym.service.RoomService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
@@ -21,6 +22,8 @@ public class RoomController{
     RoomService roomService;
     @Autowired
     MessageService messageService;
+    @Autowired
+    private RedisTemplate<String,String> redisTemplate;
 
     @RequestMapping(value = "/join", method = RequestMethod.POST)
     public Object joinRoom(@RequestBody ReqUserData data) throws Exception {
@@ -54,6 +57,19 @@ public class RoomController{
         return new BaseResponse<>();
     }
 
+    @RequestMapping(value = "joinRoomStatusNotify", method = RequestMethod.POST)
+    public Object joinRoomStatusNotify(@RequestBody RoomStatusNotify roomStatusNotify) throws Exception {
+        log.info("joinRoomStatusNotify: {}",JSONObject.toJSON(roomStatusNotify));
+        String roomId = roomStatusNotify.getRoomId();
+        String userId = roomStatusNotify.getUserId();
+        if(roomStatusNotify.isRequestStatus()){
+            roomService.joinRoomSuccess(roomId, userId);
+        }else {
+            roomService.joinRoomFailure(roomId, userId);
+        }
+        return new BaseResponse<>();
+    }
+
     @RequestMapping(value = "/statusSync")
     public void statusSync(@RequestBody String body) throws Exception {
         ChannelStateNotify notify = JSONObject.parseObject(body, ChannelStateNotify.class);

+ 0 - 4
mec-im/src/main/java/com/ym/dao/RoomMemberDao.java

@@ -58,8 +58,4 @@ public interface RoomMemberDao extends JpaRepository<RoomMember, Long> {
     int updateMusicByRidAndUid(String rid, String uid, boolean musicMode);
 
     boolean existsByRidAndUid(String rid, String uid);
-
-    @Modifying
-    @Query(value = "DELETE FROM rongyun_room_member WHERE rid = ?1 AND uid != ?2", nativeQuery = true)
-    void deleteRoomMember(String roomId, String userId);
 }

+ 41 - 0
mec-im/src/main/java/com/ym/pojo/RoomStatusNotify.java

@@ -0,0 +1,41 @@
+package com.ym.pojo;
+
+
+public class RoomStatusNotify {
+	private String roomId;
+	private String userId;
+	private boolean requestStatus;
+
+	public String getRoomId() {
+		return roomId;
+	}
+
+	public void setRoomId(String roomId) {
+		this.roomId = roomId;
+	}
+
+	public String getUserId() {
+		return userId;
+	}
+
+	public void setUserId(String userId) {
+		this.userId = userId;
+	}
+
+	public boolean isRequestStatus() {
+		return requestStatus;
+	}
+
+	public void setRequestStatus(boolean requestStatus) {
+		this.requestStatus = requestStatus;
+	}
+
+	@Override
+	public String toString() {
+		return "RoomStatusNotify{" +
+				"roomId='" + roomId + '\'' +
+				", userId='" + userId + '\'' +
+				", requestStatus=" + requestStatus +
+				'}';
+	}
+}

+ 31 - 6
mec-im/src/main/java/com/ym/service/Impl/RoomServiceImpl.java

@@ -3,6 +3,7 @@ package com.ym.service.Impl;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.ym.common.ApiException;
+import com.ym.common.BaseResponse;
 import com.ym.common.DisplayEnum;
 import com.ym.common.ErrorEnum;
 import com.ym.config.IMProperties;
@@ -244,15 +245,36 @@ public class RoomServiceImpl implements RoomService {
         return roomResult;
     }
 
+
+
     @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class,isolation = Isolation.READ_COMMITTED)
     @Override
-    public void joinRoomSuccess(String roomId,String userId) throws Exception {
+    public void joinRoomFailure(String roomId, String userId) {
         RoomMember roomMember = roomMemberDao.findByRidAndUid(roomId, userId);
         if(roomMember == null){
             return ;
         }
+        log.info("joinRoomFailure : roomId={}, userId={}", roomId, userId);
+        //如果加入失败,删除该用户数据
+        roomMemberDao.deleteUserByRidAndUid(roomId,userId);
+    }
 
+    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class,isolation = Isolation.READ_COMMITTED)
+    @Override
+    public void joinRoomSuccess(String roomId,String userId) throws Exception {
+        RoomMember roomMember = roomMemberDao.findByRidAndUid(roomId, userId);
+        if(roomMember == null){
+            return ;
+        }
+        String joinSuccessKey = "joinRoomSuccess"+ roomId + userId;
+        if(redisTemplate.hasKey(joinSuccessKey)){
+            //兼容旧版本,防止重复调用
+            redisTemplate.delete(joinSuccessKey);
+            return;
+        }
+        redisTemplate.opsForValue().set("joinRoomSuccess"+ roomId + userId,roomId);
         log.info("joinRoomSuccess : roomId={}, userId={}", roomId, userId);
+
         RoleEnum roleEnum = RoleEnum.getEnumByValue(roomMember.getRole());
         CourseSchedule schedule = courseScheduleDao.getLock(Long.parseLong(roomId.substring(1)));
 
@@ -267,17 +289,16 @@ public class RoomServiceImpl implements RoomService {
         Date curTime = DateTimeUtils.currentUTC();
         Room room = roomDao.findByRid(roomId);
         if (room == null) {
-            //如果房间不存在,删除除了自己之外的其他用户
-//            roomMemberDao.deleteRoomMember(roomId,userId);
             saveRoom(roomId, roomId, curTime, display);
             IMApiResultInfo resultInfo = imHelper.createGroup(new String[]{userId}, roomId, roomId);
             if (!resultInfo.isSuccess()) {
                 log.error("joinRoomSuccess createGroup error: roomId={}, {}", roomId, resultInfo.getErrorMessage());
                 throw new ApiException(ErrorEnum.ERR_CREATE_ROOM_ERROR, resultInfo.getErrorMessage());
             }
-        }
-        if(roleEnum == RoleTeacher || roleEnum == RoleEnum.RoleAssistant){
-            updateDisplay(roomId, userId, display, 0);
+        }else{
+            if(roleEnum == RoleTeacher || roleEnum == RoleEnum.RoleAssistant){
+                updateDisplay(roomId, userId, display, 0);
+            }
         }
 
         UserInfo userInfo = userDao.findByUid(userId);
@@ -360,6 +381,10 @@ public class RoomServiceImpl implements RoomService {
         if(roomMember == null){
             return ;
         }
+        String joinSuccessKey = "joinRoomSuccess"+ roomId + userId;
+        if(redisTemplate.hasKey(joinSuccessKey)){
+            redisTemplate.delete(joinSuccessKey);
+        }
         log.info("leaveRoomSuccess: roomId={}, userId={}", roomId,userId);
         RoleEnum roleEnum = RoleEnum.getEnumByValue(roomMember.getRole());
         Integer firstCourseId = Integer.parseInt(roomId.substring(1));

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

@@ -93,4 +93,12 @@ public interface RoomService {
      * @param status
      */
     void adjustExamSong(String roomId,Integer status,Integer examSongId) throws Exception;
+
+    /**
+     * 移动端用户加入房间失败
+     * @author zouxuan
+     * @param roomId
+     * @param userId
+     */
+    void joinRoomFailure(String roomId, String userId);
 }