259 lines
9.3 KiB
Plaintext
259 lines
9.3 KiB
Plaintext
package com.urpsys.itmsbatch.cmm.excute;
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import org.quartz.DisallowConcurrentExecution;
|
|
import org.quartz.Job;
|
|
import org.quartz.JobDataMap;
|
|
import org.quartz.JobExecutionContext;
|
|
import org.quartz.JobExecutionException;
|
|
import org.quartz.PersistJobDataAfterExecution;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.mail.javamail.JavaMailSender;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import com.urpsys.basebatch.common.util.CommonUtil;
|
|
import com.urpsys.basebatch.common.util.ConvertUtils;
|
|
import com.urpsys.basebatch.common.util.HtmlEmailUtil;
|
|
import com.urpsys.basebatch.common.util.RestApiCallUtil;
|
|
import com.urpsys.itmsbatch.cmm.dao.MailKaTalkDao;
|
|
import com.urpsys.itmsbatch.cmm.service.MailKaTalkService;
|
|
|
|
import kong.unirest.json.JSONObject;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
/**
|
|
* KIC(한국투자공사) 메일/카톡 처리 실행 클래스
|
|
*
|
|
* @author urp 인프라본부 나혁제
|
|
* @since 2025.06.11
|
|
* @version 1.0.0
|
|
* @see
|
|
*
|
|
* <pre>
|
|
*
|
|
* << 개정이력(Modification information) >>
|
|
*
|
|
* 수정일 수정자 수정내용
|
|
* ----------- --------- ------------------------
|
|
* 2025.06.11 나혁제 최초작성
|
|
*
|
|
* </pre>
|
|
*/
|
|
|
|
@Slf4j
|
|
@Component
|
|
@PersistJobDataAfterExecution
|
|
@DisallowConcurrentExecution
|
|
public class MailKaTalkSendKiccJob2 implements Job
|
|
{
|
|
@Autowired
|
|
MailKaTalkService mailKaTalkService;
|
|
|
|
@Autowired
|
|
HtmlEmailUtil htmlEmailUtil;
|
|
|
|
@Autowired
|
|
RestApiCallUtil restApiCallUtil;
|
|
|
|
@Value("${custom.api_kic_msg_key}")
|
|
private String strApiKicMsgKey; // KIC 메신저서버 api key
|
|
|
|
@Override
|
|
public void execute(JobExecutionContext context) throws JobExecutionException
|
|
{
|
|
log.info(" >>>>>>>>>> MailKaTalkSendKiccJob Executed <<<<<<<<<< ");
|
|
|
|
JobDataMap dataMap = context.getJobDetail().getJobDataMap();
|
|
|
|
log.info("dataMap date : {}", dataMap.get("date"));
|
|
log.info("dataMap executeCount : {}", dataMap.get("executeCount"));
|
|
|
|
// 전송메일 대상 조회
|
|
List<LinkedHashMap<String, Object>> listNctn = mailKaTalkService.selectNctnProcSndInfo();
|
|
|
|
for(LinkedHashMap<String, Object> tempMap : listNctn)
|
|
{
|
|
String strProcRsltCn = "";
|
|
String strProcRsltCd = "";
|
|
|
|
// 메일 처리
|
|
if(tempMap.get("procTy").equals("1"))
|
|
{
|
|
Map<String, Object> bodyMap = new HashMap();
|
|
|
|
String strMailAddress = CommonUtil.nvl(tempMap.get("rcvrAddr"));
|
|
|
|
// 2025.07.01 나혁제 자기 메일로 처리
|
|
// bodyMap.put("email" , "hong@kic.go.kr");
|
|
bodyMap.put("email" , CommonUtil.nvl(tempMap.get("rcvrAddr")) );
|
|
bodyMap.put("to" , CommonUtil.nvl(tempMap.get("rcvrAddr")) );
|
|
bodyMap.put("subject" , CommonUtil.nvl(tempMap.get("ttl")) );
|
|
bodyMap.put("content" , CommonUtil.nvl(tempMap.get("bdy")) );
|
|
// bodyMap.put("content" , "itms 메일테스트 입니다. 메일 삭제해주세요." );
|
|
bodyMap.put("contentType" , "text/html" );
|
|
|
|
try
|
|
{
|
|
// 메일주소가 없는경우 오류 처리
|
|
if(strMailAddress.equals(""))
|
|
{
|
|
strProcRsltCn = "메일주소 존재하지 않음";
|
|
strProcRsltCd = "-1";
|
|
}
|
|
else
|
|
{
|
|
// Map<String, Object> retMap = restApiCallUtil.RestApiCallNoAuthKicMailTextHtml(bodyMap, "/test/kicMailTest.do");
|
|
Map<String, Object> retMap = restApiCallUtil.RestApiCallNoAuthKicMailTextHtml(bodyMap, "/api/mail/send/json");
|
|
|
|
strProcRsltCn = retMap.toString();
|
|
strProcRsltCd = "0";
|
|
}
|
|
}
|
|
catch(Exception e)
|
|
{
|
|
e.printStackTrace();
|
|
|
|
strProcRsltCn = e.toString();
|
|
strProcRsltCd = "-2";
|
|
}
|
|
}
|
|
// 메신저 처리
|
|
else if(tempMap.get("procTy").equals("3"))
|
|
{
|
|
String strTtl = CommonUtil.nvl(tempMap.get("ttl"));
|
|
String strRcvrAddr = CommonUtil.nvl(tempMap.get("rcvrAddr"));
|
|
String strBdy = CommonUtil.nvl(tempMap.get("bdy"));
|
|
String[] srBdy = strBdy.split(",");
|
|
|
|
try
|
|
{
|
|
/*
|
|
Map<String, Object> messageMap = new HashMap();
|
|
|
|
messageMap.put("\""+"title" +"\"" , "\""+strTtl+"\"" );
|
|
messageMap.put("\""+"context" +"\"" , "\""+srBdy[0]+"\"" );
|
|
|
|
Map<String, Object> messageFuncMap = new HashMap();
|
|
|
|
messageFuncMap.put("\""+"name" +"\"", "\""+"상세페이지로이동"+"\"" );
|
|
messageFuncMap.put("\""+"type" +"\"", "\""+"link" +"\"" );
|
|
messageFuncMap.put("\""+"data" +"\"", "\""+srBdy[1] +"\"" );
|
|
|
|
messageMap.put("\""+"func"+"\"", messageFuncMap);
|
|
*/
|
|
|
|
// JSONParser parser = new JSONParser();
|
|
|
|
/*
|
|
Map<String, Object> messageMap = new HashMap();
|
|
|
|
messageMap.put("title" , strTtl );
|
|
messageMap.put("context" , srBdy[0] );
|
|
|
|
Map<String, Object> messageFuncMap = new HashMap();
|
|
|
|
messageFuncMap.put("name" , "상세페이지로이동" );
|
|
messageFuncMap.put("type" , "link" );
|
|
messageFuncMap.put("data" , srBdy[1] );
|
|
|
|
messageMap.put("func", messageFuncMap);
|
|
|
|
StringBuilder strBulider = new StringBuilder(1000);
|
|
|
|
strBulider.append("\"");
|
|
strBulider.append(messageMap.toString().replaceAll("\"", "\\\""));
|
|
strBulider.append("\"");
|
|
*/
|
|
|
|
// 변환처리
|
|
// JSONObject jsonObj = ConvertUtils.getJsonFromMap(messageMap);
|
|
|
|
|
|
Map<String, Object> bodyMap = new HashMap();
|
|
|
|
List<Map<String, Object>> targetsList = new ArrayList<>();
|
|
|
|
Map<String, Object> targetMap = new HashMap();
|
|
targetMap.put("targetCode", strRcvrAddr);
|
|
targetMap.put("targetType", "UR");
|
|
targetsList.add(targetMap);
|
|
|
|
JSONObject jsonObj = new JSONObject();
|
|
|
|
// String str = "\";
|
|
|
|
jsonObj.put("name", "상세페이지로이동");
|
|
jsonObj.put("type", "link");
|
|
jsonObj.put("data", srBdy[1]);
|
|
|
|
JSONObject jObj = new JSONObject();
|
|
|
|
jObj.put("title" , strTtl);
|
|
jObj.put("context", srBdy[0]);
|
|
|
|
jObj.put("func", jsonObj);
|
|
|
|
StringBuilder strBulider = new StringBuilder(100);
|
|
|
|
// strBulider.append("\"");
|
|
strBulider.append(jObj.toString().replaceAll("\"", "\\\""));
|
|
// strBulider.append("\"");
|
|
|
|
// bodyMap 구성
|
|
bodyMap.put("SubjectCode", strApiKicMsgKey);
|
|
bodyMap.put("targets" , targetsList );
|
|
|
|
// bodyMap.put("message" , jsonObj.toString() );
|
|
|
|
bodyMap.put("message" , strBulider.toString() );
|
|
// bodyMap.put("message" , messageMap.toString() );
|
|
// bodyMap.put("message" , messageMap );
|
|
// bodyMap.put("message" , "테스트" );
|
|
|
|
// Map<String, Object> retMap = restApiCallUtil.RestApiCallNoAuthKicMsg( bodyMap, "/test/kicMsgTest.do");
|
|
Map<String, Object> retMap = restApiCallUtil.RestApiCallNoAuthKicMsg( bodyMap, "/server/na/notice");
|
|
|
|
strProcRsltCn = retMap.toString();
|
|
strProcRsltCd = "0";
|
|
}
|
|
catch(Exception e)
|
|
{
|
|
strProcRsltCn = e.toString();
|
|
strProcRsltCd = "-2";
|
|
}
|
|
}
|
|
// 오류처리
|
|
else
|
|
{
|
|
strProcRsltCn = "알수 없는 구분값";
|
|
strProcRsltCd = (strProcRsltCn.equals("")) ? "0" : "-1";
|
|
}
|
|
|
|
LinkedHashMap<String, Object> inputMap = new LinkedHashMap<String, Object>();
|
|
|
|
inputMap.put("procRsltCn" , strProcRsltCn);
|
|
inputMap.put("procRsltCd" , strProcRsltCd);
|
|
inputMap.put("nctnEsntlId" , tempMap.get("nctnEsntlId"));
|
|
|
|
mailKaTalkService.updateNtcnProcSndInfo(inputMap);
|
|
}
|
|
|
|
//JobDataMap를 통해 Job의 실행 횟수를 받아서 횟수 + 1을한다.
|
|
int cnt = (int) dataMap.get("executeCount");
|
|
dataMap.put("executeCount", ++cnt);
|
|
dataMap.put("date", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
|
log.info(" <<<<<<<<<< MailKaTalkSendKiccJob Executed >>>>>>>>>> ");
|
|
}
|
|
|
|
|
|
} |