You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
427 lines
13 KiB
Java
427 lines
13 KiB
Java
package cokr.xit.interfaces.message.web;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
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.applib.AppCmmnUtil;
|
|
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;
|
|
|
|
@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(HttpServletRequest hreq, @RequestBody JSONObject apiSpec) {
|
|
|
|
String dmndIp = AppCmmnUtil.getClientIpAddr(hreq);
|
|
|
|
ModelAndView mav = new ModelAndView("jsonView");
|
|
|
|
MessageUtil forPlainText = new MessageUtil("plain");
|
|
MessageUtil forJsonText = new MessageUtil("json");
|
|
|
|
String sggCd = (String) apiSpec.get("sggCd"); //시군구코드
|
|
if(EgovStringUtil.null2void(sggCd).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 taskSeCd = (String) apiSpec.get("taskSeCd"); //과태료업무구분
|
|
if(taskSeCd == null) {
|
|
taskSeCd = "";
|
|
}
|
|
|
|
String systemSgg = System.getProperty("sgg");
|
|
|
|
//누리2모듈 관리 아이디 찾기
|
|
String nuri2Id = "";
|
|
MessageQuery messageQuery = new MessageQuery().setSggCd(systemSgg).setStngInfoType("01").setMsgPrps(msgPrps)
|
|
.setTaskSeCd(taskSeCd);
|
|
DataObject stng = messageMapper.selectStng(messageQuery);
|
|
if(stng != null && !stng.isEmpty()) {
|
|
nuri2Id = stng.string("MODULE_ID");
|
|
}
|
|
|
|
//메시지서비스 선순위 정책 찾기
|
|
String priorOrderPolicy = "";
|
|
messageQuery = new MessageQuery().setSggCd(systemSgg).setStngInfoType("05").setMsgPrps(msgPrps)
|
|
.setTaskSeCd(taskSeCd);
|
|
stng = messageMapper.selectStng(messageQuery);
|
|
if(stng != null && !stng.isEmpty()) {
|
|
priorOrderPolicy = stng.string("PRORD_PLCY");
|
|
}
|
|
|
|
//발신전화번호 찾기
|
|
String callbackNo = "";
|
|
messageQuery = new MessageQuery().setSggCd(systemSgg).setStngInfoType("04").setMsgPrps(msgPrps)
|
|
.setTaskSeCd(taskSeCd);
|
|
stng = messageMapper.selectStng(messageQuery);
|
|
if(stng != null && !stng.isEmpty()) {
|
|
callbackNo = stng.string("TELNO");
|
|
} else {
|
|
mav.addObject("failRsn", "발신전화번호 조회 실패");
|
|
mav.addObject("saved", false);
|
|
return mav;
|
|
}
|
|
|
|
//XMS템플릿 찾기
|
|
String xmsTemplate = "";
|
|
String xmsTitle = "";
|
|
messageQuery = new MessageQuery().setSggCd(systemSgg).setStngInfoType("02").setMsgPrps(msgPrps)
|
|
.setTaskSeCd(taskSeCd).setSvcType("XMS");
|
|
stng = messageMapper.selectStng(messageQuery);
|
|
if(stng == null || stng.isEmpty()) {
|
|
mav.addObject("failRsn", "XMS 템플릿 조회 실패");
|
|
mav.addObject("saved", false);
|
|
return mav;
|
|
} else {
|
|
xmsTitle = stng.string("TMPLT_TITLE");
|
|
xmsTemplate = stng.string("TMPLT_CN");
|
|
}
|
|
|
|
|
|
//카카오프로필키 찾기
|
|
String kkoSenderKey = "";
|
|
String kkoTemplateKey = "";
|
|
String kkoTemplate = "";
|
|
messageQuery = new MessageQuery().setSggCd(systemSgg).setStngInfoType("03").setMsgPrps(msgPrps)
|
|
.setTaskSeCd(taskSeCd).setSvcType("ALT");
|
|
stng = messageMapper.selectStng(messageQuery);
|
|
if(stng != null && !stng.isEmpty()) {
|
|
kkoSenderKey = stng.string("SVC_USER_ID");
|
|
if(!kkoSenderKey.equals("")) {
|
|
//알림톡템플릿찾기
|
|
messageQuery = new MessageQuery().setSggCd(systemSgg).setStngInfoType("02").setMsgPrps(msgPrps)
|
|
.setTaskSeCd(taskSeCd).setSvcType("ALT");
|
|
stng = messageMapper.selectStng(messageQuery);
|
|
if(stng != null && !stng.isEmpty()) {
|
|
kkoTemplateKey = stng.string("TMPLAT_ID");
|
|
kkoTemplate = stng.string("TMPLT_CN");
|
|
}
|
|
}
|
|
}
|
|
|
|
//RCS브랜드아이디 찾기
|
|
String rcsBrandKey = "";
|
|
String rcsTemplate = "";
|
|
messageQuery = new MessageQuery().setSggCd(systemSgg).setStngInfoType("03").setMsgPrps(msgPrps)
|
|
.setTaskSeCd(taskSeCd).setSvcType("RCS");
|
|
stng = messageMapper.selectStng(messageQuery);
|
|
if(stng != null && !stng.isEmpty()) {
|
|
rcsBrandKey = stng.string("SVC_USER_ID");
|
|
if(!EgovStringUtil.null2void(rcsBrandKey).equals("")) {
|
|
//RCS템플릿찾기
|
|
messageQuery = new MessageQuery().setSggCd(systemSgg).setStngInfoType("02").setMsgPrps(msgPrps)
|
|
.setTaskSeCd(taskSeCd).setSvcType("RCS");
|
|
stng = messageMapper.selectStng(messageQuery);
|
|
if(stng != null && !stng.isEmpty()) {
|
|
rcsTemplate = stng.string("TMPLT_CN");
|
|
}
|
|
}
|
|
}
|
|
|
|
String msgDtlPrps = (String) apiSpec.get("msgDtlPrps"); //상세목적
|
|
if(msgDtlPrps == null) {
|
|
msgDtlPrps = "";
|
|
}
|
|
|
|
|
|
|
|
String databaseId = databaseIdProvider.getDatabaseId(dataSource);
|
|
|
|
List<MessageEntity> messageEntityList = new ArrayList<MessageEntity>();
|
|
List<Map<String,Object>> reqs = (List<Map<String,Object>>) apiSpec.get("reqs");
|
|
for(Map<String,Object> req : reqs) {
|
|
|
|
MessageEntity messageEntity = new MessageEntity();
|
|
messageEntity.setDmndIp(dmndIp);
|
|
messageEntity.setSubId(nuri2Id);
|
|
|
|
messageEntity.setSggCd(sggCd);
|
|
messageEntity.setReqSys(reqSys);
|
|
messageEntity.setMsgPrps(msgPrps);
|
|
messageEntity.setMsgDtlPrps(msgDtlPrps);
|
|
messageEntity.setTaskSeCd(taskSeCd);
|
|
|
|
|
|
String recptnNo = (String) req.get("recptnNo");
|
|
|
|
String resDate = (String) req.get("resDate");
|
|
|
|
messageEntity.setCallback(callbackNo);
|
|
messageEntity.setPhone(recptnNo);
|
|
|
|
List<HashMap<String, String>> args = (List<HashMap<String, String>>) req.get("args");
|
|
if(args == null) {
|
|
args = new ArrayList<HashMap<String, String>>();
|
|
}
|
|
|
|
//예약발송일시
|
|
if(!EgovStringUtil.null2void(resDate).equals("")) {
|
|
messageEntity.setResDate(resDate);
|
|
}
|
|
|
|
//
|
|
String XMS_msgType = "";
|
|
String XMS_contentsType = "";
|
|
String xmsPlainComplete = "";
|
|
|
|
|
|
String altJsonComplete = "";
|
|
boolean able_kko = false; //알림톡 가능 여부
|
|
|
|
if(!kkoTemplateKey.equals("") && !kkoTemplate.equals("")) {
|
|
|
|
altJsonComplete = kkoTemplate;
|
|
|
|
try {
|
|
//변수매핑하기
|
|
for(HashMap arg : args) {
|
|
String argName = (String)arg.get("argName");
|
|
String argValue = (String)arg.get("argValue");
|
|
|
|
String replacedArgValue = "";
|
|
//탭문자 치환
|
|
replacedArgValue = argValue.replaceAll("\t", " ");
|
|
//역슬래시문자 치환
|
|
replacedArgValue = replacedArgValue.replace("\\", "\\\\");
|
|
//개행문자 치환
|
|
if(databaseId.equals("mariadb") || databaseId.equals("mysql")){
|
|
replacedArgValue = forJsonText.replaceLineChangeForNuri2Maria(replacedArgValue);
|
|
} else {
|
|
replacedArgValue = forJsonText.replaceLineChangeForNuri2Oracle(replacedArgValue);
|
|
}
|
|
|
|
altJsonComplete = altJsonComplete.replace("{{"+argName+"}}", replacedArgValue);
|
|
}
|
|
} catch (Exception e) {
|
|
messageEntity.setFailRsn("알림톡 템플릿 변수 매핑 오류");
|
|
messageEntityList.add(messageEntity);
|
|
continue;
|
|
}
|
|
|
|
able_kko = true;
|
|
}
|
|
|
|
|
|
String RCS_contentsType = "";
|
|
String rcsJsonComplete = "";
|
|
boolean able_rcs = false; //RCS 가능 여부
|
|
String rcsBaseId = "";
|
|
|
|
if(!EgovStringUtil.null2void(rcsTemplate).equals("")) {
|
|
|
|
rcsJsonComplete = rcsTemplate;
|
|
|
|
try {
|
|
//변수매핑하기
|
|
for(HashMap arg : args) {
|
|
String argName = (String)arg.get("argName");
|
|
String argValue = (String)arg.get("argValue");
|
|
String replacedArgValue = "";
|
|
|
|
//탭문자 치환
|
|
replacedArgValue = argValue.replaceAll("\t", " ");
|
|
//역슬래시문자 치환
|
|
replacedArgValue = replacedArgValue.replace("\\", "\\\\");
|
|
//개행문자 치환
|
|
if(databaseId.equals("mariadb") || databaseId.equals("mysql")){
|
|
replacedArgValue = forJsonText.replaceLineChangeForNuri2Maria(replacedArgValue);
|
|
} else {
|
|
replacedArgValue = forJsonText.replaceLineChangeForNuri2Oracle(replacedArgValue);
|
|
}
|
|
|
|
rcsJsonComplete = rcsJsonComplete.replace("{{"+argName+"}}", replacedArgValue);
|
|
}
|
|
} catch (Exception e) {
|
|
messageEntity.setFailRsn("RCS 템플릿 변수 매핑 오류");
|
|
messageEntityList.add(messageEntity);
|
|
continue;
|
|
}
|
|
|
|
//description부 구하기
|
|
String description = "";
|
|
try {
|
|
description = forJsonText.getRcsDescription(rcsJsonComplete);
|
|
}catch(Exception e) {
|
|
messageEntity.setFailRsn("RCS JSON 파싱 오류");
|
|
messageEntityList.add(messageEntity);
|
|
continue;
|
|
}
|
|
if(description.equals("")) {
|
|
messageEntity.setFailRsn("RCS JSON 파싱 오류(본문내용없음)");
|
|
messageEntityList.add(messageEntity);
|
|
continue;
|
|
}
|
|
|
|
//description부 글자수 계산하기
|
|
int rcsCharCount = description.length();
|
|
|
|
if(rcsCharCount <= 100) {
|
|
RCS_contentsType = "RCS";
|
|
rcsBaseId = "SS000000";
|
|
} else {
|
|
RCS_contentsType = "RCL";
|
|
rcsBaseId = "SL000000";
|
|
}
|
|
|
|
able_rcs = true;
|
|
|
|
}
|
|
|
|
|
|
xmsPlainComplete = xmsTemplate;
|
|
|
|
try {
|
|
//변수매핑하기
|
|
for(HashMap arg : args) {
|
|
String argName = (String)arg.get("argName");
|
|
String argValue = (String)arg.get("argValue");
|
|
String replacedArgValue = "";
|
|
|
|
//탭문자 치환
|
|
replacedArgValue = argValue.replaceAll("\t", " ");
|
|
//개행문자 치환
|
|
if(databaseId.equals("mariadb") || databaseId.equals("mysql")){
|
|
replacedArgValue = forPlainText.replaceLineChangeForNuri2Maria(replacedArgValue);
|
|
} else {
|
|
replacedArgValue = forPlainText.replaceLineChangeForNuri2Oracle(replacedArgValue);
|
|
}
|
|
|
|
xmsPlainComplete = xmsPlainComplete.replace("{{"+argName+"}}", replacedArgValue);
|
|
}
|
|
} catch(Exception e) {
|
|
messageEntity.setFailRsn("xMS 템플릿 변수 매핑 오류");
|
|
messageEntityList.add(messageEntity);
|
|
continue;
|
|
}
|
|
|
|
//글자수 계산
|
|
int xmsByteCount = forPlainText.countBytes(xmsPlainComplete,2,databaseId);
|
|
if(xmsByteCount <= 90) {
|
|
XMS_msgType = "SMS";
|
|
XMS_contentsType = "SMS";
|
|
} else {
|
|
XMS_msgType = "MMS";
|
|
XMS_contentsType = "LMS";
|
|
}
|
|
if(XMS_msgType.equals("MMS")) {
|
|
messageEntity.setXmsSubject(xmsTitle);
|
|
}
|
|
|
|
if(able_kko && able_rcs) { // 알림톡+RCS+XMS
|
|
String[] priorOrder = new String[]{"ALT","RCS",XMS_msgType};
|
|
|
|
if(priorOrderPolicy.equals("ALT")) { // 알림톡 전송을 최우선으로 사용
|
|
priorOrder = new String[]{"ALT","RCS",XMS_msgType};
|
|
} else if(priorOrderPolicy.equals("RCS")) { // RCS 전송을 최우선으로 사용
|
|
priorOrder = new String[]{"RCS","ALT",XMS_msgType};
|
|
}
|
|
|
|
messageEntity.configMsgTypes(priorOrder);
|
|
messageEntity.configContentsTypeN("ALT");
|
|
messageEntity.configContentsTypeN(RCS_contentsType);
|
|
messageEntity.configContentsTypeN(XMS_contentsType);
|
|
} else if(able_kko && !able_rcs) { // 알림톡+XMS
|
|
messageEntity.configMsgTypes(new String[]{"ALT",XMS_msgType});
|
|
messageEntity.configContentsTypeN("ALT");
|
|
messageEntity.configContentsTypeN(XMS_contentsType);
|
|
} else if(!able_kko && able_rcs){ // RCS+XMS
|
|
messageEntity.configMsgTypes(new String[]{"RCS",XMS_msgType});
|
|
messageEntity.configContentsTypeN(RCS_contentsType);
|
|
messageEntity.configContentsTypeN(XMS_contentsType);
|
|
} else {// XMS
|
|
messageEntity.configMsgTypes(new String[]{XMS_msgType});
|
|
messageEntity.configContentsTypeN(XMS_contentsType);
|
|
}
|
|
|
|
|
|
|
|
if(able_kko) {
|
|
messageEntity.setAltSenderKey(kkoSenderKey);
|
|
messageEntity.setAltTemplateCode(kkoTemplateKey);
|
|
messageEntity.setAltJson(altJsonComplete);
|
|
}
|
|
|
|
if(able_rcs) {
|
|
messageEntity.setRcsBrandKey(rcsBrandKey);
|
|
messageEntity.setRcsMassageBaseId(rcsBaseId);
|
|
messageEntity.setRcsJson(rcsJsonComplete);
|
|
}
|
|
|
|
|
|
messageEntity.setXmsText(xmsPlainComplete);
|
|
|
|
messageEntityList.add(messageEntity);
|
|
}
|
|
|
|
//
|
|
|
|
Map<String,Object> resultMap = messageService.regist(messageEntityList);
|
|
|
|
mav.addObject("resultMap", resultMap);
|
|
mav.addObject("saved",true);
|
|
return mav;
|
|
}
|
|
|
|
|
|
|
|
}
|