<?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.huatek.busi.mapper.GisLoacurrentdWaveformMapper">

    <sql id="Base_Column_List">
            phase as phase,
            site_id as siteId,
            load_waveform as loadWaveform,
            action as action
    </sql>

    <select id="selectGisLoacurrentdWaveformPage" parameterType="com.huatek.busi.dto.GisLoacurrentdWaveformDto" resultType="com.huatek.busi.vo.GisLoacurrentdWaveformVo">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        gis_loacurrentd_waveform t
        WHERE 1=1
        <if test="phase != null and phase != ''">
             and t.phase = #{phase}
        </if>
        <if test="siteId != null and siteId != ''">
             and t.site_id = #{siteId}
        </if>
        <if test="loadWaveform != null">
             and t.load_waveform = #{loadWaveform}
        </if>
        <if test="action != null and action != ''">
             and t.action = #{action}
        </if>
    </select>

	<select id="findSensorCodeList" resultType="com.huatek.busi.dto.curve.BaseCurveQueryDto">
		SELECT DISTINCT
			t.sensor_id as sensorCode,
			t.main_tree_id as mainTreeId,
			count(*) as count
		FROM gis_loacurrentd_waveform t
		WHERE t.time_stamp &gt;= #{startTime} and t.time_stamp &lt; #{endTime}
		GROUP BY t.sensor_id, t.main_tree_id
	</select>

	<select id="findDaylyPointList" resultType="com.huatek.busi.vo.curve.PointItemVo">
		SELECT
			t.sensor_id as sensorCode,
			t.time_stamp as timeStamp,
			CAST(t.${subType} AS decimal(20, 4)) as val
		FROM gis_loacurrentd_waveform t
		WHERE t.main_tree_id = #{dto.mainTreeId}
		<if test="dto.sensorCode != null and dto.sensorCode != ''">
			AND t.sensor_id = #{dto.sensorCode}
		</if>
			AND t.time_stamp &gt;= #{startTime}
			AND t.time_stamp &lt; #{endTime}
		ORDER BY t.time_stamp ASC
	</select>

	<select id="getDaylyPointStatistics" resultType="com.huatek.busi.dto.curve.PointItemDto">
		SELECT
			t.main_tree_id AS mainTreeId,
			t.sensor_id AS sensorCode,
			COUNT(*) AS count,
			CAST(SUM(t.${subType}) AS decimal(20, 4)) AS total,
			MAX(CAST(t.${subType} AS decimal(20, 4))) AS max,
			MIN(CAST(t.${subType} AS decimal(20, 4))) AS min
		FROM gis_loacurrentd_waveform t
		WHERE t.main_tree_id = #{mainTreeId}
		<if test="sensorCode != null and sensorCode != ''">
			AND t.sensor_id = #{sensorCode}
		</if>
			AND t.time_stamp &gt;= #{startTime} 
			AND t.time_stamp &lt;= #{endTime}
	</select>
</mapper>