package com.yihu.jw.gateway.dao;

import com.yihu.jw.entity.iot.gateway.GcToken;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.Date;
import java.util.List;

/**
 * Created by chenweida on 2017/8/17.
 */
public interface GcTokenDao extends PagingAndSortingRepository<GcToken, Long>, JpaSpecificationExecutor<GcToken> {

    @Query("update GcToken g set g.del=0 where g.appid=?1 and g.del=1")
    @Modifying
    void updateDel(String appid);

    @Query("from GcToken where accesstoken=?1")
    GcToken findByToken(String token);

    @Query("from GcToken where appid=?1 and outTime >= ?1")
    List<GcToken> findByAppIdByDate(String token,Date date);

    @Query("from GcToken where appid=?1 and outTime >= now () ")
    List<GcToken> findByAppId(String token);
}
