feat: Postplus API file 연계 반영

dev
gitea-관리자 1 year ago
parent c9109fb599
commit fcd14f2caa

@ -1,13 +1,35 @@
package kr.xit.ens.pplus.service; package kr.xit.ens.pplus.service;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import kr.xit.biz.ens.model.cmm.CmmEnsRlaybsnmDTO;
import kr.xit.biz.ens.model.pplus.PplusDTO.PpAcceptReqDataDtl;
import kr.xit.biz.ens.model.pplus.PplusDTO.PpAcceptReqDataMst;
import kr.xit.biz.ens.model.pplus.PplusDTO.PpAcceptReqDataStruct;
import kr.xit.biz.ens.model.pplus.PplusDTO.PpAcceptRequest; import kr.xit.biz.ens.model.pplus.PplusDTO.PpAcceptRequest;
import kr.xit.biz.ens.model.pplus.PplusDTO.PpAcceptRequestStruct;
import kr.xit.biz.ens.model.pplus.PplusDTO.PpCommonResponse; import kr.xit.biz.ens.model.pplus.PplusDTO.PpCommonResponse;
import kr.xit.biz.ens.model.pplus.PplusDTO.PpStatusRequest; import kr.xit.biz.ens.model.pplus.PplusDTO.PpStatusRequest;
import kr.xit.biz.ens.model.pplus.PplusDTO.PpStatusResponse; import kr.xit.biz.ens.model.pplus.PplusDTO.PpStatusResponse;
import kr.xit.core.spring.util.ApiWebClientUtil; import kr.xit.core.spring.util.ApiWebClientUtil;
import kr.xit.core.support.utils.FileUtil;
import kr.xit.core.support.utils.JsonUtils;
import kr.xit.ens.kt.cmm.CmmKtMmsUtils;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.egovframe.rte.fdl.cmmn.EgovAbstractServiceImpl; import org.egovframe.rte.fdl.cmmn.EgovAbstractServiceImpl;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
/** /**
* <pre> * <pre>
@ -24,18 +46,158 @@ import org.springframework.stereotype.Service;
* *
* </pre> * </pre>
*/ */
@Slf4j
@RequiredArgsConstructor @RequiredArgsConstructor
@Service @Service
public class PplusService extends EgovAbstractServiceImpl implements IPplusService { public class PplusService extends EgovAbstractServiceImpl implements IPplusService {
@Value("${file.cmm.temp-path}")
private String FILE_TEMP_PATH;
@Value("${contract.pplus.host}")
private String HOST;
@Value("${contract.pplus.api.accept}")
private String ACCEPT;
private final ApiWebClientUtil webClient; private final ApiWebClientUtil webClient;
@Override @Override
public PpCommonResponse accept(PpAcceptRequest reqDTO) { public PpCommonResponse accept(PpAcceptRequest reqDTO) {
final CmmEnsRlaybsnmDTO ktMnsInfo = CmmKtMmsUtils.getKtMnsInfo(reqDTO.getSignguCode(), reqDTO.getFfnlgCode());
reqDTO.setApiKey(ktMnsInfo.getPplusApiKey());
JSONObject mstJson = makePpAcceptMstData();
JSONObject dtlJson = makePpAcceptDtlData();
PpAcceptRequestStruct reqDataDTO = PpAcceptRequestStruct.builder()
.master(PpAcceptReqDataStruct.builder()
.cols(JsonUtils.toJson(mstJson.get("cols")))
.rows(JsonUtils.toJson(mstJson.get("rows")))
.build())
.detail(PpAcceptReqDataStruct.builder()
.cols(JsonUtils.toJson(dtlJson.get("cols")))
.rows(JsonUtils.toJson(dtlJson.get("rows")))
.build())
.build();
String reqDataJsonStr = JsonUtils.toJson(reqDataDTO);
log.debug(reqDataJsonStr);
FileUtil.saveFile(FILE_TEMP_PATH,"pstFile.json", reqDataJsonStr.getBytes(StandardCharsets.UTF_8));
MultipartFile pstFile = FileUtil.createMutipartFile("pstFile.json", FILE_TEMP_PATH);
List<MultipartFile> pstFiles = new ArrayList<>();
pstFiles.add(pstFile);
if(ObjectUtils.isNotEmpty(reqDTO.getPstFile())) pstFiles.add(reqDTO.getPstFile());
final Map<String,String> headerMap = new HashMap<>();
headerMap.put(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN_VALUE);
// headerMap.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE);
// headerMap.put("client-id", "client-id");
// headerMap.put("client-tp", "10");
// headerMap.put(HttpHeaders.AUTHORIZATION, String.format("%s %s", AUTH_TYPE_BEARER, "access-token"));
return webClient.exchangeFile(
HOST + ACCEPT,
HttpMethod.POST,
pstFiles,
"pstFile.json",
PpCommonResponse.class,
headerMap
);
/*
String reqJson = JsonUtils.toJson(reqDTO);
reqDTO.setSignguCode(null);
reqDTO.setFfnlgCode(null);
String reqJson2 = JsonUtils.toJson(reqDTO);
return null; return null;
*/
} }
@Override @Override
public PpStatusResponse status(PpStatusRequest reqDTO) { public PpStatusResponse status(PpStatusRequest reqDTO) {
return null; return null;
} }
private JSONObject makePpAcceptMstData(){
PpAcceptReqDataMst mst = PpAcceptReqDataMst.builder()
.build();
//CmmEnsUtils.validate(mst);
return JsonUtils.extractObjKeyValue(mst, "cols", "rows");
}
private JSONObject makePpAcceptDtlData(){
JSONArray arrJson = new JSONArray();
PpAcceptReqDataDtl dtl = PpAcceptReqDataDtl.builder()
.("1")
.("홍길동")
.("05048")
.("서울특별시 광진구 강변로역2")
.(1)
.build();
//CmmEnsUtils.validate(dtl);
JSONObject dtlJson = JsonUtils.toObjByObj(dtl, JSONObject.class);
// 가변인자 처리
for(int i=0; i<2; i++) {
JSONObject json = new JSONObject(dtlJson);
json.put("f1", "d1-"+i);
json.put("f2", "d2-"+i);
json.put("f3", "d3-"+i);
arrJson.add(json);
}
return JsonUtils.extractJsonArrayKeyValue(net.sf.json.JSONArray.fromObject(arrJson), "cols", "rows");
/*
List<PpAcceptReqDataDtl> dtls = new ArrayList<>();
PpAcceptReqDataDtl dtl = PpAcceptReqDataDtl.builder()
.("1")
.("홍길동")
.("05048")
.("서울특별시 광진구 강변로역2")
.(1)
.build();
dtls.add(dtl);
dtls.add(dtl);
JSONObject dtlJson = JsonUtils.extractJsonArrayKeyValue(net.sf.json.JSONArray.fromObject(dtls), "cols", "rows");
JSONArray arrDtlColsJson = (JSONArray)dtlJson.get("cols");
JSONArray tmpArr = new JSONArray();
tmpArr.add("f1");
tmpArr.add("f2");
tmpArr.add("f3");
arrDtlColsJson.addAll(tmpArr);
JSONArray arrDtlRowsJson = (JSONArray)dtlJson.get("rows");
for(int i=0; i<arrDtlRowsJson.size(); i++) {
JSONArray tmpArr1 = new JSONArray();
tmpArr1.add("d"+i);
tmpArr1.add("d"+i);
tmpArr1.add("d"+i);
((JSONArray)arrDtlRowsJson.get(i)).addAll(tmpArr1);
}
*/
}
} }

