<?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.warn.mapper.OriginalWarningMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="rtuWarningInfoEntityResultMap"
               type="org.springblade.modules.yjxt.business.warn.entity.OriginalWarningInfoEntity">
        <result column="warn_id" property="warnId"/>
        <result column="stcd" property="stcd"/>
        <result column="warn_name" property="warnName"/>
        <result column="warn_time" property="warnTime"/>
        <result column="warn_level_code" property="warnLevelCode"/>
        <result column="warn_info" property="warnInfo"/>
        <result column="warn_status" property="warnStatus"/>
        <result column="review_status" property="reviewStatus"/>
        <result column="type" property="type"/>
        <result column="remark" property="remark"/>
        <result column="rain_warn_rate" property="rainWarnRate"/>
        <result column="warn_sort" property="warnSort"/>
        <result column="warn_location" property="warnLocation"/>
        <result column="warn_adcd" property="warnAdcd"/>
        <result column="user_adcd" property="userAdcd"/>
        <result column="warn_lgtd" property="warnLgtd"/>
        <result column="warn_lttd" property="warnLttd"/>
        <result column="intv" property="intv"/>
        <result column="drp" property="drp"/>
        <result column="z" property="z"/>
        <result column="q" property="q"/>
        <result column="wptn" property="wptn"/>
        <result column="rz" property="rz"/>
        <result column="rwptn" property="rwptn"/>
        <result column="inq" property="inq"/>
        <result column="rel_warn_id" property="relWarnId"/>
        <result column="warn_qr_url" property="warnQrUrl"/>
    </resultMap>

    <select id="selectPage" resultMap="rtuWarningInfoEntityResultMap">
        SELECT
        n.*
        FROM
        data_st_warning_info n
        LEFT JOIN base_data_ad_cd a ON a.adcd = n.warn_adcd and a.is_deleted = 0
        WHERE
        n.is_deleted = 0
        <if test="entity.reviewStatus!=null">
            and (n.review_status is null or  n.review_status != #{entity.reviewStatus})
        </if>
        <if test="entity.type!=null">
            and n.type = #{entity.type}
        </if>
        <if test="entity.warnName!=null ">
            and n.warn_name LIKE concat(concat('%', #{entity.warnName}), '%')
        </if>
        <if test="entity.dangerAreaName!=null ">
            and a.adnm LIKE concat(concat('%', #{entity.dangerAreaName}), '%')
        </if>
        <if test="entity.warnAdcd!=null and entity.warnAdcd!=''">
            and (a.adcd =#{entity.warnAdcd} or  FIND_IN_SET(#{entity.warnAdcd} ,a.ancestors) >0 )
        </if>
        order by n.warn_time desc
    </select>

    <select id="selectDangerAreaList" resultMap="rtuWarningInfoEntityResultMap">
        SELECT w.* FROM data_st_warning_info w
        LEFT JOIN map_danger_area_info a on a.adcd = w.warn_adcd and a.is_deleted = 0
        WHERE
        w.is_deleted = 0
        <if test="dto.startTime!=null">
            and w.warn_time &gt;=  #{dto.startTime}
        </if>
        <if test="dto.endTime!=null">
            and w.warn_time  &lt;  #{dto.endTime}
        </if>
        <if test="dto.warnLevelCode!=null">
            and w.warn_level_code =#{dto.warnLevelCode}
        </if>
        <if test="dto.dangerAreaPid!=null">
            and a.danger_area_pid = #{dto.dangerAreaPid}
        </if>
        order by w.warn_time desc
    </select>
</mapper>
