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

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

    <select id="selectList" resultMap="rtuRsvrDataEntityResultMap">
        SELECT
        w.*
        FROM
        data_att_st_res_ware 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="selectLast" resultMap="rtuRsvrDataEntityResultMap">
        SELECT
        w.*
        FROM
        data_att_st_res_ware w
        WHERE
        w.is_deleted = 0
        <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 desc limit 1
    </select>

</mapper>
