package com.cirle.scientific.dao;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;

import com.cirle.scientific.po.QkjMember;

import java.time.LocalDateTime;
import java.util.List;


@Repository
public interface MemberDao extends PagingAndSortingRepository<QkjMember, Long>, JpaSpecificationExecutor<QkjMember> {

    @Query(value = "select * from qkj_member where mem_card = ?1 and mem_status=0",nativeQuery = true)
    public QkjMember findByMemCard(String memCard);

    @Query(value = "select mem_mobile from qkj_member where mem_card = ?1 and mem_status=0",nativeQuery = true)
    String findByMemCardA(String memCard);

    @Query(value = "select * from qkj_member where mem_mobile = ?1 and mem_status=0",nativeQuery = true)
    QkjMember findByMemMobile(String mobile);

    @Query(value = "select * from qkj_member where mem_nickname = ?1 and mem_status=0",nativeQuery = true)
    QkjMember findByMemNickname(String mobile);

    @Query(value = "SELECT * FROM qkj_member WHERE wx_id = ?1 AND mem_status <> 1", nativeQuery = true)
    QkjMember findByWxId(String wxId);


    @Query(value = "SELECT * FROM qkj_member WHERE mem_card in (?1)", nativeQuery = true)
    List<QkjMember> findAllBymemCards(List<String> memCards);

    @Query(value = "select * from qkj_member where mem_nickname = ?1 and mem_status=0",nativeQuery = true)
    List<QkjMember> listByMemNickname(String mobile);

    @Query(value = "SELECT * FROM qkj_member WHERE is_whitelist = 1 AND mem_status <> 1", nativeQuery = true)
    List<QkjMember> findAllWhitelist();

    @Query(value = "select count(*) from qkj_member where mem_status = 0", nativeQuery = true)
    Integer findPeople();


    @Query(value = "select max(user_id) from qkj_member where mem_register_time between ?1 and ?2 and  mem_status = 0", nativeQuery = true)
    Long getMaxUserId(LocalDateTime start, LocalDateTime end);

    @Query(value = "select * from qkj_member where mem_register_time between ?1 and ?2 and  mem_status = 0", nativeQuery = true)
    List<QkjMember> listByRegisterTime(LocalDateTime start, LocalDateTime end);
}
