Jelajahi Sumber

roomId 唯一

lyhzzz 2 tahun lalu
induk
melakukan
02db03de84

+ 12 - 4
src/main/java/com/fdkankan/tk/common/util/RoomUtil.java

@@ -1,5 +1,6 @@
 package com.fdkankan.tk.common.util;
 
+import com.fdkankan.tk.entity.Room;
 import com.fdkankan.tk.service.IRoomService;
 import com.fdkankan.tk.service.IRoomUserService;
 import jdk.net.SocketFlow;
@@ -29,12 +30,19 @@ public class RoomUtil {
         return roomId;
     }
 
-    public  String genRoomId(){
-        Long count = roomService.getCountAndTbStatus();
+    public  String genRoomId(Integer sum ){
+        Long count = roomService.getCountAndTbStatus() + sum;
+        String roomId = null;
         if(StringUtils.isBlank(ev)){
-            return "cs-"+geZeroNumber(count);
+            roomId= "cs-"+geZeroNumber(count);
+        }else {
+            roomId= ev+"-"+geZeroNumber(count);
         }
-        return ev+"-"+geZeroNumber(count);
+        Room room = roomService.getById(roomId);
+        if(room == null){
+            return roomId;
+        }
+        return genRoomId(1000);
     }
 
     /**

+ 4 - 3
src/main/java/com/fdkankan/tk/service/impl/RoomServiceImpl.java

@@ -156,7 +156,7 @@ public class RoomServiceImpl extends ServiceImpl<IRoomMapper, Room> implements I
                 throw new BusinessException(ResultCode.ROOM_ING);
             }
         }else {
-            room.setRoomId(roomUtil.genRoomId());
+            room.setRoomId(roomUtil.genRoomId(1000));
         }
 
         if(param.getNumList().size() >0){
@@ -363,11 +363,12 @@ public class RoomServiceImpl extends ServiceImpl<IRoomMapper, Room> implements I
             roomVisitLogService.addLog(roomId,roomUserId,userId,type);
         }
         if(type == 1 ){   //离开房间
-            room.setRoomStatus(2);
             this.stopRoom(roomId,roomUserId);
             roomVisitLogService.addLog(roomId,roomUserId,userId,type);
         }
-
+        if(type == 1 && roomUserId == null){
+            room.setRoomStatus(2);
+        }
         room.setLastLookTime(DateUtil.formatDateTime(new Date()));
         room.setUpdateTime(null);
         this.updateById(room);