Merge pull request 'feat/infer_dev_260107' (#207) from feat/infer_dev_260107 into develop

Reviewed-on: https://kamco.gitea.gs.dabeeo.com/dabeeo/kamco-dabeeo-backoffice/pulls/207
This commit is contained in:
2026-01-12 22:47:25 +09:00
9 changed files with 354 additions and 115 deletions

View File

@@ -399,10 +399,14 @@ public class InferenceDetailDto {
public static class InferenceBatchSheet { public static class InferenceBatchSheet {
private Long id; private Long id;
private UUID uuid;
private Long m1BatchId; private Long m1BatchId;
private Long m2BatchId; private Long m2BatchId;
private Long m3BatchId; private Long m3BatchId;
private String status; private String status;
private String runningModelType; private String runningModelType;
private UUID m1ModelUuid;
private UUID m2ModelUuid;
private UUID m3ModelUuid;
} }
} }

View File

@@ -11,36 +11,36 @@ import lombok.Setter;
public class InferenceProgressDto { public class InferenceProgressDto {
private InferenceProgressDto.pred_requests_areas pred_requests_areas; private InferenceProgressDto.pred_requests_areas pred_requests_areas;
private String model1_version; private String modelVersion;
private String model2_version; private String cdModelPath;
private String model3_version; private String cdModelFileName;
private String cd_model_path; private String cdModelConfigPath;
private String cd_model_config; private String cdModelConfigFileName;
private String cls_model_path; private String cdModelClsPath;
private String cls_model_version; private String cdModelClsFileName;
private String cd_model_type; private String clsModelVersion;
private Integer priority; private Integer priority;
public InferenceProgressDto( public InferenceProgressDto(
InferenceProgressDto.pred_requests_areas pred_requests_areas, InferenceProgressDto.pred_requests_areas pred_requests_areas,
String model1_version, String modelVersion,
String model2_version, String cdModelPath,
String model3_version, String cdModelFileName,
String cd_model_path, String cdModelConfigPath,
String cd_model_config, String cdModelConfigFileName,
String cls_model_path, String cdModelClsPath,
String cls_model_version, String cdModelClsFileName,
String cd_model_type, String clsModelVersion,
Integer priority) { Integer priority) {
this.pred_requests_areas = pred_requests_areas; this.pred_requests_areas = pred_requests_areas;
this.model1_version = model1_version; this.modelVersion = modelVersion;
this.model2_version = model2_version; this.cdModelPath = cdModelPath;
this.model3_version = model3_version; this.cdModelFileName = cdModelFileName;
this.cd_model_path = cd_model_path; this.cdModelConfigPath = cdModelConfigPath;
this.cd_model_config = cd_model_config; this.cdModelConfigFileName = cdModelConfigFileName;
this.cls_model_path = cls_model_path; this.cdModelClsPath = cdModelClsPath;
this.cls_model_version = cls_model_version; this.cdModelClsFileName = cdModelClsFileName;
this.cd_model_type = cd_model_type; this.clsModelVersion = clsModelVersion;
this.priority = priority; this.priority = priority;
} }

View File

@@ -8,6 +8,7 @@ import com.kamco.cd.kamcoback.common.utils.interfaces.JsonFormatDttm;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import java.time.Duration;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.util.Arrays; import java.util.Arrays;
@@ -200,6 +201,7 @@ public class InferenceResultDto {
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public static class InferenceStatusDetailDto { public static class InferenceStatusDetailDto {
private String title; private String title;
private Integer compareYyyy; private Integer compareYyyy;
private Integer targetYyyy; private Integer targetYyyy;
@@ -207,7 +209,15 @@ public class InferenceResultDto {
private String mapSheetScope; private String mapSheetScope;
@JsonFormatDttm private ZonedDateTime inferStartDttm; @JsonFormatDttm private ZonedDateTime inferStartDttm;
@JsonFormatDttm private ZonedDateTime inferEndDttm; @JsonFormatDttm private ZonedDateTime inferEndDttm;
private Long detectingCnt; private Long detectingCnt = 0L;
private Long detectingEndCnt = 0L;
@JsonFormatDttm private ZonedDateTime m1ModelStartDttm;
@JsonFormatDttm private ZonedDateTime m1ModelEndDttm;
@JsonFormatDttm private ZonedDateTime m2ModelStartDttm;
@JsonFormatDttm private ZonedDateTime m2ModelEndDttm;
@JsonFormatDttm private ZonedDateTime m3ModelStartDttm;
@JsonFormatDttm private ZonedDateTime m3ModelEndDttm;
private String model1Ver; private String model1Ver;
private String model2Ver; private String model2Ver;
@@ -222,6 +232,13 @@ public class InferenceResultDto {
ZonedDateTime inferStartDttm, ZonedDateTime inferStartDttm,
ZonedDateTime inferEndDttm, ZonedDateTime inferEndDttm,
Long detectingCnt, Long detectingCnt,
Long detectingEndCnt,
ZonedDateTime m1ModelStartDttm,
ZonedDateTime m1ModelEndDttm,
ZonedDateTime m2ModelStartDttm,
ZonedDateTime m2ModelEndDttm,
ZonedDateTime m3ModelStartDttm,
ZonedDateTime m3ModelEndDttm,
String model1Ver, String model1Ver,
String model2Ver, String model2Ver,
String model3Ver) { String model3Ver) {
@@ -233,19 +250,27 @@ public class InferenceResultDto {
this.inferStartDttm = inferStartDttm; this.inferStartDttm = inferStartDttm;
this.inferEndDttm = inferEndDttm; this.inferEndDttm = inferEndDttm;
this.detectingCnt = detectingCnt; this.detectingCnt = detectingCnt;
this.detectingEndCnt = detectingEndCnt;
this.m1ModelStartDttm = m1ModelStartDttm;
this.m1ModelEndDttm = m1ModelEndDttm;
this.m2ModelStartDttm = m2ModelStartDttm;
this.m2ModelEndDttm = m2ModelEndDttm;
this.m3ModelStartDttm = m3ModelStartDttm;
this.m3ModelEndDttm = m3ModelEndDttm;
this.model1Ver = model1Ver; this.model1Ver = model1Ver;
this.model2Ver = model2Ver; this.model2Ver = model2Ver;
this.model3Ver = model3Ver; this.model3Ver = model3Ver;
if (this.detectingEndCnt == null) this.detectingEndCnt = 0L;
} }
private String usedServerName; private String usedServerName;
private Long detectingEndCnt = 7L;
private String model1VerStatus = "PROCCESING"; private String model1VerStatus = "PROCCESING";
private String model1VerStatusName = "진행중"; private String model1VerStatusName = "진행중";
private String model2VerStatus = "PROCCESING"; private String model2VerStatus = "PROCCESING";
private String model2VerStatusName = "진행중"; private String model2VerStatusName = "진행중";
private String model3VerStatus = "PROCCESING"; private String model3VerStatus = "PROCCESING";
private String model4VerStatusName = "진행중"; private String model3VerStatusName = "진행중";
public String getDetectOptionName() { public String getDetectOptionName() {
if (this.detectOption.equals("EXCL")) return "추론제외"; if (this.detectOption.equals("EXCL")) return "추론제외";
@@ -253,9 +278,55 @@ public class InferenceResultDto {
} }
public String getMapSheetScopeName() { public String getMapSheetScopeName() {
if (this.detectOption.equals("ALL")) return "전체"; if (this.mapSheetScope.equals("ALL")) return "전체";
return "부분"; return "부분";
} }
public double getDetectingRate() {
if (this.detectingCnt == null || this.detectingCnt == 0L) {
return 0.0;
}
if (this.detectingEndCnt == null) this.detectingEndCnt = 0L;
return (double) (this.detectingEndCnt / this.detectingCnt) * 100.0;
}
public String getM1DurationFormatted() {
if (this.m1ModelStartDttm == null || this.m1ModelEndDttm == null) {
return "00:00:00";
}
Duration duration = Duration.between(m1ModelStartDttm, m1ModelEndDttm);
long hours = duration.toHours();
long minutes = duration.toMinutesPart();
long seconds = duration.toSecondsPart();
return String.format("%02d:%02d:%02d", hours, minutes, seconds);
}
public String getM2DurationFormatted() {
if (this.m2ModelStartDttm == null || this.m2ModelEndDttm == null) {
return "00:00:00";
}
Duration duration = Duration.between(this.m2ModelStartDttm, this.m2ModelEndDttm);
long hours = duration.toHours();
long minutes = duration.toMinutesPart();
long seconds = duration.toSecondsPart();
return String.format("%02d:%02d:%02d", hours, minutes, seconds);
}
public String getM3DurationFormatted() {
if (this.m3ModelStartDttm == null || this.m3ModelEndDttm == null) {
return "00:00:00";
}
Duration duration = Duration.between(this.m3ModelStartDttm, this.m3ModelEndDttm);
long hours = duration.toHours();
long minutes = duration.toMinutesPart();
long seconds = duration.toSecondsPart();
return String.format("%02d:%02d:%02d", hours, minutes, seconds);
}
} }
@Getter @Getter
@@ -372,7 +443,13 @@ public class InferenceResultDto {
private String status; private String status;
private String type; private String type;
private ZonedDateTime inferStartDttm; private ZonedDateTime inferStartDttm;
private ZonedDateTime inferEndDttm;
private Long detectEndCnt;
private String modelComparePath; private String modelComparePath;
private String modelTargetPath; private String modelTargetPath;
private String modelModelPath;
private ZonedDateTime modelStartDttm;
private ZonedDateTime modelEndDttm;
private Long updateUid;
} }
} }

View File

@@ -212,6 +212,7 @@ public class InferenceResultService {
saveInferenceAiDto.setInferStartDttm(ZonedDateTime.now()); saveInferenceAiDto.setInferStartDttm(ZonedDateTime.now());
saveInferenceAiDto.setModelComparePath(modelComparePath); saveInferenceAiDto.setModelComparePath(modelComparePath);
saveInferenceAiDto.setModelTargetPath(modelTargetPath); saveInferenceAiDto.setModelTargetPath(modelTargetPath);
saveInferenceAiDto.setModelStartDttm(ZonedDateTime.now());
inferenceResultCoreService.update(saveInferenceAiDto); inferenceResultCoreService.update(saveInferenceAiDto);
} }
@@ -412,8 +413,11 @@ public class InferenceResultService {
String serverNames = ""; String serverNames = "";
for (InferenceServerStatusDto server : servers) { for (InferenceServerStatusDto server : servers) {
if (serverNames.equals("")) serverNames = server.getServerName(); if (serverNames.equals("")) {
else serverNames = serverNames + "," + server.getServerName(); serverNames = server.getServerName();
} else {
serverNames = serverNames + "," + server.getServerName();
}
} }
InferenceStatusDetailDto dto = inferenceResultCoreService.getInferenceStatus(uuid); InferenceStatusDetailDto dto = inferenceResultCoreService.getInferenceStatus(uuid);

View File

@@ -6,6 +6,7 @@ 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.Dashboard;
import com.kamco.cd.kamcoback.inference.dto.InferenceDetailDto.InferenceBatchSheet; import com.kamco.cd.kamcoback.inference.dto.InferenceDetailDto.InferenceBatchSheet;
import com.kamco.cd.kamcoback.inference.dto.InferenceDetailDto.MapSheet; import com.kamco.cd.kamcoback.inference.dto.InferenceDetailDto.MapSheet;
import com.kamco.cd.kamcoback.inference.dto.InferenceProgressDto;
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto; import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto;
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.InferenceServerStatusDto; import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.InferenceServerStatusDto;
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.InferenceStatusDetailDto; import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.InferenceStatusDetailDto;
@@ -24,6 +25,7 @@ import com.kamco.cd.kamcoback.postgres.repository.scene.MapInkx5kRepository;
import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityNotFoundException; import jakarta.persistence.EntityNotFoundException;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import java.time.ZonedDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@@ -229,16 +231,46 @@ public class InferenceResultCoreService {
if (request.getType().equals("M1")) { if (request.getType().equals("M1")) {
entity.setM1ModelBatchId(request.getBatchId()); entity.setM1ModelBatchId(request.getBatchId());
if (request.getModelStartDttm() != null) {
entity.setM1ModelStartDttm(request.getModelStartDttm());
}
if (request.getModelEndDttm() != null) {
entity.setM1ModelEndDttm(request.getModelEndDttm());
}
} else if (request.getType().equals("M2")) { } else if (request.getType().equals("M2")) {
entity.setM2ModelBatchId(request.getBatchId()); entity.setM2ModelBatchId(request.getBatchId());
if (request.getModelStartDttm() != null) {
entity.setM2ModelStartDttm(request.getModelStartDttm());
}
if (request.getModelEndDttm() != null) {
entity.setM2ModelEndDttm(request.getModelEndDttm());
}
} else if (request.getType().equals("M3")) { } else if (request.getType().equals("M3")) {
entity.setM3ModelBatchId(request.getBatchId()); entity.setM3ModelBatchId(request.getBatchId());
if (request.getModelStartDttm() != null) {
entity.setM3ModelStartDttm(request.getModelStartDttm());
}
if (request.getModelEndDttm() != null) {
entity.setM3ModelEndDttm(request.getModelEndDttm());
}
} }
if (request.getInferStartDttm() != null) { if (request.getInferStartDttm() != null) {
entity.setInferStartDttm(request.getInferStartDttm()); entity.setInferStartDttm(request.getInferStartDttm());
} }
if (request.getInferEndDttm() != null) {
entity.setInferEndDttm(request.getInferEndDttm());
}
if (request.getModelComparePath() != null) { if (request.getModelComparePath() != null) {
entity.setModelComparePath(request.getModelComparePath()); entity.setModelComparePath(request.getModelComparePath());
} }
@@ -247,8 +279,23 @@ public class InferenceResultCoreService {
entity.setModelTargetPath(request.getModelTargetPath()); entity.setModelTargetPath(request.getModelTargetPath());
} }
entity.setRunningModelType(request.getType()); if (request.getDetectEndCnt() != null) {
entity.setStatus(request.getStatus()); entity.setDetectEndCnt(request.getDetectEndCnt());
}
if (request.getType() != null) {
entity.setRunningModelType(request.getType());
}
if (request.getStatus() != null) {
entity.setStatus(request.getStatus());
}
if (request.getUpdateUid() != null) {
entity.setUpdatedUid(request.getUpdateUid());
}
entity.setUpdatedDttm(ZonedDateTime.now());
} }
public List<InferenceServerStatusDto> getInferenceServerStatusList() { public List<InferenceServerStatusDto> getInferenceServerStatusList() {
@@ -263,17 +310,20 @@ public class InferenceResultCoreService {
InferenceBatchSheet inferenceBatchSheet = new InferenceBatchSheet(); InferenceBatchSheet inferenceBatchSheet = new InferenceBatchSheet();
inferenceBatchSheet.setId(entity.getId()); inferenceBatchSheet.setId(entity.getId());
inferenceBatchSheet.setUuid(entity.getUuid());
inferenceBatchSheet.setM1BatchId(entity.getM1ModelBatchId()); inferenceBatchSheet.setM1BatchId(entity.getM1ModelBatchId());
inferenceBatchSheet.setM2BatchId(entity.getM2ModelBatchId()); inferenceBatchSheet.setM2BatchId(entity.getM2ModelBatchId());
inferenceBatchSheet.setM3BatchId(entity.getM3ModelBatchId()); inferenceBatchSheet.setM3BatchId(entity.getM3ModelBatchId());
inferenceBatchSheet.setStatus(entity.getStatus()); inferenceBatchSheet.setStatus(entity.getStatus());
inferenceBatchSheet.setRunningModelType(entity.getRunningModelType()); inferenceBatchSheet.setRunningModelType(entity.getRunningModelType());
inferenceBatchSheet.setM1ModelUuid(entity.getM1ModelUuid());
inferenceBatchSheet.setM2ModelUuid(entity.getM2ModelUuid());
inferenceBatchSheet.setM3ModelUuid(entity.getM3ModelUuid());
return inferenceBatchSheet; return inferenceBatchSheet;
} }
public SaveInferenceAiDto getInferenceAiResultById(Long id) { public InferenceProgressDto getInferenceAiResultById(Long id, String type, UUID modelUuid) {
return mapSheetLearnRepository.getInferenceAiResultById(id, modelUuid);
return null;
} }
public InferenceStatusDetailDto getInferenceStatus(UUID uuid) { public InferenceStatusDetailDto getInferenceStatus(UUID uuid) {

View File

@@ -124,6 +124,24 @@ public class MapSheetLearnEntity {
@Column(name = "model_target_path") @Column(name = "model_target_path")
private String modelTargetPath; private String modelTargetPath;
@Column(name = "m1_model_start_dttm")
private ZonedDateTime m1ModelStartDttm;
@Column(name = "m2_model_start_dttm")
private ZonedDateTime m2ModelStartDttm;
@Column(name = "m3_model_start_dttm")
private ZonedDateTime m3ModelStartDttm;
@Column(name = "m1_model_end_dttm")
private ZonedDateTime m1ModelEndDttm;
@Column(name = "m2_model_end_dttm")
private ZonedDateTime m2ModelEndDttm;
@Column(name = "m3_model_end_dttm")
private ZonedDateTime m3ModelEndDttm;
public InferenceResultDto.ResultList toDto() { public InferenceResultDto.ResultList toDto() {
return new InferenceResultDto.ResultList( return new InferenceResultDto.ResultList(
this.uuid, this.uuid,

View File

@@ -20,7 +20,7 @@ public interface MapSheetLearnRepositoryCustom {
Optional<MapSheetLearnEntity> getInferenceResultByStatus(String status); Optional<MapSheetLearnEntity> getInferenceResultByStatus(String status);
Optional<InferenceProgressDto> getInferenceAiResultById(Long id); InferenceProgressDto getInferenceAiResultById(Long id, UUID modelUuid);
public InferenceStatusDetailDto getInferenceStatus(UUID uuid); public InferenceStatusDetailDto getInferenceStatus(UUID uuid);
} }

View File

@@ -171,6 +171,7 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
mapSheetLearnEntity.inferStartDttm, mapSheetLearnEntity.inferStartDttm,
mapSheetLearnEntity.inferEndDttm, mapSheetLearnEntity.inferEndDttm,
mapSheetLearnEntity.detectingCnt, mapSheetLearnEntity.detectingCnt,
mapSheetLearnEntity.detectEndCnt,
m1Model.modelVer.as("model1Ver"), m1Model.modelVer.as("model1Ver"),
m2Model.modelVer.as("model2Ver"), m2Model.modelVer.as("model2Ver"),
m3Model.modelVer.as("model3Ver"))) m3Model.modelVer.as("model3Ver")))
@@ -188,32 +189,34 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
} }
@Override @Override
public Optional<InferenceProgressDto> getInferenceAiResultById(Long id) { public InferenceProgressDto getInferenceAiResultById(Long id, UUID modelUuid) {
// InferenceProgressDto dto =
// queryFactory QModelMngEntity model = new QModelMngEntity("model");
// .select(
// Projections.constructor( InferenceProgressDto dto =
// InferenceProgressDto.class, queryFactory
// Projections.constructor( .select(
// InferenceProgressDto.pred_requests_areas.class, Projections.constructor(
// mapSheetLearnEntity.compareYyyy, InferenceProgressDto.class,
// mapSheetLearnEntity.targetYyyy, Projections.constructor(
// mapSheetLearnEntity.modelComparePath, InferenceProgressDto.pred_requests_areas.class,
// mapSheetLearnEntity.modelTargetPath mapSheetLearnEntity.compareYyyy,
// ), mapSheetLearnEntity.targetYyyy,
// modelMngEntity.uuid.eq(mapSheetLearnEntity.m1ModelUuid).as("m1ModelUuid"), mapSheetLearnEntity.modelComparePath,
// modelMngEntity.uuid.eq(mapSheetLearnEntity.m2ModelUuid).as("m2ModelUuid"), mapSheetLearnEntity.modelTargetPath),
// mapSheetLearnEntity.cdModelPath, model.modelVer.as("modelVer"),
// mapSheetLearnEntity.cdModelConfig, model.cdModelPath.as("cdModelPath"),
// mapSheetLearnEntity.clsModelPath, model.cdModelFileName.as("cdModelFileName"),
// mapSheetLearnEntity.clsModelVersion, model.cdModelConfigPath.as("cdModelConfigPath"),
// mapSheetLearnEntity.cdModelType, model.cdModelConfigFileName.as("cdModelConfigFileName"),
// mapSheetLearnEntity.priority model.clsModelPath,
// ) model.clsModelFileName,
// ) model.clsModelVersion))
// .from(mapSheetLearnEntity) .from(mapSheetLearnEntity)
// .where(mapSheetLearnEntity.id.eq(id)) .join(model)
// .fetchOne(); .on(model.uuid.eq(modelUuid))
return Optional.empty(); .where(mapSheetLearnEntity.id.eq(id))
.fetchOne();
return dto;
} }
} }

