package com.style24.batch.biz.job.goods;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.style24.batch.biz.job.TsbAbstractJob;
import com.style24.batch.biz.service.TsbGoodsService;

import lombok.extern.slf4j.Slf4j;

/**
 * 상품 VW_STOCK 생성
 * 
 * @author gagamel
 * @since 2021. 8. 30
 */
@Component
@Slf4j
public class TsbGoodsVwStockJob extends TsbAbstractJob<String, String, String> {

	@Autowired
	private TsbGoodsService goodsService;

	@Override
	public String read() throws Exception {
		return "OK";
	}

	@Override
	public String process(String result) throws Exception {
		// VW_STOCK임시 테이블 truncate
		log.info("1.VW_STOCK임시 테이블 truncate");
		goodsService.truncateVwStockTemporary();

		// VW_STOCK임시 테이블 생성
		log.info("2.VW_STOCK임시 테이블 생성 시작");
		int cnt = goodsService.createVwStockTemporary();
		log.info("2.VW_STOCK임시 테이블 생성 완료: {}", cnt);

		if (cnt > 0) {
			log.info("3.VW_STOCK 테이블 생성 시작");
			cnt = goodsService.createVwStock();
			log.info("3.VW_STOCK임시 테이블 생성 완료: {}", cnt);
		}

		return "OK";
	}

	@Override
	public String write(String result) throws Exception {
		return "OK";
	}

	@Override
	public void notify(String result) throws Exception {
		// Do nothing
	}

}
