<?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.SmsMapper">
	
	    <sql id="commonPagingHeader"  >
	      SELECT R1.* FROM (
	    </sql>
	    
	    <sql id="commonPagingFooter"  >
	      ) R1 LIMIT #{pgtl.startNo}, #{pgtl.listPerPage}
	    </sql>  
	    	
		<sql id="tableNameSms"> t_sms </sql>
		
	    <sql id="includePlantSeqs"  >
	      and p.seq in ( ${plantSeqs} )
	    </sql>
	
		<!-- 해당 부분의 id는 MapperClass의 함수 이름과 유사하여야 합니다. -->
		<select id="selectList" parameterType="com.elt.ems.vo.SmsVo"  resultType="com.elt.ems.vo.SmsVo">
	      <if test="pgtl != null">
	        <include refid="commonPagingHeader" /> 
	      </if>
	      		
			select 
			  a.*, p.name as plantName
			from <include refid="tableNameSms" /> a left join t_plant p
			on a.plantSeq = p.seq 
			where 1=1
			<if test="result != null and result != '' "> and a.result = #{result}</if>
			<if test="plantSeq > 0"> and a.plantSeq = #{plantSeq}</if>
			order by a.seq desc
			
	      <if test="pgtl != null">
	        <include refid="commonPagingFooter" />
	      </if>
	      			
		</select>
		
		<select id="selectListCount" parameterType="com.elt.ems.vo.SmsVo"  resultType="int">
			select count(a.seq) as count
			from <include refid="tableNameSms" /> a left join t_plant p
			on a.plantSeq = p.seq   
			where 1=1
			<if test="result != null and result != '' "> and a.result = #{result}</if>
			<if test="plantSeq > 0"> and a.plantSeq = #{plantSeq}</if>			
		</select>
		
    
		<insert id="insert"  parameterType="com.elt.ems.vo.SmsVo">
			insert into <include refid="tableNameSms" /> (
				plantSeq, title, receiver, sender, result, createId, createDateTime
			) values (
				#{plantSeq},
				#{title},
				#{receiver},
				#{sender},
				#{result},
				#{createId},
				now()
			)
		</insert>  
		
	</mapper>