package com.wzj.soopin.member.mapper;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wzj.soopin.member.domain.bo.MemberBO;
import com.wzj.soopin.member.domain.po.Member;
import com.wzj.soopin.member.domain.vo.MemberVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 会员信息Mapper接口
 *
 * @author zcc
 */
@InterceptorIgnore(tenantLine = "true")
@Mapper
public interface MemberMapper extends BaseMapper<Member> {
    /**
     * 查询会员信息列表
     *
     * @param member 会员信息
     * @return 会员信息集合
     */
    List<Member> selectByEntity(Member member);

    /**
     * 获取所有的会员手机号
     * @return 会员手机号
     */
    @Select("select m.mobile from li_member m")
    List<String> getAllMemberMobile();

    @Select("SELECT m.*, ea.created_at AS createdAt FROM li_member m " +
        "LEFT JOIN li_expert_apply ea ON m.id = ea.member_id " +
        "${ew.customSqlSegment}")
    IPage<MemberVO> pageByMemberVO(IPage<MemberVO> page, @Param(Constants.WRAPPER) Wrapper<Member> queryWrapper);

    @Select("SELECT COUNT(*) FROM li_member WHERE username = #{username}")

    int countByUsername(@Param("username") String username);


    @Select("SELECT *   " +
        "FROM li_member   " +
        "WHERE id = #{memberId}   " +
        "  AND expert = 1;")
    Member isExpert(String memberId);

    @Select("SELECT COUNT(*) FROM ums_member")
    Object countMember();

    IPage<MemberVO> getMember(@Param("page") Page<Member> page, @Param("query") MemberBO query);

    @Select("SELECT  " +
        "    su.tenant_id  " +
        "FROM  " +
        "    ums_member um  " +
        "    LEFT JOIN sys_user su ON um.user_id = su.user_id  " +
        "    WHERE um.id =  #{spreadUid} ")
    String getReferenceTenantIdBySpreadUid(@Param("spreadUid") Long spreadUid);

}
