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.TsbCjWithdrawInvoiceJob;
import com.style24.batch.biz.job.delivery.TsbCjWithdrawInvoiceStatJob;
import com.style24.batch.biz.job.delivery.TsbWithdrawExcRcvJob;
import com.style24.batch.biz.job.delivery.TsbWithdrawExcRsltJob;
import com.style24.batch.biz.job.delivery.TsbWithdrawRequestJob;
import com.style24.batch.biz.job.delivery.TsbWithdrawRsltJob;

import lombok.extern.slf4j.Slf4j;

/**
 * 회수 Task
 * @author moon
 * @since 2020. 12. 08
 */
@Component
@Slf4j
public class TsbWithdrawTask {

	@Autowired
	private TsbWithdrawExcRcvJob withdrawExcRcvJob;

	@Autowired
	private TsbWithdrawExcRsltJob withdrawExcRsltJob;

	@Autowired
	private TsbWithdrawRsltJob withdrawRsltJob;

	@Autowired
	private TsbWithdrawRequestJob tsbWithdrawRequestJob;

	@Autowired
	private TsbCjWithdrawInvoiceJob tsbCjWithdrawInvoiceJob;

	@Autowired
	private TsbCjWithdrawInvoiceStatJob tsbCjWithdrawInvoiceStatJob;

	/**
	 * 초 분 시 일 월 주(년)
	 * 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
	 */

	/**
	 * WMS 회수요청
	 *
	 * @throws Exception
	 */
	@Scheduled(cron = "${cron.withdraw.wms.request}")
	//@Scheduled(fixedDelay = 3500000)
	@Async
	public void withdrawWmsRequestJob() throws Exception {
		tsbWithdrawRequestJob.runById("cron.withdraw.wms.request");
	}

	/**
	 * WMS 회수입고예외 수신
	 *
	 * @throws Exception
	 */
	@Scheduled(cron = "${cron.withdraw.wms.ingoing.exception.receive}")
	//@Scheduled(fixedDelay = 3500000)
	@Async
	public void withdrawWmsIngoingExceptionReceiveJob() throws Exception {
		withdrawExcRcvJob.runById("cron.withdraw.wms.ingoing.exception.receive");
	}

	/**
	 * WMS 회수입고예외결과 송신
	 *
	 * @throws Exception
	 */
	@Scheduled(cron = "${cron.withdraw.wms.ingoing.exception.result.receive}")
	//@Scheduled(fixedDelay = 3500000)
	@Async
	public void withdrawWmsIngoingExceptionResultReceiveJob() throws Exception {
		withdrawExcRsltJob.runById("cron.withdraw.wms.ingoing.exception.result.receive");
	}

	/**
	 * WMS 회수입고결과 수신
	 *
	 * @throws Exception
	 */
	@Scheduled(cron = "${cron.withdraw.wms.ingoing.result.receive}")
	//@Scheduled(fixedDelay = 3500000)
	@Async
	public void withdrawWmsIngoingResultReceiveJob() throws Exception {
		withdrawRsltJob.runById("cron.withdraw.wms.ingoing.result.receive");
	}

	/**
	 * CJ 회수송장번호 수신
	 *
	 * @throws Exception
	 */
	@Scheduled(cron = "${cron.withdraw.cj.invoice.receive}")
	//@Scheduled(fixedDelay = 3500000)
	@Async
	public void withdrawCjInvoiceReceiveJob() throws Exception {
		tsbCjWithdrawInvoiceJob.runById("cron.withdraw.cj.invoice.receive");
	}

	/**
	 * CJ 회수상태 수신
	 *
	 * @throws Exception
	 */
	@Scheduled(cron = "${cron.withdraw.cj.status.receive}")
	//@Scheduled(fixedDelay = 3500000)
	@Async
	public void withdrawCjStatusJob() throws Exception {
		tsbCjWithdrawInvoiceStatJob.runById("cron.withdraw.cj.status.receive");
	}

}
