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.TsbCommonService;
import com.style24.batch.biz.service.TsbGoodsService;
import com.style24.persistence.domain.GoodsIfMeasurement;

import lombok.extern.slf4j.Slf4j;

import com.gagaframework.web.util.GagaDateUtil;

/**
 * WMS 실측사이즈 수신
 *
 * @author eskim
 * @since 2020. 12. 31
 */
@Component
@Slf4j
public class TsbGoodsWmsMeasurementJob extends TsbAbstractJob<GoodsIfMeasurement, GoodsIfMeasurement, GoodsIfMeasurement> {

	@Autowired
	private TsbGoodsService goodsService;

	@Autowired
	private TsbCommonService commonService;

	private int succCnt = 0;
	private int failCnt = 0;
	private String jobdate = "";

	@Override
	public GoodsIfMeasurement read() throws Exception {

		// WMS 동기화 옵션 여부 확인
		String wmsSyncYn = commonService.getWmsSyncYn();
		if ("N".equals(wmsSyncYn)) {
			log.info("WMS 정보 동기화 미실행 {}, 연동여부 : {}", GagaDateUtil.getToday("yyyy-MM-dd HH:mm:ss"), wmsSyncYn);
			return null;
		}
		GoodsIfMeasurement goodsIfMeasurement = new GoodsIfMeasurement();
		return goodsIfMeasurement;
	}

	@Override
	public GoodsIfMeasurement process(GoodsIfMeasurement goodsIfMeasurement) throws Exception {
		return goodsIfMeasurement;
	}

	@Override
	public GoodsIfMeasurement write(GoodsIfMeasurement goodsIfMeasurement) throws Exception {

		jobdate = GagaDateUtil.getOffsetDate(-1);	//전일자
		goodsService.saveGoodsWmsMeasurement(jobdate);
		return goodsIfMeasurement;
	}

	@Override
	public void notify(GoodsIfMeasurement goodsIfMeasurement) throws Exception {
		super.printResult(succCnt, failCnt);
	}

}