<?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.TenantMapper">

    <insert id="insertTenant" parameterType="com.tuoheng.model.po.TenantPo" keyProperty="id" useGeneratedKeys="true">
        INSERT INTO t_tenant (user_id, remark, `code`, `name`)
        VALUES (#{userId}, #{remark}, #{code}, #{name})
    </insert>
    <update id="updateById" parameterType="com.tuoheng.model.po.TenantPo">
        update t_tenant
        <set>
            <if test="name !=null and name !=''">
                name = #{name},
            </if>
            <if test="enabled !=null">
                enabled = #{enabled},
            </if>
        </set>
        where id = #{id}
    </update>
    <select id="getByCode" resultType="com.tuoheng.model.dto.TTenant">
        select *
        from tuoheng_oidc.t_tenant
        where code = #{code}
    </select>
    <select id="findList" resultType="com.tuoheng.model.po.TenantPo">
        SELECT id, user_id, remark,enabled, code, name
        FROM t_tenant
        WHERE enabled = 1
        <if test="query.name != null and query.name != ''">
            and name LIKE concat('%',#{query.name},'%')
        </if>
        ORDER BY create_time desc
    </select>
    <select id="selectById" resultType="com.tuoheng.model.po.TenantPo">
        SELECT id, user_id, remark, enabled, code, name
        FROM t_tenant
        WHERE id = #{id}
    </select>
</mapper>
