<?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.check.mapper.DangerAreaCheckInfoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="checkResultMap" type="org.springblade.modules.yjxt.business.check.entity.DangerAreaCheckInfoEntity">
        <result column="check_type" property="checkType"/>
        <result column="warn_id" property="warnId"/>
        <result column="latitude" property="latitude"/>
        <result column="longitude" property="longitude"/>
        <result column="address" property="address"/>
        <result column="is_flood" property="isFlood"/>
        <result column="is_damage" property="isDamage"/>
        <result column="is_warn" property="isWarn"/>
        <result column="warn_info" property="warnInfo"/>
        <result column="is_transfer" property="isTransfer"/>
        <result column="transfer_info" property="transferInfo"/>
        <result column="remark" property="remark"/>
        <result column="check_photos" property="checkPhotos"/>
        <result column="danger_area_pid" property="dangerAreaPid"/>
        <result column="adcd" property="adcd"/>
        <result column="river_name" property="riverName"/>
    </resultMap>

    <resultMap id="checkVOResultMap" type="org.springblade.modules.yjxt.business.check.vo.DangerAreaCheckInfoVO">
        <result column="check_type" property="checkType"/>
        <result column="warn_id" property="warnId"/>
        <result column="latitude" property="latitude"/>
        <result column="longitude" property="longitude"/>
        <result column="address" property="address"/>
        <result column="is_flood" property="isFlood"/>
        <result column="is_damage" property="isDamage"/>
        <result column="is_warn" property="isWarn"/>
        <result column="warn_info" property="warnInfo"/>
        <result column="is_transfer" property="isTransfer"/>
        <result column="transfer_info" property="transferInfo"/>
        <result column="remark" property="remark"/>
        <result column="check_photos" property="checkPhotos"/>
        <result column="danger_area_pid" property="dangerAreaPid"/>
        <result column="adcd" property="adcd"/>
        <result column="river_name" property="riverName"/>
        <result column="adnm" property="adName"/>
        <result column="danger_area_name" property="dangerAreaName"/>
    </resultMap>

    <select id="selectPage" resultMap="checkVOResultMap">
        SELECT
        p.*,a.adnm,d.danger_area_name
        FROM
        yjxt_danger_area_check_info p
        LEFT JOIN base_data_ad_cd a ON a.adcd = p.adcd and a.is_deleted=0
        LEFT JOIN map_danger_area_info d ON d.danger_area_pid = p.danger_area_pid and d.is_deleted=0
        WHERE
        p.is_deleted = 0
        <if test="dto.adcd!=null and dto.adcd!=''">
            and (a.adcd =#{dto.adcd} or  FIND_IN_SET(#{dto.adcd} ,a.ancestors) >0 )
        </if>
        <if test="dto.dangerAreaPid!=null">
            and p.danger_area_pid = #{dto.dangerAreaPid}
        </if>
        <if test="dto.warnId!=null">
            and p.warn_id = #{dto.warnId}
        </if>
        order by p.create_time desc
    </select>

</mapper>
