<?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.IvtMapper">
		
		<!-- 해당 부분의 id는 MapperClass의 함수 이름과 유사하여야 합니다. -->
	    <sql id="commonPagingHeader"  >
	      SELECT R1.* FROM (
	    </sql>
	    
	    <sql id="commonPagingFooter"  >
	      ) R1 LIMIT #{pgtl.startNo}, #{pgtl.listPerPage}
	    </sql> 
	    
	    <sql id="includePlantSeqs"  >
	      and p.seq in ( ${plantSeqs} )
	    </sql>
	    
	     <sql id="tableNameWeather"> t_weather_2021 </sql>
	     
	    <!--  /monitoring/solar_list.co :: ivt & pms -->
	    <select id="selectListAdmin" parameterType="com.elt.ems.vo.SolarIvtJuncOverviewVo"  resultType="com.elt.ems.common.CaseSensibleHashMap">
			select p.*, d.pvPower, d.dayPvPower, d.createDatetime as pmsDatetime from (
			
				select p.*, s.inputDate as lastday, s.todayEnergy as lastdayEnergy, s.todayHours as lastdayHours from (
			
					select p.*, o.oseq, o.plantSeq, o.inputDate, o.inputHour, o.inputMinute, o.currPower, o.todayEnergy, o.todayHours, o.lifetimeEnergy, o.ovStatus, o.createDatetime as ivtDatetime 
					from (
						select p.seq, p.name, p.supplyPower, p.plantType, p.plantStatus, p.geox , p.geoy, v.link, v.url1, v.url2, v.port, v.key1, v.key2, v.ivtQuantity, v.ivtType, v.syncType
						from t_plant p left join t_ivtjunc v
						on p.seq = v.plantSeq
						where p.plantType in ('02', '03') 	
						<if test="clientOrderSeq > 0 "> and p.clientOrderSeq = #{clientOrderSeq}</if>
						<if test="plantStatus != null and plantStatus != '-1' "> and p.plantStatus = #{plantStatus}</if>   
						<if test="ivtStatus != null and ivtStatus != '-1' "> and v.ivtStatus = #{ivtStatus}</if>
						<if test="plantSeq > 0 "> and p.seq = #{plantSeq}</if>
						<if test="plantSeqs != null and plantSeqs != '' "><include refid="includePlantSeqs" /></if>
					) p left join t_ivtoverview o 
					on p.seq = o.plantSeq and o.oseq = ( 
							select max(oseq) as oseq from t_ivtoverview where inputDate=#{inputDate} and plantSeq = p.seq 
							<if test="inputHour != null and inputHour != '' "> and inputHour = #{inputHour}</if> 
					) 
				) p left join t_ivtoverview_day s
				on p.seq = s.plantSeq and s.inputDate = DATE_ADD(p.inputDate, INTERVAL -1 DAY)
			) p left join t_pmsdata_${realtimeYear} d 
			on p.seq = d.plantSeq and d.inputDate=#{inputDate} and d.seq = ( 
				select max(seq) as seq from t_pmsdata_${realtimeYear} where plantSeq = p.seq and inputDate=#{inputDate}
				<if test="inputHour != null and inputHour != '' "> and inputHour = #{inputHour}</if> 
			) order by p.seq desc 				    
   		</select>
   		
   		<!--  /solar/slide.co  :: ivt  -->
	    <select id="selectListFront" parameterType="com.elt.ems.vo.SolarIvtJuncOverviewVo"  resultType="com.elt.ems.common.CaseSensibleHashMap">

			select p.*, s.inputDate as lastday, s.todayEnergy as lastdayEnergy, s.todayHours as lastdayHours from (
		
				select p.*, o.oseq, o.plantSeq, o.inputDate, o.inputHour, o.inputMinute, o.currPower, o.todayEnergy, o.todayHours, o.lifetimeEnergy, o.ovStatus, o.createDatetime as ivtDatetime 
				from (
					select p.seq, p.name, p.supplyPower, p.plantType, v.link, v.url1, v.url2, v.port, v.key1, v.key2, v.ivtQuantity, v.ivtType
					from t_plant p left join t_ivtjunc v
					on p.seq = v.plantSeq
					where p.plantType in ('02', '03') 
					<if test="plantSeq > 0 "> and p.seq = #{plantSeq}</if>	 
					<if test="clientOrderSeq > 0 "> and p.clientOrderSeq = #{clientOrderSeq}</if>
					<if test="plantStatus != null and plantStatus != '-1' "> and p.plantStatus = #{plantStatus}</if>   
					<if test="ivtStatus != null and ivtStatus != '-1' "> and v.ivtStatus = #{ivtStatus}</if>
					<if test="plantSeqs != null and plantSeqs != '' "><include refid="includePlantSeqs" /></if>
				) p left join t_ivtoverview o 
				on p.seq = o.plantSeq and o.oseq = ( 
						select max(oseq) as oseq from t_ivtoverview where inputDate=#{inputDate} and plantSeq = p.seq 
						<if test="inputHour != null and inputHour != '' "> and inputHour = #{inputHour}</if> 
				) 
			) p left join t_ivtoverview_day s
			on p.seq = s.plantSeq and s.inputDate = DATE_ADD(p.inputDate, INTERVAL -1 DAY)
			order by p.seq desc 				    
   		</select>   		
   		
   		<!--  /solar/view.co -->
	    <select id="selectOverviewFront" parameterType="com.elt.ems.vo.SolarIvtJuncOverviewVo"  resultType="com.elt.ems.vo.SolarIvtJuncOverviewForm">

			select p.*, s.inputDate as lastday, s.todayEnergy as lastdayEnergy, s.todayHours as lastdayHours from (
			
				select p.*, o.oseq, o.plantSeq, o.inputDate, o.inputHour, o.inputMinute, o.currPower, o.todayEnergy, o.todayHours, o.lifetimeEnergy, o.ovStatus, o.createDatetime as ivtDatetime 
				from (
					select p.seq, p.name as plantName, p.supplyPower, p.plantType, v.link, v.url1, v.url2, v.ivtQuantity, v.ivtType
					from t_plant p left join t_ivtjunc v
					on p.seq = v.plantSeq
					where p.plantType in ('02', '03')  and p.seq = #{plantSeq}
					<if test="plantStatus != null and plantStatus != '-1' "> and p.plantStatus = #{plantStatus}</if>   
					<if test="ivtStatus != null and ivtStatus != '-1' "> and v.ivtStatus = #{ivtStatus}</if>					
				) p left join t_ivtoverview o 
				on p.seq = o.plantSeq and o.plantSeq = #{plantSeq} and o.inputDate=#{inputDate}
				<if test="oseq > 0 "> and o.oseq = #{oseq}</if> 
			) p left join t_ivtoverview_day s
			on p.seq = s.plantSeq and s.inputDate = DATE_ADD(p.inputDate, INTERVAL -1 DAY)
			<if test="orderby == null or orderby == '' "> order by p.seq desc, p.oseq asc</if> 
			<if test="orderby != null and orderby != '' "> order by p.seq desc, p.oseq desc</if>			 			    
   		</select>
   		   		
   		<!--  /solar/profitMonth.co -->   		 
   		<select id="selectOverviewFrontMonth" parameterType="com.elt.ems.vo.SearchMapVo"  resultType="com.elt.ems.vo.SolarIvtJuncOverviewForm">
			SELECT a.inputDate, sum(a.todayEnergy) as todayEnergy, sum(a.todayHours) as todayHours
			FROM (
				SELECT inputDate, todayEnergy, todayHours FROM t_ivtoverview_day 
				WHERE plantSeq = #{plantSeq} and inputDate BETWEEN #{str1} and #{str2}
				union
				SELECT inputDate, todayEnergy, todayHours FROM t_ivtoverview_hour
				WHERE seq = (SELECT max(seq) FROM emswdb.t_ivtoverview_hour WHERE plantSeq = #{plantSeq} and inputDate=#{inputDate} )
			) a			 			   
   		</select>
   		   		   		
   		<!--  /data/ivt/list_overview.co, /monitoring/solar_overview.co, /monitoring/solar_ivt.co -->
	    <select id="selectListOverviewByPlantSeq" parameterType="com.elt.ems.vo.SolarIvtJuncOverviewVo"  resultType="com.elt.ems.vo.SolarIvtJuncOverviewForm">
	    <!-- 
			select p.*, d.pvPower, d.dayPvPower, d.createDatetime as pmsDatetime from (
		 -->	
				select p.*, s.inputDate as lastday, s.todayEnergy as lastdayEnergy, s.todayHours as lastdayHours from (
				
					select p.*, o.oseq, o.plantSeq, o.inputDate, o.inputHour, o.inputMinute, o.currPower, o.todayEnergy, o.todayHours, o.lifetimeEnergy, o.ovStatus, o.createDatetime as ivtDatetime 
					from (
						select p.seq, p.name as plantName, p.supplyPower, p.plantType, v.link, v.url1, v.url2, v.ivtQuantity, v.ivtType
						from t_plant p left join t_ivtjunc v
						on p.seq = v.plantSeq
						where p.plantType in ('02', '03')  and p.seq = #{plantSeq}
						<if test="plantStatus != null and plantStatus != '-1' "> and p.plantStatus = #{plantStatus}</if>   
						<if test="ivtStatus != null and ivtStatus != '-1' "> and v.ivtStatus = #{ivtStatus}</if>					
					) p left join t_ivtoverview o 
					on p.seq = o.plantSeq and o.plantSeq = #{plantSeq} and o.inputDate=#{inputDate}
					<if test="oseq > 0 "> and o.oseq = #{oseq}</if> 
				) p left join t_ivtoverview_day s
				on p.seq = s.plantSeq and s.inputDate = DATE_ADD(p.inputDate, INTERVAL -1 DAY)
			<!-- 				
			) p left join t_pmsdata_${realtimeYear} d 
			on p.seq = d.plantSeq and d.inputDate=#{inputDate} and 
			    d.seq = ( 
				  select max(seq) as seq from t_pmsdata_${realtimeYear} where plantSeq = p.seq and inputDate=#{inputDate} and inputHour = p.inputHour and inputMinute like concat('%', substring(p.inputMinute, 1, 1), '%') and plantSeq = #{plantSeq}
			)
 			-->			
			<if test="orderby == null or orderby == '' "> order by p.seq desc, p.oseq asc</if> 
			<if test="orderby != null and orderby != '' "> order by p.seq desc, p.oseq desc</if>			 			    
   		</select>
   		

   		
   		<select id="selectListOverviewMonth" parameterType="com.elt.ems.vo.SolarIvtJuncOverviewForm"  resultType="com.elt.ems.vo.SolarIvtJuncOverviewForm">
			select o1.*, o.seq as oseq, o.monthEnergy as todayEnergy, o.monthHours as todayHours, o.lifetimeEnergy 
            from ( 
				select p.seq as plantSeq, p.name as plantName, p.clientOrderSeq, o.inputMonth 
			    from t_plant p, ( 
					select o1.inputMonth, o.plantSeq from ( 
						select inputMonth from t_ivtoverview_month 
						where inputYear = #{inputYear}	
						<if test="plantSeq > 0 "> and plantSeq = #{plantSeq}</if>					
						group by inputMonth 
					) o1 CROSS JOIN t_ivtoverview_month o 
			        on  o.inputYear = #{inputYear}	
			        <if test="plantSeq > 0 "> and o.plantSeq = #{plantSeq}</if>
			        group by o1.inputMonth, o.plantSeq 
				) o where p.plantType in ('02', '03') and p.plantStatus = '01' and o.plantSeq = p.seq 
				<if test="clientOrderSeq > 0 "> and p.clientOrderSeq = #{clientOrderSeq}</if> 
			    <if test="plantSeq > 0 "> and p.seq = #{plantSeq}</if> 
			    <if test="seqs != null">and p.seq in 
				  <foreach item="seq" collection="seqs" open="(" separator="," close=")">#{seq} </foreach>					
			    </if>      
			) o1 left join t_ivtoverview_month o 
			on o1.plantSeq = o.plantSeq and o1.inputMonth = o.inputMonth and o.inputYear = #{inputYear}	
			group by o1.inputMonth, o1.plantSeq 
			order by o1.inputMonth asc, o1.plantSeq asc     
   		</select> 
   		   		
   		<select id="selectListOverviewDay" parameterType="com.elt.ems.vo.SolarIvtJuncOverviewForm"  resultType="com.elt.ems.vo.SolarIvtJuncOverviewForm">
			select o1.*, o.seq as oseq, o.inputDate, o.todayEnergy, o.todayHours, o.lifetimeEnergy from ( 
				select p.seq as plantSeq, p.name as plantName, p.clientOrderSeq, o.inputDate 
			    from t_plant p, ( 
					select o1.inputDate, o.plantSeq from ( 
						select inputDate from t_ivtoverview_day 
						where inputDate between #{str1} and #{str2} 
						<if test="plantSeq > 0 "> and plantSeq = #{plantSeq}</if>
						group by inputDate 
					) o1 CROSS JOIN t_ivtoverview_day o 
			        on  o.inputDate between #{str1} and #{str2} 
			        <if test="plantSeq > 0 "> and o.plantSeq = #{plantSeq}</if>
			        group by o1.inputDate, o.plantSeq 
				) o where p.plantType in ('02', '03') and p.plantStatus = '01' and o.plantSeq = p.seq 
				<if test="clientOrderSeq > 0 "> and p.clientOrderSeq = #{clientOrderSeq}</if>  
			    <if test="plantSeq > 0 "> and p.seq = #{plantSeq}</if>   
			    <if test="seqs != null">and p.seq in 
				  <foreach item="seq" collection="seqs" open="(" separator="," close=")">#{seq} </foreach>					
			    </if>     
			) o1 left join t_ivtoverview_day o 
			on o1.plantSeq = o.plantSeq and o1.inputDate = o.inputDate and o.inputDate between #{str1} and #{str2}
			group by o1.inputDate, o1.plantSeq 
			order by o1.inputDate asc, o1.plantSeq asc     
   		</select> 
   		   		
   		<!--  /data/ivt/solar_hour.co, /data/solar/chart.co 삭제 후 변경 /data/ivt/chart_all.co -->
   		<select id="selectListOverviewHour" parameterType="com.elt.ems.vo.SolarIvtJuncOverviewForm"  resultType="com.elt.ems.vo.SolarIvtJuncOverviewForm">
			select o1.*, o.seq as oseq, o.inputDate, o.currPower, o.todayEnergy, o.todayHours, o.lifetimeEnergy from ( 
				select p.seq as plantSeq, p.name as plantName, p.clientOrderSeq, o.inputHour 
			    from t_plant p, ( 
					select o1.inputHour, o.plantSeq from ( 
							select inputDate, inputHour from t_ivtoverview_hour where inputDate=#{inputDate} group by inputHour 
			            ) o1 CROSS JOIN t_ivtoverview_hour o 
						on o.inputDate = #{inputDate}
						<if test="plantSeq > 0 "> and o.plantSeq = #{plantSeq}</if>
						group by o1.inputHour, o.plantSeq
				) o
				where p.plantType in ('02', '03') and p.plantStatus = '01' and o.plantSeq = p.seq  
				<if test="clientOrderSeq > 0 "> and p.clientOrderSeq = #{clientOrderSeq}</if> 
				<if test="plantSeq > 0 "> and p.seq = #{plantSeq}</if>   
			    <if test="seqs != null">and p.seq in 
				  <foreach item="seq" collection="seqs" open="(" separator="," close=")">#{seq} </foreach>					
			    </if>         
			) o1 left join t_ivtoverview_hour o 
			on o1.plantSeq = o.plantSeq and o1.inputHour = o.inputHour and o.inputDate = #{inputDate}			
			group by o1.inputHour, o1.plantSeq 			
			order by o1.inputHour asc, o1.plantSeq asc     
   		</select>     		
   		
   		<!--  /data/ivt/solar_list.co  -->
   		<select id="selectListOverviewGroupHour" parameterType="com.elt.ems.vo.SolarIvtJuncOverviewVo"  resultType="com.elt.ems.vo.SolarIvtJuncOverviewForm">
			<!-- select o1.*, o.* from (  --> 
			select o1.inputHour, o1.plantSeq, 
				o.oseq, o.inputMinute, o.currPower, 
				max(o.todayEnergy) as todayEnergy , max(o.todayHours) as todayHours, max(o.lifetimeEnergy) as lifetimeEnergy, 
				o.ovStatus 
			from (
				select o.*, p.clientOrderSeq from (
					select o1.inputHour, o.plantSeq from  (
						select oseq, inputDate, inputHour  
						from t_ivtoverview 
						where inputDate=#{inputDate}
						<if test="plantSeq > 0 "> and plantSeq = #{plantSeq}</if> 
						group by inputHour 
					) o1 CROSS JOIN t_ivtoverview o 
					on o.inputDate = #{inputDate}
					<if test="plantSeq > 0 "> and o.plantSeq = #{plantSeq}</if> 
					group by o1.inputHour, o.plantSeq
				) o, t_plant p
				where o.plantSeq = p.seq and p.plantType in ('02', '03') and plantStatus = '01'
				<if test="clientOrderSeq > 0 "> and p.clientOrderSeq = #{clientOrderSeq}</if>
			) o1 left join t_ivtoverview o 
			on o1.plantSeq = o.plantSeq and o1.inputHour = o.inputHour and o.inputDate = #{inputDate}
			group by inputHour, plantSeq 			
			order by o1.inputHour asc, o1.plantSeq asc 			    
   		</select>  
   		
   		<!--  /json/ivt/notice_list.co  -->
	    <select id="selectPrevCurrPlantList" parameterType="com.elt.ems.vo.SolarIvtJuncOverviewVo"  resultType="com.elt.ems.common.CaseSensibleHashMap">

		    select p.*, w.inputHour, w.temp, w.cloud
			from  (	
			
				select p.*, p1.oseq as prevOseq, p1.inputHour as prevInputHour, p1.inputMinute as prevMinute, p1.currPower as prevCurrPower, TRUNCATE(IFNULL(p1.todayEnergy, 0), 1) as prevTodayEnergy, p1.createDatetime as prevCreateDatetime
				from (
					select p.*, o.oseq, o.plantSeq, o.inputDate, o.inputHour, o.inputMinute, o.currPower, TRUNCATE(IFNULL(o.todayEnergy,0), 1) as todayEnergy, o.todayHours, o.lifetimeEnergy, o.ovStatus, o.createDatetime as ivtDatetime 
					from (
						select p.seq, p.name, p.supplyPower, p.weatherCode
						from t_plant p, t_ivtjunc v
						where p.seq = v.plantSeq and v.ivtStatus='01'
						and p.plantStatus='01' and p.plantType in ('02', '03')
						<if test="clientOrderSeq > 0 "> and p.clientOrderSeq = #{clientOrderSeq}</if>
					) p left join t_ivtoverview o 
						on p.seq = o.plantSeq and o.oseq = ( 
						select max(oseq) as oseq from t_ivtoverview where inputDate = #{inputDate} and plantSeq = p.seq 
					) 
				) p, t_ivtoverview p1
					where p.plantSeq = p1.plantSeq and p1.inputDate = #{inputDate} and p1.oseq = (
						select max(oseq) as oseq from t_ivtoverview where inputDate = #{inputDate} and plantSeq = p.plantSeq and oseq &lt; p.oseq
				)
			)p, <include refid="tableNameWeather" /> w where p.weatherCode = w.weatherCode and w.inputYmd=#{inputDate} and w.inputHour = (
				select max(inputHour) from <include refid="tableNameWeather" /> where inputYmd=#{inputDate} and weatherCode = p.weatherCode
			) and w.cloud &lt; 7
   		</select>
   		
	    <select id="selectPrevCurrIvtList" parameterType="com.elt.ems.vo.SolarIvtJuncOverviewVo"  resultType="com.elt.ems.common.CaseSensibleHashMap">
		    select p.*, w.inputHour, w.temp, w.cloud
			from  (	    
				select p.*, d.ivtIdx as prevIvtIdx, d.dcPower as prevDcPower, TRUNCATE(IFNULL(d.todayEnergy, 0), 1) as prevTodayEnergy, TRUNCATE(IFNULL(d.lifetimeEnergy, 0), 1) as prevLifetimeEnergy
				from  (
					select p.* , o.oseq as prevOseq, o.inputHour as prevInputHour, o.inputMinute as prevInputMinute
					from (
						select p.*, d.ivtIdx, d.dcPower, TRUNCATE(IFNULL(d.todayEnergy, 0), 1) as todayEnergy, TRUNCATE(IFNULL(d.lifetimeEnergy, 0), 1) as lifetimeEnergy
						from  (
							select p.*, o.oseq, o.plantSeq, o.inputHour, o.inputMinute
							from (
								select p.seq, p.name, p.supplyPower, p.weatherCode
								from t_plant p, t_ivtjunc v
								where p.seq = v.plantSeq and v.ivtStatus='01' and v.ivtType='03'
								and p.plantStatus='01' and p.plantType in ('02', '03')
								<if test="clientOrderSeq > 0 "> and p.clientOrderSeq = #{clientOrderSeq}</if>
							) p, t_ivtoverview o
							where p.seq = o.plantSeq and o.oseq = ( 
								select max(oseq) as oseq from t_ivtoverview where inputDate=#{inputDate} and plantSeq = p.seq 
							) 
						) p, t_ivtdata_${realtimeYear} d
						where p.plantSeq = d.plantSeq and d.oseq = p.oseq
					) p, t_ivtoverview o
					where p.seq = o.plantSeq and o.oseq = ( 
						select max(oseq) as oseq from t_ivtoverview where inputDate=#{inputDate} and plantSeq = p.seq  and oseq &lt; p.oseq
					) 				 
				) p, t_ivtdata_${realtimeYear} d
				where p.plantSeq = d.plantSeq and d.oseq = p.prevOseq    
				and p.ivtIdx = d.ivtIdx	
			)p, <include refid="tableNameWeather" /> w where p.weatherCode = w.weatherCode and w.inputYmd=#{inputDate} and w.inputHour = (
				select max(inputHour) from <include refid="tableNameWeather" /> where inputYmd=#{inputDate} and weatherCode = p.weatherCode
			) and w.cloud &lt; 7						    
   		</select>   		
   		   		
	    <select id="selectListWeatherSensorHourPlantSeq" parameterType="com.elt.ems.vo.SolarIvtJuncOverviewForm"  resultType="com.elt.ems.vo.WeatherSensorVo">
			
			select h.*, s.*
			from t_ivtoverview_hour h, 
			(
				select *, DATE_FORMAT(createDatetime, "%H") as inputHour 
				from t_weather_sensor
				where inputDate=#{inputDate}  and plantSeq=#{plantSeq}
				group by inputHour
			) s
			where h.inputDate=#{inputDate}  and h.plantSeq=#{plantSeq}
			and h.plantSeq = s.plantSeq and h.inputHour = s.inputHour
			order by h.inputHour asc						 			  
   		</select> 

   		   		 
   		<select id="selectListStaticHourByMap" parameterType="com.elt.ems.vo.SearchMapVo"  resultType="com.elt.ems.vo.SolarIvtJuncOverviewForm">
			
			select p.name as plantName, p.supplyPower, v.ivtQuantity, d.* 
			from t_ivtoverview_hour d, t_plant p, t_ivtjunc v
			where p.seq = d.plantSeq and p.seq = v.plantSeq and d.inputDate = #{map.inputDate}  
			<if test="map.plantSeq != null and map.plantSeq != '0' "> and d.plantSeq = #{map.plantSeq}</if>
			<if test="map.clientOrderSeq != null and map.clientOrderSeq != '0' "> and p.clientOrderSeq = #{map.clientOrderSeq}</if> 
			order by d.inputDate asc, d.inputHour asc , d.plantSeq desc
						 			   
   		</select>
   		
	    <select id="selectListStaticDayByMap" parameterType="com.elt.ems.vo.SearchMapVo"  resultType="com.elt.ems.vo.SolarIvtJuncOverviewForm">
			
			select p.name as plantName, p.supplyPower, v.ivtQuantity,d.* 
			from t_ivtoverview_day d, t_plant p, t_ivtjunc v
			where p.seq = d.plantSeq and p.seq = v.plantSeq and d.inputDate between #{map.startDate} and #{map.endDate} 
			<if test="map.plantSeq != null and map.plantSeq != '0' "> and d.plantSeq = #{map.plantSeq}</if>	
			<if test="map.clientOrderSeq != null and map.clientOrderSeq != '0' "> and p.clientOrderSeq = #{map.clientOrderSeq}</if>	
			<if test="map.orderby == 'todayEnergy' ">order by d.todayEnergy desc </if>	
			<if test="map.orderby == 'todayHours' ">order by d.todayHours desc </if>
			<if test="map.orderby == 'plantSeq' or map.orderby == '' ">order by d.inputDate asc, d.plantSeq desc </if>
						 			   
   		</select>
   		   		
	    <select id="selectListStaticMonthByMap" parameterType="com.elt.ems.vo.SearchMapVo"  resultType="com.elt.ems.vo.SolarIvtJuncOverviewForm">
			select 
				p.name as plantName, p.supplyPower, v.ivtQuantity, d.seq, d.plantSeq, d.inputYear, d.inputMonth, 
				d.monthEnergy as todayEnergy, d.monthHours as todayHours, lifetimeEnergy, concat(inputYear, '-', inputMonth, '-01') as inputDate 
			from t_ivtoverview_month d, t_plant p, t_ivtjunc v
			where p.seq = d.plantSeq and p.seq = v.plantSeq and d.inputYear = #{map.inputYear}
			<if test="map.plantSeq != null and map.plantSeq != '0' "> and d.plantSeq = #{map.plantSeq}</if>
			<if test="map.clientOrderSeq != null and map.clientOrderSeq != '0'  "> and p.clientOrderSeq = #{map.clientOrderSeq}</if>	
			<if test="map.orderby == 'todayEnergy' ">order by d.monthEnergy desc </if>	
			<if test="map.orderby == 'todayHours' ">order by d.monthHours desc </if>	
			<if test="map.orderby == 'plantSeq' ">order by d.inputMonth asc, d.plantSeq desc</if>
			<if test="map.orderby == null or map.orderby == '' ">order by d.inputMonth asc, d.plantSeq desc</if>
			 			 			   
   		</select>  
   		   		
	    <select id="selectListReportDayByMap" parameterType="com.elt.ems.vo.SearchMapVo"  resultType="com.elt.ems.vo.SolarIvtJuncOverviewForm">
			
			select d.*, count(w.cloud) as count2 from (
				select d.*, count(c.seq) as count1 from (			
					select p.name as plantName, p.supplyPower, p.weatherCode, v.ivtQuantity,d.* 
					from t_ivtoverview_day d, t_plant p, t_ivtjunc v
					where p.seq = d.plantSeq and p.seq = v.plantSeq and d.inputDate between #{map.startDate} and #{map.endDate} 
					<if test="map.plantSeq != null and map.plantSeq != '0' "> and d.plantSeq = #{map.plantSeq}</if>	
					<if test="map.clientOrderSeq != null and map.clientOrderSeq != '0' "> and p.clientOrderSeq = #{map.clientOrderSeq}</if>	
				) d left join t_cs c
				on d.plantSeq = c.plantSeq and d.inputDate = c.inputDate
				group by d.inputDate
			) d left join <include refid="tableNameWeather" /> w
			on d.weatherCode = w.weatherCode and d.inputDate = w.inputYmd and w.cloud > 5
			group by d.inputDate
			<if test="map.orderby == 'todayEnergy' ">order by d.todayEnergy desc </if>	
			<if test="map.orderby == 'todayHours' ">order by d.todayHours desc </if>
			<if test="map.orderby == 'plantSeq' or map.orderby == '' ">order by d.inputDate asc, d.plantSeq desc </if>						 			  
   		</select>
   		
	    <select id="selectListReportMonthByMap" parameterType="com.elt.ems.vo.SearchMapVo"  resultType="com.elt.ems.vo.SolarIvtJuncOverviewForm">
			select d.*, count(w.cloud) as count2 from (
				select d.*, count(c.seq) as count1 from (
					    
					select 
						p.name as plantName, p.supplyPower, p.weatherCode, v.ivtQuantity, d.seq, d.plantSeq, d.inputYear, d.inputMonth, 
						d.monthEnergy as todayEnergy, d.monthHours as todayHours, lifetimeEnergy, concat(inputYear, '-', inputMonth, '-01') as inputDate 
					from t_ivtoverview_month d, t_plant p, t_ivtjunc v
					where p.seq = d.plantSeq and p.seq = v.plantSeq and d.inputYear = #{map.inputYear}
					<if test="map.plantSeq != null and map.plantSeq != '0' "> and d.plantSeq = #{map.plantSeq}</if>
					<if test="map.clientOrderSeq != null and map.clientOrderSeq != '0'  "> and p.clientOrderSeq = #{map.clientOrderSeq}</if>
				) d left join t_cs c     
			    on d.plantSeq = c.plantSeq and c.inputDate like concat(substr(d.inputDate, 1, 7), "-__")
			    group by d.inputMonth    						
			) d left join <include refid="tableNameWeather" /> w
			on d.weatherCode = w.weatherCode and d.inputDate = w.inputYmd and w.cloud > 5
			group by d.inputMonth			
			<if test="map.orderby == 'todayEnergy' ">order by d.monthEnergy desc </if>	
			<if test="map.orderby == 'todayHours' ">order by d.monthHours desc </if>	
			<if test="map.orderby == 'plantSeq' ">order by d.inputMonth asc, d.plantSeq desc</if>
			<if test="map.orderby == null or map.orderby == '' ">order by d.inputMonth asc, d.plantSeq desc</if>
			 			 			   
   		</select>     		
   		   		
	    <select id="selectListStaticHourPlantSeq" parameterType="com.elt.ems.vo.SolarIvtJuncOverviewForm"  resultType="com.elt.ems.vo.SolarIvtJuncOverviewForm">
			
			select p.name as plantName, p.supplyPower, v.ivtQuantity, d.* 
			from t_ivtoverview_hour d, t_plant p, t_ivtjunc v
			where p.seq = d.plantSeq and p.seq = v.plantSeq and d.inputDate = #{inputDate} 
			<if test="plantSeq > 0 "> and d.plantSeq = #{plantSeq}</if>
			<if test="clientOrderSeq > 0 "> and p.clientOrderSeq = #{clientOrderSeq}</if>
			order by d.inputDate asc, d.inputHour asc , d.plantSeq desc
						 			   
   		</select>     		
   		
	    <select id="selectListStaticDayPlantSeq" parameterType="com.elt.ems.vo.SolarIvtJuncOverviewForm"  resultType="com.elt.ems.vo.SolarIvtJuncOverviewForm">
			
			select p.name as plantName, p.supplyPower, v.ivtQuantity,d.* 
			from t_ivtoverview_day d, t_plant p, t_ivtjunc v
			where p.seq = d.plantSeq and p.seq = v.plantSeq and d.inputDate between #{str1} and #{str2} 
			<if test="plantSeq > 0 "> and d.plantSeq = #{plantSeq}</if>	
			<if test="clientOrderSeq > 0 "> and p.clientOrderSeq = #{clientOrderSeq}</if>	
			<if test="orderby == 'todayEnergy' ">order by d.todayEnergy desc </if>	
			<if test="orderby == 'todayHours' ">order by d.todayHours desc </if>
			<if test="orderby == 'plantSeq' or orderby == '' ">order by d.inputDate asc, d.plantSeq desc </if>
						 			   
   		</select>
   		   		
	    <select id="selectListStaticMonthPlantSeq" parameterType="com.elt.ems.vo.SolarIvtJuncOverviewForm"  resultType="com.elt.ems.vo.SolarIvtJuncOverviewForm">
			select 
				p.name as plantName, p.supplyPower, v.ivtQuantity, d.seq, d.plantSeq, d.inputYear, d.inputMonth, 
				d.monthEnergy as todayEnergy, d.monthHours as todayHours, lifetimeEnergy, concat(inputYear, '-', inputMonth, '-01') as inputDate 
			from t_ivtoverview_month d, t_plant p, t_ivtjunc v
			where p.seq = d.plantSeq and p.seq = v.plantSeq and d.inputYear = substr(#{str1}, 1, 4) and d.inputMonth between substr(#{str1}, 6, 2) and substr(#{str2}, 6, 2) 
			<if test="plantSeq > 0 "> and d.plantSeq = #{plantSeq}</if>
			<if test="clientOrderSeq > 0 "> and p.clientOrderSeq = #{clientOrderSeq}</if>	
			<if test="orderby == 'todayEnergy' ">order by d.monthEnergy desc </if>	
			<if test="orderby == 'todayHours' ">order by d.monthHours desc </if>	
			<if test="orderby == 'plantSeq' ">order by d.inputMonth asc, d.plantSeq desc</if>
			<if test="orderby == null or orderby == '' ">order by d.inputMonth asc, d.plantSeq desc</if>
			 			 			   
   		</select>  
   		
	    <select id="selectListStaticHour" parameterType="java.util.HashMap"  resultType="com.elt.ems.common.CaseSensibleHashMap">
			
			select p.name as plantName, p.supplyPower, v.ivtQuantity, d.*
			from (
				select d.seq, d.plantSeq, d.inputDate, max(d.todayEnergy) as todayEnergy, max(d.todayHours) as todayHours, 
					IFNULL(sum(d.input07), 0) as 'input07', IFNULL(sum(d.input08), 0) as 'input08', IFNULL(sum(d.input09), 0) as 'input09', IFNULL(sum(d.input10), 0) as 'input10', 
					IFNULL(sum(d.input11), 0) as 'input11', IFNULL(sum(d.input12), 0) as 'input12', IFNULL(sum(d.input13), 0) as 'input13', IFNULL(sum(d.input14), 0) as 'input14', IFNULL(sum(d.input15), 0) as 'input15', 
					IFNULL(sum(d.input16), 0) as 'input16', IFNULL(sum(d.input17), 0) as 'input17', IFNULL(sum(d.input18), 0) as 'input18', IFNULL(sum(d.input19), 0) as 'input19', IFNULL(sum(d.input20), 0) as 'input20'
				from (
					select 
						d1.seq, d1.plantSeq, d1.inputDate, max(d1.todayEnergy) as todayEnergy, max(d1.todayHours) as todayHours, 
							case when d1.inputHour = "07" then d1.today${dataName} end as 'input07',
							case when d1.inputHour = "08" then d1.today${dataName} end as 'input08',
							case when d1.inputHour = "09" then d1.today${dataName} end as 'input09',
							case when d1.inputHour = "10" then d1.today${dataName} end as 'input10',
							case when d1.inputHour = "11" then d1.today${dataName} end as 'input11',
							case when d1.inputHour = "12" then d1.today${dataName} end as 'input12',
							case when d1.inputHour = "13" then d1.today${dataName} end as 'input13',
							case when d1.inputHour = "14" then d1.today${dataName} end as 'input14',
							case when d1.inputHour = "15" then d1.today${dataName} end as 'input15',
							case when d1.inputHour = "16" then d1.today${dataName} end as 'input16',
							case when d1.inputHour = "17" then d1.today${dataName} end as 'input17',
							case when d1.inputHour = "18" then d1.today${dataName} end as 'input18',
							case when d1.inputHour = "19" then d1.today${dataName} end as 'input19',
							case when d1.inputHour = "20" then d1.today${dataName} end as 'input20'
					from t_ivtoverview_hour d1, t_plant p
					where d1.inputDate = #{inputDate} and d1.plantSeq = p.seq and p.plantStatus = '01'
					<if test="plantSeq > 0 "> and d1.plantSeq = #{plantSeq}</if>					
					<if test="clientOrderSeq > 0 "> and p.clientOrderSeq = #{clientOrderSeq}</if>
					<if test="seqs != null">and d1.plantSeq in 
					  <foreach item="seq" collection="seqs" open="(" separator="," close=")">#{seq} </foreach>					
					</if>
					group by d1.plantSeq, d1.inputHour
				)  d
				group by plantSeq 
			) d, t_plant p, t_ivtjunc v
			where  p.seq = d.plantSeq and d.plantSeq = v.plantSeq	
			<if test="clientOrderSeq > 0 "> and p.clientOrderSeq = #{clientOrderSeq}</if>				
			order by d.plantSeq desc  
						 			   
   		</select> 
   		
	    <select id="selectListStaticDay" parameterType="java.util.HashMap"  resultType="com.elt.ems.common.CaseSensibleHashMap">
			
			select p.name as plantName, p.supplyPower, v.ivtQuantity, d.*
			from (
				select d.seq, d.plantSeq, d.inputDate, sum(d.todayEnergy) as todayEnergy, avg(d.todayHours) as todayHours, 
					IFNULL(sum(d.input01), 0) as 'input01', IFNULL(sum(d.input02), 0) as 'input02', IFNULL(sum(d.input03), 0) as 'input03', IFNULL(sum(d.input04), 0) as 'input04', 
					IFNULL(sum(d.input05), 0) as 'input05', IFNULL(sum(d.input06), 0) as 'input06',
					IFNULL(sum(d.input07), 0) as 'input07', IFNULL(sum(d.input08), 0) as 'input08', IFNULL(sum(d.input09), 0) as 'input09', IFNULL(sum(d.input10), 0) as 'input10', 
					IFNULL(sum(d.input11), 0) as 'input11', IFNULL(sum(d.input12), 0) as 'input12', IFNULL(sum(d.input13), 0) as 'input13', IFNULL(sum(d.input14), 0) as 'input14', IFNULL(sum(d.input15), 0) as 'input15', 
					IFNULL(sum(d.input16), 0) as 'input16', IFNULL(sum(d.input17), 0) as 'input17', IFNULL(sum(d.input18), 0) as 'input18', IFNULL(sum(d.input19), 0) as 'input19', IFNULL(sum(d.input20), 0) as 'input20', 
					IFNULL(sum(d.input21), 0) as 'input21', IFNULL(sum(d.input22), 0) as 'input22', IFNULL(sum(d.input23), 0) as 'input23', IFNULL(sum(d.input24), 0) as 'input24', IFNULL(sum(d.input25), 0) as 'input25', 
					IFNULL(sum(d.input26), 0) as 'input26', IFNULL(sum(d.input27), 0) as 'input27', IFNULL(sum(d.input28), 0) as 'input28', IFNULL(sum(d.input29), 0) as 'input29', IFNULL(sum(d.input30), 0) as 'input30', 
					IFNULL(sum(d.input31), 0) as 'input31'
				from (
					select 
						d1.seq, d1.plantSeq, d1.inputDate, d1.todayEnergy as todayEnergy, d1.todayHours as todayHours,						
							case when substr(d1.inputDate, 9) = '01' then d1.today${dataName} end as 'input01',				
							case when substr(d1.inputDate, 9) = '02' then d1.today${dataName} end as 'input02',				
							case when substr(d1.inputDate, 9) = '03' then d1.today${dataName} end as 'input03',				
							case when substr(d1.inputDate, 9) = '04' then d1.today${dataName} end as 'input04',				
							case when substr(d1.inputDate, 9) = '05' then d1.today${dataName} end as 'input05',				
							case when substr(d1.inputDate, 9) = '06' then d1.today${dataName} end as 'input06',				
							case when substr(d1.inputDate, 9) = '07' then d1.today${dataName} end as 'input07',				
							case when substr(d1.inputDate, 9) = '08' then d1.today${dataName} end as 'input08',			
							case when substr(d1.inputDate, 9) = '09' then d1.today${dataName} end as 'input09',
                            case when substr(d1.inputDate, 9) = '10' then d1.today${dataName} end as 'input10',
                            case when substr(d1.inputDate, 9) = '11' then d1.today${dataName} end as 'input11',
                            case when substr(d1.inputDate, 9) = '12' then d1.today${dataName} end as 'input12',
                            case when substr(d1.inputDate, 9) = '13' then d1.today${dataName} end as 'input13',
                            case when substr(d1.inputDate, 9) = '14' then d1.today${dataName} end as 'input14',
                            case when substr(d1.inputDate, 9) = '15' then d1.today${dataName} end as 'input15',
                            case when substr(d1.inputDate, 9) = '16' then d1.today${dataName} end as 'input16',
                            case when substr(d1.inputDate, 9) = '17' then d1.today${dataName} end as 'input17',
                            case when substr(d1.inputDate, 9) = '18' then d1.today${dataName} end as 'input18',
                            case when substr(d1.inputDate, 9) = '19' then d1.today${dataName} end as 'input19',
                            case when substr(d1.inputDate, 9) = '20' then d1.today${dataName} end as 'input20',
                            case when substr(d1.inputDate, 9) = '21' then d1.today${dataName} end as 'input21',
                            case when substr(d1.inputDate, 9) = '22' then d1.today${dataName} end as 'input22',
                            case when substr(d1.inputDate, 9) = '23' then d1.today${dataName} end as 'input23',
                            case when substr(d1.inputDate, 9) = '24' then d1.today${dataName} end as 'input24',
                            case when substr(d1.inputDate, 9) = '25' then d1.today${dataName} end as 'input25',
                            case when substr(d1.inputDate, 9) = '26' then d1.today${dataName} end as 'input26',
                            case when substr(d1.inputDate, 9) = '27' then d1.today${dataName} end as 'input27',
                            case when substr(d1.inputDate, 9) = '28' then d1.today${dataName} end as 'input28',
                            case when substr(d1.inputDate, 9) = '29' then d1.today${dataName} end as 'input29',
                            case when substr(d1.inputDate, 9) = '30' then d1.today${dataName} end as 'input30',
                            case when substr(d1.inputDate, 9) = '31' then d1.today${dataName} end as 'input31'
					from t_ivtoverview_day d1, t_plant p
					where d1.inputDate between #{str1} and #{str2} and d1.plantSeq = p.seq and p.plantStatus = '01'
					<if test="plantSeq > 0 "> and d1.plantSeq = #{plantSeq}</if>					
					<if test="clientOrderSeq > 0 "> and p.clientOrderSeq = #{clientOrderSeq}</if>
					<if test="seqs != null">and d1.plantSeq in 
					  <foreach item="seq" collection="seqs" open="(" separator="," close=")">#{seq} </foreach>					
					</if>					
					group by d1.plantSeq, d1.inputDate
				)  d
				group by plantSeq 
			) d, t_plant p, t_ivtjunc v
			where  p.seq = d.plantSeq and d.plantSeq = v.plantSeq	
			<if test="clientOrderSeq > 0 "> and p.clientOrderSeq = #{clientOrderSeq}</if>				
			order by d.plantSeq desc  
						 			   
   		</select>    		
   		   		 		
   		
	    <select id="selectListStaticMonth" parameterType="java.util.HashMap"  resultType="com.elt.ems.common.CaseSensibleHashMap">
			
			select p.name as plantName, p.supplyPower, v.ivtQuantity, d.*
			from (
				select d.seq, d.plantSeq, d.inputYear, sum(d.todayEnergy) as todayEnergy, avg(d.todayHours) as todayHours,
					IFNULL(sum(d.input01), 0) as 'input01', IFNULL(sum(d.input02), 0) as 'input02', IFNULL(sum(d.input03), 0) as 'input03', IFNULL(sum(d.input04), 0) as 'input04', 
					IFNULL(sum(d.input05), 0) as 'input05', IFNULL(sum(d.input06), 0) as 'input06', IFNULL(sum(d.input07), 0) as 'input07', IFNULL(sum(d.input08), 0) as 'input08', 
                    IFNULL(sum(d.input09), 0) as 'input09', IFNULL(sum(d.input10), 0) as 'input10', IFNULL(sum(d.input11), 0) as 'input11', IFNULL(sum(d.input12), 0) as 'input12'
				from (
					select 
						d1.seq, d1.plantSeq, d1.inputYear, d1.inputMonth, d1.monthEnergy as todayEnergy, d1.monthHours as todayHours,						
							case when d1.inputMonth = '01' then d1.month${dataName} end as 'input01',				
							case when d1.inputMonth = '02' then d1.month${dataName} end as 'input02',				
							case when d1.inputMonth = '03' then d1.month${dataName} end as 'input03',				
							case when d1.inputMonth = '04' then d1.month${dataName} end as 'input04',				
							case when d1.inputMonth = '05' then d1.month${dataName} end as 'input05',				
							case when d1.inputMonth = '06' then d1.month${dataName} end as 'input06',				
							case when d1.inputMonth = '07' then d1.month${dataName} end as 'input07',				
							case when d1.inputMonth = '08' then d1.month${dataName} end as 'input08',			
							case when d1.inputMonth = '09' then d1.month${dataName} end as 'input09',
                            case when d1.inputMonth = '10' then d1.month${dataName} end as 'input10',
                            case when d1.inputMonth = '11' then d1.month${dataName} end as 'input11',
                            case when d1.inputMonth = '12' then d1.month${dataName} end as 'input12'
					from t_ivtoverview_month d1, t_plant p
					where d1.inputYear = #{inputYear} and d1.plantSeq = p.seq and p.plantStatus = '01'					
					<if test="clientOrderSeq > 0 ">and p.clientOrderSeq = #{clientOrderSeq} </if>					
					<if test="startMonth != null and startMonth != ''">and d1.inputMonth between #{startMonth} and #{endMonth} </if>
					<if test="seqs != null">and d1.plantSeq in 
					  <foreach item="seq" collection="seqs" open="(" separator="," close=")">#{seq} </foreach>					
					</if>
					group by d1.plantSeq, d1.inputMonth
				) d
				group by plantSeq 
			) d, t_plant p, t_ivtjunc v
			where  p.seq = d.plantSeq and d.plantSeq = v.plantSeq
			<if test="clientOrderSeq > 0 "> and p.clientOrderSeq = #{clientOrderSeq}</if>				
			order by d.plantSeq desc  
						 			   
   		</select>   
   		   		
   		<select id="selectListIvtByPlantSeq" parameterType="com.elt.ems.vo.SolarIvtJuncOverviewVo"  resultType="com.elt.ems.common.CaseSensibleHashMap">
   			SELECT R1.* FROM (   		
				select p.*, d.pvPower, d.dayPvPower, d.createDatetime as pmsDatetime from (
					select p.*, d.*  from 
					(
						select p.seq, p.name, p.supplyPower, p.plantType, v.link, v.url1, v.url2, v.ivtQuantity, v.ivtType
						from t_plant p left join t_ivtjunc v
						on p.seq = v.plantSeq
						where p.plantType in ('02', '03')  and p.seq = #{plantSeq}					 
						<if test="ivtStatus != null and ivtStatus != '-1' "> and v.ivtStatus = #{ivtStatus}</if>					
					) p left join t_ivtdata_${realtimeYear} d 
					on p.seq = d.plantSeq and d.plantSeq = #{plantSeq} <if test="oseq >= 0 "> and d.oseq = #{oseq}</if> 
				) p left join t_pmsdata_${realtimeYear} d 
				on p.seq = d.plantSeq and d.inputDate=#{inputDate} and d.seq = ( 
					select max(seq) as seq from t_pmsdata_${realtimeYear} where plantSeq = p.seq 
						and inputDate=#{inputDate} and plantSeq = #{plantSeq}
						<if test="inputHour != null and inputHour != '' "> and inputHour = #{inputHour}</if>
				) order by seq desc, ivtIdx asc  
			) R1 LIMIT 0, 50			    
   		</select>  
   		
   		<select id="selectListJuncByPlantSeq" parameterType="com.elt.ems.vo.SolarIvtJuncOverviewVo"  resultType="com.elt.ems.common.CaseSensibleHashMap">
			select p.*, d.pvPower, d.dayPvPower, d.createDatetime as pmsDatetime from (
				select p.*, d.* from 
				(
					select p.seq, p.name, p.supplyPower, p.plantType, v.link, v.url1, v.url2, v.ivtQuantity, v.ivtType
					from t_plant p left join t_ivtjunc v
					on p.seq = v.plantSeq
					where p.plantType in ('02', '03')  and p.seq = #{plantSeq}					 
					<if test="ivtStatus != null and ivtStatus != '-1' "> and v.ivtStatus = #{ivtStatus}</if>					
				) p left join t_juncdata d 
				on p.seq = d.plantSeq and d.plantSeq = #{plantSeq} <if test="oseq > 0 "> and d.oseq = #{oseq}</if> 
			) p left join t_pmsdata_${realtimeYear} d 
			on p.seq = d.plantSeq and d.inputDate=#{inputDate} and d.seq = ( 
				select max(seq) as seq from t_pmsdata_${realtimeYear} where plantSeq = p.seq 
					and inputDate=#{inputDate} and plantSeq = #{plantSeq}
					<if test="inputHour != null and inputHour != '' "> and inputHour = #{inputHour}</if>
			) order by seq desc, ivtIdx asc  			    
   		</select>
	    	      
	    <select id="select" parameterType="com.elt.ems.vo.SolarIvtJuncOverviewVo"  resultType="com.elt.ems.common.CaseSensibleHashMap">
		    select p.*, s.inputDate as lastday, s.todayEnergy as lastdayEnergy, s.todayHours as lastdayHours from (		    
				select  p.*, o.oseq, o.plantSeq, o.inputDate, o.inputHour, o.inputMinute, o.currPower, o.todayEnergy, o.todayHours, o.lifetimeEnergy, o.ovStatus, o.createDatetime as ivtDatetime
				from t_plant p left join t_ivtoverview o
				on p.seq = o.plantSeq
				where p.plantType in ('02', '03')
				<if test="plantStatus != null and plantStatus != '-1' "> and p.plantStatus = #{plantStatus}</if>
				<if test="plantSeq > 0 "> and p.seq = #{plantSeq}</if>
				<if test="oseq > 0 "> and o.oseq = #{oseq}</if>
			) p left join t_ivtoverview_day s
			on p.seq = s.plantSeq and s.inputDate = DATE_ADD(p.inputDate, INTERVAL -1 DAY)				
			order by  p.seq desc		        
   		</select>
   		
	    <select id="selectListPlant" parameterType="com.elt.ems.vo.SolarIvtJuncOverviewVo"  resultType="com.elt.ems.common.CaseSensibleHashMap">
	    	select p.name as plantName, o.plantSeq
	    	from (
				select plantSeq
				<if test="inputYear == null ">from t_ivtoverview where inputDate=#{inputDate}</if>
				<if test="inputYear != null ">from t_ivtoverview_month where inputYear=#{inputYear}</if>
				group by plantSeq   
			) o, t_plant p
			where o.plantSeq = p.seq and p.plantType in ('02', '03') and plantStatus = '01'
			<if test="plantSeq > 0 "> and o.plantSeq = #{plantSeq}</if>
			<if test="clientOrderSeq > 0 "> and p.clientOrderSeq = #{clientOrderSeq}</if>
			<if test="seqs != null">and p.seq in 
			  <foreach item="seq" collection="seqs" open="(" separator="," close=")">#{seq} </foreach>					
			</if>
			order by plantSeq     
   		</select>
   		   		
	    <select id="selectListHour" parameterType="com.elt.ems.vo.SolarIvtJuncOverviewVo"  resultType="com.elt.ems.common.CaseSensibleHashMap">
			select inputHour, max(inputMinute) as inputMinute, count(oseq) as count
			from t_ivtoverview o
			where inputDate=#{inputDate} <!--  
			group by inputHour, inputMinute	 --> 
			group by inputHour	
            order by oseq desc	        
   		</select>
   		   		
   		
	    <select id="selectIvtJuncPlant" parameterType="com.elt.ems.vo.SolarIvtJuncPlantVo"  resultType="com.elt.ems.vo.SolarIvtJuncPlantVo">
	    	select p.name as plantName, p.plantType, p.supplyPower, i.*
			from t_plant p, t_ivtjunc i  
			where p.seq = i.plantSeq and p.seq = #{plantSeq}
   		</select>
   		   		
	    <select id="selectListJuncData" parameterType="com.elt.ems.vo.SolarIvtJuncOverviewVo"  resultType="com.elt.ems.vo.SolarJuncDataVo">
	    	select o.* from t_plant p, (
				select d.* from t_juncdata d, (
					select plantSeq, max(oseq) oseq from t_ivtoverview
					where inputDate = #{inputDate}
					<if test="oseq > 0 "> and oseq = #{oseq}</if>
					<if test="plantSeq > 0 "> and plantSeq = #{plantSeq}</if>
					group by plantSeq
				) s
				where d.plantSeq = s.plantSeq and d.oseq = s.oseq
			) o
			where  o.plantSeq = p.seq and p.plantType in ('02', '03') and p.plantStatus = '01'
			<if test="clientOrderSeq > 0 "> and p.clientOrderSeq = #{clientOrderSeq}</if>
			order by plantSeq asc, ivtIdx asc 				    		       
   		</select>  
   		
  		<select id="selectListIvtData" parameterType="com.elt.ems.vo.SolarIvtJuncOverviewVo"  resultType="com.elt.ems.vo.SolarIvtDataVo">
  			select o.* from t_plant p, (
				select d.* from t_ivtdata_${realtimeYear} d, (
					select plantSeq, max(oseq) oseq from t_ivtoverview
					where inputDate = #{inputDate}
					<if test="oseq > 0 "> and oseq = #{oseq}</if>
					<if test="plantSeq > 0 "> and plantSeq = #{plantSeq}</if>
					group by plantSeq
				) s
				where d.plantSeq = s.plantSeq and d.oseq = s.oseq	
			) o
			where  o.plantSeq = p.seq and p.plantType in ('02', '03') and p.plantStatus = '01'
			<if test="clientOrderSeq > 0 "> and p.clientOrderSeq = #{clientOrderSeq}</if>
			order by plantSeq asc, ivtIdx asc        
   		</select> 
   		
   		<select id="selectListIvtDataByPlantSeq" parameterType="com.elt.ems.vo.SolarIvtDataVo"  resultType="com.elt.ems.vo.SolarIvtDataVo">
			select o.inputHour, o.inputMinute, d.*
			from t_ivtoverview o, t_ivtdata_${realtimeYear} d
			where o.oseq = d.oseq  and o.plantSeq = d.plantSeq         
			and o.plantSeq = #{plantSeq}
			and o.inputDate = #{inputDate}
			<if test="ivtIdx > 0 "> and ivtIdx = #{ivtIdx}</if>
			order by o.oseq asc, d.ivtIdx asc       
   		</select>  
   		
   		<select id="selectListJuncDataByPlantSeq" parameterType="com.elt.ems.vo.SolarJuncDataVo"  resultType="com.elt.ems.vo.SolarJuncDataVo">
			select o.inputHour, o.inputMinute, d.*
			from t_ivtoverview o, t_juncdata d
			where o.oseq = d.oseq  and o.plantSeq = d.plantSeq          
			and o.plantSeq = #{plantSeq}
			and o.inputDate = #{inputDate}
			<if test="ivtIdx > 0 "> and ivtIdx = #{ivtIdx}</if>
			order by o.oseq asc, d.ivtIdx asc       
   		</select>     		
   		
  		<select id="selectListIvtErrorCount" parameterType="com.elt.ems.common.CaseSensibleHashMap"  resultType="int">       	
			select count(d.seq) 
			from t_ivterror d, t_plant p
			where d.plantSeq = p.seq
			<if test="inputDate != null and inputDate != '' "> and d.inputDate = #{inputDate} </if>
			<if test="startDate != null and startDate != '' "> and d.inputDate between #{startDate} and #{endDate} </if>
			<if test="plantSeq > 0 "> and d.plantSeq = #{plantSeq}</if>
			<if test="clientOrderSeq > 0 "> and p.clientOrderSeq = #{clientOrderSeq}</if>
			<if test="isFault == true"> and (d.fault1 &gt; 0 or d.fault2 &gt; 0 or d.fault3 &gt; 0 or d.fault4 &gt; 0) </if>
			<if test="isFault == false"> and (d.fault1 = 0 and d.fault2 = 0 and d.fault3 = 0 and d.fault4 = 0) </if>
			order by d.seq desc      			
   		</select> 
   		   		
   		
  		<select id="selectListIvtError" parameterType="com.elt.ems.common.CaseSensibleHashMap"  resultType="com.elt.ems.vo.SolarIvtErrorVo">
	      <if test="pgtl != null">
	        <include refid="commonPagingHeader" /> 
	      </if>	        	
			select p.name as plantName, d.*
			from t_ivterror d, t_plant p
			where d.plantSeq = p.seq
			<if test="inputDate != null and inputDate != '' "> and d.inputDate = #{inputDate} </if>
			<if test="startDate != null and startDate != '' "> and d.inputDate between #{startDate} and #{endDate} </if>
			<if test="plantSeq > 0 "> and d.plantSeq = #{plantSeq}</if>
			<if test="clientOrderSeq > 0 "> and p.clientOrderSeq = #{clientOrderSeq}</if>
			<if test="isFault == true"> and (d.fault1 &gt; 0 or d.fault2 &gt; 0 or d.fault3 &gt; 0 or d.fault4 &gt; 0) </if>
			<if test="isFault == false"> and (d.fault1 = 0 and d.fault2 = 0 and d.fault3 = 0 and d.fault4 = 0) </if>
			order by d.seq desc
	      <if test="pgtl != null">
	        <include refid="commonPagingFooter" /> 
	      </if>	      			
   		</select> 
   		
   		<select id="selectWeatherSensorByPlantSeq" parameterType="com.elt.ems.vo.SolarIvtJuncOverviewVo"  resultType="com.elt.ems.vo.WeatherSensorVo">
			select *
			from t_weather_sensor
			where inputDate = #{inputDate} and plantSeq = #{plantSeq} and oseq = #{oseq}     
   		</select>  
   		   		
   		   		
  		<select id="selectMaxOseq" resultType="int" parameterType="int">
			select max(oseq) as oseq from t_ivtoverview where plantSeq = #{plantSeq} 
   		</select>  
   		   		
   		<insert id="insertIvtData"  parameterType="com.elt.ems.vo.SolarIvtDataVo">
			insert into t_ivtdata_${realtimeYear} (
				oseq, plantSeq, ivtIdx, acPower, acFreq, apparentPower, reactivePower, dcCurr, dcVolt, dcPower, temp, powerFactor, todayEnergy, lifetimeEnergy, ivtStatus, createDatetime
			) values (
				#{oseq},
				#{plantSeq},
				#{ivtIdx},
				#{acPower},
				#{acFreq},
				#{apparentPower},
				#{reactivePower},
				#{dcCurr},
				#{dcVolt},
				#{dcPower},
				#{temp},
				#{powerFactor},
				#{todayEnergy},
				#{lifetimeEnergy},
				#{ivtStatus},
				now()
			)
		</insert>
		
   		<insert id="insertOverview"  parameterType="com.elt.ems.vo.SolarIvtJuncOverviewVo">
			insert into t_ivtoverview (
				plantSeq, inputDate, inputHour, inputMinute, currPower, todayEnergy, todayHours, lifetimeEnergy, ovStatus, createDatetime
			) values (				
				#{plantSeq},
				#{inputDate},
				#{inputHour},
				#{inputMinute},
				#{currPower},
				#{todayEnergy},
				#{todayHours},
				#{lifetimeEnergy},
				#{ovStatus},
				now()
			)
		</insert>
		
   		<insert id="insertWeatherSensor"  parameterType="com.elt.ems.vo.WeatherSensorVo">
			insert into t_weather_sensor (
				inputDate, plantSeq, oseq, temp1, temp2, solarRadiation1, solarRadiation2, windSpeed, windDirection, createDatetime
			) values (
				#{inputDate},
				#{plantSeq},
				#{oseq},
				#{temp1},
				#{temp2},
				#{solarRadiation1},
				#{solarRadiation2},
				#{windSpeed},
				#{windDirection},
				now()
			)
		</insert>		
		
		<update id="updateIvtJunc"  parameterType="com.elt.ems.vo.SolarIvtJuncPlantVo">
			update t_ivtjunc set 
				url1 = #{url1},
				url2 = #{url2},
				port = #{port},
				ivtStatus = #{ivtStatus},
				ivtMaker = #{ivtMaker},
				ivtQuantity = #{ivtQuantity},
				link = #{link},
				key1 = #{key1},
				key2 = #{key2},
				ivtType = #{ivtType},
				syncType = #{syncType},
				updateId = #{updateId},
				updateDatetime = now()
			where plantSeq = #{plantSeq}
		</update>	
		
		
		
		<insert id="insertIvtJunc"  parameterType="com.elt.ems.vo.SolarIvtJuncPlantVo">
			insert into t_ivtjunc (
				plantSeq, url1, url2, port, ivtStatus, ivtMaker, ivtQuantity, link,  key1, key2, ivtType, syncType, updateId, updateDatetime, createDateTime 
			) values (
				#{plantSeq},
				#{url1},
				#{url2},
				#{port},
				#{ivtStatus},
				#{ivtMaker},
				#{ivtQuantity},
				#{link},
				#{key1},
				#{key2},
				#{ivtType},
				#{syncType},
				#{updateId},
				now(),
				now()
			)
		</insert>	
		
		<insert id="deleteIvtJunc"  parameterType="com.elt.ems.vo.SolarIvtJuncPlantVo">
			delete from t_ivtjunc where plantSeq = #{plantSeq}
		</insert>	
		
		
   		<!--    -->
	    <select id="selectListIvtInfo" parameterType="com.elt.ems.vo.SolarIvtInfoVo"  resultType="com.elt.ems.vo.SolarIvtInfoVo">

			select * from t_ivtinfo
			where plantSeq = #{plantSeq}
							    
   		</select>  
   		
		<update id="updateIvtInfo"  parameterType="com.elt.ems.vo.SolarIvtInfoVo">
			update t_ivtinfo set 
				ivtMaker = #{ivtMaker},
				ivtModel = #{ivtModel},
				ivtVolume = #{ivtVolume},
				serialNumber = #{serialNumber},
				ivtMemo = #{ivtMemo}
			where plantSeq = #{plantSeq} and ivtIdx = #{ivtIdx}
		</update>
		
			   				
		<insert id="insertIvtInfo"  parameterType="com.elt.ems.vo.SolarIvtInfoVo">
			insert into t_ivtinfo (
				plantSeq, ivtIdx, ivtMaker, ivtModel, ivtVolume, serialNumber, ivtMemo 
			) values (
				#{plantSeq},
				#{ivtIdx},
				#{ivtMaker},
				#{ivtModel},
				#{ivtVolume},
				#{serialNumber},
				#{ivtMemo}
			)
		</insert>	
		
		<insert id="deleteIvtInfo"  parameterType="com.elt.ems.vo.SolarIvtInfoVo">
			delete from t_ivtinfo where plantSeq = #{plantSeq} and ivtIdx = #{ivtIdx}
		</insert>	
   				
		
   		<insert id="insertIvtError"  parameterType="com.elt.ems.vo.SolarIvtErrorVo">
			insert into t_ivterror (
				plantSeq, ivtIdx, inputDate, inputHour, inputMinute, warn1, warn2, fault1, fault2, fault3, fault4, fault5, msg, memo, createDatetime
			) values (				
				#{plantSeq},
				#{ivtIdx},
				#{inputDate},
				#{inputHour},
				#{inputMinute},
				#{warn1},
				#{warn2},
				#{fault1},
				#{fault2},
				#{fault3},
				#{fault4},
				#{fault5},
				#{msg},
				#{memo},
				now()
			)
		</insert>
		
	    <select id="listInspectDayByTime"  parameterType="com.elt.ems.vo.SearchMapVo" resultType="com.elt.ems.common.CaseSensibleHashMap">

			select p.seq as plantSeq, p.name, i.ivtQuantity, i.ivtStatus, s.*     
			from t_plant p, t_ivtjunc i  left join (
			select  s.plantSeq as seq, s.inputYear, s.inputMonth, s.inputDay, 
				max(input01) as input01, max(input02) as input02, max(input03) as input03, max(input04) as input04, max(input05) as input05, 
				max(input06) as input06, max(input07) as input07, max(input08) as input08, max(input09) as input09, max(input10) as input10,  
				max(input11) as input11, max(input12) as input12, max(input13) as input13, max(input14) as input14, max(input15) as input15, 
				max(input16) as input16, max(input17) as input17, max(input18) as input18, max(input19) as input19, max(input20) as input20,  
				max(input21) as input21, max(input22) as input22, max(input23) as input23, max(input24) as input24, max(input25) as input25, 
				max(input26) as input26, max(input27) as input27, max(input28) as input28, max(input29) as input29, max(input30) as input30,  
				max(input31) as input31,
			    sum(total) as total
			from (
				select s.plantSeq, s.inputYear, s.inputMonth, s.inputDay, s.oseq,
				(CASE WHEN inputDay = '01' THEN cnt END) as input01,
				(CASE WHEN inputDay = '02' THEN cnt END) as input02,
				(CASE WHEN inputDay = '03' THEN cnt END) as input03,
				(CASE WHEN inputDay = '04' THEN cnt END) as input04,
				(CASE WHEN inputDay = '05' THEN cnt END) as input05,
				(CASE WHEN inputDay = '06' THEN cnt END) as input06,
				(CASE WHEN inputDay = '07' THEN cnt END) as input07,
				(CASE WHEN inputDay = '08' THEN cnt END) as input08,
				(CASE WHEN inputDay = '09' THEN cnt END) as input09,
				(CASE WHEN inputDay = '10' THEN cnt END) as input10,
				(CASE WHEN inputDay = '11' THEN cnt END) as input11,
				(CASE WHEN inputDay = '12' THEN cnt END) as input12,
				(CASE WHEN inputDay = '13' THEN cnt END) as input13,
				(CASE WHEN inputDay = '14' THEN cnt END) as input14,
				(CASE WHEN inputDay = '15' THEN cnt END) as input15,
				(CASE WHEN inputDay = '16' THEN cnt END) as input16,
				(CASE WHEN inputDay = '17' THEN cnt END) as input17,
				(CASE WHEN inputDay = '18' THEN cnt END) as input18,
				(CASE WHEN inputDay = '19' THEN cnt END) as input19,
				(CASE WHEN inputDay = '20' THEN cnt END) as input20,
				(CASE WHEN inputDay = '21' THEN cnt END) as input21,
				(CASE WHEN inputDay = '22' THEN cnt END) as input22,
				(CASE WHEN inputDay = '23' THEN cnt END) as input23,
				(CASE WHEN inputDay = '24' THEN cnt END) as input24,
				(CASE WHEN inputDay = '25' THEN cnt END) as input25,
				(CASE WHEN inputDay = '26' THEN cnt END) as input26,
				(CASE WHEN inputDay = '27' THEN cnt END) as input27,
				(CASE WHEN inputDay = '28' THEN cnt END) as input28,
				(CASE WHEN inputDay = '29' THEN cnt END) as input29,
				(CASE WHEN inputDay = '30' THEN cnt END) as input30,
				(CASE WHEN inputDay = '31' THEN cnt END) as input31,
				sum(s.cnt) total
				from (
					select s.plantSeq, s.inputDate,  substr(s.inputDate, 1, 4) as inputYear, substr(s.inputDate, 6, 2) as inputMonth, substr(s.inputDate, 9) as inputDay, s.oseq, count(s.oseq) as cnt
					from t_ivtoverview s
					where inputDate like concat(#{map.inputYm}, '-__') 
					group by s.plantSeq, s.inputDate
					order by plantSeq asc
				) s
				group by s.plantSeq, s.inputDate 
			) s 
			group by s.plantSeq
			) s
			on i.plantSeq = s.seq and i.ivtStatus='01'
			where  p.plantStatus='01' and p.seq = i.plantSeq and p.plantType in ('02', '03')
			order by p.seq desc, s.inputDay asc
												
	    </select>
	    		
	    
	    <select id="listInspectDayByHour"  parameterType="com.elt.ems.vo.SearchMapVo" resultType="com.elt.ems.common.CaseSensibleHashMap">

			select p.seq as plantSeq, p.name, i.ivtQuantity, i.ivtStatus, s.*     
			from t_plant p, t_ivtjunc i  left join (
			select  s.plantSeq as seq, s.inputYear, s.inputMonth, s.inputDay, 
				max(input01) as input01, max(input02) as input02, max(input03) as input03, max(input04) as input04, max(input05) as input05, 
				max(input06) as input06, max(input07) as input07, max(input08) as input08, max(input09) as input09, max(input10) as input10,  
				max(input11) as input11, max(input12) as input12, max(input13) as input13, max(input14) as input14, max(input15) as input15, 
				max(input16) as input16, max(input17) as input17, max(input18) as input18, max(input19) as input19, max(input20) as input20,  
				max(input21) as input21, max(input22) as input22, max(input23) as input23, max(input24) as input24, max(input25) as input25, 
				max(input26) as input26, max(input27) as input27, max(input28) as input28, max(input29) as input29, max(input30) as input30,  
				max(input31) as input31,
			    sum(total) as total
			from (
				select s.plantSeq, s.inputYear, s.inputMonth, s.inputDay, s.seq,
				(CASE WHEN inputDay = '01' THEN cnt END) as input01,
				(CASE WHEN inputDay = '02' THEN cnt END) as input02,
				(CASE WHEN inputDay = '03' THEN cnt END) as input03,
				(CASE WHEN inputDay = '04' THEN cnt END) as input04,
				(CASE WHEN inputDay = '05' THEN cnt END) as input05,
				(CASE WHEN inputDay = '06' THEN cnt END) as input06,
				(CASE WHEN inputDay = '07' THEN cnt END) as input07,
				(CASE WHEN inputDay = '08' THEN cnt END) as input08,
				(CASE WHEN inputDay = '09' THEN cnt END) as input09,
				(CASE WHEN inputDay = '10' THEN cnt END) as input10,
				(CASE WHEN inputDay = '11' THEN cnt END) as input11,
				(CASE WHEN inputDay = '12' THEN cnt END) as input12,
				(CASE WHEN inputDay = '13' THEN cnt END) as input13,
				(CASE WHEN inputDay = '14' THEN cnt END) as input14,
				(CASE WHEN inputDay = '15' THEN cnt END) as input15,
				(CASE WHEN inputDay = '16' THEN cnt END) as input16,
				(CASE WHEN inputDay = '17' THEN cnt END) as input17,
				(CASE WHEN inputDay = '18' THEN cnt END) as input18,
				(CASE WHEN inputDay = '19' THEN cnt END) as input19,
				(CASE WHEN inputDay = '20' THEN cnt END) as input20,
				(CASE WHEN inputDay = '21' THEN cnt END) as input21,
				(CASE WHEN inputDay = '22' THEN cnt END) as input22,
				(CASE WHEN inputDay = '23' THEN cnt END) as input23,
				(CASE WHEN inputDay = '24' THEN cnt END) as input24,
				(CASE WHEN inputDay = '25' THEN cnt END) as input25,
				(CASE WHEN inputDay = '26' THEN cnt END) as input26,
				(CASE WHEN inputDay = '27' THEN cnt END) as input27,
				(CASE WHEN inputDay = '28' THEN cnt END) as input28,
				(CASE WHEN inputDay = '29' THEN cnt END) as input29,
				(CASE WHEN inputDay = '30' THEN cnt END) as input30,
				(CASE WHEN inputDay = '31' THEN cnt END) as input31,
				sum(s.cnt) total
				from (
					select s.plantSeq, s.inputDate,  substr(s.inputDate, 1, 4) as inputYear, substr(s.inputDate, 6, 2) as inputMonth, substr(s.inputDate, 9) as inputDay, s.seq, count(s.seq) as cnt
					from t_ivtoverview_hour s
					where inputDate like concat(#{map.inputYm}, '-__') 
					group by s.plantSeq, s.inputDate
					order by plantSeq asc
				) s
				group by s.plantSeq, s.inputDate 
			) s 
			group by s.plantSeq
			) s
			on i.plantSeq = s.seq and i.ivtStatus='01'
			where  p.plantStatus='01' and p.seq = i.plantSeq and p.plantType in ('02', '03')
			order by p.seq desc, s.inputDay asc
												
	    </select>	
	    			
	    <select id="listInspectDay"  parameterType="com.elt.ems.vo.SearchMapVo" resultType="com.elt.ems.common.CaseSensibleHashMap">
	
			select p.seq as plantSeq, p.name, m.ivtQuantity, s.*     
			from t_plant p, t_ivtjunc m  left join (
			select  s.plantSeq as seq, s.inputDate, s.inputDay, 
				max(input01) as input01, max(input02) as input02, max(input03) as input03, max(input04) as input04, max(input05) as input05, 
				max(input06) as input06, max(input07) as input07, max(input08) as input08, max(input09) as input09, max(input10) as input10,  
				max(input11) as input11, max(input12) as input12, max(input13) as input13, max(input14) as input14, max(input15) as input15, 
				max(input16) as input16, max(input17) as input17, max(input18) as input18, max(input19) as input19, max(input20) as input20,  
				max(input21) as input21, max(input22) as input22, max(input23) as input23, max(input24) as input24, max(input25) as input25, 
				max(input26) as input26, max(input27) as input27, max(input28) as input28, max(input29) as input29, max(input30) as input30,  
				max(input31) as input31,
			    count(seq) as total
			from (
				select s.plantSeq, s.inputDate, substring(inputDate, 9, 2) as inputDay, s.seq,
				(CASE WHEN substring(inputDate, 9, 2) = '01' THEN 1 ELSE 0 END) as input01,
				(CASE WHEN substring(inputDate, 9, 2) = '02' THEN 1 ELSE 0 END) as input02,
				(CASE WHEN substring(inputDate, 9, 2) = '03' THEN 1 ELSE 0 END) as input03,
				(CASE WHEN substring(inputDate, 9, 2) = '04' THEN 1 ELSE 0 END) as input04,
				(CASE WHEN substring(inputDate, 9, 2) = '05' THEN 1 ELSE 0 END) as input05,
				(CASE WHEN substring(inputDate, 9, 2) = '06' THEN 1 ELSE 0 END) as input06,
				(CASE WHEN substring(inputDate, 9, 2) = '07' THEN 1 ELSE 0 END) as input07,
				(CASE WHEN substring(inputDate, 9, 2) = '08' THEN 1 ELSE 0 END) as input08,
				(CASE WHEN substring(inputDate, 9, 2) = '09' THEN 1 ELSE 0 END) as input09,
				(CASE WHEN substring(inputDate, 9, 2) = '10' THEN 1 ELSE 0 END) as input10,
				(CASE WHEN substring(inputDate, 9, 2) = '11' THEN 1 ELSE 0 END) as input11,
				(CASE WHEN substring(inputDate, 9, 2) = '12' THEN 1 ELSE 0 END) as input12,
				(CASE WHEN substring(inputDate, 9, 2) = '13' THEN 1 ELSE 0 END) as input13,
				(CASE WHEN substring(inputDate, 9, 2) = '14' THEN 1 ELSE 0 END) as input14,
				(CASE WHEN substring(inputDate, 9, 2) = '15' THEN 1 ELSE 0 END) as input15,
				(CASE WHEN substring(inputDate, 9, 2) = '16' THEN 1 ELSE 0 END) as input16,
				(CASE WHEN substring(inputDate, 9, 2) = '17' THEN 1 ELSE 0 END) as input17,
				(CASE WHEN substring(inputDate, 9, 2) = '18' THEN 1 ELSE 0 END) as input18,
				(CASE WHEN substring(inputDate, 9, 2) = '19' THEN 1 ELSE 0 END) as input19,
				(CASE WHEN substring(inputDate, 9, 2) = '20' THEN 1 ELSE 0 END) as input20,
				(CASE WHEN substring(inputDate, 9, 2) = '21' THEN 1 ELSE 0 END) as input21,
				(CASE WHEN substring(inputDate, 9, 2) = '22' THEN 1 ELSE 0 END) as input22,
				(CASE WHEN substring(inputDate, 9, 2) = '23' THEN 1 ELSE 0 END) as input23,
				(CASE WHEN substring(inputDate, 9, 2) = '24' THEN 1 ELSE 0 END) as input24,
				(CASE WHEN substring(inputDate, 9, 2) = '25' THEN 1 ELSE 0 END) as input25,
				(CASE WHEN substring(inputDate, 9, 2) = '26' THEN 1 ELSE 0 END) as input26,
				(CASE WHEN substring(inputDate, 9, 2) = '27' THEN 1 ELSE 0 END) as input27,
				(CASE WHEN substring(inputDate, 9, 2) = '28' THEN 1 ELSE 0 END) as input28,
				(CASE WHEN substring(inputDate, 9, 2) = '29' THEN 1 ELSE 0 END) as input29,
				(CASE WHEN substring(inputDate, 9, 2) = '30' THEN 1 ELSE 0 END) as input30,
				(CASE WHEN substring(inputDate, 9, 2) = '31' THEN 1 ELSE 0 END) as input31
				from t_ivtoverview_day s
				where inputDate  like concat(#{map.inputYm}, '-__') <!--  between #{map.startDate} and #{map.endDate} -->
			) s 
			group by s.plantSeq
			) s
			on m.plantSeq = s.seq
			where m.ivtStatus='01' and p.plantStatus='01' and p.plantType in ('02', '03') and p.seq = m.plantSeq
			order by m.plantSeq desc, s.inputDay asc
									
	    </select>
	    
	    <select id="listInspectMonth"  parameterType="com.elt.ems.vo.SearchMapVo" resultType="com.elt.ems.common.CaseSensibleHashMap">
	
			select p.seq as plantSeq, p.name, m.ivtQuantity, s.*     
			from t_plant p, t_ivtjunc m  left join (
			select  s.plantSeq as seq, s.inputYear, s.inputMonth,  
				max(input01) as input01, max(input02) as input02, max(input03) as input03, max(input04) as input04, max(input05) as input05, 
				max(input06) as input06, max(input07) as input07, max(input08) as input08, max(input09) as input09, max(input10) as input10,  
				max(input11) as input11, max(input12) as input12, 
			    count(seq) as total
			from (
				select s.plantSeq, s.inputYear, s.inputMonth, s.seq,
					(CASE WHEN inputMonth = '01' THEN 1 ELSE 0 END) as input01,
					(CASE WHEN inputMonth = '02' THEN 1 ELSE 0 END) as input02,
					(CASE WHEN inputMonth = '03' THEN 1 ELSE 0 END) as input03,
					(CASE WHEN inputMonth = '04' THEN 1 ELSE 0 END) as input04,
					(CASE WHEN inputMonth = '05' THEN 1 ELSE 0 END) as input05,
					(CASE WHEN inputMonth = '06' THEN 1 ELSE 0 END) as input06,
					(CASE WHEN inputMonth = '07' THEN 1 ELSE 0 END) as input07,
					(CASE WHEN inputMonth = '08' THEN 1 ELSE 0 END) as input08,
					(CASE WHEN inputMonth = '09' THEN 1 ELSE 0 END) as input09,
					(CASE WHEN inputMonth = '10' THEN 1 ELSE 0 END) as input10,
					(CASE WHEN inputMonth = '11' THEN 1 ELSE 0 END) as input11,
					(CASE WHEN inputMonth = '12' THEN 1 ELSE 0 END) as input12
				from t_ivtoverview_month s
				where inputYear = #{map.inputYear}
				) s 
				group by s.plantSeq
			) s
			on m.plantSeq = s.seq
			where m.ivtStatus='01' and p.plantStatus='01' and p.seq = m.plantSeq
			order by m.plantSeq desc, s.inputMonth asc
	    </select>	 
	   	    	 
	    <select id="selectListIvtHour" parameterType="com.elt.ems.vo.SolarIvtJuncOverviewVo"  resultType="com.elt.ems.vo.SolarIvtDataVo">
	    		
			select o.*, d.* from (
				select * from (
					select inputDate, inputHour, inputMinute, oseq
					from t_ivtoverview where plantSeq = #{plantSeq} and inputDate=#{inputDate}
				) a, ( ${memo} ) b
			) o left join t_ivtdata_${realtimeYear} d
			on o.oseq = d.oseq and o.ivtIdx = d.ivtIdx and d.ivtIdx &lt; 20 
			order by o.inputDate, o.inputHour, o.inputMinute, o.oseq, o.ivtIdx asc
		<!-- 
		
			select o.*, d.* from ( 
				select * from (
					select inputDate, inputHour, max(oseq) as oseq from t_ivtoverview where plantSeq = 77 and inputDate='2022-12-04' group by inputHour
				) a, (
				select 1 as ivtIdx union
				select 2 as ivtIdx union
				select 3 as ivtIdx
				) b
			) o left join t_ivtdata_2022 d on o.oseq = d.oseq and o.ivtIdx = d.ivtIdx and d.ivtIdx < 5 
							
			select o.*, d.* from 
			(
				select inputDate, inputHour, inputMinute, oseq
				from t_ivtoverview where plantSeq = #{plantSeq} and inputDate=#{inputDate}
			) o left join t_ivtdata_${realtimeYear} d
			on o.oseq = d.oseq and d.ivtIdx &lt; 5
			order by o.inputDate, o.inputHour, o.inputMinute asc -->
   		</select> 
   		
	    <select id="selectList4Expect"  parameterType="com.elt.ems.vo.SolarIvtJuncOverviewVo" resultType="com.elt.ems.common.CaseSensibleHashMap">
	
			select * from ( 
				select *,  round(d.pvPower/p.supplyPower) as pvPercent from ( 
					select p.seq as seq, p.name as plantName, p.plantStatus, p.supplyPower, p.geox, p.geoy, p.weatherCode, p.prate, p.drate, p.beginDate
					from t_plant p, t_ivtjunc i
					where p.seq = i.plantSeq and p.plantStatus='01' and i.ivtStatus='01' and p.plantType in ('02','03')
				) p left join ( 
					select o1.oseq, o1.plantSeq, o1.inputDate, o1.inputHour, o1.inputMinute, round(o1.currPower*100) as pvPower, o1.todayEnergy, o1.todayHours, o1.createDatetime from t_ivtoverview o1, (
				      select plantSeq, max(oseq) oseq from t_ivtoverview
				      where inputDate = #{inputDate}  
					  <if test="inputHour != null or inputHour != ''"> 
						and inputHour=#{inputHour} 
					  </if><!-- 
					  <if test="inputMinute == null or inputMinute == ''"> 
						and inputHour=#{inputHour} 
					  </if>
					  <if test="inputMinute != null and inputMinute != ''">
						and inputHour=#{inputHour} and inputMinute = #{inputMinute}
					  </if> -->
				      group by plantSeq
				    ) o2
				    where o1.inputDate = #{inputDate}   
				    and o1.plantSeq = o2.plantSeq and o1.oseq = o2.oseq
				) d 
			    on p.seq = d.plantSeq        
			) p left join ( 
				select inputHour as weatherHour, weatherCode, cloud from <include refid="tableNameWeather" /> where inputYmd = #{inputDate} and inputHour = ( select max(inputHour) from <include refid="tableNameWeather" /> where inputYmd = #{inputDate}) 
			) w 
			on p.weatherCode = w.weatherCode 
			
			<if test="orderby == 'plantSeq' ">order by p.plantSeq desc</if>
			<if test="orderby == 'hours' ">order by p.todayEnergy desc</if>
			<if test="orderby == null or orderby == 'pvPower' ">order by p.pvPercent desc</if>	
						
	    </select> 
	    
	    <update id="updateIvtOverviewHour"  parameterType="com.elt.ems.vo.SolarIvtJuncOverviewVo">
			update t_ivtoverview_hour set <if test="todayEnergy != -1"> todayEnergy=#{todayEnergy} </if> <if test="todayHours != -1"> todayHours=#{todayHours} </if>  where plantSeq = #{plantSeq} and inputDate=#{inputDate} and inputHour=#{inputHour}
		</update>
	    <update id="updateIvtOverviewDay"  parameterType="com.elt.ems.vo.SolarIvtJuncOverviewVo">
			update  t_ivtoverview_day set <if test="todayEnergy != -1"> todayEnergy=#{todayEnergy} </if> <if test="todayHours != -1"> todayHours=#{todayHours} </if>  where plantSeq = #{plantSeq} and inputDate=#{inputDate} 
		</update>
	    <update id="updateIvtOverviewMonth"  parameterType="com.elt.ems.vo.SolarIvtJuncOverviewVo">
			update  t_ivtoverview_month set <if test="todayEnergy != -1"> monthEnergy=#{todayEnergy} </if> <if test="todayHours != -1"> monthHours=#{todayHours} </if>  where plantSeq = #{plantSeq} and inputYear=#{inputYear} and inputMonth=#{inputMonth}
		</update>		
	</mapper>