<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="StatisticsManagement">
   <statement id="selectStatisticsManagementCount" parameterClass="java.util.HashMap" resultClass="java.lang.Integer">
         SELECT COUNT(*)
        FROM $schemaId$.TSEAIST01
        WHERE STATCJOBYMD BETWEEN CONCAT( #searchStart# , '00' ) AND CONCAT( #searchEnd# , '99' )
		<isNotEmpty prepend="AND" property="searchJobTypeCd">
			   STATCJOBCYCLDSTCD = #searchJobTypeCd#
		</isNotEmpty>
  </statement>

  <statement id="selectStatisticsManagement" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
  	SELECT 
			ROW_NUM "ROWNUM"  
			, STATCJOBYMD "STATCJOBYMD"
			, STATCJOBCYCLDSTCD "STATCJOBCYCLDSTCD" 
			, STATCJOBCYCLDSTNM "STATCJOBCYCLDSTNM" 
			, STATCJOBSTARTHMS "STATCJOBSTARTHMS"
	        , STATCJOBENDHMS "STATCJOBENDHMS"
	        , STATCJOBHMS "STATCJOBHMS"
	        , SUCSSYN "SUCSSYN"
	        , SUCSSYNNM "SUCSSYNNM"
			, ERRMSG "ERRMSG"
		FROM (
	        SELECT 
	         		@NO := @NO + 1 ROW_NUM 
	         	  , STATCJOBYMD "STATCJOBYMD"
	         	  , STATCJOBCYCLDSTCD "STATCJOBCYCLDSTCD"
	         	  , CASE  WHEN STATCJOBCYCLDSTCD = 'M' THEN '월별작업' WHEN STATCJOBCYCLDSTCD = 'D' THEN '일별작업'  ELSE '신로그작업' END "STATCJOBCYCLDSTNM"
	         	  , STATCJOBSTARTHMS "STATCJOBSTARTHMS"
	         	  , STATCJOBENDHMS "STATCJOBENDHMS"
	       	  	  , CASE  WHEN trim(STATCJOBENDHMS) IS NOT null THEN  
					convert(( CAST(SUBSTR(STATCJOBENDHMS,9,2)  as SIGNED) * 3600 + CAST(SUBSTR(STATCJOBENDHMS,11,2) as SIGNED) * 60 + CAST(SUBSTR(STATCJOBENDHMS,13,2) as SIGNED) ) 
		              - ( CAST(SUBSTR(STATCJOBSTARTHMS, 9,2)  as SIGNED) * 3600 + CAST(SUBSTR(STATCJOBSTARTHMS ,11,2) as SIGNED) * 60 + CAST(SUBSTR(STATCJOBSTARTHMS ,13,2) as SIGNED)), CHAR)
	       	  		ELSE 'RUNNING' END "STATCJOBHMS"
	         	  , SUCSSYN "SUCSSYN"
	         	  , CASE WHEN SUCSSYN = '1' THEN '성공' ELSE '실패' END "SUCSSYNNM"
	         	  , ERRMSG "ERRMSG"
	        FROM $schemaId$.TSEAIST01, (SELECT @NO := 0) R
	        WHERE STATCJOBYMD BETWEEN #searchStart# AND #searchEnd# 
			<isNotEmpty prepend="AND" property="searchJobTypeCd">
				   STATCJOBCYCLDSTCD = #searchJobTypeCd#
			</isNotEmpty>
			ORDER BY STATCJOBYMD DESC
       	) ORGTABLE
		WHERE ROW_NUM BETWEEN #startNum# AND #endNum#
  </statement>
  
   <statement id="selectDetail" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
     SELECT STATCJOBYMD "STATCJOBYMD"
         	  , STATCJOBCYCLDSTCD "STATCJOBCYCLDSTCD"
         	  , CASE  WHEN STATCJOBCYCLDSTCD = 'M' THEN '월별작업' WHEN STATCJOBCYCLDSTCD = 'D' THEN '일별작업'  ELSE '신로그작업' END "STATCJOBCYCLDSTNM"
         	  , CASE  WHEN trim(STATCJOBENDHMS) IS NOT null THEN  
					convert(( CAST(SUBSTR(STATCJOBENDHMS,9,2) as SIGNED) * 3600 + CAST(SUBSTR(STATCJOBENDHMS,11,2) as SIGNED) * 60 + CAST(SUBSTR(STATCJOBENDHMS,13,2) as SIGNED) ) 
		              - ( CAST(SUBSTR(STATCJOBSTARTHMS, 9,2) as SIGNED) * 3600 + CAST(SUBSTR(STATCJOBSTARTHMS ,11,2) as SIGNED) * 60 + CAST(SUBSTR(STATCJOBSTARTHMS ,13,2) as SIGNED)). CHAR)
	       	  		ELSE 'RUNNING' END "STATCJOBHMS"
         	  , STATCJOBSTARTHMS "STATCJOBSTARTHMS"
         	  , STATCJOBENDHMS "STATCJOBENDHMS"
         	  , SUCSSYN "SUCSSYN"
         	  , CASE WHEN SUCSSYN = '1' THEN '성공' ELSE '실패' END "SUCSSYNNM"
         	  , ERRMSG "ERRMSG"
        FROM $schemaId$.TSEAIST01
        WHERE STATCJOBYMD = #statcjobymd# 
        AND STATCJOBCYCLDSTCD = #statcjobcycldstcd#
   </statement>
	
	<statement id="selectListToExcel" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
    	SELECT 
			$headersStr$
		FROM (
			SELECT 
	         		@NO := @NO + 1 ROW_NUM 
	         	  , STATCJOBYMD "STATCJOBYMD"
	         	  , STATCJOBCYCLDSTCD "STATCJOBCYCLDSTCD"
	         	  , CASE  WHEN STATCJOBCYCLDSTCD = 'M' THEN '월별작업' WHEN STATCJOBCYCLDSTCD = 'D' THEN '일별작업'  ELSE '신로그작업' END "STATCJOBCYCLDSTNM"
	         	  , STATCJOBSTARTHMS "STATCJOBSTARTHMS"
	         	  , STATCJOBENDHMS "STATCJOBENDHMS"
	       	  	  , CASE  WHEN trim(STATCJOBENDHMS) IS NOT null THEN  
					convert(( CAST(SUBSTR(STATCJOBENDHMS,9,2)) * 3600 + CAST(SUBSTR(STATCJOBENDHMS,11,2)) * 60 + CAST(SUBSTR(STATCJOBENDHMS,13,2)) ) 
		              - ( CAST(SUBSTR(STATCJOBSTARTHMS, 9,2)) * 3600 + CAST(SUBSTR(STATCJOBSTARTHMS ,11,2)) * 60 + CAST(SUBSTR(STATCJOBSTARTHMS ,13,2))), CHAR)
	       	  		ELSE 'RUNNING' END "STATCJOBHMS"
	         	  , SUCSSYN "SUCSSYN"
	         	  , CASE WHEN SUCSSYN = '1' THEN '성공' ELSE '실패' END "SUCSSYNNM"
	         	  , ERRMSG "ERRMSG"
	        FROM $schemaId$.TSEAIST01, (SELECT @NO := 0) R
	        WHERE STATCJOBYMD BETWEEN #searchStart#  AND #searchEnd# 
			<isNotEmpty prepend="AND" property="searchJobTypeCd">
				   STATCJOBCYCLDSTCD = #searchJobTypeCd#
			</isNotEmpty>
			ORDER BY STATCJOBYMD DESC
		
		)  ORGTABLE
	</statement>
	
	
	<statement id="update" parameterClass="java.util.HashMap" resultClass="java.lang.Integer">
	 	UPDATE 	$schemaId$.TSEAIST01 
	 	SET ERRMSG = #errmsg#
	 	  WHERE STATCJOBYMD = #statcjobymd# 
        AND STATCJOBCYCLDSTCD = #statcjobcycldstcd#
	</statement>
	
	<statement id="delete" parameterClass="java.util.HashMap" resultClass="java.lang.Integer">
	 	DELETE	FROM $schemaId$.TSEAIST01 
	 	  WHERE STATCJOBYMD = #statcjobymd# 
        AND STATCJOBCYCLDSTCD = #statcjobcycldstcd#
	</statement> 
	 

</sqlMap>
