[KC-99] 추론관리 등록 ai api 추가중, spotless 적용
This commit is contained in:
@@ -4,8 +4,10 @@ import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
|
||||
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto;
|
||||
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.ResultList;
|
||||
import com.kamco.cd.kamcoback.inference.service.InferenceResultService;
|
||||
import com.kamco.cd.kamcoback.mapsheet.service.MapSheetMngService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.media.ArraySchema;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
@@ -13,6 +15,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -30,6 +33,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
public class InferenceResultApiController {
|
||||
|
||||
private final InferenceResultService inferenceResultService;
|
||||
private final MapSheetMngService mapSheetMngService;
|
||||
|
||||
@Operation(summary = "추론관리 목록", description = "어드민 홈 > 추론관리 > 추론관리 > 추론관리 목록")
|
||||
@ApiResponses(
|
||||
@@ -63,6 +67,24 @@ public class InferenceResultApiController {
|
||||
return ApiResponseDto.ok(analResList);
|
||||
}
|
||||
|
||||
@Operation(summary = "년도 목록 조회", description = "어드민 홈 > 추론관리 > 추론목록 > 변화탐지 실행 정보 입력 > 년도 목록 조회")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
responseCode = "200",
|
||||
description = "조회 성공",
|
||||
content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
array = @ArraySchema(schema = @Schema(implementation = Integer.class)))),
|
||||
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||
})
|
||||
@GetMapping("/years")
|
||||
public ApiResponseDto<List<Integer>> findMapSheetMngDoneYyyyList() {
|
||||
return ApiResponseDto.ok(mapSheetMngService.findMapSheetMngDoneYyyyList());
|
||||
}
|
||||
|
||||
@Operation(summary = "변화탐지 실행 정보 입력", description = "어드민 홈 > 추론관리 > 추론목록 > 변화탐지 실행 정보 입력")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
|
||||
@@ -114,21 +114,21 @@ public class InferenceResultDto {
|
||||
|
||||
@Schema(description = "M1", example = "2")
|
||||
@NotNull
|
||||
private Long model1Uid;
|
||||
private Long model1Uuid;
|
||||
|
||||
@Schema(description = "M2", example = "4")
|
||||
@NotNull
|
||||
private Long model2Uid;
|
||||
private Long model2Uuid;
|
||||
|
||||
@Schema(description = "M3", example = "7")
|
||||
@NotNull
|
||||
private Long model3Uid;
|
||||
private Long model3Uuid;
|
||||
|
||||
@Schema(description = "비교년도", example = "2003")
|
||||
@Schema(description = "비교년도", example = "2023")
|
||||
@NotNull
|
||||
private Integer compareYyyy;
|
||||
|
||||
@Schema(description = "탐지년도", example = "2004")
|
||||
@Schema(description = "탐지년도", example = "2024")
|
||||
@NotNull
|
||||
private Integer targetYyyy;
|
||||
|
||||
@@ -144,7 +144,9 @@ public class InferenceResultDto {
|
||||
message = "탐지 데이터 옵션은 '추론제외', '이전 년도 도엽 사용' 만 사용 가능합니다.")
|
||||
private String detectOption;
|
||||
|
||||
@Schema(description = "5k 도협 번호 목록", example = "[\"34607067\",\"35802056\"]")
|
||||
@Schema(
|
||||
description = "5k 도협 번호 목록",
|
||||
example = "[\"37914034\",\"37914024\",\"37914023\",\"37914014\",\"37914005\",\"37914004\"]")
|
||||
@NotNull
|
||||
private List<String> mapSheetNum;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.kamco.cd.kamcoback.inference.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class InferenceSendDto {
|
||||
|
||||
private PredRequestsAreas predRequestsAreas;
|
||||
private String model_version;
|
||||
private String cd_model_path;
|
||||
private String cd_model_config;
|
||||
private String cls_model_path;
|
||||
private String cls_model_version;
|
||||
private String cd_model_type;
|
||||
private Integer priority;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public static class PredRequestsAreas {
|
||||
|
||||
private Integer input1_year;
|
||||
private Integer input2_year;
|
||||
private String input1_scene_path;
|
||||
private String input2_scene_path;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,44 @@
|
||||
package com.kamco.cd.kamcoback.inference.service;
|
||||
|
||||
import com.kamco.cd.kamcoback.common.exception.CustomApiException;
|
||||
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.ResultList;
|
||||
import com.kamco.cd.kamcoback.inference.dto.InferenceSendDto;
|
||||
import com.kamco.cd.kamcoback.model.dto.ModelMngDto.Basic;
|
||||
import com.kamco.cd.kamcoback.postgres.core.InferenceResultCoreService;
|
||||
import com.kamco.cd.kamcoback.postgres.core.MapSheetMngCoreService;
|
||||
import com.kamco.cd.kamcoback.postgres.core.ModelMngCoreService;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
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.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
|
||||
@RequiredArgsConstructor
|
||||
@Transactional(readOnly = true)
|
||||
public class InferenceResultService {
|
||||
|
||||
private final InferenceResultCoreService inferenceResultCoreService;
|
||||
private final MapSheetMngCoreService mapSheetMngCoreService;
|
||||
private final ModelMngCoreService modelMngCoreService;
|
||||
private final WebClient webClient;
|
||||
|
||||
@Value("${inference.url}")
|
||||
private String inferenceUrl;
|
||||
|
||||
/**
|
||||
* 추론관리 목록
|
||||
@@ -39,7 +57,85 @@ public class InferenceResultService {
|
||||
*/
|
||||
@Transactional
|
||||
public UUID saveInferenceInfo(InferenceResultDto.RegReq req) {
|
||||
return inferenceResultCoreService.saveInferenceInfo(req);
|
||||
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());
|
||||
|
||||
InferenceSendDto m1 = this.getModelInfo(req.getModel1Uuid());
|
||||
InferenceSendDto m2 = this.getModelInfo(req.getModel2Uuid());
|
||||
InferenceSendDto m3 = this.getModelInfo(req.getModel3Uuid());
|
||||
|
||||
// ensureAccepted(m1);
|
||||
// ensureAccepted(m2);
|
||||
// ensureAccepted(m3);
|
||||
|
||||
return uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* 추론 AI API 호출
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
|
||||
private void ensureAccepted(InferenceSendDto dto) {
|
||||
|
||||
Boolean ok =
|
||||
this.inferenceSend(dto)
|
||||
.timeout(java.time.Duration.ofSeconds(3)) // 접수는 빨리 와야 함
|
||||
.onErrorReturn(false) // 타임아웃/통신오류도 실패 처리
|
||||
.block(java.time.Duration.ofSeconds(4)); // 최종 안전장치 (짧게!)
|
||||
|
||||
if (!Boolean.TRUE.equals(ok)) {
|
||||
// 여기서 예외가 터져야 @Transactional 롤백됨
|
||||
throw new CustomApiException("BAD_GATEWAY", HttpStatus.BAD_GATEWAY);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 모델정보 조회 dto 생성 후 반환
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
private InferenceSendDto getModelInfo(Long id) {
|
||||
|
||||
Basic modelInfo = modelMngCoreService.findByModelUuid(id);
|
||||
|
||||
InferenceSendDto sendDto = new InferenceSendDto();
|
||||
sendDto.setModel_version(modelInfo.getModelVer());
|
||||
sendDto.setCd_model_path(modelInfo.getCdModelPath());
|
||||
sendDto.setCd_model_config(modelInfo.getCdModelConfig());
|
||||
sendDto.setCls_model_path(modelInfo.getClsModelPath());
|
||||
// sendDto.setCls_model_version(modelInfo.getCls);
|
||||
sendDto.setCd_model_type(modelInfo.getModelType());
|
||||
// sendDto.setPriority(modelInfo.getPriority());
|
||||
return sendDto;
|
||||
}
|
||||
|
||||
/**
|
||||
* geojson 파일 생성
|
||||
*
|
||||
* @param yyyy
|
||||
* @param mapSheetNums
|
||||
*/
|
||||
private void getSceneInference(String yyyy, List<String> mapSheetNums) {
|
||||
mapSheetMngCoreService.getSceneInference(yyyy, mapSheetNums);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user