refactor: JSP API call -> server call 전환

dev
Jonguk. Lim 5 months ago
parent c4d30fb023
commit 4b990b159c

@ -78,6 +78,12 @@
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
<build>

@ -1,236 +1,105 @@
// package cokr.xit.adds.cmm.model;
//
// import java.io.FileInputStream;
// import java.io.IOException;
// import java.io.StringReader;
// import java.net.http.HttpResponse;
// import java.time.LocalDate;
// import java.time.format.DateTimeFormatter;
// import java.time.format.DateTimeParseException;
// import java.util.List;
// import java.util.Set;
//
// import javax.validation.ConstraintViolation;
// import javax.validation.Validator;
// import javax.xml.XMLConstants;
// import javax.xml.transform.stream.StreamSource;
// import javax.xml.validation.Schema;
// import javax.xml.validation.SchemaFactory;
//
// import org.apache.commons.lang3.ObjectUtils;
// import org.apache.commons.lang3.StringUtils;
// import org.json.simple.JSONObject;
// import org.springframework.http.HttpHeaders;
// import org.xml.sax.SAXException;
//
// import com.fasterxml.jackson.core.type.TypeReference;
//
// import cokr.xit.adds.core.spring.exception.ApiCustomException;
// import cokr.xit.foundation.data.JSON;
// import cokr.xit.foundation.web.WebClient;
//
// /**
// * <pre>
// * description :
// *
// * author : limju
// * date : 2024-04-04
// * ======================================================================
// * 변경일 변경자 변경 내용
// * ----------------------------------------------------------------------
// * 2024-04-04 limju 최초 생성
// *
// * </pre>
// */
// public class ApiUtil {
//
// /**
// * 유효성 검증
// * errList가 null인 경우 유효성 검증 실패 시 예외 throw ApiCustomException
// *
// * @param t validatable object
// * @param errList error list
// * @param validator validator
// */
// public static <T> void validate(final T t, final List<String> errList, final Validator validator) {
// final Set<ConstraintViolation<T>> list = validator.validate(t);
//
// if(!list.isEmpty()) {
// final List<String> errors = list.stream()
// .map(row -> String.format("%s=%s", row.getPropertyPath(), row.getMessageTemplate()))
// .toList();
//
// // 추가적인 유효성 검증이 필요 없는 경우
// if(errList == null){
// if(!errors.isEmpty()) throw ApiCustomException.create(errors.toString());
// return;
// }
// errList.addAll(errors);
// }
// }
//
// public static void checkYmdError(String dt, String fieldName) {
// String msg = "유효한 일자가 아닙니다.";
// if(ObjectUtils.isEmpty(fieldName)){
// msg = "ymd=" + msg;
// }else{
// msg = fieldName + "=" + msg;
// }
// try {
// final LocalDate rdt = LocalDate.parse(dt, DateTimeFormatter.ofPattern("yyyyMMdd"));
// if(!dt.equals(DateTimeFormatter.ofPattern("yyyyMMdd").format(rdt))){
// throw ApiCustomException.create(msg);
// }
// } catch (DateTimeParseException e) {
// throw ApiCustomException.create(msg);
// }
// }
//
// public static void checkDatetimeError(String dt, String fieldName) {
// String msg = "유효한 일시가 아닙니다.";
// if(ObjectUtils.isEmpty(fieldName)){
// msg = "ymd=" + msg;
// }else{
// msg = fieldName + "=" + msg;
// }
// try {
// final LocalDate rdt = LocalDate.parse(dt, DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
// if(!dt.equals(DateTimeFormatter.ofPattern("yyyyMMddHHmmss").format(rdt))){
// throw ApiCustomException.create(msg);
// }
// } catch (DateTimeParseException e) {
// throw ApiCustomException.create(msg);
// }
// }
//
// /**
// * NimsApi 호출 - x-www-form-urlencoded 방식
// * @param uri String
// * @param cls T
// * @return String
// */
// public static <T> String callNimsApi(String uri, T cls) {
// HttpResponse<String> rslt = new WebClient().post(request -> {
// request.contentType(WebClient.Request.ContentType.FORM);
// request.uri(uri);
// toData(request, cls);
// });
// return rslt.body();
// }
//
// /**
// * irosApi 호출 - x-www-form-urlencoded 방식
// * @param uri String
// * @param param String
// * @return String
// */
// public static String callIrosApi(String uri, String param) {
// HttpResponse<String> rslt = new WebClient().get(request -> {
// request.header(HttpHeaders.CONTENT_TYPE, "application/json");
// request.contentType(WebClient.Request.ContentType.FORM);
// request.uri(uri + param);
// });
// return rslt.body();
// }
//
// /**
// * Object -> data로 변환
// * @param request WebClient.Request
// * @param obj Object
// */
// public static void toData(final WebClient.Request request, final Object obj){
// if(ObjectUtils.isEmpty(obj)) return;
//
// JSONObject jsonObj = toObjByObj(obj, JSONObject.class);
// for (Object key : jsonObj.keySet()) {
// // API 호출 시 필요없는 파라메터 제외
// if("userId".equals(key) || "dbSkipYn".equals(key)) continue;
// request.data((String) key, ObjectUtils.isEmpty(jsonObj.get(key))? StringUtils.EMPTY: jsonObj.get(key));
// }
// }
//
// /**
// * Object -> class로 변환
// * @param obj Object
// * @param cls Class
// * @return T
// */
// public static <T> T toObjByObj(final Object obj, final Class<T> cls) {
// try {
// return ObjectUtils.isNotEmpty(obj)? new JSON().getObjectMapper().convertValue(obj, cls) : null;
// } catch (IllegalArgumentException e) {
// throw ApiCustomException.create(e.getLocalizedMessage());
// }
// }
//
// /**
// * Object -> TypeReference로 변환
// * @param obj Object
// * @param typeRef TypeReference
// * @return T
// */
// public static <T> T toObjByObj(final Object obj, final TypeReference<T> typeRef) {
// try {
// return ObjectUtils.isNotEmpty(obj)? new JSON().getObjectMapper().convertValue(obj, typeRef) : null;
// } catch (IllegalArgumentException e) {
// throw ApiCustomException.create(e.getLocalizedMessage());
// }
// }
//
// /**
// * XML 유효성 검증
// * @param xmlStr String
// * @param xsdFilePathName String
// * @return boolean
// */
// public static boolean validateXml(final String xmlStr, final String xsdFilePathName) {
// try {
// FileInputStream fis = new FileInputStream(xsdFilePathName);
// SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// Schema schema = sf.newSchema(new StreamSource(fis));
//
// javax.xml.validation.Validator validator = schema.newValidator();
// validator.validate(new StreamSource(new StringReader(xmlStr)));
// return true;
//
// } catch (SAXException | IOException e) {
// throw ApiCustomException.create(e.getMessage());
// }
// }
//
// /**
// * XML 유효성 검증
// * @param xmlStr String
// * @param xsdFilePath String
// * @return boolean
// */
// public static boolean validateXmlFromXmlStr(final String xmlStr, final String xsdFilePath) {
// try {
// FileInputStream fis = new FileInputStream(xsdFilePath);
// SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// Schema schema = sf.newSchema(new StreamSource(fis));
//
// javax.xml.validation.Validator validator = schema.newValidator();
// validator.validate(new StreamSource(new StringReader(xmlStr)));
// return true;
//
// } catch (SAXException | IOException e) {
// throw ApiCustomException.create(e.getMessage());
// }
// }
//
// /**
// * XML 유효성 검증
// * @param xmlFilePath String
// * @param xsdFilePath String
// * @return boolean
// */
// public static boolean validateXmlFromFile(String xmlFilePath, final String xsdFilePath) {
// try (FileInputStream fileInputStream = new FileInputStream(xmlFilePath)) {
// byte[] bytes = fileInputStream.readAllBytes();
// return validateXmlFromXmlStr(new String(bytes), xsdFilePath);
// }catch (IOException e) {
// throw ApiCustomException.create(e.getMessage());
// }
// }
// }
package cokr.xit.adds.cmm.model;
import java.net.http.HttpResponse;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.json.simple.JSONObject;
import org.springframework.http.HttpHeaders;
import com.fasterxml.jackson.core.type.TypeReference;
import cokr.xit.foundation.data.JSON;
import cokr.xit.foundation.web.WebClient;
/**
* <pre>
* description :
*
* author : limju
* date : 2024-04-04
* ======================================================================
*
* ----------------------------------------------------------------------
* 2024-04-04 limju
*
* </pre>
*/
public class ApiUtil {
/**
* NimsApi - x-www-form-urlencoded
* @param uri String
* @param cls T
* @return String
*/
public static <T> String callNimsApi(String uri, T cls) {
HttpResponse<String> rslt = new WebClient().post(request -> {
request.contentType(WebClient.Request.ContentType.FORM);
request.uri(uri);
toData(request, cls);
});
return rslt.body();
}
/**
* irosApi - x-www-form-urlencoded
* @param uri String
* @param param String
* @return String
*/
public static String callIrosApi(String uri, String param) {
HttpResponse<String> rslt = new WebClient().get(request -> {
request.header(HttpHeaders.CONTENT_TYPE, "application/json");
request.contentType(WebClient.Request.ContentType.FORM);
request.uri(uri + param);
});
return rslt.body();
}
/**
* Object -> data
* @param request WebClient.Request
* @param obj Object
*/
public static void toData(final WebClient.Request request, final Object obj){
if(ObjectUtils.isEmpty(obj)) return;
JSONObject jsonObj = toObjByObj(obj, JSONObject.class);
for (Object key : jsonObj.keySet()) {
// API 호출 시 필요없는 파라메터 제외
request.data((String) key, ObjectUtils.isEmpty(jsonObj.get(key))? StringUtils.EMPTY: jsonObj.get(key));
}
}
/**
* Object -> class
* @param obj Object
* @param cls Class
* @return T
*/
public static <T> T toObjByObj(final Object obj, final Class<T> cls) {
try {
return ObjectUtils.isNotEmpty(obj)? new JSON().getObjectMapper().convertValue(obj, cls) : null;
} catch (IllegalArgumentException e) {
//throw new Exception(e.getLocalizedMessage());
return null;
}
}
/**
* Object -> TypeReference
* @param obj Object
* @param typeRef TypeReference
* @return T
*/
public static <T> T toObjByObj(final Object obj, final TypeReference<T> typeRef) {
try {
return ObjectUtils.isNotEmpty(obj)? new JSON().getObjectMapper().convertValue(obj, typeRef) : null;
} catch (IllegalArgumentException e) {
//throw ApiCustomException.create(e.getLocalizedMessage());
return null;
}
}
}

