interfasce 추가

This commit is contained in:
DESKTOP-6ARNG1Q\dlsgk 2024-11-08 11:25:49 +09:00
parent 686f7e978c
commit e3b78204c2
2 changed files with 60 additions and 14 deletions

View File

@ -100,7 +100,6 @@ public class JobLauncherController {
*/
// @Scheduled(cron = "*/30 * * * * *")
@Scheduled(cron = "0 0 0 * * *")
@GetMapping("/batch/master/storeAdditionalInfo")
public String storeAdditionalInfoJob()
throws JobInstanceAlreadyCompleteException,
JobExecutionAlreadyRunningException,

View File

@ -1,5 +1,9 @@
package com.interplug.qcast.util;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.interplug.qcast.biz.user.dto.SyncResponse;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
@ -8,16 +12,20 @@ import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
@Slf4j
@Component
@RequiredArgsConstructor
public class InterfaceQsp {
@Value("${qsp.url}")
private String qspUrl;
/**
* API Call
*
@ -71,10 +79,8 @@ public class InterfaceQsp {
throw e;
} finally {
try {
if (osw != null)
osw.close();
if (br != null)
br.close();
if (osw != null) osw.close();
if (br != null) br.close();
} catch (Exception e) {
throw e;
}
@ -83,6 +89,48 @@ public class InterfaceQsp {
return sb != null ? sb.toString() : null;
}
/**
* API 호출후 Response 객체로 Return
*
* @param method
* @param qspInterUrl
* @param requestObject
* @param responseObject
* @return
* @throws Exception
*/
public <T> T callApiData(
HttpMethod method, String qspInterUrl, Object requestObject, Object responseObject)
throws Exception {
// 데이터 읽기
SyncResponse syncResponse = new SyncResponse();
String strResponse = this.callApi(method, qspUrl + qspInterUrl, requestObject);
ObjectMapper om =
new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
String dataJson = "";
if (!"".equals(strResponse)) {
syncResponse = om.readValue(strResponse, SyncResponse.class);
// 'data' 필드를 직접 사용하여 BatchResponse로 변환
if (syncResponse.getData() != null) {
dataJson = om.writeValueAsString(syncResponse.getData());
}
}
if (responseObject == null) {
return (T) dataJson;
} else if (responseObject instanceof Class<?>) {
return om.readValue(dataJson, (Class<T>) responseObject);
} else if (responseObject instanceof TypeReference<?>) {
return om.readValue(dataJson, (TypeReference<T>) responseObject);
} else {
throw new IllegalArgumentException("Unsupported responseType");
}
}
/**
* API Call - byte return, file down 사용
*
@ -91,8 +139,9 @@ public class InterfaceQsp {
* @return String
* @throws Exception
*/
public byte[] callApi(HttpMethod httpMethod, String apiPath, Object requestObject,
Map<String, String> result) throws Exception {
public byte[] callApi(
HttpMethod httpMethod, String apiPath, Object requestObject, Map<String, String> result)
throws Exception {
URL url = null;
HttpURLConnection con = null;
@ -142,10 +191,8 @@ public class InterfaceQsp {
throw e;
} finally {
try {
if (osw != null)
osw.close();
if (br != null)
br.close();
if (osw != null) osw.close();
if (br != null) br.close();
} catch (Exception e) {
throw e;
}