<?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.business.warning.mapper.RtuWarningMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="rtuWarningInfoEntityResultMap"
               type="org.springblade.modules.business.warning.entity.RtuWarningInfoEntity">
        <result column="rtu_code" property="rtuCode"/>
        <result column="warning_kind" property="warningKind"/>
        <result column="warning_desc" property="warningDesc"/>
        <result column="warning_happen_time" property="warningHappenTime"/>
        <result column="warning_recovery_time" property="warningRecoveryTime"/>
        <result column="warning_status" property="warningStatus"/>
        <result column="data_from_id" property="dataFromId"/>
        <result column="rtu_last_up_time" property="rtuLastUpTime"/>
    </resultMap>

    <!-- 通用查询映射结果 -->
    <resultMap id="rtuWarningInfoVOResultMap" type="org.springblade.modules.business.warning.vo.RtuWarningInfoVO">
        <result column="rtu_code" property="rtuCode"/>
        <result column="warning_kind" property="warningKind"/>
        <result column="warning_desc" property="warningDesc"/>
        <result column="warning_happen_time" property="warningHappenTime"/>
        <result column="warning_recovery_time" property="warningRecoveryTime"/>
        <result column="warning_status" property="warningStatus"/>
        <result column="data_from_id" property="dataFromId"/>
        <result column="rtu_last_up_time" property="rtuLastUpTime"/>
        <result column="rtu_name" property="rtuName"/>
        <result column="ad_city" property="adCity"/>
        <result column="ad_dist" property="adDist"/>
        <result column="ancestors" property="ancestors"/>
        <result column="adcd" property="adCode"/>
    </resultMap>


    <select id="selectPage" resultMap="rtuWarningInfoVOResultMap">
        SELECT
        w.*, r.rtu_name,r.ad_city,r.ad_dist,a.ancestors,a.adcd
        FROM
        data_warning_info w
        LEFT JOIN rtu_info r ON r.rtu_code = w.rtu_code
        LEFT JOIN data_ad_cd_b a ON a.adcd = r.ad_code and a.is_deleted=0
        WHERE
        w.is_deleted = 0
        <if test="rtuWarningInfoDTO.rtuCode!=null">
            and r.rtu_code like concat(concat('%', #{rtuWarningInfoDTO.rtuCode}), '%')
        </if>
        <if test="rtuWarningInfoDTO.rtuName!=null">
            and r.rtu_name like concat(concat('%', #{rtuWarningInfoDTO.rtuName}), '%')
        </if>
        <if test="rtuWarningInfoDTO.warningStatus!=null">
            and w.warning_status = #{rtuWarningInfoDTO.warningStatus}
        </if>
        <if test="rtuWarningInfoDTO.adCode!=null">
            and (a.adcd =#{rtuWarningInfoDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE ancestors  like concat(concat('%', #{rtuWarningInfoDTO.adCode}), '%')))
        </if>
        order by w.warning_happen_time desc
    </select>

    <select id="selectOfflinePage" resultMap="rtuWarningInfoVOResultMap">
        SELECT
        w.*, r.rtu_name,r.ad_city,r.ad_dist,a.ancestors,a.adcd
        FROM
        data_warning_info w
        LEFT JOIN rtu_info r ON r.rtu_code = w.rtu_code
        LEFT JOIN data_ad_cd_b a ON a.adcd = r.ad_code and a.is_deleted=0
        WHERE
        w.is_deleted = 0 and w.warning_status = 0 and w.warning_kind = 1
        <if test="rtuWarningInfoDTO.rtuCode!=null">
            and r.rtu_code like concat(concat('%', #{rtuWarningInfoDTO.rtuCode}), '%')
        </if>
        <if test="rtuWarningInfoDTO.rtuName!=null">
            and r.rtu_name like concat(concat('%', #{rtuWarningInfoDTO.rtuName}), '%')
        </if>
        <if test="rtuWarningInfoDTO.adCode!=null">
            and (a.adcd =#{rtuWarningInfoDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE ancestors  like concat(concat('%', #{rtuWarningInfoDTO.adCode}), '%')))
        </if>
        order by w.warning_happen_time desc
    </select>

    <select id="selectClockPage" resultMap="rtuWarningInfoVOResultMap">
        SELECT
        w.*, r.rtu_name,r.ad_city,r.ad_dist,a.ancestors,a.adcd
        FROM
        data_warning_info w
        LEFT JOIN rtu_info r ON r.rtu_code = w.rtu_code
        LEFT JOIN data_ad_cd_b a ON a.adcd = r.ad_code and a.is_deleted=0
        WHERE
        w.is_deleted = 0 and w.warning_status = 0 and w.warning_kind = 2
        <if test="rtuWarningInfoDTO.rtuCode!=null">
            and r.rtu_code like concat(concat('%', #{rtuWarningInfoDTO.rtuCode}), '%')
        </if>
        <if test="rtuWarningInfoDTO.rtuName!=null">
            and r.rtu_name like concat(concat('%', #{rtuWarningInfoDTO.rtuName}), '%')
        </if>
        <if test="rtuWarningInfoDTO.adCode!=null">
            and (a.adcd =#{rtuWarningInfoDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE ancestors  like concat(concat('%', #{rtuWarningInfoDTO.adCode}), '%')))
        </if>
        order by w.warning_happen_time desc
    </select>

    <select id="selectHourMissOutPage" resultMap="rtuWarningInfoVOResultMap">
        SELECT
        w.*, r.rtu_name,r.ad_city,r.ad_dist,a.ancestors,a.adcd
        FROM
        data_warning_info w
        LEFT JOIN rtu_info r ON r.rtu_code = w.rtu_code
        LEFT JOIN data_ad_cd_b a ON a.adcd = r.ad_code and a.is_deleted=0
        WHERE
        w.is_deleted = 0 and w.warning_status = 0 and (w.warning_kind = 3 or  w.warning_kind = 4)
        <if test="rtuWarningInfoDTO.rtuCode!=null">
            and r.rtu_code like concat(concat('%', #{rtuWarningInfoDTO.rtuCode}), '%')
        </if>
        <if test="rtuWarningInfoDTO.rtuName!=null">
            and r.rtu_name like concat(concat('%', #{rtuWarningInfoDTO.rtuName}), '%')
        </if>
        <if test="rtuWarningInfoDTO.adCode!=null">
            and (a.adcd =#{rtuWarningInfoDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE ancestors  like concat(concat('%', #{rtuWarningInfoDTO.adCode}), '%')))
        </if>
        order by w.warning_happen_time desc
    </select>

    <select id="selectRainHourMissOutPage" resultMap="rtuWarningInfoVOResultMap">
        SELECT
        w.*, r.rtu_name,r.ad_city,r.ad_dist,a.ancestors,a.adcd
        FROM
        data_warning_info w
        LEFT JOIN rtu_info r ON r.rtu_code = w.rtu_code
        LEFT JOIN data_ad_cd_b a ON a.adcd = r.ad_code and a.is_deleted=0
        WHERE
        w.is_deleted = 0 and w.warning_status = 0 and w.warning_kind = 3
        <if test="rtuWarningInfoDTO.rtuCode!=null">
            and r.rtu_code like concat(concat('%', #{rtuWarningInfoDTO.rtuCode}), '%')
        </if>
        <if test="rtuWarningInfoDTO.rtuName!=null">
            and r.rtu_name like concat(concat('%', #{rtuWarningInfoDTO.rtuName}), '%')
        </if>
        <if test="rtuWarningInfoDTO.adCode!=null">
            and (a.adcd =#{rtuWarningInfoDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE ancestors  like concat(concat('%', #{rtuWarningInfoDTO.adCode}), '%')))
        </if>
        order by w.warning_happen_time desc
    </select>

    <select id="selectRiverHourMissOutPage" resultMap="rtuWarningInfoVOResultMap">
        SELECT
        w.*, r.rtu_name,r.ad_city,r.ad_dist,a.ancestors,a.adcd
        FROM
        data_warning_info w
        LEFT JOIN rtu_info r ON r.rtu_code = w.rtu_code
        LEFT JOIN data_ad_cd_b a ON a.adcd = r.ad_code and a.is_deleted=0
        WHERE
        w.is_deleted = 0 and w.warning_status = 0 and w.warning_kind = 4
        <if test="rtuWarningInfoDTO.rtuCode!=null">
            and r.rtu_code like concat(concat('%', #{rtuWarningInfoDTO.rtuCode}), '%')
        </if>
        <if test="rtuWarningInfoDTO.rtuName!=null">
            and r.rtu_name like concat(concat('%', #{rtuWarningInfoDTO.rtuName}), '%')
        </if>
        <if test="rtuWarningInfoDTO.adCode!=null">
            and (a.adcd =#{rtuWarningInfoDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE ancestors  like concat(concat('%', #{rtuWarningInfoDTO.adCode}), '%')))
        </if>
        order by w.warning_happen_time desc
    </select>

    <select id="selectMinUpDelayPage" resultMap="rtuWarningInfoVOResultMap">
        SELECT
        w.*, r.rtu_name,r.ad_city,r.ad_dist,a.ancestors,a.adcd
        FROM
        data_warning_info w
        LEFT JOIN rtu_info r ON r.rtu_code = w.rtu_code
        LEFT JOIN data_ad_cd_b a ON a.adcd = r.ad_code and a.is_deleted=0
        WHERE
        w.is_deleted = 0 and w.warning_status = 0 and w.warning_kind = 5
        <if test="rtuWarningInfoDTO.rtuCode!=null">
            and r.rtu_code like concat(concat('%', #{rtuWarningInfoDTO.rtuCode}), '%')
        </if>
        <if test="rtuWarningInfoDTO.rtuName!=null">
            and r.rtu_name like concat(concat('%', #{rtuWarningInfoDTO.rtuName}), '%')
        </if>
        <if test="rtuWarningInfoDTO.adCode!=null">
            and (a.adcd =#{rtuWarningInfoDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE ancestors  like concat(concat('%', #{rtuWarningInfoDTO.adCode}), '%')))
        </if>
        order by w.warning_happen_time desc
    </select>


    <select id="selectHourUpDelayPage" resultMap="rtuWarningInfoVOResultMap">
        SELECT
        w.*, r.rtu_name,r.ad_city,r.ad_dist,a.ancestors,a.adcd
        FROM
        data_warning_info w
        LEFT JOIN rtu_info r ON r.rtu_code = w.rtu_code
        LEFT JOIN data_ad_cd_b a ON a.adcd = r.ad_code and a.is_deleted=0
        WHERE
        w.is_deleted = 0 and w.warning_status = 0  and (w.warning_kind = 6 or  w.warning_kind = 7)
        <if test="rtuWarningInfoDTO.rtuCode!=null">
            and r.rtu_code like concat(concat('%', #{rtuWarningInfoDTO.rtuCode}), '%')
        </if>
        <if test="rtuWarningInfoDTO.rtuName!=null">
            and r.rtu_name like concat(concat('%', #{rtuWarningInfoDTO.rtuName}), '%')
        </if>
        <if test="rtuWarningInfoDTO.adCode!=null">
            and (a.adcd =#{rtuWarningInfoDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE ancestors  like concat(concat('%', #{rtuWarningInfoDTO.adCode}), '%')))
        </if>
        order by w.warning_happen_time desc
    </select>

    <select id="selectRainHourUpDelayPage" resultMap="rtuWarningInfoVOResultMap">
        SELECT
        w.*, r.rtu_name,r.ad_city,r.ad_dist,a.ancestors,a.adcd
        FROM
        data_warning_info w
        LEFT JOIN rtu_info r ON r.rtu_code = w.rtu_code
        LEFT JOIN data_ad_cd_b a ON a.adcd = r.ad_code and a.is_deleted=0
        WHERE
        w.is_deleted = 0 and w.warning_status = 0  and w.warning_kind = 6
        <if test="rtuWarningInfoDTO.rtuCode!=null">
            and r.rtu_code like concat(concat('%', #{rtuWarningInfoDTO.rtuCode}), '%')
        </if>
        <if test="rtuWarningInfoDTO.rtuName!=null">
            and r.rtu_name like concat(concat('%', #{rtuWarningInfoDTO.rtuName}), '%')
        </if>
        <if test="rtuWarningInfoDTO.adCode!=null">
            and (a.adcd =#{rtuWarningInfoDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE ancestors  like concat(concat('%', #{rtuWarningInfoDTO.adCode}), '%')))
        </if>
        order by w.warning_happen_time desc
    </select>


    <select id="selectRiverHourUpDelayPage" resultMap="rtuWarningInfoVOResultMap">
        SELECT
        w.*, r.rtu_name,r.ad_city,r.ad_dist,a.ancestors,a.adcd
        FROM
        data_warning_info w
        LEFT JOIN rtu_info r ON r.rtu_code = w.rtu_code
        LEFT JOIN data_ad_cd_b a ON a.adcd = r.ad_code and a.is_deleted=0
        WHERE
        w.is_deleted = 0 and w.warning_status = 0  and w.warning_kind = 7
        <if test="rtuWarningInfoDTO.rtuCode!=null">
            and r.rtu_code like concat(concat('%', #{rtuWarningInfoDTO.rtuCode}), '%')
        </if>
        <if test="rtuWarningInfoDTO.rtuName!=null">
            and r.rtu_name like concat(concat('%', #{rtuWarningInfoDTO.rtuName}), '%')
        </if>
        <if test="rtuWarningInfoDTO.adCode!=null">
            and (a.adcd =#{rtuWarningInfoDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE ancestors  like concat(concat('%', #{rtuWarningInfoDTO.adCode}), '%')))
        </if>
        order by w.warning_happen_time desc
    </select>

    <select id="selectOutlierValuePage" resultMap="rtuWarningInfoVOResultMap">
        SELECT
        w.*, r.rtu_name,r.ad_city,r.ad_dist,a.ancestors,a.adcd
        FROM
        data_warning_info w
        LEFT JOIN rtu_info r ON r.rtu_code = w.rtu_code
        LEFT JOIN data_ad_cd_b a ON a.adcd = r.ad_code and a.is_deleted=0
        WHERE
        w.is_deleted = 0 and w.warning_status = 0  and w.warning_kind = 8
        <if test="rtuWarningInfoDTO.rtuCode!=null">
            and r.rtu_code like concat(concat('%', #{rtuWarningInfoDTO.rtuCode}), '%')
        </if>
        <if test="rtuWarningInfoDTO.rtuName!=null">
            and r.rtu_name like concat(concat('%', #{rtuWarningInfoDTO.rtuName}), '%')
        </if>
        <if test="rtuWarningInfoDTO.adCode!=null">
            and (a.adcd =#{rtuWarningInfoDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE ancestors  like concat(concat('%', #{rtuWarningInfoDTO.adCode}), '%')))
        </if>
        order by w.warning_happen_time desc
    </select>

    <select id="warningRtuCount" resultType="java.lang.Long">
        SELECT count(*) FROM
        ( SELECT
        w.rtu_code
        FROM
        data_warning_info w
        LEFT JOIN rtu_info r ON w.rtu_code = r.rtu_code and r.is_deleted=0
        LEFT JOIN data_ad_cd_b a ON a.adcd = r.ad_code and a.is_deleted=0
        WHERE
        w.is_deleted = 0
        <if test="rtuWarningInfoDTO.adCode!=null">
            and (a.adcd =#{rtuWarningInfoDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE ancestors  like concat(concat('%', #{rtuWarningInfoDTO.adCode}), '%')))
        </if>
        and w.warning_status = 0
        group by w.rtu_code ) a
    </select>

    <select id="warningOfflineRtuCount" resultType="java.lang.Long">
        SELECT count(*) FROM
        ( SELECT
        w.rtu_code
        FROM
        data_warning_info w
        LEFT JOIN rtu_info r ON w.rtu_code = r.rtu_code and r.is_deleted=0
        LEFT JOIN data_ad_cd_b a ON a.adcd = r.ad_code and a.is_deleted=0
        WHERE
        w.is_deleted = 0
        and w.warning_kind = 1
        <if test="rtuWarningInfoDTO.adCode!=null">
            and (a.adcd =#{rtuWarningInfoDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE ancestors  like concat(concat('%', #{rtuWarningInfoDTO.adCode}), '%')))
        </if>
        and w.warning_status = 0
        group by w.rtu_code ) a
    </select>

    <select id="warningClockRtuCount" resultType="java.lang.Long">
        SELECT count(*) FROM
        ( SELECT
        w.rtu_code
        FROM
        data_warning_info w
        LEFT JOIN rtu_info r ON w.rtu_code = r.rtu_code and r.is_deleted=0
        LEFT JOIN data_ad_cd_b a ON a.adcd = r.ad_code and a.is_deleted=0
        WHERE
        w.is_deleted = 0
        and w.warning_kind = 2
        <if test="rtuWarningInfoDTO.adCode!=null">
            and (a.adcd =#{rtuWarningInfoDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE ancestors  like concat(concat('%', #{rtuWarningInfoDTO.adCode}), '%')))
        </if>
        and w.warning_status = 0
        group by w.rtu_code ) a
    </select>

    <select id="warningRainHourMissOutRtuCount" resultType="java.lang.Long">
        SELECT count(*) FROM
        ( SELECT
        w.rtu_code
        FROM
        data_warning_info w
        LEFT JOIN rtu_info r ON w.rtu_code = r.rtu_code and r.is_deleted=0
        LEFT JOIN data_ad_cd_b a ON a.adcd = r.ad_code and a.is_deleted=0
        WHERE
        w.is_deleted = 0
        and w.warning_kind = 3
        <if test="rtuWarningInfoDTO.adCode!=null">
            and (a.adcd =#{rtuWarningInfoDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE ancestors  like concat(concat('%', #{rtuWarningInfoDTO.adCode}), '%')))
        </if>
        and w.warning_status = 0
        group by w.rtu_code ) a
    </select>

    <select id="warningRiverHourMissOutRtuCount" resultType="java.lang.Long">
        SELECT count(*) FROM
        ( SELECT
        w.rtu_code
        FROM
        data_warning_info w
        LEFT JOIN rtu_info r ON w.rtu_code = r.rtu_code and r.is_deleted=0
        LEFT JOIN data_ad_cd_b a ON a.adcd = r.ad_code and a.is_deleted=0
        WHERE
        w.is_deleted = 0
        and w.warning_kind = 4
        <if test="rtuWarningInfoDTO.adCode!=null">
            and (a.adcd =#{rtuWarningInfoDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE ancestors  like concat(concat('%', #{rtuWarningInfoDTO.adCode}), '%')))
        </if>
        and w.warning_status = 0
        group by w.rtu_code ) a
    </select>

    <select id="warningHourMissOutRtuCount" resultType="java.lang.Long">
        SELECT count(*) FROM
        ( SELECT
        w.rtu_code
        FROM
        data_warning_info w
        LEFT JOIN rtu_info r ON w.rtu_code = r.rtu_code and r.is_deleted=0
        LEFT JOIN data_ad_cd_b a ON a.adcd = r.ad_code and a.is_deleted=0
        WHERE
        w.is_deleted = 0
        and (w.warning_kind = 3 or  w.warning_kind = 4)
        <if test="rtuWarningInfoDTO.adCode!=null">
            and (a.adcd =#{rtuWarningInfoDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE ancestors  like concat(concat('%', #{rtuWarningInfoDTO.adCode}), '%')))
        </if>
        and w.warning_status = 0
        group by w.rtu_code ) a
    </select>

    <select id="warningMinUpDelayRtuCount" resultType="java.lang.Long">
        SELECT count(*) FROM
        ( SELECT
        w.rtu_code
        FROM
        data_warning_info w
        LEFT JOIN rtu_info r ON w.rtu_code = r.rtu_code and r.is_deleted=0
        LEFT JOIN data_ad_cd_b a ON a.adcd = r.ad_code and a.is_deleted=0
        WHERE
        w.is_deleted = 0
        and w.warning_kind = 5
        <if test="rtuWarningInfoDTO.adCode!=null">
            and (a.adcd =#{rtuWarningInfoDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE ancestors  like concat(concat('%', #{rtuWarningInfoDTO.adCode}), '%')))
        </if>
        and w.warning_status = 0
        group by w.rtu_code ) a
    </select>

    <select id="warningHourUpDelayRtuCount" resultType="java.lang.Long">
        SELECT count(*) FROM
        ( SELECT
        w.rtu_code
        FROM
        data_warning_info w
        LEFT JOIN rtu_info r ON w.rtu_code = r.rtu_code and r.is_deleted=0
        LEFT JOIN data_ad_cd_b a ON a.adcd = r.ad_code and a.is_deleted=0
        WHERE
        w.is_deleted = 0
        and (w.warning_kind = 6 or  w.warning_kind = 7)
        <if test="rtuWarningInfoDTO.adCode!=null">
            and (a.adcd =#{rtuWarningInfoDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE ancestors  like concat(concat('%', #{rtuWarningInfoDTO.adCode}), '%')))
        </if>
        and w.warning_status = 0
        group by w.rtu_code ) a
    </select>

    <select id="warningRainHourUpDelayRtuCount" resultType="java.lang.Long">
        SELECT count(*) FROM
        ( SELECT
        w.rtu_code
        FROM
        data_warning_info w
        LEFT JOIN rtu_info r ON w.rtu_code = r.rtu_code and r.is_deleted=0
        LEFT JOIN data_ad_cd_b a ON a.adcd = r.ad_code and a.is_deleted=0
        WHERE
        w.is_deleted = 0
        and w.warning_kind = 6
        <if test="rtuWarningInfoDTO.adCode!=null">
            and (a.adcd =#{rtuWarningInfoDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE ancestors  like concat(concat('%', #{rtuWarningInfoDTO.adCode}), '%')))
        </if>
        and w.warning_status = 0
        group by w.rtu_code ) a
    </select>

    <select id="warningRiverHourUpDelayRtuCount" resultType="java.lang.Long">
        SELECT count(*) FROM
        ( SELECT
        w.rtu_code
        FROM
        data_warning_info w
        LEFT JOIN rtu_info r ON w.rtu_code = r.rtu_code and r.is_deleted=0
        LEFT JOIN data_ad_cd_b a ON a.adcd = r.ad_code and a.is_deleted=0
        WHERE
        w.is_deleted = 0
        and w.warning_kind = 7
        <if test="rtuWarningInfoDTO.adCode!=null">
            and (a.adcd =#{rtuWarningInfoDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE ancestors  like concat(concat('%', #{rtuWarningInfoDTO.adCode}), '%')))
        </if>
        and w.warning_status = 0
        group by w.rtu_code ) a
    </select>

    <select id="warningOutlierValueRtuCount" resultType="java.lang.Long">
        SELECT count(*) FROM
        ( SELECT
        w.rtu_code
        FROM
        data_warning_info w
        LEFT JOIN rtu_info r ON w.rtu_code = r.rtu_code and r.is_deleted=0
        LEFT JOIN data_ad_cd_b a ON a.adcd = r.ad_code and a.is_deleted=0
        WHERE
        w.is_deleted = 0
        and w.warning_kind = 8
        <if test="rtuWarningInfoDTO.adCode!=null">
            and (a.adcd =#{rtuWarningInfoDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE ancestors  like concat(concat('%', #{rtuWarningInfoDTO.adCode}), '%')))
        </if>
        and w.warning_status = 0
        group by w.rtu_code ) a
    </select>
</mapper>
