<?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="top.xinsin.dao.UserMapper">
    <insert id="addUser" parameterType="top.xinsin.pojo.User">
        insert into user set username = #{username}, password = #{password}, auth = #{auth},base64= #{base64};
    </insert>

    <update id="changePassword" parameterType="top.xinsin.pojo.User">
        update user set password = #{password} where BINARY username = #{username};
    </update>

    <update id="setOnline" parameterType="top.xinsin.pojo.User">
        update user set online = 1 where BINARY username = #{username} and password=#{password};
    </update>

    <update id="setOffline" parameterType="top.xinsin.pojo.User">
        update user
        set online = 0
        where BINARY username = #{username}
          and password = #{password};
    </update>

    <select id="canLogin" parameterType="top.xinsin.pojo.User" resultType="top.xinsin.pojo.User">
        select *
        from user
        where BINARY username = #{username}
          and password = #{password}
          and ban = 0;
    </select>
    <update id="setHeadPortrait" parameterType="top.xinsin.pojo.User">
        update user
        set base64 = #{password}
        where BINARY username = #{username};
    </update>
    <update id="changeUsername" parameterType="top.xinsin.pojo.User">
        update user
        set username = #{username}
        where BINARY username = #{old_username};
    </update>
    <update id="changeUsernameUpdateMessage">
        update message
        set sender = #{username}
        where BINARY sender = #{old_username};
    </update>
    <select id="getUserHeadPortrait" resultType="java.lang.String">
        select `base64`
        from user
        where BINARY `username` = #{username};
    </select>
    <select id="getOnlineUser" resultType="top.xinsin.pojo.User">
        SELECT last_login
        from user
        WHERE `online` = 1;
    </select>
    <select id="selectALLBYIdAndUsername" resultType="top.xinsin.pojo.User">
        select id, username, auth, base64, exclusiveColor
        from user where username = #{username} and id = #{id} and ban = 0;
    </select>
    <update id="setColorById">
        update user
        set exclusiveColor = #{exclusiveColor}
        where BINARY username = #{username};
    </update>
</mapper>