refactor: HistoryRecorder 제거 및 identify/trans 리스너·적재 로직 단일화 (12/12 테스트 통과)

This commit is contained in:
binz 2026-11-18 08:30:26 +00:00
parent f3ca322fdb
commit ad1b50e96b
5 changed files with 41 additions and 124 deletions

View File

@ -1,17 +0,0 @@
package com.bccard.tsp.adapt.history;
/**
* [이력/로그 저장소 최상위 공통 인터페이스]
* - 업무 이력(본인인증), 기술 로그(통신로그) 등 다양한 유형의 이력을 일관된 규격으로 적재하기 위한 인터페이스
*
* @param <T> 저장할 이력/로그 데이터 객체 타입
*/
public interface HistoryRecorder<T> {
/**
* 이력 또는 로그 데이터를 적재한다.
*
* @param data 이력/로그 데이터 객체
*/
void record(T data);
}

View File

@ -1,24 +1,29 @@
package com.bccard.tsp.adapt.history.identify;
import com.bccard.tsp.adapt.history.identify.event.CardIdentifyEvent;
import com.bccard.tsp.adapt.history.identify.impl.IdnvServiceMapper;
import com.bccard.tsp.vo.IdnvCtnt;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
/**
* [카드 본인인증 이력 이벤트 리스너 (동기 실행)]
* - 핸들러가 발행한 CardIdentifyEvent를 수신하여 CardIdentifyHistoryRecorder에 위임한다.
* [카드 본인인증 이력 이벤트 리스너 (수신 및 적재 단일화)]
* - 핸들러가 발행한 CardIdentifyEvent를 동기(@EventListener)로 수신하여
* 내부 코드 메시지 매핑 후 IdnvServiceMapper를 통해 DB(LKG_CTNT)에 적재한다.
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class CardIdentifyHistoryListener {
private final CardIdentifyHistoryRecorder historyRecorder;
private final IdnvServiceMapper idnvServiceMapper;
/**
* CardIdentifyEvent 수신 후 CardIdentifyHistoryRecorder를 통해 DB 적재 처리
* CardIdentifyEvent 수신 및 본인인증 연계내역 DB 적재 처리
*
* @param event 카드 본인인증 이력 이벤트
*/
@ -28,11 +33,31 @@ public class CardIdentifyHistoryListener {
return;
}
IdnvCtnt idnvCtnt = event.getIdnvCtnt();
try {
historyRecorder.record(event.getIdnvCtnt());
// 내부 코드로 변환된 메시지 조회 (DB 함수 조회)
if (idnvCtnt.getIntnMsg() == null && idnvCtnt.getIntnCd() != null) {
try {
String intnMsg = idnvServiceMapper.selectMessageByCode(idnvCtnt.getIntnCd());
if (intnMsg != null && !intnMsg.trim().isEmpty()) {
idnvCtnt.setIntnMsg(intnMsg);
}
} catch (Exception e) {
log.warn("[CardIdentifyHistoryListener] selectMessageByCode 조회 실패 - intnCd={}",
idnvCtnt.getIntnCd(), e);
}
}
if (idnvCtnt.getRegDtim() == null) {
idnvCtnt.setRegDtim(LocalDateTime.now());
}
idnvServiceMapper.insertLkgCtnt(idnvCtnt);
log.info("[CardIdentifyHistoryListener] 이력 적재 완료 - ifId={}, trid={}, intnCd={}",
idnvCtnt.getIfId(), idnvCtnt.getTrid(), idnvCtnt.getIntnCd());
} catch (Exception e) {
log.error("[CardIdentifyHistoryListener] 이력 적재 위임 중 예외 발생 - ifId={}, trid={}",
event.getIdnvCtnt().getIfId(), event.getIdnvCtnt().getTrid(), e);
log.error("[CardIdentifyHistoryListener] 이력 적재 중 예외 발생 - ifId={}, trid={}",
idnvCtnt.getIfId(), idnvCtnt.getTrid(), e);
}
}
}

View File

