diff --git a/src/main/java/cokr/xit/fims/mngt/service/bean/MsgServiceBean.java b/src/main/java/cokr/xit/fims/mngt/service/bean/MsgServiceBean.java index 23ad2d73..4516a735 100644 --- a/src/main/java/cokr/xit/fims/mngt/service/bean/MsgServiceBean.java +++ b/src/main/java/cokr/xit/fims/mngt/service/bean/MsgServiceBean.java @@ -6,7 +6,9 @@ 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; @@ -21,6 +23,12 @@ import cokr.xit.foundation.data.DataObject; @Service("msgService") public class MsgServiceBean extends AbstractServiceBean implements MsgService { + @Resource(name="databaseIdProvider") + private VendorDatabaseIdProvider databaseIdProvider; + + @Resource(name="dataSource") + private DataSource dataSource; + @Resource(name="msgBean") private MsgBean msgBean; @@ -31,11 +39,14 @@ public class MsgServiceBean extends AbstractServiceBean implements MsgService { @Override public Map regist(List msgEntityList) { + Map resultMap = new HashMap(); List successList = new ArrayList(); List failList = new ArrayList(); + String databaseId = databaseIdProvider.getDatabaseId(dataSource); + for(MsgEntity msgEntity : msgEntityList) { boolean isSuccess = false; @@ -86,24 +97,37 @@ public class MsgServiceBean extends AbstractServiceBean implements MsgService { // } - int xmlSubjectByteCnt = hangul.getByteLength(msgEntity.getXmsSubject()); - int xmlContentByteCnt = hangul.getByteLength(msgEntity.getXmsText()); + //XMS 제목 바이트 수 + int xmsSubjectByteCnt = hangul.getByteLength(msgEntity.getXmsSubject()); + + //XMS 내용 바이트 수 + int xmsContentByteCnt = hangul.getByteLength(msgEntity.getXmsText()); + + //XMS 내용 바이트 수 보정(줄바꿈문자) + if(databaseId.equals("mariadb") || databaseId.equals("mysql")) { + int lineChageCount = this.countLineChangeForNuri2Maria(msgEntity.getXmsText()); + xmsContentByteCnt = xmsContentByteCnt - (lineChageCount*3); + } else { + int lineChageCount = this.countLineChangeForNuri2Oracle(msgEntity.getXmsText()); + xmsContentByteCnt = xmsContentByteCnt - lineChageCount; + } + String contentsTypeOfXMS = msgEntity.getContentsTypeOfXMS(); - if("SMS".equals(contentsTypeOfXMS) && xmlContentByteCnt > 90) { + if("SMS".equals(contentsTypeOfXMS) && xmsContentByteCnt > 90) { isSuccess = false; msgEntity.setFailRsn("SMS 최대 바이트 수(90byte) 초과"); failList.add(msgEntity); continue; } if("LMS".equals(contentsTypeOfXMS)) { - if(xmlSubjectByteCnt > 30) { + if(xmsSubjectByteCnt > 30) { isSuccess = false; msgEntity.setFailRsn("LMS 제목 최대 바이트 수(30byte) 초과"); failList.add(msgEntity); continue; } - if(xmlContentByteCnt > 2000) { + if(xmsContentByteCnt > 2000) { isSuccess = false; msgEntity.setFailRsn("LMS 내용 최대 바이트 수(2000byte) 초과"); failList.add(msgEntity); @@ -125,4 +149,18 @@ public class MsgServiceBean extends AbstractServiceBean implements MsgService { 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; + } } diff --git a/src/main/java/cokr/xit/fims/rent/web/RentInterfaceController.java b/src/main/java/cokr/xit/fims/rent/web/RentInterfaceController.java index 025be0ee..62c7201f 100644 --- a/src/main/java/cokr/xit/fims/rent/web/RentInterfaceController.java +++ b/src/main/java/cokr/xit/fims/rent/web/RentInterfaceController.java @@ -5,7 +5,9 @@ import java.util.List; import java.util.Map; import javax.annotation.Resource; +import javax.sql.DataSource; +import org.apache.ibatis.mapping.VendorDatabaseIdProvider; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -23,6 +25,12 @@ import net.minidev.json.JSONObject; @RequestMapping(value = "/intf/rent", name = "렌트카 관련 연계") public class RentInterfaceController extends ApplicationController { + @Resource(name="databaseIdProvider") + private VendorDatabaseIdProvider databaseIdProvider; + + @Resource(name="dataSource") + private DataSource dataSource; + @Resource(name="msgService") private MsgService msgService; @@ -61,6 +69,8 @@ public class RentInterfaceController extends ApplicationController { mav.addObject("saved", false); } + String databaseId = databaseIdProvider.getDatabaseId(dataSource); + List reqs = (List) apiSpec.get("reqs"); for(Map req : reqs) { MsgEntity msgEntity = new MsgEntity(); @@ -74,6 +84,12 @@ public class RentInterfaceController extends ApplicationController { msgEntity.setCallback(trnsmisNo); msgEntity.setPhone(recptnNo); + if(databaseId.equals("mariadb") || databaseId.equals("mysql")){ + mssageCn = this.replaceLineChangeForNuri2Maria(mssageCn); + } else { + mssageCn = this.replaceLineChangeForNuri2Oracle(mssageCn); + } + boolean able_kko = false; //알림톡 가능 여부 boolean able_rcs = false; //RCS 가능 여부 @@ -147,4 +163,18 @@ public class RentInterfaceController extends ApplicationController { 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; + } }