<?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.modules.yjxt.business.resident.mapper.DangerAreaResidentInfoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="desidentResultMap" type="org.springblade.modules.yjxt.business.resident.entity.DangerAreaResidentInfoEntity">

        <result column="person_id" property="personId"/>
        <result column="person_name" property="personName"/>
        <result column="is_householder" property="isHouseholder"/>
        <result column="householder_id" property="householderId"/>
        <result column="danger_area_code" property="dangerAreaCode"/>


    </resultMap>

    <resultMap id="residentVOResultMap" type="org.springblade.modules.yjxt.business.resident.vo.DangerAreaResidentInfoVO">

        <result column="person_id" property="personId"/>
        <result column="person_name" property="personName"/>
        <result column="is_householder" property="isHouseholder"/>
        <result column="householder_id" property="householderId"/>
        <result column="danger_area_code" property="dangerAreaCode"/>


    </resultMap>

    <select id="selectPage" resultMap="residentVOResultMap">

        SELECT
        n.*
        FROM
        yjxt_danger_area_resident_info n
        WHERE
        n.is_deleted = 0
        <if test="dto.householderId!=null">
            and (n.householder_id = #{dto.householderId} || n.person_id = #{dto.householderId})
        </if>
        <if test="dto.dangerAreaCode!=null">
            and n.danger_area_code = #{dto.dangerAreaCode}
        </if>
        ORDER BY
        n.person_id
    </select>

    <select id="residentCount" resultType="java.lang.Long">
        SELECT
        count(n.person_id)
        FROM
        yjxt_danger_area_resident_info n
        WHERE
        n.is_deleted = 0
        <if test="dto.householderId != null">
            and (n.householder_id = #{dto.householderId} || n.person_id = #{dto.householderId})
        </if>
        <if test="dto.dangerAreaCode!=null">
            and n.danger_area_code = #{dto.dangerAreaCode}
        </if>
    </select>

    <select id="getFamilyMembers" resultMap="desidentResultMap">
        SELECT
        n.*
        FROM
        yjxt_danger_area_resident_info n
        WHERE
        n.is_deleted = 0
        <if test="dto.personId!=null">
            and (n.person_id =  #{dto.personId} or n.householder_id = #{dto.personId})
        </if>
        ORDER BY
        n.person_id
    </select>
</mapper>
