<?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.KescoMapper">

		<!-- 해당 부분의 id는 MapperClass의 함수 이름과 유사하여야 합니다. -->
	    <sql id="commonPagingHeader"  >
	      SELECT R1.* FROM (
	    </sql>
	    
	    <sql id="commonPagingFooter"  >
	      ) R1 LIMIT #{pgtl.startNo}, #{pgtl.listPerPage}
	    </sql>    
	     		
	    <select id="selectListCount"  parameterType="com.elt.ems.vo.KescoDataVo" resultType="integer">
	
			select count(k.seq) as count 
			from t_kesco_data k, t_plant p
			where k.plantSeq = p.seq
			and sendStatus = #{sendStatus}
			and k.inputDate &gt;= #{str1} and k.inputDate &lt;= #{str2}
			<if test="inputHour != null and inputHour != '' "> and k.inputHour = #{inputHour}</if>
			<if test="plantName != null and plantName != '' "> and p.name like concat('%', #{plantName}, '%')</if>
			<if test="plantSeq > 0"> and p.seq = #{plantSeq}</if>
			
	    </select>
	    		
	    <select id="selectList"  parameterType="com.elt.ems.vo.KescoDataVo" resultType="com.elt.ems.vo.KescoDataVo">
	
	      <if test="pgtl != null">
	        <include refid="commonPagingHeader" /> 
	      </if>
	
			select p.name as plantName, k.*
			from t_kesco_data k, t_plant p
			where k.plantSeq = p.seq
			and sendStatus = #{sendStatus}
			and k.inputDate &gt;= #{str1} and k.inputDate &lt;= #{str2}
			<if test="inputHour != null"> and k.inputHour = #{inputHour}</if>
			<if test="plantName != null and plantName != '' "> and p.name like concat('%', #{plantName}, '%')</if>
			<if test="plantSeq > 0"> and p.seq = #{plantSeq}</if>
			order by k.inputDate desc, k.inputHour desc, k.plantSeq asc	
			
	      <if test="pgtl != null">
	        <include refid="commonPagingFooter" />
	      </if>
	      
	    </select>
	    
	    <select id="selectListTimetable"  parameterType="com.elt.ems.vo.TimetableKescoVo" resultType="com.elt.ems.vo.TimetableKescoVo">
	
	      <if test="pgtl != null">
	        <include refid="commonPagingHeader" /> 
	      </if>
	
			select *
			from t_timetable_kesco k
			where k.inputDate = #{inputDate} 
			order by k.inputDate desc, k.inputHour desc	
			
	      <if test="pgtl != null">
	        <include refid="commonPagingFooter" />
	      </if>
	      
	    </select>	    
	    						
		
	</mapper>