<?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">
        <result property="tenantId"    column="tenant_id"    />
        <result property="tenantName"    column="tenant_name"    />
        <result property="tenantCode"    column="tenant_code"    />
        <result property="owner"    column="owner"    />
        <result property="contactInfo"    column="contact_info"    />
        <result property="address"    column="address"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="isDel"    column="is_del"    />
    </resultMap>

    <sql id="selectSysTenantVo">
        select tenant_id, tenant_name, tenant_code, owner, contact_info, address, create_by, create_time, is_del from sys_tenant
    </sql>

    <select id="selectSysTenantList" parameterType="SysTenant" resultMap="SysTenantResult">
        <include refid="selectSysTenantVo"/>
        <where>  
            <if test="tenantName != null  and tenantName != ''"> and tenant_name like concat('%', #{tenantName}, '%')</if>
            <if test="tenantCode != null  and tenantCode != ''"> and tenant_code = #{tenantCode}</if>
            <if test="owner != null  and owner != ''"> and owner = #{owner}</if>
            <if test="contactInfo != null  and contactInfo != ''"> and contact_info = #{contactInfo}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="isDel != null  and isDel != ''"> and is_del = #{isDel}</if>
        </where>
    </select>
    
    <select id="selectSysTenantByTenantId" parameterType="Long" resultMap="SysTenantResult">
        <include refid="selectSysTenantVo"/>
        where tenant_id = #{tenantId}
    </select>
        
    <insert id="insertSysTenant" parameterType="SysTenant" useGeneratedKeys="true" keyProperty="tenantId">
        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="owner != null">owner,</if>
            <if test="contactInfo != null">contact_info,</if>
            <if test="address != null">address,</if>
            <if test="createBy != null and createBy != ''">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="isDel != null and isDel != ''">is_del,</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="owner != null">#{owner},</if>
            <if test="contactInfo != null">#{contactInfo},</if>
            <if test="address != null">#{address},</if>
            <if test="createBy != null and createBy != ''">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="isDel != null and isDel != ''">#{isDel},</if>
         </trim>
    </insert>

    <update id="updateSysTenant" 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="owner != null">owner = #{owner},</if>
            <if test="contactInfo != null">contact_info = #{contactInfo},</if>
            <if test="address != null">address = #{address},</if>
            <if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="isDel != null and isDel != ''">is_del = #{isDel},</if>
        </trim>
        where tenant_id = #{tenantId}
    </update>

    <delete id="deleteSysTenantByTenantId" parameterType="Long">
        delete from sys_tenant where tenant_id = #{tenantId}
    </delete>

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