<?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="fcb.project.manager.base.dao.TmEstateDao">

    <select id="listProject" resultType="fcb.project.manager.base.vo.house.HouseVO">
        <include refid="loadProjects"></include>
    </select>

    <select id="exportProject" resultType="fcb.project.manager.base.vo.house.HouseVO">
        <include refid="loadProjects"></include>
    </select>


    <sql id="loadProjects">
        SELECT
        estate.id estateId,
        estate.estate_name estateName,
        estate.fcb_estate_id fcbEstateId,
        house.id,
        house.create_time createTime,
        house.update_time updateTime,
        house.`status` auditStatus,
        house.auditor_name auditorName,
        house.audit_time auditTime,
        house.cover_imag_url coverImagUrl,
        house.create_by_name createByName,
        house.house_title houseTitle,
        house.submit_audit_time submitAuditTime,
        house.vr_link vrLink,
        house.vr_path vrPath,
        house.inner_vr_link innerVrLink,
        house.type
        FROM
        tm_estate estate
        INNER JOIN tm_house house ON house.estate_id = house.id
        AND house.isDelete = 0
        AND house.is_show = 1
        WHERE
        estate.isDelete = 0
        <if test="ew.departmentId != null and ew.departmentId != ''">
            and estate.belong_company_id = #{departmentId}
        </if>
        <if test="ew.fcbEstateId != null and ew.fcbEstateId != ''">
            and estate.fcb_estate_id = #{ew.fcbEstateId}
        </if>
        <if test="ew.houseTitle != null and ew.houseTitle != ''">
            and house.house_title like concat('%', #{ew.houseTitle}, '%')
        </if>
        <if test="ew.status != null">
            and house.status = #{ew.status}
        </if>
        <if test="ew.type != null">
            and house.type = #{ew.type}
        </if>
        <if test="ew.createStartTime != null">
            and house.create_time >= #{ew.createStartTime}
        </if>
        <if test="ew.createEndTime != null">
            and house.create_time &lt;= #{ew.createEndTime}
        </if>
        <if test="ew.updateStartTime != null">
            and house.update_time >= #{ew.updateStartTime}
        </if>
        <if test="ew.updateEndTime != null">
            and house.update_time &lt;= #{ew.updateEndTime}
        </if>
        <if test="ew.auditTimeStartTime != null">
            and house.audit_time >= #{ew.auditTimeStartTime}
        </if>
        <if test="ew.auditTimeEndTime != null">
            and house.audit_time &lt;= #{ew.auditTimeEndTime}
        </if>
        <if test="ew.statues != null and ew.statues.size() != 0">
            and house.status in
            <foreach collection="ew.statues" item="status" separator="," open="(" close=")">
                #{status}
            </foreach>
        </if>
        order by estate.create_time desc
    </sql>
</mapper>
