<?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.transfer.mapper.DamageTransferPersonInfoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="transferPersonResultMap"
               type="org.springblade.modules.yjxt.business.transfer.entity.DamageTransferPersonInfoEntity">
        <result column="warn_id" property="warnId"/>
        <result column="person_name" property="personName"/>
        <result column="person_id" property="personId"/>
        <result column="remark" property="remark"/>
        <result column="keep_photos" property="keepPhotos"/>
    </resultMap>

    <resultMap id="transferPersonVOResultMap"
               type="org.springblade.modules.yjxt.business.transfer.vo.DamageTransferPersonInfoVO">
        <result column="warn_id" property="warnId"/>
        <result column="person_name" property="personName"/>
        <result column="person_id" property="personId"/>
        <result column="remark" property="remark"/>
        <result column="keep_photos" property="keepPhotos"/>
        <result column="record_person_name" property="recordPersonName"/>
        <result column="record_time" property="recordTime"/>
    </resultMap>

    <select id="selectPage" resultMap="transferPersonVOResultMap">
        SELECT
        r.id,p.warn_id,p.person_name as record_person_name,p.remark,p.keep_photos,p.create_time as record_time,r.person_name,r.person_id
        FROM
        yjxt_danger_area_resident_info r
        LEFT JOIN yjxt_damage_transfer_person_info p on p.person_id = r.person_id and  p.person_name = r.person_name and p.is_deleted = 0
        WHERE
        r.is_deleted = 0
        <if test="dto.warnId!=null">
            and (p.warn_id =  #{dto.warnId} or p.warn_id is null)
        </if>
        <if test="dto.dangerAreaCode!=null">
            and  FIND_IN_SET(r.danger_area_pid ,#{dto.dangerAreaCode}) >0
        </if>
        ORDER BY
        p.warn_id desc,r.person_name
    </select>

    <select id="transferPersonCount" resultType="java.lang.Long">
        SELECT
        count(n.person_id)
        FROM
        yjxt_damage_transfer_person_info n
        WHERE
        n.is_deleted = 0
        <if test="dto.warnId!=null">
            and n.warn_id = #{dto.warnId}
        </if>
    </select>

</mapper>
