<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN" "http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">

<mapper namespace="i2c.biz.admin.fileMng.dao.FileCvtDAO">
 	
 	<parameterMap id="fileCvtVO"  type="i2c.biz.admin.fileMng.vo.FileCvtVO" />
 	<resultMap 	  id="fileCvtVO"  type="i2c.biz.admin.fileMng.vo.FileCvtVO" />
	 
	 <select id="selectFileCvtCount"  parameterMap="fileCvtVO" resultType="int">
	 /* [i2c.biz.admin.fileMng.dao.FileCvtDAO.selectFileCvtCount] 파일변환 통계 count */
	 	SELECT COUNT(0) AS TOTCNT
		FROM
			(
				SELECT ROWNUM RNUM
					, COUNT(a.dttm) OVER() TOTAL_CNT
					, ROW_NUMBER() OVER(ORDER BY a.dttm) RN
					, a.*
				FROM (
					select 
					     dttm
					   , tar_tp
					   , CASE tar_tp 
							WHEN 'NOTICE' 		THEN '게시판'
							WHEN 'FAQ' 			THEN '게시판'
							WHEN 'CFRC' 		THEN '회의'
							WHEN 'POST' 		THEN '피드'
							WHEN 'TASK' 		THEN '작업'
							WHEN 'SITTN' 		THEN '부산항 일일운영현황'
						 ELSE '기타' 		
					     END tar_tp_nm
					   , IFNULL(max(y_cnt),0) + IFNULL(max(n_cnt),0) t_cnt 
					   , IFNULL(max(y_cnt),0) as y_cnt
					   , IFNULL(max(n_cnt),0) as n_cnt 
					from (
						select 
						     SUBSTR(conv_req_dttm,0,8) dttm
						   , tar_tp
						   , decode(IFNULL(conv_yn,'N'),'Y',count(*)) as y_cnt
						   , decode(IFNULL(conv_yn,'N'),'N',count(*)) as n_cnt
						from sns_attach
						where  SUBSTR(conv_req_dttm,0,8) between #{start_dttm} AND #{end_dttm}
					<if test="searchType != null and searchType !=''">
						<choose>							
							<when test="searchType =='NOTICE'">
					    		and tar_tp in ('NOTICE','FAQ')
							</when>							
							<otherwise>
								AND TAR_TP IN 
								<foreach collection="searchType" item="item" index="index" separator="," open="(" close=")">
				                    #{item}
				                </foreach>
							</otherwise>
						</choose>	
				     </if>		
						group by SUBSTR(conv_req_dttm,0,8), tar_tp, conv_yn
					) group by dttm, tar_tp
				) a
				order by a.dttm, tar_tp
			)
		
	</select>
	
	
	 <select id="listFileCvtStats"  parameterMap="fileCvtVO"  resultMap="fileCvtVO">
	 /* [i2c.biz.admin.fileMng.dao.FileCvtDAO.listFileCvtStats] 파일변환 통계 리스트 */
		
		SELECT
			*
		FROM
		(
			SELECT ROWNUM RNUM
				, COUNT(a.dttm) OVER() TOTAL_CNT
				, ROW_NUMBER() OVER(ORDER BY A.DTTM DESC) RN
				, a.*
			FROM (
				select 
				   	TO_CHAR(TO_DATE(DTTM,'YYYYMMDD'),'YYYY-MM-DD') DTTM
				   , tar_tp
				   , CASE tar_tp 						
						WHEN 'NOTICE' 		THEN '게시판'
						WHEN 'FAQ' 			THEN '게시판'
						WHEN 'CFRC' 		THEN '회의'
						WHEN 'POST' 		THEN '피드'
						WHEN 'TASK' 		THEN '작업'
						WHEN 'SITTN' 		THEN '부산항 일일운영현황'
					 ELSE '기타'	
				     END tar_tp_nm
				   , IFNULL(max(y_cnt),0) + IFNULL(max(n_cnt),0) t_cnt 
				   , IFNULL(max(y_cnt),0) as y_cnt
				   , IFNULL(max(n_cnt),0) as n_cnt 
				from (
					select 
					     SUBSTR(conv_req_dttm,0,8) dttm
					   , tar_tp
					   , decode(IFNULL(conv_yn,'N'),'Y',count(*)) as y_cnt
					   , decode(IFNULL(conv_yn,'N'),'N',count(*)) as n_cnt
					from sns_attach
					where  SUBSTR(conv_req_dttm,0,8) between #{start_dttm} AND #{end_dttm}
				<if test="searchType != null and searchType !=''">
					<choose>						
						<when test="searchType =='NOTICE'">
				    		and tar_tp in ('NOTICE','FAQ')
						</when>						
						<otherwise>
							AND TAR_TP IN 
							<foreach collection="searchType" item="item" index="index" separator="," open="(" close=")">
			                    #{item}
			                </foreach>
						</otherwise>
					</choose>	
			     </if>			        	
					group by SUBSTR(conv_req_dttm,0,8), tar_tp, conv_yn
				) group by dttm, tar_tp
				ORDER BY DTTM DESC 
			) a			
		)
		 <![CDATA[
			 WHERE RNUM  > #{firstIndex}
		     AND   RNUM <= #{firstIndex} + #{recordCountPerPage}
			 ORDER BY RN 
	   ]]> 
	 </select>
	
	
	
	 <select id="selectFileCvtLogCount"  parameterMap="fileCvtVO" resultType="int">
	 /* [i2c.biz.admin.fileMng.dao.FileCvtDAO.selectFileCvtLogCount] 파일변환 내역 count */
	 	SELECT COUNT(0) AS TOTCNT
		FROM
		(
			SELECT 
				COUNT(a.attachNm) OVER() TOTAL_CNT,
				ROW_NUMBER() OVER(ORDER BY a.DTTM) RN,
				a.*
			FROM (
				SELECT
					   TO_CHAR(TO_DATE(conv_req_dttm,'yyyyMMddHH24MISS'), 'yyyy-MM-dd DY HH24:MI:SS') DTTM
					 , tar_tp
					 , attach_nm attachNm
					 , crt_usr_id, FN_GET_USR_NM(crt_usr_id) crt_usr_nm
		    		 , conv_yn
					 , CASE tar_tp 						
						WHEN 'NOTICE' 		THEN '게시판'
						WHEN 'FAQ' 			THEN '게시판'
						WHEN 'CFRC' 		THEN '회의'
						WHEN 'POST' 		THEN '피드'
						WHEN 'TASK' 		THEN '작업'
						WHEN 'SITTN' 		THEN '부산항 일일운영현황'
					   ELSE '기타'	
			   		   END tar_tp_nm
				FROM
					sns_attach
				WHERE conv_req_dttm is not null
				AND SUBSTR(conv_req_dttm,0,8) between #{start_dttm} AND #{end_dttm}
				<if test="searchType != null and searchType !=''">
					<choose>						
						<when test="searchType =='NOTICE'">
				    		and tar_tp in ('NOTICE','FAQ')
						</when>						
						<otherwise>
							AND TAR_TP IN 
							<foreach collection="searchType" item="item" index="index" separator="," open="(" close=")">
			                    #{item}
			                </foreach>
						</otherwise>
					</choose>	
			     </if>		
			) a
			order by a.DTTM
		)
		
	</select>
	
	
	 <select id="listFileCvtLogStats"  parameterMap="fileCvtVO"  resultMap="fileCvtVO">
	 /* [i2c.biz.admin.fileMng.dao.FileCvtDAO.listFileCvtLogStats] 파일변환 내역 리스트 */
		
		SELECT
			*
		FROM
		(
			SELECT 	ROWNUM RNUM,
				COUNT(a.attachNm) OVER() TOTAL_CNT,
				ROW_NUMBER() OVER(ORDER BY A.DTTM DESC) RN,
				a.*
			FROM (
				SELECT
					   TO_CHAR(TO_DATE(conv_req_dttm,'yyyyMMddHH24MISS'), 'yyyy-MM-dd DY HH24:MI:SS') DTTM
					 , tar_tp
					 , attach_nm attachNm
					 , crt_usr_id, FN_GET_USR_NM(crt_usr_id) crt_usr_nm
		    		 , conv_yn
					 , CASE tar_tp						
						WHEN 'NOTICE' 		THEN '게시판'
						WHEN 'FAQ' 			THEN '게시판'
						WHEN 'CFRC' 		THEN '회의'
						WHEN 'POST' 		THEN '피드'
						WHEN 'TASK' 		THEN '작업'
						WHEN 'SITTN' 		THEN '부산항 일일운영현황'
					   ELSE '기타'
			   		   END tar_tp_nm
				FROM
					sns_attach
				WHERE conv_req_dttm is not null
				AND SUBSTR(conv_req_dttm,0,8) between #{start_dttm} AND #{end_dttm}
				<if test="searchType != null and searchType !=''">
					<choose>						
						<when test="searchType =='NOTICE'">
				    		and tar_tp in ('NOTICE','FAQ')
						</when>						
						<otherwise>
							AND TAR_TP IN 
							<foreach collection="searchType" item="item" index="index" separator="," open="(" close=")">
			                    #{item}
			                </foreach>
						</otherwise>
					</choose>	
			     </if>		
			     ORDER BY DTTM DESC 
			) a			
			
		)
	    <![CDATA[
			 WHERE RNUM  > #{firstIndex}
		     AND   RNUM <= #{firstIndex} + #{recordCountPerPage}
			 ORDER BY RN 
	   ]]> 
	 </select>
	
	
</mapper>