package com.yihu.jw.wechat.dao;

import com.yihu.jw.entity.base.wx.WxAccessTokenDO;
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.List;

/**
 * Created by Administrator on 2017/5/18 0018.
 */
public interface WxAccessTokenDao extends PagingAndSortingRepository<WxAccessTokenDO, String>, JpaSpecificationExecutor<WxAccessTokenDO> {

    @Query("from WxAccessTokenDO w where w.wechatId =?1 order by w.addTimestamp desc")
    List<WxAccessTokenDO> getWxAccessTokenById(String wechatId);
    
    @Modifying
    @Query("delete from WxAccessTokenDO p where p.wechatId=?1 ")
    void deleteByWechatId(String wechatId);


    @Query("select p from WxAccessTokenDO p where p.code = ?1 order by p.addTimestamp desc")
    Iterable<WxAccessTokenDO> findAccessToken(String accId);

    @Modifying
    @Query("delete from WxAccessTokenDO p where p.code=?1 ")
    void deleteByAccId(String accId);
}
