feat: [다른내용] 장문, 단문 / 수신자별 다른 메세지 문자 전송 일단완

This commit is contained in:
hylee 2023-05-23 16:54:09 +09:00
parent dee07fecb1
commit 5fc4ba2f84
8 changed files with 1354 additions and 8 deletions

View File

@ -2,9 +2,13 @@ package com.itn.mjonApi.cmn.msg;
import com.itn.mjonApi.mjon.api.send.mapper.domain.MjonResponseVO;
import lombok.*;
import lombok.extern.slf4j.Slf4j;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
@Setter
@Getter
@NoArgsConstructor
@ -19,10 +23,14 @@ public class SendSuccessRestResponse {
private String msgGroupId; // 문자 전송 그룹 아이디
private List<String> msgGroupIdList; // 문자 전송 그룹 아이디
private String successCnt; // 성공 건수
private String blockCnt; // 수신거부 건수
private String failCnt; // 실패 건수
private String msgType; // 메세지 타입
private LocalDateTime localDateTime;
@ -53,4 +61,48 @@ public class SendSuccessRestResponse {
// .msgType(mjonResponseVO.getMsgType())
}
/**
* @description 1건~100건 까지 수신자별 메세지 보낸 성공 결과를 리턴한다.
* @param mjonResponseVOList
* @return
*/
public static SendSuccessRestResponse SendSuccessMsgsRestResponse(List<MjonResponseVO> mjonResponseVOList) {
// 실패 카운트
int failCnt = (int) mjonResponseVOList.stream()
.filter(s->"fail".equals(s.getResult()))
.count();
// 성공 카운트
int successCnt = mjonResponseVOList.parallelStream()
.filter(s->!"fail".equals(s.getResult()))
.mapToInt(s -> Integer.parseInt(s.getResultSts()))
.sum();
// 수신거부 카운트
int blockCnt = mjonResponseVOList.parallelStream()
.filter(s->!"fail".equals(s.getResult()))
.mapToInt(s -> Integer.parseInt(s.getResultBlockSts()))
.sum();
// 성공한 메세지 그룹 아이디
List<String> msgGroupIdList = mjonResponseVOList.stream()
.filter(s->!"fail".equals(s.getResult()))
.map(s -> s.getMsgGroupId())
.collect(Collectors.toList());
return SendSuccessRestResponse.builder()
// .resultCode(StatMsg.valueOf(enumStr).getCode()) // 성공 코드 200 - StatMsg 참고
// .message(StatMsg.valueOf(enumStr).getMsg()) // 성공은 message가 없음 - StatMsg 참고
.msgGroupIdList(msgGroupIdList) // 전송 메세지 그룹 ID
.successCnt(Integer.toString(successCnt)) // 성공 건수
.blockCnt(Integer.toString(blockCnt)) // 수신거부 건수
.failCnt(Integer.toString(failCnt)) // 수신거부 건수
.localDateTime(LocalDateTime.now()) // 현재 시간
.build();
}
}

View File

@ -17,6 +17,11 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface SendMapper {
/**
* @description 발신자 번호 체크
* @param callFrom, mberId
* @return
*/
Boolean findByCallFrom(MsgRequestVO msgRequestVO);
}

View File

