Merge pull request '[KC-99] 추론관리 등록 수정, 모델 조회 추가' (#176) from feat/infer_dev_260107 into develop

Reviewed-on: https://kamco.gitea.gs.dabeeo.com/dabeeo/kamco-dabeeo-backoffice/pulls/176
This commit is contained in:
2026-01-09 17:52:17 +09:00
7 changed files with 137 additions and 28 deletions

View File

@@ -487,22 +487,13 @@ public class GlobalExceptionHandler {
this.errorLog(request, e);
String codeName = e.getCodeName();
HttpStatus status = e.getStatus();
// String message = e.getMessage() == null ? ApiResponseCode.getMessage(codeName) :
// e.getMessage();
//
// ApiResponseCode apiCode = ApiResponseCode.getCode(codeName);
//
// ErrorLogEntity errorLog =
// saveErrorLogData(
// request, apiCode, status, ErrorLogDto.LogErrorLevel.WARNING, e.getStackTrace());
//
// ApiResponseDto<String> body =
// ApiResponseDto.createException(apiCode, message, status, errorLog.getId());
ApiResponseCode responseCode = ApiResponseCode.from(codeName, status);
ErrorLogEntity errorLog =
saveErrorLogData(
request,
ApiResponseCode.getCode(codeName),
responseCode,
HttpStatus.valueOf(status.value()),
ErrorLogDto.LogErrorLevel.WARNING,
e.getStackTrace());

View File

@@ -194,5 +194,26 @@ public class ApiResponseDto<T> {
public static String getMessage(String name) {
return ApiResponseCode.valueOf(name.toUpperCase()).getText();
}
public static ApiResponseCode from(String codeName, HttpStatus status) {
if (codeName != null && !codeName.isBlank()) {
try {
return ApiResponseCode.valueOf(codeName.toUpperCase());
} catch (IllegalArgumentException ignore) {
// fallback
}
}
if (status != null) {
try {
return ApiResponseCode.valueOf(status.name());
} catch (IllegalArgumentException ignore) {
// fallback
}
}
return INTERNAL_SERVER_ERROR;
}
}
}

View File

@@ -5,6 +5,8 @@ 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 com.kamco.cd.kamcoback.model.dto.ModelMngDto;
import com.kamco.cd.kamcoback.model.service.ModelMngService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.ArraySchema;
@@ -34,6 +36,7 @@ public class InferenceResultApiController {
private final InferenceResultService inferenceResultService;
private final MapSheetMngService mapSheetMngService;
private final ModelMngService modelMngService;
@Operation(summary = "추론관리 목록", description = "어드민 홈 > 추론관리 > 추론관리 > 추론관리 목록")
@ApiResponses(
@@ -110,6 +113,35 @@ public class InferenceResultApiController {
return ApiResponseDto.ok(uuid);
}
@Operation(summary = "분석 모델 선택 조회", description = "변화탐지 실행 정보 입력 모델선택 팝업 ")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
description = "분석 모델 조회 성공",
content =
@Content(
mediaType = "application/json",
schema = @Schema(description = "분석 모델", implementation = Page.class))),
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
@GetMapping("/model")
public ApiResponseDto<Page<ModelMngDto.ModelList>> saveInferenceInfo(
@Parameter(description = "모델 생성일 시작", example = "2025-12-01") @RequestParam(required = false)
LocalDate strtDttm,
@Parameter(description = "모델 생성일 종료", example = "2026-01-09") @RequestParam(required = false)
LocalDate endDttm,
@Parameter(description = "키워드 (모델버전)", example = "M1.H1.E28") @RequestParam(required = false)
String searchVal,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "20") int size) {
ModelMngDto.searchReq searchReq = new ModelMngDto.searchReq(page, size, null);
Page<ModelMngDto.ModelList> result =
modelMngService.findModelMgmtList(searchReq, strtDttm, endDttm, null, searchVal);
return ApiResponseDto.ok(result);
}
// @ApiResponses(
// value = {
// @ApiResponse(

View File

@@ -61,13 +61,13 @@ public class InferenceResultService {
// 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());
// 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);
@@ -93,16 +93,20 @@ public class InferenceResultService {
.onErrorReturn(false);
}
/**
* api 호출 실패시 예외처리
*
* @param dto
*/
private void ensureAccepted(InferenceSendDto dto) {
Boolean ok =
this.inferenceSend(dto)
.timeout(java.time.Duration.ofSeconds(3)) // 접수는 빨리 와야 함
.timeout(java.time.Duration.ofSeconds(3))
.onErrorReturn(false) // 타임아웃/통신오류도 실패 처리
.block(java.time.Duration.ofSeconds(4)); // 최종 안전장치 (짧게!)
.block(java.time.Duration.ofSeconds(4));
if (!Boolean.TRUE.equals(ok)) {
// 여기서 예외가 터져야 @Transactional 롤백됨
throw new CustomApiException("BAD_GATEWAY", HttpStatus.BAD_GATEWAY);
}
}

View File

@@ -1,5 +1,6 @@
package com.kamco.cd.kamcoback.postgres.core;
import com.kamco.cd.kamcoback.common.enums.CommonUseStatus;
import com.kamco.cd.kamcoback.common.utils.UserUtil;
import com.kamco.cd.kamcoback.inference.dto.InferenceDetailDto;
import com.kamco.cd.kamcoback.inference.dto.InferenceDetailDto.Dashboard;
@@ -20,6 +21,7 @@ import jakarta.persistence.EntityNotFoundException;
import jakarta.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
@@ -69,6 +71,14 @@ public class InferenceResultCoreService {
// learn 테이블 저장
MapSheetLearnEntity savedLearn = mapSheetLearnRepository.save(mapSheetLearnEntity);
// if (req.getMapSheetScope().equals(MapSheetScope.ALL)) {
// List<String> mapSheetIds = new ArrayList<>();
// mapInkx5kRepository.findAll().forEach(mapInkx5kEntity -> {
// mapSheetIds.add(mapInkx5kEntity.getMapidcdNo());
// });
// req.setMapSheetNum(mapSheetIds);
// }
final int CHUNK = 1000;
List<MapSheetLearn5kEntity> buffer = new ArrayList<>(CHUNK);
List<String> mapSheetNumList = req.getMapSheetNum();
@@ -82,22 +92,48 @@ public class InferenceResultCoreService {
buffer.add(e);
if (buffer.size() == CHUNK) {
mapSheetLearn5kRepository.saveAll(buffer);
mapSheetLearn5kRepository.flush();
entityManager.clear();
this.flushChunk(buffer);
buffer.clear();
}
}
if (!buffer.isEmpty()) {
mapSheetLearn5kRepository.saveAll(buffer);
mapSheetLearn5kRepository.flush();
entityManager.clear();
this.flushChunk(buffer);
buffer.clear();
}
return savedLearn.getUuid();
}
private void flushChunk(List<MapSheetLearn5kEntity> buffer) {
// 청크 번호 추출 in 조건 만들기
List<String> chunkNums =
buffer.stream().map(e -> String.valueOf(e.getMapSheetNum())).distinct().toList();
// 추론 제외
List<MapInkx5kEntity> usedEntities =
mapInkx5kRepository.findByMapSheetNumInAndUseInference(chunkNums, CommonUseStatus.USE);
// TODO 추론 제외 했으면 파일 있는지도 확인 해야함
// 조회 결과에서 번호만 Set으로
Set<String> usedSet =
usedEntities.stream()
.map(MapInkx5kEntity::getMapidcdNo)
.collect(java.util.stream.Collectors.toSet());
// 필터 후 저장
List<MapSheetLearn5kEntity> toSave =
buffer.stream().filter(e -> usedSet.contains(String.valueOf(e.getMapSheetNum()))).toList();
if (!toSave.isEmpty()) {
mapSheetLearn5kRepository.saveAll(toSave);
mapSheetLearn5kRepository.flush();
}
entityManager.clear();
}
/****/
/**

View File

@@ -22,4 +22,9 @@ public interface MapInkx5kRepositoryCustom {
Page<MapInkx5kEntity> getSceneListByPage(
CommonUseStatus useInference, String searchVal, searchReq searchReq);
List<MapInkx5kEntity> findByMapSheetNumInAndUseInference(
List<String> mapSheetNums, CommonUseStatus use);
Optional<MapInkx5kEntity> findByMapidList();
}

View File

@@ -20,7 +20,9 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;
import org.springframework.stereotype.Repository;
@Repository
public class MapInkx5kRepositoryImpl extends QuerydslRepositorySupport
implements MapInkx5kRepositoryCustom {
@@ -127,6 +129,24 @@ public class MapInkx5kRepositoryImpl extends QuerydslRepositorySupport
return new PageImpl<>(content, pageable, count);
}
@Override
public List<MapInkx5kEntity> findByMapSheetNumInAndUseInference(
List<String> mapSheetNums, CommonUseStatus use) {
if (mapSheetNums == null || mapSheetNums.isEmpty()) {
return List.of();
}
return queryFactory
.selectFrom(mapInkx5kEntity)
.where(mapInkx5kEntity.mapidcdNo.in(mapSheetNums), mapInkx5kEntity.useInference.eq(use))
.fetch();
}
@Override
public Optional<MapInkx5kEntity> findByMapidList() {
return Optional.empty();
}
private BooleanExpression searchUseInference(CommonUseStatus useInference) {
if (Objects.isNull(useInference)) {
return null;