package com.style24.core.biz.service;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.gagaframework.web.parameter.GagaMap;
import com.style24.core.biz.thirdparty.NaverShortUrl;
import com.style24.core.biz.thirdparty.NetpathyMailSender;
import com.style24.core.support.env.TscConstants;
import com.style24.persistence.domain.Coupon;
import com.style24.persistence.domain.CustContactHst;
import com.style24.persistence.domain.CustCoupon;
import com.style24.persistence.domain.Customer;
import com.style24.persistence.domain.Order;
import com.style24.persistence.domain.Point;

import lombok.extern.slf4j.Slf4j;

import java.text.DecimalFormat;

/**
 * 메일 서비스
 *
 * @author jsshin
 * @since 2021. 6. 2
 */
@Service
@Slf4j
public class TscMailService {

	@Autowired
	private NetpathyMailSender netpathyMailSender;

	@Autowired
	private TscCustomerService coreCustomerService;


	/**
	 * 고객 임시비밀번호 이메일 발송
	 * @param customer - 고객 정보
	 * @author jsshin
	 * @since 2021. 06. 02
	 */
	@Transactional("shopTxnManager")
	public void sendCustomerTempPassword(Customer customer, Integer senderNo) {
		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setString("custNm", customer.getCustNm());
		replaceInfo.setString("passwd", customer.getPasswd());
		replaceInfo.setString("custId", customer.getCustId());

		netpathyMailSender.send(NetpathyMailSender.MailAnswerSq.TEMP_PASSWD.value(), customer.getEmail(), replaceInfo);

		try {
			// 고객접촉이력 정보
			CustContactHst custContactHst = new CustContactHst();
			custContactHst.setContactType(TscConstants.ContactType.TEMP_PASSWD.value()); // 접촉유형:임시비밀번호발급(공통코드G054)
			custContactHst.setContactMethod(TscConstants.ContactMethod.EMAIL.value()); // 접촉방법:알림톡+문자(공통코드G055)
			custContactHst.setContactContents("고객 임시비밀번호 발송");
			custContactHst.setReceiverNo(customer.getCustNo());
			custContactHst.setSenderNo(senderNo);
			custContactHst.setRegNo(senderNo);
			coreCustomerService.createCustomerContactHistory(custContactHst);
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
	}
	/**
	 * 회원가입 완료
	 *
	 * @param customer - 고객 정보
	 * @param coupon - 쿠폰정보
	 * @author jsshin
	 * @since 2021. 06. 02
	 */
	@Transactional("shopTxnManager")
	public void sendJoinCongrat(Customer customer, Coupon coupon, Integer senderNo) {
		String emailAgreeYn = "Y".equals(customer.getEmailAgreeYn()) ? "수신":"수신거부";
		String smsAgreeYn = "Y".equals(customer.getSmsAgreeYn()) ? "수신":"수신거부";

		String custId = customer.getCustId();
		if (TscConstants.SnsType.NAVER.value().equals(customer.getSnsType())) {
			custId = "네이버 간편가입회원";
		} else if (TscConstants.SnsType.KAKAO.value().equals(customer.getSnsType())) {
			custId = "카카오 간편가입회원";
		} else if (TscConstants.SnsType.YES24.value().equals(customer.getSnsType())) {
			custId = "YES24 간편가입회원";
		}

		GagaMap replaceInfo = new GagaMap();
		DecimalFormat df = new DecimalFormat("###,###");
		replaceInfo.setString("custId", custId);
		replaceInfo.setString("custNm", customer.getCustNm());
		replaceInfo.setInt("custNo", customer.getCustNo());
		replaceInfo.setString("emailAgreeYn", emailAgreeYn);
		replaceInfo.setString("smsAgreeYn", smsAgreeYn);
		replaceInfo.setString("dcVal", df.format(coupon.getDcVal()));
		replaceInfo.setString("dcWay", coupon.getDcWay());
		replaceInfo.setString("availStdtTime", coupon.getAvailStdtTime());
		replaceInfo.setString("availEddtTime", coupon.getAvailEddtTime());

		if (StringUtils.isNotBlank(coupon.getAvailStdtTime())) {
			String[] availStdt = coupon.getAvailStdtTime().split(" ");
			replaceInfo.setString("availStdt", availStdt[0]);
		}
		if (StringUtils.isNotBlank(coupon.getAvailEddtTime())) {
			String[] availEddt = coupon.getAvailEddtTime().split(" ");
			replaceInfo.setString("availEddt", availEddt[0]);
		}
		String tgtCondition = StringUtils.isBlank(coupon.getTgtCondition()) ? "제한없음" : coupon.getTgtCondition();
		replaceInfo.setString("tgtCondition", tgtCondition);
		replaceInfo.setString("useCondition", coupon.getUseCondition());

		netpathyMailSender.send(NetpathyMailSender.MailAnswerSq.JOIN_CONGRATS.value(), customer.getEmail(), replaceInfo);

		try {
			// 고객접촉이력 정보
			CustContactHst custContactHst = new CustContactHst();
			custContactHst.setContactType(TscConstants.ContactType.JOIN_CONGRATS.value()); // 접촉유형:회원가입축하(공통코드G054)
			custContactHst.setContactMethod(TscConstants.ContactMethod.EMAIL.value()); // 접촉방법:알림톡+문자(공통코드G055)
			custContactHst.setContactContents("회원가입축하");
			custContactHst.setReceiverNo(customer.getCustNo());
			custContactHst.setSenderNo(senderNo);
			custContactHst.setRegNo(senderNo);
			coreCustomerService.createCustomerContactHistory(custContactHst);
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
	}

	/**
	 * 회원탈퇴
	 *
	 * @param customer - 고객 정보
	 * @param senderNo - 보낸NO
	 * @author jsshin
	 * @since 2021. 06. 02
	 */
	@Transactional("shopTxnManager")
	public void sendSecedComplete(Customer customer, Integer senderNo) {

		String custId = customer.getCustId();
		if (TscConstants.SnsType.NAVER.value().equals(customer.getSnsType())) {
			custId = "네이버 간편가입회원";
		} else if (TscConstants.SnsType.KAKAO.value().equals(customer.getSnsType())) {
			custId = "카카오 간편가입회원";
		} else if (TscConstants.SnsType.YES24.value().equals(customer.getSnsType())) {
			custId = "YES24 간편가입회원";
		}

		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setInt("custNo", customer.getCustNo());
		replaceInfo.setString("custId", custId);
		replaceInfo.setString("custNm", customer.getCustNm());
		replaceInfo.setString("secedeDt", customer.getSecedeDt());
		replaceInfo.setInt("rejoinRejectDay", customer.getRejoinRejectDay());

		netpathyMailSender.send(NetpathyMailSender.MailAnswerSq.SECEDE_CUST.value(), customer.getEmail(), replaceInfo);

		try {
			// 고객접촉이력 정보
			CustContactHst custContactHst = new CustContactHst();
			custContactHst.setContactType(TscConstants.ContactType.SECEDE_CUST.value()); // 접촉유형:임시비밀번호발급(공통코드G054)
			custContactHst.setContactMethod(TscConstants.ContactMethod.EMAIL.value()); // 접촉방법:알림톡+문자(공통코드G055)
			custContactHst.setContactContents("회원탈퇴안내");
			custContactHst.setReceiverNo(customer.getCustNo());
			custContactHst.setSenderNo(senderNo);
			custContactHst.setRegNo(senderNo);
			coreCustomerService.createCustomerContactHistory(custContactHst);
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
	}

	/**
	 * 휴면계정전환 안내
	 *
	 * @param customer - 고객 정보
	 * @param senderNo - 보낸
	 * @author jsshin
	 * @since 2021. 06. 07
	 */
	@Transactional("shopTxnManager")
	public void sendExpectedDormentCustomer(Customer customer, Integer senderNo) {
		String year  = "";
		String month = "";
		String day = "";
		if (StringUtils.isNotBlank(customer.getFewDt()) && customer.getFewDt().length() > 7) {
			String fewDt = customer.getFewDt();
			year = fewDt.substring(0, 4);
			month = fewDt.substring(4, 6);
			day = fewDt.substring(6, 8);
		}

		String custId = customer.getCustId();
		if (TscConstants.SnsType.NAVER.value().equals(customer.getSnsType())) {
			custId = "네이버 간편가입회원";
		} else if (TscConstants.SnsType.KAKAO.value().equals(customer.getSnsType())) {
			custId = "카카오 간편가입회원";
		} else if (TscConstants.SnsType.YES24.value().equals(customer.getSnsType())) {
			custId = "YES24 간편가입회원";
		}


		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setInt("custNo", customer.getCustNo());
		replaceInfo.setString("custId", custId);
		replaceInfo.setString("custNm", customer.getCustNm());
		replaceInfo.setString("dormantDt", customer.getDormantDt());
		replaceInfo.setString("year", year);
		replaceInfo.setString("month", month);
		replaceInfo.setString("day", day);

		netpathyMailSender.send(NetpathyMailSender.MailAnswerSq.DORMANT_EXPECT.value(), customer.getEmail(), replaceInfo);

		try {
			// 고객접촉이력 정보
			CustContactHst custContactHst = new CustContactHst();
			custContactHst.setContactType(TscConstants.ContactType.DORMANT_EXPECTED.value()); // 접촉유형:임시비밀번호발급(공통코드G054)
			custContactHst.setContactMethod(TscConstants.ContactMethod.EMAIL.value()); // 접촉방법:알림톡+문자(공통코드G055)
			custContactHst.setContactContents("휴면계정전환안내");
			custContactHst.setReceiverNo(customer.getCustNo());
			custContactHst.setSenderNo(senderNo);
			custContactHst.setRegNo(senderNo);
			coreCustomerService.createCustomerContactHistory(custContactHst);
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
	}

	/**
	 * 개인정보이용내역 안내
	 *
	 * @param customer - 고객 정보
	 * @param senderNo - 보낸
	 * @author jsshin
	 * @since 2021. 06. 07
	 */
	@Transactional("shopTxnManager")
	public void sendPrivacyPolicyNotice(Customer customer, Integer senderNo) {
		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setInt("custNo", customer.getCustNo());

		netpathyMailSender.send(NetpathyMailSender.MailAnswerSq.PRIVACY_POLICY.value(), customer.getEmail(), replaceInfo);

		try {
			// 고객접촉이력 정보
			CustContactHst custContactHst = new CustContactHst();
			custContactHst.setContactType(TscConstants.ContactType.PRIVACY_POLICY.value()); // 접촉유형:임시비밀번호발급(공통코드G054)
			custContactHst.setContactMethod(TscConstants.ContactMethod.EMAIL.value()); // 접촉방법:알림톡+문자(공통코드G055)
			custContactHst.setContactContents("개인정보이용내역");
			custContactHst.setReceiverNo(customer.getCustNo());
			custContactHst.setSenderNo(senderNo);
			custContactHst.setRegNo(senderNo);
			coreCustomerService.createCustomerContactHistory(custContactHst);
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
	}

	/**
	 * 마케팅정보수신동의내역안내
	 *
	 * @param customer - 고객 정보
	 * @param senderNo - 보낸
	 * @author jsshin
	 * @since 2021. 06. 07
	 */
	@Transactional("shopTxnManager")
	public void sendMarketingAgreeNotice(Customer customer, Integer senderNo) {

		String emailAgreeYn = "Y".equals(customer.getEmailAgreeYn()) ? "수신동의" : "미동의";		// 이메일수신동의여부
		String smsAgreeYn = "Y".equals(customer.getSmsAgreeYn()) ? "수신동의" : "미동의";			// SMS수신동의여부
		String mkAgreeYn = "Y".equals(customer.getMkAgreeYn()) ? "수신동의" : "미동의";				// 마케팅수신동의여부

		String emailAgreeDt = "Y".equals(customer.getEmailAgreeYn()) ? customer.getEmailAgreeDt() : "";
		String smsAgreeDt = "Y".equals(customer.getSmsAgreeYn()) ? customer.getSmsAgreeDt() : "";
		String mkAgreeDt = "Y".equals(customer.getMkAgreeYn()) ? customer.getMkAgreeDt() : "";

		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setInt("custNo", customer.getCustNo());
		replaceInfo.setString("custId", customer.getCustId());
		replaceInfo.setString("emailAgreeYn", emailAgreeYn);
		replaceInfo.setString("emailAgreeDt", emailAgreeDt);
		replaceInfo.setString("smsAgreeYn", smsAgreeYn);
		replaceInfo.setString("smsAgreeDt", smsAgreeDt);
		replaceInfo.setString("mkAgreeYn", mkAgreeYn);
		replaceInfo.setString("mkAgreeDt", mkAgreeDt);

		netpathyMailSender.send(NetpathyMailSender.MailAnswerSq.MARKETING_AGREE.value(), customer.getEmail(), replaceInfo);

		try {
			// 고객접촉이력 정보
			CustContactHst custContactHst = new CustContactHst();
			custContactHst.setContactType(TscConstants.ContactType.MARKETING_AGREE.value()); // 접촉유형:임시비밀번호발급(공통코드G054)
			custContactHst.setContactMethod(TscConstants.ContactMethod.EMAIL.value()); // 접촉방법:알림톡+문자(공통코드G055)
			custContactHst.setContactContents("마케팅수신동의내역");
			custContactHst.setReceiverNo(customer.getCustNo());
			custContactHst.setSenderNo(senderNo);
			custContactHst.setRegNo(senderNo);
			coreCustomerService.createCustomerContactHistory(custContactHst);
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
	}

	/**
	 * 생일쿠폰다운로드안내
	 *
	 * @param custCoupon - 고객, 쿠폰정보
	 * @param senderNo - 보낸
	 * @author jsshin
	 * @since 2021. 06. 07
	 */
	@Transactional("shopTxnManager")
	public void sendBirthDayCouponNotice(CustCoupon custCoupon, Integer senderNo) {

		String custId = custCoupon.getCustId();
		if (TscConstants.SnsType.NAVER.value().equals(custCoupon.getSnsType())) {
			custId = "네이버 간편가입회원";
		} else if (TscConstants.SnsType.KAKAO.value().equals(custCoupon.getSnsType())) {
			custId = "카카오 간편가입회원";
		} else if (TscConstants.SnsType.YES24.value().equals(custCoupon.getSnsType())) {
			custId = "YES24 간편가입회원";
		}

		GagaMap replaceInfo = new GagaMap();
		DecimalFormat df = new DecimalFormat("###,###");
		replaceInfo.setInt("custNo", custCoupon.getCustNo());
		replaceInfo.setString("custId", custId);
		replaceInfo.setString("custNm", custCoupon.getCustNm());

		replaceInfo.setString("dcVal", df.format(custCoupon.getDcVal()));
		replaceInfo.setString("dcWay", custCoupon.getDcWay());
		replaceInfo.setString("availStdtTime", custCoupon.getAvailStdtTime());
		replaceInfo.setString("availEddtTime", custCoupon.getAvailEddtTime());
		if (StringUtils.isNotBlank(custCoupon.getAvailStdtTime())) {
			String[] availStdt = custCoupon.getAvailStdtTime().split(" ");
			replaceInfo.setString("availStdt", availStdt[0]);
		}
		if (StringUtils.isNotBlank(custCoupon.getAvailEddtTime())) {
			String[] availEddt = custCoupon.getAvailEddtTime().split(" ");
			replaceInfo.setString("availEddt", availEddt[0]);
		}
		String tgtCondition = StringUtils.isBlank(custCoupon.getTgtCondition()) ? "제한없음" : custCoupon.getTgtCondition();

		replaceInfo.setString("tgtCondition", tgtCondition);
		replaceInfo.setString("useCondition",custCoupon.getUseCondition());
		replaceInfo.setString("emailAgreeDt",custCoupon.getEmailAgreeDt());
		netpathyMailSender.send(NetpathyMailSender.MailAnswerSq.BIRTH_COUPON_NOTICE.value(), custCoupon.getEmail(), replaceInfo);

		try {
			// 고객접촉이력 정보
			CustContactHst custContactHst = new CustContactHst();
			custContactHst.setContactType(TscConstants.ContactType.BIRTH_COUPON_NOTICE.value()); // 접촉유형:임시비밀번호발급(공통코드G054)
			custContactHst.setContactMethod(TscConstants.ContactMethod.EMAIL.value()); // 접촉방법:알림톡+문자(공통코드G055)
			custContactHst.setContactContents("생일쿠폰다운로드안내");
			custContactHst.setReceiverNo(custCoupon.getCustNo());
			custContactHst.setSenderNo(senderNo);
			custContactHst.setRegNo(senderNo);
			coreCustomerService.createCustomerContactHistory(custContactHst);
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
	}

	/**
	 * 휴면/미접속자 복귀 쿠폰
	 *
	 * @param customer - 고객 정보
	 * @param custCoupon - 쿠폰정보
	 * @param senderNo - 발송자NO
	 * @author jsshin
	 * @since 2021. 06. 07
	 */
	@Transactional("shopTxnManager")
	public void sendCombackCoupon(Customer customer, CustCoupon custCoupon,Integer senderNo){
		String custId = customer.getCustId();
		if (TscConstants.SnsType.NAVER.value().equals(customer.getSnsType())) {
			custId = "네이버 간편가입회원";
		} else if (TscConstants.SnsType.KAKAO.value().equals(customer.getSnsType())) {
			custId = "카카오 간편가입회원";
		} else if (TscConstants.SnsType.YES24.value().equals(customer.getSnsType())) {
			custId = "YES24 간편가입회원";
		}

		GagaMap replaceInfo = new GagaMap();
		DecimalFormat df = new DecimalFormat("###,###");
		replaceInfo.setInt("custNo", customer.getCustNo());
		replaceInfo.setString("custId", custId);
		replaceInfo.setString("custNm", customer.getCustNm());
		replaceInfo.setString("dcVal", df.format(custCoupon.getDcVal()));
		replaceInfo.setString("dcWay", custCoupon.getDcWay());
		replaceInfo.setString("availStdtTime", custCoupon.getAvailStdtTime());
		replaceInfo.setString("availEddtTime", custCoupon.getAvailEddtTime());
		if (StringUtils.isNotBlank(custCoupon.getAvailStdtTime())) {
			String[] availStdt = custCoupon.getAvailStdtTime().split(" ");
			replaceInfo.setString("availStdt", availStdt[0]);
		}
		if (StringUtils.isNotBlank(custCoupon.getAvailEddtTime())) {
			String[] availEddt = custCoupon.getAvailEddtTime().split(" ");
			replaceInfo.setString("availEddt", availEddt[0]);
		}
		String tgtCondition = StringUtils.isBlank(custCoupon.getTgtCondition()) ? "제한없음" : custCoupon.getTgtCondition();
		replaceInfo.setString("tgtCondition",tgtCondition);
		replaceInfo.setString("useCondition",custCoupon.getUseCondition());
		replaceInfo.setString("emailAgreeDt",custCoupon.getEmailAgreeDt());
		netpathyMailSender.send(NetpathyMailSender.MailAnswerSq.DORMANT_EXPECT_COMBACK.value(), customer.getEmail(), replaceInfo);

		try {
			// 고객접촉이력 정보
			CustContactHst custContactHst = new CustContactHst();
			custContactHst.setContactType(TscConstants.ContactType.DORMANT_EXPECT_COMBACK.value()); // 접촉유형:임시비밀번호발급(공통코드G054)
			custContactHst.setContactMethod(TscConstants.ContactMethod.EMAIL.value()); // 접촉방법:알림톡+문자(공통코드G055)
			custContactHst.setContactContents("휴면/미접속자 방어쿠폰안내");
			custContactHst.setReceiverNo(customer.getCustNo());
			custContactHst.setSenderNo(senderNo);
			custContactHst.setRegNo(senderNo);
			coreCustomerService.createCustomerContactHistory(custContactHst);
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
	}
	
	/**
	 * 포인트 만료예정 안내(30일)
	 *
	 * @param customer - 고객 정보
	 * @param point - 포인트정보
	 * @param senderNo - 보낸
	 * @author sowon
	 * @since 2021. 06. 08
	 */
	@Transactional("shopTxnManager")
	public void sendPointExpectNotify(Point point, Integer senderNo) {

		GagaMap replaceInfo = new GagaMap();
		DecimalFormat df = new DecimalFormat("###,###");
		replaceInfo.setInt("custNo", point.getCustNo());
		replaceInfo.setString("custNm", point.getCustNm());
		replaceInfo.setString("rmPntAmt", df.format(point.getRmPntAmt()));
		replaceInfo.setString("expBeDt", point.getExpBeDt());
		replaceInfo.setString("today", point.getToday());

		netpathyMailSender.send(NetpathyMailSender.MailAnswerSq.POINT_EXTNC_EXPECT.value(), point.getEmail(), replaceInfo);

		try {
			// 고객접촉이력 정보
			CustContactHst custContactHst = new CustContactHst();
			custContactHst.setContactType(TscConstants.ContactType.COUPON_EXTNC_EXPECT.value()); // 접촉유형:임시비밀번호발급(공통코드G054)
			custContactHst.setContactMethod(TscConstants.ContactMethod.EMAIL.value()); // 접촉방법:알림톡+문자(공통코드G055)
			custContactHst.setContactContents("포인트소멸예정");
			custContactHst.setReceiverNo(point.getCustNo());
			custContactHst.setSenderNo(senderNo);
			custContactHst.setRegNo(senderNo);
			coreCustomerService.createCustomerContactHistory(custContactHst);
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
	}

	/**
	 * 주문 취소 안내
	 *
	 * @param GagaMap
	 * @param Integer
	 * @author card007
	 * @since 2021. 06. 10
	 */
	@Transactional("shopTxnManager")
	public void sendOrderCancel(GagaMap replaceInfo, Integer senderNo) {

		// 주문 취소 메일 발송
		netpathyMailSender.send(NetpathyMailSender.MailAnswerSq.CANCEL_REFUND.value(), replaceInfo.getString("ordEmail"), replaceInfo);

		try {
			if (replaceInfo.getInt("custNo") > 0) {
				// 고객접촉이력 정보
				CustContactHst custContactHst = new CustContactHst();
				custContactHst.setContactType(TscConstants.ContactType.CANCEL_INFO.value());				// 접촉유형:주문-취소안내(공통코드G054)
				custContactHst.setContactMethod(TscConstants.ContactMethod.EMAIL.value());					// 접촉방법:알림톡+문자(공통코드G055)
				custContactHst.setContactContents("주문-취소안내");
				custContactHst.setReceiverNo(replaceInfo.getInt("custNo"));
				custContactHst.setSenderNo(senderNo);
				custContactHst.setRegNo(senderNo);
				coreCustomerService.createCustomerContactHistory(custContactHst);
			}
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
	}

	/**
	 * 주문 반품 안내
	 *
	 * @param GagaMap
	 * @param Integer
	 * @author card007
	 * @since 2021. 06. 14
	 */
	@Transactional("shopTxnManager")
	public void sendOrderReturn(GagaMap replaceInfo, Integer senderNo) {

		// 주문 취소 메일 발송
		netpathyMailSender.send(NetpathyMailSender.MailAnswerSq.RETURN_REQUEST.value(), replaceInfo.getString("ordEmail"), replaceInfo);

		try {
			if (replaceInfo.getInt("custNo") > 0) {
				// 고객접촉이력 정보
				CustContactHst custContactHst = new CustContactHst();
				custContactHst.setContactType(TscConstants.ContactType.RETURN_RECEIPT.value());				// 접촉유형:반품-반품접수완료(공통코드G054)
				custContactHst.setContactMethod(TscConstants.ContactMethod.EMAIL.value());					// 접촉방법:이메일(공통코드G055)
				custContactHst.setContactContents("반품-반품접수완료");
				custContactHst.setReceiverNo(replaceInfo.getInt("custNo"));
				custContactHst.setSenderNo(senderNo);
				custContactHst.setRegNo(senderNo);
				coreCustomerService.createCustomerContactHistory(custContactHst);
			}
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
	}

	/**
	 * 주문 교환 안내
	 *
	 * @param GagaMap
	 * @param Integer
	 * @author card007
	 * @since 2021. 06. 14
	 */
	@Transactional("shopTxnManager")
	public void sendOrderExchange(GagaMap replaceInfo, Integer senderNo) {

		// 주문 취소 메일 발송
		netpathyMailSender.send(NetpathyMailSender.MailAnswerSq.EXCHANGE_REQUEST.value(), replaceInfo.getString("ordEmail"), replaceInfo);

		try {
			if (replaceInfo.getInt("custNo") > 0) {
				// 고객접촉이력 정보
				CustContactHst custContactHst = new CustContactHst();
				custContactHst.setContactType(TscConstants.ContactType.EXCHANGE_RECEIPT.value());			// 접촉유형:교환-교환접수완료(공통코드G054)
				custContactHst.setContactMethod(TscConstants.ContactMethod.EMAIL.value());					// 접촉방법:이메일(공통코드G055)
				custContactHst.setContactContents("교환-교환접수완료");
				custContactHst.setReceiverNo(replaceInfo.getInt("custNo"));
				custContactHst.setSenderNo(senderNo);
				custContactHst.setRegNo(senderNo);
				coreCustomerService.createCustomerContactHistory(custContactHst);
			}
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
	}
	
	/**
	 * 주문 결제 완료 안내
	 *
	 * @param GagaMap
	 * @param Integer
	 * @author jsh77b
	 * @since 2021. 06. 22
	 */
	@Transactional("shopTxnManager")
	public void sendOrderComplete(GagaMap replaceInfo, Integer senderNo) {
		
		Order orderInfo = (Order)replaceInfo.get("orderInfo");

		// 주문 결제 완료 메일 발송
		netpathyMailSender.send(NetpathyMailSender.MailAnswerSq.ORDER_COMPLETE.value(), orderInfo.getOrdEmail(), replaceInfo);

		try {
			if (replaceInfo.getInt("custNo") > 0) {
				// 고객접촉이력 정보
				CustContactHst custContactHst = new CustContactHst();
				custContactHst.setContactType(TscConstants.ContactType.CANCEL_INFO.value());				// 접촉유형:주문-취소안내(공통코드G054)
				custContactHst.setContactMethod(TscConstants.ContactMethod.EMAIL.value());					// 접촉방법:알림톡+문자(공통코드G055)
				custContactHst.setContactContents("주문-결제안내");
				custContactHst.setReceiverNo(replaceInfo.getInt("custNo"));
				custContactHst.setSenderNo(senderNo);
				custContactHst.setRegNo(senderNo);
				coreCustomerService.createCustomerContactHistory(custContactHst);
			}
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
	}
	
	/**
	 * 무통장 입금 요청
	 *
	 * @param GagaMap
	 * @param Integer
	 * @author jsh77b
	 * @since 2021. 06. 25
	 */
	@Transactional("shopTxnManager")
	public void sendVaDepositRequest(GagaMap replaceInfo, Integer senderNo) {
		
		Order orderInfo = (Order)replaceInfo.get("orderInfo");

		// 주문 결제 완료 메일 발송
		netpathyMailSender.send(NetpathyMailSender.MailAnswerSq.VA_DEPOSIT_REQUEST.value(), orderInfo.getOrdEmail(), replaceInfo);

		try {
			if (replaceInfo.getInt("custNo") > 0) {
				// 고객접촉이력 정보
				CustContactHst custContactHst = new CustContactHst();
				custContactHst.setContactType(TscConstants.ContactType.CANCEL_INFO.value());				// 접촉유형:주문-취소안내(공통코드G054)
				custContactHst.setContactMethod(TscConstants.ContactMethod.EMAIL.value());					// 접촉방법:알림톡+문자(공통코드G055)
				custContactHst.setContactContents("주문-결제안내");
				custContactHst.setReceiverNo(replaceInfo.getInt("custNo"));
				custContactHst.setSenderNo(senderNo);
				custContactHst.setRegNo(senderNo);
				coreCustomerService.createCustomerContactHistory(custContactHst);
			}
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
	}

	/**
	 * 기본메일
	 * @param customer - 고객 정보
	 * @param senderNo
	 * @author jsshin
	 * @since 2021. 06. 02
	 */
	@Transactional("shopTxnManager")
	public void sendBasicMail(Customer customer,Integer senderNo) {
		GagaMap replaceInfo = new GagaMap();

		replaceInfo.setInt("custNo", customer.getCustNo());
		replaceInfo.setString("custId", customer.getCustId());
		replaceInfo.setString("custNm", customer.getCustNm());
		replaceInfo.setString("title", customer.getTitle());
		replaceInfo.setString("content", customer.getContent().replaceAll("\\\n", "<br/>"));

		netpathyMailSender.send(NetpathyMailSender.MailAnswerSq.BASIC.value(), customer.getEmail(), replaceInfo);

		try {
			// 고객접촉이력 정보
			CustContactHst custContactHst = new CustContactHst();
			custContactHst.setContactType(TscConstants.ContactType.BASIC_EMAIL.value());
			custContactHst.setContactMethod(TscConstants.ContactMethod.EMAIL.value());
			custContactHst.setContactContents("기본EMAIL안내발송");
			custContactHst.setReceiverNo(customer.getCustNo());
			custContactHst.setSenderNo(senderNo);
			custContactHst.setRegNo(senderNo);
			coreCustomerService.createCustomerContactHistory(custContactHst);
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}

	}
}
