<?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.TdHygfJpCollectorHistoryMapper">
	<select id="dayList" resultType="com.yeejoin.amos.boot.module.hygf.api.dto.TdHygfJpCollectorHistoryDto">
		SELECT * FROM house_pv_data.td_hygf_jp_collector_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 &gt;= #{startTime} AND time &lt;= #{endTime}
			</if>
		</where>
	</select>
	<select id="monthList" resultType="com.yeejoin.amos.boot.module.hygf.api.dto.JpCollectorHistoryMonthDto">
		SELECT * FROM house_pv_data.td_hygf_jp_collector_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.JpCollectorHistoryYearDto">
		SELECT * FROM house_pv_data.td_hygf_jp_collector_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.JpCollectorHistoryAllDto">
		SELECT * FROM house_pv_data.td_hygf_jp_collector_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(signal_strength) AS signal_strength,third_station_id,third_code  FROM house_pv_data.td_hygf_jp_collector_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(signal_strength) AS signal_strength,third_station_id,third_code  FROM house_pv_data.td_hygf_jp_collector_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(signal_strength) AS signal_strength,third_station_id,third_code  FROM house_pv_data.td_hygf_jp_collector_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_collector_history_month VALUES
		<foreach collection="list" item="item" index="index" separator=",">
             (#{item.created_time},#{item.sn_code},#{item.signal_strength},#{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_collector_history_year VALUES
		<foreach collection="list" item="item" index="index" separator=",">
             (#{item.created_time},#{item.sn_code},#{item.signal_strength},#{item.third_station_id},#{item.third_code},#{item.month},#{item.year})
        </foreach>
	</insert>
	<insert id="updateAll">
		INSERT INTO house_pv_data.td_hygf_jp_collector_history_all VALUES
		<foreach collection="list" item="item" index="index" separator=",">
             (#{item.created_time},#{item.sn_code},#{item.signal_strength},#{item.third_station_id},#{item.third_code},#{item.year})
        </foreach>
	</insert>
</mapper>
