대량문자발송 수정

This commit is contained in:
hehihoho3@gmail.com 2025-09-03 14:57:02 +09:00
parent da556ac32a
commit b6e48e0488
4 changed files with 136 additions and 8 deletions

View File

@ -102,7 +102,8 @@ public class MsgRequestVO implements Serializable {
private String test_yn; // 테스트 여부
private String sendKind; // 테스트 여부
private String sendKind; // 문자종류
List<MjonMsgSendVO> mjonMsgSendVOList;

View File

@ -4,6 +4,8 @@ import com.itn.mjonApi.cmn.msg.RestResponse;
import com.itn.mjonApi.mjon.api.msg.send.mapper.domain.MsgRequestVO;
import com.itn.mjonApi.mjon.api.msg.send.mapper.domain.MsgsRequestVO;
import java.util.Map;
public interface SendService {
@ -14,4 +16,6 @@ public interface SendService {
// RestResponse sendMsgsData(MsgsRequestVO msgsRequestVO) throws Exception;
RestResponse sendMsgsData_advc(MsgsRequestVO msgsRequestVO) throws Exception;
RestResponse sendMsgsData_advc(MsgsRequestVO msgsRequestVO, Map<String, String> allParams) throws Exception;
}

View File

@ -10,14 +10,15 @@ import com.itn.mjonApi.mjon.api.msg.send.mapper.domain.*;
import com.itn.mjonApi.mjon.api.msg.send.service.SendService;
import com.itn.mjonApi.util.MunjaUtil;
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.stereotype.Service;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@ -25,7 +26,7 @@ import java.util.Optional;
@Service
public class SendServiceImpl implements SendService {
private ApiService<Response> apiService;
private ApiService apiService;
@Autowired
SendMapper sendMapper;
@ -34,7 +35,7 @@ public class SendServiceImpl implements SendService {
PriceMapper priceMapper;
@Autowired
public SendServiceImpl(ApiService<Response> apiService) {
public SendServiceImpl(ApiService apiService) {
this.apiService = apiService;
}
@ -201,6 +202,49 @@ public class SendServiceImpl implements SendService {
// msgsVO -> msgVO List로 변환
List<MsgRequestVO> msgRequestVOList = this.getDataCleaning_advc(msgsRequestVO);
msgRequestVOList.forEach(t->log.info(" + t.toString() :: [{}]", t.toString()));
log.info("msgRequestVOList :: [{}]", msgRequestVOList.size());
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
);
log.info("munjaSendResponse :: [{}]", munjaSendResponse.toString());
mjonResponseVOList.add(munjaSendResponse);
}
return new RestResponse(SendSucRestResponse.SendSuccessMsgsRestResponse(mjonResponseVOList));
}
@Override
public RestResponse sendMsgsData_advc(MsgsRequestVO msgsRequestVO, Map<String, String> allParams) throws Exception {
log.info(" :: sendMsgData_advc with Map params ::");
if(StringUtils.isNotEmpty(msgsRequestVO.getTest_yn())){
return this._getTestMsgsReturnData(msgsRequestVO.getTest_yn());
}
// Map 기반 동적 파라미터 처리
List<MsgRequestVO> msgRequestVOList = this.getDataCleaning_advc_withMap(msgsRequestVO, allParams);
log.info("msgRequestVOList :: [{}]", msgRequestVOList.size());
List<MjonResponseVO> mjonResponseVOList = new ArrayList<MjonResponseVO>();
for(MsgRequestVO aa : msgRequestVOList){
@ -214,6 +258,7 @@ public class SendServiceImpl implements SendService {
, String.class
);
log.info("munjaSendResponse :: [{}]", munjaSendResponse.toString());
mjonResponseVOList.add(munjaSendResponse);
}
@ -302,9 +347,82 @@ public class SendServiceImpl implements SendService {
return msgRequestVOList;
}
/**
* Map 기반 동적 파라미터 처리를 위한 새로운 메소드
* callTo_1, smsTxt_1, callTo_2, smsTxt_2 등의 동적 파라미터를 처리
*/
private List<MsgRequestVO> getDataCleaning_advc_withMap(MsgsRequestVO msgsRequestVO, Map<String, String> allParams) {
List<MsgRequestVO> msgRequestVOList = new ArrayList<>();
String mberId = msgsRequestVO.getMberId();
String accessKey = msgsRequestVO.getAccessKey();
String callFrom = msgsRequestVO.getCallFrom();
// 동적 파라미터를 순서대로 처리하기 위해 인덱스 기반으로 처리
Map<Integer, String> callToMap = new HashMap<>();
Map<Integer, String> smsTxtMap = new HashMap<>();
// 파라미터를 분석하여 인덱스별로 분류
for (Map.Entry<String, String> entry : allParams.entrySet()) {
String paramName = entry.getKey();
String paramValue = entry.getValue();
log.info("Processing param: [{}] = [{}]", paramName, paramValue);
if (paramName.startsWith("callTo_")) {
try {
int index = Integer.parseInt(paramName.substring(7)); // "callTo_" 이후 숫자
callToMap.put(index, paramValue);
} catch (NumberFormatException e) {
log.warn("Invalid callTo parameter format: [{}]", paramName);
}
} else if (paramName.startsWith("smsTxt_")) {
try {
int index = Integer.parseInt(paramName.substring(7)); // "smsTxt_" 이후 숫자
if (StringUtils.isNotEmpty(paramValue)) {
smsTxtMap.put(index, paramValue);
}
} catch (NumberFormatException e) {
log.warn("Invalid smsTxt parameter format: [{}]", paramName);
}
}
}
// 인덱스별로 메시지 요청 VO 생성
for (Integer index : smsTxtMap.keySet()) {
String callTo = callToMap.get(index);
String smsTxt = smsTxtMap.get(index);
if (StringUtils.isNotEmpty(callTo) && StringUtils.isNotEmpty(smsTxt)) {
List<MjonMsgSendVO> mjonMsgSendVOList = new ArrayList<>();
MjonMsgSendVO vo = new MjonMsgSendVO();
vo.setPhone(callTo);
mjonMsgSendVOList.add(vo);
msgRequestVOList.add(
MsgRequestVO.builder()
.mberId(mberId)
.accessKey(accessKey)
.callFrom(callFrom)
.smsTxt(smsTxt)
.reserveYn("N")
.mjonMsgSendVOList(mjonMsgSendVOList)
.build()
);
log.info("Created MsgRequestVO for index [{}]: callTo=[{}], smsTxt=[{}]",
index, callTo, smsTxt);
}
// else {
// log.warn("Skipping index [{}]: callTo=[{}], smsTxt=[{}]", index, callTo, smsTxt);
// }
}
msgRequestVOList.forEach(t->log.info("+ t.getReserveYn() :: [{}]", t.getReserveYn()));
return msgRequestVOList;
}
}

View File

@ -9,8 +9,11 @@ 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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
/**
* packageName : com.itn.mjonApi.mjon.send.web
* fileName : SendRestController
@ -48,14 +51,16 @@ public class SendRestController {
/**
*
* @param msgsRequestVO
* @description [문자 발송] 다른 내용으로 여려명에게 보냄
* @param allParams
* @description [문자 발송] 다른 내용으로 여려명에게 보냄 - Map 기반 동적 파라미터 처리
* @return
* @throws Exception
*/
@CrossOrigin("*") // 모든 요청에 접근 허용
@PostMapping("/api/send/sendMsgs")
public ResponseEntity<RestResponse> sendMsgs(MsgsRequestVO msgsRequestVO) throws Exception {
return ResponseEntity.ok().body(sendService.sendMsgsData_advc(msgsRequestVO));
public ResponseEntity<RestResponse> sendMsgs(MsgsRequestVO msgsRequestVO,
@RequestParam Map<String, String> allParams) throws Exception {
return ResponseEntity.ok().body(sendService.sendMsgsData_advc(msgsRequestVO, allParams));
// return ResponseEntity.ok().body(sendService.sendMsgsData(msgsRequestVO));
}