@ -0,0 +1,346 @@
package cokr.xit.adds.cmm.model;
import org.apache.commons.lang3.StringUtils;
import lombok.Data;
/**
* <pre>
* description :
*
* packageName : cokr.xit.adds.inf.nims.model
* fileName : NimsApiRequest
* author : limju
* date : 2024-03-21
* ======================================================================
*
* ----------------------------------------------------------------------
* 2024-03-21 limju
*
* </pre>
*/
public class NimsApiRequest {
/**
* request
*/
@Data
public static class BsshInfoReq {
/**
*
*/
private String k;
/**
*
* 1-, 2-
*/
private String fg;
/**
*
*/
private String pg;
/**
*
*/
private String bi;
/**
*
*/
private String hp;
/**
* (like )
*/
private String bn;
/**
*
*
*/
private String bc;
/**
*
* yyyyMMdd
*/
private String ymd;
/**
* <pre>
* 2
* 1:NK() - default
* 2:NK()
* </pre>
*/
private String fg2 = "1";
/**
* <pre>
* DB skip
* DB NIMS API
* true DB skip
* </pre>
*/
private String dbSkipYn = "N";
/**
* <pre>
*
* </pre>
*/
private String userId;
}
/**
* request
*/
@Data
public static class ProductInfoReq {
/**
*
*/
private String k;
/**
*
* 1-, 2-, 3-
*/
private String fg;
/**
*
*/
private String pg;
/**
*
* yyyyMMdd
*/
private String ymd;
/**
* /
* 1:
* 2:
*/
private String fg2;
/**
*
* (like )
* (pg) 3
*/
private String p;
/**
* (like )
*/
private String pn;
/**
* <pre>
* DB skip
* DB NIMS API
* true DB skip
*
* </pre>
*/
private String dbSkipYn = "N";
/**
* <pre>
*
* </pre>
*/
private String userId;
}
@Data
public static class DsuseRptInfoReq {
/**
*
*/
private String k;
/**
* (1-,2-)
* 1- : NIMS -
* 2-
*/
private String fg = "2";
/**
*
*/
private String pg;
/**
*
* :
* 0: , 1: , 2:
*/
private String fg2;
/**
*
* AAR -
*/
private String se = "AAR";
/**
* (yyyyMMdd)
* 1
*/
private String sdt;
/**
* (yyyyMMdd)
* 1
*/
private String edt;
/**
*
*/
private String bc;
/**
*
*/
private String bn;
/**
*
*/
private String ur;
/**
*
* "": , 01: , 02: , 03: , 04:
*/
private String ps;
/**
* <pre>
*
* 4050147 -
* 4050148 -
* 4050149 -
* </pre>
*/
private String gc;
/**
* <pre>
*
* </pre>
*/
private String userId;
}
/**
* request
*/
@Data
public static class MnfSeqInfoReq {
/**
*
*/
private String k;
/**
* :
* 1-, 2-, 3-/RFID
*/
private String fg;
/**
*
*/
private String pg;
/**
*
* (like )
* (pg) 3
*/
private String p;
/**
*
* yyyyMMdd
*/
private String ymd;
/**
* : like - ->
*/
private String t = StringUtils.EMPTY;
/**
* <pre>
*
* </pre>
*/
private String userId;
}
/**
* request
*/
@Data
public static class JurisdictionGovInfoReq {
/**
*
*/
private String k;
/**
*
* 1-
*/
private String fg;
/**
*
*/
private String pg;
/**
*
*/
private String onm;
/**
*
*/
private String ocd;
/**
*
*/
private String adr;
/**
* <pre>
* DB skip
* DB NIMS API
* true DB skip
* </pre>
*/
private String dbSkipYn = "N";
/**
* <pre>
*
* </pre>
*/
private String userId;
}
}

