OBP GwMetric API 추가

This commit is contained in:
Rinjae
2025-12-16 19:37:04 +09:00
parent 914c9047e6
commit 64aeedde2e
8 changed files with 260 additions and 26 deletions
@@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.nio.charset.StandardCharsets;
@@ -27,7 +28,7 @@ public class ObpGwMetricController implements InterceptorSkipController {
private static final Logger log = LoggerFactory.getLogger(ObpGwMetricController.class);
private static final DateTimeFormatter PATH_FORMATTER =
DateTimeFormatter.ofPattern("yyyy-MM-dd_HH:mm:ss");
DateTimeFormatter.ofPattern("yyyy-MM-dd_HH:mm:ss");
private final ObpGwMetricManService obpGwMetricManService;
@@ -39,15 +40,18 @@ public class ObpGwMetricController implements InterceptorSkipController {
* 특정 시간대의 GwMetric 데이터 조회
*
* @param datetime 조회 시간대 (형식: yyyy-MM-dd_HH:mm:ss)
* @param pretty true면 JSON 들여쓰기 적용
* @return JSON Array
*/
@RequestMapping(
value = "/kjb/gw-metrics/{datetime}",
value = "/kjb/gw-metrics/{datetime}.json",
produces = "application/json;charset=utf-8"
)
@ResponseBody
public String getGwMetrics(@PathVariable("datetime") String datetime) {
log.debug("GwMetric 조회 요청: datetime={}", datetime);
public String getGwMetrics(
@PathVariable("datetime") String datetime,
@RequestParam(value = "pretty", required = false) Boolean pretty) {
log.debug("GwMetric 조회 요청: datetime={}, pretty={}", datetime, pretty);
long startTime = System.currentTimeMillis();
try {
@@ -59,11 +63,7 @@ public class ObpGwMetricController implements InterceptorSkipController {
List<ObpGwMetricDTO> metrics = obpGwMetricManService.findByTimeslice(timeslice);
// JSON 변환 (GSON)
Gson gson = new GsonBuilder()
.serializeNulls()
.create();
String json = gson.toJson(metrics);
String json = toJson(metrics, pretty);
// 응답 크기 계산 (UTF-8 기준)
int jsonBytes = json.getBytes(StandardCharsets.UTF_8).length;
@@ -85,15 +85,18 @@ public class ObpGwMetricController implements InterceptorSkipController {
* 특정 시간대 이후의 GwMetric 데이터 조회
*
* @param datetime 조회 시작 시간대 (형식: yyyy-MM-dd_HH:mm:ss)
* @param pretty true면 JSON 들여쓰기 적용
* @return JSON Array (해당 시간대 이후의 모든 지표)
*/
@RequestMapping(
value = "/kjb/gw-metrics/after-timeslice/{datetime}",
value = "/kjb/gw-metrics/after-timeslice/{datetime}.json",
produces = "application/json;charset=utf-8"
)
@ResponseBody
public String getGwMetricsAfterTimeslice(@PathVariable("datetime") String datetime) {
log.debug("GwMetric after-timeslice 조회 요청: datetime={}", datetime);
public String getGwMetricsAfterTimeslice(
@PathVariable("datetime") String datetime,
@RequestParam(value = "pretty", required = false) Boolean pretty) {
log.debug("GwMetric after-timeslice 조회 요청: datetime={}, pretty={}", datetime, pretty);
long startTime = System.currentTimeMillis();
try {
@@ -105,11 +108,7 @@ public class ObpGwMetricController implements InterceptorSkipController {
List<ObpGwMetricAfterDTO> metrics = obpGwMetricManService.findByTimesliceAfter(timeslice);
// JSON 변환 (GSON)
Gson gson = new GsonBuilder()
.serializeNulls()
.create();
String json = gson.toJson(metrics);
String json = toJson(metrics, pretty);
// 응답 크기 계산 (UTF-8 기준)
int jsonBytes = json.getBytes(StandardCharsets.UTF_8).length;
@@ -127,6 +126,21 @@ public class ObpGwMetricController implements InterceptorSkipController {
}
}
/**
* 객체를 JSON 문자열로 변환
*
* @param object 변환할 객체
* @param pretty true면 들여쓰기 적용
* @return JSON 문자열
*/
private String toJson(Object object, Boolean pretty) {
GsonBuilder builder = new GsonBuilder().serializeNulls();
if (Boolean.TRUE.equals(pretty)) {
builder.setPrettyPrinting();
}
return builder.create().toJson(object);
}
/**
* 바이트 크기를 읽기 쉬운 형식으로 변환
* 예: 1024 -> "1.0 KB", 1048576 -> "1.0 MB"