From d2acc245679b8888d9e567f9dd647c060a438dd4 Mon Sep 17 00:00:00 2001 From: "Jonguk. Lim" Date: Thu, 5 Sep 2024 12:17:51 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20keySequence=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=20=EC=B6=94=EA=B0=80=20=20=20=20=20=20=20p6spy=20log?= =?UTF-8?q?=20=EC=B6=9C=EB=A0=A5=20=EB=B3=80=EA=B2=BD=20=20=20=20=20=20=20?= =?UTF-8?q?-=20connection=20ID=20=EC=B6=9C=EB=A0=A5=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=20=EC=A0=81=EC=9A=A9=20=20=20=20=20=20=20-=20sql=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=20=ED=8F=AC=EB=A7=B7=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logging/P6spySqlFormatConfiguration.java | 60 +++----- ...MngMapper.java => IKeySequenceMapper.java} | 12 +- .../sys/mng/service/KeySequenceService.java | 36 +++++ .../service/support/KkoTalkAcceptor.java | 7 +- .../modules/iup-keyseq-mapper.xml | 27 ++++ .../modules/iup-kkotalk-mapper.xml | 144 +++++++++--------- 6 files changed, 172 insertions(+), 114 deletions(-) rename src/main/java/cokr/xit/ens/modules/common/ctgy/sys/mng/mapper/{IOrgMngMapper.java => IKeySequenceMapper.java} (62%) create mode 100644 src/main/java/cokr/xit/ens/modules/common/ctgy/sys/mng/service/KeySequenceService.java create mode 100644 src/main/resources/mybatis-mapper/modules/iup-keyseq-mapper.xml diff --git a/src/main/java/cokr/xit/ens/core/config/logging/P6spySqlFormatConfiguration.java b/src/main/java/cokr/xit/ens/core/config/logging/P6spySqlFormatConfiguration.java index 79feb06..fa0453b 100644 --- a/src/main/java/cokr/xit/ens/core/config/logging/P6spySqlFormatConfiguration.java +++ b/src/main/java/cokr/xit/ens/core/config/logging/P6spySqlFormatConfiguration.java @@ -2,64 +2,46 @@ package cokr.xit.ens.core.config.logging; import java.util.Locale; +import javax.annotation.PostConstruct; + import org.hibernate.engine.jdbc.internal.FormatStyle; import com.p6spy.engine.logging.Category; +import com.p6spy.engine.spy.P6SpyOptions; import com.p6spy.engine.spy.appender.MessageFormattingStrategy; import lombok.extern.slf4j.Slf4j; @Slf4j public class P6spySqlFormatConfiguration implements MessageFormattingStrategy { - private static final String NEW_LINE = "\n"; - private static final String TAP = "\t"; private static final String CREATE = "create"; private static final String ALTER = "alter"; private static final String DROP = "drop"; private static final String COMMENT = "comment"; - @Override - public String formatMessage(int connectionId, String now, long elapsed, String category, String prepared, String sql, String url) { - if (sql.trim().isEmpty()) { - return formatByCommand(category); - } return formatBySql(sql, category) + getAdditionalMessages(elapsed); - } - private static String formatByCommand(String category) { - return NEW_LINE - + "Execute Command : " - + NEW_LINE - + NEW_LINE - + TAP - + category - + NEW_LINE - + NEW_LINE - + "----------------------------------------------------------------------------------------------------"; + @PostConstruct + public void setLogMessageFormat() { + P6SpyOptions.getActiveInstance().setLogMessageFormat(this.getClass().getName()); } - private String formatBySql(String sql, String category) { - if (isStatementDDL(sql, category)) { - return NEW_LINE - + "Execute DDL : " - + NEW_LINE - + FormatStyle.DDL - .getFormatter() - .format(sql); - } return NEW_LINE - + "Execute DML : " - + NEW_LINE - + FormatStyle.BASIC - .getFormatter() - .format(sql); - } - private String getAdditionalMessages(long elapsed) { - return NEW_LINE - + NEW_LINE - + String.format("Execution Time: %s ms", elapsed) - + NEW_LINE - + "----------------------------------------------------------------------------------------------------"; + + @Override + public String formatMessage(final int connectionId, final String now, final long elapsed, final String category, final String prepared, final String sql, final String url) { + + // FIXME: JPA 미사용시 SQL format 적용 + //return "connection " + connectionId + " | took " + elapsed + "ms | " + category + "\n" + sql; + + // FIXME: JPA 사용시 SQL format 적용 + if(isStatementDDL(sql, category)) { + + return "connection " + connectionId + " | took " + elapsed + "ms | " + category + "\n" + FormatStyle.DDL.getFormatter().format(sql); + } + return "connection " + connectionId + " | took " + elapsed + "ms | " + category + "\n" + FormatStyle.BASIC.getFormatter().format(sql); } + private boolean isStatementDDL(String sql, String category) { return isStatement(category) && isDDL(sql.trim().toLowerCase(Locale.ROOT)); } + private boolean isStatement(String category) { return Category.STATEMENT.getName().equals(category); } diff --git a/src/main/java/cokr/xit/ens/modules/common/ctgy/sys/mng/mapper/IOrgMngMapper.java b/src/main/java/cokr/xit/ens/modules/common/ctgy/sys/mng/mapper/IKeySequenceMapper.java similarity index 62% rename from src/main/java/cokr/xit/ens/modules/common/ctgy/sys/mng/mapper/IOrgMngMapper.java rename to src/main/java/cokr/xit/ens/modules/common/ctgy/sys/mng/mapper/IKeySequenceMapper.java index 0ca2788..51a9fcf 100644 --- a/src/main/java/cokr/xit/ens/modules/common/ctgy/sys/mng/mapper/IOrgMngMapper.java +++ b/src/main/java/cokr/xit/ens/modules/common/ctgy/sys/mng/mapper/IKeySequenceMapper.java @@ -1,10 +1,14 @@ package cokr.xit.ens.modules.common.ctgy.sys.mng.mapper; +import java.util.Map; + +import org.apache.ibatis.annotations.Mapper; + /** *
  * description :
  * packageName : cokr.xit.ens.modules.common.ctgy.sys.mng.mapper
- * fileName    : IOrgMngMapper
+ * fileName    : IKeySequenceMapper
  * author      : limju
  * date        : 2024 9월 03
  * ======================================================================
@@ -14,5 +18,9 @@ package cokr.xit.ens.modules.common.ctgy.sys.mng.mapper;
  *
  * 
*/ -public interface IOrgMngMapper { +// FIXME: 카카오톡 신규 추가 +@Mapper +public interface IKeySequenceMapper { + Long selectKeySequence(String seqName); + void saveKeySequence(Map map); } diff --git a/src/main/java/cokr/xit/ens/modules/common/ctgy/sys/mng/service/KeySequenceService.java b/src/main/java/cokr/xit/ens/modules/common/ctgy/sys/mng/service/KeySequenceService.java new file mode 100644 index 0000000..b6f9d23 --- /dev/null +++ b/src/main/java/cokr/xit/ens/modules/common/ctgy/sys/mng/service/KeySequenceService.java @@ -0,0 +1,36 @@ +package cokr.xit.ens.modules.common.ctgy.sys.mng.service; + +import java.util.HashMap; +import java.util.Map; + +import javax.transaction.Transactional; + +import org.springframework.stereotype.Service; + +import cokr.xit.ens.modules.common.ctgy.sys.mng.mapper.IKeySequenceMapper; +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +public class KeySequenceService { + + private final IKeySequenceMapper mapper; + + /** + * 키 시퀀스 조회 + * @param seqName 키 시퀀스 이름 + * @return Long + */ + @Transactional + public Long getKeySequence(String seqName) { + Long nextSeq = mapper.selectKeySequence(seqName); + if(nextSeq == null) { + nextSeq = 1L; + } + Map map = new HashMap<>(); + map.put("seqName", seqName); + map.put("nextVal", nextSeq); + mapper.saveKeySequence(map); + return nextSeq; + } +} diff --git a/src/main/java/cokr/xit/ens/modules/kkotalk/service/support/KkoTalkAcceptor.java b/src/main/java/cokr/xit/ens/modules/kkotalk/service/support/KkoTalkAcceptor.java index 3b66b6c..897371b 100644 --- a/src/main/java/cokr/xit/ens/modules/kkotalk/service/support/KkoTalkAcceptor.java +++ b/src/main/java/cokr/xit/ens/modules/kkotalk/service/support/KkoTalkAcceptor.java @@ -39,6 +39,7 @@ import cokr.xit.ens.modules.common.ctgy.intgrnbill.support.entity.repository.Bil import cokr.xit.ens.modules.common.ctgy.mblpage.domain.SendDetailMblPage; import cokr.xit.ens.modules.common.ctgy.mblpage.domain.repository.SendDetailMblPageRepository; import cokr.xit.ens.modules.common.ctgy.sys.mng.domain.OrgMng; +import cokr.xit.ens.modules.common.ctgy.sys.mng.service.KeySequenceService; import cokr.xit.ens.modules.common.ctgy.sys.mng.service.OrgMngService; import cokr.xit.ens.modules.common.ctgy.sys.mng.service.TmpltMngService; import cokr.xit.ens.modules.common.domain.SendMast; @@ -57,6 +58,7 @@ public class KkoTalkAcceptor implements EnsPhaseProcSupport, Kk private final SendMastRepository sendMastRepository; private final IKkoTalkMapper kkoTalkMapper; + private final KeySequenceService keySequenceService; private final SendDetailMblPageRepository sendDetailMblPageRepository; private final BillRepository billRepository; private final OrgMngService orgMngService; @@ -235,7 +237,10 @@ public class KkoTalkAcceptor implements EnsPhaseProcSupport, Kk ); // kkotalk 발송상세 저장 - sendDetails.forEach(kkoTalkMapper::saveSndDtlKkoTalk); + sendDetails.forEach(d -> { + d.setSendDetailId(keySequenceService.getKeySequence("SendDetailKkoTalk_id")); + kkoTalkMapper.saveSndDtlKkoTalk(d); + }); if (!sendDetailMblPages.isEmpty()) diff --git a/src/main/resources/mybatis-mapper/modules/iup-keyseq-mapper.xml b/src/main/resources/mybatis-mapper/modules/iup-keyseq-mapper.xml new file mode 100644 index 0000000..822cfa7 --- /dev/null +++ b/src/main/resources/mybatis-mapper/modules/iup-keyseq-mapper.xml @@ -0,0 +1,27 @@ + + + + + + + + /** iup-keyseq-mapper|saveKeySequence-key sequence 저장|julim */ + MERGE + INTO ens_seq_generator tgt + USING (SELECT #{seqName} AS seq_name, #{nextVal} AS next_val FROM dual) src + ON (tgt.seq_name = src.seq_name) + WHEN MATCHED THEN + UPDATE SET tgt.next_val = src.next_val + WHEN NOT MATCHED THEN + INSERT (seq_name, next_val) + VALUES (src.seq_name, src.next_val) + + + diff --git a/src/main/resources/mybatis-mapper/modules/iup-kkotalk-mapper.xml b/src/main/resources/mybatis-mapper/modules/iup-kkotalk-mapper.xml index ecd13e0..66bf048 100644 --- a/src/main/resources/mybatis-mapper/modules/iup-kkotalk-mapper.xml +++ b/src/main/resources/mybatis-mapper/modules/iup-kkotalk-mapper.xml @@ -1,79 +1,79 @@ + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - - - - - /** iup-kkotalk-mapper|saveSndDtlKkoTalk-카카오톡발송상세생성|julim */ - INSERT INTO ens_snd_dtl_kko_talk ( - send_detail_id, - title, - link, - hash, - guide, - payload, - read_expires_at, - review_expires_at, - use_non_personalized_noti, - ci, - phone_number, - name, - birthday, - external_id, - error_code, - error_message, - bill_uid, - send_mast_id, - regist_dt - ) VALUES ( - #{sendDetailId}, - #{title}, - #{link}, - #{hash}, - #{guide}, - #{payload}, - #{readExpiresAt}, - #{reviewExpiresAt}, - #{useNonPersonalizedNotification}, - #{ci}, - #{phoneNumber}, - #{name}, - #{birthday}, - #{externalId}, - #{errorCode}, - #{errorMessage}, - #{billUid}, - #{sendMastId}, - sysdate - ) - + + + + + /** iup-kkotalk-mapper|saveSndDtlKkoTalk-카카오톡발송상세생성|julim */ + INSERT INTO ens_snd_dtl_kko_talk ( + send_detail_id, + title, + link, + hash, + guide, + payload, + read_expires_at, + review_expires_at, + use_non_personalized_noti, + ci, + phone_number, + name, + birthday, + external_id, + error_code, + error_message, + bill_uid, + send_mast_id, + regist_dt + ) VALUES ( + select ens_seq_generator.nextval from dual, + #{title}, + #{link}, + #{hash}, + #{guide}, + #{payload}, + #{readExpiresAt}, + #{reviewExpiresAt}, + #{useNonPersonalizedNotification}, + #{ci}, + #{phoneNumber}, + #{name}, + #{birthday}, + #{externalId}, + #{errorCode}, + #{errorMessage}, + #{billUid}, + #{sendMastId}, + sysdate + ) + - +