From 65fe0128fbbd1e707cc66b1e4c33d4dbdf18e798 Mon Sep 17 00:00:00 2001 From: hylee Date: Fri, 2 Jun 2023 11:48:22 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20pms=20[#3176]=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 7 +++ .../com/itn/mjonApi/cmn/aop/LogAspect.java | 59 +++++++++++++++++-- .../send/service/impl/SendServiceImpl.java | 11 ++++ 3 files changed, 73 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 05a9236..c59a9ae 100644 --- a/pom.xml +++ b/pom.xml @@ -128,6 +128,13 @@ 16.0.1 compile + + + + org.springframework.boot + spring-boot-starter-validation + + diff --git a/src/main/java/com/itn/mjonApi/cmn/aop/LogAspect.java b/src/main/java/com/itn/mjonApi/cmn/aop/LogAspect.java index f1de3a3..d5de758 100644 --- a/src/main/java/com/itn/mjonApi/cmn/aop/LogAspect.java +++ b/src/main/java/com/itn/mjonApi/cmn/aop/LogAspect.java @@ -20,6 +20,8 @@ import org.springframework.web.context.request.ServletRequestAttributes; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.Map; /** * packageName : com.itn.mjonApi.cmn.aop @@ -96,34 +98,83 @@ public class LogAspect { /** * @description 메소드 종료 후 return 값에 따른 로그 처리 - * - 매개변수 RestResponse는 메소드의 return 값과 일치해야 함 * @param joinPoint * @param returnValue * @throws JsonProcessingException + * @important 메소드의 매개변수 RestResponse는 메소드의 return 값과 일치해야 함 */ @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, Object returnValue) throws Exception { log.info(" :: AfterReturning :: "); String resutlCode = ""; // HttpServletRequest 객체를 가져옴 HttpServletRequest request = this.getHttpServletRequest(); + // @Befer에서 저장한 logId를 가져옴 String logId = (String) request.getAttribute("logId"); - RestResponse restResponse = (RestResponse) returnValue; // lettngnrlmber_access_log 응답값 Udpate LettnAccessLogVO lettnAccessLogVO = new LettnAccessLogVO() .builder() .logId(logId) - .resCn(this.getJsonToString(restResponse)) + .resCn(this.mapToJson(this.getStringObjectMap(returnValue))) .resCode(resutlCode) .build(); lettnAccessLogMapper.update(lettnAccessLogVO); } + private Map getStringObjectMap(Object returnValue) throws IllegalAccessException { + Map returnMap = new HashMap(); + Map dataMap = new HashMap(); + String val = ""; + + +// for(Field field : returnValue.getClass().getDeclaredFields()){ +// field.setAccessible(true); +// +// if("data".equals(field.getName())) +// { +// Object dataObj = field.get(returnValue); +// for(Field dataF : dataObj.getClass().getDeclaredFields()){ +// dataF.setAccessible(true); +// log.info("dataF.getName() :: [{}]", dataF.getName()); +// log.info("dataF.get(dataObj) :: [{}]", dataF.get(dataObj)); +// dataMap.put(dataF.getName(), this.getValChk(dataF.get(dataObj))); +// } +// +// returnMap.put(field.getName(), dataMap); +// continue; +// +// } +// //field.get(returnValue) null check +// returnMap.put(field.getName(), this.getValChk(field.get(returnValue))); +// } + return returnMap; + } + + /** + * @description : field.get(returnValue) null check + * null 이면 nullPointException 발생 + * @param returnValue + * @return + * @throws IllegalAccessException + */ + private static String getValChk(Object returnValue) { + String val; + if(returnValue == null) val = ""; + else val = returnValue.toString(); + return val; + } + + public String mapToJson(Map map) throws Exception + { + ObjectMapper mapper = new ObjectMapper(); + return mapper.writeValueAsString(map); + } + /** * @description : VO를 json으로 변환 * @param restResponse diff --git a/src/main/java/com/itn/mjonApi/mjon/api/send/service/impl/SendServiceImpl.java b/src/main/java/com/itn/mjonApi/mjon/api/send/service/impl/SendServiceImpl.java index a8048e1..d51e0ae 100644 --- a/src/main/java/com/itn/mjonApi/mjon/api/send/service/impl/SendServiceImpl.java +++ b/src/main/java/com/itn/mjonApi/mjon/api/send/service/impl/SendServiceImpl.java @@ -264,6 +264,17 @@ public class SendServiceImpl implements SendService { .callFrom(callFrom) .callToList(new String[]{callTo}) .smsTxt(value.toString()) + .eachPrice("0") // 디폴트 + .sPrice("0") // 디폴트 + .totPrice("0") // 디폴트 + .fileCnt("0") // 디폴트 + .msgType("4") // 디폴트 + .smsPrice(0) // 디폴트 + .mmsPrice(0) // 디폴트 + .imgFilePath(new String[0]) // 디폴트 + .txtReplYn("N") // 디폴트 + .reserveYn("N") // 디폴트 + .msgKind("N") // 디폴트 .build() ); // 초기화