package com.style24.core.biz.service;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

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.dao.TscOrderChangeDao;
import com.style24.core.biz.thirdparty.NaverShortUrl;
import com.style24.core.biz.thirdparty.SsgKakaoSender;
import com.style24.core.support.env.TscConstants;
import com.style24.persistence.domain.Counsel;
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.ExtmallOrder;
import com.style24.persistence.domain.GiftCard;
import com.style24.persistence.domain.Order;
import com.style24.persistence.domain.OrderChange;
import com.style24.persistence.domain.Payment;
import com.style24.persistence.domain.Point;
import com.style24.persistence.domain.SsgDirectMessage;

import lombok.extern.slf4j.Slf4j;

/**
 * 카카오알림톡 Service. 모든 카카오알림톡 발송은 여기에서 처리한다.
 * 
 * @author gagamel
 * @since 2020. 11. 9
 */
@Service
@Slf4j
public class TscKakaotalkService {

	private static final String siteNm = "STYLE24";

	@Autowired
	private Environment env;

	@Autowired
	private SsgKakaoSender kakaoSender;

	@Autowired
	private TscCustomerService coreCustomerService;

	@Autowired
	private NaverShortUrl shortUrl;

	@Autowired
	private TscOrderChangeDao orderChangeDao;

	/**
	 * 고객 임시비밀번호 알림톡 발송
	 * @param customer - 고객 정보
	 * @author jsshin
	 * @since 2021. 01. 20
	 */
	@Transactional("shopTxnManager")
	public void sendCustomerTempPassword(Customer customer, Integer senderNo) {
		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFuserid(String.valueOf(senderNo)); // 발송자NO
		dm.setFdestine(customer.getCellPhnno());
		dm.setFkkoresendtype("LMS");

		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setString("siteNm", siteNm);
		replaceInfo.setString("custNm", customer.getCustNm());
		replaceInfo.setString("passwd", customer.getPasswd());

		kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.TEMP_PASSWD.value(), dm, replaceInfo);

