|
|
@@ -0,0 +1,147 @@
|
|
|
+package com.style24.core.biz.thirdparty;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.cache.annotation.Cacheable;
|
|
|
+import org.springframework.core.env.Environment;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import com.style24.core.biz.dao.NetpathyMailDao;
|
|
|
+import com.style24.persistence.domain.MailTemplate;
|
|
|
+import com.style24.persistence.domain.Netpathy;
|
|
|
+
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+
|
|
|
+import com.gagaframework.web.parameter.GagaMap;
|
|
|
+import com.gagaframework.web.util.GagaStringUtil;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 넷퍼시를 이용한 메일 발송
|
|
|
+ *
|
|
|
+ * @author gagamel
|
|
|
+ * @since 2021. 5. 10
|
|
|
+ */
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class NetpathyMailSender {
|
|
|
+
|
|
|
+// // 발신자전화번호
|
|
|
+// private String callbackTelNo;
|
|
|
+//
|
|
|
+// private String domainUrl;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private Environment env;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private NetpathyMailDao netpathyDao;
|
|
|
+
|
|
|
+ @PostConstruct
|
|
|
+ public void init() {
|
|
|
+// domainUrl = env.getProperty("domain.front");
|
|
|
+// callbackTelNo = TscConstants.CALLCENTER_TEL_NO;
|
|
|
+
|
|
|
+// log.debug("\n\n---- NetpathyMailSender initialization started ----");
|
|
|
+// log.debug("domainUrl: [{}]", domainUrl);
|
|
|
+// log.debug("callbackTelNo: [{}]", callbackTelNo);
|
|
|
+// log.debug("\n--- NetpathyMailSender initialization completed ----\n");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 메일 발송
|
|
|
+ * @param mailtSq - 메일템플릿번호
|
|
|
+ * @param toAddress - 보낼 메일 주소
|
|
|
+ * @param replaceInfo - 메시지내용 중 대체할 정보
|
|
|
+ * @author gagamel
|
|
|
+ * @since 2021. 5. 10
|
|
|
+ */
|
|
|
+ @Transactional("shopTxnManager")
|
|
|
+ public void send(Integer mailtSq, String toAddress, GagaMap replaceInfo) {
|
|
|
+ // 메일템플릿 조회
|
|
|
+ MailTemplate mailTemplate = this.getMailTemplate(mailtSq, replaceInfo);
|
|
|
+
|
|
|
+ Netpathy netpathy = new Netpathy();
|
|
|
+// netpathy.setLegacyid(legacyid);
|
|
|
+ netpathy.setAutotype("TST");
|
|
|
+ netpathy.setEmail(toAddress);
|
|
|
+// netpathy.setName(name);
|
|
|
+ netpathy.setTitle(mailTemplate.getMailtNm());
|
|
|
+ netpathy.setContent(mailTemplate.getMailContent());
|
|
|
+
|
|
|
+ // 메일 생성
|
|
|
+ netpathyDao.createMail(netpathy);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 메일템플릿 조회
|
|
|
+ * 어드민의 "회원/마케팅 > 마케팅 > 메일템플릿관리" 화면에서 등록/수정 시 mailTemplate 캐시를 삭제
|
|
|
+ * @param mailtSq - 메일템플릿번호
|
|
|
+ * @param replaceInfo - 메시지내용 중 대체할 정보
|
|
|
+ * @return
|
|
|
+ * @author gagamel
|
|
|
+ * @since 2021. 5. 10
|
|
|
+ */
|
|
|
+ @Cacheable(value = "mailTemplate", key = "#mailtSq")
|
|
|
+ public MailTemplate getMailTemplate(Integer mailtSq, GagaMap replaceInfo) {
|
|
|
+ MailTemplate mailTemplate = netpathyDao.getMailTemplate(mailtSq);
|
|
|
+ mailTemplate.setMailtNm(GagaStringUtil.replace(this.mergeData(mailTemplate.getMailtNm(), replaceInfo), ">", ">"));
|
|
|
+ mailTemplate.setMailContent(GagaStringUtil.replace(this.mergeData(mailTemplate.getMailContent(), replaceInfo), ">", ">"));
|
|
|
+ return mailTemplate;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 메시지 문자열 중에 '#{'로 시작하고 '}'로 끝나는 부분을 대체할 정보(replaceInfo)로 대체해 반환한다.
|
|
|
+ * @param message - 메시지 문자열
|
|
|
+ * @param replaceInfo - 알림톡 메시지 중 대체할 정보
|
|
|
+ * @return
|
|
|
+ * @author gagamel
|
|
|
+ * @date 2018. 1. 21.
|
|
|
+ */
|
|
|
+ private String mergeData(String message, GagaMap replaceInfo) {
|
|
|
+ List<String> keyList = getKeyList(message, "#{", "}");
|
|
|
+
|
|
|
+ String key = "";
|
|
|
+ String value = "";
|
|
|
+
|
|
|
+ if (!keyList.isEmpty()) {
|
|
|
+ for (int i = 0; i < keyList.size(); i++) {
|
|
|
+ key = keyList.get(i);
|
|
|
+ value = replaceInfo.getString(key);
|
|
|
+ message = message.replace("#{" + key + "}", value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return message;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 입력 문자열로부터 시작 태그와 종료 태그 안의 key 목록을 반환한다.
|
|
|
+ * @param inputStr - 입력 문자열
|
|
|
+ * @param startTag - 시작 태그
|
|
|
+ * @param endTag - 종료 태그
|
|
|
+ * @return
|
|
|
+ * @author gagamel
|
|
|
+ * @date 2018. 1. 21.
|
|
|
+ */
|
|
|
+ private List<String> getKeyList(String inputStr, String startTag, String endTag) {
|
|
|
+ List<String> keyList = new ArrayList<>();
|
|
|
+
|
|
|
+ String targetStr = inputStr;
|
|
|
+
|
|
|
+ while (targetStr.indexOf(startTag) > -1) {
|
|
|
+ int startPos = targetStr.indexOf(startTag) + startTag.length();
|
|
|
+ int endPos = targetStr.indexOf(endTag, startPos);
|
|
|
+
|
|
|
+ keyList.add(targetStr.substring(startPos, endPos));
|
|
|
+ targetStr = targetStr.substring(endPos + endTag.length());
|
|
|
+ }
|
|
|
+
|
|
|
+ return keyList;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|