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.delivery.TsbDailyDeliveryZoneJob;
import com.style24.batch.biz.job.delivery.TsbDeliveryExcRcvJob;
import com.style24.batch.biz.job.delivery.TsbDeliveryOrderJob;
import com.style24.batch.biz.job.delivery.TsbDeliveryOrderRsltJob;
import com.style24.batch.biz.job.delivery.TsbInvoiceNoRcvJob;
import com.style24.batch.biz.job.delivery.TsbSoldoutCancelJob;
import com.style24.batch.biz.job.delivery.TsbSweetTrackerJob;
import com.style24.core.support.controller.TscBaseController;

import lombok.extern.slf4j.Slf4j;

/**
 * 배송 Controller
 * 
 * @author gagamel
 * @since 2021. 5. 24
 */
@Controller
@RequestMapping("/delivery")
@CrossOrigin(origins = "${domain.admin}")
@Slf4j
public class TsbDeliveryController extends TscBaseController {

	@Autowired
	private TsbDailyDeliveryZoneJob dailyDeliveryZoneJob;

	@Autowired
	private TsbDeliveryOrderJob deliveryOrderJob;

	@Autowired
	private TsbDeliveryExcRcvJob deliveryExcRcvJob;

	@Autowired
	private TsbDeliveryOrderRsltJob deliveryOrderRsltJob;

	@Autowired
	private TsbInvoiceNoRcvJob tsbInvoiceNoRcvJob;

	@Autowired
	private TsbSweetTrackerJob tsbSweetTrackerJob;

	@Autowired
	private TsbSoldoutCancelJob tsbSoldoutCancelJob;

	/**
	 * 총알배송 권역정보   : 일배치  오전 11시
	 *
	 * @throws Exception
	 */
	@GetMapping("/shot/deliveryzone/refresh")
	@ResponseBody
	public String shotDeliveryZoneRefreshJob() throws Exception {
		dailyDeliveryZoneJob.run("cron.delivery.shot.deliveryzone.refresh");
		return "OK";
	}

	/**
	 * 출고처지정 및 배송(출고)지시   : 분배치 10분??
	 *
	 * @throws Exception
	 */
	@GetMapping("/loc/assign")
	@ResponseBody
	public String deliveryLocAssignJob() throws Exception {
		deliveryOrderJob.run("cron.delivery.loc.assign");
		return "OK";
	}

	/**
	 * WMS 출고예외 수신
	 *
	 * @throws Exception
	 */
	@GetMapping("/wms/outgoing/exception/receive")
	@ResponseBody
	public String wmsOutgoingExceptionReceiveJob() throws Exception {
		deliveryExcRcvJob.run("cron.delivery.wms.outgoing.exception.receive");
		return "OK";
	}

	/**
	 * WMS 출고결과 수신
	 *
	 * @throws Exception
	 */
	@GetMapping("/wms/outgoing/result/receive")
	@ResponseBody
	public String wmsOutgoingResultReceiveJob() throws Exception {
		deliveryOrderRsltJob.run("cron.delivery.wms.outgoing.result.receive");
		return "OK";
	}

	/**
	 * WMS 송장번호 수신  
	 *
	 * @throws Exception
	 */
	@GetMapping("/wms/invoice/receive")
	@ResponseBody
	public String wmsInvoiceReceiveJob() throws Exception {
		tsbInvoiceNoRcvJob.run("cron.delivery.wms.invoice.receive");
		return "OK";
	}

	/**
	 * 스윗트래커  배송 추적 요청
	 *
	 * @throws Exception
	 */
	@GetMapping("/sweettracker/invoice/retrieve")
	@ResponseBody
	public String sweettrackerInvoiceRetrieveJob() throws Exception {
		tsbSweetTrackerJob.run("cron.delivery.sweettracker.invoice.retrieve");
		return "OK";
	}

	/**
	 * 자동품절취소
	 *
	 * @throws Exception
	 */
	@GetMapping("/auto/soldout/cancel")
	@ResponseBody
	public String autoSoldoutCancelJob() throws Exception {
		tsbSoldoutCancelJob.run("cron.delivery.auto.soldout.cancel");
		return "OK";
	}

}
