Merge branch 'hylee'
This commit is contained in:
commit
029715266b
6
pom.xml
6
pom.xml
@ -111,6 +111,12 @@
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.12.0</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-jsr310 -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@ -1,13 +1,27 @@
|
||||
package com.itn.mjonApi.cmn.aop;
|
||||
|
||||
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.msg.FailRestResponse;
|
||||
import com.itn.mjonApi.cmn.msg.RestResponse;
|
||||
import com.itn.mjonApi.cmn.msg.SendSuccessRestResponse;
|
||||
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;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.AfterReturning;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* packageName : com.itn.mjonApi.cmn.aop
|
||||
@ -24,34 +38,115 @@ import org.springframework.stereotype.Component;
|
||||
@Aspect
|
||||
@Component
|
||||
public class SendAspect {
|
||||
// @Autowired
|
||||
// private LettnAccessLogService lettnAccessLogService;
|
||||
|
||||
@Autowired
|
||||
LettnAccessLogMapper lettnAccessLogMapper;
|
||||
@Resource(name = "apiAccessLog")
|
||||
private IdgenService idgenApiAccessLogId;
|
||||
|
||||
/**
|
||||
* @description SendServiceImpl.sendMsgData 메소드 실행 전 로그 처리
|
||||
* - 대량문자와 개별문자의 파마리터 VO가 다르므로 메소드로 분기 처리하기위함
|
||||
* @param joinPoint
|
||||
*/
|
||||
@Before(value = "execution(* com.itn.mjonApi.mjon.api.send.service.impl.SendServiceImpl.sendMsgData(..))" )
|
||||
public void before(JoinPoint joinPoint){
|
||||
log.info(" :: SendAspect before :: ");
|
||||
|
||||
// HttpServletRequest 객체를 가져옴
|
||||
HttpServletRequest request = this.getHttpServletRequest();
|
||||
|
||||
//메서드에 들어가는 매개변수 배열을 읽어옴
|
||||
Object[] args = joinPoint.getArgs();
|
||||
log.info("args[0] : [{}]", args[0]);
|
||||
|
||||
MsgRequestVO msgRequestVO = (MsgRequestVO) args[0];
|
||||
|
||||
log.info("msgRequestVO : [{}]", msgRequestVO.getSmsTxt());
|
||||
|
||||
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("문자 전송")
|
||||
.reqInfoRef(request.getHeader("Referer"))
|
||||
.reqUrl(request.getRequestURI())
|
||||
.build();
|
||||
if (lettnAccessLogVO.getReqUrl().length() > 200) { //길이문제로 오류가 발생하는 경우도 처리하도록 수정
|
||||
lettnAccessLogVO.setReqUrl(lettnAccessLogVO.getReqUrl().substring(0, 199));
|
||||
}
|
||||
lettnAccessLogMapper.insert(lettnAccessLogVO);
|
||||
|
||||
// setAttribute logId값 저장 -> @AfterReturning에서 사용하기 위함
|
||||
request.setAttribute("logId", nextStringId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@AfterReturning(pointcut = "execution(* com.itn.mjonApi.mjon.api.send.service.impl.SendServiceImpl.sendMsgData(..))", returning = "returnValue")
|
||||
public void afterReturning(JoinPoint joinPoint, ResponseEntity<?> returnValue){
|
||||
/**
|
||||
* @description 메소드 종료 후 return 값에 따른 로그 처리
|
||||
* - 매개변수 RestResponse는 메소드의 return 값과 일치해야 함
|
||||
* @param joinPoint
|
||||
* @param returnValue
|
||||
* @throws JsonProcessingException
|
||||
*/
|
||||
@AfterReturning(pointcut = "execution(* com.itn.mjonApi.mjon.api.send.service.impl.SendServiceImpl.*(..))", returning = "returnValue")
|
||||
public void afterReturning(JoinPoint joinPoint, RestResponse returnValue) throws JsonProcessingException {
|
||||
log.info(" :: AfterReturning :: ");
|
||||
|
||||
String bodyClassName = returnValue.getBody().toString();
|
||||
String resutlCode = "";
|
||||
// HttpServletRequest 객체를 가져옴
|
||||
HttpServletRequest request = this.getHttpServletRequest();
|
||||
// @Befer에서 저장한 logId를 가져옴
|
||||
String logId = (String) request.getAttribute("logId");
|
||||
|
||||
log.info("bodyClassName : [{}]", bodyClassName);
|
||||
// body에 담긴 calss가 SendSuccessRestResponse이면
|
||||
if(bodyClassName.indexOf("SendSuccessRestResponse") > -1){
|
||||
RestResponse restResponse = (RestResponse) returnValue;
|
||||
|
||||
// TODO :: 성공 실패에 따른 로그 처리 예정
|
||||
if(restResponse.getObject().toString().indexOf("SendSuccessRestResponse") > -1){
|
||||
log.info(" :: SendSuccessRestResponse :: ");
|
||||
|
||||
SendSuccessRestResponse sendSuccessRestResponse = (SendSuccessRestResponse) restResponse.getObject();
|
||||
resutlCode = sendSuccessRestResponse.getResultCode();
|
||||
}else{
|
||||
log.info(" :: SendFailRestResponse :: ");
|
||||
|
||||
FailRestResponse failRestResponse = (FailRestResponse) restResponse.getObject();
|
||||
resutlCode = failRestResponse.getResultCode();
|
||||
}
|
||||
|
||||
// lettngnrlmber_access_log 응답값 Udpate
|
||||
LettnAccessLogVO lettnAccessLogVO = new LettnAccessLogVO()
|
||||
.builder()
|
||||
.logId(logId)
|
||||
.resCn(this.getJsonToString(restResponse))
|
||||
.resCode(resutlCode)
|
||||
.build();
|
||||
lettnAccessLogMapper.update(lettnAccessLogVO);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @description : VO를 json으로 변환
|
||||
* @param restResponse
|
||||
* @return String
|
||||
* @throws JsonProcessingException
|
||||
*/
|
||||
private static String getJsonToString(RestResponse restResponse) throws JsonProcessingException {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
// .registerModule(new JavaTimeModule()) : LocalDateTime을 json으로 변환하기 위함
|
||||
return objectMapper.registerModule(new JavaTimeModule()).writeValueAsString(restResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : HttpServletRequest 객체를 가져옴
|
||||
* @return
|
||||
*/
|
||||
private static HttpServletRequest getHttpServletRequest() {
|
||||
HttpServletRequest request = // 5
|
||||
((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
|
||||
return request;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
package com.itn.mjonApi.cmn.msg;
|
||||
|
||||
import com.itn.mjonApi.mjon.api.send.mapper.domain.MjonResponseVO;
|
||||
import lombok.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@ -16,7 +17,6 @@ public class FailRestResponse {
|
||||
|
||||
private String message;
|
||||
|
||||
private LocalDateTime localDateTime;
|
||||
|
||||
/*
|
||||
* 200-OK : 정상접속
|
||||
@ -29,7 +29,6 @@ public class FailRestResponse {
|
||||
FailRestResponse sendFailResponse = new FailRestResponse();
|
||||
sendFailResponse.setResultCode(StatMsg.valueOf(resultCode).getCode());
|
||||
sendFailResponse.setMessage(StatMsg.valueOf(resultCode).getMsg());
|
||||
sendFailResponse.setLocalDateTime(LocalDateTime.now());
|
||||
|
||||
return sendFailResponse;
|
||||
}
|
||||
|
||||
@ -26,6 +26,7 @@ public class RestResponse{
|
||||
* */
|
||||
|
||||
public RestResponse(HttpStatus status, String message, LocalDateTime timestamp) {
|
||||
|
||||
this.resultCode = status.value();
|
||||
checkMessage(status, message);
|
||||
this.localDateTime = timestamp;
|
||||
|
||||
@ -47,7 +47,7 @@ public class SendSuccessRestResponse {
|
||||
*/
|
||||
public static SendSuccessRestResponse convertMjonDataToApiResponse(MjonResponseVO mjonResponseVO) {
|
||||
|
||||
String enumStr = "STAT_200";
|
||||
String enumStr = "STAT_0";
|
||||
|
||||
return SendSuccessRestResponse.builder()
|
||||
.resultCode(StatMsg.valueOf(enumStr).getCode()) // 성공 코드 200 - StatMsg 참고
|
||||
|
||||
@ -26,7 +26,7 @@ import lombok.Getter;
|
||||
@Getter
|
||||
public enum StatMsg {
|
||||
// 문자보내기 ======================================================================
|
||||
STAT_200("200","")
|
||||
STAT_0("0","")
|
||||
, STAT_1010("1010","발신자 전화번호 사용 불가")
|
||||
, STAT_1020("1020","수신자 전화번호 오류")
|
||||
, STAT_1030("1030","문자 내용 발송 불가")
|
||||
|
||||
@ -31,9 +31,6 @@ public class MjonResponseVO {
|
||||
private String afterCash;
|
||||
private String msgType;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param stringResponseEntity
|
||||
|
||||
@ -116,6 +116,7 @@ public class MsgRequestVO implements Serializable {
|
||||
private String msgKind="N"; // '문자 종류 일반:N, 광고:A, 선거:C',
|
||||
|
||||
|
||||
|
||||
// private String msgId ;// '문자ID',
|
||||
// private String userId ; // '문자온 일반회원ID',
|
||||
// private String agentFlag ;//'전송사코드(1:아이하트,2:...)',
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.itn.mjonApi.mjon.api.send.service;
|
||||
|
||||
import com.itn.mjonApi.cmn.msg.RestResponse;
|
||||
import com.itn.mjonApi.mjon.api.send.mapper.domain.MsgRequestVO;
|
||||
import com.itn.mjonApi.mjon.api.send.mapper.domain.MsgsRequestVO;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@ -7,7 +8,7 @@ import org.springframework.http.ResponseEntity;
|
||||
public interface SendService {
|
||||
|
||||
|
||||
ResponseEntity<?> sendMsgData(MsgRequestVO msgRequestVO) throws Exception;
|
||||
RestResponse sendMsgData(MsgRequestVO msgRequestVO) throws Exception;
|
||||
|
||||
ResponseEntity<?> sendMsgsData(MsgsRequestVO msgsRequestVO) throws Exception;
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package com.itn.mjonApi.mjon.api.send.service.impl;
|
||||
|
||||
import com.itn.mjonApi.cmn.apiServer.ApiService;
|
||||
import com.itn.mjonApi.cmn.msg.FailRestResponse;
|
||||
import com.itn.mjonApi.cmn.msg.RestResponse;
|
||||
import com.itn.mjonApi.cmn.msg.SendSuccessRestResponse;
|
||||
import com.itn.mjonApi.mjon.api.send.mapper.SendMapper;
|
||||
import com.itn.mjonApi.mjon.api.send.mapper.domain.MjonResponseVO;
|
||||
@ -13,11 +14,13 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.catalina.connector.Response;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@ -40,22 +43,21 @@ public class SendServiceImpl implements SendService {
|
||||
private static final String replaseStrList = "[*이름*],[*1*],[*2*],[*3*],[*4*]";
|
||||
|
||||
@Override
|
||||
public ResponseEntity<?> sendMsgData(MsgRequestVO msgRequestVO) throws Exception {
|
||||
public RestResponse sendMsgData(MsgRequestVO msgRequestVO) throws Exception {
|
||||
|
||||
//sendMsg 문자 발송 전 체크 사항
|
||||
log.info(" :: sendMsgData ::");
|
||||
|
||||
//step1.발신자 전화번호 사용 가능 여부 체크(해당 사용자의 기 등록된 번호만 발송 가능)
|
||||
// 1010
|
||||
if(!sendMapper.findByCallFrom(msgRequestVO)){
|
||||
return ResponseEntity.ok().body(_falseRetunDate("STAT_1010"));
|
||||
return new RestResponse(HttpStatus.OK,"", LocalDateTime.now(), _falseRetunDate("STAT_1010"));
|
||||
}
|
||||
|
||||
//step2.수신자 전화번호 정상 여부 체크(정상 번호에 대해서만 발송 가능)
|
||||
// 1020
|
||||
// 폰번호 확인 - 빈 값 -> 유효성 정규식
|
||||
if(StringUtils.isNotEmpty(this.getCallToListChk(msgRequestVO))){
|
||||
return ResponseEntity.ok().body(_falseRetunDate("STAT_1020"));
|
||||
return new RestResponse(HttpStatus.OK,"", LocalDateTime.now(), _falseRetunDate("STAT_1020"));
|
||||
}
|
||||
|
||||
//step3.문자 내용 정상 여부 확인 - 스미싱 문구는 발송 30분 지연으로 처리됨
|
||||
@ -99,7 +101,6 @@ public class SendServiceImpl implements SendService {
|
||||
msgRequestVO = getLengthOfShortAndLongMsg(msgRequestVO);
|
||||
}
|
||||
|
||||
/*
|
||||
// 문자 전송하는 부분
|
||||
// apiService.postForEntity => restTemplate.postForEntity 호출 후 MjonResponseVO에 맞게 데이터 정제하는 메소드
|
||||
MjonResponseVO munjaSendResponse = apiService.postForEntity(
|
||||
@ -111,15 +112,11 @@ public class SendServiceImpl implements SendService {
|
||||
|
||||
// convertMjonDataToApiResponse => MjonResponseVO 데이터를 ApiResponse 데이터로 변환하는 메소드
|
||||
if(munjaSendResponse.getResult() != "fail"){ // 성공
|
||||
return ResponseEntity.ok().body(SendSuccessRestResponse.convertMjonDataToApiResponse(munjaSendResponse));
|
||||
return new RestResponse(HttpStatus.OK, "", LocalDateTime.now(), SendSuccessRestResponse.convertMjonDataToApiResponse(munjaSendResponse));
|
||||
}else{ // 실패
|
||||
return ResponseEntity.ok().body(FailRestResponse.convertMjonDataToApiResponse(munjaSendResponse));
|
||||
return new RestResponse(HttpStatus.OK, "", LocalDateTime.now(), FailRestResponse.convertMjonDataToApiResponse(munjaSendResponse));
|
||||
}
|
||||
*/
|
||||
SendSuccessRestResponse sendSuccessRestResponse = new SendSuccessRestResponse();
|
||||
sendSuccessRestResponse.setMsgGroupId("1234567890");
|
||||
return ResponseEntity.ok().body(sendSuccessRestResponse);
|
||||
// return ResponseEntity.ok().body(new RestResponse(sendSuccessRestResponse));
|
||||
|
||||
//step5.발송일시 정상여부 확인
|
||||
// 1050
|
||||
//step6.문자 타입에 따른 비용 처리 가능 여부 확인
|
||||
@ -186,7 +183,11 @@ public class SendServiceImpl implements SendService {
|
||||
}
|
||||
|
||||
|
||||
return ResponseEntity.ok().body(SendSuccessRestResponse.SendSuccessMsgsRestResponse(mjonResponseVOList));
|
||||
return ResponseEntity.ok().body(new RestResponse(HttpStatus.OK
|
||||
, ""
|
||||
, LocalDateTime.now()
|
||||
, SendSuccessRestResponse.SendSuccessMsgsRestResponse(mjonResponseVOList))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.itn.mjonApi.mjon.api.send.web;
|
||||
|
||||
import com.itn.mjonApi.cmn.msg.RestResponse;
|
||||
import com.itn.mjonApi.mjon.api.send.mapper.domain.MsgRequestVO;
|
||||
import com.itn.mjonApi.mjon.api.send.mapper.domain.MsgsRequestVO;
|
||||
import com.itn.mjonApi.mjon.api.send.service.SendService;
|
||||
@ -49,8 +50,8 @@ public class SendRestController {
|
||||
@CrossOrigin("*") // 모든 요청에 접근 허용
|
||||
@PostMapping("/api/send/sendMsg")
|
||||
@ApiOperation(value= "단문 문자 전송", notes = "같은 내용으로 여러명에게 보냄")
|
||||
public ResponseEntity<?> sendMsg(MsgRequestVO msgRequestVO) throws Exception {
|
||||
return sendService.sendMsgData(msgRequestVO);
|
||||
public ResponseEntity<RestResponse> sendMsg(MsgRequestVO msgRequestVO) throws Exception {
|
||||
return ResponseEntity.ok().body(sendService.sendMsgData(msgRequestVO));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
package com.itn.mjonApi.mjon.log.service;
|
||||
|
||||
import com.itn.mjonApi.cmn.msg.RestResponse;
|
||||
import com.itn.mjonApi.mjon.log.service.mapper.domain.LettnAccessLogVO;
|
||||
|
||||
public interface LettnAccessLogService {
|
||||
|
||||
//기본 insert 구문
|
||||
RestResponse insert(LettnAccessLogVO lettnAccessLogVO);
|
||||
void insert(LettnAccessLogVO lettnAccessLogVO);
|
||||
|
||||
}
|
||||
|
||||
@ -1,15 +1,11 @@
|
||||
package com.itn.mjonApi.mjon.log.service.impl;
|
||||
|
||||
import com.itn.mjonApi.cmn.msg.RestResponse;
|
||||
import com.itn.mjonApi.mjon.log.service.LettnAccessLogService;
|
||||
import com.itn.mjonApi.mjon.log.service.mapper.LettnAccessLogMapper;
|
||||
import com.itn.mjonApi.mjon.log.service.mapper.domain.LettnAccessLogVO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Service
|
||||
public class LettnAccessLogServiceImpl implements LettnAccessLogService {
|
||||
|
||||
@ -19,8 +15,7 @@ public class LettnAccessLogServiceImpl implements LettnAccessLogService {
|
||||
|
||||
|
||||
@Override
|
||||
public RestResponse insert(LettnAccessLogVO lettnAccessLogVO) {
|
||||
int i_ret = lettnAccessLogMapper.insert(lettnAccessLogVO);
|
||||
return new RestResponse(HttpStatus.OK, "성공", LocalDateTime.now());
|
||||
public void insert(LettnAccessLogVO lettnAccessLogVO) {
|
||||
lettnAccessLogMapper.insert(lettnAccessLogVO);
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
@Mapper
|
||||
public interface LettnAccessLogMapper {
|
||||
|
||||
int insert(LettnAccessLogVO lettnAccessLogVO);
|
||||
void insert(LettnAccessLogVO lettnAccessLogVO);
|
||||
|
||||
void update(LettnAccessLogVO lettnAccessLogVO);
|
||||
}
|
||||
|
||||
@ -31,20 +31,9 @@
|
||||
<!-- 수정용 공통 컬럼 명 -->
|
||||
<sql id="update_column_name">
|
||||
|
||||
LOG_ID
|
||||
, ACCESS_TYPE
|
||||
, ACCESS_KEY
|
||||
, ACCESS_TOKEN
|
||||
, REQ_USER_ID
|
||||
, REQ_CN
|
||||
, REQ_INFO_REF
|
||||
, REQ_URL
|
||||
, RES_CN
|
||||
, RES_CODE
|
||||
, REQ_REGIST_PNTTM
|
||||
, REQ_REGISTER_ID
|
||||
, RES_UPDT_PNTTM
|
||||
, RES_UPDUSR_ID
|
||||
RES_CN = #{resCn }
|
||||
, RES_CODE = #{resCode }
|
||||
, RES_UPDT_PNTTM = now()
|
||||
|
||||
</sql>
|
||||
|
||||
@ -70,4 +59,13 @@
|
||||
|
||||
</insert>
|
||||
|
||||
<!-- access_log 정보 등록 -->
|
||||
<update id="update">
|
||||
UPDATE <include refid="table_name"/>
|
||||
SET
|
||||
<include refid="update_column_name"/>
|
||||
WHERE log_id = #{logId }
|
||||
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue
Block a user