<?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="tableNameIvtdata"> t_ivtdata_2022 </sql>
			 		   
	    <sql id="includePlantSeqs"  >
	      and p.seq in ( ${plantSeqs} )
	    </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, 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="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>
   		   		
   		<!--  /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>
   		
   		<!--  /data/ivt/solar_hour.co, /data/solar/chart.co -->
   		<select id="selectListOverviewHour" parameterType="com.elt.ems.vo.SolarIvtJuncOverviewVo"  resultType="com.elt.ems.vo.SolarIvtJuncOverviewForm">
			select o1.inputHour, o1.plantSeq, o1.name, 
				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, p.name from (
						select o1.inputHour, o.plantSeq from  (
							select oseq, inputDate, inputHour  from t_ivtoverview 
							where inputDate=#{inputDate} and inputHour &lt; #{inputHour}	 				
							group by inputHour 
						) o1 CROSS JOIN t_ivtoverview o 
						on o.inputDate = #{inputDate} 
						group by o1.inputHour, o.plantSeq
						order by o.plantSeq asc 
				) 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>   
				<if test="plantSeq > 0 "> and plantSeq = #{plantSeq}</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>     		
   		
   		<!--  /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
					order by o.plantSeq asc
				) 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>  
   		
	    <select id="selectListStaticHourPlantSeq" parameterType="com.elt.ems.vo.SolarIvtJuncOverviewForm"  resultType="com.elt.ems.vo.SolarIvtJuncOverviewForm">
			
			select * from t_ivtoverview_hour
			where inputDate = #{inputDate} 
			<if test="plantSeq > 0 "> and plantSeq = #{plantSeq}</if>
			order by inputDate asc, inputHour asc 
						 			   
   		</select>     		
   		
	    <select id="selectListStaticDayPlantSeq" parameterType="com.elt.ems.vo.SolarIvtJuncOverviewForm"  resultType="com.elt.ems.vo.SolarIvtJuncOverviewForm">
			
			select p.name as plantName, p.supplyPower, d.* 
			from t_ivtoverview_day d, t_plant p
			where d.plantSeq = p.seq and d.inputDate between #{str1} and #{str2} 
			<if test="plantSeq > 0 "> and d.plantSeq = #{plantSeq}</if>			
			order by inputDate asc 
						 			   
   		</select>
   		   		
	    <select id="selectListStaticMonthPlantSeq" parameterType="com.elt.ems.common.CaseSensibleHashMap"  resultType="com.elt.ems.vo.SolarIvtJuncOverviewForm">
			<!-- 
			select 
				p.name as plantName, p.supplyPower, 
				d.seq, d.plantSeq, d.inputYear, d.inputMonth, d.monthEnergy as todayEnergy, d.monthHours todayHours, d.lifetimeEnergy, d.createDatetime
			from t_ivtoverview_month d, t_plant p
			where d.plantSeq = p.seq and d.inputYear = #{inputYear} 
			<if test="inputMonth != null and inputMonth != '' "> and d.inputMonth = #{inputMonth} </if>
			<if test="plantSeq > 0 "> and d.plantSeq = #{plantSeq}</if>			
			order by inputYear desc, inputMonth desc 
			 -->
			 
			select 
				p.name as plantName, p.supplyPower, d.plantSeq, 
				(max(d.lifetimeEnergy) - min(d.lifetimeEnergy)) as todayEnergy, TRUNCATE(avg(todayHours), 2) as todayHours
			from t_ivtoverview_day d, t_plant p
			where d.plantSeq = p.seq and d.inputDate between #{str1} and #{str2}  
			<if test="plantSeq > 0 "> and d.plantSeq = #{plantSeq}</if>	
			group by d.plantSeq	 
			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
				from t_ivtoverview 
				where inputDate=#{inputDate}
				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>
			order by plantSeq     
   		</select>
   		   		
	    <select id="selectListHour" parameterType="com.elt.ems.vo.SolarIvtJuncOverviewVo"  resultType="com.elt.ems.common.CaseSensibleHashMap">
			select inputHour, inputMinute, count(oseq) as count
			from t_ivtoverview o
			where inputDate=#{inputDate}
			group by inputHour, inputMinute	
            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 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	
			order by oseq 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="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>
			order by d.seq desc
	      <if test="pgtl != null">
	        <include refid="commonPagingFooter" /> 
	      </if>
	      			
   		</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>
		
		<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>
				
	</mapper>