<?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
                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,
                if(tbu2.name is not null,tbu2.name,tbu1.name) as updateName,
                if(tbo.update_time is not null,tbo.update_time,tbo.create_time) as updateTime
            from
                t_b_org tbo
            left join t_b_user tbu1 on tbo.create_id = tbu1.id
            left join t_b_user tbu2 on tbo.update_id = tbu2.id
            <where>
                <if test="code != null and code != ''">
                    and tbo.code = #{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>
    </select>
</mapper>
