Compare commits

..

No commits in common. "15deda383abfdcab6cbe8147d08f5ebc2e96c47a" and "709425a4848d129cfc52452d9936ea859d55cb20" have entirely different histories.

2 changed files with 72 additions and 138 deletions

View File

@ -4,11 +4,8 @@ import com.fasterxml.jackson.core.type.TypeReference;
import com.interplug.qcast.biz.displayItem.DisplayItemService; import com.interplug.qcast.biz.displayItem.DisplayItemService;
import com.interplug.qcast.biz.displayItem.dto.ItemSyncResponse; import com.interplug.qcast.biz.displayItem.dto.ItemSyncResponse;
import com.interplug.qcast.util.InterfaceQsp; import com.interplug.qcast.util.InterfaceQsp;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.springframework.batch.core.Job; import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecutionListener; import org.springframework.batch.core.JobExecutionListener;
import org.springframework.batch.core.Step; import org.springframework.batch.core.Step;
@ -37,9 +34,6 @@ public class MaterialConfiguration implements JobExecutionListener {
@Value("${qsp.master-material-batch-url}") @Value("${qsp.master-material-batch-url}")
private String qspInterfaceUrl; private String qspInterfaceUrl;
@Value("${qsp.master-material-batch-page-size:1000}")
private int pageSize;
public MaterialConfiguration(DisplayItemService displayItemService, InterfaceQsp interfaceQsp) { public MaterialConfiguration(DisplayItemService displayItemService, InterfaceQsp interfaceQsp) {
this.displayItemService = displayItemService; this.displayItemService = displayItemService;
this.interfaceQsp = interfaceQsp; this.interfaceQsp = interfaceQsp;
@ -64,32 +58,12 @@ public class MaterialConfiguration implements JobExecutionListener {
@Bean @Bean
@StepScope @StepScope
public ListItemReader<ItemSyncResponse> materialReader() throws Exception { public ListItemReader<ItemSyncResponse> materialReader() throws Exception {
List<ItemSyncResponse> aggregated = new ArrayList<>(); this.itemSyncList =
int page = 1;
while (true) {
Map<String, Object> params = new HashMap<>();
params.put("allYn", "N");
params.put("page", page);
params.put("size", pageSize);
List<ItemSyncResponse> pageItems =
interfaceQsp.callApiData( interfaceQsp.callApiData(
HttpMethod.GET, HttpMethod.GET,
qspInterfaceUrl, qspInterfaceUrl + "?allYn=N",
params, null,
new TypeReference<List<ItemSyncResponse>>() {}); new TypeReference<List<ItemSyncResponse>>() {});
if (pageItems == null || pageItems.isEmpty()) {
break;
}
aggregated.addAll(pageItems);
if (pageItems.size() < pageSize) {
break;
}
page++;
}
this.itemSyncList = aggregated;
return (itemSyncList != null) return (itemSyncList != null)
? new ListItemReader<>(itemSyncList) ? new ListItemReader<>(itemSyncList)
: new ListItemReader<>(Collections.emptyList()); : new ListItemReader<>(Collections.emptyList());

View File

@ -45,8 +45,6 @@ public class InterfaceQsp {
OutputStreamWriter osw = null; OutputStreamWriter osw = null;
BufferedReader br = null; BufferedReader br = null;
StringBuilder sb = null; StringBuilder sb = null;
long startAt = System.currentTimeMillis();
String requestType = requestObject == null ? "none" : requestObject.getClass().getSimpleName();
try { try {
@ -62,11 +60,6 @@ public class InterfaceQsp {
apiPath += "?" + queryString; // 쿼리 스트링 추가 apiPath += "?" + queryString; // 쿼리 스트링 추가
} }
log.debug(
"QSP API call start: method={}, url={}, requestType={}",
httpMethod,
apiPath,
requestType);
url = new URL(apiPath); url = new URL(apiPath);
con = (HttpURLConnection) url.openConnection(); con = (HttpURLConnection) url.openConnection();
con.setConnectTimeout(120000); // 서버에 연결되는 Timeout 시간 설정 con.setConnectTimeout(120000); // 서버에 연결되는 Timeout 시간 설정
@ -91,8 +84,7 @@ public class InterfaceQsp {
} }
sb = new StringBuilder(); sb = new StringBuilder();
int status = con.getResponseCode(); if (con.getResponseCode() == HttpURLConnection.HTTP_OK) {
if (status == HttpURLConnection.HTTP_OK) {
br = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8")); br = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8"));
String line; String line;
@ -100,19 +92,7 @@ public class InterfaceQsp {
sb.append(line); sb.append(line);
} }
} }
log.debug(
"QSP API call end: method={}, url={}, status={}, durationMs={}",
httpMethod,
apiPath,
status,
System.currentTimeMillis() - startAt);
} catch (Exception e) { } catch (Exception e) {
log.error(
"QSP API call failed: method={}, url={}, durationMs={}",
httpMethod,
apiPath,
System.currentTimeMillis() - startAt,
e);
throw e; throw e;
} finally { } finally {
try { try {
@ -186,15 +166,8 @@ public class InterfaceQsp {
BufferedReader br = null; BufferedReader br = null;
byte[] bt = null; byte[] bt = null;
long startAt = System.currentTimeMillis();
String requestType = requestObject == null ? "none" : requestObject.getClass().getSimpleName();
try { try {
log.debug(
"QSP API call start: method={}, url={}, requestType={}",
httpMethod,
apiPath,
requestType);
url = new URL(apiPath); url = new URL(apiPath);
con = (HttpURLConnection) url.openConnection(); con = (HttpURLConnection) url.openConnection();
con.setConnectTimeout(30000); // 서버에 연결되는 Timeout 시간 설정 con.setConnectTimeout(30000); // 서버에 연결되는 Timeout 시간 설정
@ -217,8 +190,7 @@ public class InterfaceQsp {
osw.flush(); osw.flush();
} }
} }
int status = con.getResponseCode(); if (con.getResponseCode() == HttpURLConnection.HTTP_OK) {
if (status == HttpURLConnection.HTTP_OK) {
// response 헤더 결과 셋팅 // response 헤더 결과 셋팅
result.put("type", con.getHeaderField("Content-Type")); result.put("type", con.getHeaderField("Content-Type"));
result.put("disposition", con.getHeaderField("Content-Disposition")); result.put("disposition", con.getHeaderField("Content-Disposition"));
@ -233,19 +205,7 @@ public class InterfaceQsp {
} }
bt = outputStream.toByteArray(); // 파일 데이터 반환 bt = outputStream.toByteArray(); // 파일 데이터 반환
} }
log.debug(
"QSP API call end: method={}, url={}, status={}, durationMs={}",
httpMethod,
apiPath,
status,
System.currentTimeMillis() - startAt);
} catch (Exception e) { } catch (Exception e) {
log.error(
"QSP API call failed: method={}, url={}, durationMs={}",
httpMethod,
apiPath,
System.currentTimeMillis() - startAt,
e);
throw e; throw e;
} finally { } finally {
try { try {