[KC-108] 분석도엽 ai api호출 테스트

This commit is contained in:
2026-01-12 13:42:25 +09:00
parent e42c99cd60
commit 0b45f42528
10 changed files with 155 additions and 71 deletions

View File

@@ -170,7 +170,7 @@ public class InferenceResultDto {
@NotNull
private Integer targetYyyy;
@Schema(description = "분석대상 도엽 - 전체(ALL), 부분(PART)", example = "PART")
@Schema(description = "분석대상 도엽 - 전체(ALL), 부분(PART)", example = "ALL")
@NotBlank
@EnumValid(enumClass = MapSheetScope.class, message = "분석대상 도엽 옵션은 '전체', '부분' 만 사용 가능합니다.")
private String mapSheetScope;
@@ -184,8 +184,16 @@ public class InferenceResultDto {
@Schema(
description = "5k 도협 번호 목록",
example = "[\"37914034\",\"37914024\",\"37914023\",\"37914014\",\"37914005\",\"37914004\"]")
example = "[{\"mapSheetNum\":37914034,\"mapSheetName\":\"죽변\"}]")
@NotNull
private List<String> mapSheetNum;
private List<MapSheetNumDto> mapSheetNum;
}
@Getter
@Setter
public static class MapSheetNumDto {
private String mapSheetNum;
private String mapSheetName;
}
}

View File

@@ -1,11 +1,14 @@
package com.kamco.cd.kamcoback.inference.service;
import com.kamco.cd.kamcoback.common.exception.CustomApiException;
import com.kamco.cd.kamcoback.config.resttemplate.ExternalHttpClient;
import com.kamco.cd.kamcoback.config.resttemplate.ExternalHttpClient.ExternalCallResult;
import com.kamco.cd.kamcoback.inference.dto.InferenceDetailDto;
import com.kamco.cd.kamcoback.inference.dto.InferenceDetailDto.Dashboard;
import com.kamco.cd.kamcoback.inference.dto.InferenceDetailDto.Detail;
import com.kamco.cd.kamcoback.inference.dto.InferenceDetailDto.MapSheet;
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto;
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.MapSheetNumDto;
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.MapSheetScope;
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.ResultList;
import com.kamco.cd.kamcoback.inference.dto.InferenceSendDto;
@@ -22,12 +25,12 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
@Service
@Log4j2
@@ -38,7 +41,7 @@ public class InferenceResultService {
private final InferenceResultCoreService inferenceResultCoreService;
private final MapSheetMngCoreService mapSheetMngCoreService;
private final ModelMngCoreService modelMngCoreService;
private final WebClient webClient;
private final ExternalHttpClient externalHttpClient;
@Value("${inference.url}")
private String inferenceUrl;
@@ -60,34 +63,41 @@ public class InferenceResultService {
*/
@Transactional
public UUID saveInferenceInfo(InferenceResultDto.RegReq req) {
// TODO tif 없으면 전년도 파일 조회 쿼리 추가해야함
// 전체일때 5k도협 가져오기
List<MapSheetNumDto> mapSheetNum = new ArrayList<>();
if (MapSheetScope.ALL.getId().equals(req.getMapSheetScope())) {
Search5kReq mapReq = new Search5kReq();
mapReq.setUseInference("USE");
List<String> mapSheetIds = new ArrayList<>();
MapSheetNumDto mapSheetNumDto = new MapSheetNumDto();
inferenceResultCoreService
.findByMapidList(mapReq)
.forEach(
mapInkx5kEntity -> {
mapSheetIds.add(mapInkx5kEntity.getMapidcdNo());
mapSheetNumDto.setMapSheetNum(mapInkx5kEntity.getMapidcdNo());
mapSheetNumDto.setMapSheetName(mapInkx5kEntity.getMapidNm());
mapSheetNum.add(mapSheetNumDto);
});
req.setMapSheetNum(mapSheetIds);
}
// 추론 테이블 저장
UUID uuid = inferenceResultCoreService.saveInferenceInfo(req);
// TODO tif 없으면 전년도 파일 조회 쿼리 추가해야함
// TODO 도엽 개수를 target 기준으로 맞춰야함
this.getSceneInference(String.valueOf(req.getCompareYyyy()), req.getMapSheetNum());
this.getSceneInference(String.valueOf(req.getTargetYyyy()), req.getMapSheetNum());
List<String> mapSheetNumList = new ArrayList<>();
for (MapSheetNumDto mapSheetDto : mapSheetNum) {
mapSheetNumList.add(mapSheetDto.getMapSheetNum());
}
this.getSceneInference(String.valueOf(req.getCompareYyyy()), mapSheetNumList);
this.getSceneInference(String.valueOf(req.getTargetYyyy()), mapSheetNumList);
InferenceSendDto m1 = this.getModelInfo(req.getModel1Uuid());
InferenceSendDto m2 = this.getModelInfo(req.getModel2Uuid());
InferenceSendDto m3 = this.getModelInfo(req.getModel3Uuid());
//
// ensureAccepted(m1);
ensureAccepted(m1);
// ensureAccepted(m2);
// ensureAccepted(m3);
@@ -99,33 +109,15 @@ public class InferenceResultService {
*
* @param dto
*/
private Mono<Boolean> inferenceSend(InferenceSendDto dto) {
return webClient
.post()
.uri("http://localhost:8080/test") // inferenceUrl
.contentType(MediaType.APPLICATION_JSON)
.bodyValue(dto)
.retrieve()
.toBodilessEntity()
.map(res -> res.getStatusCode().is2xxSuccessful())
.doOnNext(ok -> log.info("발송결과={}", ok))
.onErrorReturn(false);
}
/**
* api 호출 실패시 예외처리
*
* @param dto
*/
private void ensureAccepted(InferenceSendDto dto) {
Boolean ok =
this.inferenceSend(dto)
.timeout(java.time.Duration.ofSeconds(3))
.onErrorReturn(false) // 타임아웃/통신오류도 실패 처리
.block(java.time.Duration.ofSeconds(4));
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
if (!Boolean.TRUE.equals(ok)) {
ExternalCallResult result =
externalHttpClient.call(inferenceUrl, HttpMethod.POST, dto, headers);
if (!result.success()) {
throw new CustomApiException("BAD_GATEWAY", HttpStatus.BAD_GATEWAY);
}
}