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