package com.style24.batch.biz.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.style24.batch.biz.job.statistics.TsbInflowStatisticsJob;
import com.style24.batch.biz.job.statistics.TsbInflowYesterdayStatisticsJob;
import com.style24.batch.biz.job.statistics.TsbSalesSmsSendJob;
import com.style24.batch.biz.job.statistics.TsbSalesUploadJob;
import com.style24.core.support.controller.TscBaseController;

import lombok.extern.slf4j.Slf4j;

/**
 * 통계 Controller
 * 
 * @author gagamel
 * @since 2021. 5. 24
 */
@Controller
@RequestMapping("/statistics")
@CrossOrigin(origins = "${domain.admin}")
@Slf4j
public class TsbStatisticsController extends TscBaseController {

	@Autowired
	private TsbInflowStatisticsJob inflowStatisticsJob;

	@Autowired
	private TsbInflowYesterdayStatisticsJob inflowYesterdayStatisticsJob;

	@Autowired
	private TsbSalesSmsSendJob salesSmsSendJob;

	@Autowired
	private TsbSalesUploadJob salesUploadJob;

	/**
	 * 제휴채널 유입집계 생성
	 * @throws Exception
	 * @author gagamel
	 * @since 2021. 5. 24
	 */
	@GetMapping("/aflink/inflow/create")
	@ResponseBody
	public String createAflinkInflow() throws Exception {
		inflowStatisticsJob.runById("cron.statistics.aflink.inflow.create");
		return "OK";
	}

	/**
	 * 제휴채널 유입집계 전일자 생성
	 * @return 메시지
	 * @throws Exception
	 * @author gagamel
	 * @since 2021. 5. 24
	 */
	@GetMapping("/aflink/inflow/yesterday/create")
	@ResponseBody
	public String createAflinkInflowYesterday() throws Exception {
		inflowYesterdayStatisticsJob.runById("cron.statistics.aflink.inflow.yesterday.create");
		return "OK";
	}

	/**
	 * 매출문자 발송 (평일은 저녁 8시30분, 11시30분, 주말(토/일)은 오전 10시, 오후 2시, 6시, 저녁 10시)
	 */
	@GetMapping("/sales/sms/send")
	@ResponseBody
	public String sendSalesSmsJob() throws Exception {
		salesSmsSendJob.runById("cron.statistics.sales.sms.send");
		return "OK";
	}

	/**
	 * 매출반영
	 *
	 * @throws Exception
	 */
	@GetMapping("/sales/upload")
	@ResponseBody
	public String salesUploadJob() throws Exception {
		salesUploadJob.runById("cron.statistics.sales.upload");
		return "OK";
	}

}
