feat: LogAspect AOP 공통
This commit is contained in:
parent
2508460283
commit
ba59048931
@ -5,7 +5,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
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.mjon.api.send.mapper.domain.MsgRequestVO;
|
|
||||||
import com.itn.mjonApi.mjon.log.service.mapper.LettnAccessLogMapper;
|
import com.itn.mjonApi.mjon.log.service.mapper.LettnAccessLogMapper;
|
||||||
import com.itn.mjonApi.mjon.log.service.mapper.domain.LettnAccessLogVO;
|
import com.itn.mjonApi.mjon.log.service.mapper.domain.LettnAccessLogVO;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -20,13 +19,14 @@ import org.springframework.web.context.request.ServletRequestAttributes;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* packageName : com.itn.mjonApi.cmn.aop
|
* packageName : com.itn.mjonApi.cmn.aop
|
||||||
* fileName : SendAspect
|
* fileName : LogAspect
|
||||||
* author : hylee
|
* author : hylee
|
||||||
* date : 2023-05-24
|
* date : 2023-05-24
|
||||||
* description : send package 관련 AOP
|
* description : lettngnrlmber_access_log 기록 남기는 AOP
|
||||||
* ===========================================================
|
* ===========================================================
|
||||||
* DATE AUTHOR NOTE
|
* DATE AUTHOR NOTE
|
||||||
* -----------------------------------------------------------
|
* -----------------------------------------------------------
|
||||||
@ -35,7 +35,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@Aspect
|
@Aspect
|
||||||
@Component
|
@Component
|
||||||
public class SendAspect {
|
public class LogAspect {
|
||||||
// @Autowired
|
// @Autowired
|
||||||
// private LettnAccessLogService lettnAccessLogService;
|
// private LettnAccessLogService lettnAccessLogService;
|
||||||
|
|
||||||
@ -45,31 +45,41 @@ public class SendAspect {
|
|||||||
private IdgenService idgenApiAccessLogId;
|
private IdgenService idgenApiAccessLogId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description SendServiceImpl.sendMsgData 메소드 실행 전 로그 처리
|
* @description com.itn.mjonApi.mjon.api 패키지 하위에 모든 *Impl 클래스의 모든 메소드 실행 전
|
||||||
* - 대량문자와 개별문자의 파마리터 VO가 다르므로 메소드로 분기 처리하기위함
|
|
||||||
* @param joinPoint
|
* @param joinPoint
|
||||||
|
* @important 메소드의 매개변수 VO의 필드명이 다르면 수정 필요
|
||||||
|
* - mberId
|
||||||
|
* - accessKey
|
||||||
*/
|
*/
|
||||||
@Before(value = "execution(* com.itn.mjonApi.mjon.api.send.service.impl.SendServiceImpl.sendMsgData(..))" )
|
@Before(value = "execution(* com.itn.mjonApi.mjon.api.*..*Impl.*(..))" )
|
||||||
public void before(JoinPoint joinPoint){
|
// @Before(value = "execution(* com.itn.mjonApi.mjon.api.send.service.impl.SendServiceImpl.*(..))" )
|
||||||
log.info(" :: SendAspect before :: ");
|
public void before(JoinPoint joinPoint) throws IllegalAccessException {
|
||||||
|
log.info(" :: AOP before :: ");
|
||||||
|
|
||||||
// HttpServletRequest 객체를 가져옴
|
|
||||||
HttpServletRequest request = this.getHttpServletRequest();
|
HttpServletRequest request = this.getHttpServletRequest();
|
||||||
|
|
||||||
//메서드에 들어가는 매개변수 배열을 읽어옴
|
// VO 객체를 가져옴
|
||||||
Object[] args = joinPoint.getArgs();
|
Object objectVO = joinPoint.getArgs()[0];
|
||||||
|
|
||||||
MsgRequestVO msgRequestVO = (MsgRequestVO) args[0];
|
|
||||||
|
|
||||||
|
// VO 객체의 필드값을 가져옴
|
||||||
|
// 각각 메소드들의 매개변수VO가 다름으로
|
||||||
|
// 필드명으로 구분하여 값을 가져옴
|
||||||
|
String mberId = "";
|
||||||
|
String accessKey = "";
|
||||||
|
for(Field field : objectVO.getClass().getDeclaredFields()){
|
||||||
|
field.setAccessible(true);
|
||||||
|
if("mberId".equals(field.getName())){ mberId=field.get(objectVO).toString(); }
|
||||||
|
if("accessKey".equals(field.getName())){ accessKey=field.get(objectVO).toString(); }
|
||||||
|
}
|
||||||
|
|
||||||
String nextStringId = idgenApiAccessLogId.getNextStringId();
|
String nextStringId = idgenApiAccessLogId.getNextStringId();
|
||||||
LettnAccessLogVO lettnAccessLogVO = new LettnAccessLogVO()
|
LettnAccessLogVO lettnAccessLogVO = new LettnAccessLogVO()
|
||||||
.builder()
|
.builder()
|
||||||
.logId(nextStringId)
|
.logId(nextStringId)
|
||||||
.accessType("K") // key : K , token : T // TODO accessType 구분추가
|
.accessType("K") // key : K , token : T // TODO accessType 구분추가
|
||||||
.accessKey(msgRequestVO.getAccessKey())
|
.accessKey(accessKey)
|
||||||
.reqUserId(msgRequestVO.getMberId())
|
.reqUserId(mberId)
|
||||||
.reqCn("문자 전송")
|
.reqCn(joinPoint.toString())
|
||||||
.reqInfoRef(request.getHeader("Referer"))
|
.reqInfoRef(request.getHeader("Referer"))
|
||||||
.reqUrl(request.getRequestURI())
|
.reqUrl(request.getRequestURI())
|
||||||
.build();
|
.build();
|
||||||
@ -80,6 +90,7 @@ public class SendAspect {
|
|||||||
|
|
||||||
// setAttribute logId값 저장 -> @AfterReturning에서 사용하기 위함
|
// setAttribute logId값 저장 -> @AfterReturning에서 사용하기 위함
|
||||||
request.setAttribute("logId", nextStringId);
|
request.setAttribute("logId", nextStringId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -90,7 +101,7 @@ public class SendAspect {
|
|||||||
* @param returnValue
|
* @param returnValue
|
||||||
* @throws JsonProcessingException
|
* @throws JsonProcessingException
|
||||||
*/
|
*/
|
||||||
@AfterReturning(pointcut = "execution(* com.itn.mjonApi.mjon.api.send.service.impl.SendServiceImpl.*(..))", returning = "returnValue")
|
@AfterReturning(pointcut = "execution(* com.itn.mjonApi.mjon.api.*..*Impl.*(..))", returning = "returnValue")
|
||||||
public void afterReturning(JoinPoint joinPoint, RestResponse returnValue) throws JsonProcessingException {
|
public void afterReturning(JoinPoint joinPoint, RestResponse returnValue) throws JsonProcessingException {
|
||||||
log.info(" :: AfterReturning :: ");
|
log.info(" :: AfterReturning :: ");
|
||||||
|
|
||||||
@ -102,8 +113,6 @@ public class SendAspect {
|
|||||||
|
|
||||||
RestResponse restResponse = (RestResponse) returnValue;
|
RestResponse restResponse = (RestResponse) returnValue;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// lettngnrlmber_access_log 응답값 Udpate
|
// lettngnrlmber_access_log 응답값 Udpate
|
||||||
LettnAccessLogVO lettnAccessLogVO = new LettnAccessLogVO()
|
LettnAccessLogVO lettnAccessLogVO = new LettnAccessLogVO()
|
||||||
.builder()
|
.builder()
|
||||||
@ -1,12 +1,16 @@
|
|||||||
package com.itn.mjonApi.cmn.msg;
|
package com.itn.mjonApi.cmn.msg;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
@Getter
|
@Getter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
public class RestResponse{
|
public class RestResponse{
|
||||||
|
|
||||||
private String resultCode = "0";
|
private String resultCode = "0";
|
||||||
|
|||||||
@ -62,6 +62,11 @@ public enum StatMsg {
|
|||||||
private static final List<StatMsg> VALUES = Collections.unmodifiableList(Arrays.asList(values()));
|
private static final List<StatMsg> VALUES = Collections.unmodifiableList(Arrays.asList(values()));
|
||||||
private static final int SIZE = VALUES.size();
|
private static final int SIZE = VALUES.size();
|
||||||
private static final Random RANDOM = new Random();
|
private static final Random RANDOM = new Random();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : 랜덤한 에러코드를 반환한다.
|
||||||
|
* @return errorCode
|
||||||
|
*/
|
||||||
public static String randomErrorStatCode() {
|
public static String randomErrorStatCode() {
|
||||||
String errorCode = "";
|
String errorCode = "";
|
||||||
while(true){
|
while(true){
|
||||||
|
|||||||
@ -54,6 +54,7 @@ public class SendServiceImpl implements SendService {
|
|||||||
|
|
||||||
//step1.발신자 전화번호 사용 가능 여부 체크(해당 사용자의 기 등록된 번호만 발송 가능)
|
//step1.발신자 전화번호 사용 가능 여부 체크(해당 사용자의 기 등록된 번호만 발송 가능)
|
||||||
// 1010
|
// 1010
|
||||||
|
msgRequestVO.setCallFrom(MunjaUtil.removeCharactersWithRegex(msgRequestVO.getCallFrom()));
|
||||||
if(!sendMapper.findByCallFrom(msgRequestVO)){
|
if(!sendMapper.findByCallFrom(msgRequestVO)){
|
||||||
return new RestResponse("STAT_1010");
|
return new RestResponse("STAT_1010");
|
||||||
}
|
}
|
||||||
@ -61,7 +62,7 @@ public class SendServiceImpl implements SendService {
|
|||||||
// step2.수신자 전화번호 정상 여부 체크(정상 번호에 대해서만 발송 가능)
|
// step2.수신자 전화번호 정상 여부 체크(정상 번호에 대해서만 발송 가능)
|
||||||
// 1020
|
// 1020
|
||||||
// 폰번호 확인 - 빈 값 -> 유효성 정규식
|
// 폰번호 확인 - 빈 값 -> 유효성 정규식
|
||||||
if(StringUtils.isNotEmpty(this.getCallToListChk(msgRequestVO))){
|
if(this.getCallToListChk(msgRequestVO)){
|
||||||
return new RestResponse("STAT_1020");
|
return new RestResponse("STAT_1020");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,17 +117,20 @@ public class SendServiceImpl implements SendService {
|
|||||||
|
|
||||||
private RestResponse _getTestReturnData(String testYn)
|
private RestResponse _getTestReturnData(String testYn)
|
||||||
{
|
{
|
||||||
|
// YF => 실패 테스트 데이터
|
||||||
if("YF".equals(testYn))
|
if("YF".equals(testYn))
|
||||||
{
|
{
|
||||||
|
// 실패 코드 중 랜덤으로 리턴
|
||||||
return new RestResponse(StatMsg.randomErrorStatCode());
|
return new RestResponse(StatMsg.randomErrorStatCode());
|
||||||
}else{
|
}else{
|
||||||
return new RestResponse(SendSuccessRestResponse.builder()
|
return new RestResponse(
|
||||||
.msgGroupId("MSGGID_0000000000000") // 전송 메세지 그룹 ID
|
SendSuccessRestResponse.builder()
|
||||||
.successCnt("5") // 성공 건수
|
.msgGroupId("MSGGID_0000000000000") // 전송 메세지 그룹 ID
|
||||||
.blockCnt("2") // 수신거부 건수
|
.successCnt("5") // 성공 건수
|
||||||
.msgType("LMS")
|
.blockCnt("2") // 수신거부 건수
|
||||||
.failCnt("0")
|
.msgType("LMS")
|
||||||
.build()
|
.failCnt("0")
|
||||||
|
.build()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,17 +139,12 @@ public class SendServiceImpl implements SendService {
|
|||||||
public RestResponse sendMsgsData(MsgsRequestVO msgsRequestVO) throws Exception {
|
public RestResponse sendMsgsData(MsgsRequestVO msgsRequestVO) throws Exception {
|
||||||
|
|
||||||
if(StringUtils.isNotEmpty(msgsRequestVO.getTest_yn())){
|
if(StringUtils.isNotEmpty(msgsRequestVO.getTest_yn())){
|
||||||
// YF => 실패 테스트 데이터
|
|
||||||
return this._getTestReturnData(msgsRequestVO.getTest_yn());
|
return this._getTestReturnData(msgsRequestVO.getTest_yn());
|
||||||
}
|
}
|
||||||
// msgsVO -> msgVO List로 변환
|
// msgsVO -> msgVO List로 변환
|
||||||
List<MsgRequestVO> msgRequestVOList = this.getDataCleaning(msgsRequestVO);
|
List<MsgRequestVO> msgRequestVOList = this.getDataCleaning(msgsRequestVO);
|
||||||
|
|
||||||
msgRequestVOList.forEach(msgRequestVO -> {
|
|
||||||
log.info("msgRequestVO getCallToList() :: [{}]", msgRequestVO.getCallToList());
|
|
||||||
log.info("msgRequestVO getSmsTxt() :: [{}]", msgRequestVO.getSmsTxt());
|
|
||||||
log.info("======================");
|
|
||||||
});
|
|
||||||
//step1.발신자 전화번호 사용 가능 여부 체크(해당 사용자의 기 등록된 번호만 발송 가능)
|
//step1.발신자 전화번호 사용 가능 여부 체크(해당 사용자의 기 등록된 번호만 발송 가능)
|
||||||
// 1010
|
// 1010
|
||||||
if(!sendMapper.findByCallFrom(msgRequestVOList.get(0))){
|
if(!sendMapper.findByCallFrom(msgRequestVOList.get(0))){
|
||||||
@ -153,12 +152,13 @@ public class SendServiceImpl implements SendService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//step2.수신자 전화번호 정상 여부 체크(정상 번호에 대해서만 발송 가능)
|
// step2.수신자 전화번호 정상 여부 체크(정상 번호에 대해서만 발송 가능)
|
||||||
// 1020
|
// 1020
|
||||||
// 폰번호 확인 - 빈 값 -> 유효성 정규식
|
// 폰번호 확인 - 빈 값 -> 유효성 정규식
|
||||||
for(MsgRequestVO msgRequestVO : msgRequestVOList){
|
for(MsgRequestVO msgRequestVO : msgRequestVOList){
|
||||||
if(StringUtils.isNotEmpty(this.getCallToListChk(msgRequestVO))){
|
if(this.getCallToListChk(msgRequestVO)){
|
||||||
return callToErrorReturnData(msgRequestVO);
|
// if(StringUtils.isNotEmpty(this.getCallToListChk(msgRequestVO))){
|
||||||
|
return this.callToErrorReturnData(msgRequestVO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -442,18 +442,29 @@ public class SendServiceImpl implements SendService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 수신자 목록 번호 검증
|
* 수신자 목록 번호 검증
|
||||||
|
* message가 없으면 정상
|
||||||
* @param msgRequestVO
|
* @param msgRequestVO
|
||||||
* @return
|
* @return String
|
||||||
*/
|
*/
|
||||||
private static String getCallToListChk(MsgRequestVO msgRequestVO) {
|
private static Boolean getCallToListChk(MsgRequestVO msgRequestVO) {
|
||||||
String message = "";
|
Boolean returnData = false;
|
||||||
for(String callTo : msgRequestVO.getCallToList()){
|
for(String callTo : msgRequestVO.getCallToList()){
|
||||||
|
/*
|
||||||
if(!MunjaUtil.checkPhoneNumberEmpty(callTo)){
|
if(!MunjaUtil.checkPhoneNumberEmpty(callTo)){
|
||||||
message = "수신 목록에 핸드폰 번호가 없는 항목이 있습니다."; break;};
|
message = "수신 목록에 핸드폰 번호가 없는 항목이 있습니다."; break;};
|
||||||
if(!MunjaUtil.validatePNumWithRegex(callTo)){
|
if(!MunjaUtil.validatePNumWithRegex(callTo)){
|
||||||
message = "휴대폰 번호가 올바르지 않습니다. : " + callTo; break;};
|
message = "휴대폰 번호가 올바르지 않습니다. : " + callTo; break;};
|
||||||
|
*/
|
||||||
|
if(!MunjaUtil.validatePNumWithRegex(callTo) // 비여있는지 체크
|
||||||
|
|| !MunjaUtil.validatePNumWithRegex(callTo) // 정규식으로 번호 체크
|
||||||
|
)
|
||||||
|
{
|
||||||
|
returnData = true;
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
return message;
|
return returnData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -39,6 +39,9 @@ public class MunjaUtil {
|
|||||||
public static String replaceCommaToStrSymbol(String name) {
|
public static String replaceCommaToStrSymbol(String name) {
|
||||||
return name.replaceAll(",", "§");
|
return name.replaceAll(",", "§");
|
||||||
}
|
}
|
||||||
|
public static String removeCharactersWithRegex(String str) {
|
||||||
|
return str.replaceAll("[^0-9]", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user