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

	<delete id="deleteOneDayData">
		delete from capacitance_equipment_summary where d_time = #{day}
	</delete>

	<select id="getOneDayData" resultType="java.util.Map">
		SELECT
		DISTINCT
		  t.site_id AS siteId,
		  t.main_tree_id AS mainTreeId,
		  t.sub_tree_id AS subTreeId,
		  t.main_equipment_id AS mainEquipmentId,
		  t.sub_equipment_id AS subEquipmentId
		FROM capacitance_equipment_im t
		WHERE t.time_stamp &gt;= #{startTime}
		AND t.time_stamp &lt; #{endTime}
	</select>

	<select id="getAvgData" resultType="java.util.Map">
		SELECT
			CAST(AVG(t.total_current) AS decimal(20, 8)) AS fullCurrent,
			CAST(AVG(t.capacitance) AS decimal(20, 8)) AS capacitance,
			CAST(AVG(t.loss_factor) AS decimal(20, 8)) AS lossFactor
		FROM capacitance_equipment_im t
		WHERE t.site_id = #{siteId}
			AND t.main_tree_id = #{mainTreeId}
			AND t.sub_tree_id = #{subTreeId}
			AND t.main_equipment_id = #{mainEquipmentId}
			AND t.sub_equipment_id = #{subEquipmentId}
		<choose>
			<when test="phase eq 'A'.toString()">
				AND t.phase LIKE 'A%'
			</when>
			<when test="phase eq 'B'.toString()">
				AND t.phase LIKE 'B%'
			</when>
			<when test="phase eq 'C'.toString()">
				AND t.phase LIKE 'C%'
			</when>
		</choose>
		LIMIT 1
	</select>

	<select id="getAvgSystemVoltageData" resultType="java.util.Map">
		SELECT
		CAST(AVG(t.system_voltage) AS decimal(20, 8)) AS systemVoltage
		FROM capacitance_equipment_im t
		WHERE t.site_id = #{siteId}
		AND t.main_tree_id = #{mainTreeId}
		AND t.sub_tree_id = #{subTreeId}
		AND t.main_equipment_id = #{mainEquipmentId}
		AND t.sub_equipment_id = #{subEquipmentId}
	</select>
</mapper>