<?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="com.njcn.prepare.harmonic.mapper.mysql.line.RMpVThdMapper">

    <insert id="insertRate">
        INSERT INTO r_mp_v_thd ( measurement_point_id, data_type, data_date, v_thd) VALUES
            ( #{item.lineId}, #{item.dataType}, #{item.dataDate}, #{item.vThd}   )
            ON DUPLICATE KEY UPDATE v_thd = #{item.vThd}
    </insert>

    <select id="getVThdData" resultType="com.njcn.harmonic.pojo.po.RMpVThd">
        select
            line_id measurementPointId,
            max(v_thd) vThd,
            `time` dataDate,
            '0' dataType
        from
            r_stat_data_v_d
        where
            `time` = #{time}
            and phasic_type in ('A', 'B', 'C')
            and value_type = 'CP95'
            <if test="lineList != null and lineList.size() > 0">
                and line_id in
                <foreach collection="lineList" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
        group by line_id, `time`
    </select>
</mapper>
