Преглед изворни кода

넷퍼시메일발송 기능 구현

gagamel пре 5 година
родитељ
комит
0d80f53d3d

+ 34 - 0
src/main/java/com/style24/core/biz/dao/NetpathyMailDao.java

@@ -0,0 +1,34 @@
+package com.style24.core.biz.dao;
+
+import com.style24.core.support.annotation.ShopDs;
+import com.style24.persistence.domain.MailTemplate;
+import com.style24.persistence.domain.Netpathy;
+
+/**
+ * 넷퍼시메일 Dao
+ * 
+ * @author gagamel
+ * @since 2021. 5. 10
+ */
+@ShopDs
+public interface NetpathyMailDao {
+
+	/**
+	 * 메일템플릿 조회
+	 * @param mailtSq - 메일템플릿번호
+	 * @return
+	 * @author gagamel
+	 * @since 2021. 5. 10
+	 */
+	MailTemplate getMailTemplate(Integer mailtSq);
+
+	/**
+	 * 메일 생성
+	 * @param netpathy - 넷퍼시메일 정보
+	 * @return
+	 * @author gagamel
+	 * @since 2021. 5. 10
+	 */
+	void createMail(Netpathy netpathy);
+
+}

+ 147 - 0
src/main/java/com/style24/core/biz/thirdparty/NetpathyMailSender.java

@@ -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;
+	}
+
+}

+ 25 - 0
src/main/java/com/style24/persistence/domain/Netpathy.java

@@ -0,0 +1,25 @@
+package com.style24.persistence.domain;
+
+import java.io.Serializable;
+
+import lombok.Data;
+
+/**
+ * 넷퍼시메일 Domain
+ *
+ * @author gagamel
+ * @since 2021. 5. 10
+ */
+
+@SuppressWarnings("serial")
+@Data
+public class Netpathy implements Serializable {
+
+	private String legacyid;	// 회원ID
+	private String autotype;	// 자동메일타입
+	private String email;		// 이메일
+	private String name;		// 이름
+	private String title;		// 메일제목
+	private String content;		// 메일내용
+
+}

+ 45 - 0
src/main/java/com/style24/persistence/mybatis/shop/NetpathyMail.xml

@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.style24.core.biz.dao.NetpathyMailDao">
+
+	<!-- 메일템플릿 조회 -->
+	<select id="getMailTemplate" parameterType="Integer" resultType="MailTemplate">
+		/* NetpathyMail.getMailTemplate */
+		SELECT MAILT_SQ     /*메일템플릿일련번호*/
+		     , MAILT_GB     /*메일템플릿구분*/
+		     , MAILH_SQ     /*메일템플릿헤더일련번호*/
+		     , MAILF_SQ     /*메일템플릿푸터일련번호*/
+		     , MAILT_NM     /*메일템플릿명*/
+		     , MAIL_CONTENT /*메일내용*/
+		FROM   TB_MAILT
+		WHERE  MAILT_SQ = #{mailtSq}
+	</select>
+	
+	<!-- 메일 생성 -->
+	<insert id="createMail" parameterType="Netpathy">
+		/* NetpathyMail.createMail */
+		INSERT INTO AUTOMAIL_INTERFACE (
+		       LEGACYID     /*회원ID*/
+		     , AUTOTYPE     /*자동메일타입*/
+		     , EMAIL        /*이메일*/
+		     , NAME         /*이름*/
+		     , INSERTDATE   /*입력일*/
+		     , SENDTIME     /*전송일*/
+		     , SENDYN       /*전송여부*/
+		     , TITLE        /*메일제목*/
+		     , CONTENT      /*메일내용*/
+		)
+		VALUES (
+		       #{legacyid}
+		     , #{autotype}
+		     , #{email}
+		     , #{name}
+		     , NOW()
+		     , NOW()
+		     , 'N'
+		     , #{title}
+		     , #{content}
+		)
+	</insert>
+
+</mapper>