@ -12,16 +12,23 @@ import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import net.minidev.json.JSONObject;
import net.minidev.json.parser.ParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import cokr.xit.adds.cmm.model.ApiBaseResponse;
import cokr.xit.adds.cmm.model.ApiUtil;
import cokr.xit.adds.cmm.model.DsuseMappingInfo;
import cokr.xit.adds.cmm.model.DsuseReceiptDtl;
import cokr.xit.adds.cmm.model.DsuseRsltInfo;
import cokr.xit.adds.cmm.model.NimsApiRequest;
import cokr.xit.adds.cmmn.hwp.format.DisposeProcessDetails;
import cokr.xit.adds.cmmn.hwp.format.DisposeResultReport;
import cokr.xit.adds.nims.DsuseMgtDocQuery;
@ -42,8 +49,6 @@ import cokr.xit.base.web.ApplicationController;
import cokr.xit.foundation.data.DataObject;
import cokr.xit.foundation.data.JSON;
import cokr.xit.foundation.web.WebClient;
import net.minidev.json.JSONObject;
import net.minidev.json.parser.ParseException;
@Controller
@RequestMapping(
@ -57,6 +62,12 @@ public class AddsNimsController extends ApplicationController {
@Value("${app.file.root.path}")
private String fileRootPath;
@Value("${app.inf.nims.api.bsshInfo}")
private String bsshInfoEndpoint;
@Value("${app.inf.nims.api.productAndseqInfo}")
private String productAndseqInfoEndpoint;
@Resource(name="defaultOgdpBean")
private DefaultOgdpBean defaultOgdpBean;
@ -69,6 +80,7 @@ public class AddsNimsController extends ApplicationController {
@Resource(name="fileService")
private FileService fileService;
private JSON json = new JSON();
//-------------------------------------------------------------------------------------------------
// 신청서 접수
//-------------------------------------------------------------------------------------------------
@ -470,8 +482,21 @@ public class AddsNimsController extends ApplicationController {
//-------------------------------------------------------------------------------------------------
//TODO : 서버통신으로 변경 할것
@RequestMapping(name="마약류폐기 신청서 접수 조회", value="")
public ModelAndView getbsshList(ProductQuery query) throws JsonProcessingException, ParseException {
@RequestMapping(value = "/getNimsProductInfoKdAndMnfSeqInfo.do", name="제품 & 시리얼번호 검색", produces = "application/json;charset=UTF-8")
public @ResponseBody ApiBaseResponse<List<JSONObject>> getNimsProductInfoKdAndMnfSeqInfo(@ModelAttribute NimsApiRequest.ProductInfoReq dto) throws JsonProcessingException, ParseException {
String rslt = ApiUtil.callNimsApi(apiHost + productAndseqInfoEndpoint, dto);
return json.parse(rslt, new TypeReference<>() {});
}
@RequestMapping(value = "/getNimsBsshInfoSt.do", name="업체(마약류취급자) 검색", produces = "application/json;charset=UTF-8")
public @ResponseBody ApiBaseResponse<List<JSONObject>> getNimsBsshInfoSt(@ModelAttribute NimsApiRequest.BsshInfoReq dto) throws JsonProcessingException, ParseException {
String rslt = ApiUtil.callNimsApi(apiHost + bsshInfoEndpoint, dto);
return json.parse(rslt, new TypeReference<>() {});
}
//TODO : 서버통신으로 변경 할것
@RequestMapping(name="업체(마약류취급자) 검색", value="")
public ModelAndView getbsshList2(ProductQuery query) throws JsonProcessingException, ParseException {
ModelAndView mav = new ModelAndView();
JSON json = new JSON();

@ -52,6 +52,22 @@ app:
file:
root:
path: ${app.data.root.path}/files/
inf:
nims:
api:
# 업체(마약류 취급자) 조회
bsshInfo: /api/biz/nims/v1/getNimsBsshInfoSt
# 제품 조회
productInfo: /api/biz/nims/v1/getNimsProductInfoKd
# 제품 & 시리얼 번호 조회
productAndseqInfo: /api/biz/nims/v1/getNimsProductInfoKdAndMnfSeqInfo
# 제품 시리얼 번호 조회
seqInfo: /api/biz/nims/v1/getNimsMnfSeqInfo
# 관할관청 조회
jurisdictionGovInfo: /api/biz/nims/v1/getNimsJurisdictionGovInfo
# 폐기보고 조회
nimsDsuseRptInfo: /api/biz/nims/v1/getNimsDsuseRptInfo
logging:
file:

@ -39,13 +39,13 @@
<thead>
<tr>
<!-- <th style="width: 15.828px;text-align:center;" tabindex="0">No</th> -->
<th class="sorting" style="width: 146.156px;">취급자번호</th>
<th class="sorting" style="width: 140.156px;">취급자번호</th>
<th class="sorting" style="width: 160.141px;">취급업체명</th>
<th class="sorting" style="width: 160.141px;">업종명</th>
<th class="sorting" style="width: 230.469px;">대표자</th>
<th class="sorting" style="width: 230.469px;">허가번호</th>
<th class="sorting" style="width: 230.469px;">구분</th>
<th class="sorting" style="width: 230.469px;">담당자명</th>
<th class="sorting" style="width: 120.469px;">대표자</th>
<th class="sorting" style="width: 250.469px;">허가번호</th>
<th class="sorting" style="width: 120.469px;">담당자명</th>
<th class="sorting" style="width: 120.469px;">구분</th>
</tr>
</thead>
<tbody id="tbody--${pageName}">
@ -58,8 +58,8 @@
<td class="cmn text-center" onclick="{onclick}" ondblclick="{ondblclick}">{indutyNm}</td>
<td class="cmn text-center" onclick="{onclick}" ondblclick="{ondblclick}">{rprsntvNm}</td>
<td class="cmn text-center" onclick="{onclick}" ondblclick="{ondblclick}">{prmisnNo}</td>
<td class="cmn text-center" onclick="{onclick}" ondblclick="{ondblclick}">{hdntCd}</td>
<td class="cmn text-center" onclick="{onclick}" ondblclick="{ondblclick}">{chrgNm}</td>
<td class="cmn text-center" onclick="{onclick}" ondblclick="{ondblclick}">{hdntNm}</td>
</tr>
</template>
<template id="${infoPrefix}NotFound--${pageName}">
@ -98,7 +98,8 @@
**************************************************************************/
$P.control = new DatasetControl({
urls : {
load : '<c:url value="${apiHost}/api/biz/nims/v1/getNimsBsshInfoSt" />',
<%--load : '<c:url value="${apiHost}/api/biz/nims/v1/getNimsBsshInfoSt" />',--%>
load : wctx.url("/adds/nims/getNimsBsshInfoSt.do"),
}
, prefix: "bsshPopup"
, prefixName: "마약류 취급업체 조회"

@ -105,7 +105,8 @@
**************************************************************************/
$P.control = new DatasetControl({
urls : {
load : '<c:url value="${apiHost}/api/biz/nims/v1/getNimsProductInfoKdAndMnfSeqInfo" />',
load : wctx.url("/adds/nims/getNimsProductInfoKdAndMnfSeqInfo.do"),
<%--load : '<c:url value="${apiHost}/api/biz/nims/v1/getNimsProductInfoKdAndMnfSeqInfo" />',--%>
}
, prefix: "productMain"
, prefixName: "마약류 제품 조회"

Loading…
Cancel
Save