diff --git a/src/main/java/cokr/xit/interfaces/message/MessageUtil.java b/src/main/java/cokr/xit/interfaces/message/MessageUtil.java new file mode 100644 index 0000000..a6600e0 --- /dev/null +++ b/src/main/java/cokr/xit/interfaces/message/MessageUtil.java @@ -0,0 +1,53 @@ +package cokr.xit.interfaces.message; + +import cokr.xit.applib.Hangul; + +public class MessageUtil { + + public static String replaceLineChangeForNuri2Oracle(String str) { + String result = ""; + result = str.replaceAll("\r",""); + result = result.replaceAll("\n","\r\n"); + return result; + } + + public static String replaceLineChangeForNuri2Maria(String str) { + String result = ""; + result = str.replaceAll("\r",""); + result = result.replaceAll("\n", "\\\\r\\\\n"); + return result; + } + + public static int countLineChangeForNuri2Oracle(String str) { + if(str == null || str.equals("")) { + return 0; + } + + return str.split("\r\n",-1).length - 1; + } + + public static int countLineChangeForNuri2Maria(String str) { + if(str == null || str.equals("")) { + return 0; + } + + return str.split("\\\\r\\\\n",-1).length - 1; + } + + public static int countBytes(String str, int hangulBytes, String db) { + + Hangul hangul = new Hangul(hangulBytes); + + int contentsByteCnt = hangul.getByteLength(str); + if(db.equals("mariadb") || db.equals("mysql")) { + int lineChangeCnt = countLineChangeForNuri2Maria(str); + contentsByteCnt = contentsByteCnt - (lineChangeCnt*3); + } else { + int lineChangeCnt = countLineChangeForNuri2Oracle(str); + contentsByteCnt = contentsByteCnt - lineChangeCnt; + } + + return contentsByteCnt; + } + +} 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 index 6a7dfa1..0fd6f46 100644 --- a/src/main/java/cokr/xit/interfaces/message/service/bean/MessageServiceBean.java +++ b/src/main/java/cokr/xit/interfaces/message/service/bean/MessageServiceBean.java @@ -18,6 +18,7 @@ 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.MessageUtil; import cokr.xit.interfaces.message.service.MessageService; @Service("messageService") @@ -109,10 +110,10 @@ public class MessageServiceBean extends AbstractServiceBean implements MessageSe //XMS 내용 바이트 수 보정(줄바꿈문자) if(databaseId.equals("mariadb") || databaseId.equals("mysql")) { - int lineChageCount = this.countLineChangeForNuri2Maria(messageEntity.getXmsText()); + int lineChageCount = MessageUtil.countLineChangeForNuri2Maria(messageEntity.getXmsText()); xmsContentByteCnt = xmsContentByteCnt - (lineChageCount*3); } else { - int lineChageCount = this.countLineChangeForNuri2Oracle(messageEntity.getXmsText()); + int lineChageCount = MessageUtil.countLineChangeForNuri2Oracle(messageEntity.getXmsText()); xmsContentByteCnt = xmsContentByteCnt - lineChageCount; } @@ -154,21 +155,6 @@ public class MessageServiceBean extends AbstractServiceBean implements MessageSe 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/MessageInterfaceController.java b/src/main/java/cokr/xit/interfaces/message/web/MessageInterfaceController.java index 9e5d413..0ccdae6 100644 --- a/src/main/java/cokr/xit/interfaces/message/web/MessageInterfaceController.java +++ b/src/main/java/cokr/xit/interfaces/message/web/MessageInterfaceController.java @@ -15,9 +15,11 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; +import cokr.xit.foundation.data.DataObject; import cokr.xit.foundation.web.AbstractController; import cokr.xit.interfaces.message.MessageEntity; import cokr.xit.interfaces.message.MessageQuery; +import cokr.xit.interfaces.message.MessageUtil; import cokr.xit.interfaces.message.dao.MessageMapper; import cokr.xit.interfaces.message.service.MessageService; import net.minidev.json.JSONObject; @@ -55,13 +57,19 @@ public class MessageInterfaceController extends AbstractController { 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; + + DataObject stng = messageMapper.selectStng(messageQuery); + String nuri2Id = ""; + if(stng != null && !stng.isEmpty()) { + nuri2Id = stng.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", "요청시스템이 없습니다."); @@ -116,40 +124,55 @@ public class MessageInterfaceController extends AbstractController { messageEntity.setPhone(recptnNo); if(databaseId.equals("mariadb") || databaseId.equals("mysql")){ - mssageCn = this.replaceLineChangeForNuri2Maria(mssageCn); + mssageCn = MessageUtil.replaceLineChangeForNuri2Maria(mssageCn); } else { - mssageCn = this.replaceLineChangeForNuri2Oracle(mssageCn); + mssageCn = MessageUtil.replaceLineChangeForNuri2Oracle(mssageCn); } if(!EgovStringUtil.null2void(resDate).equals("")) { messageEntity.setResDate(resDate); } + + String XMS_msgType = ""; + String XMS_contentsType = ""; + int xmsByteCount = MessageUtil.countBytes(mssageCn,2,databaseId); + if(xmsByteCount <= 90) { + XMS_msgType = "SMS"; + XMS_contentsType = "SMS"; + } else { + XMS_msgType = "MMS"; + XMS_contentsType = "LMS"; + } + boolean able_kko = false; //알림톡 가능 여부 boolean able_rcs = false; //RCS 가능 여부 if(able_kko && able_rcs) { // 알림톡+RCS+XMS - messageEntity.configMsgTypes(new String[]{"ALT","RCS","MMS"}); + messageEntity.configMsgTypes(new String[]{"ALT","RCS",XMS_msgType}); messageEntity.configContentsTypeN("ALT"); messageEntity.configContentsTypeN("RCL"); - messageEntity.configContentsTypeN("LMS"); + messageEntity.configContentsTypeN(XMS_contentsType); } else if(able_kko && !able_rcs) { // 알림톡+XMS - messageEntity.configMsgTypes(new String[]{"ALT","MMS"}); + messageEntity.configMsgTypes(new String[]{"ALT",XMS_msgType}); messageEntity.configContentsTypeN("ALT"); - messageEntity.configContentsTypeN("LMS"); + messageEntity.configContentsTypeN(XMS_contentsType); messageEntity.setXmsText(mssageCn); } else if(!able_kko && able_rcs){ // RCS+XMS - messageEntity.configMsgTypes(new String[]{"RCS","MMS"}); + messageEntity.configMsgTypes(new String[]{"RCS",XMS_msgType}); messageEntity.configContentsTypeN("RCL"); - messageEntity.configContentsTypeN("LMS"); + messageEntity.configContentsTypeN(XMS_contentsType); messageEntity.setXmsText(mssageCn); } else {// XMS - messageEntity.configMsgTypes(new String[]{"MMS"}); - messageEntity.configContentsTypeN("LMS"); + messageEntity.configMsgTypes(new String[]{XMS_msgType}); + messageEntity.configContentsTypeN(XMS_contentsType); } - messageEntity.setXmsText(mssageCn); + messageEntity.setXmsText(mssageCn); + if(XMS_msgType.equals("MMS")) { + messageEntity.setXmsSubject("민원 처리결과 알림"); + } if(able_kko) { @@ -199,18 +222,6 @@ public class MessageInterfaceController extends AbstractController { 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 index 7c4211f..9df0ebf 100644 --- a/src/main/resources/sql/mapper/interfaces/message-mapper.xml +++ b/src/main/resources/sql/mapper/interfaces/message-mapper.xml @@ -3,7 +3,7 @@ -/* 문자전송 요청 등록(msgMapper.insert) */ +/* 문자전송 요청 등록(messageMapper.insert) */ INSERT INTO NURI2_NRMSG_DATA ( SUB_ID @@ -131,7 +131,12 @@ INSERT , TASK_SE_CD ) VALUES ( + #{subId} + + + NULL + , #{userKey}, #{userGroup}, #{userId}, #{userJobid} , CURRENT_TIMESTAMP , @@ -186,8 +191,8 @@ VALUES ( ) - +/* 문자전송 설정 정보 조회(messageMapper.selectStng) */ SELECT MSG_STNG_ID , SGG_CD , STNG_INFO_TYPE @@ -203,7 +208,7 @@ SELECT MSG_STNG_ID FROM TB_MSG_STNG WHERE STNG_INFO_TYPE = #{stngInfoType} AND USE_YN = 'Y' - + AND SGG_CD = #{sggCd}