Interface IpAccessRepository

All Superinterfaces:
org.springframework.data.repository.CrudRepository<IpAccessEntity,Long>, org.springframework.data.jpa.repository.JpaRepository<IpAccessEntity,Long>, org.springframework.data.jpa.repository.JpaSpecificationExecutor<IpAccessEntity>, org.springframework.data.repository.ListCrudRepository<IpAccessEntity,Long>, org.springframework.data.repository.ListPagingAndSortingRepository<IpAccessEntity,Long>, org.springframework.data.repository.PagingAndSortingRepository<IpAccessEntity,Long>, org.springframework.data.repository.query.QueryByExampleExecutor<IpAccessEntity>, org.springframework.data.repository.Repository<IpAccessEntity,Long>

public interface IpAccessRepository extends org.springframework.data.jpa.repository.JpaRepository<IpAccessEntity,Long>, org.springframework.data.jpa.repository.JpaSpecificationExecutor<IpAccessEntity>
  • Method Details

    • findFirstByIpAndEndpointAndAccessTimeAfter

      Optional<IpAccessEntity> findFirstByIpAndEndpointAndAccessTimeAfter(String ip, String endpoint, ZonedDateTime time)
    • findFirstByIpAndEndpointAndHttpMethodAndAccessTimeAfter

      Optional<IpAccessEntity> findFirstByIpAndEndpointAndHttpMethodAndAccessTimeAfter(String ip, String endpoint, String httpMethod, ZonedDateTime time)
    • findByUid

      Optional<IpAccessEntity> findByUid(String uid)
    • existsByUid

      Boolean existsByUid(String uid)
    • incrementAccessCount

      @Modifying @Transactional @Query(value="UPDATE bytedesk_core_ip_access SET access_count = access_count + 1, last_access_time = :lastAccessTime, updated_at = :updatedAt WHERE id = :id", nativeQuery=true) int incrementAccessCount(@Param("id") Long id, @Param("lastAccessTime") ZonedDateTime lastAccessTime, @Param("updatedAt") ZonedDateTime updatedAt)
      原子更新访问次数和最后访问时间 使用原生SQL避免乐观锁冲突
    • findByIpsAndEndpointAndAccessTimeAfter

      @Query("SELECT a FROM IpAccessEntity a WHERE a.ip IN :ips AND a.endpoint = :endpoint AND a.accessTime > :time") List<IpAccessEntity> findByIpsAndEndpointAndAccessTimeAfter(@Param("ips") List<String> ips, @Param("endpoint") String endpoint, @Param("time") ZonedDateTime time)
      批量查询IP访问记录 用于批量检查多个IP的访问情况
    • countByIpAndEndpointAndAccessTimeAfter

      @Query("SELECT COUNT(a) FROM IpAccessEntity a WHERE a.ip = :ip AND a.endpoint = :endpoint AND a.accessTime > :time") long countByIpAndEndpointAndAccessTimeAfter(@Param("ip") String ip, @Param("endpoint") String endpoint, @Param("time") ZonedDateTime time)
      统计指定IP在指定时间范围内的访问次数