diff --git a/.gitignore b/.gitignore index 64d06b5..c9e9721 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,9 @@ local.properties .settings/ .loadpath .recommenders +.classpath +.project +target/ # External tool builders .externalToolBuilders/ diff --git a/README.md b/README.md deleted file mode 100644 index b41d319..0000000 --- a/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# xit-mms - -모바일 메시지 서비스 \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..7b4ee02 --- /dev/null +++ b/pom.xml @@ -0,0 +1,227 @@ + + + 4.0.0 + + cokr.xit.interfaces + xit-mms + 1.0.0-SNAPSHOT + 모바일 문자전송 서비스(mobile message service) + jar + + xit-mms + + + UTF-8 + 17 + ${java.version} + ${java.version} + + + + + mvn2s + https://repo1.maven.org/maven2/ + + true + + + true + + + + egovframe + https://maven.egovframe.go.kr/maven/ + + true + + + false + + + + maven-public + https://nas.xit.co.kr:8888/repository/maven-public/ + + + + + + maven-public + https://nas.xit.co.kr:8888/repository/maven-public/ + + true + + + false + + + + + + + + org.egovframe.rte + org.egovframe.psl.dataaccess + + + javax + javaee-api + + + + + + + + + cokr.xit.base + xit-foundation + 23.04.01-SNAPSHOT + + + + + org.mariadb.jdbc + mariadb-java-client + 2.7.2 + runtime + + + + + net.minidev + json-smart + 2.4.11 + + + + + cokr.xit.app + app-support-java + 1.0.0-SNAPSHOT + + + + + + install + ${basedir}/target + ${project.artifactId}-${project.version} + + + + ${basedir}/src/main/resources + + + + + ${basedir}/src/test/resources + ${basedir}/src/main/resources + + + + + + org.apache.maven.plugins + maven-resources-plugin + 3.3.1 + + true + + + + org.apache.maven.plugins + maven-compiler-plugin + + ${java.version} + ${java.version} + UTF-8 + + + + + org.codehaus.mojo + emma-maven-plugin + 1.0-alpha-3 + + + + org.apache.maven.plugins + maven-pmd-plugin + 3.1 + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.3.0 + + + **/*.* + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0 + + true + xml + + **/Abstract*.java + **/*Suite.java + + + **/*Test.java + + + + + org.codehaus.mojo + emma-maven-plugin + true + + + org.apache.maven.plugins + maven-source-plugin + 2.2 + + + attach-sources + + jar + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + + + + + + + + maven-snapshot + https://nas.xit.co.kr:8888/repository/maven-snapshots/ + + + + maven-release + https://nas.xit.co.kr:8888/repository/maven-releases/ + + + + + + \ No newline at end of file diff --git a/src/main/java/cokr/xit/interfaces/message/MessageEntity.java b/src/main/java/cokr/xit/interfaces/message/MessageEntity.java new file mode 100644 index 0000000..d4be517 --- /dev/null +++ b/src/main/java/cokr/xit/interfaces/message/MessageEntity.java @@ -0,0 +1,415 @@ +package cokr.xit.interfaces.message; + +import java.util.Arrays; + +import cokr.xit.foundation.AbstractEntity; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class MessageEntity extends AbstractEntity { + + /** + * 고유번호 + */ + private String msgKey; + + /** + * G/W에 전송할 아이디 + */ + private String subId; + + /** + * 사용자 고유 번호 + */ + private String userKey; + + /** + * 사용자 그룹 + */ + private String userGroup; + + /** + * 사용자 고유 아이디 + */ + private String userId; + + /** + * 사용자 JOB 아이디 + */ + private String userJobid; + + /** + * 전송라인(추후 요구 시 사용) + */ + private String centerKey; + + /** + * 메시지 전송 우선 순위(추후 요구 시 사용) + */ + private String msgPriority; + + /** + * 메시지 상태 값 + */ + private String msgState; + + /** + * 메시지 입력시간(DB 서버 시간 기준) + */ + private String inputDate; + + /** + * 메시지 예약일시 + */ + private String resDate; + + /** + * 메시지를 수집한 시간 + */ + private String queDate; + + /** + * 메시지를 전송한 시간 + */ + private String sentDate; + + /** + * 핸드폰에 전달된 시간 + */ + private String rsltDate; + + /** + * G/W에서 결과를 수신한 시간 + */ + private String reportDate; + + /** + * 결과처리 상세코드 + */ + private String rsltCode; + + /** + * 결과처리 통신사 + */ + private String rsltNet; + + /** + * 결과처리된 메시지 유형 + */ + private String rsltType; + + /** + * 결과처리 히스토리 재전송 횟수 + */ + private String sentCount; + + /** + * 결과처리 히스토리 전송 타입 + */ + private String historyMsgType; + + /** + * 결과처리 히스토리 결과처리 상세코드 + */ + private String historyRsltCode; + + /** + * 메시지 식별자코드 + */ + private String identifier; + + /** + * 수신 번호 + */ + private String phone; + + /** + * 발신 번호 + */ + private String callback; + + /** + * 전송 타입 1번째 + */ + private String msgType1; + + /** + * 메시지 내용에 대한 타입 1번째 + */ + private String contentsType1; + + /** + * 1번째 메시지 수집한 시간 + */ + private String queDate1; + + /** + * 1번째 메시지 전송한 시간 + */ + private String sentDate1; + + /** + * 전송 타입 2번째 + */ + private String msgType2; + + /** + * 메시지 내용에 대한 타입 2번째 + */ + private String contentsType2; + + /** + * 2번째 메시지 수집한 시간 + */ + private String queDate2; + + /** + * 2번째 메시지 전송한 시간 + */ + private String sentDate2; + + /** + * 전송 타입 3번째 + */ + private String msgType3; + + /** + * 메시지 내용에 대한 타입 3번째 + */ + private String contentsType3; + + /** + * 3번째 메시지 수집한 시간 + */ + private String queDate3; + + /** + * 3번째 메시지 전송한 시간 + */ + private String sentDate3; + + /** + * XMS 결과처리 상세코드 + */ + private String xmsRsltCode; + + /** + * XMS 결과처리 통신사 + */ + private String xmsRsltNet; + + /** + * XMS 핸드폰에 전달된 시간 + */ + private String xmsRsltDate; + + /** + * XMS G/W에서 결과를 수신한 시간 + */ + private String xmsReportDate; + + /** + * ALT 결과처리 상세코드 + */ + private String altRsltCode; + + /** + * ALT 결과처리 통신사 + */ + private String altRsltNet; + + /** + * ALT 핸드폰에 전달된 시간 + */ + private String altRsltDate; + + /** + * ALT G/W에서 결과를 수신한 시간 + */ + private String altReportDate; + + /** + * RCS 결과처리 상세코드 + */ + private String rcsRsltCode; + + /** + * RCS 결과처리 통신사 + */ + private String rcsRsltNet; + + /** + * RCS 핸드폰에 전달된 시간 + */ + private String rcsRsltDate; + + /** + * RCS G/W에서 결과를 수신한 시간 + */ + private String rcsReportDate; + + /** + * 메시지 타이틀(LMS/MMS) + */ + private String xmsSubject; + + /** + * 메시지 본문(SMS/LMS/MMS) + */ + private String xmsText; + + /** + * 파일경로를 포함한 파일명1(MMS) + */ + private String xmsFileName1; + + /** + * 파일경로를 포함한 파일명2(MMS) + */ + private String xmsFileName2; + + /** + * 파일경로를 포함한 파일명3(MMS) + */ + private String xmsFileName3; + + /** + * ALT 국가코드(ALT,ALI) + */ + private String altCountryCode; + + /** + * ALT 사용자 아이디(ALT,ALI) + */ + private String altSenderKey; + + /** + * ALT 등록된 템플릿 고유키(ALT,ALI) + */ + private String altTemplateCode; + + /** + * 메시지 본문(ALT,ALI) + */ + private String altJson; + + /** + * RCS 브랜드 키 + */ + private String rcsBrandKey; + + /** + * RCS 메시지 베이스 아이디 + */ + private String rcsMassageBaseId; + + /** + * 메시지 본문(RCS) + */ + private String rcsJson; + + /** + * 실패 사유 + */ + private String failRsn; + + /** + * 1차,2차,3차 메시지 유형 설정 + */ + public void configMsgTypes(String[] types) { + if(types != null) { + if(types.length == 1) { + this.setMsgType1(types[0]); + this.setMsgType2(null); + this.setMsgType3(null); + } else if(types.length == 2) { + this.setMsgType1(types[0]); + this.setMsgType2(types[1]); + this.setMsgType3(null); + } else if(types.length == 3) { + this.setMsgType1(types[0]); + this.setMsgType2(types[1]); + this.setMsgType3(types[2]); + } + } + } + + /** + * 메시지 유형별 콘텐츠 유형 + */ + public static String[] SMS = {"SMS"}; + public static String[] MMS = {"LMS","MMS"}; + public static String[] ALT = {"ALT","ALI","FRT","FRI","FRW"}; + public static String[] RCS = {"RCS","RCL","RCM","RCT","RCD","RCF","RIT"}; + + /** + * (1차,2차,3차 메시지 유형 설정 후)콘텐츠 유형 설정 + */ + public void configContentsTypeN(String contentsType) { + + String msgType = ""; + if(Arrays.asList(SMS).contains(contentsType)) { + msgType = "SMS"; + } else if(Arrays.asList(MMS).contains(contentsType)){ + msgType = "MMS"; + } else if(Arrays.asList(ALT).contains(contentsType)) { + msgType = "ALT"; + } else if(Arrays.asList(RCS).contains(contentsType)) { + msgType = "RCS"; + } + + if(msgType.equals(this.msgType1)) { + this.contentsType1 = contentsType; + } else if(msgType.equals(this.msgType2)) { + this.contentsType2 = contentsType; + } else if(msgType.equals(this.msgType3)) { + this.contentsType3 = contentsType; + } + + } + + /** + * 현재 메시지 엔티티의 RCS의 콘텐츠 유형 반환 + */ + public String findContentsTypeOfRCS() { + if("RCS".equals(this.msgType1)) { + return this.contentsType1; + } else if("RCS".equals(this.msgType2)){ + return this.contentsType2; + } else if("RCS".equals(this.msgType3)){ + return this.contentsType3; + } + return null; + } + + /** + * 현재 메시지 엔티티의 알림톡의 콘텐츠 유형 반환 + */ + public String findContentsTypeOfALT() { + if("ALT".equals(this.msgType1)) { + return this.contentsType1; + } else if("ALT".equals(this.msgType2)){ + return this.contentsType2; + } else if("ALT".equals(this.msgType3)){ + return this.contentsType3; + } + return null; + } + + /** + * 현재 메시지 엔티티의 XMS의 콘텐츠 유형 반환 + */ + public String findContentsTypeOfXMS() { + if("SMS".equals(this.msgType1) || "MMS".equals(this.msgType1)) { + return this.contentsType1; + } else if("SMS".equals(this.msgType2) || "MMS".equals(this.msgType2)) { + return this.contentsType2; + } else if("SMS".equals(this.msgType3) || "MMS".equals(this.msgType3)) { + return this.contentsType3; + } + return null; + } + +} diff --git a/src/main/java/cokr/xit/interfaces/message/MessageQuery.java b/src/main/java/cokr/xit/interfaces/message/MessageQuery.java new file mode 100644 index 0000000..059583c --- /dev/null +++ b/src/main/java/cokr/xit/interfaces/message/MessageQuery.java @@ -0,0 +1,57 @@ +package cokr.xit.interfaces.message; + +import cokr.xit.foundation.component.QueryRequest; + +public class MessageQuery extends QueryRequest { + private static final long serialVersionUID = 1L; + + private String sggCd; + + private String schInputYmdFrom; + private String schInputYmdTo; + + private String stngInfoType; //설정정보유형(01:게이트웨이ID,02:송신전화번호,03:서비스사용자ID,04:템플릿) + + private String msgPrps; //고장신고,사전알림,주차신고민원,기타민원 + private String msgDtlPrps; + + private String callback; + private String phone; + private String msgState; + + public String getSggCd() { + return ifEmpty(sggCd, () -> null); + } + + public T setSggCd(String sggCd) { + this.sggCd = sggCd; + return self(); + } + + public String getSchInputYmdFrom() { + return ifEmpty(schInputYmdFrom, () -> null); + } + + public T setSchInputYmdFrom(String schInputYmdFrom) { + this.schInputYmdFrom = schInputYmdFrom; + return self(); + } + + public String getSchInputYmdTo() { + return ifEmpty(schInputYmdTo, () -> null); + } + + public T setSchInputYmdTo(String schInputYmdTo) { + this.schInputYmdTo = schInputYmdTo; + return self(); + } + + public String getStngInfoType() { + return ifEmpty(stngInfoType, () -> null); + } + + public T setStngInfoType(String stngInfoType) { + this.stngInfoType = stngInfoType; + return self(); + } +} diff --git a/src/main/java/cokr/xit/interfaces/message/dao/MessageMapper.java b/src/main/java/cokr/xit/interfaces/message/dao/MessageMapper.java new file mode 100644 index 0000000..f176172 --- /dev/null +++ b/src/main/java/cokr/xit/interfaces/message/dao/MessageMapper.java @@ -0,0 +1,20 @@ +package cokr.xit.interfaces.message.dao; + +import java.util.List; + +import org.egovframe.rte.psl.dataaccess.mapper.Mapper; + +import cokr.xit.foundation.component.AbstractMapper; +import cokr.xit.foundation.data.DataObject; +import cokr.xit.interfaces.message.MessageEntity; +import cokr.xit.interfaces.message.MessageQuery; + +@Mapper("messageMapper") +public interface MessageMapper extends AbstractMapper { + + int insert(MessageEntity messageEntity); + + DataObject selectStng(MessageQuery messageQuery); + + List selectList(MessageQuery messageQuery); +} diff --git a/src/main/java/cokr/xit/interfaces/message/service/MessageService.java b/src/main/java/cokr/xit/interfaces/message/service/MessageService.java new file mode 100644 index 0000000..d903caa --- /dev/null +++ b/src/main/java/cokr/xit/interfaces/message/service/MessageService.java @@ -0,0 +1,16 @@ +package cokr.xit.interfaces.message.service; + +import java.util.List; +import java.util.Map; + +import cokr.xit.foundation.data.DataObject; +import cokr.xit.interfaces.message.MessageEntity; +import cokr.xit.interfaces.message.MessageQuery; + +public interface MessageService { + + Map regist(List messageEntity); + + List getList(MessageQuery messageQuery); + +} diff --git a/src/main/java/cokr/xit/interfaces/message/service/bean/MessageBean.java b/src/main/java/cokr/xit/interfaces/message/service/bean/MessageBean.java new file mode 100644 index 0000000..904be05 --- /dev/null +++ b/src/main/java/cokr/xit/interfaces/message/service/bean/MessageBean.java @@ -0,0 +1,33 @@ +package cokr.xit.interfaces.message.service.bean; + +import java.util.List; + +import javax.annotation.Resource; + +import org.springframework.stereotype.Component; + +import cokr.xit.foundation.component.AbstractBean; +import cokr.xit.foundation.data.DataObject; +import cokr.xit.interfaces.message.MessageEntity; +import cokr.xit.interfaces.message.MessageQuery; +import cokr.xit.interfaces.message.dao.MessageMapper; + +@Component("messageBean") +public class MessageBean extends AbstractBean { + + @Resource(name="messageMapper") + private MessageMapper messageMapper; + + public boolean regist(MessageEntity messageEntity) { + int result = messageMapper.insert(messageEntity); + return result == 1 ? true : false; + } + + public List getList(MessageQuery messageQuery) { + if(ifEmpty(messageQuery.getOrderBy(), ()->"").equals("")) { + messageQuery.setOrderBy("MSG_KEY"); + } + return messageMapper.selectList(messageQuery); + } + +} diff --git a/src/main/java/cokr/xit/interfaces/message/service/bean/MessageServiceBean.java b/src/main/java/cokr/xit/interfaces/message/service/bean/MessageServiceBean.java new file mode 100644 index 0000000..6a7dfa1 --- /dev/null +++ b/src/main/java/cokr/xit/interfaces/message/service/bean/MessageServiceBean.java @@ -0,0 +1,177 @@ +package cokr.xit.interfaces.message.service.bean; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.annotation.Resource; +import javax.sql.DataSource; + +import org.apache.ibatis.mapping.VendorDatabaseIdProvider; +import org.egovframe.rte.fdl.string.EgovStringUtil; +import org.springframework.stereotype.Service; + +import cokr.xit.applib.AppCmmnUtil; +import cokr.xit.applib.Hangul; +import cokr.xit.foundation.component.AbstractServiceBean; +import cokr.xit.foundation.data.DataObject; +import cokr.xit.interfaces.message.MessageEntity; +import cokr.xit.interfaces.message.MessageQuery; +import cokr.xit.interfaces.message.service.MessageService; + +@Service("messageService") +public class MessageServiceBean extends AbstractServiceBean implements MessageService { + + @Resource(name="databaseIdProvider") + private VendorDatabaseIdProvider databaseIdProvider; + + @Resource(name="dataSource") + private DataSource dataSource; + + @Resource(name="messageBean") + private MessageBean messageBean; + + @Override + public Map regist(List messageEntityList) { + + Map resultMap = new HashMap(); + + List successList = new ArrayList(); + List failList = new ArrayList(); + + String databaseId = databaseIdProvider.getDatabaseId(dataSource); + + for(MessageEntity messageEntity : messageEntityList) { + + boolean isSuccess = false; + + //발신전화 검증 + if(ifEmpty(messageEntity.getCallback(), ()->"").equals("")) { + isSuccess = false; + messageEntity.setFailRsn("발신 전화번호 없음"); + failList.add(messageEntity); + continue; + } + if(!AppCmmnUtil.isTelno(messageEntity.getCallback())) { + isSuccess = false; + messageEntity.setFailRsn("발신 가능한 전화번호 형식이 아님"); + failList.add(messageEntity); + continue; + } + //수신전화 검증 + if(ifEmpty(messageEntity.getPhone(), ()->"").equals("")) { + isSuccess = false; + messageEntity.setFailRsn("수신 전화번호 없음"); + failList.add(messageEntity); + continue; + } + if(!AppCmmnUtil.isReceivePhone(messageEntity.getPhone())) { + isSuccess = false; + messageEntity.setFailRsn("수신 가능한 전화번호 형식이 아님"); + failList.add(messageEntity); + continue; + } + //발송예약일시 검증 + if(!ifEmpty(messageEntity.getResDate(), ()->"").equals("")) { + if(!AppCmmnUtil.isDateTimeDigitPattern(messageEntity.getResDate())) { + isSuccess = false; + messageEntity.setFailRsn("발송예약일시가 연월일시분초 형식이 아님"); + failList.add(messageEntity); + continue; + } + } + + Hangul hangul = new Hangul(2); + + //알림톡 검증 + if(!EgovStringUtil.null2void(messageEntity.getAltSenderKey()).equals("")) { + String altJson = messageEntity.getAltJson(); + if(altJson.length() > 1000) { + isSuccess = false; + messageEntity.setFailRsn("알림톡 글자수(1000자) 초과"); + failList.add(messageEntity); + continue; + } + } + + //RCS 검증 + if(!EgovStringUtil.null2void(messageEntity.getRcsBrandKey()).equals("")) { + String rcsJson = messageEntity.getRcsJson(); + // + } + + //XMS 제목 바이트 수 + int xmsSubjectByteCnt = hangul.getByteLength(messageEntity.getXmsSubject()); + + //XMS 내용 바이트 수 + int xmsContentByteCnt = hangul.getByteLength(messageEntity.getXmsText()); + + //XMS 내용 바이트 수 보정(줄바꿈문자) + if(databaseId.equals("mariadb") || databaseId.equals("mysql")) { + int lineChageCount = this.countLineChangeForNuri2Maria(messageEntity.getXmsText()); + xmsContentByteCnt = xmsContentByteCnt - (lineChageCount*3); + } else { + int lineChageCount = this.countLineChangeForNuri2Oracle(messageEntity.getXmsText()); + xmsContentByteCnt = xmsContentByteCnt - lineChageCount; + } + + String contentsTypeOfXMS = messageEntity.findContentsTypeOfXMS(); + + //XMS 검증 + if("SMS".equals(contentsTypeOfXMS) && xmsContentByteCnt > 90) { + isSuccess = false; + messageEntity.setFailRsn("SMS 최대 바이트 수(90byte) 초과"); + failList.add(messageEntity); + continue; + } + if("LMS".equals(contentsTypeOfXMS)) { + if(xmsSubjectByteCnt > 30) { + isSuccess = false; + messageEntity.setFailRsn("LMS 제목 최대 바이트 수(30byte) 초과"); + failList.add(messageEntity); + continue; + } + if(xmsContentByteCnt > 2000) { + isSuccess = false; + messageEntity.setFailRsn("LMS 내용 최대 바이트 수(2000byte) 초과"); + failList.add(messageEntity); + continue; + } + } + + isSuccess = messageBean.regist(messageEntity); + if(isSuccess) { + successList.add(messageEntity); + } else { + failList.add(messageEntity); + } + } + + resultMap.put("successList", successList); + resultMap.put("failList", failList); + + return resultMap; + } + + public int countLineChangeForNuri2Oracle(String str) { + if(str == null || str.equals("")) { + return 0; + } + + return str.split("\r\n",-1).length - 1; + } + public int countLineChangeForNuri2Maria(String str) { + if(str == null || str.equals("")) { + return 0; + } + + return str.split("\\\\r\\\\n",-1).length - 1; + } + + @Override + public List getList(MessageQuery messageQuery) { + return messageBean.getList(messageQuery); + } + +} diff --git a/src/main/java/cokr/xit/interfaces/message/web/MessageController.java b/src/main/java/cokr/xit/interfaces/message/web/MessageController.java new file mode 100644 index 0000000..d9fe1eb --- /dev/null +++ b/src/main/java/cokr/xit/interfaces/message/web/MessageController.java @@ -0,0 +1,29 @@ +package cokr.xit.interfaces.message.web; + +import java.util.List; + +import javax.annotation.Resource; + +import org.springframework.stereotype.Controller; +import org.springframework.web.servlet.ModelAndView; + +import cokr.xit.foundation.data.DataObject; +import cokr.xit.foundation.web.AbstractController; +import cokr.xit.interfaces.message.MessageQuery; +import cokr.xit.interfaces.message.service.MessageService; + +@Controller +public class MessageController extends AbstractController { + + @Resource(name="messageService") + private MessageService messageService; + + + public ModelAndView list(MessageQuery messageQuery) { + ModelAndView mav = new ModelAndView("jsonView"); + + List list = messageService.getList(messageQuery); + + return setPagingInfo(mav, list, ""); + } +} diff --git a/src/main/java/cokr/xit/interfaces/message/web/MessageInterfaceController.java b/src/main/java/cokr/xit/interfaces/message/web/MessageInterfaceController.java new file mode 100644 index 0000000..b05eb98 --- /dev/null +++ b/src/main/java/cokr/xit/interfaces/message/web/MessageInterfaceController.java @@ -0,0 +1,196 @@ +package cokr.xit.interfaces.message.web; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.annotation.Resource; +import javax.sql.DataSource; + +import org.apache.ibatis.mapping.VendorDatabaseIdProvider; +import org.egovframe.rte.fdl.string.EgovStringUtil; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import cokr.xit.foundation.web.AbstractController; +import cokr.xit.interfaces.message.MessageEntity; +import cokr.xit.interfaces.message.MessageQuery; +import cokr.xit.interfaces.message.dao.MessageMapper; +import cokr.xit.interfaces.message.service.MessageService; +import net.minidev.json.JSONObject; + +@Controller("messageInterfaceController") +@RequestMapping(value = "/intf/message", name = "메시지 연계") +public class MessageInterfaceController extends AbstractController { + + @Resource(name="databaseIdProvider") + private VendorDatabaseIdProvider databaseIdProvider; + + @Resource(name="dataSource") + private DataSource dataSource; + + @Resource(name="messageService") + private MessageService messageService; + + @Resource(name="messageMapper") + private MessageMapper messageMapper; + + public final static String[] m_b_d = { + "{\"msg\":{\"body\":\"{description\":", + "},},}" + }; + public final static String[] t = { + "{\"text\":", + "}" + }; + + @PostMapping(name="문자전송 요청 등록", value="/regist") + public ModelAndView regist(@RequestBody JSONObject apiSpec) { + ModelAndView mav = new ModelAndView("jsonView"); + + //누리2모듈 아이디 찾기 + MessageQuery messageQuery = new MessageQuery(); + messageQuery.setStngInfoType("01"); + messageQuery.setSggCd(System.getProperty("sgg")); + String nuri2Id = messageMapper.selectStng(messageQuery).string("MODULE_ID"); + if(ifEmpty(nuri2Id, ()->"").equals("")) { + mav.addObject("failRsn", "문자발송모듈아이디 찾기 실패"); + mav.addObject("saved", false); + return mav; + } + + String reqSys = (String) apiSpec.get("reqSys"); //요청시스템(이노,진우,엑스아이티) + if(EgovStringUtil.null2void(reqSys).equals("")) { + mav.addObject("failRsn", "요청시스템이 없습니다."); + mav.addObject("saved", false); + return mav; + } + + String msgPrps = (String) apiSpec.get("msgPrps"); //목적(고장신고,사전알림,주차신고민원,기타민원) + if(EgovStringUtil.null2void(msgPrps).equals("")) { + mav.addObject("failRsn", "메시지 발송 목적이 없습니다."); + mav.addObject("saved", false); + return mav; + } + + String msgDtlPrps = (String) apiSpec.get("msgDtlPrps"); //상세목적 + + String sggCd = (String) apiSpec.get("sggCd"); //시군구코드 + + String databaseId = databaseIdProvider.getDatabaseId(dataSource); + + List messageEntityList = new ArrayList(); + List reqs = (List) apiSpec.get("reqs"); + for(Map req : reqs) { + MessageEntity messageEntity = new MessageEntity(); + messageEntity.setSubId(nuri2Id); + + String trnsmisNo = (String) req.get("trnsmisNo"); + String recptnNo = (String) req.get("recptnNo"); + String mssageCn = (String) req.get("mssageCn"); + String resDate = (String) req.get("resDate"); + + messageEntity.setCallback(trnsmisNo); + messageEntity.setPhone(recptnNo); + + if(databaseId.equals("mariadb") || databaseId.equals("mysql")){ + mssageCn = this.replaceLineChangeForNuri2Maria(mssageCn); + } else { + mssageCn = this.replaceLineChangeForNuri2Oracle(mssageCn); + } + + if(!EgovStringUtil.null2void(resDate).equals("")) { + messageEntity.setResDate(resDate); + } + + boolean able_kko = false; //알림톡 가능 여부 + boolean able_rcs = false; //RCS 가능 여부 + + if(able_kko && able_rcs) { // 알림톡+RCS+XMS + messageEntity.configMsgTypes(new String[]{"ALT","RCS","MMS"}); + messageEntity.configContentsTypeN("ALT"); + messageEntity.configContentsTypeN("RCL"); + messageEntity.configContentsTypeN("LMS"); + } else if(able_kko && !able_rcs) { // 알림톡+XMS + messageEntity.configMsgTypes(new String[]{"ALT","MMS"}); + messageEntity.configContentsTypeN("ALT"); + messageEntity.configContentsTypeN("LMS"); + messageEntity.setXmsText(mssageCn); + } else if(!able_kko && able_rcs){ // RCS+XMS + messageEntity.configMsgTypes(new String[]{"RCS","MMS"}); + messageEntity.configContentsTypeN("RCL"); + messageEntity.configContentsTypeN("LMS"); + messageEntity.setXmsText(mssageCn); + } else {// XMS + messageEntity.configMsgTypes(new String[]{"MMS"}); + messageEntity.configContentsTypeN("LMS"); + } + messageEntity.setXmsText(mssageCn); + + + + + if(able_kko) { + String json = t[0] + mssageCn + t[1]; + + messageEntity.setAltSenderKey("신청한센더키"); + messageEntity.setAltTemplateCode("신청한템플릿코드"); + + messageEntity.setAltJson(json); + + + } + + if(able_rcs) { + + messageEntity.setRcsBrandKey("신청한브랜드키"); + + String json = ""; + String contentsTypeOfRCS = messageEntity.findContentsTypeOfRCS(); + + if("RCS".equals(contentsTypeOfRCS)) { + messageEntity.setRcsMassageBaseId("SS000000"); + } else if("RCL".equals(contentsTypeOfRCS)) { + messageEntity.setRcsMassageBaseId("SL000000"); + } else { + + throw new RuntimeException(""); + //RCT //baseid 발급 필요 + //RLT //RCT의 오타 + //RCD,RCF //baseId 발급 필요,mgov예제에 없는 형식 + //RCM,RIT //baseId 발급 필요,필요하지 않는 형식(미디어 첨부) + } + + json = m_b_d[0] + mssageCn + m_b_d[1]; + + messageEntity.setRcsJson(json); + } + messageEntityList.add(messageEntity); + } + + // + + Map resultMap = messageService.regist(messageEntityList); + + mav.addObject("resultMap", resultMap); + mav.addObject("saved",true); + return mav; + } + + public String replaceLineChangeForNuri2Oracle(String str) { + String result = ""; + result = str.replaceAll("\r",""); + result = result.replaceAll("\n","\r\n"); + return result; + } + + public String replaceLineChangeForNuri2Maria(String str) { + String result = ""; + result = str.replaceAll("\r",""); + result = result.replaceAll("\n", "\\\\r\\\\n"); + return result; + } +} diff --git a/src/main/resources/sql/mapper/interfaces/message-mapper.xml b/src/main/resources/sql/mapper/interfaces/message-mapper.xml new file mode 100644 index 0000000..13eb521 --- /dev/null +++ b/src/main/resources/sql/mapper/interfaces/message-mapper.xml @@ -0,0 +1,192 @@ + + + + + + + +/* 문자전송 요청 등록(msgMapper.insert) */ +INSERT + INTO NURI2_NRMSG_DATA ( + SUB_ID + , USER_KEY, USER_GROUP, USER_ID, USER_JOBID + , INPUT_DATE + , INPUT_DT + , RES_DATE + , RES_DT + , IDENTIFIER + , PHONE, CALLBACK + , MSG_TYPE_1, CONTENTS_TYPE_1 + , MSG_TYPE_2, CONTENTS_TYPE_2 + , MSG_TYPE_3, CONTENTS_TYPE_3 + , XMS_SUBJECT + , XMS_TEXT + + , ALT_COUNTRY_CODE + , ALT_SENDER_KEY + , ALT_TEMPLATE_CODE + , ALT_JSON + + + , RCS_BRAND_KEY + , RCS_MASSAGE_BASE_ID + , RCS_JSON + + + + + + + + + + + + +) +VALUES ( + #{subId} + , #{userKey}, #{userGroup}, #{userId}, #{userJobid} + , CURRENT_TIMESTAMP + , + + + , CURRENT_TIMESTAMP + , + + + + , STR_TO_DATE(#{resDate},'%Y%m%d%H%i%s') + + + , TO_DATE(#{resDate},'YYYYMMDDHH24MISS') + + , #{resDate} + + , #{identifier} + , #{phone}, #{callback} + , #{msgType1}, #{contentsType1} + , #{msgType2}, #{contentsType2} + , #{msgType3}, #{contentsType3} + , #{xmsSubject} + , #{xmsText} + + , '82' + , #{altSenderKey} + , #{altTemplateCode} + , #{altJson} + + + , #{rcsBrandKey} + , #{rcsMassageBaseId} + , #{rcsJson} + + + + + + + + + + + + +) + + + + + \ No newline at end of file