<?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.ruoyi.gysl.mapper.BasicInformationMapper">

    <resultMap id="ProjectExcelInfoResult" type="com.ruoyi.gysl.entity.response.ProjectExcelInfo">
        <!-- 基础信息字段 -->
        <id property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="xmfrdwxz" column="xmfrdwxz"/>
        <result property="nature" column="nature"/>

        <!-- 规划信息字段 -->
        <result property="zydmj" column="zydmj"/>
        <result property="rjl" column="rjl"/>
        <result property="zjzmj" column="zjzmj"/>
        <result property="bzcjzmj" column="bzcjzmj"/>

        <!-- 嵌套集合：建筑信息（一对多） -->
        <collection
                property="xmjzxx"
                ofType="com.ruoyi.gysl.entity.response.ProjectBuildingExcel"
                javaType="java.util.List">
            <result property="floor" column="floor"/>
            <result property="totalBuildingHeight" column="total_building_height"/>
            <result property="scgd" column="scgd"/>
            <result property="twoAndFourCg" column="two_and_four_cg"/>
            <result property="fourYscg" column="four_yscg"/>
        </collection>
    </resultMap>

	<select id="selectList" resultMap="ProjectExcelInfoResult">
        SELECT
        a.id,
        a.name,
        a.xmfrdwxz,
        a.nature,
        b.zydmj,
        b.rjl,
        b.zjzmj,
        b.bzcjzmj,
        <!-- 建筑信息字段添加 c_ 前缀 -->
        c.floor,
        c.total_building_height,
        c.scgd,
        c.two_and_four_cg,
        c.four_yscg
        FROM
        basic_information a
        LEFT JOIN plan_information b ON a.id = b.xm_id
        LEFT JOIN building_information c ON a.id = c.xm_id
        WHERE
        a.id IN
        <foreach collection="idList" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>
    <select id="page" resultType="com.ruoyi.gysl.entity.BasicInformation">
        SELECT a.*,b.zydmj
        FROM basic_information a left join plan_information b on a.id = b.xm_id
        <where>
            <if test="req.name != null and req.name != ''">
                AND a.name like concat('%',#{req.name},'%')
            </if>
            <if test="req.xmfrdwxz != null and req.xmfrdwxz != ''">
                AND a.xmfrdwxz like concat('%',#{req.xmfrdwxz},'%')
            </if>
            <if test="req.name != null and req.name != ''">
                AND a.xzfl = #{req.name}
            </if>
            <if test="req.startTime != null">
                AND a.begain_time &gt;= #{req.startTime}  <!-- 大于等于 -->
            </if>
            <if test="req.endTime != null">
                AND a.begain_time &lt;= #{req.endTime}     <!-- 小于等于 -->
            </if>
            <if test="req.tyshxydm != null and req.tyshxydm!=''">
                AND a.tyshxydm = #{req.tyshxydm}
            </if>
        </where>
    </select>
    <select id="projectList" resultType="com.ruoyi.gysl.entity.BasicInformation">
        SELECT a.*,
            ROUND( IFNULL( SUM( b.zjzmj ), 0 ) / 10000, 2 ) AS zjzmj
        FROM basic_information a left join plan_information b on a.id = b.xm_id
        where a.longitude is not null and a.latitude is not null
    </select>
</mapper>