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

    <sql id="Base_Column_List">
            id as id,
            sensor_code as sensorCode,
            sub_type as subType,
            day as day,
            val as val
    </sql>

	<delete id="deleteCurveSensorEntityList">
		delete from curve_sensor_entity 
		where main_tree_id = #{dto.mainTreeId} and day = #{day}
		<if test="dto.sensorCode != null and dto.sensorCode != ''">
			and sensor_code = #{dto.sensorCode}
		</if>
		<if test="subType != null and subType != ''">
			and sub_type = #{subType}
		</if>
	</delete>

	<select id="getHistoryPointList" resultType="com.huatek.busi.vo.curve.PointItemVo">
		SELECT
		  p.time as timeStamp,
		  IFNULL(p.val,'') as val,
		  IFNULL(p.extend_vala,'') as extendVala,
		  IFNULL(p.extend_valb,'') as extendValb,
		  IFNULL(p.extend_valc,'') as extendValc
		FROM curve_sensor_entity t,
		     curve_sensor_point_entity p
		WHERE t.id = p.ref_id
		AND t.sensor_code = #{dto.sensorCode}
		<if test="subType != null and subType != ''">
			AND t.sub_type = #{subType}
		</if>
		AND t.day &gt;= #{dto.startDate}
		AND t.day &lt;= #{dto.endDate}
		ORDER BY p.time ASC
	</select>

	<select id="getTrendPointList" resultType="com.huatek.busi.vo.curve.CurveSensorEntityVo">
		SELECT
		  t.day as day,
		  t.val as val
		FROM curve_sensor_entity t
		<where>
			and t.main_tree_id = #{dto.mainTreeId}
			<if test="dto.sensorCode != null and dto.sensorCode != ''">
				AND t.sensor_code = #{dto.sensorCode}
			</if>
			<if test="subType != null and subType != ''">
				AND t.sub_type = #{subType}
			</if>
			AND t.day &gt;= #{dto.startDate}
			AND t.day &lt;= #{dto.endDate}
		</where>
		ORDER BY t.day ASC
	</select>
</mapper>