feat: api log 처리 완료
This commit is contained in:
parent
08d81992e3
commit
8f230012ed
@ -1,10 +1,9 @@
|
|||||||
package com.itn.mjonApi.cmn.aop;
|
package com.itn.mjonApi.cmn.aop;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
|
||||||
import com.itn.mjonApi.cmn.idgen.service.IdgenService;
|
import com.itn.mjonApi.cmn.idgen.service.IdgenService;
|
||||||
import com.itn.mjonApi.cmn.msg.RestResponse;
|
import com.itn.mjonApi.cmn.msg.RestResponse;
|
||||||
|
import com.itn.mjonApi.cmn.msg.SendFailRestResponse;
|
||||||
import com.itn.mjonApi.cmn.msg.SendSucRestResponse;
|
import com.itn.mjonApi.cmn.msg.SendSucRestResponse;
|
||||||
import com.itn.mjonApi.mjon.api.access.mapper.domain.AccessKeyVO;
|
import com.itn.mjonApi.mjon.api.access.mapper.domain.AccessKeyVO;
|
||||||
import com.itn.mjonApi.mjon.api.send.mapper.domain.MsgRequestVO;
|
import com.itn.mjonApi.mjon.api.send.mapper.domain.MsgRequestVO;
|
||||||
@ -13,6 +12,7 @@ import com.itn.mjonApi.mjon.log.service.mapper.LettnAccessLogMapper;
|
|||||||
import com.itn.mjonApi.mjon.log.service.mapper.LettnApiSendMsgLogMapper;
|
import com.itn.mjonApi.mjon.log.service.mapper.LettnApiSendMsgLogMapper;
|
||||||
import com.itn.mjonApi.mjon.log.service.mapper.domain.LettnAccessLogVO;
|
import com.itn.mjonApi.mjon.log.service.mapper.domain.LettnAccessLogVO;
|
||||||
import com.itn.mjonApi.mjon.log.service.mapper.domain.LettnApiSendMsgLogVO;
|
import com.itn.mjonApi.mjon.log.service.mapper.domain.LettnApiSendMsgLogVO;
|
||||||
|
import com.itn.mjonApi.util.ApiObjectUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.aspectj.lang.JoinPoint;
|
import org.aspectj.lang.JoinPoint;
|
||||||
@ -144,15 +144,8 @@ public class LogAspect {
|
|||||||
String methodNm = getMethodSignature(joinPoint);
|
String methodNm = getMethodSignature(joinPoint);
|
||||||
if("sendMsgData".equals(methodNm) || "sendMsgsData".equals(methodNm)){
|
if("sendMsgData".equals(methodNm) || "sendMsgsData".equals(methodNm)){
|
||||||
|
|
||||||
String resultCode = this.getResultCodeString(returnValue);
|
LettnApiSendMsgLogVO apiSendMsgLogVO = this.makeApiSendMsgLogVO(returnValue, logId, methodNm);
|
||||||
|
lettnApiSendMsgLogMapper.insert(apiSendMsgLogVO);
|
||||||
|
|
||||||
// resultCode == 0 : 문자 발송이 성공일 때
|
|
||||||
if("0".equals(resultCode)){
|
|
||||||
|
|
||||||
LettnApiSendMsgLogVO apiSendMsgLogVO = this.makeApiSendMsgLogVO(returnValue, logId, methodNm);
|
|
||||||
lettnApiSendMsgLogMapper.insert(apiSendMsgLogVO);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,38 +158,73 @@ public class LogAspect {
|
|||||||
* @param methodNm
|
* @param methodNm
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private LettnApiSendMsgLogVO makeApiSendMsgLogVO(Object returnValue, String logId, String methodNm) {
|
private LettnApiSendMsgLogVO makeApiSendMsgLogVO(Object returnValue, String logId, String methodNm) throws IllegalAccessException {
|
||||||
|
|
||||||
|
// 성공 / 실패 코드
|
||||||
|
String resultCode = this.getResultCodeString(returnValue);
|
||||||
|
|
||||||
RestResponse restResponse = (RestResponse) returnValue;
|
RestResponse restResponse = (RestResponse) returnValue;
|
||||||
SendSucRestResponse SendSucRestResponse = (SendSucRestResponse) restResponse.getData();
|
Object dataObject = restResponse.getData();
|
||||||
|
|
||||||
|
// 파라미터 return class 이름 추출
|
||||||
|
String classNm = this.getClassNmFromObject(dataObject);
|
||||||
|
|
||||||
|
|
||||||
String msgGroupId = null;
|
String msgGroupId = null;
|
||||||
|
String test_yn = null;
|
||||||
|
// 성공일때 CLASS
|
||||||
|
if("SendSucRestResponse".equals(classNm)) {
|
||||||
|
SendSucRestResponse sendSucRestResponse = (SendSucRestResponse) dataObject;
|
||||||
|
|
||||||
|
if("sendMsgData".equals(methodNm)){
|
||||||
|
|
||||||
|
msgGroupId = sendSucRestResponse.getMsgGroupId();
|
||||||
|
}
|
||||||
|
else if("sendMsgsData".equals(methodNm)){
|
||||||
|
|
||||||
|
// list to String
|
||||||
|
msgGroupId = sendSucRestResponse.getMsgGroupIdList().stream()
|
||||||
|
.map(n -> String.valueOf(n))
|
||||||
|
.collect(Collectors.joining("," ));
|
||||||
|
}
|
||||||
|
test_yn = sendSucRestResponse.getTest_yn();
|
||||||
|
|
||||||
|
// ApiObjectUtil.getAccessKeyVOToJsonString(sendSucRestResponse);
|
||||||
|
}
|
||||||
|
// 실패일때 CLASS
|
||||||
|
else if("SendFailRestResponse".equals(classNm)) {
|
||||||
|
SendFailRestResponse sendFailRestResponse = (SendFailRestResponse) dataObject;
|
||||||
|
|
||||||
|
test_yn = sendFailRestResponse.getTest_yn();
|
||||||
|
// ApiObjectUtil.getAccessKeyVOToJsonString(sendSucRestResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
String msgSendType = null;
|
String msgSendType = null;
|
||||||
if("sendMsgData".equals(methodNm)){
|
if("sendMsgData".equals(methodNm)){msgSendType = "msg";}
|
||||||
msgSendType = "msg";
|
else if("sendMsgsData".equals(methodNm)){msgSendType = "msgs";}
|
||||||
msgGroupId = SendSucRestResponse.getMsgGroupId();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
else if("sendMsgsData".equals(methodNm)){
|
|
||||||
msgSendType = "msgs";
|
|
||||||
// msgGroupId = SendSucRestResponse.getMsgGroupIdList().toString();
|
|
||||||
|
|
||||||
// list to String
|
|
||||||
msgGroupId = SendSucRestResponse.getMsgGroupIdList().stream()
|
|
||||||
.map(n -> String.valueOf(n))
|
|
||||||
.collect(Collectors.joining("," ));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return LettnApiSendMsgLogVO.builder()
|
return LettnApiSendMsgLogVO.builder()
|
||||||
.logNo(idgenApiSendLogId.getNextStringId())
|
.logNo(idgenApiSendLogId.getNextStringId())
|
||||||
.accessLogId(logId)
|
.accessLogId(logId)
|
||||||
|
.sendResultCode(resultCode)
|
||||||
.msgSendType(msgSendType)
|
.msgSendType(msgSendType)
|
||||||
.msgGroupId(msgGroupId)
|
.msgGroupId(msgGroupId)
|
||||||
|
.test_yn(test_yn)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static String getClassNmFromObject(Object returnValue) {
|
||||||
|
String classNmTemp = returnValue.getClass().getName();
|
||||||
|
String classNm = classNmTemp.substring(classNmTemp.lastIndexOf(".")+1, classNmTemp.length());
|
||||||
|
return classNm;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description returnCode 가져옴
|
* @description returnCode 가져옴
|
||||||
* @param returnValue
|
* @param returnValue
|
||||||
@ -212,6 +240,8 @@ public class LogAspect {
|
|||||||
for(Field field : data.getClass().getDeclaredFields()){
|
for(Field field : data.getClass().getDeclaredFields()){
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
if("resultCode".equals(field.getName())){ resultCode =field.get(data).toString(); }
|
if("resultCode".equals(field.getName())){ resultCode =field.get(data).toString(); }
|
||||||
|
|
||||||
|
if(StringUtils.isNotEmpty(resultCode)){ break;}
|
||||||
}
|
}
|
||||||
return resultCode;
|
return resultCode;
|
||||||
}
|
}
|
||||||
@ -228,81 +258,10 @@ public class LogAspect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description object의 맞는 Class를 찾아서 맵핑
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private String getJsonToString(Object returnValue) throws JsonProcessingException {
|
|
||||||
|
|
||||||
if(ObjectUtils.isEmpty(returnValue)){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
String classNmTemp = returnValue.getClass().getName();
|
|
||||||
String classNm = classNmTemp.substring(classNmTemp.lastIndexOf(".")+1, classNmTemp.length());
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description : return Class가 추가되면 여기에 추가
|
|
||||||
*/
|
|
||||||
if("AccessKeyVO".equals(classNm)) {
|
|
||||||
AccessKeyVO accessKeyVO = (AccessKeyVO) returnValue;
|
|
||||||
return this.getAccessKeyVOToJsonString(accessKeyVO);
|
|
||||||
}
|
|
||||||
else if("RestResponse".equals(classNm)){
|
|
||||||
RestResponse restResponse = (RestResponse) returnValue;
|
|
||||||
return this.getRestResponseToJsonString(restResponse);
|
|
||||||
}
|
|
||||||
else if("MsgsRequestVO".equals(classNm)){
|
|
||||||
MsgsRequestVO msgsRequestVO = (MsgsRequestVO) returnValue;
|
|
||||||
return this.getMsgsRequestVOToJsonString(msgsRequestVO);
|
|
||||||
}
|
|
||||||
else if("MsgRequestVO".equals(classNm)){
|
|
||||||
MsgRequestVO restResponse = (MsgRequestVO) returnValue;
|
|
||||||
return this.getMsgRequestVOToJsonString(restResponse);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
return "데이터를 추가해 주세요";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description : VO를 json으로 변환
|
|
||||||
* @param restResponse
|
|
||||||
* @return String
|
|
||||||
* @throws JsonProcessingException
|
|
||||||
*/
|
|
||||||
private static String getRestResponseToJsonString(RestResponse restResponse) throws JsonProcessingException {
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
// .registerModule(new JavaTimeModule()) : LocalDateTime을 json으로 변환하기 위함
|
|
||||||
return objectMapper.registerModule(new JavaTimeModule()).writeValueAsString(restResponse);
|
|
||||||
}
|
|
||||||
private static String getMsgsRequestVOToJsonString(MsgsRequestVO msgsRequestVO) throws JsonProcessingException {
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
// .registerModule(new JavaTimeModule()) : LocalDateTime을 json으로 변환하기 위함
|
|
||||||
return objectMapper.registerModule(new JavaTimeModule()).writeValueAsString(msgsRequestVO);
|
|
||||||
}
|
|
||||||
private static String getMsgRequestVOToJsonString(MsgRequestVO msgRequestVO) throws JsonProcessingException {
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
// .registerModule(new JavaTimeModule()) : LocalDateTime을 json으로 변환하기 위함
|
|
||||||
return objectMapper.registerModule(new JavaTimeModule()).writeValueAsString(msgRequestVO);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description : VO를 json으로 변환
|
|
||||||
* @param accessKeyVO
|
|
||||||
* @return String
|
|
||||||
* @throws JsonProcessingException
|
|
||||||
*/
|
|
||||||
private static String getAccessKeyVOToJsonString(AccessKeyVO accessKeyVO) throws JsonProcessingException {
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
// .registerModule(new JavaTimeModule()) : LocalDateTime을 json으로 변환하기 위함
|
|
||||||
return objectMapper.registerModule(new JavaTimeModule()).writeValueAsString(accessKeyVO);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : HttpServletRequest 객체를 가져옴
|
* @description : HttpServletRequest 객체를 가져옴
|
||||||
@ -313,4 +272,46 @@ public class LogAspect {
|
|||||||
((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
|
((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description object의 맞는 Class를 찾아서 맵핑
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getJsonToString(Object returnValue) throws JsonProcessingException {
|
||||||
|
|
||||||
|
if(ObjectUtils.isEmpty(returnValue)){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String classNm = this.getClassNmFromObject(returnValue);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : return Class가 추가되면 여기에 추가
|
||||||
|
*/
|
||||||
|
if("AccessKeyVO".equals(classNm)) {
|
||||||
|
AccessKeyVO accessKeyVO = (AccessKeyVO) returnValue;
|
||||||
|
return ApiObjectUtil.getAccessKeyVOToJsonString(accessKeyVO);
|
||||||
|
}
|
||||||
|
else if("RestResponse".equals(classNm)){
|
||||||
|
RestResponse restResponse = (RestResponse) returnValue;
|
||||||
|
return ApiObjectUtil.getRestResponseToJsonString(restResponse);
|
||||||
|
}
|
||||||
|
else if("MsgsRequestVO".equals(classNm)){
|
||||||
|
MsgsRequestVO msgsRequestVO = (MsgsRequestVO) returnValue;
|
||||||
|
return ApiObjectUtil.getMsgsRequestVOToJsonString(msgsRequestVO);
|
||||||
|
}
|
||||||
|
else if("MsgRequestVO".equals(classNm)){
|
||||||
|
MsgRequestVO restResponse = (MsgRequestVO) returnValue;
|
||||||
|
return ApiObjectUtil.getMsgRequestVOToJsonString(restResponse);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return "데이터를 추가해 주세요";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,6 +49,10 @@ public enum StatMsg {
|
|||||||
//상세발송======================================================================
|
//상세발송======================================================================
|
||||||
, STAT_4099("4099","기타 시스템 오류")
|
, STAT_4099("4099","기타 시스템 오류")
|
||||||
|
|
||||||
|
//발송가능건수======================================================================
|
||||||
|
|
||||||
|
, STAT_5099("5099","기타 시스템 오류")
|
||||||
|
|
||||||
//======================================================================
|
//======================================================================
|
||||||
, msgType4("단문","SMS")
|
, msgType4("단문","SMS")
|
||||||
, msgType6("장문","LMS")
|
, msgType6("장문","LMS")
|
||||||
|
|||||||
@ -126,6 +126,7 @@ public class SendServiceImpl implements SendService {
|
|||||||
}else{
|
}else{
|
||||||
return new RestResponse(
|
return new RestResponse(
|
||||||
SendSucRestResponse.builder()
|
SendSucRestResponse.builder()
|
||||||
|
.resultCode("0")
|
||||||
.msgGroupId("MSGGID_0000000000000") // 전송 메세지 그룹 ID
|
.msgGroupId("MSGGID_0000000000000") // 전송 메세지 그룹 ID
|
||||||
.successCnt("5") // 성공 건수
|
.successCnt("5") // 성공 건수
|
||||||
.blockCnt("2") // 수신거부 건수
|
.blockCnt("2") // 수신거부 건수
|
||||||
|
|||||||
@ -28,7 +28,7 @@ public class LettnApiSendMsgLogVO implements Serializable {
|
|||||||
private String logNo; // access log 고유번호
|
private String logNo; // access log 고유번호
|
||||||
private String accessLogId; // 일반회원ID
|
private String accessLogId; // 일반회원ID
|
||||||
private String sendResultCode; // 메세지 정송 결과 코드
|
private String sendResultCode; // 메세지 정송 결과 코드
|
||||||
private String testYn; // 테스트 여부 (실 발송 : "", 실패 테스트 : "YF", 성공 테스트 "YS")
|
private String test_yn; // 테스트 여부 (실 발송 : "", 실패 테스트 : "YF", 성공 테스트 "YS")
|
||||||
private String msgSendType; // 문자 : msg 대량문자 : msgs
|
private String msgSendType; // 문자 : msg 대량문자 : msgs
|
||||||
private String msgGroupId; // 문자 그룹 ID
|
private String msgGroupId; // 문자 그룹 ID
|
||||||
|
|
||||||
|
|||||||
65
src/main/java/com/itn/mjonApi/util/ApiObjectUtil.java
Normal file
65
src/main/java/com/itn/mjonApi/util/ApiObjectUtil.java
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
package com.itn.mjonApi.util;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||||
|
import com.itn.mjonApi.cmn.msg.RestResponse;
|
||||||
|
import com.itn.mjonApi.mjon.api.access.mapper.domain.AccessKeyVO;
|
||||||
|
import com.itn.mjonApi.mjon.api.send.mapper.domain.MsgRequestVO;
|
||||||
|
import com.itn.mjonApi.mjon.api.send.mapper.domain.MsgsRequestVO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* packageName : com.itn.mjonApi.util
|
||||||
|
* fileName : ObjectUtil
|
||||||
|
* author : hylee
|
||||||
|
* date : 2023-06-15
|
||||||
|
* description :
|
||||||
|
* ===========================================================
|
||||||
|
* DATE AUTHOR NOTE
|
||||||
|
* -----------------------------------------------------------
|
||||||
|
* 2023-06-15 hylee 최초 생성
|
||||||
|
*/
|
||||||
|
public class ApiObjectUtil {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : VO를 json으로 변환
|
||||||
|
* @param restResponse
|
||||||
|
* @return String
|
||||||
|
* @throws JsonProcessingException
|
||||||
|
*/
|
||||||
|
public static String getRestResponseToJsonString(RestResponse restResponse) throws JsonProcessingException {
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
// .registerModule(new JavaTimeModule()) : LocalDateTime을 json으로 변환하기 위함
|
||||||
|
return objectMapper.registerModule(new JavaTimeModule()).writeValueAsString(restResponse);
|
||||||
|
}
|
||||||
|
public static String getMsgsRequestVOToJsonString(MsgsRequestVO msgsRequestVO) throws JsonProcessingException {
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
// .registerModule(new JavaTimeModule()) : LocalDateTime을 json으로 변환하기 위함
|
||||||
|
return objectMapper.registerModule(new JavaTimeModule()).writeValueAsString(msgsRequestVO);
|
||||||
|
}
|
||||||
|
public static String getMsgRequestVOToJsonString(MsgRequestVO msgRequestVO) throws JsonProcessingException {
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
// .registerModule(new JavaTimeModule()) : LocalDateTime을 json으로 변환하기 위함
|
||||||
|
return objectMapper.registerModule(new JavaTimeModule()).writeValueAsString(msgRequestVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : VO를 json으로 변환
|
||||||
|
* @param accessKeyVO
|
||||||
|
* @return String
|
||||||
|
* @throws JsonProcessingException
|
||||||
|
*/
|
||||||
|
public static String getAccessKeyVOToJsonString(AccessKeyVO accessKeyVO) throws JsonProcessingException {
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
// .registerModule(new JavaTimeModule()) : LocalDateTime을 json으로 변환하기 위함
|
||||||
|
return objectMapper.registerModule(new JavaTimeModule()).writeValueAsString(accessKeyVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -27,10 +27,12 @@
|
|||||||
<sql id="insert_column_name">
|
<sql id="insert_column_name">
|
||||||
|
|
||||||
LOG_NO
|
LOG_NO
|
||||||
, ACCESS_LOG_ID
|
, ACCESS_LOG_ID
|
||||||
, MSG_SEND_TYPE
|
, SEND_RESULT_CODE
|
||||||
, MSG_GROUP_ID
|
, TEST_YN
|
||||||
, REQ_REGIST_PNTTM
|
, MSG_SEND_TYPE
|
||||||
|
, MSG_GROUP_ID
|
||||||
|
, REQ_REGIST_PNTTM
|
||||||
|
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
@ -43,6 +45,8 @@
|
|||||||
VALUE (
|
VALUE (
|
||||||
#{logNo}
|
#{logNo}
|
||||||
, #{accessLogId}
|
, #{accessLogId}
|
||||||
|
, #{sendResultCode}
|
||||||
|
, #{test_yn}
|
||||||
, #{msgSendType}
|
, #{msgSendType}
|
||||||
, #{msgGroupId}
|
, #{msgGroupId}
|
||||||
, now()
|
, now()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user