Merge branch 'master' of

http://yongjoon.cho@vcs.iten.co.kr:9999/hylee/mjon_api
This commit is contained in:
myname 2023-05-19 17:53:14 +09:00
parent ccbd49a2c4
commit c451abed3c
7 changed files with 518 additions and 2 deletions

View File

@ -0,0 +1,11 @@
package com.itn.mjonApi.mjon.api.inqry.service;
import com.itn.mjonApi.mjon.api.inqry.service.mapper.domain.HstryResponseVO;
import com.itn.mjonApi.mjon.api.inqry.service.mapper.domain.HstryVO;
import com.itn.mjonApi.mjon.api.send.mapper.domain.MsgRequestVO;
public interface HstryService {
HstryResponseVO hstryList(MsgRequestVO msgRequestVO) throws Exception;
}

View File

@ -0,0 +1,326 @@
package com.itn.mjonApi.mjon.api.inqry.service.impl;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicInteger;
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 com.itn.mjonApi.cmn.apiServer.ApiService;
import com.itn.mjonApi.mjon.api.inqry.service.HstryService;
import com.itn.mjonApi.mjon.api.inqry.service.mapper.domain.HstryResponseVO;
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.util.MunjaUtil;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Service
public class HstryServiceImpl implements HstryService {
private ApiService<Response> apiService;
@Autowired
SendMapper sendMapper;
@Autowired
public HstryServiceImpl(ApiService<Response> apiService) {
this.apiService = apiService;
}
private static final String replaseStrList = "[*이름*],[*1*],[*2*],[*3*],[*4*]";
@Override
public HstryResponseVO hstryList(MsgRequestVO msgRequestVO) throws Exception {
log.info(" :: hstryList ::");
//해당 id에 대한 전체 발송 리스트를 가져온다.
Boolean byCallFrom = sendMapper.findByCallFrom(msgRequestVO);
log.info(" :: byCallFrom ::" + byCallFrom);
if(byCallFrom){
}
/*
발신번호 체크
SELECT PHONE_NUMBER
FROM MJ_PHONE_MEMBER
WHERE 1=1
AND USER_ID = 'goodgkdus'
AND AUTH_YN = 'Y'
AND PHM_TYPE = '01'
ORDER BY BASE_YN DESC
* */
//sendMsg 문자 발송 체크 사항
//step1.발신자 전화번호 사용 가능 여부 체크(해당 사용자의 등록된 번호만 발송 가능)
// 1010
//step2.수신자 전화번호 정상 여부 체크(정상 번호에 대해서만 발송 가능)
// 1020
//step3.문자 내용 정상 여부 확인 - 스미싱 문구는 발송 안됨
// 1030
//step4.치환명 정상 여부 확인
// 1040
//step5.발송일시 정상여부 확인
// 1050
//step6.문자 타입에 따른 비용 처리 가능 여부 확인
// 1060
String message = "";
// 폰번호 확인 - -> 유효성 정규식
message = this.getCallToListChk(msgRequestVO);
if(StringUtils.isNotEmpty(message)){
return HstryResponseVO.builder()
.result("fail")
.message(message)
.build();
}
// 치환데이터 여부 확인
msgRequestVO.setTxtReplYn(this.getTxtReplYn(msgRequestVO));
if("Y".equals(msgRequestVO.getTxtReplYn())){
//일괄변환 문자에 콤마(,) 들어가있으면 배열로 넘길때 문제가 발생하여 특수문자(§) 치환하여 넘겨주도록 한다.
msgRequestVO = this.getReplaceCommaToStrSymbol(msgRequestVO);
// 치환 단문 장문 개수 구하기
msgRequestVO = getLengthOfShortAndLongMsg(msgRequestVO);
}
// 스팸체크 하는 부분
MjonResponseVO spamChkEntity = apiService.postForEntity(
"/web/user/login/selectSpamTxtChkAjax.do"
, msgRequestVO
, String.class
);
if("spams".equals(spamChkEntity.getResult())){
msgRequestVO.setSpamStatus("Y");
};
log.info("msgRequestVO.getSpamStatus() :: [[}]",msgRequestVO.getSpamStatus());
// 문자 전송하는 부분
MjonResponseVO munjaSendResponse = apiService.postForEntity(
"/web/user/login/sendMsgDataAjax.do"
, msgRequestVO
, String.class
);
System.out.println("======HstryResponseVO hstryList===");
return null;
// return munjaSendResponse;
}
/**
* 치환 단문 장문 msg 개수 구하기
* @param msgRequestVO
* @return msgRequestVO
* @throws UnsupportedEncodingException
*/
private static MsgRequestVO getLengthOfShortAndLongMsg(MsgRequestVO msgRequestVO) throws UnsupportedEncodingException {
String charset = "euc-kr";
int totListCnt = msgRequestVO.getCallToList().length;
int shortMsgCnt=0; // 치환 단문 개수
int longMsgCnt=0; // 치환 장문 개수
for(int i=0; i < totListCnt; i ++) {
String smsTxt = msgRequestVO.getSmsTxt().replaceAll(String.valueOf((char)13), ""); //발송 문자 내용
String[] nameList = msgRequestVO.getNameList(); //치환 이름 리스트
String[] phone = msgRequestVO.getCallToList(); //수신자 휴대폰 번호
String[] rep1 = msgRequestVO.getRep1List(); //치환 문자1 리스트
String[] rep2 = msgRequestVO.getRep2List(); //치환 문자2 리스트
String[] rep3 = msgRequestVO.getRep3List(); //치환 문자3 리스트
String[] rep4 = msgRequestVO.getRep4List(); //치환 문자4 리스트
if (smsTxt.indexOf("[*이름*]") > -1) {
if(nameList.length > i && StringUtils.isNotEmpty(nameList[i])) {
smsTxt = smsTxt.replaceAll("\\[\\*이름\\*\\]", MunjaUtil.getString(nameList[i].replaceAll("§", ",")));
}else {
smsTxt = smsTxt.replaceAll("\\[\\*이름\\*\\]", "");
}
}
if (smsTxt.indexOf("[*1*]") > -1) {
if(rep1.length > i && StringUtils.isNotEmpty(rep1[i])) {
smsTxt = smsTxt.replaceAll("\\[\\*1\\*\\]", MunjaUtil.getString(rep1[i].replaceAll("§", ",")));
}else {
smsTxt = smsTxt.replaceAll("\\[\\*1\\*\\]", "");
}
}
if (smsTxt.indexOf("[*2*]") > -1) {
if(rep2.length > i && StringUtils.isNotEmpty(rep2[i])) {
smsTxt = smsTxt.replaceAll("\\[\\*2\\*\\]", MunjaUtil.getString(rep2[i].replaceAll("§", ",")));
}else {
smsTxt = smsTxt.replaceAll("\\[\\*2\\*\\]", "");
}
}
if (smsTxt.indexOf("[*3*]") > -1) {
if(rep3.length > i && StringUtils.isNotEmpty(rep3[i])) {
smsTxt = smsTxt.replaceAll("\\[\\*3\\*\\]", MunjaUtil.getString(rep3[i].replaceAll("§", ",")));
}else {
smsTxt = smsTxt.replaceAll("\\[\\*3\\*\\]", "");
}
}
if (smsTxt.indexOf("[*4*]") > -1) {
if(rep4.length > i && StringUtils.isNotEmpty(rep4[i])) {
smsTxt = smsTxt.replaceAll("\\[\\*4\\*\\]", MunjaUtil.getString(rep4[i].replaceAll("§", ",")));
}else {
smsTxt = smsTxt.replaceAll("\\[\\*4\\*\\]", "");
}
}
int bytes = smsTxt.getBytes(charset).length;
if(bytes > 90) {//장문문자 리스트 만들기
longMsgCnt++;
}else {//단문문자 리스트 만들기
shortMsgCnt++;
}
}
msgRequestVO.setLongMsgCnt(Integer.toString(longMsgCnt));
msgRequestVO.setShortMsgCnt(Integer.toString(shortMsgCnt));
return msgRequestVO;
}
/**
* 치환문자가 있으면 , => § 치환
* @param msgRequestVO
* @return
*/
private static MsgRequestVO getReplaceCommaToStrSymbol(MsgRequestVO msgRequestVO) {
AtomicInteger index = new AtomicInteger();
// 이름 배열
if(StringUtils.isNotEmpty(msgRequestVO.getNameStr()))
{
msgRequestVO.setNameList(msgRequestVO.getNameStr().split("\\|"));
String[] nameList = new String[msgRequestVO.getNameList().length];
Arrays.stream(msgRequestVO.getNameList()).forEach(name -> {
nameList[index.getAndIncrement()] = MunjaUtil.replaceCommaToStrSymbol(name);
});
msgRequestVO.setNameList(nameList);
}
// Rep1 배열
if(StringUtils.isNotEmpty(msgRequestVO.getRep1Str()))
{
index.set(0);
msgRequestVO.setRep1List(msgRequestVO.getRep1Str().split("\\|"));
String[] rep1List = new String[msgRequestVO.getRep1List().length];
Arrays.stream(msgRequestVO.getRep1List()).forEach(str -> {
rep1List[index.getAndIncrement()] = MunjaUtil.replaceCommaToStrSymbol(str);
});
msgRequestVO.setRep1List(rep1List);
}
// Rep2 배열
if(StringUtils.isNotEmpty(msgRequestVO.getRep2Str()))
{
index.set(0);
msgRequestVO.setRep2List(msgRequestVO.getRep2Str().split("\\|"));
String[] rep2List = new String[msgRequestVO.getRep2List().length];
Arrays.stream(msgRequestVO.getRep2List()).forEach(str -> {
rep2List[index.getAndIncrement()] = MunjaUtil.replaceCommaToStrSymbol(str);
});
msgRequestVO.setRep2List(rep2List);
}
// Rep3 배열
if(StringUtils.isNotEmpty(msgRequestVO.getRep3Str()))
{
index.set(0);
msgRequestVO.setRep3List(msgRequestVO.getRep3Str().split("\\|"));
String[] rep3List = new String[msgRequestVO.getRep3List().length];
Arrays.stream(msgRequestVO.getRep3List()).forEach(str -> {
rep3List[index.getAndIncrement()] = MunjaUtil.replaceCommaToStrSymbol(str);
});
msgRequestVO.setRep3List(rep3List);
}
// Rep4 배열
if(StringUtils.isNotEmpty(msgRequestVO.getRep4Str()))
{
index.set(0);
msgRequestVO.setRep4List(msgRequestVO.getRep4Str().split("\\|"));
String[] rep4List = new String[msgRequestVO.getRep4List().length];
Arrays.stream(msgRequestVO.getRep4List()).forEach(str -> {
rep4List[index.getAndIncrement()] = MunjaUtil.replaceCommaToStrSymbol(str);
});
msgRequestVO.setRep4List(rep4List);
}
return msgRequestVO;
}
/**
* 치환 문자 여부 확인
* @param msgRequestVO
* @return
*/
private static String getTxtReplYn(MsgRequestVO msgRequestVO) {
int callLen = msgRequestVO.getCallToList().length;
// 치환 데이터 확인
Arrays.stream(replaseStrList.split(",")).forEach(
str -> {
if(msgRequestVO.getSmsTxt().indexOf(str) > -1){
msgRequestVO.setTxtReplYn("Y");
}
}
);
return msgRequestVO.getTxtReplYn();
}
/**
* 수신자 목록 번호 검증
* @param msgRequestVO
* @return
*/
private static String getCallToListChk(MsgRequestVO msgRequestVO) {
String message = "";
for(String callTo : msgRequestVO.getCallToList()){
if(!MunjaUtil.checkPhoneNumberEmpty(callTo)){
message = "수신 목록에 핸드폰 번호가 없는 항목이 있습니다."; break;};
if(!MunjaUtil.validatePNumWithRegex(callTo)){
message = "휴대폰 번호가 올바르지 않습니다. : " + callTo; break;};
}
return message;
}
}

