<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.dromara.member.mapper.AppUserMapper">

    <resultMap type="org.dromara.member.domain.AppUser" id="AppUserResult">
        <id property="userId" column="user_id"/>
        <result property="userName" column="user_name"/>
        <result property="nickName" column="nick_name"/>
        <result property="phone" column="phone"/>
        <result property="email" column="email"/>
        <result property="sex" column="sex"/>
        <result property="avatar" column="avatar"/>
        <result property="password" column="password"/>
        <result property="status" column="status"/>
        <result property="delFlag" column="del_flag"/>
        <result property="loginIp" column="login_ip"/>
        <result property="loginDate" column="login_date"/>
        <result property="registerTime" column="register_time"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>


    <resultMap type="org.dromara.member.domain.vo.AppUserVo" id="AppUserResultVo">
        <id property="userId" column="user_id"/>
        <result property="userName" column="user_name"/>
        <result property="nickName" column="nick_name"/>
        <result property="phone" column="phone"/>
        <result property="email" column="email"/>
        <result property="sex" column="sex"/>
        <result property="avatar" column="avatar"/>
        <result property="status" column="status"/>
        <result property="loginIp" column="login_ip"/>
        <result property="loginDate" column="login_date"/>
        <result property="registerTime" column="register_time"/>
        <result property="createTime" column="create_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectAppUserVo">
        select user_id,
               user_name,
               nick_name,
               phone,
               email,
               sex,
               avatar,
               password,
               status,
               del_flag,
               login_ip,
               login_date,
               register_time,
               create_by,
               create_time,
               update_by,
               update_time,
               remark
        from app_user
    </sql>

    <select id="selectUserByUserName" parameterType="String" resultMap="AppUserResultVo">
        <include refid="selectAppUserVo"/>
        where user_name = #{userName} and del_flag = '0'
    </select>

    <select id="selectUserByPhone" parameterType="String" resultMap="AppUserResultVo">
        <include refid="selectAppUserVo"/>
        where phone = #{phone} and del_flag = '0'
    </select>

    <select id="selectUserByEmail" parameterType="String" resultMap="AppUserResultVo">
        <include refid="selectAppUserVo"/>
        where email = #{email} and del_flag = '0'
    </select>

    <select id="checkUserNameUnique" parameterType="String" resultType="int">
        select count(*)
        from app_user
        where user_name = #{userName}
          and del_flag = '0'
    </select>

    <select id="checkPhoneUnique" parameterType="String" resultType="int">
        select count(*)
        from app_user
        where phone = #{phone}
          and del_flag = '0'
    </select>

    <select id="checkEmailUnique" parameterType="String" resultType="int">
        select count(*)
        from app_user
        where email = #{email}
          and del_flag = '0'
    </select>

</mapper>