Merge branch 'master' of

http://yongjoon.cho@vcs.iten.co.kr:9999/hylee/mjon_api
This commit is contained in:
myname 2023-05-22 12:30:16 +09:00
commit 6247288f90
8 changed files with 149 additions and 80 deletions

View File

@ -2,7 +2,6 @@ package com.itn.mjonApi.cmn.apiServer;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.itn.mjonApi.mjon.api.send.mapper.domain.MjonResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
@ -13,6 +12,7 @@ import org.springframework.web.client.RestTemplate;
* author : hylee
* date : 2023-05-15
* description : API 서버 호출 Service - 호출 데이터 정제 까지 구현
* 필요한 데이터 정제가 있으면 추가 수정 해야
* ===========================================================
* DATE AUTHOR NOTE
* -----------------------------------------------------------
@ -21,23 +21,28 @@ import org.springframework.web.client.RestTemplate;
@Service
public class ApiService <T> {
// RestTemplateConfig.class의 셋팅값으로 생성
private RestTemplate restTemplate;
@Autowired
public ApiService(RestTemplate restTemplate) {
this.restTemplate = restTemplate;
}
/**
*
* @param url
* @param request
* @param responseType
* @discription restTemplate.postForEntity 호출 MjonResponseVO에 맞게 데이터 정제
* @return MjonResponseVO.class
* @throws JsonProcessingException
*/
public MjonResponseVO postForEntity(String url, Object request, Class<String> responseType) throws JsonProcessingException {
ResponseEntity<String> spamChkEntity = (ResponseEntity<String>) restTemplate.postForEntity(
url
, request
, responseType
);
MjonResponseVO spamResponse = MjonResponseVO.getMjonResponse(spamChkEntity);
return spamResponse;
}

View File

@ -1,7 +1,6 @@
package com.itn.mjonApi.cmn.msg;
import lombok.Getter;
import lombok.Setter;
import lombok.*;
import org.springframework.http.HttpStatus;
import java.time.LocalDateTime;
@ -9,7 +8,7 @@ import java.util.List;
@Setter
@Getter
public class RestResponse {
public class RestResponse{
//private HttpStatus status;
private int resultCode;

View File

@ -0,0 +1,34 @@
package com.itn.mjonApi.cmn.msg;
import lombok.*;
import java.time.LocalDateTime;
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class SendRestResponse {
//private HttpStatus status;
private String resultCode;
private String message;
private LocalDateTime localDateTime;
/*
* 200-OK : 정상접속
* 401-Unauthorized : 인증실패
*
* */
@Builder
public SendRestResponse(String resultStr) {
this.resultCode = StatMsg.valueOf(resultStr).getCode();
this.message = StatMsg.valueOf(resultStr).getMsg();
this.localDateTime = LocalDateTime.now();
}
}

View File

@ -0,0 +1,40 @@
package com.itn.mjonApi.cmn.msg;
import lombok.Getter;
/**
* packageName : com.itn.mjonApi.cmn.msg
* fileName : statMsg
* author : hylee
* date : 2023-05-19
* description :
* ===========================================================
* DATE AUTHOR NOTE
* -----------------------------------------------------------
* 2023-05-19 hylee 최초 생성
*/
/**
* 사용 예시
*
* StatMsg.valueOf("STAT1010") :: STAT1010
* StatMsg.valueOf("STAT1010").getCode() :: 1010
* StatMsg.valueOf("STAT1010").getMsg() :: 발신자 전화번호 사용 불가
*/
@Getter
public enum StatMsg {
STAT1010("1010","발신자 전화번호 사용 불가")
,STAT1020("1020","수신자 전화번호 오류")
;
private final String code;
private final String msg;
StatMsg(String code, String msg) {
this.code = code;
this.msg = msg;
}
}

View File

@ -51,6 +51,7 @@ public class MsgRequestVO implements Serializable {
@ApiModelProperty(value = "전송문자 개별가격", example = "0", hidden = true)
private String eachPrice="0";
private String sPrice="0"; // 임시
@ApiModelProperty(value = "전송문자 토탈가격", example = "0", hidden = true)
private String totPrice="0";
@ -93,15 +94,15 @@ public class MsgRequestVO implements Serializable {
private String rep4Str;
@ApiModelProperty(value = "nameStr 을 |로 split 후 담는 변수", example = "", hidden = true)
private String[] nameList;
private String[] nameList= new String[0];;
@ApiModelProperty(value = "rep1Str 을 |로 split 후 담는 변수", example = "", hidden = true)
private String[] rep1List;
private String[] rep1List= new String[0];;
@ApiModelProperty(value = "rep2Str 을 |로 split 후 담는 변수", example = "", hidden = true)
private String[] rep2List;
private String[] rep2List= new String[0];;
@ApiModelProperty(value = "rep3Str 을 |로 split 후 담는 변수", example = "", hidden = true)
private String[] rep3List;
private String[] rep3List= new String[0];;
@ApiModelProperty(value = "rep4Str 을 |로 split 후 담는 변수", example = "", hidden = true)
private String[] rep4List;
private String[] rep4List= new String[0];;
@ApiModelProperty(value = "예약 유무 (Y/N)", example = "N", hidden = true)
private String reserveYn="N"; // 예약문자 여부 default N

View File

@ -1,10 +1,10 @@
package com.itn.mjonApi.mjon.api.send.service;
import com.itn.mjonApi.mjon.api.send.mapper.domain.MjonResponseVO;
import com.itn.mjonApi.cmn.msg.SendRestResponse;
import com.itn.mjonApi.mjon.api.send.mapper.domain.MsgRequestVO;
public interface SendService {
MjonResponseVO sendMsgData(MsgRequestVO msgRequestVO) throws Exception;
SendRestResponse sendMsgData(MsgRequestVO msgRequestVO) throws Exception;
}

View File

@ -1,6 +1,7 @@
package com.itn.mjonApi.mjon.api.send.service.impl;
import com.itn.mjonApi.cmn.apiServer.ApiService;
import com.itn.mjonApi.cmn.msg.SendRestResponse;
import com.itn.mjonApi.mjon.api.send.mapper.SendMapper;
import com.itn.mjonApi.mjon.api.send.mapper.domain.MjonResponseVO;
import com.itn.mjonApi.mjon.api.send.mapper.domain.MsgRequestVO;
@ -33,65 +34,41 @@ public class SendServiceImpl implements SendService {
private static final String replaseStrList = "[*이름*],[*1*],[*2*],[*3*],[*4*]";
@Override
public MjonResponseVO sendMsgData(MsgRequestVO msgRequestVO) throws Exception {
log.info(" :: sendMsgData ::");
Boolean byCallFrom = sendMapper.findByCallFrom(msgRequestVO);
log.info(" :: byCallFrom ::" + byCallFrom);
if(byCallFrom){
}
/*
발신번호 체크
SELECT PHONE_NUMBER
FROM MJ_PHONE_MEMBER
WHERE 1=1
AND USER_ID = 'goodgkdus'
AND AUTH_YN = 'Y'
AND PHM_TYPE = '01'
ORDER BY BASE_YN DESC
* */
public SendRestResponse sendMsgData(MsgRequestVO msgRequestVO) throws Exception {
//sendMsg 문자 발송 체크 사항
log.info(" :: sendMsgData ::");
//step1.발신자 전화번호 사용 가능 여부 체크(해당 사용자의 등록된 번호만 발송 가능)
// 1010
if(!sendMapper.findByCallFrom(msgRequestVO)){
return _falseRetunDate("STAT1010");
}
//step2.수신자 전화번호 정상 여부 체크(정상 번호에 대해서만 발송 가능)
// 1020
// 폰번호 확인 - -> 유효성 정규식
if(StringUtils.isNotEmpty(this.getCallToListChk(msgRequestVO))){
return _falseRetunDate("STAT1020");
}
//step3.문자 내용 정상 여부 확인 - 스미싱 문구는 발송 안됨
// 1030
//step3.문자 내용 정상 여부 확인 - 스미싱 문구는 발송 30분 지연으로 처리됨
// 1030 => 현재 사용안함
// 스팸체크 하는 부분
// apiService.postForEntity => restTemplate.postForEntity 호출 MjonResponseVO에 맞게 데이터 정제하는 메소드
MjonResponseVO spamChkEntity = apiService.postForEntity(
"/web/user/login/selectSpamTxtChkAjax.do"
, msgRequestVO
, String.class
);
// 스팸체크 결과값이 spams 이면 스팸문자로 처리
if("spams".equals(spamChkEntity.getResult())){
msgRequestVO.setSpamStatus("Y");
};
//step4.치환명 정상 여부 확인
// 1040
//step5.발송일시 정상여부 확인
// 1050
//step6.문자 타입에 따른 비용 처리 가능 여부 확인
// 1060
String message = "";
// 폰번호 확인 - -> 유효성 정규식
message = this.getCallToListChk(msgRequestVO);
if(StringUtils.isNotEmpty(message)){
return MjonResponseVO.builder()
.result("fail")
.message(message)
.build();
}
// 치환데이터 여부 확인
msgRequestVO.setTxtReplYn(this.getTxtReplYn(msgRequestVO));
@ -106,28 +83,30 @@ public class SendServiceImpl implements SendService {
}
// 치환데이터 여부 확인
msgRequestVO.setTxtReplYn(this.getTxtReplYn(msgRequestVO));
// 치환데이터가 있을 경우
if("Y".equals(msgRequestVO.getTxtReplYn())){
//일괄변환 문자에 콤마(,) 들어가있으면 배열로 넘길때 문제가 발생하여 특수문자(§) 치환하여 넘겨주도록 한다.
msgRequestVO = this.getReplaceCommaToStrSymbol(msgRequestVO);
// 치환 단문 장문 개수 구하기
msgRequestVO = getLengthOfShortAndLongMsg(msgRequestVO);
}
// 스팸체크 하는 부분
MjonResponseVO spamChkEntity = apiService.postForEntity(
"/web/user/login/selectSpamTxtChkAjax.do"
, msgRequestVO
, String.class
);
if("spams".equals(spamChkEntity.getResult())){
msgRequestVO.setSpamStatus("Y");
};
log.info("msgRequestVO.getSpamStatus() :: [[}]",msgRequestVO.getSpamStatus());
// 문자 전송하는 부분
// apiService.postForEntity => restTemplate.postForEntity 호출 MjonResponseVO에 맞게 데이터 정제하는 메소드
MjonResponseVO munjaSendResponse = apiService.postForEntity(
"/web/user/login/sendMsgDataAjax.do"
, msgRequestVO
, String.class
);
log.info("munjaSendResponse : [{}]", munjaSendResponse.toString());
//step5.발송일시 정상여부 확인
// 1050
//step6.문자 타입에 따른 비용 처리 가능 여부 확인
// 1060
@ -135,6 +114,16 @@ public class SendServiceImpl implements SendService {
// return munjaSendResponse;
}
/**
* 리턴 데이터 메소드
* @return
*/
private static SendRestResponse _falseRetunDate(String ststCode) {
return SendRestResponse.builder()
.resultStr(ststCode)
.build();
}
/**
* 치환 단문 장문 msg 개수 구하기
* @param msgRequestVO

View File

@ -1,11 +1,12 @@
package com.itn.mjonApi.mjon.api.send.web;
import com.itn.mjonApi.mjon.api.send.mapper.domain.MjonResponseVO;
import com.itn.mjonApi.cmn.msg.SendRestResponse;
import com.itn.mjonApi.mjon.api.send.mapper.domain.MsgRequestVO;
import com.itn.mjonApi.mjon.api.send.service.SendService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
@ -48,9 +49,9 @@ public class SendRestController {
@CrossOrigin("*") // 모든 요청에 접근 허용
@PostMapping("/api/send/sendMsg")
@ApiOperation(value= "단문 문자 전송", notes = "같은 내용으로 여러명에게 보냄")
public MjonResponseVO sendTest(MsgRequestVO msgRequestVO) throws Exception {
public ResponseEntity<SendRestResponse> sendMsg(MsgRequestVO msgRequestVO) throws Exception {
return sendService.sendMsgData(msgRequestVO);
return ResponseEntity.ok().body(sendService.sendMsgData(msgRequestVO));
}