zouxuan 5 jaren geleden
bovenliggende
commit
87d7315538

+ 1 - 5
edu-im/edu-im-server/src/main/java/com/keao/edu/im/dao/RoomDao.java

@@ -14,25 +14,21 @@ import java.util.List;
  */
 @Repository
 public interface RoomDao extends JpaRepository<Room, Long> {
-    public List<Room> findByRid(String rid);
+    public Room findByRid(String rid);
 
-    @Transactional
     @Modifying
     public int deleteByRid(String rid);
 
     public boolean existsByRid(String rid);
 
-    @Transactional
     @Modifying
     @Query(value = "update rongyun_room set display=?2 where rid=?1", nativeQuery = true)
     public int updateDisplayByRid(String rid, String display);
 
-    @Transactional
     @Modifying
     @Query(value = "update rongyun_room set play_midi_json=?2 where rid=?1", nativeQuery = true)
     public int updatePlayMidiByRid(String rid, String playMidi);
 
-    @Transactional
     @Modifying
     @Query(value = "update rongyun_room set whiteboard_name_index=?2 where rid=?1", nativeQuery = true)
     public int updateWhiteboardNameIndexByRid(String rid, int whiteboardNameIndex);

+ 1 - 12
edu-im/edu-im-server/src/main/java/com/keao/edu/im/dao/RoomMemberDao.java

@@ -18,50 +18,39 @@ import java.util.List;
 public interface RoomMemberDao extends JpaRepository<RoomMember, Long> {
     public List<RoomMember> findByRid(String rid);
 
+    @Lock(value = LockModeType.PESSIMISTIC_WRITE)
     public RoomMember findByRidAndUid(String rid, String uid);
 
     public List<RoomMember> findByRidAndRole(String rid, int role);
 
     public List<RoomMember> findByUid(String uid);
 
-    public int countByRidAndRole(String rid, int role);
-
     @Modifying
-    @Transactional
     public int deleteByRid(String roomId);
 
     @Query(value = "select count(*) from rongyun_room_member where rid=?1", nativeQuery = true)
     public int countByRid(String roomId);
 
-    @Query(value = "select count(*) from rongyun_room_member where rid=?1 and role!=?2", nativeQuery = true)
-    public int countByRidAndExcludeRole(String roomId, int excludeRole);
-
-    @Transactional
     @Modifying
     @Query(value = "delete from rongyun_room_member where rid=?1 and uid=?2", nativeQuery = true)
     public int deleteUserByRidAndUid(String rid, String uid);
 
-    @Transactional
     @Modifying
     @Query(value = "update rongyun_room_member set role=?3 where rid=?1 and uid=?2", nativeQuery = true)
     public int updateRoleByRidAndUid(String rid, String uid, int role);
 
-    @Transactional
     @Modifying
     @Query(value = "update rongyun_room_member set role=?3 where rid=?1 and role=?2", nativeQuery = true)
     public int updateRoleByRidAndRole(String rid, int role);
 
-    @Transactional
     @Modifying
     @Query(value = "update rongyun_room_member set camera=?3 where rid=?1 and uid=?2", nativeQuery = true)
     public int updateCameraByRidAndUid(String rid, String uid, boolean camera);
 
-    @Transactional
     @Modifying
     @Query(value = "update rongyun_room_member set mic=?3 where rid=?1 and uid=?2", nativeQuery = true)
     public int updateMicByRidAndUid(String rid, String uid, boolean mic);
 
-    @Transactional
     @Modifying
     @Query(value = "update rongyun_room_member set music_mode=?3 where rid=?1 and uid=?2", nativeQuery = true)
     public int updateMusicByRidAndUid(String rid, String uid, boolean musicMode);

+ 0 - 1
edu-im/edu-im-server/src/main/java/com/keao/edu/im/dao/UserDao.java

@@ -18,7 +18,6 @@ public interface UserDao extends JpaRepository<UserInfo, Long> {
     @Lock(value = LockModeType.PESSIMISTIC_WRITE)
     UserInfo findByUid(String uid);
 
-    @Transactional
     @Modifying
     public int deleteByUid(String uid);
 }

+ 0 - 3
edu-im/edu-im-server/src/main/java/com/keao/edu/im/dao/WhiteboardDao.java

@@ -20,16 +20,13 @@ public interface WhiteboardDao extends JpaRepository<Whiteboard, Long> {
 
     public int deleteByRid(String rid);
 
-    @Transactional
     @Modifying
     public int deleteByWbid(String wbid);
 
-    @Transactional
     @Modifying
     @Query(value = "delete from rongyun_whiteboard where rid=?1 and creator=?2", nativeQuery = true)
     public int deleteByRidAndCreator(String rid, String creator);
 
-    @Transactional
     @Modifying
     @Query(value = "update rongyun_whiteboard set cur_pg=?3 where wbid=?2 and rid=?1", nativeQuery = true)
     public int updatePageByRidAndWbid(String rid, String wbid, int page);

+ 28 - 28
edu-im/edu-im-server/src/main/java/com/keao/edu/im/service/Impl/RoomServiceImpl.java

@@ -113,8 +113,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;
@@ -191,8 +191,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;
@@ -296,8 +296,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;
         }
@@ -372,8 +372,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 {
@@ -395,8 +395,8 @@ public class RoomServiceImpl implements RoomService {
         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);
         }
 
@@ -422,10 +422,10 @@ public class RoomServiceImpl implements RoomService {
                         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);
@@ -602,8 +602,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();
@@ -640,19 +640,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();
@@ -692,8 +692,8 @@ public class RoomServiceImpl implements RoomService {
         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);
@@ -985,16 +985,16 @@ 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());
@@ -1205,11 +1205,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());
                     }