<?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.xlk.mapper.SearchHouseMapper">

    <select id="selectSearchHouseList" resultType="com.yunzhi.marketing.xlk.vo.SearchHouseVO">
        SELECT
            t.*,
            p.avatarurl,
            p.`nickname`,
            p.phone,
            p.gender,
            CONCAT(cc.name,c.name) as `name`
        FROM
            xlk_search_house t
            LEFT JOIN ta_person p ON t.person_id = p.person_id
            LEFT JOIN td_city c on t.intent_area = c.id
            LEFT JOIN td_city cc on cc.id = c.parentid
            WHERE t.ORG_ID = #{params.orgId}
                and t.type = #{params.type}
        <if test="params.nickname != null and params.nickname != ''">
            and p.nickname like concat('%', #{params.nickname}, '%')
        </if>
        <if test="params.phone != null and params.phone != ''">
            and p.phone like concat('%', #{params.phone}, '%')
        </if>
        <if test="params.status != null and params.status != ''">
            and t.status = #{params.status}
        </if>
        order by CREATED_TIME desc
    </select>
    <select id="selectSearchHouseDetail" resultType="com.yunzhi.marketing.xlk.vo.SearchHouseVO">
        SELECT
            t.*,
            p.avatarurl,
            p.`nickname`,
            p.phone,
            p.gender
        FROM
            xlk_search_house t
            LEFT JOIN ta_person p ON t.person_id = p.person_id
            WHERE t.id = #{id}
    </select>
    <select id="getRecommendBuildings" resultType="com.yunzhi.marketing.entity.TaBuilding">
        SELECT
            DISTINCT t.*
        FROM
            ta_building t
            INNER JOIN ta_building_project_type s ON t.building_id = s.building_id
        WHERE
            t.org_id = #{orgId}
        <if test="cityId != null">
            AND t.city_id = #{cityId}
        </if>
        <if test="areaId != null">
            AND t.building_area = #{areaId}
        </if>
            AND (
                ( s.start_price &gt;= #{minPriceW} AND s.end_price &lt;= #{maxPriceW} AND s.price_type = 'total' )
                OR ( s.start_price &gt;= #{minPrice} AND s.end_price &lt;= #{maxPrice} AND s.price_type = 'average' )
            )
            AND t.`status` > - 1
        ORDER BY
            t.is_main ASC
        LIMIT #{limit}
    </select>
    <select id="selectExportHouseList" resultType="com.yunzhi.marketing.xlk.vo.ExportSearchHouseVO">
        SELECT
        t.*,
        p.avatarurl,
        p.`nickname`,
        p.phone,
        p.gender,
        CONCAT(cc.name,c.name) as `name`
        FROM
        xlk_search_house t
        LEFT JOIN ta_person p ON t.person_id = p.person_id
        LEFT JOIN td_city c on t.intent_area = c.id
        LEFT JOIN td_city cc on cc.id = c.parentid
        WHERE t.ORG_ID = #{params.orgId}
        and t.type = #{params.type}
        <if test="params.nickname != null and params.nickname != ''">
            and p.nickname like concat('%', #{params.nickname}, '%')
        </if>
        <if test="params.phone != null and params.phone != ''">
            and p.phone like concat('%', #{params.phone}, '%')
        </if>
        <if test="params.status != null and params.status != ''">
            and t.status = #{params.status}
        </if>
        order by CREATED_TIME desc
    </select>
</mapper>
