package com.style24.batch.biz.job.statistics;

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.TsbMonitoringService;
import com.style24.batch.biz.service.TsbStatisticsService;
import com.style24.persistence.domain.SalesSms;

import lombok.extern.slf4j.Slf4j;

import com.gagaframework.web.parameter.GagaMap;
import com.gagaframework.web.util.GagaDateUtil;

/**
 * 매출문자 발송
 * 
 * @author gagamel
 * @since 2021. 8. 13
 */
@Component
@Slf4j
public class TsbSalesSmsSendJob extends TsbAbstractJob<SalesSms, String, String> {

	@Autowired
	private TsbStatisticsService statisticsService;

	@Autowired
	private TsbMonitoringService monitoringService;

	@Override
	public SalesSms read() throws Exception {
		// 당일 매출 조회 (주문, 취소, 반품)
		SalesSms salesInfo = statisticsService.getCurrentDaySalesSms();
		log.info("{}", salesInfo);
		return salesInfo;
	}

	@Override
	public String process(SalesSms salesInfo) throws Exception {
		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setString("salesDt", GagaDateUtil.getToday("MM/dd"));
		replaceInfo.setString("totNetSalesAmt", String.format("%,d", salesInfo.getTotNetSalesAmt()));
		replaceInfo.setString("totCnclAmt", String.format("%,d", salesInfo.getTotCnclAmt()));

		// 전일자 전체매출 문자 발송
		monitoringService.createSystemAlarmSms("A006", replaceInfo);

		// 전일자 캐주얼파트매출 문자 발송 (한세엠케이 + FRJ 합산)
		replaceInfo.setString("mkNetSalesAmt", String.format("%,d", salesInfo.getMkNetSalesAmt()));
		monitoringService.createSystemAlarmSms("A007", replaceInfo);

		// 전일자 유아동파트매출 문자 발송 (한세드림)
		replaceInfo.setString("drNetSalesAmt", String.format("%,d", salesInfo.getDrNetSalesAmt()));
		monitoringService.createSystemAlarmSms("A008", replaceInfo);

		return "OK";
	}

	@Override
	public String write(String result) throws Exception {
		return result;
	}

	@Override
	public void notify(String result) throws Exception {
		// Do nothing
	}

}