fix: 폐기신청서접수, 폐기결과처리 서버호출로 변경

dev
Jonguk. Lim 4 months ago
parent 5462748f11
commit 42d43c78b6

@ -6,7 +6,6 @@ import java.util.List;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.springframework.http.HttpHeaders;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
@ -45,21 +44,6 @@ public class ApiUtil {
return rslt.body(); 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 * Object -> data
* @param request WebClient.Request * @param request WebClient.Request

@ -1,12 +1,19 @@
package cokr.xit.adds.nims.web; package cokr.xit.adds.nims.web;
import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse; import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.IntStream; import java.util.stream.IntStream;
@ -19,6 +26,7 @@ import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
@ -79,6 +87,12 @@ public class AddsNimsController extends ApplicationController {
@Value("${app.inf.nims.api.dsuseMgtListForRptDoc}") @Value("${app.inf.nims.api.dsuseMgtListForRptDoc}")
private String dsuseMgtListForRptDocEndpoint; private String dsuseMgtListForRptDocEndpoint;
@Value("${app.inf.nims.api.saveDsuseMgtRslt}")
private String saveDsuseMgtRsltEndpoint;
@Value("${app.inf.nims.api.saveDsuseMgtReceipt}")
private String saveDsuseMgtReceiptEndpoint;
@Resource(name="sigunguDepartmentService") @Resource(name="sigunguDepartmentService")
private SigunguDepartmentService sggDeptService; private SigunguDepartmentService sggDeptService;
@ -148,9 +162,7 @@ public class AddsNimsController extends ApplicationController {
} }
mav.addObject("fileInfo", toJson(fileInfo)); mav.addObject("fileInfo", toJson(fileInfo));
return mav return mav.addObject("pageName", "dsuseMgtReceiptInfo"); // View(jsp)에서 사용할 id 뒤에 붙일 suffix
.addObject("pageName", "dsuseMgtReceiptInfo") // View(jsp)에서 사용할 id 뒤에 붙일 suffix
.addObject("apiHost", apiHost);
} }
@RequestMapping(value = "/removeDsuseMgt.do", name="신청서 접수 목록 조회") @RequestMapping(value = "/removeDsuseMgt.do", name="신청서 접수 목록 조회")
@ -224,8 +236,7 @@ public class AddsNimsController extends ApplicationController {
.addObject("pageName", "dsuseMgtRsltInfo") // View(jsp)에서 사용할 id 뒤에 붙일 suffix .addObject("pageName", "dsuseMgtRsltInfo") // View(jsp)에서 사용할 id 뒤에 붙일 suffix
.addObject("infoPrefix", "dsuseMgtRsltInfo") // prefix .addObject("infoPrefix", "dsuseMgtRsltInfo") // prefix
.addObject("infoPrefixUrl", "/adds/nims") // prefixUrl .addObject("infoPrefixUrl", "/adds/nims") // prefixUrl
.addObject("dsuseRsltInfo", toJson(dsuseRsltInfo)) // View(jsp)에서 사용할 id 뒤에 붙일 suffix .addObject("dsuseRsltInfo", toJson(dsuseRsltInfo)); // View(jsp)에서 사용할 id 뒤에 붙일 suffix
.addObject("apiHost", apiHost);
} }
@RequestMapping(value = "/getDsuseMgtRsltImgDscdmngList.do", name="결과[통보] 처리 등록 이미지 폐기관리 목록 조회") @RequestMapping(value = "/getDsuseMgtRsltImgDscdmngList.do", name="결과[통보] 처리 등록 이미지 폐기관리 목록 조회")
@ -381,7 +392,6 @@ public class AddsNimsController extends ApplicationController {
mav.addObject("DEPTList", deptList); mav.addObject("DEPTList", deptList);
mav.addObject("pageName", "dsuseMgtDoc"); mav.addObject("pageName", "dsuseMgtDoc");
mav.addObject("apiHost", apiHost);
return mav; return mav;
} }
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
@ -455,6 +465,64 @@ public class AddsNimsController extends ApplicationController {
return json.parse(rslt, new TypeReference<>() {}); return json.parse(rslt, new TypeReference<>() {});
} }
@RequestMapping(value = "/saveDsuseMgtReceipt.do", name="폐기신청서 접수", produces = "application/json;charset=UTF-8")
public @ResponseBody ApiBaseResponse<JSONObject> saveDsuseMgtReceipt(
@RequestParam("dsuseMgtJsonStr") String dsuseMgtJsonStr,
@RequestParam("dsuseMgtDtlsJsonStr") String dsuseMgtDtlsJsonStr,
@RequestParam(value = "dsusePrdImgFiles", required = false) List<MultipartFile> dsusePrdImgFiles) {
String boundary = UUID.randomUUID().toString();
try {
HttpRequest.BodyPublisher bodyPublisher = buildMultipartBodyReceipt(dsuseMgtJsonStr, dsuseMgtDtlsJsonStr,
dsusePrdImgFiles, boundary);
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(apiHost + saveDsuseMgtReceiptEndpoint))
.header("Content-Type", "multipart/form-data; boundary=" + boundary)
.POST(bodyPublisher)
.build();
HttpResponse<String> apiRslt = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
String rslt = apiRslt.body();
return json.parse(rslt, new TypeReference<>() {});
}catch (Exception e){
}
return null;
}
@RequestMapping(value = "/saveDsuseMgtRslt.do", name="폐기결과[통보] 처리", produces = "application/json;charset=UTF-8")
public @ResponseBody ApiBaseResponse<JSONObject> saveDsuseMgtRslt(
@RequestParam("dsuseMgtRsltJsonStr") String dsuseMgtRsltJsonStr,
@RequestParam(value = "dsuseDsuseImgFiles", required = false) List<MultipartFile> dsuseDsuseImgFiles,
@RequestParam("fileChangeYn") String fileChangeYn) {
String boundary = UUID.randomUUID().toString();
try {
HttpRequest.BodyPublisher bodyPublisher = buildMultipartBody(dsuseMgtRsltJsonStr, dsuseDsuseImgFiles,
fileChangeYn, boundary);
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(apiHost + saveDsuseMgtRsltEndpoint))
.header("Content-Type", "multipart/form-data; boundary=" + boundary)
.POST(bodyPublisher)
.build();
HttpResponse<String> apiRslt = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
String rslt = apiRslt.body();
return json.parse(rslt, new TypeReference<>() {});
}catch (Exception e){
}
return null;
}
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// API server call // API server call
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
@ -644,6 +712,70 @@ public class AddsNimsController extends ApplicationController {
} }
return partitions; return partitions;
} }
private HttpRequest.BodyPublisher buildMultipartBody(String dsuseMgtRsltJsonStr, List<MultipartFile> files, String fileChangeYn, String boundary) throws IOException {
var byteOut = new ByteArrayOutputStream();
String lineSeparator = "\r\n";
// JSON part
byteOut.write(("--" + boundary + lineSeparator).getBytes(StandardCharsets.UTF_8));
byteOut.write(("Content-Disposition: form-data; name=\"dsuseMgtRsltJsonStr\"" + lineSeparator).getBytes(StandardCharsets.UTF_8));
byteOut.write(("Content-Type: application/json; charset=UTF-8" + lineSeparator + lineSeparator).getBytes(StandardCharsets.UTF_8));
byteOut.write((dsuseMgtRsltJsonStr + lineSeparator).getBytes(StandardCharsets.UTF_8));
// File parts
if (files != null) {
for (MultipartFile file : files) {
byteOut.write(("--" + boundary + lineSeparator).getBytes(StandardCharsets.UTF_8));
byteOut.write(("Content-Disposition: form-data; name=\"dsuseDsuseImgFiles\"; filename=\"" + file.getOriginalFilename() + "\"" + lineSeparator).getBytes(StandardCharsets.UTF_8));
byteOut.write(("Content-Type: " + file.getContentType() + lineSeparator + lineSeparator).getBytes(StandardCharsets.UTF_8));
byteOut.write(file.getBytes());
byteOut.write((lineSeparator).getBytes(StandardCharsets.UTF_8));
}
}
// fileChangeYn part
byteOut.write(("--" + boundary + lineSeparator).getBytes(StandardCharsets.UTF_8));
byteOut.write(("Content-Disposition: form-data; name=\"fileChangeYn\"" + lineSeparator).getBytes(StandardCharsets.UTF_8));
byteOut.write(("Content-Type: text/plain; charset=UTF-8" + lineSeparator + lineSeparator).getBytes(StandardCharsets.UTF_8));
byteOut.write((fileChangeYn + lineSeparator).getBytes(StandardCharsets.UTF_8));
byteOut.write(("--" + boundary + "--" + lineSeparator).getBytes(StandardCharsets.UTF_8));
return HttpRequest.BodyPublishers.ofByteArray(byteOut.toByteArray());
}
private HttpRequest.BodyPublisher buildMultipartBodyReceipt(String dsuseMgtJsonStr, String dsuseMgtDtlsJsonStr, List<MultipartFile> files, String boundary) throws IOException {
var byteOut = new ByteArrayOutputStream();
String lineSeparator = "\r\n";
// JSON part
byteOut.write(("--" + boundary + lineSeparator).getBytes(StandardCharsets.UTF_8));
byteOut.write(("Content-Disposition: form-data; name=\"dsuseMgtJsonStr\"" + lineSeparator).getBytes(StandardCharsets.UTF_8));
byteOut.write(("Content-Type: application/json; charset=UTF-8" + lineSeparator + lineSeparator).getBytes(StandardCharsets.UTF_8));
byteOut.write((dsuseMgtJsonStr + lineSeparator).getBytes(StandardCharsets.UTF_8));
// File parts
if (files != null) {
for (MultipartFile file : files) {
byteOut.write(("--" + boundary + lineSeparator).getBytes(StandardCharsets.UTF_8));
byteOut.write(("Content-Disposition: form-data; name=\"dsusePrdImgFiles\"; filename=\"" + file.getOriginalFilename() + "\"" + lineSeparator).getBytes(StandardCharsets.UTF_8));
byteOut.write(("Content-Type: " + file.getContentType() + lineSeparator + lineSeparator).getBytes(StandardCharsets.UTF_8));
byteOut.write(file.getBytes());
byteOut.write((lineSeparator).getBytes(StandardCharsets.UTF_8));
}
}
// fileChangeYn part
byteOut.write(("--" + boundary + lineSeparator).getBytes(StandardCharsets.UTF_8));
byteOut.write(("Content-Disposition: form-data; name=\"dsuseMgtDtlsJsonStr\"" + lineSeparator).getBytes(StandardCharsets.UTF_8));
byteOut.write(("Content-Type: text/plain; charset=UTF-8" + lineSeparator + lineSeparator).getBytes(StandardCharsets.UTF_8));
byteOut.write((dsuseMgtDtlsJsonStr + lineSeparator).getBytes(StandardCharsets.UTF_8));
byteOut.write(("--" + boundary + "--" + lineSeparator).getBytes(StandardCharsets.UTF_8));
return HttpRequest.BodyPublishers.ofByteArray(byteOut.toByteArray());
}
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// private method // private method
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------

