<?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.yeejoin.amos.boot.module.hygf.api.tdenginemapper.TdHygfJpInvertorElecHistoryMapper">
	<select id="dayList" resultType="com.yeejoin.amos.boot.module.hygf.api.dto.TdHygfJpInvertorElecHistoryDto">
		SELECT * FROM house_pv_data.td_hygf_jp_invertor_elec_history
		<where>
			<if test="snCode!=null">
			AND `sn_code` = #{snCode}
		    </if>
			<if test="thirdStationId!=null">
			AND `third_station_id` = #{thirdStationId}
		    </if>
			<if test="startTime!=null and endTime!=null">
			AND time BETWEEN #{startTime} AND #{endTime}
			</if>
		</where>
	</select>
	<select id="monthList" resultType="com.yeejoin.amos.boot.module.hygf.api.dto.JpInvertorElecHistoryMonthDto">
		SELECT * FROM house_pv_data.td_hygf_jp_invertor_elec_history_month
		<where>
			<if test="snCode!=null">
			AND `sn_code` = #{snCode}
		    </if>
			<if test="thirdStationId!=null">
			AND `third_station_id` = #{thirdStationId}
		    </if>
			<if test="month!=null">
			AND year_month = #{month}
			</if>
		</where>
	</select>
	<select id="yearList" resultType="com.yeejoin.amos.boot.module.hygf.api.dto.JpInvertorElecHistoryYearDto">
		SELECT * FROM house_pv_data.td_hygf_jp_invertor_elec_history_year
		<where>
			<if test="snCode!=null">
			AND `sn_code` = #{snCode}
		    </if>
			<if test="thirdStationId!=null">
			AND `third_station_id` = #{thirdStationId}
		    </if>
			<if test="year!=null">
			AND year = #{year}
			</if>
		</where>
	</select>
	<select id="allList" resultType="com.yeejoin.amos.boot.module.hygf.api.dto.JpInvertorElecHistoryAllDto">
		SELECT * FROM house_pv_data.td_hygf_jp_invertor_elec_history_all
		<where>
			<if test="snCode!=null">
			AND `sn_code` = #{snCode}
		    </if>
			<if test="thirdStationId!=null">
			AND `third_station_id` = #{thirdStationId}
		    </if>
		</where>
	</select>
	<select id="dayToMonth" resultType="Map">
		SELECT sn_code,AVG(u_ac_voltage) AS u_ac_voltage,AVG(v_ac_voltage) AS v_ac_voltage,AVG(w_ac_voltage) AS w_ac_voltage,
		AVG(u_ac_current) AS u_ac_current,AVG(v_ac_current) AS v_ac_current,AVG(w_ac_current) AS w_ac_current,third_station_id,third_code FROM house_pv_data.td_hygf_jp_invertor_elec_history
		<where>
			<if test="startTime!=null and endTime!=null">
			AND time &gt;= #{startTime} AND time &lt;= #{endTime}
			</if>
		</where>
		GROUP BY sn_code,third_station_id,third_code
	</select>
	<select id="monthToYear" resultType="Map">
		SELECT sn_code,AVG(u_ac_voltage) AS u_ac_voltage,AVG(v_ac_voltage) AS v_ac_voltage,AVG(w_ac_voltage) AS w_ac_voltage,
		AVG(u_ac_current) AS u_ac_current,AVG(v_ac_current) AS v_ac_current,AVG(w_ac_current) AS w_ac_current,third_station_id,third_code FROM house_pv_data.td_hygf_jp_invertor_elec_history_month
		<where>
			<if test="month!=null">
			AND year_month = #{month}
			</if>
		</where>
		GROUP BY sn_code,third_station_id,third_code
	</select>
	<select id="yearToAll" resultType="Map">
		SELECT sn_code,AVG(u_ac_voltage) AS u_ac_voltage,AVG(v_ac_voltage) AS v_ac_voltage,AVG(w_ac_voltage) AS w_ac_voltage,
		AVG(u_ac_current) AS u_ac_current,AVG(v_ac_current) AS v_ac_current,AVG(w_ac_current) AS w_ac_current,third_station_id,third_code FROM house_pv_data.td_hygf_jp_invertor_elec_history_year
		<where>
			<if test="year!=null">
			AND year = #{year}
			</if>
		</where>
		GROUP BY sn_code,third_station_id,third_code
	</select>
	<insert id="updateMonth">
		INSERT INTO house_pv_data.td_hygf_jp_invertor_elec_history_month VALUES
		<foreach collection="list" item="item" index="index" separator=",">
             (#{item.created_time},#{item.sn_code},#{item.u_ac_voltage},#{item.v_ac_voltage},#{item.w_ac_voltage},
             #{item.u_ac_current},#{item.v_ac_current},#{item.w_ac_current},#{item.third_station_id},#{item.third_code},#{item.day},#{item.year_month})
        </foreach>
	</insert>
	<insert id="updateYear">
		INSERT INTO house_pv_data.td_hygf_jp_invertor_elec_history_year VALUES
		<foreach collection="list" item="item" index="index" separator=",">
             (#{item.created_time},#{item.sn_code},#{item.u_ac_voltage},#{item.v_ac_voltage},#{item.w_ac_voltage},
             #{item.u_ac_current},#{item.v_ac_current},#{item.w_ac_current},#{item.third_station_id},#{item.third_code},#{item.month},#{item.year})
        </foreach>
	</insert>
	<insert id="updateAll">
		INSERT INTO house_pv_data.td_hygf_jp_invertor_elec_history_all VALUES
		<foreach collection="list" item="item" index="index" separator=",">
             (#{item.created_time},#{item.sn_code},#{item.u_ac_voltage},#{item.v_ac_voltage},#{item.w_ac_voltage},
             #{item.u_ac_current},#{item.v_ac_current},#{item.w_ac_current},#{item.third_station_id},#{item.third_code},#{item.year})
        </foreach>
	</insert>
</mapper>
