<?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.RtuDataRsvrMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="rtuRsvrDataEntityResultMap" type="org.springblade.modules.business.data.entity.RtuDataRsvrEntity">
        <result column="rtu_code" property="rtuCode"/>
        <result column="tm" property="tm"/>
        <result column="rz" property="rz"/>
        <result column="from_time" property="fromTime"/>
    </resultMap>

    <resultMap id="rtuRsvrDataVOResultMap" type="org.springblade.modules.business.data.vo.RtuDataRsvrVO">
        <result column="rtu_code" property="rtuCode"/>
        <result column="tm" property="tm"/>
        <result column="rz" property="rz"/>
        <result column="rtu_name" property="rtuName"/>
        <result column="ad_city" property="adCity"/>
        <result column="ad_dist" property="adDist"/>
        <result column="from_time" property="fromTime"/>
    </resultMap>


    <select id="selectPage" resultMap="rtuRsvrDataVOResultMap">
        SELECT
        n.*,
        r.rtu_name,r.ad_city,r.ad_dist
        FROM
        data_att_st_res_ware_cache n
        LEFT JOIN  rtu_info r ON n.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
        n.is_deleted = 0
        <if test="rsvrDTO.rtuName!=null ">
            and r.rtu_name LIKE concat(concat('%', #{rsvrDTO.rtuName}), '%')
        </if>
        <if test="rsvrDTO.rtuCode!=null">
            and n.rtu_code like concat(concat('%', #{rsvrDTO.rtuCode}), '%')
        </if>
        <if test="rsvrDTO.excludeCode!=null and rsvrDTO.excludeCode==1">
            and a.exclude_ad = 0
        </if>
        <if test="rsvrDTO.adCode!=null">
            and (a.adcd =#{rsvrDTO.adCode} or a.ancestors in (SELECT ancestors FROM data_ad_cd_b WHERE is_deleted =0 and ancestors like concat(concat('%', #{rsvrDTO.adCode}), '%')))
        </if>
    </select>
</mapper>
