<?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="com.iotechn.unimall.data.mapper.UserMapper">


    <select id="login" resultType="com.iotechn.unimall.data.dto.UserDTO">
        SELECT
            id,
            phone,
            login_type AS loginType,
            open_id AS openId,
            nickname,
            user_name as userName,
            avatar_url AS avatarUrl,
            birthday,
            gender,
            gmt_last_login AS gmtLastLogin,
            last_login_ip AS lastLoginIp,
            `status`,
            gmt_update AS gmtUpdate,
            gmt_create AS gmtCreate
        FROM
            unimall_user
        WHERE
            phone = #{phone} AND `password` = #{cryptPassword}
    </select>


    <select id="getUserList" resultType="com.iotechn.unimall.data.domain.UserDO">
        SELECT
        id,
        phone,
        password,
        login_type as loginType,
        open_id as openId,
        nickname,
        user_name as userName,
        avatar_url AS avatarUrl,
        role_ids as roleIds,
        birthday,
        gender,
        gmt_last_login AS gmtLastLogin,
        last_login_ip AS lastLoginIp,
        `status`,
        gmt_update AS gmtUpdate,
        gmt_create AS gmtCreate
        FROM
        unimall_user
        WHERE
        1 = 1
        <if test="id != null">
            AND id = #{id}
        </if>
        <if test="nickname != null">
            AND nickname like concat(concat("%",#{nickname}),"%")
        </if>
        <if test="gender != null">
            AND gender = #{gender}
        </if>
        <if test="status != null">
            AND status = #{status}
        </if>
        <if test="phone!= null">
            AND phone = #{phone}
        </if>
        limit #{offset},#{limit}
    </select>


    <select id="countUser" resultType="java.lang.Integer">
        SELECT
        count(1)
        FROM
        unimall_user
        WHERE
        1 = 1
        <if test="id != null">
            AND id = #{id}
        </if>
        <if test="nickname != null">
            AND nickname like concat(concat("%",#{nickname}),"%")
        </if>
        <if test="gender != null">
            AND gender = #{gender}
        </if>
        <if test="status != null">
            AND status = #{status}
        </if>
        <if test="phone!= null">
            AND phone = #{phone}
        </if>
    </select>

</mapper>