<?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="cn.iocoder.yudao.module.system.dal.mysql.user.AdminUserMapper">

    <!--
        一般情况下，尽可能使用 Mapper 进行 CRUD 增删改查即可。
        无法满足的场景，例如说多表关联查询，才使用 XML 编写 SQL。
        代码生成器暂时只生成 Mapper XML 文件本身，更多推荐 MybatisX 快速开发插件来生成查询。
        文档可见：https://www.iocoder.cn/MyBatis/x-plugins/
     -->



    <select id="selectTenantUserById"
            resultType="cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserRespVO">

        select * from system_users where tenant_id=#{tenantId,jdbcType=BIGINT}
    </select>

    <select id="selectByUsernameAndTenantIdWithAgencyRenewal"
            resultType="cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO">
        select * from system_users
        where username=#{initialUser,jdbcType=VARCHAR} and tenant_id=#{targetTenantId,jdbcType=BIGINT}
    </select>

    <update id="updateByIdWithRenwal">
        update system_users set
        <if test="username != null">
            username = #{username,jdbcType=VARCHAR},
        </if>
        <if test="password != null">
            password = #{password,jdbcType=VARCHAR},
        </if>
        <if test="nickname != null">
            nickname = #{nickname,jdbcType=VARCHAR},
        </if>
        <if test="remark != null">
            remark = #{remark,jdbcType=VARCHAR},
        </if>
        <if test="deptId != null">
            dept_id = #{deptId,jdbcType=BIGINT},
        </if>
        <if test="postIds != null">
            post_ids = #{postIds,jdbcType=VARCHAR,typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler},
        </if>
        <if test="email != null">
            email = #{email,jdbcType=VARCHAR},
        </if>
        <if test="mobile != null">
            mobile = #{mobile,jdbcType=VARCHAR},
        </if>
        <if test="sex != null">
            sex = #{sex,jdbcType=INTEGER},
        </if>
        <if test="avatar != null">
            avatar = #{avatar,jdbcType=VARCHAR},
        </if>
        <if test="status != null">
            status = #{status,jdbcType=INTEGER},
        </if>
        <if test="loginIp != null">
            login_ip = #{loginIp,jdbcType=VARCHAR},
        </if>
        <if test="loginDate != null">
            login_date = #{loginDate,jdbcType=TIMESTAMP},
        </if>
        <if test="crawl != null">
            crawl = #{crawl,jdbcType=TINYINT},
        </if>
        <if test="bigBrother != null">
            big_brother = #{bigBrother,jdbcType=TINYINT},
        </if>
        <if test="aiChat != null">
            ai_chat = #{aiChat,jdbcType=TINYINT},
        </if>
        <if test="aiReplay != null">
            ai_replay = #{aiReplay,jdbcType=TINYINT},
        </if>
        update_time = NOW()
        where id = #{id,jdbcType=BIGINT}
    </update>
</mapper>