package com.style24.batch.biz.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.style24.batch.biz.dao.TsbBatchDao;
import com.style24.batch.support.env.TsbConstants;
import com.style24.persistence.domain.BatchLog;

import lombok.extern.slf4j.Slf4j;

/**
 * 배치 Service
 *
 * @author gagamel
 * @since 2020. 12. 2
 */
@Service
@Slf4j
public class TsbBatchService {

	@Autowired
	private TsbBatchDao batchDao;

	/**
	 * 배치ID로 배치명 조회
	 * @param batchId - 배치ID
	 * @return
	 * @author gagamel
	 * @since 2020. 12. 2
	 */
	public String getBatchName(String batchId) {
		return batchDao.getBatchName(batchId);
	}

	/**
	 * 배치로그 생성
	 * @param batchId - 배치ID
	 * @return 배치로그일련번호
	 * @author gagamel
	 * @since 2020. 12. 2
	 */
	@Transactional("shopTxnManager")
	public Integer createBatchLog(String batchId) {

		BatchLog batchLog = new BatchLog();
		batchLog.setBatchId(batchId);
		batchLog.setRegNo(TsbConstants.REG_NO);
		batchDao.createBatchLog(batchLog);

		return batchLog.getBatchLogSq();
	}

	/**
	 * 배치로그 종료 처리
	 * @param batchLogSq - 배치로그일련번호
	 * @return
	 * @author gagamel
	 * @since 2020. 12. 2
	 */
	public void updateBatchLog(Integer batchLogSq) {
		batchDao.updateBatchLog(batchLogSq);
	}

}
