<?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.qmth.themis.business.dao.TBOrgMapper">

    <select id="queryByPage" resultType="com.qmth.themis.business.dto.response.TBOrgDto">
        select
            t.id,
            t.logo,
            t.enableSimulate,
            t.simulatePaperId,
            t.enableMonitorRecord,
            t.enableLiveness,
            t.accessKey,
            t.accessSecret,
            t.name,
            t.code,
            t.enable,
            t.contactName,
            t.contactPhone,
            if(t.updateName is not null,t.updateName,t.createName) as updateName,
            if(t.updateTime is not null,t.updateTime,t.createTime) as updateTime
            from
            (
            select
                tbo.id, tbo.logo, tbo.enable_simulate as enableSimulate, tbo.simulate_paper_id as simulatePaperId,
                tbo.enable_monitor_record as enableMonitorRecord,tbo.enable_liveness as enableLiveness,
                tbo.access_key as accessKey,tbo.access_secret as accessSecret,
                tbo.name, tbo.code, tbo.enable, tbo.contact_name as contactName, tbo.contact_phone as contactPhone, (
                select
                    tbu.name
                from
                    t_b_user tbu
                where
                    tbu.id = tbo.create_id) as createName, tbo.create_time as createTime, (
                select
                    tbu.name
                from
                    t_b_user tbu
                where
                    tbu.id = tbo.update_id) as updateName, tbo.update_time as updateTime
            from
                t_b_org tbo
            <where>
                <if test="code != null and code != ''">
                    and tbo.code like concat('%', #{code}, '%')
                </if>
                <if test="name != null and name != ''">
                    and tbo.name like concat('%', #{name}, '%')
                </if>
                <if test="enable != null and enable != '' or enable == 0">
                    and tbo.enable = #{enable}
                </if>
            </where> ) t
    </select>
</mapper>