View File

@@ -1,19 +1,30 @@
package com.kamco.cd.kamcoback.scheduler.service; package com.kamco.cd.kamcoback.scheduler.service;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.kamco.cd.kamcoback.common.exception.CustomApiException;
import com.kamco.cd.kamcoback.config.resttemplate.ExternalHttpClient; import com.kamco.cd.kamcoback.config.resttemplate.ExternalHttpClient;
import com.kamco.cd.kamcoback.config.resttemplate.ExternalHttpClient.ExternalCallResult; import com.kamco.cd.kamcoback.config.resttemplate.ExternalHttpClient.ExternalCallResult;
import com.kamco.cd.kamcoback.inference.dto.InferenceDetailDto.InferenceBatchSheet; import com.kamco.cd.kamcoback.inference.dto.InferenceDetailDto.InferenceBatchSheet;
import com.kamco.cd.kamcoback.inference.dto.InferenceProgressDto;
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.SaveInferenceAiDto;
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.Status; import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.Status;
import com.kamco.cd.kamcoback.inference.dto.InferenceSendDto;
import com.kamco.cd.kamcoback.inference.dto.InferenceSendDto.pred_requests_areas;
import com.kamco.cd.kamcoback.postgres.core.InferenceResultCoreService; import com.kamco.cd.kamcoback.postgres.core.InferenceResultCoreService;
import com.kamco.cd.kamcoback.scheduler.dto.JobStatusDto; import com.kamco.cd.kamcoback.scheduler.dto.JobStatusDto;
import jakarta.transaction.Transactional;
import java.time.ZonedDateTime;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.UUID;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -31,13 +42,18 @@ public class MapSheetInferenceJobService {
@Value("${inference.batch-url}") @Value("${inference.batch-url}")
private String batchUrl; private String batchUrl;
@Value("${spring.profiles.active}")
private String profile;
@Value("${inference.url}")
private String inferenceUrl;
/** 추론 진행 배치 1분 */
@Scheduled(fixedDelay = 60_000) @Scheduled(fixedDelay = 60_000)
@Transactional
public void runBatch() { public void runBatch() {
log.info("1분 배치 시작");
try { try {
// TODO: 배치 로직 작성
InferenceBatchSheet batchSheet = InferenceBatchSheet batchSheet =
inferenceResultCoreService.getInferenceResultByStatus(Status.IN_PROGRESS.getId()); inferenceResultCoreService.getInferenceResultByStatus(Status.IN_PROGRESS.getId());
@@ -80,64 +96,131 @@ public class MapSheetInferenceJobService {
String type = batchSheet.getRunningModelType(); String type = batchSheet.getRunningModelType();
if (type.equals("M1")) { if (type.equals("M1")) {
// M1 완료되었으면 M2 실행
this.startInference(
batchSheet.getId(), batchSheet.getUuid(), "M2", batchSheet.getM2ModelUuid());
// 종료시간
this.updateProcessingEndTimeByModel(batchSheet.getUuid(), ZonedDateTime.now(), "M1");
} else if (type.equals("M2")) { } else if (type.equals("M2")) {
// M1 완료되었으면 M3 실행
this.startInference(
batchSheet.getId(), batchSheet.getUuid(), "M3", batchSheet.getM3ModelUuid());
// 종료시간
this.updateProcessingEndTimeByModel(batchSheet.getUuid(), ZonedDateTime.now(), "M2");
} else if (type.equals("M3")) { } else if (type.equals("M3")) {
// 완료
SaveInferenceAiDto saveInferenceAiDto = new SaveInferenceAiDto();
saveInferenceAiDto.setUuid(batchSheet.getUuid());
saveInferenceAiDto.setStatus(Status.END.getId());
saveInferenceAiDto.setInferEndDttm(ZonedDateTime.now());
inferenceResultCoreService.update(saveInferenceAiDto);
// 종료시간
this.updateProcessingEndTimeByModel(batchSheet.getUuid(), ZonedDateTime.now(), "M3");
} }
} else {
SaveInferenceAiDto saveInferenceAiDto = new SaveInferenceAiDto();
saveInferenceAiDto.setUuid(batchSheet.getUuid());
saveInferenceAiDto.setStatus(Status.IN_PROGRESS.getId());
saveInferenceAiDto.setDetectEndCnt(dto.getCompletedJobs().longValue());
inferenceResultCoreService.update(saveInferenceAiDto);
} }
System.out.println(dto); } catch (JsonProcessingException e) {
Thread.sleep(3000); // 예시: 처리 시간 3초
} catch (InterruptedException | JsonProcessingException e) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
log.error("배치 중 인터럽트 발생", e); log.error("배치 중 인터럽트 발생", e);
} }
log.info("1분 배치 종료");
} }
private void startInference(Long id, String type) { private void startInference(Long id, UUID uuid, String type, UUID modelUuid) {
// InferenceResultDto.SaveInferenceAiDto req
// inferenceResultCoreService.getInferenceResultByU InferenceProgressDto progressDto =
// inferenceResultCoreService.getInferenceAiResultById(id, type, modelUuid);
// List<MapSheetNumDto> mapSheetNum = req.getMapSheetNum();
// List<String> mapSheetNumList = new ArrayList<>(); pred_requests_areas predRequestsAreas = new pred_requests_areas();
// predRequestsAreas.setInput1_year(progressDto.getPred_requests_areas().getInput1_year());
// for (MapSheetNumDto mapSheetDto : mapSheetNum) { predRequestsAreas.setInput2_year(progressDto.getPred_requests_areas().getInput2_year());
// mapSheetNumList.add(mapSheetDto.getMapSheetNum()); predRequestsAreas.setInput1_scene_path(
// } progressDto.getPred_requests_areas().getInput1_scene_path());
// predRequestsAreas.setInput2_scene_path(
// String modelComparePath = progressDto.getPred_requests_areas().getInput2_scene_path());
// this.getSceneInference(String.valueOf(req.getCompareYyyy()), mapSheetNumList);
// String modelTargetPath = InferenceSendDto m = new InferenceSendDto();
// this.getSceneInference(String.valueOf(req.getTargetYyyy()), mapSheetNumList); m.setModel_version(progressDto.getModelVersion());
// m.setCd_model_path(progressDto.getCdModelPath() + "/" + progressDto.getCdModelFileName());
// pred_requests_areas predRequestsAreas = new pred_requests_areas(); m.setCd_model_config(
// predRequestsAreas.setInput1_year(req.getCompareYyyy()); progressDto.getCdModelConfigPath() + "/" + progressDto.getCdModelConfigFileName());
// predRequestsAreas.setInput2_year(req.getTargetYyyy()); m.setCls_model_path(
// predRequestsAreas.setInput1_scene_path(modelComparePath); progressDto.getCdModelClsPath() + "/" + progressDto.getCdModelClsFileName());
// predRequestsAreas.setInput2_scene_path(modelTargetPath); m.setCls_model_version(progressDto.getClsModelVersion());
// m.setCd_model_type(type);
// InferenceSendDto m1 = this.getModelInfo(req.getModel1Uuid()); m.setPriority(progressDto.getPriority());
// InferenceSendDto m2 = this.getModelInfo(req.getModel2Uuid());
// InferenceSendDto m3 = this.getModelInfo(req.getModel3Uuid()); // 추론 다음모델 실행
// Long batchId = this.ensureAccepted(m);
// m1.setPred_requests_areas(predRequestsAreas);
// m2.setPred_requests_areas(predRequestsAreas); SaveInferenceAiDto saveInferenceAiDto = new SaveInferenceAiDto();
// m3.setPred_requests_areas(predRequestsAreas); saveInferenceAiDto.setUuid(uuid);
// saveInferenceAiDto.setBatchId(batchId);
// Long batchId = this.ensureAccepted(m1); saveInferenceAiDto.setStatus(Status.IN_PROGRESS.getId());
// saveInferenceAiDto.setType(type);
// SaveInferenceAiDto saveInferenceAiDto = new SaveInferenceAiDto(); saveInferenceAiDto.setModelStartDttm(ZonedDateTime.now());
// saveInferenceAiDto.setUuid(uuid); inferenceResultCoreService.update(saveInferenceAiDto);
// saveInferenceAiDto.setBatchId(batchId); }
// saveInferenceAiDto.setStatus(Status.IN_PROGRESS.getId());
// saveInferenceAiDto.setType("M1"); private Long ensureAccepted(InferenceSendDto dto) {
// saveInferenceAiDto.setInferStartDttm(ZonedDateTime.now()); log.info("dto null? {}", dto == null);
// inferenceResultCoreService.update(saveInferenceAiDto); ObjectMapper om = new ObjectMapper();
try {
log.info("dto json={}", om.writeValueAsString(dto));
} catch (Exception e) {
log.error(e.getMessage());
}
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(List.of(MediaType.APPLICATION_JSON));
// TODO 추후 삭제
if ("local".equals(profile)) {
dto.getPred_requests_areas().setInput1_scene_path("/kamco-nfs/requests/2023_local.geojson");
dto.getPred_requests_areas().setInput2_scene_path("/kamco-nfs/requests/2024_local.geojson");
}
ExternalCallResult<String> result =
externalHttpClient.call(inferenceUrl, HttpMethod.POST, dto, headers, String.class);
int status = result.statusCode();
String body = result.body();
if (status < 200 || status >= 300) {
throw new CustomApiException("BAD_GATEWAY", HttpStatus.BAD_GATEWAY);
}
Long batchId = 0L;
try {
List<Map<String, Object>> list =
om.readValue(body, new TypeReference<List<Map<String, Object>>>() {});
Integer batchIdInt = (Integer) list.get(0).get("batch_id");
batchId = batchIdInt.longValue();
if (list.isEmpty()) {
throw new IllegalStateException("Inference response is empty");
}
} catch (Exception e) {
log.error(e.getMessage());
}
return batchId;
}
private void updateProcessingEndTimeByModel(UUID uuid, ZonedDateTime dateTime, String type) {
SaveInferenceAiDto saveInferenceAiDto = new SaveInferenceAiDto();
saveInferenceAiDto.setUuid(uuid);
saveInferenceAiDto.setUpdateUid(0L);
saveInferenceAiDto.setModelEndDttm(dateTime);
saveInferenceAiDto.setType(type);
inferenceResultCoreService.update(saveInferenceAiDto);
} }
} }