<?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.izouma.awesomeadmin.dao.SuperUserMapper">
    <sql id="columns">
        user_id, power, password, user_name, profile, del_flag
  	</sql>

    <select id="queryUserById" resultType="com.izouma.awesomeadmin.model.SuperUser" parameterType="string">
        SELECT
        <include refid="columns"/>
        FROM sys_super_user
        WHERE user_id = #{userId}
        LIMIT 1
    </select>

    <select id="userLogin" resultType="com.izouma.awesomeadmin.model.SuperUser" parameterType="map">
        SELECT
        <include refid="columns"/>
        FROM sys_super_user
        WHERE user_name = #{username}
        and password = #{password}
        LIMIT 1
    </select>

    <select id="queryAllUsers" resultType="com.izouma.awesomeadmin.model.SuperUser">
        SELECT
        <include refid="columns"/>
        FROM sys_super_user
        where del_flag = 'N'
        order by user_id
        <!-- 为了测试只取100个 -->
        <!-- LIMIT 100  -->
    </select>

    <select id="queryAllUsersByPage" parameterType="java.util.Map" resultType="com.izouma.awesomeadmin.model.SuperUser">
        select
        <include refid="columns"/>
        from sys_super_user
        <where>
            <!--  
            <if test="userInfo.userId != null and !&quot;&quot;.equals(userInfo.userId)">
                and user_id=#{userInfo.userId}
            </if>
            <if test="userInfo.username != null and !&quot;&quot;.equals(userInfo.username.trim())">
                and user_name like '%' #{userInfo.username} '%'
            </if>
            -->
        </where>
        order by user_id
    </select>

    <insert id="save" parameterType="com.izouma.awesomeadmin.model.SuperUser" useGeneratedKeys="true" keyProperty="id">
	    INSERT INTO sys_super_user (user_name, power, password, profile)
        VALUES (#{username}, #{power}, #{password}, #{profile})
    </insert>

    <update id="updateUserInfo">
        UPDATE sys_super_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="userInfo.userId != null">
                user_Id = #{userInfo.userId},
            </if>
            <if test="userInfo.username != null">
                user_name = #{userInfo.username},
            </if>
            <if test="userInfo.password != null">
                password = #{userInfo.password},
            </if>
            <if test="userInfo.profile != null">
                profile = #{userInfo.profile},
            </if>
            <if test="userInfo.power != null">
                power = #{userInfo.power},
            </if>
        </trim>
        <where>
            AND user_id = #{userId}
        </where>
    </update>

    <update id="delete">
        UPDATE sys_super_user SET del_flag = 'Y'
        <where>
            AND user_id = #{userId}
        </where>
    </update>
</mapper>