<?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.ruoyi.file.mapper.UserMapper">

    <insert id="insertUser" parameterType="com.ruoyi.file.domain.user.UserBean" useGeneratedKeys="true" keyProperty="userId">
        INSERT INTO user (userId, username, salt, PASSWORD,  telephone, sex, imageUrl, registerTime, available)
        VALUES (#{userId}, #{username},#{salt}, #{password}, #{telephone}, #{sex}, #{imageUrl}, #{registerTime}, 1);
    </insert>

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

    <select id="selectRoleListByUserId" resultType="com.ruoyi.file.domain.user.Role">
        select b.*
        from user_role a
        left join role b on b.roleId = a.roleId
        where userId = #{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="com.ruoyi.file.domain.user.UserBean">
        select userId
        from user
        where telephone = #{telephone}
        AND password = #{password}
    </select>

</mapper>
