<?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.starry.admin.modules.system.mapper.SysTenantMapper">
    <resultMap type="com.starry.admin.modules.system.entity.SysTenantEntity" id="SysTenantResult">
        <result property="tenantId" column="tenant_id"/>
        <result property="tenantType" column="tenant_type"/>
        <result property="tenantStatus" column="tenant_status"/>
        <result property="tenantCode" column="tenant_code"/>
        <result property="tenantName" column="tenant_name"/>
        <result property="tenantLogo" column="tenant_logo"/>
        <result property="sortOrder" column="sort_order"/>
        <result property="homeUrl" column="home_url"/>
        <result property="phone" column="phone"/>
        <result property="fax" column="fax"/>
        <result property="email" column="email"/>
        <result property="address" column="address"/>
        <result property="userName" column="user_name"/>
        <result property="userPwd" column="user_pwd"/>
        <result property="packageId" column="package_id"/>
        <result property="tenantTime" column="tenant_time"/>
        <result property="remarks" column="remarks"/>
        <result property="updatedTime" column="updated_time"/>
        <result property="updatedBy" column="updated_by"/>
        <result property="createdTime" column="created_time"/>
        <result property="createdBy" column="created_by"/>
        <result property="deleted" column="deleted"/>
        <result property="version" column="version"/>
    </resultMap>

    <sql id="selectSysTenantVo">
        select tenant_id,
               tenant_type,
               tenant_status,
               tenant_code,
               tenant_name,
               tenant_logo,
               sort_order,
               home_url,
               phone,
               fax,
               email,
               address,
               user_name,
               user_pwd,
               package_id,
               tenant_time,
               remarks,
               updated_time,
               updated_by,
               created_time,
               created_by,
               deleted,
               version
        from sys_tenant
    </sql>

    <select id="selectSysTenantList" resultType="com.starry.admin.modules.system.vo.TenantResultVo">
        <include refid="selectSysTenantVo"/>
        <where>
            deleted = 0
        </where>
        <if test="vo.tenantName != null and vo.tenantName != ''">
            AND tenant_name like concat('%', #{vo.tenantName}, '%')
        </if>
        <if test="vo.tenantStatus != null and vo.tenantStatus != ''">
            AND tenant_status = #{vo.tenantStatus}
        </if>
        <if test="vo.beginTime != null and vo.beginTime != ''">
            <!-- 开始时间检索 -->
            AND date_format(tenant_time,'%y%m%d') &gt;= date_format(#{vo.beginTime},'%y%m%d')
        </if>
        <if test="vo.endTime != null and vo.endTime != ''">
            <!-- 结束时间检索 -->
            AND date_format(tenant_time,'%y%m%d') &lt;= date_format(#{vo.endTime},'%y%m%d')
        </if>
    </select>

    <select id="selectSysTenantByTenantId" parameterType="String" resultMap="SysTenantResult">
        <include refid="selectSysTenantVo"/>
        where tenant_id = #{tenantId}
    </select>

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