@ -58,7 +58,7 @@ public class PplusController {
""") """)
}) })
})*/ })*/
@Operation(summary = "우편제작접수", description = "우편제작접수 요청") @Operation(summary = "우편제작접수", description = "우편제작접수 요청<br><a href='/pstFile.html'>우편제작접수</a>")
@PostMapping(value = "/accept", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) @PostMapping(value = "/accept", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
//@PostMapping(value = "/accept", produces = MediaType.APPLICATION_JSON_VALUE) //@PostMapping(value = "/accept", produces = MediaType.APPLICATION_JSON_VALUE)
public ApiResponseDTO<?> accept(@ModelAttribute final PpAcceptRequest paramDTO) { public ApiResponseDTO<?> accept(@ModelAttribute final PpAcceptRequest paramDTO) {

@ -72,7 +72,8 @@ app:
url: 'http://localhost:${server.port}${server.servlet.context-path:}/' url: 'http://localhost:${server.port}${server.servlet.context-path:}/'
data: data:
root: root:
path: /Users/minuk/data #path: /Users/minuk/data
path: d:/data
#--------------------------------------------------------------- #---------------------------------------------------------------
# log 설정 # log 설정

@ -83,6 +83,7 @@ logging:
file: file:
cmm: cmm:
temp-path: ${app.data.root.path}/temp
upload: upload:
root: ${app.data.root.path} root: ${app.data.root.path}
# root: /data # root: /data

@ -55,7 +55,7 @@
detail.cols = detailCols; detail.cols = detailCols;
var detailRows = new Array(); var detailRows = new Array();
var detailRowsArr1 = ['1','홍길동1','31010','서울특별시 광진구 강변역로2','서울광진우체국 B동 1층','01012341234','pstFile.pdf','24926737','2021-09-02','대출(고정)','31,000,000']; var detailRowsArr1 = ['1',['홍길동1','lll'],'31010','서울특별시 광진구 강변역로2','서울광진우체국 B동 1층','01012341234','pstFile.pdf','24926737','2021-09-02','대출(고정)','31,000,000'];
detailRows.push(detailRowsArr1); detailRows.push(detailRowsArr1);
var detailRowsArr2 = ['2','홍길동2','08394','서울특별시 광진구 강변역로2','서울광진우체국 B동 2층','01012341234','pstFile.pdf','25685047','2021-09-02','대출B(변동)','421,000,000']; var detailRowsArr2 = ['2','홍길동2','08394','서울특별시 광진구 강변역로2','서울광진우체국 B동 2층','01012341234','pstFile.pdf','25685047','2021-09-02','대출B(변동)','421,000,000'];
detailRows.push(detailRowsArr2); detailRows.push(detailRowsArr2);
@ -73,16 +73,18 @@
var formData = new FormData(); var formData = new FormData();
formData.append("signguCode", "88328");
formData.append("ffnlgCode", "11");
formData.append("apiKey", "PnvGWlH0X55ZyEqIEyJIJpKAf26xIcY11/UYgMehuhlR8+8yfV01S2Qjr7d/f0FMhVhdeJGg/KChN2sjb/Rg=="); formData.append("apiKey", "PnvGWlH0X55ZyEqIEyJIJpKAf26xIcY11/UYgMehuhlR8+8yfV01S2Qjr7d/f0FMhVhdeJGg/KChN2sjb/Rg==");
formData.append('pstFile', new Blob([pstMsr], {type : "application/json"})); formData.append('pstFile', new File([new Blob([pstMsr], {type : "application/json"})], "pstFile", {type : "application/json"}));
var files = $("input[name=attchFile]")[0].files; var files = $("input[name=attchFile]")[0].files;
formData.append("pstFile", files[0]); formData.append("pstFile", files[0]);
$.ajax({ $.ajax({
url: 'https://t.postplus.co.kr/po/api/postplusPstMsrApi.do', //url: 'https://t.postplus.co.kr/po/api/postplusPstMsrApi.do',
//url: '/api/ens/pplus/v1/accept', url: '/api/ens/pplus/v1/accept',
data: formData, data: formData,
cache: false, cache: false,
contentType: false, contentType: false,
@ -91,9 +93,11 @@
type: 'POST', type: 'POST',
success: function(data) { success: function(data) {
console.log(data); console.log(data);
alert(JSON.stringify(data));
}, },
error: function(e) { error: function(e) {
console.log(e); console.log(e);
alert(JSON.stringify(e));
} }
}); });
} }

Loading…
Cancel
Save