package com.itn.mjonApi.util; import com.itn.mjonApi.mjon.api.kakao.at.send.mapper.domain.MsgAtRequestVO; import com.itn.mjonApi.mjon.api.kakao.at.send.mapper.domain.VarAtListMapVO; import com.itn.mjonApi.mjon.api.kakao.ft.send.mapper.domain.MsgFtRequestVO; import com.itn.mjonApi.mjon.api.kakao.ft.send.mapper.domain.VarFtListMapVO; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; /** * packageName : com.itn.mjonApi.util * fileName : SendUtil * author : hylee * date : 2023-05-17 * description : * =========================================================== * DATE AUTHOR NOTE * ----------------------------------------------------------- * 2023-05-17 hylee 최초 생성 */ @Slf4j public class MunjaUtil { /** * 폰번호 빈값 검사 * @param str * @return */ public static Boolean checkPhoneNumberEmpty(String str){ return StringUtils.isEmpty(str) ? false : true; } public static String replaceCommaToStrSymbol(String name) { return name.replaceAll(",", "§"); } public static String removeCharactersWithRegex(String str) { return str.replaceAll("[^0-9]", ""); } /** * 파라미터를 String 타입으로 가져옵니다.
* - null일 경우 빈 문자열을 가져옵니다.
* Get String(if object is null, return empty string). * @param obj * @return String */ public static String getString(Object obj) { if (obj == null) return ""; else return String.valueOf(obj); } /** * 수신자 목록 번호 검증 * message가 없으면 정상 * @param callToList * @return String */ public static Boolean getCallToListChk(String[] callToList) { Boolean returnData = false; if (ArrayUtils.isEmpty(callToList)) { return true; } for(String callTo : callToList){ if(!MunjaUtil.checkPhoneNumberEmpty(callTo) // 비여있는지 체크 || !MunjaUtil.validatePNumWithRegex(callTo) // 정규식으로 번호 체크 ) { return true; }; } return returnData; } public static Boolean getCallToChk(String callTo) { Boolean returnData = false; if(!MunjaUtil.checkPhoneNumberEmpty(callTo) // 비여있는지 체크 || !MunjaUtil.validatePNumWithRegex(callTo) // 정규식으로 번호 체크 ) { return true; }; return returnData; } // 기존 정규식 검사 메서드 (변경 없음) public static boolean validatePNumWithRegex(String pNum) { return pNum != null && pNum.matches("^\\d{10,11}$"); } /** * VarListMapVO의 필드들을 검증 * * @param vo 검증할 VarListMapVO 객체 * @param msgAtRequestVO * @return 검증 실패 시 오류 코드, 성공 시 null */ public static String kakaoAtValidate(VarAtListMapVO vo, MsgAtRequestVO msgAtRequestVO) { String subMsgSendYn = msgAtRequestVO.getSubMsgSendYn(); Boolean hasTemplateTitle = msgAtRequestVO.getHasTemplateTitle(); // 수신번호 검증 String callTo = vo.getCallToList(); if (MunjaUtil.getCallToChk(callTo)) { return "STAT_1020"; // 수신자 전화번호 오류 } // 본문 데이터 검증 String templateContent = vo.getTemplateContent(); if (StringUtils.isEmpty(templateContent)) { return "STAT_2040"; // 본문 데이터 오류 } // 템플릿에 타이틀이 있으면 값 확인 if (hasTemplateTitle && StringUtils.isEmpty(vo.getTemplateTitle())) { return "STAT_2041"; // 타이틀 데이터 오류 } // 대체문자 검증 (대체문자 발송이 활성화된 경우에만) if ("Y".equals(subMsgSendYn)) { String subMsgTxt = vo.getSubMsgTxt(); if (StringUtils.isEmpty(subMsgTxt)) { return "STAT_2042"; // 대체문자 데이터 오류 } } // 모든 검증 통과 return null; } public static String kakaoFtValidate(VarFtListMapVO vo, MsgFtRequestVO msgFtRequestVO) { log.info(" vo.toString() [{}]", vo.toString()); String ok = null; // 수신번호 검증 String callTo = vo.getPhone(); if (MunjaUtil.getCallToChk(callTo)) { return "STAT_1020"; // 수신자 전화번호 오류 } // 본문 데이터 검증 String smsTxt = vo.getTemplateContent(); if (StringUtils.isEmpty(smsTxt)) { return "STAT_2040"; // 본문 데이터 오류 } // 대체문자 검증 (대체문자 발송이 활성화된 경우에만) if ("Y".equals(msgFtRequestVO.getSubMsgSendYn())) { String subMsgTxt = vo.getSubMsgTxt(); if (StringUtils.isEmpty(subMsgTxt)) { return "STAT_2042"; // 대체문자 데이터 오류 } String callFrom = msgFtRequestVO.getCallFrom(); if (StringUtils.isEmpty(callFrom)) { return "STAT_2043"; // 대체문자 발송 시 발신번호 필요 } } // 모든 검증 통과 return ok; } }