package com.style24.batch.biz.task;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.style24.batch.biz.job.delivery.TsbShopGoodsStockJob;
import com.style24.batch.biz.job.goods.TsbDaumAllEp;
import com.style24.batch.biz.job.goods.TsbDaumReviewEp;
import com.style24.batch.biz.job.goods.TsbDaumSummaryEp;
import com.style24.batch.biz.job.goods.TsbGoodsBenefitJob;
import com.style24.batch.biz.job.goods.TsbGoodsBenefitPriceJob;
import com.style24.batch.biz.job.goods.TsbGoodsInfantsSafeNoJob;
import com.style24.batch.biz.job.goods.TsbGoodsPriceJob;
import com.style24.batch.biz.job.goods.TsbGoodsReinboundJob;
import com.style24.batch.biz.job.goods.TsbGoodsRelateScoreJob;
import com.style24.batch.biz.job.goods.TsbGoodsSearchAllJob;
import com.style24.batch.biz.job.goods.TsbGoodsSearchSectionJob;
import com.style24.batch.biz.job.goods.TsbGoodsSnmJob;
import com.style24.batch.biz.job.goods.TsbGoodsSummaryJob;
import com.style24.batch.biz.job.goods.TsbGoodsTnmJob;
import com.style24.batch.biz.job.goods.TsbGoodsVwStockJob;
import com.style24.batch.biz.job.goods.TsbGoodsWmsBrandproviderJob;
import com.style24.batch.biz.job.goods.TsbGoodsWmsGoodsJob;
import com.style24.batch.biz.job.goods.TsbGoodsWmsGoodsStockJob;
import com.style24.batch.biz.job.goods.TsbGoodsWmsIncomelotJob;
import com.style24.batch.biz.job.goods.TsbGoodsWmsMeasurementJob;
import com.style24.batch.biz.job.goods.TsbNaverAllEp;
import com.style24.batch.biz.job.goods.TsbNaverSellEp;
import com.style24.batch.biz.job.goods.TsbNaverSummaryEp;
import com.style24.batch.biz.job.social.TsbSocialGoodsJob;

import lombok.extern.slf4j.Slf4j;

/**
 * 상품 Task
 * @author eskim
 * @since 2020. 11. 27
 */
@Component
@Slf4j
public class TsbGoodsTask {

	@Autowired
	private TsbGoodsTnmJob goodsTnmJob;

	@Autowired
	private TsbGoodsPriceJob goodsPriceJob;

	@Autowired
	private TsbGoodsSnmJob goodsSnmJob;

	@Autowired
	private TsbGoodsBenefitPriceJob goodsBenefitPriceJob;

	@Autowired
	private TsbGoodsRelateScoreJob goodsRelateScoreJob;

	@Autowired
	private TsbGoodsSummaryJob goodsSummaryJob;

	@Autowired
	private TsbGoodsInfantsSafeNoJob goodsInfantsSafeNoJob;

	@Autowired
	private TsbGoodsWmsMeasurementJob goodsWmsMeasurementJob;

	@Autowired
	private TsbGoodsWmsIncomelotJob goodsWmsIncomelotJob;

	@Autowired
	private TsbGoodsWmsBrandproviderJob goodsWmsBrandproviderJob;

	@Autowired
	private TsbGoodsWmsGoodsJob goodsWmsGoodsJob;

	@Autowired
	private TsbGoodsWmsGoodsStockJob goodsWmsGoodsStockJob;

	@Autowired
	private TsbNaverAllEp naverAllEp;

	@Autowired
	private TsbNaverSummaryEp naverSummaryEp;

	@Autowired
	private TsbNaverSellEp naverSellEp;

	@Autowired
	private TsbDaumAllEp daumAllEp;

	@Autowired
	private TsbDaumSummaryEp daumSummaryEp;

	@Autowired
	private TsbDaumReviewEp daumReviewEp;

	@Autowired
	private TsbGoodsBenefitJob goodsBenefitJob;

	@Autowired
	private TsbShopGoodsStockJob tsbShopGoodsStockJob;

	@Autowired
	private TsbSocialGoodsJob socialGoodsJob;

	@Autowired
	private TsbGoodsSearchAllJob goodsSearchAllJob;

	@Autowired
	private TsbGoodsSearchSectionJob goodsSearcSectionJob;

	@Autowired
	private TsbGoodsReinboundJob goodsReinboundJob;

	@Autowired
	private TsbGoodsVwStockJob goodVwStockJob;

