<?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.residential.mapper.ResidentialMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="residentialResultMap" type="org.springblade.community.residential.entity.Residential">
        <result column="id" property="id"/>
        <result column="old_id" property="oldId"/>
        <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="residential_number" property="residentialNumber"/>
        <result column="root_org_id" property="rootOrgId"/>
        <result column="org_pid" property="orgPid"/>
        <result column="org_pid_name" property="orgPidName"/>
        <result column="org_position" property="orgPosition"/>
        <result column="estate_pid" property="estatePid"/>
        <result column="estate_pid_name" property="estatePidName"/>
        <result column="estate_position" property="estatePosition"/>
        <result column="region_province" property="regionProvince"/>
        <result column="region_city" property="regionCity"/>
        <result column="region_area" property="regionArea"/>
        <result column="region" property="region"/>
        <result column="address" property="address"/>
        <result column="total_unit_number" property="totalUnitNumber"/>
        <result column="total_room_number" property="totalRoomNumber"/>
        <result column="total_user_number" property="totalUserNumber"/>
        <result column="unit_number" property="unitNumber"/>
        <result column="room_number" property="roomNumber"/>
        <result column="user_number" property="userNumber"/>
        <result column="user_face_number" property="userFaceNumber"/>
        <result column="person_name" property="personName"/>
        <result column="person_tel" property="personTel"/>
        <result column="remark" property="remark"/>
        <result column="open_evacuate_time" property="openEvacuateTime"/>
        <result column="create_account_id" property="createAccountId"/>
        <result column="create_date" property="createDate"/>
        <result column="creator_type" property="creatorType"/>
        <result column="is_assign" property="isAssign"/>
        <result column="latitude" property="latitude"/>
        <result column="longitude" property="longitude"/>
        <result column="estate_pid_phone" property="estatePidPhone"/>
        <result column="floor_number" property="floorNumber"/>
        <result column="pic" property="pic"/>
        <result column="tenant_id" property="tenantId"/>
        <result column="boundary_path" property="boundaryPath"/>
        <result column="inhabitant_id" property="inhabitantId"/>
        <result column="area_inhabitant_id" property="areaInhabitantId"/>
    </resultMap>


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

    <select id="getListWithYtelevatorXq" resultMap="residentialResultMap">
        SELECT * FROM estate_residential
        WHERE id in (SELECT DISTINCT residential_id FROM `yt_elevator`)
        and is_deleted = 0
    </select>

    <update id="updateNumberById">
        UPDATE estate_residential set
        building_number = (SELECT COUNT(*) FROM estate_building WHERE residential_id = #{residentialId} and is_deleted = 0),
        unit_number = (SELECT COUNT(*) FROM estate_unit WHERE residential_id = #{residentialId} and is_deleted = 0),
        floor_number = (SELECT COUNT(*) FROM estate_floor WHERE residential_id = #{residentialId} and is_deleted = 0),
        room_number = (SELECT COUNT(*) FROM estate_room WHERE residential_id = #{residentialId} and is_deleted = 0)
        WHERE id = #{residentialId};
    </update>

</mapper>
