<?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.zdsz.mapper.ZHouseMapper">

    <resultMap type="com.ruoyi.zdsz.domain.ZHouse" id="ZHouseResult">
        <result property="id" column="id"/>
        <result property="areaId" column="area_id"/>
        <result property="buildingId" column="building_id"/>
        <result property="unitId" column="unit_id"/>
        <result property="name" column="name"/>
        <result property="remark" column="remark"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <select id="getPageList" resultType="com.ruoyi.zdsz.domain.vo.ZHouseVo">
        select a.id as id,
        a.name as name,
        (select b.name from z_area b where b.id = a.area_id) as areaName,
        (select c.name from z_building c where c.id = a.building_id) as buildingName,
        (select d.name from z_unit d where d.id = a.unit_id) as unitName
        from z_house a
        <where>
            a.del_flag = '0'
            <if test="p.name != null  and p.name != ''">
                and a.name LIKE CONCAT('%',#{p.name},'%')
            </if>
            <if test="p.areaId != null  and p.areaId != ''">
                and a.area_id = #{p.areaId}
            </if>
            <if test="p.buildingId != null  and p.buildingId != ''">
                and a.building_id = #{p.buildingId}
            </if>
            <if test="p.unitId != null  and p.unitId != ''">
                and a.unit_id = #{p.unitId}
            </if>
        </where>
    </select>


    <select id="selectListByunitId" resultType="com.ruoyi.zdsz.domain.vo.ZHouseVo">
        select * from z_house as zh where zh.del_flag = '0'
        <if test="unitId != null  and unitId != ''">
            and zh.unit_id = #{unitId}
        </if>
    </select>
</mapper>
