<?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">
	 
	<!-- 해당 부분의 namespace는 project package + Mapper Package + Mapper Interface 이름입니다. -->
	<mapper namespace="com.elt.ems.mapper.WeatherMapper">
	
		<sql id="tableName"> t_weather_2021 </sql>

		<!-- 해당 부분의 id는 MapperClass의 함수 이름과 유사하여야 합니다. -->
		<!-- 
		<select id="selectList" parameterType="com.elt.ems.vo.WeatherVo"  resultType="com.elt.ems.vo.WeatherVo">
			select 
			  a.*, p.seq as plantSeq
			from <include refid="tableName" /> a, t_plant p
			where  a.weatherCode = p.weatherCode and p.plantStatus='01'  and a.inputYmd = #{inputYmd}
			and a.inputHour = ( select max(inputHour) from <include refid="tableName" /> where inputYmd=#{inputYmd} )
			order by p.seq desc
		</select>  -->
		 		 
		<select id="selectList" parameterType="com.elt.ems.vo.WeatherVo"  resultType="com.elt.ems.vo.WeatherVo">
			select p.seq as plantSeq, p.name as plantName, w.*
			from <include refid="tableName" /> w, t_plant p
			where w.weatherCode = p.weatherCode and p.plantStatus='01' and inputYmd= #{inputYmd}  
			<if test="inputHour != null and inputHour != '' "> and w.inputHour = ( select max(inputHour) from <include refid="tableName" /> where inputYmd=#{inputYmd} and inputHour &lt;= #{inputHour} ) </if>
			<if test="inputHour == null or inputHour == '' "> and w.inputHour = ( select max(inputHour) from <include refid="tableName" /> where inputYmd=#{inputYmd} ) </if>			
			<if test="plantSeq > 0"> and p.seq = #{plantSeq}</if>
			order by  p.seq desc		        
   		</select>
   		
   		<select id="selectListHour" parameterType="com.elt.ems.vo.WeatherVo"  resultType="com.elt.ems.vo.WeatherVo">
			select 
				inputHour, count(inputHour) as count
			from <include refid="tableName" />
			where inputYmd = #{inputYmd}  
			group by inputHour
			order by inputHour desc		        
   		</select>
   		
   		<select id="selectListByPlantSeq" parameterType="com.elt.ems.vo.WeatherVo"  resultType="com.elt.ems.vo.WeatherVo">
			select p.seq as plantSeq, p.name as plantName, w.*
			from <include refid="tableName" /> w, t_plant p
			where w.weatherCode = p.weatherCode and p.plantStatus='01' and inputYmd= #{inputYmd}  and p.seq = #{plantSeq}			
			order by  w.inputHour desc		        
   		</select>
   		
	    <select id="listWeatherDay"  parameterType="com.elt.ems.vo.WeatherVo" resultType="com.elt.ems.common.CaseSensibleHashMap">
			select inputYmd, inputHour, count(weatherCode) as count
			from  <include refid="tableName" />
			where inputYmd = #{inputYmd} 
			group by inputYmd, inputHour	

	    </select>
	       	
	    <select id="selectMaxWeather"  parameterType="com.elt.ems.vo.WeatherVo" resultType="com.elt.ems.vo.WeatherVo">
	
			select inputYmd, inputHour, count(inputYmd) as count
			from <include refid="tableName" />
			where inputYmd =  #{inputYmd}  and inputHour =  ( select max(inputHour) from <include refid="tableName" /> where inputYmd = #{inputYmd} )
	      
	    </select> 
	    	       		
		
	</mapper>