package com.ym.dao; import com.ym.pojo.RoomMember; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Lock; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import javax.persistence.LockModeType; import java.util.List; /** * Created by weiqinxiao on 2019/2/25. */ @Repository public interface RoomMemberDao extends JpaRepository { public List findByRid(String rid); @Lock(value = LockModeType.PESSIMISTIC_WRITE) public List findByRidAndUid(String rid, String uid); public List findByRidAndRole(String rid, int role); public List 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); public boolean existsByRidAndUid(String rid, String uid); public boolean existsByRidAndRole(String rid, int role); }