<?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">
<mapper namespace="com.style24.batch.biz.dao.TsbBatchDao">
	
	<!-- 배치정보 조회 -->
	<select id="getBatchInfo" parameterType="String" resultType="BatchLog">
		/* TsbBatch.getBatchName */
		SELECT BATCH_NM
		     , IFNULL(BATCH_STAT,'F') AS BATCH_STAT
		FROM   TB_BATCH
		WHERE  BATCH_ID = #{batchId}
		AND    USE_YN = 'Y' /*사용하는 넘만*/
	</select>
	
	<!-- 배치로그 생성 -->
	<insert id="createBatchLog" parameterType="BatchLog" keyProperty="batchLogSq">
		/* TsbBatch.createBatchLog */
		INSERT INTO TB_BATCH_LOG (
		       BATCH_LOG_SQ
		     , BATCH_ID
		     , BATCH_STDT
		     , BATCH_STAT
		     , REG_NO
		     , REG_DT
		)
		VALUES (
		       #{batchLogSq}
		     , #{batchId}
		     , NOW(6) /*millisecond 까지 저장*/
		     , 'I'
		     , #{regNo}
		     , NOW()
		)
	</insert>
	
	<!-- 배치로그 종료 처리 -->
	<update id="updateBatchLog" parameterType="Integer">
		/* TsbBatch.updateBatchLog */
		UPDATE TB_BATCH_LOG
		SET    BATCH_EDDT = NOW(6) /*millisecond 까지 저장*/
		     , BATCH_STAT = 'F'
		WHERE  BATCH_LOG_SQ = #{batchLogSq}
		AND    BATCH_STAT = 'I'
	</update>
	
	<!-- 배치상태 처리 -->
	<update id="updateBatchStatus" parameterType="BatchLog">
		/* TsbBatch.updateBatchStatus */
		UPDATE TB_BATCH
		SET    BATCH_STAT = #{batchStat}
		WHERE  BATCH_ID = #{batchId}
	</update>
	
</mapper>