<?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="vip.xiaonuo.disk.mapper.UserMapper">

    <insert id="insertUser" parameterType="vip.xiaonuo.disk.domain.user.UserBean" useGeneratedKeys="true" keyProperty="userId">
        INSERT INTO user (USER_ID, USERNAME, SALT, PASSWORD,  TELEPHONE, SEX, IMAGE_URL, REGISTER_TIME, AVAILABLE)
        VALUES (#{userId}, #{username},#{salt}, #{password}, #{telephone}, #{sex}, #{imageUrl}, #{registerTime}, 1);
    </insert>

    <insert id="insertUserRole">
        INSERT INTO user_role (USER_ID, ROLE_ID)
        VALUES (#{userId}, #{roleId});
    </insert>

    <select id="selectRoleListByUserId" resultType="vip.xiaonuo.disk.domain.user.Role">
        select b.*
        from user_role a
        left join role b on b.ROLE_ID = a.ROLE_ID
        where USER_ID = #{userId}
    </select>

    <select id="selectSaltByTelephone" parameterType="java.lang.String" resultType="java.lang.String">
        SELECT SALT
        FROM user
        where TELEPHONE = #{telephone}
    </select>

    <select id="selectUserByTelephoneAndPassword" parameterType="java.lang.String"
            resultType="vip.xiaonuo.disk.domain.user.UserBean">
        select USER_ID
        from user
        where TELEPHONE = #{telephone}
        AND PASSWORD = #{password}
    </select>

</mapper>
