<?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.tuoheng.mapper.ClientUserMapper">

    <insert id="insertClientUser" parameterType="com.tuoheng.model.po.UserPo" keyProperty="id" useGeneratedKeys="true">
        insert into users (username, password, create_user, tenant_id, is_tenant)
        values (#{username}, #{password}, #{createUser}, #{tenantId}, #{isTenant})
    </insert>

    <select id="judgeCreateByUserName" parameterType="java.lang.String" resultType="int">
        select count(1)
        from users
        where username = #{username}
    </select>

    <select id="getUserByUserName" parameterType="java.lang.String" resultType="com.tuoheng.model.po.UserPo">
        select *
        from users
        where username = #{username}
    </select>
    <select id="selectByUserId" resultType="com.tuoheng.model.po.UserPo">
        SELECT id,
               username,
               `password`,
               enabled,
               tenant_id,
               is_tenant
        FROM users
        WHERE id = #{userId}
          and enabled = 1
    </select>

    <update id="updatePass" parameterType="com.tuoheng.model.po.UserPo">
        update users
        <set>
            <if test="password != null and password != ''">
                password = #{password},
            </if>
            <if test="updateUser != null">
                update_user = #{updateUser},
            </if>
            <if test="enabled != null">
                enabled = #{enabled},
            </if>
        </set>
        where username = #{username,jdbcType=VARCHAR}
    </update>


</mapper>
