<?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.yinlihupo.enlish.service.domain.mapper.UserDOMapper">
    <resultMap id="BaseResultMap" type="com.yinlihupo.enlish.service.domain.dataobject.UserDO">
        <id column="id" jdbcType="BIGINT" property="id" />
        <result column="password" jdbcType="VARCHAR" property="password" />
        <result column="name" jdbcType="VARCHAR" property="name" />
        <result column="openid" jdbcType="VARCHAR" property="openid" />
        <result column="phone" jdbcType="VARCHAR" property="phone" />
        <result column="email" jdbcType="VARCHAR" property="email" />
    </resultMap>

    <insert id="insert" useGeneratedKeys="true" keyProperty="id">
        insert into user (password, phone, name)
        values (#{password}, #{phone}, #{name})
    </insert>

    <insert id="createUser">
        insert into user (phone, name, password)
        values (#{phone}, #{name}, #{password})
    </insert>

    <select id="selectByPhone" resultMap="BaseResultMap">
        select *
        from user
        where phone = #{phone}
    </select>

    <select id="selectById">
        select *
        from user
        where id = #{id}
    </select>

    <select id="selectUserDOList" resultMap="BaseResultMap">
        select *
        from user
        where 1 = 1
        <if test="name != null">
            and name = #{name}
        </if>
        limit #{startIndex}, #{pageSize}
    </select>

    <select id="selectUserTotal" resultType="java.lang.Integer">
        select count(*)
        from user
    </select>

</mapper>