카카오 속도개선 진행중

This commit is contained in:
hehihoho3@gmail.com 2025-03-12 16:02:10 +09:00
parent e2a3d281a6
commit 7b7b76b99f
4 changed files with 205 additions and 112 deletions

View File

@ -24,7 +24,9 @@ public class KakaoSendAdvcVO implements Serializable {
*
*/
private static final long serialVersionUID = 343099046833205405L;
// =====
// Insert 데이터
private String msgId; // 문자ID
private String msgGroupId; // 전송그룹ID
private String userId; // 사용자ID
@ -41,6 +43,16 @@ public class KakaoSendAdvcVO implements Serializable {
private String subMsgType; // 대체문자 타입
private String bizJsonName; // JSON 파일명
private String reqDate; // 예약일시
// =====
// =====
private float smsPrice; // sms 단가
private float mmsPrice; // mms 단가
private float kakaoAtPrice; // 카카오 알림톡 단가
@Override
public String toString() {
@ -61,6 +73,11 @@ public class KakaoSendAdvcVO implements Serializable {
"\n , subMsgType=[" + subMsgType + "]" +
"\n , bizJsonName=[" + bizJsonName + "]" +
"\n , reqDate=[" + reqDate + "]" +
"\n , ==== MJ_MSG_DATA INSERT DATA END =======" +
"\n " +
"\n , smsPrice=[" + smsPrice + "]" +
"\n , mmsPrice=[" + mmsPrice + "]" +
"\n , kakaoAtPrice=[" + kakaoAtPrice + "]" +
"\n ]";
}

View File

@ -9,18 +9,22 @@ import java.util.Map;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import itn.com.cmm.util.StringUtil;
import itn.let.kakao.kakaoComm.kakaoApi.KakaoApiJsonSave;
import itn.let.mail.service.StatusResponse;
import itn.let.mjo.mjocommon.MjonCommon;
import itn.let.mjo.msg.service.MjonMsgVO;
import itn.let.mjo.msgdata.service.MjonMsgDataService;
import itn.let.mjo.spammsg.web.ComGetSpamStringParser;
import itn.let.module.base.PriceAndPoint;
import itn.let.sym.site.service.JoinSettingVO;
import itn.let.uss.umt.service.MberManageVO;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Component
public class KakaoSendUtil {
@ -32,6 +36,16 @@ public class KakaoSendUtil {
@Autowired
private PriceAndPoint priceAndPoint;
@Autowired
private MjonCommon mjonCommon;
// 단문 메세지 타입
public static final String SHORT_MSG_TYPE = "SMS";
// 장문 메세지 타입
public static final String LONG_MSG_TYPE = "MMS";
/**
* @methodName : kakaoSendPrice_advc
@ -45,126 +59,178 @@ public class KakaoSendUtil {
* @throws Exception
*
*/
public KakaoVO populateSendLists(KakaoVO kakaoVO, StatusResponse statusResponse) throws Exception {
public List<KakaoSendAdvcVO> populateSendLists(KakaoVO kakaoVO, StatusResponse statusResponse) throws Exception {
//사용자 현재 보유 금액 불러오기(문자 발송 금액 차감 이전 금액)
// String befCash = kakaoVO.getBefCash();
MjonMsgVO mjonMsgVO = new MjonMsgVO();
mjonMsgVO.setUserId(kakaoVO.getUserId());
String userMoney = priceAndPoint.getBefCash(kakaoVO.getUserId());
String userPoint = priceAndPoint.getBefPoint(kakaoVO.getUserId());
//1.시스템 기본 단가 정보 불러오기
JoinSettingVO sysJoinSetVO = mjonMsgDataService.selectJoinSettingInfo();
//2.사용자 개인 단가 정보 불러오기
MberManageVO mberManageVO = mjonMsgDataService.selectMberManageInfo(kakaoVO.getUserId());
Float kakaoAtPrice = mberManageVO.getKakaoAtPrice();
/** 대체문자 여부 체크(있으면 대체문자 가격으로 없으면 카카오톡 가격으로) */
//대체문자 발송 여부 확인
if("Y".equals(kakaoVO.getSubMsgSendYn())) {
log.info(" +kakaoVO.getVarListMap().size() :: [{}]", kakaoVO.getVarListMap().size());
List<KakaoSendAdvcVO> kakaoSendAdvcListVO = new ArrayList<>();
// Map에 갯수가 수신자 갯수와 동일함
for(Map<String, String> variables : kakaoVO.getVarListMap()) {
// MsgSendUtils.getSmsTxtBytes
KakaoSendAdvcVO kakaoSendAdvcVO = new KakaoSendAdvcVO();
String charset = "euc-kr"; //문자 바이트 계산에 필요한 캐릭터 : 한글 2Byte로 계산
int callToCnt = kakaoVO.getCallToList().length;
String sendType = "";
// step1
// Step 1-1: 치환 수신번호 셋팅
String templateContent = kakaoVO.getTemplateContent(); // 알림톡 템플릿
for(int count =0; count < callToCnt; count++) {
String tempSubMagTxt = kakaoVO.getSubMsgTxt().replace("\r\n", "\n");
if(kakaoVO.getSubMsgTxtReplYn().equals("Y")) {
tempSubMagTxt = kakaoSubMagTxtRepl(tempSubMagTxt, kakaoVO, count);
// Step 1-2: 수신자 정보 설정 (callToList는 항상 설정).
if (variables.containsKey("callToList")) {
kakaoSendAdvcVO.setCallTo(variables.get("callToList"));
variables.remove("callToList"); // 사용 제거.
}
// Step 1-3: 템플릿 치환데이터 설정
// TxtReplYn이 "Y" 때만 치환 수행
if ("Y".equals(kakaoVO.getTxtReplYn())) {
templateContent = replaceTemplateVariables(templateContent, variables);
}
kakaoSendAdvcVO.setTemplateContent(templateContent);
// Step 1-4: 실패 대체 문자 치환데이터 설정
if("Y".equals(kakaoVO.getSubMsgSendYn())) {
String subMsgTxt = kakaoVO.getSubMsgTxt(); // 실패 대체 치환 문자
// TxtReplYn이 "Y" 때만 치환 수행
if ("Y".equals(kakaoVO.getSubMsgTxtReplYn())) {
subMsgTxt = replaceTemplateVariables(subMsgTxt, variables);
}
int bytes = tempSubMagTxt.getBytes(charset).length;
kakaoSendAdvcVO.setSubMsgTxt(subMsgTxt);// 실패
}
/*
log.info("kakaoSendAdvcVO Details: [callTo={}\n, templateContent=\n{}\n, subMsgTxt=\n{}]\n\n\n\n",
kakaoSendAdvcVO.getCallTo(),
kakaoSendAdvcVO.getTemplateContent(),
kakaoSendAdvcVO.getSubMsgTxt()
);
*/
// 시스템 기본 단가 정보 불러오기
JoinSettingVO sysJoinSetVO = mjonMsgDataService.selectJoinSettingInfo();
// 사용자 개인 단가 정보 불러오기
MberManageVO mberManageVO = mjonMsgDataService.selectMberManageInfo(kakaoVO.getUserId());
Float kakaoAtPrice = mberManageVO.getKakaoAtPrice();
// 유효한 단가 계산
float shortPrice = getValidPrice(mberManageVO.getShortPrice(), sysJoinSetVO.getShortPrice());
float longPrice = getValidPrice(mberManageVO.getLongPrice(), sysJoinSetVO.getLongPrice());
// 공통 가격 설정
kakaoVO.setSmsPrice(shortPrice);
kakaoVO.setMmsPrice(longPrice);
if("Y".equals(kakaoVO.getSubMsgSendYn())) {
int smsTxtByte = mjonCommon.getSmsTxtBytes(kakaoSendAdvcVO.getSubMsgTxt());
if(bytes < 2000) {
if(bytes > 90) {
sendType = "MMS";
break;
}else {
sendType = "SMS";
}
}else {
kakaoVO.setResultCode("2000");
return kakaoVO;
String sendType = getMsgType(smsTxtByte);
if ("INVALID".equals(sendType)) {
statusResponseSet(statusResponse, HttpStatus.BAD_REQUEST, "전송 문자 길이를 초과하였습니다.");return kakaoSendAdvcListVO;
}
boolean isMms = "MMS".equals(sendType);
kakaoAtPrice = isMms ? longPrice : shortPrice;
kakaoVO.setKakaoAtPrice(getValidPrice(mberManageVO.getKakaoAtPrice(), sysJoinSetVO.getKakaoAtPrice()));
} else {
kakaoAtPrice = getValidPrice(mberManageVO.getKakaoAtPrice(), sysJoinSetVO.getKakaoAtPrice());
kakaoVO.setKakaoAtPrice(kakaoAtPrice);
}
if(sendType.equals("MMS")) {
//협의 단가가 없으면 시스템 단가로 지정
if(mberManageVO.getLongPrice() < 1) {
kakaoAtPrice = sysJoinSetVO.getLongPrice();
kakaoVO.setSmsPrice(sysJoinSetVO.getShortPrice());
kakaoVO.setMmsPrice(sysJoinSetVO.getLongPrice());
kakaoVO.setKakaoAtPrice(sysJoinSetVO.getKakaoAtPrice());
}else {
kakaoAtPrice = mberManageVO.getLongPrice();
kakaoVO.setSmsPrice(mberManageVO.getShortPrice());
kakaoVO.setMmsPrice(mberManageVO.getLongPrice());
if(mberManageVO.getKakaoAtPrice() < 1) {
kakaoVO.setKakaoAtPrice(sysJoinSetVO.getKakaoAtPrice());
}else {
kakaoVO.setKakaoAtPrice(mberManageVO.getKakaoAtPrice());
}
}
}else {
//협의 단가가 없으면 시스템 단가로 지정
if(mberManageVO.getShortPrice() < 1) {
kakaoAtPrice = sysJoinSetVO.getShortPrice();
kakaoVO.setSmsPrice(sysJoinSetVO.getShortPrice());
kakaoVO.setMmsPrice(sysJoinSetVO.getLongPrice());
kakaoVO.setKakaoAtPrice(sysJoinSetVO.getKakaoAtPrice());
}else {
kakaoAtPrice = mberManageVO.getShortPrice();
kakaoVO.setSmsPrice(mberManageVO.getShortPrice());
kakaoVO.setMmsPrice(mberManageVO.getLongPrice());
if(mberManageVO.getKakaoAtPrice() < 1) {
kakaoVO.setKakaoAtPrice(sysJoinSetVO.getKakaoAtPrice());
}else {
kakaoVO.setKakaoAtPrice(mberManageVO.getKakaoAtPrice());
}
}
}
}else {
if(kakaoAtPrice < 1) { //협의 단가가 없으면 시스템 단가로 지정
kakaoAtPrice = sysJoinSetVO.getKakaoAtPrice();
kakaoVO.setSmsPrice(sysJoinSetVO.getShortPrice());
kakaoVO.setMmsPrice(sysJoinSetVO.getLongPrice());
kakaoVO.setKakaoAtPrice(sysJoinSetVO.getKakaoAtPrice());
}else {
kakaoVO.setSmsPrice(mberManageVO.getShortPrice());
kakaoVO.setMmsPrice(mberManageVO.getLongPrice());
kakaoVO.setKakaoAtPrice(mberManageVO.getKakaoAtPrice());
}
// step3
// 바이트 체크 ==> 실패 성공
// step4
// 예약 시간 설정 분할 데이터 설정
// step5
// 전송 메세지 설정 kakaoSendMsg 참고
// kakaoSendAdvcVO.setSendType("AT");
kakaoSendAdvcVO.setMsgType("8");
kakaoSendAdvcVO.setUserId(kakaoVO.getUserId());
}
/** 전송인원 확인*/
int totCallCnt = kakaoVO.getCallToList().length;
Float kakaoTotPrice = totCallCnt * kakaoAtPrice; // 총결제 금액 = 전송수량 * 카카오 알림톡 단가
String totPrice = kakaoTotPrice.toString();
System.out.println("@@@@@@@ : "+kakaoTotPrice +" = "+totCallCnt+" * "+kakaoAtPrice);
kakaoVO.setEachPrice(kakaoAtPrice.toString());
kakaoVO.setBefCash(userMoney); // 고객 충전금액
kakaoVO.setBefPoint(userPoint); // 고객 충전 포인트
kakaoVO.setTotPrice(totPrice); // 카카오 전송 금액
return kakaoVO;
return kakaoSendAdvcListVO;
}
public Float getValidPrice(Float personalPrice, Float defaultPrice) {
return (personalPrice != null && personalPrice > 0) ? personalPrice : defaultPrice;
}
/**
* @methodName : getMsgType
* @author : 이호영
* @date : 2025. 3. 12.
* @description : 메세지 타입 구하기
* @return : String
* @param smsTxtByte
* @return
*
*/
private String getMsgType(int smsTxtByte) {
// TODO Auto-generated method stub
String msgType = SHORT_MSG_TYPE;
// 1. 2000 Byte 초과는 에러 처리
if (smsTxtByte > 2000) {
return "INVALID";
}
// 2. 문자 길이에 따라 메시지 타입 설정 (90 Byte 초과는 장문)
if (smsTxtByte > 90) {
msgType = LONG_MSG_TYPE;
}
return msgType;
}
/**
* @methodName : replaceTemplateVariables
* @author : 이호영
* @date : 2025. 3. 12.
* @description : 헬퍼 메서드: 템플릿 변수 치환
* @return : String
* @param content
* @param variables
* @return
*/
private String replaceTemplateVariables(String content, Map<String, String> variables) {
String result = content;
for (Map.Entry<String, String> entry : variables.entrySet()) {
String placeholder = entry.getKey();
String value = entry.getValue();
result = result.replace(placeholder, value);
}
return result;
}
/**
* @Method Name : kakaoSendPrice
* @작성일 : 2023. 2. 14.
@ -847,5 +913,10 @@ public class KakaoSendUtil {
//}
return "";
}
public static void statusResponseSet (StatusResponse statusResponse, HttpStatus httpStatus, String msg ) {
statusResponse.setStatus(httpStatus);
statusResponse.setMessage(msg);
}
}

View File

@ -25,6 +25,7 @@ import itn.let.kakao.kakaoComm.KakaoSendUtil;
import itn.let.kakao.kakaoComm.KakaoVO;
import itn.let.kakao.user.kakaoAt.service.KakaoAlimTalkService;
import itn.let.mail.service.StatusResponse;
import itn.let.mjo.mjocommon.MjonCommon;
import itn.let.mjo.mjocommon.MjonHolidayApi;
import itn.let.mjo.msg.service.MjonMsgVO;
import itn.let.mjo.msg.service.impl.MjonMsgDAO;
@ -74,10 +75,10 @@ public class KakaoAlimTalkServiceImpl extends EgovAbstractServiceImpl implements
private EgovUserManageService userManageService;
@Autowired
private PriceAndPoint priceAndPoint;
KakaoSendUtil kakaoSendUtil;
@Autowired
KakaoSendUtil kakaoSendUtil;
private MjonCommon mjonCommon;
//발신프로필 상태값 변경(삭제/복구 기능)
@Override
@ -845,7 +846,7 @@ public class KakaoAlimTalkServiceImpl extends EgovAbstractServiceImpl implements
@Override
public StatusResponse insertKakaoAtSandAjax_advc(KakaoVO kakaoVO, HttpServletRequest request) throws Exception {
// log.info(" :: [{}]", kakaoVO.toString());
log.info(" :: [{}]", kakaoVO.toString());
// KakaoSendAdvcVO
@ -860,6 +861,7 @@ public class KakaoAlimTalkServiceImpl extends EgovAbstractServiceImpl implements
return new StatusResponse(HttpStatus.BAD_REQUEST, "로그인 후 이용이 가능합니다.");
}
kakaoVO.setUserId(userId);
/**
* 회원 정지된 상태이면 문자 발송이 안되도록 처리함 현재 로그인 세션도 만료 처리함
@ -877,18 +879,23 @@ public class KakaoAlimTalkServiceImpl extends EgovAbstractServiceImpl implements
/** 카카오톡 전송 기본 설정 -------------------------------------------*/
kakaoVO.setSendType("AT");
kakaoVO.setMsgType("8");
kakaoVO.setUserId(userId);
/** 전송금액 설정 --------------------------------------------------*/
// KakaoVO priceSet = kakaoSendUtil.populateSendLists(kakaoVO, statusResponse);
List<KakaoSendAdvcVO> kakaoSendAdvcListVO = kakaoSendUtil.populateSendLists(kakaoVO, statusResponse);
if (statusResponse.getStatus() != null && !statusResponse.getStatus().equals(HttpStatus.OK)) {
log.error(" + populateSendLists 처리 중 오류 발생: {}", statusResponse.getMessage());
return statusResponse;
}
// step 1
// List<String> idList = mjonCommon.getNextCustomMsgCId(mjonMsgSendVOList.size());

View File

@ -221,6 +221,8 @@ public class KakaoAlimTalkSendController {
}
return "web/kakao/msgdata/at/KakaoAlimtalkMsgDataView";
// return "web/kakao/msgdata/at/KakaoAlimtalkMsgDataView_advcbackup_20250310";
}
@ -1127,10 +1129,6 @@ public class KakaoAlimTalkSendController {
/** 전송금액 설정 --------------------------------------------------*/
KakaoVO priceSet = kakaoSendUtil.kakaoSendPrice(kakaoVO);
if (true) {
throw new IllegalStateException("배열 크기 초과");
}
if(priceSet.getResultCode() != null && priceSet.getResultCode().equals("2000")) {