View File

@ -0,0 +1,49 @@
package com.itn.mjonApi.mjon.api.inqry.service.mapper.domain;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.*;
import org.springframework.http.ResponseEntity;
/**
* packageName : com.itn.mjonApi.cmn.msg
* fileName : mjonResponse
* author : hylee
* date : 2023-05-12
* description : 문자온 프로젝트에서 받은 리턴값
* ===========================================================
* DATE AUTHOR NOTE
* -----------------------------------------------------------
* 2023-05-12 hylee 최초 생성
*/
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class HstryResponseVO {
private String result;
private String message;
private String resultSts; // 전송결과 갯수
private String resultBlockSts; // 수신거부 갯수
private String msgGroupId;
private String afterCash;
/**
*
* @param stringResponseEntity
* @return ResponseEntity vo convert
* @throws JsonProcessingException
*/
public static HstryResponseVO getMjonResponse(ResponseEntity<String> stringResponseEntity) throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
HstryResponseVO mjonResponseVO = objectMapper.readValue(stringResponseEntity.getBody(), HstryResponseVO.class);
return mjonResponseVO;
}
}

View File

@ -0,0 +1,24 @@
package com.itn.mjonApi.mjon.api.inqry.service.mapper.domain;
import java.io.Serializable;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class HstryVO implements Serializable{
private static final long serialVersionUID = -7865729705175845268L;
private String mberId; // 사용자 ID
// private double shortPrice; // 단문 이용단가
// private double longPrice; // 장문 이용단가
// private double picturePrice; // 그림 이용단가
// private double userMoney; // 잔액
// private int sendPsbltEa; //발송 가능건
}