		try {
			// 고객접촉이력 정보
			CustContactHst custContactHst = new CustContactHst();
			custContactHst.setContactType(TscConstants.ContactType.TEMP_PASSWD.value()); // 접촉유형:임시비밀번호발급(공통코드G054)
			custContactHst.setContactMethod(TscConstants.ContactMethod.KAKAOTALK.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 2020. 4. 9
	 */
	@Transactional("shopTxnManager")
	public void sendJoinCongrat(Customer customer, Coupon coupon, Integer senderNo) {
		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFuserid(String.valueOf(senderNo)); // 발송자NO
		dm.setFdestine(customer.getCellPhnno());
		dm.setFkkoresendtype("LMS");

		SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd");
		Date currentTime = new Date();
		String today = formatter.format(currentTime);

		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 간편가입회원";
		}

//		String dcVal = "";
		String dcWay = "";
		if (coupon != null) {
//			dcVal = String.valueOf(coupon.getDcVal());
			dcWay = String.valueOf(coupon.getDcWay());
		}

		GagaMap replaceInfo = new GagaMap();
//		DecimalFormat df = new DecimalFormat("###,###");
		replaceInfo.setString("siteNm", siteNm);
		replaceInfo.setString("custNm", customer.getCustNm());
		replaceInfo.setString("custId", custId);
		replaceInfo.setString("dcVal", String.format("%,d", coupon.getDcVal()));
		replaceInfo.setString("dcWay", dcWay);
		replaceInfo.setString("joinDt", today);

		replaceInfo.set("custNo", customer.getCustNo());
		kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.JOIN_CONGRATS.value(), dm, replaceInfo);

		try {
			// 고객접촉이력 정보
			CustContactHst custContactHst = new CustContactHst();
			custContactHst.setContactType(TscConstants.ContactType.JOIN_CONGRATS.value()); // 접촉유형:임시비밀번호발급(공통코드G054)
			custContactHst.setContactMethod(TscConstants.ContactMethod.KAKAOTALK.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 - 발송자번호(userNo, custNo)
	 * @author jsshin
	 * @since 2021. 05. 31
	 */
	@Transactional("shopTxnManager")
	public void sendBirthDayCouponNotice(CustCoupon custCoupon, Integer senderNo) {
		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFuserid(String.valueOf(senderNo)); // 발송자NO
		dm.setFdestine(custCoupon.getCellPhnno());
		dm.setFkkoresendtype("LMS");
		dm.setBizTime("Y"); // 예약 발송여부

		GagaMap replaceInfo = new GagaMap();
		DecimalFormat df = new DecimalFormat("###,###");
		replaceInfo.setString("siteNm", siteNm);
		replaceInfo.setString("custNm", custCoupon.getCustNm());
		replaceInfo.setString("dcVal", df.format(custCoupon.getDcVal()));
		replaceInfo.setString("dcWay", custCoupon.getDcWay());

		replaceInfo.set("custNo", custCoupon.getCustNo());
		kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.BIRTH_COUPON_NOTICE.value(), dm, replaceInfo);

		try {
			// 고객접촉이력 정보
			CustContactHst custContactHst = new CustContactHst();
			custContactHst.setContactType(TscConstants.ContactType.BIRTH_COUPON_NOTICE.value()); // 접촉유형:임시비밀번호발급(공통코드G054)
			custContactHst.setContactMethod(TscConstants.ContactMethod.KAKAOTALK.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
		}
	}

	/**
	 * 기본 LMS 발송
	 *
	 * @param customer - LMS 정보
	 * @author jsshin
	 * @since 2021. 01. 21
	 */
	@Transactional("shopTxnManager")
	public void sendCustomerBasicLms(Customer customer, Integer senderNo) {
		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFuserid(String.valueOf(senderNo)); // 발송자NO
		dm.setFdestine(customer.getCellPhnno());

		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setString("siteNm", siteNm);
		replaceInfo.setString("custNm", customer.getCustNm());
		replaceInfo.setString("content", customer.getContent());
		replaceInfo.setString("callcenterTelNo", TscConstants.CALLCENTER_TEL_NO);
		kakaoSender.sendLms(SsgKakaoSender.KakaoAnswerSq.BASIC_LMS.value(), dm, replaceInfo);

		try {
			// 고객접촉이력 정보
			CustContactHst custContactHst = new CustContactHst();
			custContactHst.setContactType(TscConstants.ContactType.BASIC_LMS.value()); // 접촉유형:회원-기본LMS안내발송
			custContactHst.setContactMethod(TscConstants.ContactMethod.LMS.value()); // 접촉방법:LMS(공통코드G055)
			custContactHst.setContactContents("기본LMS안내발송");
			custContactHst.setReceiverNo(customer.getCustNo());
			custContactHst.setSenderNo(senderNo);
			custContactHst.setRegNo(senderNo);
			custContactHst.setUpdNo(senderNo);
			coreCustomerService.createCustomerContactHistory(custContactHst);
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
	}

	/**
	 * 인증번호발송
	 *
	 * @param customer - 인증번호 발송
	 * @author jsshin
	 * @since 2021. 01. 25
	 */
	@Transactional("shopTxnManager")
	public void sendCustomerCertNo(Customer customer, Integer senderNo) {
		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFuserid(String.valueOf(senderNo)); // 발송자NO
		dm.setFdestine(customer.getCellPhnno());
		dm.setFkkoresendtype("LMS");

		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setString("siteNm", siteNm);
		replaceInfo.setString("custNm", customer.getCustNm());
		replaceInfo.setString("certNo", customer.getCertNo());

		kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.CERT_NO_SEND.value(), dm, replaceInfo);

		try {
			// 고객접촉이력 정보
			CustContactHst custContactHst = new CustContactHst();
			custContactHst.setContactType(TscConstants.ContactType.CERT_NO_SEND.value()); // 접촉유형:회원-휴대전화인증(공통코드G054)
			custContactHst.setContactMethod(TscConstants.ContactMethod.KAKAOTALK.value()); // 접촉방법:알림톡+문자(공통코드G055)
			custContactHst.setContactContents("인증번호");
			custContactHst.setReceiverNo(customer.getCustNo());
			custContactHst.setSenderNo(senderNo);
			custContactHst.setRegNo(senderNo);
			custContactHst.setUpdNo(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) {
		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFuserid(String.valueOf(senderNo)); // 발송자NO
		dm.setFdestine(customer.getCellPhnno());
		dm.setFkkoresendtype("LMS");
		dm.setBizTime("Y"); // 예약 발송여부

		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());

		kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.DORMANT_EXPECT.value(), dm, replaceInfo);

		try {
			// 고객접촉이력 정보
			CustContactHst custContactHst = new CustContactHst();
			custContactHst.setContactType(TscConstants.ContactType.DORMANT_EXPECTED.value()); // 접촉유형:회원-휴대전화인증(공통코드G054)
			custContactHst.setContactMethod(TscConstants.ContactMethod.KAKAOTALK.value()); // 접촉방법:알림톡+문자(공통코드G055)
			custContactHst.setContactContents("휴면계정전환안내");
			custContactHst.setReceiverNo(customer.getCustNo());
			custContactHst.setSenderNo(senderNo);
			custContactHst.setRegNo(senderNo);
			custContactHst.setUpdNo(senderNo);
			coreCustomerService.createCustomerContactHistory(custContactHst);
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}

	}

	/**
	 * 이달의 등급 안내 알림톡
	 *
	 * @param customer - 고객 정보
	 * @param senderNo - 발송자번호(userNo, custNo)
	 * @author jsshin
	 * @since 2021. 05. 31
	 */
	@Transactional("shopTxnManager")
	public void sendGradeNotice(Customer customer, Integer senderNo) {
		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFuserid(String.valueOf(senderNo)); // 발송자NO
		dm.setFdestine(customer.getCellPhnno());
		dm.setFkkoresendtype("LMS");
		dm.setBizTime("Y"); // 예약 발송여부

		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setString("siteNm", siteNm);
		replaceInfo.setString("custNm", customer.getCustNm());
		replaceInfo.setString("mm", customer.getMm());
		replaceInfo.setString("custGradeNm", customer.getCustGradeNm());

		replaceInfo.set("custNo", customer.getCustNo());
		kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.GRADE_NOTICE.value(), dm, replaceInfo);

		try {
			// 고객접촉이력 정보
			CustContactHst custContactHst = new CustContactHst();
			custContactHst.setContactType(TscConstants.ContactType.GRADE_NOTICE.value()); // 접촉유형:임시비밀번호발급(공통코드G054)
			custContactHst.setContactMethod(TscConstants.ContactMethod.KAKAOTALK.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 - 고객정보
	 * @author jsshin
	 * @since 2021. 05. 31
	 */
	@Transactional("shopTxnManager")
	public void sendPrivacyPolicyNotice(Customer customer, Integer senderNo) {
		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFuserid(String.valueOf(senderNo)); // 발송자NO
		dm.setFdestine(customer.getCellPhnno());
		dm.setFkkoresendtype("LMS");
		dm.setBizTime("Y"); // 예약 발송여부

		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setString("siteNm", siteNm);

		kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.PRIVACY_POLICY.value(), dm, replaceInfo);

		try {
			// 고객접촉이력 정보
			CustContactHst custContactHst = new CustContactHst();
			custContactHst.setContactType(TscConstants.ContactType.PRIVACY_POLICY.value()); // 접촉유형:회원-휴대전화인증(공통코드G054)
			custContactHst.setContactMethod(TscConstants.ContactMethod.KAKAOTALK.value()); // 접촉방법:알림톡+문자(공통코드G055)
			custContactHst.setContactContents("개인정보이용내역");
			custContactHst.setReceiverNo(customer.getCustNo());
			custContactHst.setSenderNo(senderNo);
			custContactHst.setRegNo(senderNo);
			custContactHst.setUpdNo(senderNo);
			coreCustomerService.createCustomerContactHistory(custContactHst);
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
	}

	/**
	 * 마케팅 수신동의내역 안내
	 *
	 * @param customer - 고객정보
	 * @author jsshin
	 * @since 2021. 05. 31
	 */
	@Transactional("shopTxnManager")
	public void sendMarketingAgreeNotice(Customer customer, Integer senderNo) {
		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFuserid(String.valueOf(senderNo)); // 발송자NO
		dm.setFdestine(customer.getCellPhnno());
		dm.setFkkoresendtype("LMS");
		dm.setBizTime("Y"); // 예약 발송여부

		String emailAgreeYn = "Y".equals(customer.getEmailAgreeYn()) ? "수신동의" : "미동의";
		String smsAgreeYn = "Y".equals(customer.getSmsAgreeYn()) ? "수신동의" : "미동의";
		String mkAgreeYn = "Y".equals(customer.getMkAgreeYn()) ? "수신동의" : "미동의";

		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setString("siteNm", siteNm);
		replaceInfo.setString("emailAgreeDt", customer.getEmailAgreeDt());
		replaceInfo.setString("emailAgreeYn", emailAgreeYn);
		replaceInfo.setString("smsAgreeDt", customer.getSmsAgreeDt());
		replaceInfo.setString("smsAgreeYn", smsAgreeYn);
		replaceInfo.setString("mkAgreeDt", customer.getMkAgreeDt());
		replaceInfo.setString("mkAgreeYn", mkAgreeYn);
		kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.MARKETING_AGREE.value(), dm, replaceInfo);

		try {
			// 고객접촉이력 정보
			CustContactHst custContactHst = new CustContactHst();
			custContactHst.setContactType(TscConstants.ContactType.MARKETING_AGREE.value()); // 접촉유형:회원-휴대전화인증(공통코드G054)
			custContactHst.setContactMethod(TscConstants.ContactMethod.KAKAOTALK.value()); // 접촉방법:알림톡+문자(공통코드G055)
			custContactHst.setContactContents("마케팅수신동의내역");
			custContactHst.setReceiverNo(customer.getCustNo());
			custContactHst.setSenderNo(senderNo);
			custContactHst.setRegNo(senderNo);
			custContactHst.setUpdNo(senderNo);
			coreCustomerService.createCustomerContactHistory(custContactHst);
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
	}

	/**
	 * 상품권 기간만료 알림톡(30일)
	 * @param giftcard - 상품권 정보
	 * @param senderNo - 발송자번호(고객번호)
	 * @author sowon
	 * @since 2021. 5. 27
	 */
	@Transactional("shopTxnManager")
	public void sendGiftcardExpectNotify(GiftCard giftcard, Integer senderNo) {
		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFuserid(String.valueOf(senderNo)); // 발송자NO
		dm.setFdestine(giftcard.getCellPhnno());
		dm.setFkkoresendtype("LMS");
		dm.setBizTime("Y"); // 예약 발송여부

		GagaMap replaceInfo = new GagaMap();
		DecimalFormat df = new DecimalFormat("###,###");
		replaceInfo.setString("siteNm", siteNm);
		replaceInfo.setString("custNm", giftcard.getCustNm());
		replaceInfo.setString("rmGfcdAmt", df.format(giftcard.getRmGfcdAmt()));
		replaceInfo.setString("useExpDate", giftcard.getUseExpDate());
//		kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.GIFTCARD_EXTNC_EXPECT.value(), dm, replaceInfo);

		kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.GIFTCARD_EXTNC_EXPECT.value(), dm, replaceInfo);

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

	}

	/**
	 *  포인트 기간만료 알림톡(30일)
	 * @param point - 상품권 정보
	 * @param senderNo - 발송자번호(고객번호)
	 * @author sowon
	 * @since 2021. 5. 28
	 */
	@Transactional("shopTxnManager")
	public void sendPointExpectNotify(Point point, Integer senderNo) {
		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFuserid(String.valueOf(senderNo)); // 발송자NO
		dm.setFdestine(point.getCellPhnno());
		dm.setFkkoresendtype("LMS");
		dm.setBizTime("Y"); // 예약 발송여부

		GagaMap replaceInfo = new GagaMap();
		DecimalFormat df = new DecimalFormat("###,###");
		replaceInfo.setString("siteNm", siteNm);
		replaceInfo.setString("custNm", point.getCustNm());
		replaceInfo.setString("rmPntAmt", df.format(point.getRmPntAmt()));
		replaceInfo.setString("expBeDt", point.getExpBeDt());
//		kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.POINT_EXTNC_EXPECT.value(), dm, replaceInfo);

		kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.POINT_EXTNC_EXPECT.value(), dm, replaceInfo);

		try {
			// 고객접촉이력 정보
			CustContactHst custContactHst = new CustContactHst();
			custContactHst.setContactType(TscConstants.ContactType.POINT_EXTNC_EXPECT.value()); // 접촉유형:임시비밀번호발급(공통코드G054)
			custContactHst.setContactMethod(TscConstants.ContactMethod.KAKAOTALK.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
		}
	}

	/**
	 *  쿠폰 기간만료 알림톡(7일)
	 * @param coupon - 쿠폰 정보
	 * @param senderNo - 발송자번호(고객번호)
	 * @author sowon
	 * @since 2021. 5. 31
	 */
	@Transactional("shopTxnManager")
	public void sendCouponExpectNotify(Coupon coupon, Integer senderNo) {
		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFuserid(String.valueOf(senderNo)); // 발송자NO
		dm.setFdestine(coupon.getCellPhnno());
		dm.setFkkoresendtype("LMS");
		dm.setBizTime("Y"); // 예약 발송여부

		GagaMap replaceInfo = new GagaMap();
		DecimalFormat df = new DecimalFormat("###,###");
		replaceInfo.setString("siteNm", siteNm);
		replaceInfo.setString("custNm", coupon.getCustNm());
		replaceInfo.setString("cpnNm", coupon.getCpnNm());
		replaceInfo.setString("dcVal", df.format(coupon.getDcVal()));
		replaceInfo.setString("dcWay", coupon.getDcWay());
//		kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.COUPON_EXTNC_EXPECT.value(), dm, replaceInfo);

		kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.COUPON_EXTNC_EXPECT.value(), dm, replaceInfo);

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

	/**
	 * 결제완료 알림톡
	 * @param order - 주문 정보
	 * @param senderNo - 발송자번호(고객)
	 * @author jsh77b
	 * @since 2021. 6. 2
	 */
	@Transactional("shopTxnManager")
	public void sendOrderComplete(Order order, Integer senderNo) throws Exception {
		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFuserid(String.valueOf(senderNo)); // 발송자NO
		dm.setFdestine(order.getOrdPhnno());
		dm.setFkkoresendtype("LMS");

		dm.setButtonNm("마이페이지 > 주문상세");
		//dm.setButtonUrl("https://www.style24.com/mypage/order/detail/" + order.getOrdNo());

		DecimalFormat dc = new DecimalFormat("###,###,###,###");
		String payAmt = dc.format(order.getPayAmt());

		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setString("siteNm", siteNm);
		replaceInfo.setString("ordNm", order.getOrdNm());
		replaceInfo.set("ordNo", order.getOrdNo());

		// 2021.07.08 상품명 수정
		if (Integer.parseInt(order.getGoodsCnt()) > 0) {
			replaceInfo.setString("goodsNm", order.getGoodsNm() + " 외 " + order.getGoodsCnt() + "건");
		} else {
			replaceInfo.setString("goodsNm", order.getGoodsNm());
		}

		replaceInfo.setString("goodsCnt", order.getGoodsCnt());
		replaceInfo.setString("payAmt", payAmt);

		// 2021.07.09 선물하기시 배송지 정보 없음
		if (order.getRecipBaseAddr() == null || "".equals(order.getRecipBaseAddr())) {
			replaceInfo.setString("recipBaseAddr", "주소 입력 대기중");
		} else {
			replaceInfo.setString("recipBaseAddr", order.getRecipBaseAddr());
		}
		replaceInfo.setString("recipNm", order.getRecipNm());

		SimpleDateFormat sd = new SimpleDateFormat("yyyy년 MM월 dd일");
		String todayDate = sd.format(System.currentTimeMillis());

		int kakaoAnswerSq = 0;

		// KCP
		if ("KCP".equals(order.getPgGb())) {
			// 무통장입금
			if (TscConstants.PayMeans.BANK_DEPOSIT.value().equals(order.getPayMeans())) {
				Date deadline = new SimpleDateFormat("yyyy-MM-dd").parse(order.getVaDeadline().substring(0, 10));
				replaceInfo.setString("ordDt", todayDate);
				replaceInfo.setString("vaBankNm", order.getCardNm());
				replaceInfo.setString("vaNo", order.getVaNo());
				replaceInfo.setString("vaDeadline", new SimpleDateFormat("yyyy년 MM월 dd일").format(deadline));
				replaceInfo.setString("deadlineH", "17");

				kakaoAnswerSq = SsgKakaoSender.KakaoAnswerSq.VA_ORDER_COMPLETE.value();
			}
			// 실시간계좌이체
			else if (TscConstants.PayMeans.ACCOUNT_TRANSFER.value().equals(order.getPayMeans())) {
				replaceInfo.setString("ordDt", todayDate);
				replaceInfo.setString("vaBankNm", order.getCardNm());

				kakaoAnswerSq = SsgKakaoSender.KakaoAnswerSq.AT_ORDER_COMPLETE.value();
			}
			// 신용카드, 휴대폰결제
			else {
				kakaoAnswerSq = SsgKakaoSender.KakaoAnswerSq.ORDER_COMPLETE.value();
			}
		} else {
			kakaoAnswerSq = SsgKakaoSender.KakaoAnswerSq.ORDER_COMPLETE.value();
		}

		kakaoSender.send(kakaoAnswerSq, dm, replaceInfo);

		try {
			// 고객접촉이력 정보
			CustContactHst custContactHst = new CustContactHst();
			custContactHst.setContactType(TscConstants.ContactType.ORDER_INFO.value());
			custContactHst.setContactMethod(TscConstants.ContactMethod.KAKAOTALK.value());
			custContactHst.setContactContents("주문안내");
			custContactHst.setReceiverNo(order.getCustNo());
			custContactHst.setSenderNo(senderNo);
			custContactHst.setRegNo(senderNo);
			custContactHst.setContactMemo(String.valueOf(order.getOrdNo()));
			coreCustomerService.createCustomerContactHistory(custContactHst);
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
	}

	/**
	 * 무통장입금 확인 알림톡
	 * @param order - 주문정보
	 * @return void
	 * @throws Exception - exception
	 * @author jsh77b
	 * @since 2021. 06. 03
	 */
	@Transactional("shopTxnManager")
	public void sendDepositComplete(Order order, Integer senderNo) throws Exception {
		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFuserid(String.valueOf(senderNo)); // 발송자NO
		dm.setFdestine(order.getOrdPhnno());
		dm.setFkkoresendtype("LMS");

		DecimalFormat dc = new DecimalFormat("###,###,###,###");
		String payAmt = dc.format(order.getPayAmt());

		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setString("siteNm", siteNm);
		replaceInfo.setString("custNm", order.getOrdNm());
		replaceInfo.setString("ordDt", order.getOrdDt());
		replaceInfo.setString("payAmt", payAmt);
		replaceInfo.setString("goodsNm", order.getGoodsNm());
		replaceInfo.setString("vaNm", order.getVaNm());
		replaceInfo.setString("vaNo", order.getVaNo());

		replaceInfo.set("ordNo", order.getOrdNo());
		replaceInfo.setString("recipNm", order.getRecipNm());
		replaceInfo.setString("vaBankNm", order.getCardNm());
		replaceInfo.setString("recipBaseAddr", order.getRecipBaseAddr());

		kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.VA_DEPOSIT_CONFIRM.value(), dm, replaceInfo);

		try {
			CustContactHst custContactHst = new CustContactHst();
			// 고객접촉이력 정보
			custContactHst.setContactType(TscConstants.ContactType.BANK_DEPOSIT_INFO.value());
			custContactHst.setContactMethod(TscConstants.ContactMethod.KAKAOTALK.value());
			custContactHst.setContactContents("주문-무통장입금안내");
			custContactHst.setReceiverNo(order.getCustNo());
			custContactHst.setSenderNo(senderNo);
			custContactHst.setCustNo(order.getCustNo());
			custContactHst.setContactMemo(String.valueOf(order.getOrdNo()));
			coreCustomerService.createCustomerContactHistory(custContactHst);
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
	}

	/**
	 * 무통장입금 입금 대기 알림톡
	 * @param order - 주문정보
	 * @return void
	 * @throws Exception - exception
	 * @author xodud1202
	 * @since 2021. 07. 07
	 */
	@Transactional("shopTxnManager")
	public void sendOrderDepositWaitingNotify(Order order, Integer senderNo) {
		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFuserid(String.valueOf(senderNo)); // 발송자NO
		dm.setFdestine(order.getOrdPhnno());
		dm.setFkkoresendtype("LMS");

		DecimalFormat dc = new DecimalFormat("###,###,###,###");
		String payAmt = dc.format(order.getPayAmt());

		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setString("siteNm", siteNm);
		replaceInfo.setString("ordNo", String.valueOf(order.getOrdNo()));
		replaceInfo.setString("ordNm", order.getOrdNm());
		replaceInfo.setString("payAmt", payAmt);
		replaceInfo.setString("vaBankNm", order.getBankNm());
		replaceInfo.setString("vaNo", order.getVaNo());
		replaceInfo.setString("vaDeadline", order.getVaDeadline());

		if (Integer.parseInt(order.getGoodsCnt()) < 1) {
			replaceInfo.setString("goodsNm", order.getGoodsNm());
		} else {
			replaceInfo.setString("goodsNm", order.getGoodsNm() + " 외 " + order.getGoodsNm() + "건");
		}

		kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.VA_DEPOSIT_REQUEST.value(), dm, replaceInfo);

		try {
			CustContactHst custContactHst = new CustContactHst();
			// 고객접촉이력 정보
			custContactHst.setContactType(TscConstants.ContactType.BANK_DEPOSIT_INFO.value());
			custContactHst.setContactMethod(TscConstants.ContactMethod.KAKAOTALK.value());
			custContactHst.setContactContents("주문-무통장 입금 요청");
			custContactHst.setReceiverNo(order.getCustNo());
			custContactHst.setSenderNo(senderNo);
			custContactHst.setCustNo(order.getCustNo());
			custContactHst.setContactMemo(String.valueOf(order.getOrdNo()));
			coreCustomerService.createCustomerContactHistory(custContactHst);
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
	}

	/**
	 * 선물하기 취소 (배송지 입력기간 경과)
	 * @param order - 주문정보
	 * @return void
	 * @throws Exception - exception
	 * @author xodud1202
	 * @since 2021. 07. 07
	 */
	@Transactional("shopTxnManager")
	public void sendDontWriteGiftAddress(OrderChange order, Integer senderNo) throws Exception {
		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFuserid(String.valueOf(senderNo));
		dm.setFdestine(order.getOrdPhnno());
		dm.setFkkoresendtype("LMS");
		dm.setButtonNm("주문 취소 확인");

		if (order.getGoodsCnt() > 0) {
			order.setGoodsNm(order.getGoodsNm() + " 외 " + order.getGoodsCnt() + "건");
		}

		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setString("siteNm", siteNm);
		replaceInfo.setString("custNm", order.getOrdNm());
		replaceInfo.setString("goodsNm", order.getGoodsNm());
		replaceInfo.setString("giftPackCloaseDt", order.getGiftPackCloseDt());

		kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.GIFT_EXPIRATION_CANCEL.value(), dm, replaceInfo);

		try {
			CustContactHst custContactHst = new CustContactHst();
			// 고객접촉이력 정보
			custContactHst.setContactType(TscConstants.ContactType.CANCEL_INFO.value());
			custContactHst.setContactMethod(TscConstants.ContactMethod.KAKAOTALK.value());
			custContactHst.setContactContents("선물하기 - 주문취소");
			custContactHst.setReceiverNo(order.getCustNo());
			custContactHst.setSenderNo(senderNo);
			custContactHst.setCustNo(order.getCustNo());
			custContactHst.setRegNo(senderNo);
			coreCustomerService.createCustomerContactHistory(custContactHst);
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
	}

	/**
	 * 배송출발
	 * @param order - 주문정보
	 * @return void
	 * @throws Exception - exception
	 * @author xodud1202
	 * @since 2021. 06. 07
	 */
	@Transactional("shopTxnManager")
	public void sendDeliveryStart(Order order, Integer senderNo) throws Exception {
		Payment payment = new Payment();
		payment.setOrdNo(order.getOrdNo());
		payment = orderChangeDao.getPaymentInfo(payment);
		// 네이버페이 주문형 데이터는 알림톡 송부X
		if (TscConstants.PgGb.NAVER_ORDER.value().equals(payment.getPgGb())) {
			return;
		}

		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFuserid(String.valueOf(senderNo)); // 발송자NO
		dm.setFdestine(order.getOrdPhnno());
		dm.setFkkoresendtype("LMS");

		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setString("siteNm", siteNm);
		replaceInfo.setString("ordNm", order.getOrdNm());
		replaceInfo.setString("ordNo", String.valueOf(order.getOrdNo()));
		if (Integer.parseInt(order.getGoodsCnt()) > 0) {
			order.setGoodsNm(order.getGoodsNm() + " 외 " + order.getGoodsCnt() + "건");
		}
		replaceInfo.setString("goodsNm", order.getGoodsNm());

		dm.setBizTime("Y");
		kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.GOODS_SEND.value(), dm, replaceInfo);

		try {
			CustContactHst custContactHst = new CustContactHst();
			// 고객접촉이력 정보
			custContactHst.setContactType(TscConstants.ContactType.SHIPPING_INFO.value());
			custContactHst.setContactMethod(TscConstants.ContactMethod.KAKAOTALK.value());
			custContactHst.setContactContents("배송시작");
			custContactHst.setReceiverNo(order.getCustNo());
			custContactHst.setSenderNo(senderNo);
			custContactHst.setCustNo(order.getCustNo());
			custContactHst.setRegNo(senderNo);
			coreCustomerService.createCustomerContactHistory(custContactHst);
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
	}

	/**
	 * 선물받기 배송지입력
	 * @param order - 주문 정보
	 * @param senderNo - 발송자번호(고객)
	 * @author jsh77b
	 * @since 2021. 6. 2
	 */
	@Transactional("shopTxnManager")
	public void sendOrderGiftComplete(Order order, Integer senderNo) throws Exception {
		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFuserid(String.valueOf(senderNo)); // 발송자NO
		dm.setFdestine(order.getRecipPhnno());
		dm.setFkkoresendtype("LMS");

		dm.setButtonNm("선물받기 > 배송지입력");
		dm.setButtonUrl("https://www.style24.com/order/giftComplete?ordNo=" + order.getOrdNo());

		DecimalFormat dc = new DecimalFormat("###,###,###,###");
		String payAmt = dc.format(order.getPayAmt());

		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setString("siteNm", siteNm);
		replaceInfo.setString("recipNm", order.getRecipNm());
		replaceInfo.setString("ordNm", order.getOrdNm());
		replaceInfo.set("ordNo", order.getOrdNo());
		replaceInfo.setString("goodsNm", order.getGoodsNm());
		replaceInfo.setString("goodsCnt", order.getGoodsCnt());

		Date giftPackCloseDt = new SimpleDateFormat("yyyy-MM-dd").parse(order.getGiftPackCloseDt().substring(0, 10));
		replaceInfo.setString("giftPackCloaseDt", new SimpleDateFormat("yyyy년 MM월 dd일").format(giftPackCloseDt));

		kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.GIFT_ARRIVED.value(), dm, replaceInfo);

		try {
			// 고객접촉이력 정보
			CustContactHst custContactHst = new CustContactHst();
			custContactHst.setContactType(TscConstants.ContactType.GIFT.value()); 				// 접촉유형:임시비밀번호발급(공통코드G054)
			custContactHst.setContactMethod(TscConstants.ContactMethod.KAKAOTALK.value()); 		// 접촉방법:알림톡+문자(공통코드G055)
			custContactHst.setContactContents("선물하기");
			custContactHst.setContactMemo(String.valueOf(order.getOrdNo()));
			custContactHst.setReceiverNo(order.getCustNo());
			custContactHst.setSenderNo(senderNo);
			custContactHst.setRegNo(senderNo);
			coreCustomerService.createCustomerContactHistory(custContactHst);
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
	}

//
//	/**
//	 * 주문취소안내 알림톡
//	 * @param customer - 고객 정보
//	 * @return void
//	 * @throws Exception - exception
//	 * @author yh98kim
//	 * @since 2020. 4. 9
//	 */
//	@Transactional("shopTxnManager")
//	public void sendOrderCancel(WfoCustomer customer, WfoOrder order) throws Exception {
//		SsgDirectMessage dm = new SsgDirectMessage();
//		dm.setFdestine(customer.getCellPhnno());
//		dm.setFkkoresendtype("LMS");
//
//		dm.setButtonNm("마이페이지 > 주문내역");
//		dm.setButtonUrl("/mypage/order/list/form");
//
//		GagaMap replaceInfo = new GagaMap();
//		replaceInfo.setString("siteNm", commonService.getSiteName(WfoConstants.SITE_CD));
//		replaceInfo.setString("custNm", order.getOrderNm());
//
//		if (order.getPayMeans().equals(WfoConstants.PayMeans.CARD.value())) {
//			/* 신용카드 */
//			kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.CARD_CANCEL_REFUND.value(), dm, replaceInfo);
//		} else if (order.getPayMeans().equals(WfoConstants.PayMeans.REALTIME_TRANSFER.value())) {
//			/* 실시간계좌이체 */
//			kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.AT_CANCEL_REFUND.value(), dm, replaceInfo);
//		} else if (order.getPayMeans().equals(WfoConstants.PayMeans.ACCOUNT_DEPOSIT.value())) {
//			/* 무통장입금 */
//			kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.VA_CANCEL_REFUND.value(), dm, replaceInfo);
//		}
//
//		try {
//			// 고객접촉이력 정보
//			customer.setContactType("305"); // 접촉유형:주문안내(공통코드G054)
//			customer.setContactMethod(WfoConstants.ContactMethod.KAKAOTALK.value()); // 접촉방법:알림톡+문자(공통코드G055)
//			customer.setContactContents("주문-취소안내");
//			customer.setReceiverId(customer.getCustNo());
//			customerService.createCustomerContactHistory(customer);
//		} catch (Exception e) {
//			log.error("error", e);
//			// Do nothing
//		}
//	}

	/**
	 * APP다운로드URL 발송
	 * @param cellPhnno - 휴대전화번호
	 * @author gagamel
	 * @since 2020. 6. 18
	 */
	@Transactional("shopTxnManager")
	public void sendAppDownloadUrl(String cellPhnno) {
		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFdestine(cellPhnno);
		dm.setFkkoresendtype("LMS");

		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setString("siteNm", siteNm);
		replaceInfo.setString("iosAppDownUrl", shortUrl.getShortUrl(env.getProperty("app.down.url.ios")));
		replaceInfo.setString("aosAppDownUrl", shortUrl.getShortUrl(env.getProperty("app.down.url.aos")));

		kakaoSender.sendLms(SsgKakaoSender.KakaoAnswerSq.APP_DOWNLOAD.value(), dm, replaceInfo);
	}

	/**
	 * 휴면/미접속자 방어 쿠폰
	 *
	 * @param customer - 휴대전화번호,고객이름
	 * @param custCoupon - 쿠폰정보
	 * @author jssin
	 * @since 2021. 05. 28
	 */
	@Transactional("shopTxnManager")
	public void sendCombackCoupon(Customer customer, CustCoupon custCoupon, Integer senderNo) {
		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFuserid(String.valueOf(senderNo)); // 발송자NO
		dm.setFdestine(customer.getCellPhnno());
		dm.setFkkoresendtype("LMS");
		dm.setBizTime("Y"); // 예약 발송여부

		GagaMap replaceInfo = new GagaMap();
		DecimalFormat df = new DecimalFormat("###,###");
		replaceInfo.setString("siteNm", siteNm);
		replaceInfo.setString("custNm", customer.getCustNm());
		replaceInfo.setString("custId", customer.getCustId());
		replaceInfo.setString("dcVal", df.format(custCoupon.getDcVal()));
		replaceInfo.setString("dcWay", custCoupon.getDcWay());

		replaceInfo.set("custNo", customer.getCustNo());
		kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.DORMANT_EXPECT_COMBACK.value(), dm, replaceInfo);

		try {
			// 고객접촉이력 정보
			CustContactHst custContactHst = new CustContactHst();
			custContactHst.setContactType(TscConstants.ContactType.DORMANT_EXPECT_COMBACK.value());
			custContactHst.setContactMethod(TscConstants.ContactMethod.KAKAOTALK.value());
			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 goods
	 * @param senderNo
	 * @author eskim
	 * @since 2021. 5. 28
	 */
	@Transactional("shopTxnManager")
	public int goodsRestock(GagaMap goods, Integer senderNo) {
		int result = 0;
		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFuserid(String.valueOf(senderNo)); // 발송자NO======>
		dm.setFdestine(goods.getString("cellPhnno"));
		dm.setFkkoresendtype("LMS");

		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setString("siteNm", siteNm);
		replaceInfo.setString("custNm", goods.getString("custNm"));
		replaceInfo.setString("goodsNm", goods.getString("goodsNm"));
		replaceInfo.setString("optCd1", goods.getString("optCd1"));
		replaceInfo.setString("optCd2", goods.getString("optCd2"));
		replaceInfo.setString("goodsCd", goods.getString("goodsCd"));
		replaceInfo.setString("colorCd", goods.getString("colorCd"));

		kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.GOODS_RESTOCK.value(), dm, replaceInfo);

		try {
			// 고객접촉이력 정보
			CustContactHst custContactHst = new CustContactHst();
			custContactHst.setContactType(TscConstants.ContactType.GOODS_RESTOCK.value()); // 접촉유형:알림톡(공통코드G054)
			custContactHst.setContactMethod(TscConstants.ContactMethod.KAKAOTALK.value()); // 접촉방법:알림톡+문자(공통코드G055)
			custContactHst.setContactContents("재입고안내");
			custContactHst.setReceiverNo(goods.getInt("custNo"));
			custContactHst.setSenderNo(senderNo);
			custContactHst.setRegNo(senderNo);
			coreCustomerService.createCustomerContactHistory(custContactHst);
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
		result = 1;
		return result;
	}

	//----------------------------

	/**
	 * 주문취소 알림톡
	 * 
	 * @param OrderChange
	 * @param senderNo
	 * @author card007
	 * @since 2021. 06. 07
	 */
	@Transactional("shopTxnManager")
	public void sendOrderCancelComplete(OrderChange orderChange, Integer senderNo) throws Exception {
		// Payment payment = new Payment();
		// payment.setOrdNo(orderChange.getOrdNo());
		// payment = orderChangeDao.getPaymentInfo(payment);
		// 네이버페이 주문형 데이터는 알림톡 송부X
		if (TscConstants.PgGb.NAVER_ORDER.value().equals(orderChange.getPgGb())) {
			return;
		}

		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFuserid(String.valueOf(senderNo));
		dm.setFdestine(orderChange.getOrdPhnno());
		dm.setFkkoresendtype("LMS");
		dm.setButtonNm("주문 취소 확인");

		// 취소금액 콤마 처리
		DecimalFormat dc = new DecimalFormat("###,###,###,###");
		String refundAmt = dc.format(orderChange.getRefundAmt());

		// 상품명 처리
		String goodsNm = orderChange.getGoodsNm();
		int goodsCnt = orderChange.getGoodsCnt();
		if (goodsCnt > 0) {
			goodsNm += " 외 " + goodsCnt + "건";
		}

		Integer ansSq = 0;
		String pgGb = orderChange.getPgGb();
		String payMeans = orderChange.getPayMeans();
		String payMeansNm = orderChange.getPayMeansNm();

		// 품절 취소
		if (StringUtils.isNotBlank(orderChange.getChgReason()) && TscConstants.OrderCancelReason.SOLDOUT_CANCEL.value().equals(orderChange.getChgReason())) {
			// KCP
			if (TscConstants.PgGb.KCP.value().equals(pgGb)) {
				// 신용카드
				if (TscConstants.PayMeans.CREDIT_CARD.value().equals(payMeans)) {
					ansSq = SsgKakaoSender.KakaoAnswerSq.CARD_CANCEL_BY_SOLDOUT.value();
				}
				// 휴대폰
				else if (TscConstants.PayMeans.CELL_PHONE.value().equals(payMeans)) {
					ansSq = SsgKakaoSender.KakaoAnswerSq.NA_CANCEL_BY_SOLDOUT.value();
				}
				// 실시간계좌이체
				else if (TscConstants.PayMeans.ACCOUNT_TRANSFER.value().equals(payMeans)) {
					ansSq = SsgKakaoSender.KakaoAnswerSq.AT_CANCEL_BY_SOLDOUT.value();
				}
				// 무통장입금
				else if (TscConstants.PayMeans.BANK_DEPOSIT.value().equals(payMeans)) {
					// 입금 전
					if (TscConstants.PaymentStat.PAY_BEFORE_CANCEL.value().equals(orderChange.getPayStat())) {
						ansSq = SsgKakaoSender.KakaoAnswerSq.VA_CANCEL_BEFORE_PAYMENT_BY_SOLDOUT.value();
					}
					// 환불계좌 X
					else if (StringUtils.isBlank(orderChange.getAccountNm()) || StringUtils.isBlank(orderChange.getAccountNo()) || StringUtils.isBlank(orderChange.getBankCd())) {
						ansSq = SsgKakaoSender.KakaoAnswerSq.VA_CANCEL_NO_ACCOUNT_BY_SOLDOUT.value();
					}
					// 입금 후 환불계좌 O
					else {
						ansSq = SsgKakaoSender.KakaoAnswerSq.VA_CANCEL_BY_SOLDOUT.value();
					}
				}
			}
			// PAYCO, NAVERPAY 결제형, KAKAOPAY, 상품권
			else if (TscConstants.PgGb.PAYCO.value().equals(pgGb) || TscConstants.PgGb.KAKAO.value().equals(pgGb) || TscConstants.PgGb.NAVER.value().equals(pgGb) || TscConstants.PgGb.ISTYLE.value().equals(pgGb)) {
				if (TscConstants.PgGb.PAYCO.value().equals(pgGb)) {
					payMeansNm = "PAYCO";
				} else if (TscConstants.PgGb.KAKAO.value().equals(pgGb)) {
					payMeansNm = "카카오페이";
				} else if (TscConstants.PgGb.NAVER.value().equals(pgGb)) {
					payMeansNm = "네이버페이";
				}

				ansSq = SsgKakaoSender.KakaoAnswerSq.ETC_CANCEL_BY_SOLDOUT.value();
			}
		}
		// 일반 취소
		else {
			// KCP
			if (TscConstants.PgGb.KCP.value().equals(pgGb)) {
				// 신용카드
				if (TscConstants.PayMeans.CREDIT_CARD.value().equals(payMeans)) {
					ansSq = SsgKakaoSender.KakaoAnswerSq.CARD_CANCEL_REFUND.value();
				}
				// 휴대폰
				else if (TscConstants.PayMeans.CELL_PHONE.value().equals(payMeans)) {
					ansSq = SsgKakaoSender.KakaoAnswerSq.NA_CANCEL_REFUND.value();
				}
				// 실시간계좌이체
				else if (TscConstants.PayMeans.ACCOUNT_TRANSFER.value().equals(payMeans)) {
					ansSq = SsgKakaoSender.KakaoAnswerSq.AT_CANCEL_REFUND.value();
				}
				// 무통장입금
				else if (TscConstants.PayMeans.BANK_DEPOSIT.value().equals(payMeans)) {
					// 입금 전
					if (TscConstants.PaymentStat.PAY_BEFORE_CANCEL.value().equals(orderChange.getPayStat())) {
						ansSq = SsgKakaoSender.KakaoAnswerSq.VA_CANCEL_BEFORE_PAYMENT_REFUND.value();
					}
					// 환불계좌 X
					else if (StringUtils.isBlank(orderChange.getAccountNm()) || StringUtils.isBlank(orderChange.getAccountNo()) || StringUtils.isBlank(orderChange.getBankCd())) {
						ansSq = SsgKakaoSender.KakaoAnswerSq.VA_CANCEL_NO_ACCOUNT_REFUND.value();
					}
					// 입금 후 환불계좌 O
					else {
						ansSq = SsgKakaoSender.KakaoAnswerSq.VA_CANCEL_REFUND.value();
					}
				}
			}
			// PAYCO, NAVERPAY 결제형, KAKAOPAY, 상품권
			else if (TscConstants.PgGb.PAYCO.value().equals(pgGb) || TscConstants.PgGb.KAKAO.value().equals(pgGb) || TscConstants.PgGb.NAVER.value().equals(pgGb) || TscConstants.PgGb.ISTYLE.value().equals(pgGb)) {
				if (TscConstants.PgGb.PAYCO.value().equals(pgGb)) {
					payMeansNm = "PAYCO";
				} else if (TscConstants.PgGb.KAKAO.value().equals(pgGb)) {
					payMeansNm = "카카오페이";
				} else if (TscConstants.PgGb.NAVER.value().equals(pgGb)) {
					payMeansNm = "네이버페이";
				}

				ansSq = SsgKakaoSender.KakaoAnswerSq.ETC_CANCEL_REFUND.value();
			}
		}

		// 치환데이터 설정
		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setString("siteNm", siteNm);
		replaceInfo.setString("ordNm", orderChange.getOrdNm());
		// replaceInfo.setString("회원명"				, orderChange.getOrdNm());
		replaceInfo.setInt("ordNo", orderChange.getOrdNo());
		// replaceInfo.setInt("OrderNo"				, orderChange.getOrdNo());
		replaceInfo.setString("goodsNm", goodsNm);
		// replaceInfo.setInt("goodsCnt"				, orderChange.getGoodsCnt());
		// replaceInfo.setInt("N"						, orderChange.getGoodsCnt());
		replaceInfo.setString("payMeansNm", payMeansNm);
		replaceInfo.setString("refundAmt", refundAmt);

		if (orderChange.getCustNo() > 0) {
			replaceInfo.setString("url", "/mypage/cre/list/form");
		} else {
			replaceInfo.setString("url", "/customer/noncust/order/confirm/form");
		}

		if (ansSq > 0) {
			if (senderNo < 100000) {
				dm.setBizTime("Y");
			}

			kakaoSender.send(ansSq, dm, replaceInfo);

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

	/**
	 * 반품접수 알림톡
	 *
	 * @param OrderChange
	 * @param senderNo
	 * @author card007
	 * @since 2021. 06. 07
	 */
	@Transactional("shopTxnManager")
	public void sendOrderReturnRequest(OrderChange orderChange, Integer senderNo) throws Exception {
		Integer ansSq;
		String contactType;
		String contactContents;
		int addPayCost = orderChange.getAddPayCost();
		String wdGb = orderChange.getWdGb();
		String chgerBaseAddr = orderChange.getChgerBaseAddr() + " " + orderChange.getChgerDtlAddr();
		DecimalFormat df = new DecimalFormat("###,###");

		if ("D".equals(wdGb)) {
			chgerBaseAddr = "직접배송";
		}

		if (addPayCost > 0) {
			ansSq = SsgKakaoSender.KakaoAnswerSq.RETURN_ADD_COST.value();
			contactType = TscConstants.ContactType.RETURN_ADD_PAYMENT.value();
			contactContents = "반품-추가배송비결제안내";
		} else {
			ansSq = SsgKakaoSender.KakaoAnswerSq.RETURN_REQUEST.value();
			contactType = TscConstants.ContactType.RETURN_RECEIPT.value();
			contactContents = "반품-반품접수완료";
		}

		// 상품명 처리
		String goodsNm = orderChange.getGoodsNm();
		int goodsCnt = orderChange.getGoodsCnt();
		if (goodsCnt > 0) {
			goodsNm += " 외 " + goodsCnt + "건";
		}

		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setString("siteNm", siteNm);
		replaceInfo.setString("ordNm", orderChange.getOrdNm());
		replaceInfo.setInt("ordNo", orderChange.getOrdNo());
		replaceInfo.setString("goodsNm", goodsNm);
		// replaceInfo.setInt("goodsCnt"				, orderChange.getGoodsCnt());
		replaceInfo.setString("chgerBaseAddr", chgerBaseAddr);
		replaceInfo.setString("addPayCost", addPayCost == 0 ? "0" : df.format(addPayCost) + "원");

		if (ansSq > 0) {
			SsgDirectMessage dm = new SsgDirectMessage();
			dm.setFuserid(String.valueOf(senderNo));
			dm.setFdestine(orderChange.getOrdPhnno());
			dm.setFkkoresendtype("LMS");
			dm.setButtonNm("반품 접수 확인");

			kakaoSender.send(ansSq, dm, replaceInfo);

			try {
				if (orderChange.getCustNo() > 0) {
					// 고객접촉이력 정보
					CustContactHst custContactHst = new CustContactHst();
					custContactHst.setContactType(contactType);											// 접촉유형:반품-반품접수완료, 반품-추가배송비결제안내(공통코드G054)
					custContactHst.setContactMethod(TscConstants.ContactMethod.KAKAOTALK.value());		// 접촉방법:알림톡+문자(공통코드G055)
					custContactHst.setContactContents(contactContents);
					custContactHst.setReceiverNo(orderChange.getCustNo());
					custContactHst.setSenderNo(senderNo);
					custContactHst.setRegNo(senderNo);
					coreCustomerService.createCustomerContactHistory(custContactHst);
				}
			} catch (Exception e) {
				log.error("error", e);
				// Do nothing
			}
		}
	}

	/**
	 * 교환접수 알림톡
	 *
	 * @param OrderChange
	 * @param senderNo
	 * @author card007
	 * @since 2021. 06. 07
	 */
	@Transactional("shopTxnManager")
	public void sendOrderExchangeRequest(OrderChange orderChange, Integer senderNo) throws Exception {
		Integer ansSq;
		String contactType;
		String contactContents;
		int addPayCost = orderChange.getAddPayCost();
		String wdGb = orderChange.getWdGb();
		String chgerBaseAddr = orderChange.getChgerBaseAddr() + " " + orderChange.getChgerDtlAddr();
		DecimalFormat df = new DecimalFormat("###,###");

		if ("D".equals(wdGb)) {
			chgerBaseAddr = "직접배송";
		}

		if (addPayCost > 0) {
			ansSq = SsgKakaoSender.KakaoAnswerSq.EXCHANGE_ADD_COST.value();
			contactType = TscConstants.ContactType.EXCHANGE_ADD_PAYMENT.value();
			contactContents = "교환-추가배송비결제안내";
		} else {
			ansSq = SsgKakaoSender.KakaoAnswerSq.EXCHANGE_REQUEST.value();
			contactType = TscConstants.ContactType.EXCHANGE_RECEIPT.value();
			contactContents = "교환-교환접수완료";
		}

		// 상품명 처리
		String goodsNm = orderChange.getGoodsNm();
		int goodsCnt = orderChange.getGoodsCnt();
		if (goodsCnt > 0) {
			goodsNm += " 외 " + goodsCnt + "건";
		}

		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setString("siteNm", siteNm);
		replaceInfo.setString("ordNm", orderChange.getOrdNm());
		replaceInfo.setInt("ordNo", orderChange.getOrdNo());
		replaceInfo.setString("goodsNm", goodsNm);
		// replaceInfo.setInt("goodsCnt"				, orderChange.getGoodsCnt());
		replaceInfo.setString("chgerBaseAddr", chgerBaseAddr);
		replaceInfo.setString("addPayCost", addPayCost == 0 ? "0" : df.format(addPayCost) + "원");

		if (ansSq > 0) {
			SsgDirectMessage dm = new SsgDirectMessage();
			dm.setFuserid(String.valueOf(senderNo));
			dm.setFdestine(orderChange.getOrdPhnno());
			dm.setFkkoresendtype("LMS");
			dm.setButtonNm("교환 접수 확인");

			kakaoSender.send(ansSq, dm, replaceInfo);

			try {
				if (orderChange.getCustNo() > 0) {
					// 고객접촉이력 정보
					CustContactHst custContactHst = new CustContactHst();
					custContactHst.setContactType(contactType);												// 접촉유형:교환-교환접수완료, 교환-추가배송비결제안내(공통코드G054)
					custContactHst.setContactMethod(TscConstants.ContactMethod.KAKAOTALK.value());			// 접촉방법:알림톡+문자(공통코드G055)
					custContactHst.setContactContents(contactContents);
					custContactHst.setReceiverNo(orderChange.getCustNo());
					custContactHst.setSenderNo(senderNo);
					custContactHst.setRegNo(senderNo);
					coreCustomerService.createCustomerContactHistory(custContactHst);
				}
			} catch (Exception e) {
				log.error("error", e);
				// Do nothing
			}
		}
	}

	/**
	 *  1:1문의 알림톡
	 * @param counsel
	 * @param senderNo - 발송자번호(고객번호)
	 * @author sowon
	 * @since 2021. 6. 21
	 */
	@Transactional("shopTxnManager")
	public void sendOneToOneAnswerNotify(Counsel counsel, Integer senderNo) {
		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFuserid(String.valueOf(senderNo)); // 발송자NO
		dm.setFdestine(counsel.getCellPhnno());
		dm.setFkkoresendtype("LMS");
		dm.setBizTime("Y"); // 예약 발송여부

		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setString("siteNm", siteNm);
		replaceInfo.setString("custNm", counsel.getCustNm());
		kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.ONE_TO_ONE_ANSWER.value(), dm, replaceInfo);

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

	/**
	 *  상품문의 알림톡
	 * @param counsel
	 * @param senderNo - 발송자번호(고객번호)
	 * @author sowon
	 * @since 2021. 6. 21
	 */
	@Transactional("shopTxnManager")
	public void sendGoodsAskNotify(Counsel counsel, Integer senderNo) {
		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFuserid(String.valueOf(senderNo)); // 발송자NO
		dm.setFdestine(counsel.getCellPhnno());
		dm.setFkkoresendtype("LMS");
		dm.setBizTime("Y"); // 예약 발송여부

		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setString("siteNm", siteNm);
		replaceInfo.setString("custNm", counsel.getCustNm());
		replaceInfo.setString("goodsNm", counsel.getGoodsNm());
		kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.GOODS_ASK_ANSWER.value(), dm, replaceInfo);

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

	/**
	 * 품절알림 - 샵링커, 제휴몰주문업로드
	 * @param extmallOrder - 고객 정보
	 * @author jmh
	 * @since 2021. 06. 23
	 */
	@Transactional("shopTxnManager")
	public void sendShoplinkerOrder(ExtmallOrder extmallOrder, Integer senderNo) {

		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFuserid(String.valueOf(senderNo)); // 발송자NO
		dm.setFdestine(extmallOrder.getOrderPhnno());
		dm.setFkkoresendtype("LMS");
		dm.setBizTime("Y"); // 예약 발송여부

		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setString("siteNm", siteNm);
		replaceInfo.setString("extmallNm", extmallOrder.getExtmallNm());
		replaceInfo.setString("soldoutGoodsNm", extmallOrder.getSoldoutGoodsNm());

		Integer ansSq = 0;
		if ("Y".equals(extmallOrder.getCnclAllSoldoutYn())) {
			ansSq = SsgKakaoSender.KakaoAnswerSq.EXTMALL_SOLDOUT.value(); // 전체품절
		} else {
			ansSq = SsgKakaoSender.KakaoAnswerSq.EXTMALL_PART_SOLDOUT.value(); // 부분품절
		}
		kakaoSender.send(ansSq, dm, replaceInfo);

		try {
			// 고객접촉이력 정보
			CustContactHst custContactHst = new CustContactHst();
			custContactHst.setContactType(TscConstants.ContactType.SOLDOUT_INFO.value()); // 접촉유형:주문-결품안내(공통코드G054)
			custContactHst.setContactMethod(TscConstants.ContactMethod.KAKAOTALK.value()); // 접촉방법:알림톡+문자(공통코드G055)
			custContactHst.setContactContents("샵링커 주문수집(" + extmallOrder.getUploadGb() + ") 품절안내");
			custContactHst.setReceiverNo(0);
			custContactHst.setSenderNo(senderNo);
			custContactHst.setRegNo(senderNo);
			coreCustomerService.createCustomerContactHistory(custContactHst);
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
	}

	/**
	 * 회수시작 안내 
	 * @param order - 주문정보
	 * @return void
	 * @throws Exception - exception
	 * @author moon
	 * @since 2021. 07. 15
	 */
	@Transactional("shopTxnManager")
	public void sendWithdrawStart(Order order, Integer senderNo) throws Exception {
		Payment payment = new Payment();
		payment.setOrdNo(order.getOrdNo());
		payment = orderChangeDao.getPaymentInfo(payment);
		// 네이버페이 주문형 데이터는 알림톡 송부X
		if (TscConstants.PgGb.NAVER_ORDER.value().equals(payment.getPgGb())) {
			return;
		}

		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFuserid(String.valueOf(senderNo)); // 발송자NO
		dm.setFdestine(order.getOrdPhnno());
		dm.setFkkoresendtype("LMS");

		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setString("siteNm", siteNm);
		replaceInfo.setString("ordNm", order.getOrdNm());
		replaceInfo.setString("ordNo", String.valueOf(order.getOrdNo()));
		if (Integer.parseInt(order.getGoodsCnt()) > 0) {
			order.setGoodsNm(order.getGoodsNm() + " 외 " + order.getGoodsCnt() + "건");
		}
		replaceInfo.setString("goodsNm", order.getGoodsNm());
		replaceInfo.setString("chgerBaseAddr", order.getChgerBaseAddr());

		dm.setBizTime("Y");
		kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.WHITHDRAW_START.value(), dm, replaceInfo);

		try {
			CustContactHst custContactHst = new CustContactHst();
			// 고객접촉이력 정보
			custContactHst.setContactType(TscConstants.ContactType.WITHDRAW_INFO.value());
			custContactHst.setContactMethod(TscConstants.ContactMethod.KAKAOTALK.value());
			custContactHst.setContactContents("회수시작");
			custContactHst.setReceiverNo(order.getCustNo());
			custContactHst.setSenderNo(senderNo);
			custContactHst.setCustNo(order.getCustNo());
			custContactHst.setRegNo(senderNo);
			coreCustomerService.createCustomerContactHistory(custContactHst);
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
	}

	/**
	 * 반품완료 안내 
	 * @param order - 주문정보
	 * @return void
	 * @throws Exception - exception
	 * @author moon
	 * @since 2021. 07. 15
	 */
	@Transactional("shopTxnManager")
	public void sendRefundComplete(Order order, Integer senderNo) throws Exception {

		DecimalFormat df = new DecimalFormat("###,###");

		Payment payment = new Payment();
		payment.setOrdNo(order.getOrdNo());
		payment = orderChangeDao.getPaymentInfo(payment);
		// 네이버페이 주문형 데이터는 알림톡 송부X
		// 2021.09.10 card007 외부몰주문 추가
		if (TscConstants.PgGb.NAVER_ORDER.value().equals(payment.getPgGb())
			|| TscConstants.PayMeans.EXTMALL.value().equals(payment.getPayMeans())) {
			return;
		}

		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFuserid(String.valueOf(senderNo)); // 발송자NO
		dm.setFdestine(order.getOrdPhnno());
		dm.setFkkoresendtype("LMS");

		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setString("siteNm", siteNm);
		replaceInfo.setString("ordNm", order.getOrdNm());
		replaceInfo.setString("ordNo", String.valueOf(order.getOrdNo()));
		if (Integer.parseInt(order.getGoodsCnt()) > 0) {
			order.setGoodsNm(order.getGoodsNm() + " 외 " + order.getGoodsCnt() + "건");
		}
		replaceInfo.setString("goodsNm", order.getGoodsNm());
		replaceInfo.setString("refundAmt", df.format(order.getRefundAmt()) + "원");

		dm.setBizTime("Y");
		kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.RETURN_COMPLETE.value(), dm, replaceInfo);

		try {
			CustContactHst custContactHst = new CustContactHst();
			// 고객접촉이력 정보
			custContactHst.setContactType(TscConstants.ContactType.RETURN_COMPLETED.value());
			custContactHst.setContactMethod(TscConstants.ContactMethod.KAKAOTALK.value());
			custContactHst.setContactContents("반품완료");
			custContactHst.setReceiverNo(order.getCustNo());
			custContactHst.setSenderNo(senderNo);
			custContactHst.setCustNo(order.getCustNo());
			custContactHst.setRegNo(senderNo);
			coreCustomerService.createCustomerContactHistory(custContactHst);
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
	}

	/**
	 * 품절취소 안내 
	 * @param order - 주문정보
	 * @return void
	 * @throws Exception - exception
	 * @author moon
	 * @since 2021. 07. 16
	 */
	@Transactional("shopTxnManager")
	public void sendSoldoutCancel(Order order, Integer senderNo) throws Exception {

		Payment payment = new Payment();
		payment.setOrdNo(order.getOrdNo());
		payment = orderChangeDao.getPaymentInfo(payment);
		// 네이버페이 주문형 데이터는 알림톡 송부X
		if (TscConstants.PgGb.NAVER_ORDER.value().equals(payment.getPgGb())) {
			return;
		}
		// 제휴몰일경우  제휴몰에서 발송인 제휴몰건은 제외
		if (TscConstants.MallGb.EXTMALL.value().equals(order.getMallGb()) && "Y".equals(order.getCnclsmsSendYn())) {
			return;
		}
		
		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFuserid(String.valueOf(senderNo)); // 발송자NO
		dm.setFdestine(order.getOrdPhnno());

		dm.setFkkoresendtype("LMS");

		Integer ansSq = 0;
		String pgGb = payment.getPgGb();
		String payMeans = payment.getPayMeans();

		// KCP
		if (TscConstants.PgGb.KCP.value().equals(pgGb)) {
			// 신용카드
			if (TscConstants.PayMeans.CREDIT_CARD.value().equals(payMeans)) {
				ansSq = SsgKakaoSender.KakaoAnswerSq.CARD_CANCEL_BY_SOLDOUT.value();
			}
			// 휴대폰
			else if (TscConstants.PayMeans.CELL_PHONE.value().equals(payMeans)) {
				ansSq = SsgKakaoSender.KakaoAnswerSq.CARD_CANCEL_BY_SOLDOUT.value();
			}
			// 실시간계좌이체
			else if (TscConstants.PayMeans.ACCOUNT_TRANSFER.value().equals(payMeans)) {
				ansSq = SsgKakaoSender.KakaoAnswerSq.AT_CANCEL_BY_SOLDOUT.value();
			}
			// 무통장입금
			else if (TscConstants.PayMeans.BANK_DEPOSIT.value().equals(payMeans)) {
				// 입금 전
				if (TscConstants.PaymentStat.PAY_BEFORE_CANCEL.value().equals(payment.getPayStat())) {
					ansSq = SsgKakaoSender.KakaoAnswerSq.VA_CANCEL_BEFORE_PAYMENT_BY_SOLDOUT.value();
				}
				// 환불계좌 X
				else if (StringUtils.isBlank(payment.getAccountNm()) || StringUtils.isBlank(payment.getAccountNo()) || StringUtils.isBlank(payment.getBankCd())) {
					ansSq = SsgKakaoSender.KakaoAnswerSq.VA_CANCEL_NO_ACCOUNT_BY_SOLDOUT.value();
				}
				// 입금 후 환불계좌 O
				else {
					ansSq = SsgKakaoSender.KakaoAnswerSq.VA_CANCEL_BY_SOLDOUT.value();
				}
			}
		}
		// PAYCO, NAVERPAY 결제형, KAKAOPAY, 상품권
		else if (TscConstants.PgGb.PAYCO.value().equals(pgGb) || TscConstants.PgGb.KAKAO.value().equals(pgGb) || TscConstants.PgGb.NAVER.value().equals(pgGb) || TscConstants.PgGb.ISTYLE.value().equals(pgGb)) {

			ansSq = SsgKakaoSender.KakaoAnswerSq.CARD_CANCEL_BY_SOLDOUT.value();
		}

		// 제휴몰일경우    전체/부분 알림톡 구분 
		if (TscConstants.MallGb.EXTMALL.value().equals(order.getMallGb())) {
			if ("Y".equals(order.getCancelAllYn())) {
				ansSq = SsgKakaoSender.KakaoAnswerSq.EXTMALL_SOLDOUT.value();
			} else {
				ansSq = SsgKakaoSender.KakaoAnswerSq.EXTMALL_PART_SOLDOUT.value();
			}
		}

		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setString("siteNm", siteNm);
		if (Integer.parseInt(order.getGoodsCnt()) > 0) {
			order.setGoodsNm(order.getGoodsNm() + " 외 " + order.getGoodsCnt() + "건");
		}

		if (TscConstants.MallGb.SELFMALL.value().equals(order.getMallGb())) {
			replaceInfo.setString("ordNm", order.getOrdNm());
			replaceInfo.setString("ordNo", String.valueOf(order.getOrdNo()));
			replaceInfo.setString("goodsNm", order.getGoodsNm());
		} else {
			replaceInfo.setString("soldoutGoodsNm", order.getGoodsNm());
			replaceInfo.setString("extmallNm", order.getExtmallNm() + "(" + order.getExtmallTell() + ")");
		}

		dm.setBizTime("Y");
		kakaoSender.send(ansSq, dm, replaceInfo);

		try {
			CustContactHst custContactHst = new CustContactHst();
			// 고객접촉이력 정보
			custContactHst.setContactType(TscConstants.ContactType.SOLDOUT_INFO.value());
			custContactHst.setContactMethod(TscConstants.ContactMethod.KAKAOTALK.value());
			custContactHst.setContactContents("품절취소");
			custContactHst.setReceiverNo(order.getCustNo());
			custContactHst.setSenderNo(senderNo);
			custContactHst.setCustNo(order.getCustNo());
			custContactHst.setRegNo(senderNo);
			coreCustomerService.createCustomerContactHistory(custContactHst);
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
	}

	/**
	 * 배송완료 안내(상품평 작성하기) 
	 * @param order - 주문정보
	 * @return void
	 * @throws Exception - exception
	 * @author moon
	 * @since 2021. 07. 20
	 */
	@Transactional("shopTxnManager")
	public void sendDeliveryComplete(Order order, Integer senderNo) throws Exception {

		Payment payment = new Payment();
		payment.setOrdNo(order.getOrdNo());
		payment = orderChangeDao.getPaymentInfo(payment);
		// 네이버페이 주문형 데이터는 알림톡 송부X
		if (TscConstants.PgGb.NAVER_ORDER.value().equals(payment.getPgGb())) {
			return;
		}

		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFuserid(String.valueOf(senderNo)); // 발송자NO
		dm.setFdestine(order.getOrdPhnno());
		dm.setFkkoresendtype("LMS");

		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setString("siteNm", siteNm);
		replaceInfo.setString("custNm", order.getOrdNm());
		replaceInfo.setString("ordNo", String.valueOf(order.getOrdNo()));

		dm.setBizTime("Y");
		kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.REVIEW_WRITE.value(), dm, replaceInfo);

		try {
			CustContactHst custContactHst = new CustContactHst();
			// 고객접촉이력 정보
			custContactHst.setContactType(TscConstants.ContactType.DELIVERY_COMPLETED.value());
			custContactHst.setContactMethod(TscConstants.ContactMethod.KAKAOTALK.value());
			custContactHst.setContactContents("배송완료");
			custContactHst.setReceiverNo(order.getCustNo());
			custContactHst.setSenderNo(senderNo);
			custContactHst.setCustNo(order.getCustNo());
			custContactHst.setRegNo(senderNo);
			coreCustomerService.createCustomerContactHistory(custContactHst);
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
	}

	/**
	 * 반품,교환 철회(회수X, 잘못된 주소)
	 * @param order - 주문정보
	 * @return void
	 * @throws Exception - exception
	 * @author moon
	 * @since 2021. 07. 21
	 */
	@Transactional("shopTxnManager")
	public void sendRecallCancel(Order order, Integer senderNo, String gubun) throws Exception {

		Integer ansSq = 0;

		Payment payment = new Payment();
		payment.setOrdNo(order.getOrdNo());
		payment = orderChangeDao.getPaymentInfo(payment);
		// 네이버페이 주문형 데이터는 알림톡 송부X
		if (TscConstants.PgGb.NAVER_ORDER.value().equals(payment.getPgGb())) {
			return;
		}

		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFuserid(String.valueOf(senderNo)); // 발송자NO
		dm.setFdestine(order.getOrdPhnno());
		dm.setFkkoresendtype("LMS");

		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setString("siteNm", siteNm);
		replaceInfo.setString("ordNm", order.getOrdNm());
		replaceInfo.setString("ordNo", String.valueOf(order.getOrdNo()));
		if (Integer.parseInt(order.getGoodsCnt()) > 0) {
			order.setGoodsNm(order.getGoodsNm() + " 외 " + order.getGoodsCnt() + "건");
		}
		replaceInfo.setString("goodsNm", order.getGoodsNm());
		replaceInfo.setString("chgerBaseAddr", order.getChgerBaseAddr());

		if ("RETURN_CANCEL_CUSTOMER".equals(gubun)) {
			ansSq = SsgKakaoSender.KakaoAnswerSq.RETURN_CANCEL_CUSTOMER.value(); 	// 반품 철회 안내 - 고객부재
		} else if ("RETURN_CANCEL_ADDR".equals(gubun)) {
			ansSq = SsgKakaoSender.KakaoAnswerSq.RETURN_CANCEL_ADDR.value(); 		// 반품 철회 안내 - 주소불일치 
		} else if ("EXCHANGE_CANCEL_CUSTOMER".equals(gubun)) {
			ansSq = SsgKakaoSender.KakaoAnswerSq.EXCHANGE_CANCEL_CUSTOMER.value(); 	// 교환 철회 안내 - 고객부재
		} else if ("EXCHANGE_CANCEL_ADDR".equals(gubun)) {
			ansSq = SsgKakaoSender.KakaoAnswerSq.EXCHANGE_CANCEL_ADDR.value(); 		// 교환 철회 안내 - 주소불일치
		}

		dm.setBizTime("Y");
		kakaoSender.send(ansSq, dm, replaceInfo);

		try {
			CustContactHst custContactHst = new CustContactHst();
			// 고객접촉이력 정보
			custContactHst.setContactType(TscConstants.ContactType.WITHDRAW_CANCEL.value());
			custContactHst.setContactMethod(TscConstants.ContactMethod.KAKAOTALK.value());
			custContactHst.setContactContents("회수철회");
			custContactHst.setReceiverNo(order.getCustNo());
			custContactHst.setSenderNo(senderNo);
			custContactHst.setCustNo(order.getCustNo());
			custContactHst.setRegNo(senderNo);
			coreCustomerService.createCustomerContactHistory(custContactHst);
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
	}

	/**
	 * 기본 LMS 발송
	 *
	 * @param customer - LMS 정보
	 * @author moon
	 * @since 2021. 07. 23
	 */
	@Transactional("shopTxnManager")
	public void sendBasicLms(Customer customer, Integer senderNo) {
		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFuserid(String.valueOf(senderNo)); // 발송자NO
		dm.setFdestine(customer.getCellPhnno());

		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setString("siteNm", siteNm);
		replaceInfo.setString("content", customer.getContent());
		replaceInfo.setString("callcenterTelNo", TscConstants.CALLCENTER_TEL_NO);
		kakaoSender.sendLms(SsgKakaoSender.KakaoAnswerSq.BASIC_INFO_LMS.value(), dm, replaceInfo);

		try {
			// 고객접촉이력 정보
			CustContactHst custContactHst = new CustContactHst();
			custContactHst.setContactType(TscConstants.ContactType.BASIC_LMS.value()); // 접촉유형:회원-기본LMS안내발송
			custContactHst.setContactMethod(TscConstants.ContactMethod.LMS.value()); // 접촉방법:LMS(공통코드G055)
			custContactHst.setContactContents("기본LMS안내발송");
			custContactHst.setReceiverNo(customer.getCustNo());
			custContactHst.setSenderNo(senderNo);
			custContactHst.setRegNo(senderNo);
			custContactHst.setUpdNo(senderNo);
			coreCustomerService.createCustomerContactHistory(custContactHst);
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
	}

	/**
	 * 기본 LMS 발송
	 *
	 * @param customer - LMS 정보
	 * @author moon
	 * @since 2021. 07. 23
	 */
	@Transactional("shopTxnManager")
	public void sendBasicLms3(Customer customer, Integer senderNo) {
		SsgDirectMessage dm = new SsgDirectMessage();
		dm.setFuserid(String.valueOf(senderNo)); // 발송자NO
		dm.setFdestine(customer.getCellPhnno());

		GagaMap replaceInfo = new GagaMap();
		replaceInfo.setString("siteNm", siteNm);
		replaceInfo.setString("content", customer.getContent());
		replaceInfo.setString("callcenterTelNo", customer.getCallcenterTelNo());
		Integer kakaoSq = SsgKakaoSender.KakaoAnswerSq.BASIC_INFO_LMS.value();
		if("Y".equals(customer.getSelfYn())){
			kakaoSq = SsgKakaoSender.KakaoAnswerSq.BASIC_INFO_LMS.value();
		} else {
			kakaoSq = SsgKakaoSender.KakaoAnswerSq.BASIC_INFO_EXT_LMS.value();
		}
		kakaoSender.sendLms3(kakaoSq, dm, replaceInfo);
	}	
}
