<?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.ruoyi.system.mapper.SysTenantMapper">

    <resultMap type="SysTenant" id="SysTenantResult">
        <id property="id" column="id"/>
        <result property="tenantName" column="tenant_name"/>
        <result property="tenantCode" column="tenant_code"/>
        <result property="updateTime" column="update_time"/>
        <result property="createTime" column="create_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateBy" column="update_by"/>
    </resultMap>

    <sql id="selectTenantVo">
        select id, tenant_name, tenant_code, update_time, create_time, create_by, update_by
        from sys_tenant
    </sql>

    <select id="selectTenantList" parameterType="SysTenant" resultMap="SysTenantResult">
        <include refid="selectTenantVo"/>
        <where>
            <if test="tenantName != null and tenantName != ''">
                AND tenant_name like concat('%', #{tenantName},'%')
            </if>
            <if test="tenantCode != null and tenantCode != ''">
                AND tenant_code like concat('%', #{tenantCode},'%')
            </if>
        </where>
    </select>

    <select id="selectTenantById" parameterType="Long" resultMap="SysTenantResult">
        <include refid="selectTenantVo"/>
        where
        id = #{id}
        limit 1
    </select>

    <insert id="insertTenant" parameterType="SysTenant">
        insert into sys_tenant
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="tenantName != null and tenantName != ''">
                tenant_name,
            </if>
            <if test="tenantCode != null and tenantCode != ''">
                tenant_code,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="tenantName != null and tenantName != ''">
                #{tenantName},
            </if>
            <if test="tenantCode != null and tenantCode != ''">
                #{tenantCode},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
        </trim>
    </insert>
    <update id="updateTenant" parameterType="SysTenant">
        update sys_tenant
        <trim prefix="set" suffixOverrides=",">
            <if test="tenantName != null and tenantName != ''">
                tenant_name = #{tenantName},
            </if>
            <if test="tenantCode != null and tenantCode != ''">
                tenant_code = #{tenantCode},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
            <if test="createTime != null"></if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysTenantById" parameterType="Long">
        delete from sys_tenant where id = #{id}
    </delete>

    <delete id="deleteSysTenantByIds" parameterType="String">
        delete from sys_tenant where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper> 