package com.ssj.dao.weixin.library.dao;

import com.ssj.bean.weixin.libmy.domain.LibReadVip;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author sh
 * @className IReadVipDao
 * @description dao
 * @date 2020/4/17
 */
@Repository
public interface IReadVipDao extends JpaRepository<LibReadVip,String> {

    /**根据用户id和服务类型以及馆查找
     * @date 2020/4/17 14:11
     * @author Admin
     * @param userId
     * @param s001
     * @param libId
     * @return java.util.List<com.ssj.bean.weixin.libmy.domain.LibReadVip>
     */
    @Query(nativeQuery = true, value = "SELECT  v.*   FROM  tb_lib_read_vip v   JOIN tb_lib_vip_service  e \n" +
            "  on e.vip_id =v.id\n" +
            "where   v.user_id=?1 and e.species=?2 and e.lib_id=?3 and e.stat=1  \n" +
            "GROUP BY v.id  order by e.stat ASC  ")
    List<LibReadVip> findByUserIdAndSpeciseService(String userId, String s001, String libId);

    /**查询未生成二维码的记录
     *
     * @date 2020/4/17 14:09
     * @author Admin
     * @param
     * @return java.util.List<com.ssj.bean.weixin.libmy.domain.LibReadVip>
     */
    @Query(nativeQuery = true, value = "select *  from tb_lib_read_vip  where qrcode_url is  null   order by flow_id ASC ")
    List<LibReadVip> getLibVipIsNullQrCodeAll();

    @Query(nativeQuery = true, value = "select *  from tb_lib_read_vip  where  user_id=?1 limit 1 ")
    LibReadVip findByUserId(String userId);

    @Query(nativeQuery = true, value = "select *  from tb_lib_read_vip  where  user_id=?1 and child_name=?2 limit 1 ")
    LibReadVip findByUserIdAndChildName(String id, String childName);
}
