<?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.upcount.mapper.RtuUpCountMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="rtuRainDataResultMap" type="org.springblade.modules.business.upcount.entity.RtuUpCountInfoEntity">
        <result column="rtu_code" property="rtuCode"/>
        <result column="count_time" property="countTime"/>
        <result column="up_kind" property="upKind"/>
        <result column="time_kind" property="timeKind"/>

    </resultMap>


    <select id="upCount" resultType="java.lang.Long">

        SELECT
        sum(w.up_count)
        FROM
        data_rtu_up_count 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.count_time >= #{dto.beginTime}
        AND w.count_time &lt; #{dto.endTime}
        <if test="dto.countTime!=null">
            and w.time_kind = #{dto.countTime}
        </if>
        <if test="dto.upKind!=null">
            and a.up_kind = #{dto.upKind}
        </if>
        <if test="dto.excludeCode!=null and dto.excludeCode==1">
            and a.exclude_ad = 0
        </if>
        <if test="dto.adCode!=null">
            and (a.adcd =#{dto.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE is_deleted =0 and
            ancestors like concat(concat('%', #{dto.adCode}), '%')))
        </if>

    </select>

</mapper>
