api 문자 요청 시 advc 버전으로 수정 완료

This commit is contained in:
hehihoho3@gmail.com 2025-06-26 11:37:23 +09:00
parent 8091778410
commit 2bcecc2199
7 changed files with 158 additions and 46 deletions

View File

@ -51,6 +51,9 @@ public class ApiService <T> {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
JsonNode rootNode = mapper.readTree(returnEntity.getBody()); JsonNode rootNode = mapper.readTree(returnEntity.getBody());
// log.info("rootNode :: [{}]", rootNode.toString());
// "apiReturn" 필드만 추출 // "apiReturn" 필드만 추출
JsonNode apiReturnNode = rootNode.get("apiReturn"); JsonNode apiReturnNode = rootNode.get("apiReturn");
if (apiReturnNode == null || apiReturnNode.isNull()) { if (apiReturnNode == null || apiReturnNode.isNull()) {

View File

@ -33,7 +33,8 @@ public enum StatMsg {
// 문자보내기 ====================================================================== // 문자보내기 ======================================================================
STAT_0("0","") STAT_0("0","")
, STAT_1010("1010","발신자 전화번호 사용 불가") , STAT_1010("1010","발신자 전화번호 사용 불가")
, STAT_1020("1020","수신자 전화번호 오류") , STAT_1020("1020","수신자 전화번호 오류") //
, STAT_1021("1021","수신거부 번호 제거 후 수신자 목록 없음")
, STAT_1030("1030","문자 내용 발송 불가") , STAT_1030("1030","문자 내용 발송 불가")
, STAT_1040("1040","치환 데이터 오류") , STAT_1040("1040","치환 데이터 오류")
, STAT_1050("1050","치환 후 문자 길이 초과") , STAT_1050("1050","치환 후 문자 길이 초과")
@ -68,13 +69,17 @@ public enum StatMsg {
} }
// Random을 만들기 위한 코드 // Random을 만들기 위한 코드
// 모든 enum 항목을 불변 리스트로 저장
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 * , 코드 값이 3자리 이하(: "단문", "장문") 항목은 제외된다.
* @return "STAT_코드" 형식의 문자열
*/ */
public static String randomErrorStatCode() { public static String randomErrorStatCode() {
String errorCode = ""; String errorCode = "";

View File

@ -34,10 +34,11 @@ public class MjonResponseVO {
private String msgGroupId; private String msgGroupId;
private String afterCash; private String afterCash;
private String msgType; private String msgType;
private String statCode;
/** /**
* *
* @param JsonNode apiReturnNode * @param apiReturnNode
* @return ResponseEntity vo convert * @return ResponseEntity vo convert
* @throws JsonProcessingException * @throws JsonProcessingException
*/ */

View File

@ -85,31 +85,33 @@ public class SendSucRestResponse {
*/ */
public static SendSucRestResponse SendSuccessMsgsRestResponse(List<MjonResponseVO> mjonResponseVOList) { public static SendSucRestResponse SendSuccessMsgsRestResponse(List<MjonResponseVO> mjonResponseVOList) {
mjonResponseVOList.forEach(t->log.info(t.toString()));
// 실패 카운트 // 실패 카운트
int failCnt = (int) mjonResponseVOList.stream() int failCnt = (int) mjonResponseVOList.stream()
.filter(s->"fail".equals(s.getResult())) .filter(s->!"OK".equals(s.getResult()))
.count(); .count();
// 성공 카운트 // 성공 카운트
int successCnt = mjonResponseVOList.parallelStream() int successCnt = (int) mjonResponseVOList.parallelStream()
.filter(s->!"fail".equals(s.getResult())) .filter(s->"OK".equals(s.getResult()))
.mapToInt(s -> Integer.parseInt(s.getResultSts())) .count();
.sum();
// 수신거부 카운트 // 수신거부 카운트
int blockCnt = mjonResponseVOList.parallelStream() // int blockCnt = mjonResponseVOList.parallelStream()
.filter(s->!"fail".equals(s.getResult())) // .filter(s->!"OK".equals(s.getResult()))
.mapToInt(s -> Integer.parseInt(s.getResultBlockSts())) // .mapToInt(s -> Integer.parseInt(s.getResultBlockSts()))
.sum(); // .sum();
// 성공한 메세지 그룹 아이디 // 성공한 메세지 그룹 아이디
List<String> msgGroupIdList = mjonResponseVOList.stream() List<String> msgGroupIdList = mjonResponseVOList.stream()
.filter(s->!"fail".equals(s.getResult())) .filter(s->"OK".equals(s.getResult()))
.map(s -> s.getMsgGroupId()) .map(s -> s.getMsgGroupId())
.collect(Collectors.toList()); .collect(Collectors.toList());
// 성공한 메세지 그룹 아이디 // 메세지 타입
List<String> msgTypeList = mjonResponseVOList.stream() List<String> msgTypeList = mjonResponseVOList.stream()
.map(s -> StatMsg.valueOf("msgType"+s.getMsgType()).getMsg()) .filter(s -> s.getMsgType() != null)
.collect(Collectors.toList()); .map(s -> StatMsg.valueOf("msgType"+s.getMsgType()).getMsg())
.collect(Collectors.toList());
@ -118,8 +120,8 @@ public class SendSucRestResponse {
.resultCode(StatMsg.valueOf("STAT_0").getCode()) // 성공 코드 0 - StatMsg 참고 .resultCode(StatMsg.valueOf("STAT_0").getCode()) // 성공 코드 0 - StatMsg 참고
.msgGroupIdList(msgGroupIdList) // 전송 메세지 그룹 ID .msgGroupIdList(msgGroupIdList) // 전송 메세지 그룹 ID
.successCnt(Integer.toString(successCnt)) // 성공 건수 .successCnt(Integer.toString(successCnt)) // 성공 건수
.blockCnt(Integer.toString(blockCnt)) // 수신거부 건수 // .blockCnt(Integer.toString(blockCnt)) // 수신거부 건수
.failCnt(Integer.toString(failCnt)) // 수신거부 건수 .failCnt(Integer.toString(failCnt)) // 실패 건수
.msgTypeList(msgTypeList) // msgType List .msgTypeList(msgTypeList) // msgType List
.build(); .build();

View File

@ -12,4 +12,6 @@ public interface SendService {
RestResponse sendMsgData_advc(MsgRequestVO msgRequestVO) throws Exception; RestResponse sendMsgData_advc(MsgRequestVO msgRequestVO) throws Exception;
RestResponse sendMsgsData(MsgsRequestVO msgsRequestVO) throws Exception; RestResponse sendMsgsData(MsgsRequestVO msgsRequestVO) throws Exception;
RestResponse sendMsgsData_advc(MsgsRequestVO msgsRequestVO) throws Exception;
} }

View File

@ -13,9 +13,11 @@ import com.itn.mjonApi.mjon.api.send.service.SendService;
import com.itn.mjonApi.util.MunjaUtil; import com.itn.mjonApi.util.MunjaUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.connector.Response; import org.apache.catalina.connector.Response;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
@ -135,18 +137,12 @@ public class SendServiceImpl implements SendService {
}else{ // 실패 }else{ // 실패
return new RestResponse(new FailRestResponse(StatMsg.randomErrorStatCode(),"")); return new RestResponse(new FailRestResponse(StatMsg.randomErrorStatCode(),""));
} }
//step5.발송일시 정상여부 확인
// 1050
//step6.문자 타입에 따른 비용 처리 가능 여부 확인
// 1060
} }
@Override @Override
public RestResponse sendMsgData_advc(MsgRequestVO msgRequestVO) throws Exception { public RestResponse sendMsgData_advc(MsgRequestVO msgRequestVO) throws Exception {
log.info(" :: sendMsgData_advc ::");
msgRequestVO.setSendKind("A"); msgRequestVO.setSendKind("A");
@ -155,8 +151,6 @@ public class SendServiceImpl implements SendService {
return this._getTestMsgReturnData(msgRequestVO.getTest_yn()); return this._getTestMsgReturnData(msgRequestVO.getTest_yn());
} }
// step2.수신자 전화번호 정상 여부 체크(정상 번호에 대해서만 발송 가능) // step2.수신자 전화번호 정상 여부 체크(정상 번호에 대해서만 발송 가능)
// 1020 // 1020
// 폰번호 확인 - -> 유효성 정규식 // 폰번호 확인 - -> 유효성 정규식
@ -164,31 +158,25 @@ public class SendServiceImpl implements SendService {
return new RestResponse(new FailRestResponse("STAT_1020","")); return new RestResponse(new FailRestResponse("STAT_1020",""));
} }
// 치환 데이터 수신자 번호 VO 생성
msgRequestVO.setMjonMsgSendVOList(this.buildMsgSendVOList(msgRequestVO));
//step4.치환명 정상 여부 확인
// 1040 // sms 변수 변경
msgRequestVO.setTxtReplYn(this.getTxtReplYn(msgRequestVO));
// 치환데이터가 있을 경우
if("Y".equals(msgRequestVO.getTxtReplYn())){
// 치환 데이터 생성
msgRequestVO.setMjonMsgSendVOList(this.buildMsgSendVOList(msgRequestVO));
}
msgRequestVO.setSmsTxtArea(msgRequestVO.getSmsTxt()); msgRequestVO.setSmsTxtArea(msgRequestVO.getSmsTxt());
MjonResponseVO munjaSendResponse = apiService.postForEntity( MjonResponseVO munjaSendResponse = apiService.postForEntity(
"/web/mjon/msgdata/sendMsgDataAjax_advc.do" "/web/mjon/msgdata/sendMsgDataAjax_advc.do"
// "/web/user/login/sendMsgDataAjax.do"
, msgRequestVO , msgRequestVO
, String.class , String.class
); );
// convertMjonDataToApiResponse => MjonResponseVO 데이터를 ApiResponse 데이터로 변환하는 메소드 // convertMjonDataToApiResponse => MjonResponseVO 데이터를 ApiResponse 데이터로 변환하는 메소드
if(!"fail".equals(munjaSendResponse.getResult())){ // 성공 log.info(" + munjaSendResponse :: [{}]", munjaSendResponse.toString());
if("OK".equals(munjaSendResponse.getResult())){ // 성공
return new RestResponse(SendSucRestResponse.convertMjonDataToApiResponse(munjaSendResponse)); return new RestResponse(SendSucRestResponse.convertMjonDataToApiResponse(munjaSendResponse));
}else{ // 실패 }else{ // 실패
return new RestResponse(new FailRestResponse(StatMsg.randomErrorStatCode(),"")); return new RestResponse(new FailRestResponse(munjaSendResponse.getStatCode(),""));
} }
@ -303,6 +291,7 @@ public class SendServiceImpl implements SendService {
); );
} }
} }
@Override @Override
public RestResponse sendMsgsData(MsgsRequestVO msgsRequestVO) throws Exception { public RestResponse sendMsgsData(MsgsRequestVO msgsRequestVO) throws Exception {
@ -377,9 +366,9 @@ public class SendServiceImpl implements SendService {
, String.class , String.class
); );
// 스팸체크 결과값이 spams 이면 스팸문자로 처리 // 스팸체크 결과값이 spams 이면 스팸문자로 처리
if("spams".equals(spamChkEntity.getResult())){ // if("spams".equals(spamChkEntity.getResult())){
msgRequestVO.setSpamStatus("Y"); // msgRequestVO.setSpamStatus("Y");
}; // };
log.info("msgRequestVO : [{}]", msgRequestVO.toString()); log.info("msgRequestVO : [{}]", msgRequestVO.toString());
// 문자 전송하는 부분 // 문자 전송하는 부분
@ -397,6 +386,41 @@ public class SendServiceImpl implements SendService {
return new RestResponse(SendSucRestResponse.SendSuccessMsgsRestResponse(mjonResponseVOList));
}
@Override
public RestResponse sendMsgsData_advc(MsgsRequestVO msgsRequestVO) throws Exception {
log.info(" :: sendMsgData_advc ::");
if(StringUtils.isNotEmpty(msgsRequestVO.getTest_yn())){
return this._getTestMsgsReturnData(msgsRequestVO.getTest_yn());
}
// msgsVO -> msgVO List로 변환
List<MsgRequestVO> msgRequestVOList = this.getDataCleaning_advc(msgsRequestVO);
List<MjonResponseVO> mjonResponseVOList = new ArrayList<MjonResponseVO>();
for(MsgRequestVO aa : msgRequestVOList){
aa.setSmsTxtArea(aa.getSmsTxt());
aa.setSendKind("A");
MjonResponseVO munjaSendResponse = apiService.postForEntity(
"/web/mjon/msgdata/sendMsgDataAjax_advc.do"
, aa
, String.class
);
mjonResponseVOList.add(munjaSendResponse);
}
return new RestResponse(SendSucRestResponse.SendSuccessMsgsRestResponse(mjonResponseVOList)); return new RestResponse(SendSucRestResponse.SendSuccessMsgsRestResponse(mjonResponseVOList));
} }
@ -496,7 +520,73 @@ public class SendServiceImpl implements SendService {
return msgRequestVOList; return msgRequestVOList;
} }
private static List<MsgRequestVO> getDataCleaning_advc(MsgsRequestVO msgsRequestVO) {
List<MsgRequestVO> msgRequestVOList = new ArrayList<>();
// Reflection으로 Object Field에 접근한다.
Field[] declaredFields = msgsRequestVO.getClass().getDeclaredFields();
String mberId = msgsRequestVO.getMberId(); // 사용자 ID
String accessKey = msgsRequestVO.getAccessKey(); // accessKey
String callFrom = msgsRequestVO.getCallFrom(); // 발신자 번호
String callTo = null; // 수신자 번호
List<MjonMsgSendVO> mjonMsgSendVOList = new ArrayList<>();
for (Field field : declaredFields) {
Object value = null;
// private Field일 경우 접근을 허용한다.
field.setAccessible(true);
try {
// Field Value를 참조한다.
value = field.get(msgsRequestVO);
} catch (IllegalAccessException e) {
log.info("Reflection Error. {}", e);
}
// nullPointException 방지
if(value != null)
{
log.info("field.getName() : [{}]", field.getName());
log.info("value.toString() : [{}]", value.toString());
/**
* 필드 이름으로 분기하여
* 각각에 맞는 위치에 값을 넣어준다.
*/
if(field.getName().startsWith("callTo")){ // 수신자 번호
callTo = value.toString();
}else if(field.getName().startsWith("smsTxt")){ // 문자 내용
// 값이 비여 있으면 다음 반복문으로 넘어간다.
if(StringUtils.isEmpty(value.toString())){
callTo = "";
continue;
}
MjonMsgSendVO vo = new MjonMsgSendVO();
vo.setPhone(callTo);
mjonMsgSendVOList.add(vo);
msgRequestVOList.add(
MsgRequestVO.builder()
.mberId(mberId)
.accessKey(accessKey)
.callFrom(callFrom)
.smsTxt(value.toString())
.mjonMsgSendVOList(mjonMsgSendVOList)
.build()
);
// 초기화
callTo = "";
}
}
}
return msgRequestVOList;
}
/** /**
* 치환 단문 장문 msg 개수 구하기 * 치환 단문 장문 msg 개수 구하기
* @param msgRequestVO * @param msgRequestVO
@ -667,6 +757,13 @@ public class SendServiceImpl implements SendService {
*/ */
private static Boolean getCallToListChk(MsgRequestVO msgRequestVO) { private static Boolean getCallToListChk(MsgRequestVO msgRequestVO) {
Boolean returnData = false; Boolean returnData = false;
String[] test = msgRequestVO.getCallToList();
if (ArrayUtils.isEmpty(test)) {
returnData = true;
}
for(String callTo : msgRequestVO.getCallToList()){ for(String callTo : msgRequestVO.getCallToList()){
/* /*
if(!MunjaUtil.checkPhoneNumberEmpty(callTo)){ if(!MunjaUtil.checkPhoneNumberEmpty(callTo)){
@ -674,7 +771,8 @@ public class SendServiceImpl implements SendService {
if(!MunjaUtil.validatePNumWithRegex(callTo)){ if(!MunjaUtil.validatePNumWithRegex(callTo)){
message = "휴대폰 번호가 올바르지 않습니다. : " + callTo; break;}; message = "휴대폰 번호가 올바르지 않습니다. : " + callTo; break;};
*/ */
if(!MunjaUtil.validatePNumWithRegex(callTo) // 비여있는지 체크
if(!MunjaUtil.checkPhoneNumberEmpty(callTo) // 비여있는지 체크
|| !MunjaUtil.validatePNumWithRegex(callTo) // 정규식으로 번호 체크 || !MunjaUtil.validatePNumWithRegex(callTo) // 정규식으로 번호 체크
) )
{ {

View File

@ -63,7 +63,8 @@ public class SendRestController {
@CrossOrigin("*") // 모든 요청에 접근 허용 @CrossOrigin("*") // 모든 요청에 접근 허용
@PostMapping("/api/send/sendMsgs") @PostMapping("/api/send/sendMsgs")
public ResponseEntity<RestResponse> sendMsgs(MsgsRequestVO msgsRequestVO) throws Exception { public ResponseEntity<RestResponse> sendMsgs(MsgsRequestVO msgsRequestVO) throws Exception {
return ResponseEntity.ok().body(sendService.sendMsgsData(msgsRequestVO)); return ResponseEntity.ok().body(sendService.sendMsgsData_advc(msgsRequestVO));
// return ResponseEntity.ok().body(sendService.sendMsgsData(msgsRequestVO));
} }