@ -1,58 +0,0 @@
package com.bccard.tsp.adapt.history.identify;
import com.bccard.tsp.adapt.history.HistoryRecorder;
import com.bccard.tsp.adapt.history.identify.impl.IdnvServiceMapper;
import com.bccard.tsp.vo.IdnvCtnt;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;
import java.time.LocalDateTime;
/**
* [카드 본인인증 이력 저장소 클래스]
* - 공통 HistoryRecorder<IdnvCtnt>를 구현하여 단일화된 이력 적재를 수행한다.
* - IdnvServiceMapper를 통해 DB(LKG_CTNT)에 본인인증 연계내역을 적재한다.
*/
@Slf4j
@Repository
@RequiredArgsConstructor
public class CardIdentifyHistoryRecorder implements HistoryRecorder<IdnvCtnt> {
private final IdnvServiceMapper idnvServiceMapper;
/**
* 핸들러가 조립한 IdnvCtnt를 받아 내부 메시지 매핑 후 DB에 적재한다.
*
* @param idnvCtnt 카드 본인인증 이력 VO
*/
@Override
public void record(IdnvCtnt idnvCtnt) {
if (idnvCtnt == null) {
return;
}
try {
// 내부 코드로 변환된 메시지 조회 (DB 함수 조회)
if (idnvCtnt.getIntnMsg() == null && idnvCtnt.getIntnCd() != null) {
try {
String intnMsg = idnvServiceMapper.selectMessageByCode(idnvCtnt.getIntnCd());
if (intnMsg != null && !intnMsg.trim().isEmpty()) {
idnvCtnt.setIntnMsg(intnMsg);
}
} catch (Exception e) {
log.warn("[CardIdentifyHistoryRecorder] selectMessageByCode 조회 실패 - intnCd={}", idnvCtnt.getIntnCd(), e);
}
}
if (idnvCtnt.getRegDtim() == null) {
idnvCtnt.setRegDtim(LocalDateTime.now());
}
idnvServiceMapper.insertLkgCtnt(idnvCtnt);
log.info("[CardIdentifyHistoryRecorder] 이력 적재 완료 - ifId={}, trid={}, intnCd={}",
idnvCtnt.getIfId(), idnvCtnt.getTrid(), idnvCtnt.getIntnCd());
} catch (Exception e) {
log.error("insertLkgCtnt", e);
}
}
}

View File

@ -8,18 +8,16 @@ import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
/**
* [통신 기술 로그 이벤트 리스너]
* - 대외 통신 발생 시 발행된 CommLogEvent를 수신하여 CommLogRecorder에 위임한다.
* [통신 기술 로그 이벤트 리스너 (수신 및 적재 단일화)]
* - 대외 통신 발생 시 발행된 CommLogEvent를 수신하여 통신 로그를 직접 적재한다.
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class CommLogListener {
private final CommLogRecorder commLogRecorder;
/**
* CommLogEvent 수신 및 적재 위임
* CommLogEvent 수신 및 통신 기술 로그 적재 처리
*
* @param event 통신 로그 이벤트
*/
@ -29,12 +27,14 @@ public class CommLogListener {
return;
}
CommLogVo commLogVo = event.getCommLogVo();
try {
commLogRecorder.record(event.getCommLogVo());
// DB 통신 로그 테이블 적재 또는 로깅 시스템 전송
log.info("[CommLogListener] 통신 로그 적재 완료 - intfId={}, usrId={}, status={}, elapsedTime={}ms",
commLogVo.getIntfId(), commLogVo.getUsrId(), commLogVo.getStatus(), commLogVo.getElapsedTimeMs());
} catch (Exception e) {
CommLogVo vo = event.getCommLogVo();
log.error("[CommLogListener] 통신 로그 처리 중 오류 발생 - intfId={}, usrId={}",
vo.getIntfId(), vo.getUsrId(), e);
log.error("[CommLogListener] 통신 로그 적재 중 예외 발생 - intfId={}, usrId={}",
commLogVo.getIntfId(), commLogVo.getUsrId(), e);
}
}
}

View File

@ -1,33 +0,0 @@
package com.bccard.tsp.adapt.history.trans;
import com.bccard.tsp.adapt.history.HistoryRecorder;
import com.bccard.tsp.adapt.history.trans.vo.CommLogVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;
/**
* [통신 기술 로그 저장소 클래스]
* - 공통 HistoryRecorder<CommLogVo>를 구현하여 단일화된 통신 로그 적재를 수행한다.
*/
@Slf4j
@Repository
@RequiredArgsConstructor
public class CommLogRecorder implements HistoryRecorder<CommLogVo> {
@Override
public void record(CommLogVo commLogVo) {
if (commLogVo == null) {
return;
}
try {
// DB 통신 로그 테이블 적재 또는 로깅 시스템 전송
log.info("[CommLogRecorder] 통신 로그 적재 완료 - intfId={}, usrId={}, status={}, elapsedTime={}ms",
commLogVo.getIntfId(), commLogVo.getUsrId(), commLogVo.getStatus(), commLogVo.getElapsedTimeMs());
} catch (Exception e) {
log.error("[CommLogRecorder] 통신 로그 적재 실패 - intfId={}, usrId={}",
commLogVo.getIntfId(), commLogVo.getUsrId(), e);
}
}
}