diff --git a/src/main/java/cokr/xit/fims/nxrp/service/bean/NisIndivBean.java b/src/main/java/cokr/xit/fims/nxrp/service/bean/NisIndivBean.java index 71ed75ba..61a79d7b 100644 --- a/src/main/java/cokr/xit/fims/nxrp/service/bean/NisIndivBean.java +++ b/src/main/java/cokr/xit/fims/nxrp/service/bean/NisIndivBean.java @@ -1,11 +1,28 @@ package cokr.xit.fims.nxrp.service.bean; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.net.URL; +import java.nio.charset.Charset; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; import java.util.List; import javax.annotation.Resource; +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; import org.springframework.stereotype.Component; +import com.fasterxml.jackson.databind.ObjectMapper; + import cokr.xit.foundation.AbstractComponent; import cokr.xit.foundation.data.DataObject; import cokr.xit.base.user.service.bean.UserBean; @@ -210,11 +227,11 @@ public class NisIndivBean extends AbstractComponent { nisIndivA01.setGlLotnoDaddr(""); // 물건지지번상세주소 nisIndivA01.setGlLotnoAlAddr(""); // 물건지지번전체주소 */ - nisIndivA01.setLvyTrgtSeCd(selectCrdnInfo.string("01")); // 부과대상구분코드 01:차량 + nisIndivA01.setLvyTrgtSeCd("01"); // 부과대상구분코드 01:차량 nisIndivA01.setRegYmd(selectCrdnInfo.string("CRDN_YMD")); // 등록일자 / 위반일자 nisIndivA01.setFinScrgAmt(selectCrdnInfo.string("FFNLG_AMT")); // 과태료과징금금액 -// nisIndivA01.setFcltSeCd(""); // 시설구분코드 / 금연구역흡연위반 과태료인 경우 활용 -// nisIndivA01.setRegSeCd(""); // 등록구분코드 / 폐기물관리법위반 과태료인 경우 01투기, 02소각, 99기타 + nisIndivA01.setFcltSeCd(""); // 시설구분코드 / 금연구역흡연위반 과태료인 경우 활용 + nisIndivA01.setRegSeCd(""); // 등록구분코드 / 폐기물관리법위반 과태료인 경우 01투기, 02소각, 99기타 // 감경 사유 코드(FIM019) -> 감경사유구분코드 if (selectCrdnInfo.string("RDUCT_RSN_CD").equals("01")) { // 국민기초생활수급자 nisIndivA01.setRdtRsnSeCd("0101"); @@ -242,10 +259,10 @@ public class NisIndivBean extends AbstractComponent { vltnLaw = selectCrdnInfo.string("VLTN_LAW_NM") + " " + selectCrdnInfo.string("VLTN_LAW1") + selectCrdnInfo.string("VLTN_LAW2"); nisIndivA01.setMclncLaoBssNm(vltnLaw); // 조례법령근거명 / 과태료/과징금 법령 근거 - nisIndivA01.setMngItemCn1("위반일시 : " + selectCrdnInfo.string("CRDN_YMD_TM_MASK")); // 관리항목1 - nisIndivA01.setMngItemCn2("위반장소 : " + selectCrdnInfo.string("CRDN_PLC")); // 관리항목2 - nisIndivA01.setMngItemCn3("부과근거 : " + vltnLaw); // 관리항목3 - nisIndivA01.setMngItemCn4("위반항목 : " + selectCrdnInfo.string("VLTN_ARTCL")); // 관리항목4 + nisIndivA01.setMngItemCn1("위반일시:" + selectCrdnInfo.string("CRDN_YMD_TM_MASK")); // 관리항목1 + nisIndivA01.setMngItemCn2("위반장소:" + selectCrdnInfo.string("CRDN_PLC")); // 관리항목2 + nisIndivA01.setMngItemCn3("부과근거:" + vltnLaw); // 관리항목3 + nisIndivA01.setMngItemCn4("위반항목:" + selectCrdnInfo.string("VLTN_ARTCL")); // 관리항목4 // 관리항목5 if (selectCrdnInfo.string("CRDN_INPT_SE_CD").equals("06")) { nisIndivA01.setMngItemCn5("관내단속"); @@ -258,19 +275,19 @@ public class NisIndivBean extends AbstractComponent { vltnLaw = selectCrdnInfo.string("VLTN_LAW_NM") + " " + selectCrdnInfo.string("VLTN_LAW1") + selectCrdnInfo.string("VLTN_LAW2"); nisIndivA01.setMclncLaoBssNm(vltnLaw); // 조례법령근거명 / 과태료/과징금 법령 근거 - nisIndivA01.setMngItemCn1("위반일시 : " + selectCrdnInfo.string("CRDN_YMD_TM_MASK")); // 관리항목1 - nisIndivA01.setMngItemCn2("위반장소 : " + selectCrdnInfo.string("CRDN_PLC")); // 관리항목2 - nisIndivA01.setMngItemCn3("부과근거 : " + vltnLaw); // 관리항목3 - nisIndivA01.setMngItemCn4("위반항목 : " + selectCrdnInfo.string("VLTN_ARTCL")); // 관리항목4 + nisIndivA01.setMngItemCn1("위반일시:" + selectCrdnInfo.string("CRDN_YMD_TM_MASK")); // 관리항목1 + nisIndivA01.setMngItemCn2("위반장소:" + selectCrdnInfo.string("CRDN_PLC")); // 관리항목2 + nisIndivA01.setMngItemCn3("부과근거:" + vltnLaw); // 관리항목3 + nisIndivA01.setMngItemCn4("위반항목:" + selectCrdnInfo.string("VLTN_ARTCL")); // 관리항목4 nisIndivA01.setMngItemCn5(""); // 관리항목5 } else if ("BPV,PVS".contains(selectCrdnInfo.string("TASK_SE_CD"))) { // 주정차, 전용차로 vltnLaw = selectCrdnInfo.string("VLTN_LAW_NM") + " " + selectCrdnInfo.string("VLTN_LAW1") + "~" + selectCrdnInfo.string("VLTN_LAW2"); nisIndivA01.setMclncLaoBssNm(vltnLaw); // 조례법령근거명 / 과태료/과징금 법령 근거 - nisIndivA01.setMngItemCn1("위반일시 : " + selectCrdnInfo.string("CRDN_YMD_TM_MASK")); // 관리항목1 - nisIndivA01.setMngItemCn2("위반장소 : " + selectCrdnInfo.string("CRDN_PLC")); // 관리항목2 - nisIndivA01.setMngItemCn3("부과근거 : " + vltnLaw + ", 도로교통법 제160조"); // 관리항목3 - nisIndivA01.setMngItemCn4("위반항목 : " + selectCrdnInfo.string("VLTN_ARTCL")); // 관리항목4 + nisIndivA01.setMngItemCn1("위반일시:" + selectCrdnInfo.string("CRDN_YMD_TM_MASK")); // 관리항목1 + nisIndivA01.setMngItemCn2("위반장소:" + selectCrdnInfo.string("CRDN_PLC")); // 관리항목2 + nisIndivA01.setMngItemCn3("부과근거:" + vltnLaw + ", 도로교통법 제160조"); // 관리항목3 + nisIndivA01.setMngItemCn4("위반항목:" + selectCrdnInfo.string("VLTN_ARTCL")); // 관리항목4 nisIndivA01.setMngItemCn5(""); // 관리항목5 } else { throw new RuntimeException("지정되지 않은 업무 구분코드가 입력되었습니다."); // 예외를 발생시켜서 DB Rollback @@ -283,11 +300,39 @@ public class NisIndivBean extends AbstractComponent { nisIndivA01.setRsveItem3(selectCrdnInfo.string("")); // 예비항목3 nisIndivA01.setRsveItem4(selectCrdnInfo.string("")); // 예비항목4 nisIndivA01.setRsveItem5(selectCrdnInfo.string("")); // 예비항목5 + nisIndivA01.setCreatedBy(userInfo.string("USER_ID")); + nisIndivA01.setModifiedBy(userInfo.string("USER_ID")); + + // 차세대 세외수입 연계 서비스 호출 - A01 과태료 대장 단속 정보 등록 + String sUrl = "https://211.119.124.117:18080/intf/lntris/a01/create"; + String sMethod = "POST"; + String sJsonData = ""; + + // Json 파라미터 설정 + ObjectMapper mapper = new ObjectMapper(); + try { + String voToJson = mapper.writeValueAsString(nisIndivA01); + + sJsonData = "{\"taskSeCd\":" + "\"" + nisIndivA01.getTaskSeCd() + "\"" + + ", \"msg\":" + voToJson + + "}"; + } catch (IOException e) { + throw new RuntimeException("세외수입 과태료대장에 보낼 자료 생성중 오류가 발생하엿습니다."); // 예외를 발생시켜서 DB Rollback + } + + String resultMsg = callHttpsJson(sUrl, sMethod, sJsonData); // 연계 서비스 호출 + System.out.println(resultMsg); + + if (resultMsg.equals("")) { + throw new RuntimeException("세외수입 과태료대장 연계에 실패하였습니다."); + } +/* rtnScs = nisIndivA01Mapper.insert(nisIndivA01); if (!rtnScs) { throw new RuntimeException("세외수입 과태료대장에 단속 정보 등록에 실패하였습니다."); // 예외를 발생시켜서 DB Rollback } +*/ // 발송 대장(TB_SNDNG) - 발송 상태 코드(SNDNG_DTL_STTS_CD) 수정 SndngDtl sndngDtl = new SndngDtl(); @@ -308,6 +353,7 @@ public class NisIndivBean extends AbstractComponent { if(effected != 1) { throw new RuntimeException("세외수입 과태료대장 연계 정보를 단속 대장에 수정하지 못했습니다."); } + } rtnMsg = "[S] 작업이 정상 처리 되었습니다."; @@ -385,4 +431,139 @@ public class NisIndivBean extends AbstractComponent { return rtnMsg; } + /**지정한 조건에 따라 과태료 대장 등록 자료 일괄 조회 목록을 조회하여 반환한다. + * @param req 과태료 대장 등록 자료 일괄 조회 조회 조건 + * @return 과태료 대장 등록 자료 일괄 조회 목록 + */ + public String callHttpsJson(String sUrl, String sMethod, String sJsonData) { + // + String returnMsg = "F "; + // + HttpsURLConnection httpsConn = null; + + try { + // HTTPS 통신을 위한 URL 생성 + URL url = new URL(sUrl); + + // SSL 무시 + ignoreSsl(); + + // HttpsURLConnection 객체 생성 + httpsConn = (HttpsURLConnection) url.openConnection(); + + // Content-Type + httpsConn.setRequestProperty("Content-Type", "application/json"); + // Method Setting(GET/POST) + httpsConn.setRequestMethod(sMethod); // GET, POST, DELETE + // Connection Timeout setting + httpsConn.setConnectTimeout(10000); // 컨텍션타임아웃 10초 + // Read Timeout Setting + httpsConn.setReadTimeout(10000); // 컨텐츠조회 타임아웃 10초 + + if (sMethod.equals("POST")) { + // Input setting + httpsConn.setDoInput(true); + // Output setting + httpsConn.setDoOutput(true); // 항상 갱신된내용을 가져옴 + + // POST방식으로 송신할 json 데이터 전송 + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(httpsConn.getOutputStream())); + bw.write(sJsonData); + bw.flush(); + bw.close(); + } else { + // Input setting + httpsConn.setDoInput(false); + // Output setting + httpsConn.setDoOutput(false); + } + + // HTTP 응답 코드 수신, 서버에서 보낸 응답 데이터 수신 받기 + int responseCode = httpsConn.getResponseCode(); + + Charset charset = Charset.forName("UTF-8"); + String inputLine; + StringBuffer response = new StringBuffer(); + + if (responseCode == 200) { + BufferedReader in = new BufferedReader(new InputStreamReader(httpsConn.getInputStream(), charset)); + + while ((inputLine = in.readLine()) != null) { + response.append(inputLine); + } + in.close(); + + returnMsg = "S "; + } else { + BufferedReader in = new BufferedReader(new InputStreamReader(httpsConn.getErrorStream(), charset)); + + while ((inputLine = in.readLine()) != null) { + response.append(inputLine); + } + in.close(); + + returnMsg = "F "; + } + + returnMsg = returnMsg + response.toString(); + } catch (IOException e) { + System.out.println("IOException :" + e); + } catch (Exception e) { + System.out.println("error : " + e); + } finally { + if (httpsConn != null) { + httpsConn.disconnect(); + } + } + + return returnMsg; + } + + // SSL 무시 ///////////////////////////////////////////////////////////////// + public void ignoreSsl() throws Exception { + HostnameVerifier hv = new HostnameVerifier() { + public boolean verify(String urlHostName, SSLSession session) { + return true; + } + }; + + trustAllHttpsCertificates(); + HttpsURLConnection.setDefaultHostnameVerifier(hv); + } + + public void trustAllHttpsCertificates() throws Exception { + TrustManager[] trustAllCerts = new TrustManager[1]; + TrustManager tm = new miTM(); + trustAllCerts[0] = tm; + SSLContext sc = SSLContext.getInstance("SSL"); + sc.init(null, trustAllCerts, null); + HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); + } + + static class miTM implements TrustManager,X509TrustManager { + public X509Certificate[] getAcceptedIssuers() { + return null; + } + + public boolean isServerTrusted(X509Certificate[] certs) { + return true; + } + + public boolean isClientTrusted(X509Certificate[] certs) { + return true; + } + + public void checkServerTrusted(X509Certificate[] certs, String authType) + throws CertificateException { + return; + } + + public void checkClientTrusted(X509Certificate[] certs, String authType) + throws CertificateException { + return; + } + } + // SSL 무시 ///////////////////////////////////////////////////////////////// + + } diff --git a/src/main/resources/sql/mapper/fims/nxrp/nisIndivA01-mapper.xml b/src/main/resources/sql/mapper/fims/nxrp/nisIndivA01-mapper.xml index 4f7db3a8..19b8362a 100644 --- a/src/main/resources/sql/mapper/fims/nxrp/nisIndivA01-mapper.xml +++ b/src/main/resources/sql/mapper/fims/nxrp/nisIndivA01-mapper.xml @@ -522,14 +522,14 @@ SELECT C.CRDN_ID , C.SGG_CD , C.TASK_SE_CD - , C.CRDN_REG_SE_CD - , C.CRDN_INPT_SE_CD - , C.CVLCPT_LINK_YN - , C.LINK_TBL_NM - , C.LINK_ID - , C.RTPYR_ID - , C.CRDN_YMD - , C.CRDN_TM + , C.CRDN_REG_SE_CD + , C.CRDN_INPT_SE_CD + , C.CVLCPT_LINK_YN + , C.LINK_TBL_NM + , C.LINK_ID + , C.RTPYR_ID + , C.CRDN_YMD + , C.CRDN_TM , C.VHRNO , C.CRDN_STDG_NM , C.CRDN_ROAD_NM