<?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.data.mapper.RtuDataGroundStoreMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="rtuGroundDataResultMap" type="org.springblade.modules.business.data.entity.RtuDataGroundStoreEntity">
        <result column="rtu_code" property="rtuCode"/>
        <result column="tm" property="tm"/>
        <result column="vtavslm" property="vtavslm"/>
        <result column="srlslm" property="srlslm"/>
        <result column="slm10" property="slm10"/>
        <result column="slm20" property="slm20"/>
        <result column="slm30" property="slm30"/>
        <result column="slm40" property="slm40"/>
        <result column="slm50" property="slm50"/>
        <result column="slm40" property="slm40"/>
        <result column="slm60" property="slm60"/>
        <result column="slm80" property="slm80"/>
        <result column="slm100" property="slm100"/>
        <result column="from_time" property="fromTime"/>
    </resultMap>

    <select id="selectList" resultMap="rtuGroundDataResultMap">
        SELECT
        w.*
        FROM
        data_att_st_somo w
        WHERE
        w.is_deleted = 0
        <if test="dto.beginTime!=null">
            AND w.tm >= #{dto.beginTime}
        </if>
        <if test="dto.endTime!=null">
            AND w.tm &lt; #{dto.endTime}
        </if>
        <if test="dto.rtuCode!=null">
            and w.rtu_code = #{dto.rtuCode}
        </if>
        order by w.tm
    </select>

    <select id="rtuUpDataCount" resultType="java.lang.Long">
        SELECT
        count( * )
        FROM
        (
        SELECT
        w.rtu_code
        FROM
        data_att_st_somo 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.tm >= #{groundDTO.beginTime}
        AND w.tm &lt; #{groundDTO.endTime}
        <if test="groundDTO.excludeCode!=null and groundDTO.excludeCode==1">
            and a.exclude_ad = 0
        </if>
        <if test="groundDTO.adCode!=null">
            and (a.adcd =#{groundDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE is_deleted =0 and ancestors like concat(concat('%', #{groundDTO.adCode}), '%')))
        </if>
        GROUP BY
        w.rtu_code
        ) a
    </select>
</mapper>