View File

@ -0,0 +1,49 @@
package com.itn.mjonApi.mjon.api.inqry.service.mapper.domain;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.*;
import org.springframework.http.ResponseEntity;
/**
* packageName : com.itn.mjonApi.cmn.msg
* fileName : mjonResponse
* author : hylee
* date : 2023-05-12
* description : 문자온 프로젝트에서 받은 리턴값
* ===========================================================
* DATE AUTHOR NOTE
* -----------------------------------------------------------
* 2023-05-12 hylee 최초 생성
*/
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class MjonResponseVO {
private String result;
private String message;
private String resultSts; // 전송결과 갯수
private String resultBlockSts; // 수신거부 갯수
private String msgGroupId;
private String afterCash;
/**
*
* @param stringResponseEntity
* @return ResponseEntity vo convert
* @throws JsonProcessingException
*/
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

@ -0,0 +1,59 @@
package com.itn.mjonApi.mjon.api.inqry.web;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import com.itn.mjonApi.mjon.api.inqry.service.HstryService;
import com.itn.mjonApi.mjon.api.inqry.service.mapper.domain.HstryResponseVO;
import com.itn.mjonApi.mjon.api.send.mapper.domain.MsgRequestVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
/**
* packageName : com.itn.mjonApi.mjon.hstry.web
* fileName : HstryRestController
* author : hylee
* date : 2023-02-15
* description :
* ===========================================================
* DATE AUTHOR NOTE
* -----------------------------------------------------------
* 2023-02-15 hylee 최초 생성
*/
// 치환문자가 있으면 , => § 치환
@Slf4j
@RestController
public class HstryRestController {
private final RestTemplate restTemplate;
public HstryRestController(RestTemplate restTemplate) {
this.restTemplate = restTemplate;
}
@Autowired
private HstryService hstryService;
/**
*
* @param msgRequestVO
* @Discription 문자 발송 테스트
* @return
*/
@CrossOrigin("*") // 모든 요청에 접근 허용
@PostMapping("/api/inqry/hstry")
@ApiOperation(value= "전송 내역 조회", notes = "전체 전송 내역 조회")
public HstryResponseVO inqryHstry(MsgRequestVO msgRequestVO) throws Exception {
return hstryService.hstryList(msgRequestVO);
}
}

View File

@ -79,7 +79,6 @@ public class SendServiceImpl implements SendService {
/*
String message = "";
@ -130,7 +129,6 @@ public class SendServiceImpl implements SendService {
, String.class
);
*/
return null;