<?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.huiju.estateagents.eContract.mapper.TaCompanyOrgMapper">

    <select id="listCompanyAndOrg" resultType="com.huiju.estateagents.eContract.entity.TaCompanyOrg">
        SELECT
            t.*,
            t2.company_name,
            t2.company_code,
            t2.certified_status,
            t2.status companyStatus,
            t3.`name` orgName,
            t4.`name` miniAppName
        FROM
            ta_company_org t
            LEFT JOIN ta_company t2 ON t.company_id = t2.company_id
            LEFT JOIN ta_org t3 ON t.org_id = t3.org_id
            LEFT JOIN ta_miniapp t4 ON t3.org_id = t4.org_id
        WHERE
            t2.`status` != -1
            <if test = "companyName != null and companyName != ''">
                AND t2.company_name like CONCAT('%',#{companyName} , '%')
            </if>
            <if test = "companyStatus != null ">
                AND t2.`status` = #{companyStatus}
            </if>
            <if test = "companyCode != null and companyCode != ''">
                AND t2.company_code like CONCAT('%',#{companyCode} , '%')
            </if>
            <if test = "certifiedStatus != null and certifiedStatus != ''">
                AND t2.certified_status = #{certifiedStatus}
            </if>
            <if test = "orgName != null and orgName != ''">
                AND t3.`name` like CONCAT('%',#{orgName} , '%')
            </if>
            <if test = "miniAppName != null and miniAppName != ''">
                AND t4.`name` like CONCAT('%',#{miniAppName} , '%')
            </if>
        ORDER BY
            t.create_date DESC
    </select>

</mapper>