	/**
	 * 초 분 시 일 월 주(년)
	 * 0 0 12 * * ?" : 아무 요일, 매월, 매일 12:00:00
	 * 0 15 10 ? * *" : 모든 요일, 매월, 아무 날이나 10:15:00
	 * 0 15 10 * * ?" : 아무 요일, 매월, 매일 10:15:00
	 * 0 15 10 * * ? *" : 모든 연도, 아무 요일, 매월, 매일 10:15
	 * 0 15 10 * * ? : 2005" 2005년 아무 요일이나 매월, 매일 10:15
	 * 0 * 14 * * ?" : 아무 요일, 매월, 매일, 14시 매분 0초
	 * 0 0/5 14 * * ?" : 아무 요일, 매월, 매일, 14시 매 5분마다 0초
	 * 0 0/5 14,18 * * ?" : 아무 요일, 매월, 매일, 14시, 18시 매 5분마다 0초
	 * 0 0-5 14 * * ?" : 아무 요일, 매월, 매일, 14:00 부터 매 14:05까지 매 분 0초
	 * 0 10,44 14 ? 3 WED" : 3월의 매 주 수요일, 아무 날짜나 14:10:00, 14:44:00
	 * 0 15 10 ? * MON-FRI" : 월~금, 매월, 아무 날이나 10:15:00
	 * 0 15 10 15 * ?" : 아무 요일, 매월 15일 10:15:00
	 * 0 15 10 L * ?" : 아무 요일, 매월 마지막 날 10:15:00
	 * 0 15 10 ? * 6L" : 매월 마지막 금요일 아무 날이나 10:15:00
	 * 0 15 10 ? * 6L 2002-2005" : 2002년부터 2005년까지 매월 마지막 금요일 아무 날이나 10:15:00
	 * 0 15 10 ? * 6#3" : 매월 3번째 금요일 아무 날이나 10:15:00
	 *
	 * @throws Exception
	 */

	/**
	 * 상품 타이틀예약 적용 주기 : 시간배치 - 매시 1분 (소셜과 시간 중복)
	 *
	 * @throws Exception
	 */
	@Scheduled(cron = "${cron.goods.reserve.titlename.apply}")
	@Async
	public void reserveTitlenameApplyJob() throws Exception {
		goodsTnmJob.runById("cron.goods.reserve.titlename.apply");
	}

	/**
	 * 상품 가격예약 적용 주기 : 시간배치 - 매시 1분 (소셜과 시간 중복)
	 *
	 * @throws Exception
	 */
	@Scheduled(cron = "${cron.goods.reserve.price.apply}")
	@Async
	public void reservePriceApplyJob() throws Exception {
		goodsPriceJob.runById("cron.goods.reserve.price.apply");
	}

	/**
	 * 상품 검색어 적용 주기 : 시간배치 - 매시 5분
	 *
	 * @throws Exception
	 */
	@Scheduled(cron = "${cron.goods.keyword.create}")
	@Async
	public void keywordCreateJob() throws Exception {
		goodsSnmJob.runById("cron.goods.keyword.create");
	}

	/**
	 * 상품 즉시할인가 생성 : 시간배치 - 매시 2분
	 *
	 * @throws Exception
	 * @author eskim
	 * @since 2020. 12. 02.
	 */
	@Scheduled(cron = "${cron.goods.benefit.price.create}")
	@Async
	public void benefitPriceCreateJob() throws Exception {
		goodsBenefitPriceJob.runById("cron.goods.benefit.price.create");
	}

//	/**
//	 * 연관상품보기 스코어링 주기 : 일배치 - 매일 2시
//	 *
//	 * @throws Exception
//	 */
//	@Scheduled(cron = "${cron.goods.relgoods.scoring}")
//	@Async
//	public void relationGoodsScoringJob() throws Exception {
//		goodsRelateScoreJob.runById("cron.goods.relgoods.scoring");
//	}

	/**
	 * 전시상품 통계정보 주기 : 일배치 - 매일 1시 5분
	 *
	 * @throws Exception
	 */
	@Scheduled(cron = "${cron.goods.summary.create}")
	@Async
	public void summaryCreateJob() throws Exception {
		goodsSummaryJob.run("cron.goods.summary.create");
	}

	/**
	 * 영유아상품 인증번호 수신 : 일회성배치
	 *
	 * @throws Exception
	 */
//	@Scheduled(cron = "${cron.goods.infants.safe}")
//	//@Scheduled(fixedDelay = 3500000)
//	@Async
//	public void tsbGoodsInfantsSafeNoJob() throws Exception {
//		goodsInfantsSafeNoJob.run("cron.goods.infants.safe");
//	}

	/**
	 * WMS 실측사이즈 연동 적용 주기 : 일배치 - 03시
	 *
	 * @throws Exception
	 */
	@Scheduled(cron = "${cron.goods.wms.measurement.receive}")
	@Async
	public void wmsMeasurementReceiveJob() throws Exception {
		goodsWmsMeasurementJob.runById("cron.goods.wms.measurement.receive");
	}

	/**
	 * WMS 입고상품 연동 적용 주기 : 일배치 - 03시 10분
	 *
	 * @throws Exception
	 */
	@Scheduled(cron = "${cron.goods.wms.incomelot.receive}")
	@Async
	public void wmsIncomelotReceiveJob() throws Exception {
		goodsWmsIncomelotJob.runById("cron.goods.wms.incomelot.receive");
	}

	/**
	 * WMS 업체/브랜드 송신 적용 주기 : 일배치 - 03시 12분
	 *
	 * @throws Exception
	 */
	@Scheduled(cron = "${cron.goods.wms.brandprovider.send}")
	@Async
	public void wmsBrandproviderSendJob() throws Exception {
		goodsWmsBrandproviderJob.runById("cron.goods.wms.brandprovider.send");
	}