@ -70,6 +70,10 @@ app:
prdMnfSeqInfoOfBarcode: /api/biz/nims/v1/getPrdMnfSeqInfoOfBarcode prdMnfSeqInfoOfBarcode: /api/biz/nims/v1/getPrdMnfSeqInfoOfBarcode
# 보고문서 정보 목록 조회 # 보고문서 정보 목록 조회
dsuseMgtListForRptDoc: /api/biz/nims/v1/getDsuseMgtListForRptDoc dsuseMgtListForRptDoc: /api/biz/nims/v1/getDsuseMgtListForRptDoc
# 폐기신청서 접수
saveDsuseMgtReceipt: /api/biz/nims/v1/saveDsuseMgtReceipt
# 폐기결과[통보] 처리
saveDsuseMgtRslt: /api/biz/nims/v1/saveDsuseMgtRslt
logging: logging:
file: file:

@ -357,7 +357,7 @@
} }
upload({ upload({
url: '<c:url value="${apiHost}/api/biz/nims/v1/saveDsuseMgtReceipt" />' url: wctx.url("/adds/nims/saveDsuseMgtReceipt.do")
, data: { , data: {
dsuseMgtJsonStr: JSON.stringify(saveBsshData), dsuseMgtJsonStr: JSON.stringify(saveBsshData),
dsuseMgtDtlsJsonStr: JSON.stringify(datasetListPrd), dsuseMgtDtlsJsonStr: JSON.stringify(datasetListPrd),

@ -341,7 +341,7 @@
, init: () => setDialogZindex() , init: () => setDialogZindex()
, onOK: () => { , onOK: () => {
upload({ upload({
url: '<c:url value="${apiHost}/api/biz/nims/v1/saveDsuseMgtRslt" />' url: wctx.url("/adds/nims/saveDsuseMgtRslt.do")
, data: { , data: {
fileChangeYn: fileChangeYn, fileChangeYn: fileChangeYn,
dsuseMgtRsltJsonStr: JSON.stringify(saveData), dsuseMgtRsltJsonStr: JSON.stringify(saveData),

Loading…
Cancel
Save