OBP GwMetric 조회범위 제한 설정

This commit is contained in:
Rinjae
2026-02-04 17:49:41 +09:00
parent ffb6dcac66
commit 1222a3b013
3 changed files with 39 additions and 2 deletions
@@ -2,6 +2,9 @@ package com.eactive.eai.rms.data.entity.onl.apim.obp;
import com.eactive.apim.portal.obp.entity.ObpGwMetric; import com.eactive.apim.portal.obp.entity.ObpGwMetric;
import com.eactive.apim.portal.obp.repository.ObpGwMetricRepository; import com.eactive.apim.portal.obp.repository.ObpGwMetricRepository;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@@ -50,6 +53,24 @@ public class ObpGwMetricService {
return repository.findByTimesliceGreaterThanEqual(timeslice); return repository.findByTimesliceGreaterThanEqual(timeslice);
} }
/**
* 특정 시간대 이후의 GwMetric 데이터 조회 (row 수 제한)
*
* @param timeslice 조회 시작 시간대
* @param limit 최대 조회 건수 (0이면 무제한)
* @return 조회된 지표 목록 (timeslice ASC 정렬)
*/
public List<ObpGwMetric> findByTimesliceGreaterThanEqual(LocalDateTime timeslice, int limit) {
if (limit <= 0) {
// 무제한 조회 (기존 동작 유지)
return repository.findByTimesliceGreaterThanEqual(timeslice);
} else {
// 제한적 조회 (timeslice ASC 정렬 + limit)
Pageable pageable = PageRequest.of(0, limit, Sort.by(Sort.Order.asc("timeslice")));
return repository.findByTimesliceGreaterThanEqual(timeslice, pageable);
}
}
/** /**
* 엔티티 저장 (INSERT 또는 UPDATE) * 엔티티 저장 (INSERT 또는 UPDATE)
*/ */
@@ -55,7 +55,7 @@ public class ObpGwMetricController extends BaseRestController {
produces = JSON_CONTENT_TYPE produces = JSON_CONTENT_TYPE
) )
@ResponseBody @ResponseBody
public String getGwMetricsAfterTimesliceV2( public String getGwMetricsAfterTimeslice(
@PathVariable("timeslice") String timeslice, @PathVariable("timeslice") String timeslice,
@PathVariable("providerCode") String providerCode, @PathVariable("providerCode") String providerCode,
@RequestParam(value = "pretty", required = false) Boolean pretty) { @RequestParam(value = "pretty", required = false) Boolean pretty) {
@@ -10,6 +10,7 @@ import com.eactive.eai.rms.common.util.CommonUtil;
import com.eactive.eai.rms.data.entity.onl.apim.obp.ObpGwMetricJpaDAO; import com.eactive.eai.rms.data.entity.onl.apim.obp.ObpGwMetricJpaDAO;
import com.eactive.eai.rms.data.entity.onl.apim.obp.ObpGwMetricService; import com.eactive.eai.rms.data.entity.onl.apim.obp.ObpGwMetricService;
import com.eactive.eai.rms.data.entity.onl.apim.obp.ObpGwMetricVO; import com.eactive.eai.rms.data.entity.onl.apim.obp.ObpGwMetricVO;
import com.eactive.ext.kjb.common.KjbPropertyHolder;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.dao.DataIntegrityViolationException; import org.springframework.dao.DataIntegrityViolationException;
@@ -314,12 +315,27 @@ public class ObpGwMetricManService extends BaseService {
/** /**
* 특정 시간대 이후의 GwMetric 데이터 조회 (REST API용) * 특정 시간대 이후의 GwMetric 데이터 조회 (REST API용)
* after-timeslice 엔드포인트에서 사용 * after-timeslice 엔드포인트에서 사용
*
* <p>조회 범위 제한:</p>
* <ul>
* <li>pageSize 값을 KjbProperty.apiGwMetricPageSize에서 읽어옴 (기본값: 10000)</li>
* <li>0일 경우 무제한 조회</li>
* <li>정렬: timeslice ASC (오래된 데이터부터 반환)</li>
* </ul>
*/ */
public List<ObpGwMetricDTO> findByTimesliceAfter(LocalDateTime timeslice) { public List<ObpGwMetricDTO> findByTimesliceAfter(LocalDateTime timeslice) {
DataSourceContextHolder.setDataSourceType( DataSourceContextHolder.setDataSourceType(
DataSourceTypeManager.getDataSourceType(DataSourceTypeManager.MONITORING)); DataSourceTypeManager.getDataSourceType(DataSourceTypeManager.MONITORING));
List<ObpGwMetric> entities = obpGwMetricService.findByTimesliceGreaterThanEqual(timeslice); // KjbProperty에서 pageSize 읽기
Integer pageSize = KjbPropertyHolder.get().getApiGwMetricPageSize();
if (pageSize == null) {
pageSize = 10000; // 기본값 (null 안전 처리)
}
// Service 호출 (limit 적용)
List<ObpGwMetric> entities = obpGwMetricService.findByTimesliceGreaterThanEqual(timeslice, pageSize);
return entities.stream() return entities.stream()
.map(ObpGwMetricDTO::from) .map(ObpGwMetricDTO::from)
.collect(Collectors.toList()); .collect(Collectors.toList());