@ -29,6 +29,7 @@ public class MjonResponseVO {
private String resultBlockSts; // 수신거부 갯수
private String msgGroupId;
private String afterCash;
private String msgType;
@ -41,7 +42,6 @@ public class MjonResponseVO {
*/
public static MjonResponseVO getMjonResponse(ResponseEntity<String> stringResponseEntity) throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
MjonResponseVO mjonResponseVO = objectMapper.readValue(stringResponseEntity.getBody(), MjonResponseVO.class);
return mjonResponseVO;
}

View File

@ -2,10 +2,7 @@ package com.itn.mjonApi.mjon.api.send.mapper.domain;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.*;
import java.io.Serializable;
@ -24,6 +21,7 @@ import java.io.Serializable;
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@ApiModel(description = "문자 발송에 필요한 값들을 받는 vo")
public class MsgRequestVO implements Serializable {

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,13 @@
package com.itn.mjonApi.mjon.api.send.service;
import com.itn.mjonApi.mjon.api.send.mapper.domain.MsgRequestVO;
import com.itn.mjonApi.mjon.api.send.mapper.domain.MsgsRequestVO;
import org.springframework.http.ResponseEntity;
public interface SendService {
ResponseEntity<?> sendMsgData(MsgRequestVO msgRequestVO) throws Exception;
ResponseEntity<?> sendMsgsData(MsgsRequestVO msgsRequestVO) throws Exception;
}

View File

@ -6,6 +6,7 @@ import com.itn.mjonApi.cmn.msg.SendSuccessRestResponse;
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;
import com.itn.mjonApi.mjon.api.send.mapper.domain.MsgsRequestVO;
import com.itn.mjonApi.mjon.api.send.service.SendService;
import com.itn.mjonApi.util.MunjaUtil;
import lombok.extern.slf4j.Slf4j;
@ -16,7 +17,10 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@ -113,13 +117,156 @@ public class SendServiceImpl implements SendService {
}
//step5.발송일시 정상여부 확인
// 1050
//step6.문자 타입에 따른 비용 처리 가능 여부 확인
// 1060
}
@Override
public ResponseEntity<?> sendMsgsData(MsgsRequestVO msgsRequestVO) throws Exception {
List<MsgRequestVO> msgRequestVOList = this.getDataCleaning(msgsRequestVO);
log.info("msgRequestVOList.size() :: [{}]", msgRequestVOList.size());
msgRequestVOList.forEach(msgRequestVO -> {
log.info("msgRequestVO getCallToList() :: [{}]", msgRequestVO.getCallToList());
log.info("msgRequestVO getSmsTxt() :: [{}]", msgRequestVO.getSmsTxt());
log.info("======================");
});
//step1.발신자 전화번호 사용 가능 여부 체크(해당 사용자의 등록된 번호만 발송 가능)
// 1010
if(!sendMapper.findByCallFrom(msgRequestVOList.get(0))){
return ResponseEntity.ok().body(_falseRetunDate("STAT_1010"));
}
List<MjonResponseVO> mjonResponseVOList = new ArrayList<MjonResponseVO>();
for(MsgRequestVO msgRequestVO : msgRequestVOList){
//step2.수신자 전화번호 정상 여부 체크(정상 번호에 대해서만 발송 가능)
// 1020
// 폰번호 확인 - -> 유효성 정규식
if(StringUtils.isNotEmpty(this.getCallToListChk(msgRequestVO))){
FailRestResponse failRestResponse = _falseRetunDate("STAT_1020");
String returnMsg = failRestResponse.getMessage();
returnMsg = returnMsg.replace("수신자", "수신자(" + msgRequestVO.getCallToList()[0] + ")");
failRestResponse.setMessage(returnMsg);
return ResponseEntity.ok().body(failRestResponse);
// return ResponseEntity.ok().body(_falseRetunDate("STAT_1020"));
}
//step3.문자 내용 정상 여부 확인 - 스미싱 문구는 발송 30분 지연으로 처리됨
// 1030 => 현재 사용안함
// 스팸체크 하는 부분
MjonResponseVO spamChkEntity = apiService.postForEntity(
"/web/user/login/selectSpamTxtChkAjax.do"
, msgRequestVO
, String.class
);
// 스팸체크 결과값이 spams 이면 스팸문자로 처리
if("spams".equals(spamChkEntity.getResult())){
msgRequestVO.setSpamStatus("Y");
};
// 문자 전송하는 부분
// apiService.postForEntity => restTemplate.postForEntity 호출 MjonResponseVO에 맞게 데이터 정제하는 메소드
MjonResponseVO munjaSendResponse = apiService.postForEntity(
"/web/user/login/sendMsgDataAjax.do"
, msgRequestVO
, String.class
);
//
mjonResponseVOList.add(munjaSendResponse);
}
return ResponseEntity.ok().body(SendSuccessRestResponse.SendSuccessMsgsRestResponse(mjonResponseVOList));
}
/**
* @description
* @param msgsRequestVO
* @return
*/
private static List<MsgRequestVO> getDataCleaning(MsgsRequestVO msgsRequestVO) {
List<MsgRequestVO> msgRequestVOList = new ArrayList<>();
// Reflection으로 Object Field에 접근한다.
Field[] declaredFields = msgsRequestVO.getClass().getDeclaredFields();
String mberId = null; // 사용자 ID
String accessKey = null; // accessKey
String callFrom = null; // 발신자 번호
String callTo = null; // 수신자 번호
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());
if("mberId".equals(field.getName())){ // 사용자 ID
mberId = value.toString();
}else if("accessKey".equals(field.getName())){ // accessKey
accessKey = value.toString();
}else if("callFrom".equals(field.getName())){ // 발신자 번호
callFrom = value.toString();
}else if(field.getName().startsWith("callTo")){ // 수신자 번호
callTo = value.toString();
}else if(field.getName().startsWith("smsTxt")){ // 문자 내용
// 값이 비여 있으면 다음 반복문으로 넘어간다.
if(StringUtils.isEmpty(value.toString())){
continue;
}
// MsgRequestVO msgRequestVO = new MsgRequestVO();
// msgRequestVO.setMberId(mberId);
// msgRequestVO.setAccessKey(accessKey);
// msgRequestVO.setCallFrom(callFrom);
// msgRequestVO.setCallToList(new String[]{callTo});
// msgRequestVO.setSmsTxt(value.toString());
msgRequestVOList.add(
MsgRequestVO.builder()
.mberId(mberId)
.accessKey(accessKey)
.callFrom(callFrom)
.callToList(new String[]{callTo})
.smsTxt(value.toString())
.build()
);
// 초기화
callTo = "";
}
}
}
return msgRequestVOList;
}
/**
* 리턴 데이터 메소드
* @return

View File

@ -1,6 +1,7 @@
package com.itn.mjonApi.mjon.api.send.web;
import com.itn.mjonApi.mjon.api.send.mapper.domain.MsgRequestVO;
import com.itn.mjonApi.mjon.api.send.mapper.domain.MsgsRequestVO;
import com.itn.mjonApi.mjon.api.send.service.SendService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
@ -42,16 +43,28 @@ public class SendRestController {
/**
*
* @param msgRequestVO
* @Discription 문자 발송 테스트
* @Discription [문자 발송] 같은 내용으로 여려명에게 보냄
* @return
*/
@CrossOrigin("*") // 모든 요청에 접근 허용
@PostMapping("/api/send/sendMsg")
@ApiOperation(value= "단문 문자 전송", notes = "같은 내용으로 여러명에게 보냄")
public ResponseEntity<?> sendMsg(MsgRequestVO msgRequestVO) throws Exception {
return sendService.sendMsgData(msgRequestVO);
}
/**
*
* @param msgsRequestVO
* @description [문자 발송] 다른 내용으로 여려명에게 보냄
* @return
* @throws Exception
*/
@CrossOrigin("*") // 모든 요청에 접근 허용
@PostMapping("/api/send/sendMsgs")
@ApiOperation(value= "문자 전송", notes = "[문자 발송] 다른 내용으로 여려명에게 보냄")
public ResponseEntity<?> sendMsgs(MsgsRequestVO msgsRequestVO) throws Exception {
return sendService.sendMsgsData(msgsRequestVO);
}