<?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.gxwebsoft.common.system.mapper.TenantMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*,b.company_name,b.company_logo as logo
        FROM sys_tenant a
        LEFT JOIN sys_company b ON a.tenant_id = b.tenant_id
        <where>
            <if test="param.tenantId != null">
                AND a.tenant_id = #{param.tenantId}
            </if>
            <if test="param.tenantName != null">
                AND a.tenant_name LIKE CONCAT('%', #{param.tenantName}, '%')
            </if>
            <if test="param.tenantCode != null">
                AND a.tenant_code LIKE CONCAT('%', #{param.tenantCode}, '%')
            </if>
            <if test="param.logo != null">
                AND a.logo LIKE CONCAT('%', #{param.logo}, '%')
            </if>
            <if test="param.comments != null">
                AND a.comments LIKE CONCAT('%', #{param.comments}, '%')
            </if>
            <if test="param.status != null">
                AND a.status = #{param.status}
            </if>
            <if test="param.userId != null">
                AND a.user_id = #{param.userId}
            </if>
            <if test="param.deleted != null">
                AND a.deleted = #{param.deleted}
            </if>
            <if test="param.deleted == null">
                AND a.deleted = 0
            </if>
            <if test="param.createTimeStart != null">
                AND a.create_time &gt;= #{param.createTimeStart}
            </if>
            <if test="param.createTimeEnd != null">
                AND a.create_time &lt;= #{param.createTimeEnd}
            </if>
            <if test="param.keywords != null">
              AND (
              a.tenant_name LIKE CONCAT('%', #{param.keywords}, '%')
              OR a.tenant_id = #{param.keywords}
              )
            </if>
        </where>
    </sql>

    <!-- 分页查询 -->
    <select id="selectPageRel" resultType="com.gxwebsoft.common.system.entity.Tenant">
        <include refid="selectSql"></include>
    </select>

    <!-- 查询全部 -->
    <select id="selectListRel" resultType="com.gxwebsoft.common.system.entity.Tenant">
        <include refid="selectSql"></include>
    </select>

    <!-- 销毁租户-->
    <delete id="destructionAll">
      DELETE FROM sys_tenant WHERE tenant_id = #{param.tenantId}
    </delete>

</mapper>
