xiongzhu 3 anni fa
parent
commit
082dce3cc5

+ 3 - 0
src/main/java/com/izouma/yags/repo/BindGameRepo.java

@@ -5,9 +5,12 @@ import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 
 
 import java.util.List;
 import java.util.List;
+import java.util.Optional;
 
 
 public interface BindGameRepo extends JpaRepository<BindGame, Long>, JpaSpecificationExecutor<BindGame> {
 public interface BindGameRepo extends JpaRepository<BindGame, Long>, JpaSpecificationExecutor<BindGame> {
     List<BindGame> findByUserIdAndGameIdAndZone(Long userId, Long gameId, String zone);
     List<BindGame> findByUserIdAndGameIdAndZone(Long userId, Long gameId, String zone);
 
 
     List<BindGame> findByUserId(Long userId);
     List<BindGame> findByUserId(Long userId);
+
+    Optional<BindGame> findByUserIdAndGameIdAndZoneAndActive(Long userId, Long gameId, String zone, boolean active);
 }
 }

+ 2 - 1
src/main/java/com/izouma/yags/service/RoomService.java

@@ -70,7 +70,8 @@ public class RoomService {
         Game game = gameRepo.findById(gameId).orElseThrow(new BusinessException("游戏无记录"));
         Game game = gameRepo.findById(gameId).orElseThrow(new BusinessException("游戏无记录"));
         GameMode mode = gameModeRepo.findById(modeId).orElseThrow(new BusinessException("模式无记录"));
         GameMode mode = gameModeRepo.findById(modeId).orElseThrow(new BusinessException("模式无记录"));
         GameMap map = gameMapRepo.findById(mapId).orElseThrow(new BusinessException("地图无记录"));
         GameMap map = gameMapRepo.findById(mapId).orElseThrow(new BusinessException("地图无记录"));
-        BindGame bindGame = bindGameRepo.findByUserIdAndGameId(userId, gameId).orElse(null);
+        BindGame bindGame = bindGameRepo.findByUserIdAndGameIdAndZoneAndActive(userId, gameId, zone, true)
+                .orElseThrow(new BusinessException("请先绑定游戏"));
         Room room = Room.builder()
         Room room = Room.builder()
                 .name(mode.getName() + " " + map.getName())
                 .name(mode.getName() + " " + map.getName())
                 .status(RoomStatus.WAITING)
                 .status(RoomStatus.WAITING)