<?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.yunzhi.marketing.mapper.TdBizEventMapper">

    <select id="selectBizEventAndIntention" resultType="com.yunzhi.marketing.entity.TdBizEvent">
        select
            biz_event.*,
            building_intention.intention AS intention,
            IF( building_intention.event_code IS NOT NULL, 'true', 'false' ) AS checkbox,
            building_intention.building_id AS buildingId,
            building_intention.intention_id AS intentionId
        FROM
        (
            SELECT
              tbe.*
            FROM
                td_biz_event tbe
        ) as biz_event
        LEFT JOIN
        (select
            tbi.*
         from
            ta_building_intention tbi
            <trim prefix="where" prefixOverrides="and | or">
                <if test="buildingId != null and buildingId != ''">
                    tbi.building_id = #{buildingId}
                </if>
                <if test="orgId != null">
                    and tbi.org_id = #{orgId}
                </if>
            </trim>
        ) as building_intention

        ON biz_event.event_id = building_intention.event_id
        where biz_event.points is not null
    </select>

</mapper>