	/**
	 * WMS 상품정보 송신 적용 주기 : 일배치 - 03시 15분
	 *
	 * @throws Exception
	 */
	@Scheduled(cron = "${cron.goods.wms.goods.send}")
	@Async
	public void wmsGoodsSendJob() throws Exception {
		goodsWmsGoodsJob.runById("cron.goods.wms.goods.send");
	}

	/**
	 * WMS 상품 재고 수신 적용 주기 : 시간배치 - 01분
	 *
	 * @throws Exception
	 */
	@Scheduled(cron = "${cron.goods.wms.stock.receive}")
	@Async
	public void wmsStockReceiveJob() throws Exception {
		goodsWmsGoodsStockJob.runById("cron.goods.wms.stock.receive");
	}

	/**
	 * 네이버 전체EP 생성
	 * @throws Exception
	 */
	@Scheduled(cron = "${cron.goods.ep.naver.all.goods.create}")
	@Async
	public void naverAllEpCreateJob() throws Exception {
		naverAllEp.runById("cron.goods.ep.naver.all.goods.create");
	}

	/**
	 * 네이버 요약EP 생성
	 * @throws Exception
	 */
	@Scheduled(cron = "${cron.goods.ep.naver.summary.goods.create}")
	@Async
	public void naverSummaryEpCreateJob() throws Exception {
		naverSummaryEp.runById("cron.goods.ep.naver.summary.goods.create");
	}

	/**
	 * 네이버 판매지수EP 생성
	 * @throws Exception
	 */
	@Scheduled(cron = "${cron.goods.ep.naver.sell.create}")
	@Async
	public void naverSellEpCreateJob() throws Exception {
		naverSellEp.runById("cron.goods.ep.naver.sell.create");
	}

	/**
	 * 다음 전체EP 생성
	 * @throws Exception
	 */
	@Scheduled(cron = "${cron.goods.ep.daum.all.goods.create}")
	@Async
	public void daumAllEpCreateJob() throws Exception {
		daumAllEp.runById("cron.goods.ep.daum.all.goods.create");
	}

	/**
	 * 다음 요약EP 생성
	 * @throws Exception
	 */
	@Scheduled(cron = "${cron.goods.ep.daum.summary.goods.create}")
	@Async
	public void daumSummaryEpCreateJob() throws Exception {
		daumSummaryEp.runById("cron.goods.ep.daum.summary.goods.create");
	}

	/**
	 * 다음 상품평EP 생성
	 * @throws Exception
	 */
	@Scheduled(cron = "${cron.goods.ep.daum.review.create}")
	@Async
	public void daumReviewEpCreateJob() throws Exception {
		daumReviewEp.runById("cron.goods.ep.daum.review.create");
	}

	/**
	 * 상품혜택(쿠폰할인, 무료배송, 사은품, 신상) 생성
	 * @throws Exception
	 */
	@Scheduled(cron = "${cron.goods.benefit.create}")
	@Async
	public void benefitCreateJob() throws Exception {
		goodsBenefitJob.runById("cron.goods.benefit.create");
	}

	/**
	 * 매장상품재고 수신
	 *
	 * @throws Exception
	 */
	@Scheduled(cron = "${cron.goods.shop.stock.receive}")
	@Async
	public void shopGoodsStockReceiveJob() throws Exception {
		tsbShopGoodsStockJob.runById("cron.goods.shop.stock.receive");
	}

	/**
	 * 소셜 상품 적용 : 시간배치 - 매시 00분
	 *
	 * @throws Exception
	 */
	@Scheduled(cron = "${cron.goods.social.price.apply}")
	@Async
	public void socialPriceApplyJob() throws Exception {
		socialGoodsJob.runById("cron.goods.social.price.apply");
	}

	/**
	 * 검색전체색인 적용 : 일배치 - 매시 분
	 *
	 * @throws Exception
	 */
	@Scheduled(cron = "${cron.goods.search.all.create}")
	@Async
	public void searchGoodsAllCreateJob() throws Exception {
		goodsSearchAllJob.runById("cron.goods.search.all.create");
	}

	/**
	 * 검색전체색인 적용 : 일배치 - 매시 분
	 *
	 * @throws Exception
	 */
	@Scheduled(cron = "${cron.goods.search.section.create}")
	@Async
	public void searchGoodsCreateSectionJob() throws Exception {
		goodsSearcSectionJob.runById("cron.goods.search.section.create");
	}

	/**
	 * 재입고 알림
	 *
	 * @throws Exception
	 */
	@Scheduled(cron = "${cron.goods.reinbound.notify}")
	@Async
	public void reinboundJob() throws Exception {
		goodsReinboundJob.runById("cron.goods.reinbound.notify");
	}

	/**
	 * 상품 VW_STOCK 생성
	 *
	 * @throws Exception
	 */
	@Scheduled(cron = "${cron.goods.vwstock.create}")
	@Async
	public void goodsVwStockJob() throws Exception {
		goodVwStockJob.runById("cron.goods.vwstock.create");
	}

}
