<?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="org.springblade.community.mapper.ResidentialMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="residentialResultMap" type="org.springblade.community.entity.Residential">
        <result column="id" property="id"/>
        <result column="create_user" property="createUser"/>
        <result column="create_dept" property="createDept"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="status" property="status"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="name" property="name"/>
        <result column="agency_id" property="agencyId"/>
        <result column="agency_name" property="agencyName"/>
        <result column="region_province" property="regionProvince"/>
        <result column="region_city" property="regionCity"/>
        <result column="region_area" property="regionArea"/>
        <result column="region_street" property="regionStreet"/>
        <result column="address" property="address"/>
        <result column="longitude" property="longitude"/>
        <result column="latitude" property="latitude"/>
        <result column="building_count" property="buildingCount"/>
        <result column="unit_count" property="unitCount"/>
        <result column="floor_count" property="floorCount"/>
        <result column="room_count" property="roomCount"/>
        <result column="user_count" property="userCount"/>
        <result column="remark" property="remark"/>
        <result column="pic" property="pic"/>
        <result column="old_id" property="oldId"/>
        <result column="org_position" property="orgPosition"/>
        <result column="tenant_id" property="tenantId"/>
        <result column="door_need_audit" property="doorNeedAudit"/>
        <result column="person_name" property="personName"/>
        <result column="person_phone" property="personPhone"/>
        <result column="third_residential_id" property="thirdResidentialId"/>
        <result column="grid_id" property="gridId"/>
        <result column="boundary_path" property="boundaryPath"/>
    </resultMap>


    <select id="selectResidentialPage" resultMap="residentialResultMap">
        select * from community_residential where is_deleted = 0
    </select>

    <select id="findPage" parameterType="org.springblade.core.mp.support.Query"  resultType="org.springblade.community.vo.ResidentialVO">
        SELECT a.*,b.name as estateName,b.office_phone as estatePhone
        FROM cyzh_community.community_residential as a
        LEFT JOIN cyzh_estate.estate_company as b
        ON a.estate_id=b.id
        <where>
            <if test="agencyId != null and agencyId > 0">
                AND a.agency_id = #{agencyId}
            </if>
            <if test="name != null and name != ''">
                AND a.name LIKE concat('%',#{name},'%')
            </if>
        </where>
        LIMIT #{current} , #{size}
    </select>

    <delete id="delete" parameterType="Long">
        delete from community_residential where id=#{id}
    </delete>

</mapper>
