[KC-108] ai api batch 작업중

This commit is contained in:
2026-01-12 22:28:38 +09:00
parent 49f2efeb1e
commit 2b8af3215d
9 changed files with 557 additions and 360 deletions

View File

@@ -29,20 +29,22 @@ public class InferenceDetailDto {
private String dataName; private String dataName;
private Long mapSheepNum; private Long mapSheepNum;
private Long detectingCnt; private Long detectingCnt;
@JsonFormatDttm private ZonedDateTime analStrtDttm; @JsonFormatDttm
@JsonFormatDttm private ZonedDateTime analEndDttm; private ZonedDateTime analStrtDttm;
@JsonFormatDttm
private ZonedDateTime analEndDttm;
private Long analSec; private Long analSec;
private String analState; private String analState;
public Basic( public Basic(
Long id, Long id,
String dataName, String dataName,
Long mapSheepNum, Long mapSheepNum,
Long detectingCnt, Long detectingCnt,
ZonedDateTime analStrtDttm, ZonedDateTime analStrtDttm,
ZonedDateTime analEndDttm, ZonedDateTime analEndDttm,
Long analSec, Long analSec,
String analState) { String analState) {
this.id = id; this.id = id;
this.dataName = dataName; this.dataName = dataName;
this.mapSheepNum = mapSheepNum; this.mapSheepNum = mapSheepNum;
@@ -61,8 +63,10 @@ public class InferenceDetailDto {
private Long id; private Long id;
private String analTitle; private String analTitle;
private Long detectingCnt; private Long detectingCnt;
@JsonFormatDttm private ZonedDateTime analStrtDttm; @JsonFormatDttm
@JsonFormatDttm private ZonedDateTime analEndDttm; private ZonedDateTime analStrtDttm;
@JsonFormatDttm
private ZonedDateTime analEndDttm;
private Long analSec; private Long analSec;
private Long analPredSec; private Long analPredSec;
private String analState; private String analState;
@@ -70,16 +74,16 @@ public class InferenceDetailDto {
private String gukyuinUsed; private String gukyuinUsed;
public AnalResList( public AnalResList(
Long id, Long id,
String analTitle, String analTitle,
Long detectingCnt, Long detectingCnt,
ZonedDateTime analStrtDttm, ZonedDateTime analStrtDttm,
ZonedDateTime analEndDttm, ZonedDateTime analEndDttm,
Long analSec, Long analSec,
Long analPredSec, Long analPredSec,
String analState, String analState,
String analStateNm, String analStateNm,
String gukyuinUsed) { String gukyuinUsed) {
this.id = id; this.id = id;
this.analTitle = analTitle; this.analTitle = analTitle;
this.detectingCnt = detectingCnt; this.detectingCnt = detectingCnt;
@@ -102,8 +106,10 @@ public class InferenceDetailDto {
private String modelInfo; private String modelInfo;
private Integer targetYyyy; private Integer targetYyyy;
private Integer compareYyyy; private Integer compareYyyy;
@JsonFormatDttm private ZonedDateTime analStrtDttm; @JsonFormatDttm
@JsonFormatDttm private ZonedDateTime analEndDttm; private ZonedDateTime analStrtDttm;
@JsonFormatDttm
private ZonedDateTime analEndDttm;
private Long analSec; private Long analSec;
private Long analPredSec; private Long analPredSec;
private String resultUrl; private String resultUrl;
@@ -113,20 +119,20 @@ public class InferenceDetailDto {
private String analStateNm; private String analStateNm;
public AnalResSummary( public AnalResSummary(
Long id, Long id,
String analTitle, String analTitle,
String modelInfo, String modelInfo,
Integer targetYyyy, Integer targetYyyy,
Integer compareYyyy, Integer compareYyyy,
ZonedDateTime analStrtDttm, ZonedDateTime analStrtDttm,
ZonedDateTime analEndDttm, ZonedDateTime analEndDttm,
Long analSec, Long analSec,
Long analPredSec, Long analPredSec,
String resultUrl, String resultUrl,
Long detectingCnt, Long detectingCnt,
Double accuracy, Double accuracy,
String analState, String analState,
String analStateNm) { String analStateNm) {
this.id = id; this.id = id;
this.analTitle = analTitle; this.analTitle = analTitle;
this.modelInfo = modelInfo; this.modelInfo = modelInfo;
@@ -183,16 +189,17 @@ public class InferenceDetailDto {
private Clazzes target; private Clazzes target;
private MapSheet mapSheet; private MapSheet mapSheet;
private Coordinate center; private Coordinate center;
@JsonFormatDttm private ZonedDateTime updatedDttm; @JsonFormatDttm
private ZonedDateTime updatedDttm;
public DetailListEntity( public DetailListEntity(
UUID uuid, UUID uuid,
Double detectionScore, Double detectionScore,
Clazzes compare, Clazzes compare,
Clazzes target, Clazzes target,
MapSheet mapSheet, MapSheet mapSheet,
Coordinate center, Coordinate center,
ZonedDateTime updatedDttm) { ZonedDateTime updatedDttm) {
this.code = new Uid(uuid); this.code = new Uid(uuid);
this.detectionScore = detectionScore; this.detectionScore = detectionScore;
this.compare = compare; this.compare = compare;
@@ -233,7 +240,8 @@ public class InferenceDetailDto {
private String code; private String code;
private String name; private String name;
@JsonIgnore private Double score; @JsonIgnore
private Double score;
public Clazz(String code, Double score) { public Clazz(String code, Double score) {
this.code = code; this.code = code;
@@ -300,21 +308,23 @@ public class InferenceDetailDto {
String classAfterName; String classAfterName;
Double classAfterProb; Double classAfterProb;
Long mapSheetNum; Long mapSheetNum;
@JsonIgnore String gemoStr; @JsonIgnore
@JsonIgnore String geomCenterStr; String gemoStr;
@JsonIgnore
String geomCenterStr;
JsonNode gemo; JsonNode gemo;
JsonNode geomCenter; JsonNode geomCenter;
public Geom( public Geom(
Integer compareYyyy, Integer compareYyyy,
Integer targetYyyy, Integer targetYyyy,
String classBeforeCd, String classBeforeCd,
Double classBeforeProb, Double classBeforeProb,
String classAfterCd, String classAfterCd,
Double classAfterProb, Double classAfterProb,
Long mapSheetNum, Long mapSheetNum,
String gemoStr, String gemoStr,
String geomCenterStr) { String geomCenterStr) {
this.compareYyyy = compareYyyy; this.compareYyyy = compareYyyy;
this.targetYyyy = targetYyyy; this.targetYyyy = targetYyyy;
this.classBeforeCd = classBeforeCd; this.classBeforeCd = classBeforeCd;
@@ -385,7 +395,7 @@ public class InferenceDetailDto {
String[] sortParams = sort.split(","); String[] sortParams = sort.split(",");
String property = sortParams[0]; String property = sortParams[0];
Sort.Direction direction = Sort.Direction direction =
sortParams.length > 1 ? Sort.Direction.fromString(sortParams[1]) : Sort.Direction.ASC; sortParams.length > 1 ? Sort.Direction.fromString(sortParams[1]) : Sort.Direction.ASC;
return PageRequest.of(page, size, Sort.by(direction, property)); return PageRequest.of(page, size, Sort.by(direction, property));
} }
return PageRequest.of(page, size); return PageRequest.of(page, size);
@@ -399,10 +409,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

@@ -22,7 +22,9 @@ import org.springframework.data.domain.Pageable;
public class InferenceResultDto { public class InferenceResultDto {
/** 목록조회 dto */ /**
* 목록조회 dto
*/
@Getter @Getter
@Setter @Setter
@AllArgsConstructor @AllArgsConstructor
@@ -34,11 +36,15 @@ public class InferenceResultDto {
private String status; private String status;
private String mapSheetCnt; private String mapSheetCnt;
private Long detectingCnt; private Long detectingCnt;
@JsonFormatDttm private ZonedDateTime startTime; @JsonFormatDttm
@JsonFormatDttm private ZonedDateTime endTime; private ZonedDateTime startTime;
@JsonFormatDttm private ZonedDateTime elapsedTime; @JsonFormatDttm
private ZonedDateTime endTime;
@JsonFormatDttm
private ZonedDateTime elapsedTime;
private Boolean applyYn; private Boolean applyYn;
@JsonFormatDttm private ZonedDateTime applyDttm; @JsonFormatDttm
private ZonedDateTime applyDttm;
@JsonProperty("statusName") @JsonProperty("statusName")
public String statusName() { public String statusName() {
@@ -46,7 +52,9 @@ public class InferenceResultDto {
} }
} }
/** 목록조회 검색 조건 dto */ /**
* 목록조회 검색 조건 dto
*/
@Getter @Getter
@Setter @Setter
@NoArgsConstructor @NoArgsConstructor
@@ -68,7 +76,9 @@ public class InferenceResultDto {
} }
} }
/** 탐지 데이터 옵션 dto */ /**
* 탐지 데이터 옵션 dto
*/
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public enum MapSheetScope implements EnumType { public enum MapSheetScope implements EnumType {
@@ -89,7 +99,9 @@ public class InferenceResultDto {
} }
} }
/** 분석대상 도엽 enum */ /**
* 분석대상 도엽 enum
*/
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public enum DetectOption implements EnumType { public enum DetectOption implements EnumType {
@@ -137,7 +149,9 @@ public class InferenceResultDto {
} }
} }
/** 변화탐지 실행 정보 저장 요청 정보 */ /**
* 변화탐지 실행 정보 저장 요청 정보
*/
@Getter @Getter
@Setter @Setter
@NoArgsConstructor @NoArgsConstructor
@@ -176,13 +190,13 @@ public class InferenceResultDto {
@Schema(description = "탐지 데이터 옵션 - 추론제외(EXCL), 이전 년도 도엽 사용(PREV)", example = "EXCL") @Schema(description = "탐지 데이터 옵션 - 추론제외(EXCL), 이전 년도 도엽 사용(PREV)", example = "EXCL")
@NotBlank @NotBlank
@EnumValid( @EnumValid(
enumClass = DetectOption.class, enumClass = DetectOption.class,
message = "탐지 데이터 옵션은 '추론제외', '이전 년도 도엽 사용' 만 사용 가능합니다.") message = "탐지 데이터 옵션은 '추론제외', '이전 년도 도엽 사용' 만 사용 가능합니다.")
private String detectOption; private String detectOption;
@Schema( @Schema(
description = "5k 도협 번호 목록", description = "5k 도협 번호 목록",
example = "[{\"mapSheetNum\":37914034,\"mapSheetName\":\"죽변\"}]") example = "[{\"mapSheetNum\":37914034,\"mapSheetName\":\"죽변\"}]")
@NotNull @NotNull
private List<MapSheetNumDto> mapSheetNum; private List<MapSheetNumDto> mapSheetNum;
} }
@@ -200,13 +214,16 @@ 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;
private String detectOption; private String detectOption;
private String mapSheetScope; private String mapSheetScope;
@JsonFormatDttm private ZonedDateTime inferStartDttm; @JsonFormatDttm
@JsonFormatDttm private ZonedDateTime inferEndDttm; private ZonedDateTime inferStartDttm;
@JsonFormatDttm
private ZonedDateTime inferEndDttm;
private Long detectingCnt; private Long detectingCnt;
private String model1Ver; private String model1Ver;
@@ -214,17 +231,17 @@ public class InferenceResultDto {
private String model3Ver; private String model3Ver;
public InferenceStatusDetailDto( public InferenceStatusDetailDto(
String title, String title,
Integer compareYyyy, Integer compareYyyy,
Integer targetYyyy, Integer targetYyyy,
String detectOption, String detectOption,
String mapSheetScope, String mapSheetScope,
ZonedDateTime inferStartDttm, ZonedDateTime inferStartDttm,
ZonedDateTime inferEndDttm, ZonedDateTime inferEndDttm,
Long detectingCnt, Long detectingCnt,
String model1Ver, String model1Ver,
String model2Ver, String model2Ver,
String model3Ver) { String model3Ver) {
this.title = title; this.title = title;
this.compareYyyy = compareYyyy; this.compareYyyy = compareYyyy;
this.targetYyyy = targetYyyy; this.targetYyyy = targetYyyy;
@@ -248,12 +265,16 @@ public class InferenceResultDto {
private String model4VerStatusName = "진행중"; private String model4VerStatusName = "진행중";
public String getDetectOptionName() { public String getDetectOptionName() {
if (this.detectOption.equals("EXCL")) return "추론제외"; if (this.detectOption.equals("EXCL")) {
return "추론제외";
}
return "이전 년도 도엽 사용"; return "이전 년도 도엽 사용";
} }
public String getMapSheetScopeName() { public String getMapSheetScopeName() {
if (this.detectOption.equals("ALL")) return "전체"; if (this.detectOption.equals("ALL")) {
return "전체";
}
return "부분"; return "부분";
} }
} }
@@ -265,9 +286,12 @@ public class InferenceResultDto {
public static class InferenceServerStatusDto { public static class InferenceServerStatusDto {
private String serverName; private String serverName;
@JsonIgnore private float cpu_user; @JsonIgnore
@JsonIgnore private float cpu_system; private float cpu_user;
@JsonIgnore private float memused; @JsonIgnore
private float cpu_system;
@JsonIgnore
private float memused;
private Long kbmemused; private Long kbmemused;
private float gpuUtil; private float gpuUtil;
@@ -372,7 +396,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

@@ -96,7 +96,7 @@ public class InferenceResultService {
// 기준년도 조회 // 기준년도 조회
List<MngListDto> targetList = List<MngListDto> targetList =
mapSheetMngCoreService.getHstMapSheetList(req.getTargetYyyy(), mapTargetIds); mapSheetMngCoreService.getHstMapSheetList(req.getTargetYyyy(), mapTargetIds);
req.setMapSheetNum(this.createdMngDto(req, targetList)); req.setMapSheetNum(this.createdMngDto(req, targetList));
} }
@@ -109,19 +109,19 @@ public class InferenceResultService {
// 비교년도 탐지 제이터 옵션 별로 조회하여 req에 적용 // 비교년도 탐지 제이터 옵션 별로 조회하여 req에 적용
private List<MapSheetNumDto> createdMngDto( private List<MapSheetNumDto> createdMngDto(
InferenceResultDto.RegReq req, List<MngListDto> targetList) { InferenceResultDto.RegReq req, List<MngListDto> targetList) {
List<String> mapTargetIds = new ArrayList<>(); List<String> mapTargetIds = new ArrayList<>();
targetList.forEach( targetList.forEach(
hstMapSheet -> { hstMapSheet -> {
// 비교년도는 target 년도 기준으로 가져옴 파라미터 만들기 // 비교년도는 target 년도 기준으로 가져옴 파라미터 만들기
mapTargetIds.add(hstMapSheet.getMapSheetNum()); mapTargetIds.add(hstMapSheet.getMapSheetNum());
}); });
// 비교년도 조회 // 비교년도 조회
List<String> mapCompareIds = new ArrayList<>(); List<String> mapCompareIds = new ArrayList<>();
List<MngListCompareDto> compareList = List<MngListCompareDto> compareList =
mapSheetMngCoreService.getByHstMapSheetCompareList(req.getCompareYyyy(), mapTargetIds); mapSheetMngCoreService.getByHstMapSheetCompareList(req.getCompareYyyy(), mapTargetIds);
for (MngListCompareDto dto : compareList) { for (MngListCompareDto dto : compareList) {
// 추론 제외일때 이전년도 파일이 없으면 제외 // 추론 제외일때 이전년도 파일이 없으면 제외
@@ -136,35 +136,35 @@ public class InferenceResultService {
} }
Set<String> compareSet = Set<String> compareSet =
mapCompareIds.stream() mapCompareIds.stream()
.filter(Objects::nonNull) .filter(Objects::nonNull)
.map(String::trim) // 공백/개행 방지 .map(String::trim) // 공백/개행 방지
.collect(Collectors.toSet()); .collect(Collectors.toSet());
// target 기준 compare 비교하여 서로 있는것만 저장 // target 기준 compare 비교하여 서로 있는것만 저장
List<String> commonIds = List<String> commonIds =
mapTargetIds.stream() mapTargetIds.stream()
.filter(Objects::nonNull) .filter(Objects::nonNull)
.map(String::trim) .map(String::trim)
.filter(compareSet::contains) .filter(compareSet::contains)
.toList(); .toList();
Set<String> commonIdSet = Set<String> commonIdSet =
commonIds.stream().filter(Objects::nonNull).map(String::trim).collect(Collectors.toSet()); commonIds.stream().filter(Objects::nonNull).map(String::trim).collect(Collectors.toSet());
// 저장하기위해 파라미터 다시 구성 // 저장하기위해 파라미터 다시 구성
List<MapSheetNumDto> mapSheetNum = List<MapSheetNumDto> mapSheetNum =
targetList.stream() targetList.stream()
.filter(dto -> dto.getMapSheetNum() != null) .filter(dto -> dto.getMapSheetNum() != null)
.filter(dto -> commonIdSet.contains(dto.getMapSheetNum().trim())) .filter(dto -> commonIdSet.contains(dto.getMapSheetNum().trim()))
.map( .map(
dto -> { dto -> {
MapSheetNumDto mapSheetNumDto = new MapSheetNumDto(); MapSheetNumDto mapSheetNumDto = new MapSheetNumDto();
mapSheetNumDto.setMapSheetNum(dto.getMapSheetNum()); mapSheetNumDto.setMapSheetNum(dto.getMapSheetNum());
mapSheetNumDto.setMapSheetName(dto.getMapSheetName()); mapSheetNumDto.setMapSheetName(dto.getMapSheetName());
return mapSheetNumDto; return mapSheetNumDto;
}) })
.toList(); .toList();
return mapSheetNum; return mapSheetNum;
} }
@@ -184,9 +184,9 @@ public class InferenceResultService {
} }
String modelComparePath = String modelComparePath =
this.getSceneInference(String.valueOf(req.getCompareYyyy()), mapSheetNumList); this.getSceneInference(String.valueOf(req.getCompareYyyy()), mapSheetNumList);
String modelTargetPath = String modelTargetPath =
this.getSceneInference(String.valueOf(req.getTargetYyyy()), mapSheetNumList); this.getSceneInference(String.valueOf(req.getTargetYyyy()), mapSheetNumList);
pred_requests_areas predRequestsAreas = new pred_requests_areas(); pred_requests_areas predRequestsAreas = new pred_requests_areas();
predRequestsAreas.setInput1_year(req.getCompareYyyy()); predRequestsAreas.setInput1_year(req.getCompareYyyy());
@@ -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);
} }
@@ -240,7 +241,7 @@ public class InferenceResultService {
} }
ExternalCallResult<String> result = ExternalCallResult<String> result =
externalHttpClient.call(inferenceUrl, HttpMethod.POST, dto, headers, String.class); externalHttpClient.call(inferenceUrl, HttpMethod.POST, dto, headers, String.class);
int status = result.statusCode(); int status = result.statusCode();
String body = result.body(); String body = result.body();
@@ -253,7 +254,8 @@ public class InferenceResultService {
try { try {
List<Map<String, Object>> list = List<Map<String, Object>> list =
om.readValue(body, new TypeReference<List<Map<String, Object>>>() {}); om.readValue(body, new TypeReference<List<Map<String, Object>>>() {
});
Integer batchIdInt = (Integer) list.get(0).get("batch_id"); Integer batchIdInt = (Integer) list.get(0).get("batch_id");
batchId = batchIdInt.longValue(); batchId = batchIdInt.longValue();
@@ -352,7 +354,7 @@ public class InferenceResultService {
* @return * @return
*/ */
public Page<InferenceDetailDto.Geom> getInferenceResultGeomList( public Page<InferenceDetailDto.Geom> getInferenceResultGeomList(
Long id, InferenceDetailDto.SearchGeoReq searchGeoReq) { Long id, InferenceDetailDto.SearchGeoReq searchGeoReq) {
return inferenceResultCoreService.getInferenceResultGeomList(id, searchGeoReq); return inferenceResultCoreService.getInferenceResultGeomList(id, searchGeoReq);
} }
@@ -363,7 +365,7 @@ public class InferenceResultService {
* @return * @return
*/ */
public Page<InferenceDetailDto.DetailListEntity> listInferenceResultWithGeom( public Page<InferenceDetailDto.DetailListEntity> listInferenceResultWithGeom(
@NotNull Long id, InferenceDetailDto.SearchGeoReq searchReq) { @NotNull Long id, InferenceDetailDto.SearchGeoReq searchReq) {
return inferenceResultCoreService.listInferenceResultWithGeom(id, searchReq); return inferenceResultCoreService.listInferenceResultWithGeom(id, searchReq);
} }
@@ -408,12 +410,15 @@ public class InferenceResultService {
public InferenceStatusDetailDto getInferenceStatus(UUID uuid) { public InferenceStatusDetailDto getInferenceStatus(UUID uuid) {
List<InferenceServerStatusDto> servers = List<InferenceServerStatusDto> servers =
inferenceResultCoreService.getInferenceServerStatusList(); inferenceResultCoreService.getInferenceServerStatusList();
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;
@@ -63,11 +65,11 @@ public class InferenceResultCoreService {
*/ */
public UUID saveInferenceInfo(InferenceResultDto.RegReq req) { public UUID saveInferenceInfo(InferenceResultDto.RegReq req) {
String mapSheetName = String mapSheetName =
req.getMapSheetNum().get(0).getMapSheetName() + "" + req.getMapSheetNum().size() + ""; req.getMapSheetNum().get(0).getMapSheetName() + "" + req.getMapSheetNum().size() + "";
if (req.getMapSheetNum().size() == 1) { if (req.getMapSheetNum().size() == 1) {
mapSheetName = mapSheetName =
req.getMapSheetNum().get(0).getMapSheetName() + " " + req.getMapSheetNum().size() + ""; req.getMapSheetNum().get(0).getMapSheetName() + " " + req.getMapSheetNum().size() + "";
} }
MapSheetLearnEntity mapSheetLearnEntity = new MapSheetLearnEntity(); MapSheetLearnEntity mapSheetLearnEntity = new MapSheetLearnEntity();
@@ -115,22 +117,22 @@ public class InferenceResultCoreService {
// 청크 번호 추출 in 조건 만들기 // 청크 번호 추출 in 조건 만들기
List<String> chunkNums = List<String> chunkNums =
buffer.stream().map(e -> String.valueOf(e.getMapSheetNum())).distinct().toList(); buffer.stream().map(e -> String.valueOf(e.getMapSheetNum())).distinct().toList();
// 추론 제외 // 추론 제외
List<MapInkx5kEntity> usedEntities = List<MapInkx5kEntity> usedEntities =
mapInkx5kRepository.findByMapSheetNumInAndUseInference(chunkNums, CommonUseStatus.USE); mapInkx5kRepository.findByMapSheetNumInAndUseInference(chunkNums, CommonUseStatus.USE);
// TODO 추론 제외 했으면 파일 있는지도 확인 해야함 // TODO 추론 제외 했으면 파일 있는지도 확인 해야함
// 조회 결과에서 번호만 Set으로 // 조회 결과에서 번호만 Set으로
Set<String> usedSet = Set<String> usedSet =
usedEntities.stream() usedEntities.stream()
.map(MapInkx5kEntity::getMapidcdNo) .map(MapInkx5kEntity::getMapidcdNo)
.collect(java.util.stream.Collectors.toSet()); .collect(java.util.stream.Collectors.toSet());
// 필터 후 저장 // 필터 후 저장
List<MapSheetLearn5kEntity> toSave = List<MapSheetLearn5kEntity> toSave =
buffer.stream().filter(e -> usedSet.contains(String.valueOf(e.getMapSheetNum()))).toList(); buffer.stream().filter(e -> usedSet.contains(String.valueOf(e.getMapSheetNum()))).toList();
if (!toSave.isEmpty()) { if (!toSave.isEmpty()) {
mapSheetLearn5kRepository.saveAll(toSave); mapSheetLearn5kRepository.saveAll(toSave);
@@ -150,9 +152,9 @@ public class InferenceResultCoreService {
*/ */
public InferenceDetailDto.AnalResSummary getInferenceResultSummary(Long id) { public InferenceDetailDto.AnalResSummary getInferenceResultSummary(Long id) {
InferenceDetailDto.AnalResSummary summary = InferenceDetailDto.AnalResSummary summary =
mapSheetAnalDataRepository mapSheetAnalDataRepository
.getInferenceResultSummary(id) .getInferenceResultSummary(id)
.orElseThrow(() -> new EntityNotFoundException("요약정보를 찾을 수 없습니다. " + id)); .orElseThrow(() -> new EntityNotFoundException("요약정보를 찾을 수 없습니다. " + id));
return summary; return summary;
} }
@@ -173,7 +175,7 @@ public class InferenceResultCoreService {
* @return * @return
*/ */
public Page<InferenceDetailDto.Geom> getInferenceResultGeomList( public Page<InferenceDetailDto.Geom> getInferenceResultGeomList(
Long id, InferenceDetailDto.SearchGeoReq searchGeoReq) { Long id, InferenceDetailDto.SearchGeoReq searchGeoReq) {
return mapSheetAnalDataRepository.getInferenceGeomList(id, searchGeoReq); return mapSheetAnalDataRepository.getInferenceGeomList(id, searchGeoReq);
} }
@@ -185,16 +187,16 @@ public class InferenceResultCoreService {
*/ */
@Transactional(readOnly = true) @Transactional(readOnly = true)
public Page<InferenceDetailDto.DetailListEntity> listInferenceResultWithGeom( public Page<InferenceDetailDto.DetailListEntity> listInferenceResultWithGeom(
@NotNull Long analyId, InferenceDetailDto.SearchGeoReq searchReq) { @NotNull Long analyId, InferenceDetailDto.SearchGeoReq searchReq) {
// 분석 ID 에 해당하는 dataids를 가져온다. // 분석 ID 에 해당하는 dataids를 가져온다.
List<Long> dataIds = List<Long> dataIds =
mapSheetAnalDataRepository.listAnalyGeom(analyId).stream() mapSheetAnalDataRepository.listAnalyGeom(analyId).stream()
.mapToLong(MapSheetAnalDataInferenceEntity::getId) .mapToLong(MapSheetAnalDataInferenceEntity::getId)
.boxed() .boxed()
.toList(); .toList();
// 해당데이터의 폴리곤데이터를 가져온다 // 해당데이터의 폴리곤데이터를 가져온다
Page<MapSheetAnalDataInferenceGeomEntity> mapSheetAnalDataGeomEntities = Page<MapSheetAnalDataInferenceGeomEntity> mapSheetAnalDataGeomEntities =
mapSheetAnalDataRepository.listInferenceResultWithGeom(dataIds, searchReq); mapSheetAnalDataRepository.listInferenceResultWithGeom(dataIds, searchReq);
return mapSheetAnalDataGeomEntities.map(MapSheetAnalDataInferenceGeomEntity::toEntity); return mapSheetAnalDataGeomEntities.map(MapSheetAnalDataInferenceGeomEntity::toEntity);
} }
@@ -211,34 +213,64 @@ public class InferenceResultCoreService {
@Transactional(readOnly = true) @Transactional(readOnly = true)
public List<MapSheet> listGetScenes5k(Long analyId) { public List<MapSheet> listGetScenes5k(Long analyId) {
List<String> sceneCodes = List<String> sceneCodes =
mapSheetAnalDataRepository.listAnalyGeom(analyId).stream() mapSheetAnalDataRepository.listAnalyGeom(analyId).stream()
.mapToLong(MapSheetAnalDataInferenceEntity::getMapSheetNum) .mapToLong(MapSheetAnalDataInferenceEntity::getMapSheetNum)
.mapToObj(String::valueOf) .mapToObj(String::valueOf)
.toList(); .toList();
return mapInkx5kRepository.listGetScenes5k(sceneCodes).stream() return mapInkx5kRepository.listGetScenes5k(sceneCodes).stream()
.map(MapInkx5kEntity::toEntity) .map(MapInkx5kEntity::toEntity)
.toList(); .toList();
} }
public void update(SaveInferenceAiDto request) { public void update(SaveInferenceAiDto request) {
MapSheetLearnEntity entity = MapSheetLearnEntity entity =
mapSheetLearnRepository mapSheetLearnRepository
.getInferenceResultByUuid(request.getUuid()) .getInferenceResultByUuid(request.getUuid())
.orElseThrow(() -> new EntityNotFoundException()); .orElseThrow(() -> new EntityNotFoundException());
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,24 @@ 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() {
@@ -257,23 +305,26 @@ public class InferenceResultCoreService {
public InferenceBatchSheet getInferenceResultByStatus(String status) { public InferenceBatchSheet getInferenceResultByStatus(String status) {
MapSheetLearnEntity entity = MapSheetLearnEntity entity =
mapSheetLearnRepository mapSheetLearnRepository
.getInferenceResultByStatus(status) .getInferenceResultByStatus(status)
.orElseThrow(() -> new EntityNotFoundException(status)); .orElseThrow(() -> new EntityNotFoundException(status));
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

@@ -25,9 +25,9 @@ public class MapSheetLearnEntity {
@Id @Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "tb_map_sheet_learn_id_gen") @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "tb_map_sheet_learn_id_gen")
@SequenceGenerator( @SequenceGenerator(
name = "tb_map_sheet_learn_id_gen", name = "tb_map_sheet_learn_id_gen",
sequenceName = "tb_map_sheet_learn_uid", sequenceName = "tb_map_sheet_learn_uid",
allocationSize = 1) allocationSize = 1)
@Column(name = "id", nullable = false) @Column(name = "id", nullable = false)
private Long id; private Long id;
@@ -124,17 +124,30 @@ 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,
this.title, this.title,
this.status, this.status,
this.mapSheetCnt, this.mapSheetCnt,
this.detectingCnt, this.detectingCnt,
this.inferStartDttm, this.inferStartDttm,
this.inferEndDttm, this.inferEndDttm,
this.elapsedTime, this.elapsedTime,
this.applyYn, this.applyYn,
this.applyDttm); this.applyDttm);
} }
} }

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

@@ -40,7 +40,7 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
BooleanBuilder builder = new BooleanBuilder(); BooleanBuilder builder = new BooleanBuilder();
NumberExpression<Integer> statusOrder = NumberExpression<Integer> statusOrder =
new CaseBuilder().when(mapSheetLearnEntity.status.eq("Y")).then(0).otherwise(1); new CaseBuilder().when(mapSheetLearnEntity.status.eq("Y")).then(0).otherwise(1);
// 국유인 반영 여부 // 국유인 반영 여부
if (StringUtils.isNotBlank(req.getApplyYn())) { if (StringUtils.isNotBlank(req.getApplyYn())) {
@@ -54,10 +54,10 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
// 국유인 반영일 // 국유인 반영일
if (req.getStrtDttm() != null && req.getEndDttm() != null) { if (req.getStrtDttm() != null && req.getEndDttm() != null) {
builder.and( builder.and(
mapSheetLearnEntity mapSheetLearnEntity
.applyDttm .applyDttm
.goe(DateRange.start(req.getStrtDttm())) .goe(DateRange.start(req.getStrtDttm()))
.and(mapSheetLearnEntity.applyDttm.lt(DateRange.end(req.getEndDttm())))); .and(mapSheetLearnEntity.applyDttm.lt(DateRange.end(req.getEndDttm()))));
} }
// 제목 // 제목
@@ -66,21 +66,21 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
} }
List<MapSheetLearnEntity> content = List<MapSheetLearnEntity> content =
queryFactory queryFactory
.select(mapSheetLearnEntity) .select(mapSheetLearnEntity)
.from(mapSheetLearnEntity) .from(mapSheetLearnEntity)
.where(builder) .where(builder)
.offset(pageable.getOffset()) .offset(pageable.getOffset())
.limit(pageable.getPageSize()) .limit(pageable.getPageSize())
.orderBy(statusOrder.asc()) .orderBy(statusOrder.asc())
.fetch(); .fetch();
Long total = Long total =
queryFactory queryFactory
.select(mapSheetLearnEntity.count()) .select(mapSheetLearnEntity.count())
.from(mapSheetLearnEntity) .from(mapSheetLearnEntity)
.where(builder) .where(builder)
.fetchOne(); .fetchOne();
return new PageImpl<>(content, pageable, total == null ? 0L : total); return new PageImpl<>(content, pageable, total == null ? 0L : total);
} }
@@ -88,10 +88,10 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
@Override @Override
public Optional<MapSheetLearnEntity> getInferenceResultByUuid(UUID uuid) { public Optional<MapSheetLearnEntity> getInferenceResultByUuid(UUID uuid) {
return Optional.ofNullable( return Optional.ofNullable(
queryFactory queryFactory
.selectFrom(mapSheetLearnEntity) .selectFrom(mapSheetLearnEntity)
.where(mapSheetLearnEntity.uuid.eq(uuid)) .where(mapSheetLearnEntity.uuid.eq(uuid))
.fetchOne()); .fetchOne());
} }
@Override @Override
@@ -100,41 +100,41 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
BooleanBuilder builder = new BooleanBuilder(); BooleanBuilder builder = new BooleanBuilder();
List<Integer> latestIds = List<Integer> latestIds =
queryFactory queryFactory
.select(systemMetricEntity.id1.max()) .select(systemMetricEntity.id1.max())
.from(systemMetricEntity) .from(systemMetricEntity)
.groupBy(systemMetricEntity.serverName) .groupBy(systemMetricEntity.serverName)
.fetch(); .fetch();
List<Integer> latestGpuIds = List<Integer> latestGpuIds =
queryFactory queryFactory
.select(gpuMetricEntity.id1.max()) .select(gpuMetricEntity.id1.max())
.from(gpuMetricEntity) .from(gpuMetricEntity)
.groupBy(gpuMetricEntity.serverName) .groupBy(gpuMetricEntity.serverName)
.fetch(); .fetch();
List<InferenceServerStatusDto> foundContent = List<InferenceServerStatusDto> foundContent =
queryFactory queryFactory
.select( .select(
Projections.constructor( Projections.constructor(
InferenceServerStatusDto.class, InferenceServerStatusDto.class,
systemMetricEntity.serverName, systemMetricEntity.serverName,
systemMetricEntity.cpuUser, systemMetricEntity.cpuUser,
systemMetricEntity.cpuSystem, systemMetricEntity.cpuSystem,
systemMetricEntity.memused, systemMetricEntity.memused,
systemMetricEntity.kbmemused, systemMetricEntity.kbmemused,
gpuMetricEntity.gpuUtil)) gpuMetricEntity.gpuUtil))
.from(systemMetricEntity) .from(systemMetricEntity)
.leftJoin(gpuMetricEntity) .leftJoin(gpuMetricEntity)
.on( .on(
gpuMetricEntity gpuMetricEntity
.id1 .id1
.in(latestGpuIds) .in(latestGpuIds)
.and(gpuMetricEntity.serverName.eq(systemMetricEntity.serverName))) .and(gpuMetricEntity.serverName.eq(systemMetricEntity.serverName)))
.where(systemMetricEntity.id1.in(latestIds)) // In 절 사용 .where(systemMetricEntity.id1.in(latestIds)) // In 절 사용
.orderBy(systemMetricEntity.serverName.asc()) .orderBy(systemMetricEntity.serverName.asc())
.limit(4) .limit(4)
.fetch(); .fetch();
return foundContent; return foundContent;
} }
@@ -142,11 +142,11 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
@Override @Override
public Optional<MapSheetLearnEntity> getInferenceResultByStatus(String status) { public Optional<MapSheetLearnEntity> getInferenceResultByStatus(String status) {
return Optional.ofNullable( return Optional.ofNullable(
queryFactory queryFactory
.selectFrom(mapSheetLearnEntity) .selectFrom(mapSheetLearnEntity)
.where(mapSheetLearnEntity.status.eq(status)) .where(mapSheetLearnEntity.status.eq(status))
.limit(1) .limit(1)
.fetchOne()); .fetchOne());
} }
@Override @Override
@@ -159,61 +159,64 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
QModelMngEntity m3Model = new QModelMngEntity("m3Model"); QModelMngEntity m3Model = new QModelMngEntity("m3Model");
InferenceStatusDetailDto foundContent = InferenceStatusDetailDto foundContent =
queryFactory queryFactory
.select( .select(
Projections.constructor( Projections.constructor(
InferenceStatusDetailDto.class, InferenceStatusDetailDto.class,
mapSheetLearnEntity.title, mapSheetLearnEntity.title,
mapSheetLearnEntity.compareYyyy, mapSheetLearnEntity.compareYyyy,
mapSheetLearnEntity.targetYyyy, mapSheetLearnEntity.targetYyyy,
mapSheetLearnEntity.detectOption, mapSheetLearnEntity.detectOption,
mapSheetLearnEntity.mapSheetScope, mapSheetLearnEntity.mapSheetScope,
mapSheetLearnEntity.inferStartDttm, mapSheetLearnEntity.inferStartDttm,
mapSheetLearnEntity.inferEndDttm, mapSheetLearnEntity.inferEndDttm,
mapSheetLearnEntity.detectingCnt, mapSheetLearnEntity.detectingCnt,
m1Model.modelVer.as("model1Ver"), m1Model.modelVer.as("model1Ver"),
m2Model.modelVer.as("model2Ver"), m2Model.modelVer.as("model2Ver"),
m3Model.modelVer.as("model3Ver"))) m3Model.modelVer.as("model3Ver")))
.from(mapSheetLearnEntity) .from(mapSheetLearnEntity)
.leftJoin(m1Model) .leftJoin(m1Model)
.on(m1Model.uuid.eq(mapSheetLearnEntity.m1ModelUuid)) .on(m1Model.uuid.eq(mapSheetLearnEntity.m1ModelUuid))
.leftJoin(m2Model) .leftJoin(m2Model)
.on(m2Model.uuid.eq(mapSheetLearnEntity.m2ModelUuid)) .on(m2Model.uuid.eq(mapSheetLearnEntity.m2ModelUuid))
.leftJoin(m3Model) .leftJoin(m3Model)
.on(m3Model.uuid.eq(mapSheetLearnEntity.m3ModelUuid)) .on(m3Model.uuid.eq(mapSheetLearnEntity.m3ModelUuid))
.where(mapSheetLearnEntity.uuid.eq(uuid)) .where(mapSheetLearnEntity.uuid.eq(uuid))
.fetchOne(); .fetchOne();
return foundContent; return foundContent;
} }
@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) ))
// .where(mapSheetLearnEntity.id.eq(id)) .from(mapSheetLearnEntity)
// .fetchOne(); .join(model)
return Optional.empty(); .on(model.uuid.eq(modelUuid))
.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,7 +42,14 @@ 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;
@Scheduled(fixedDelay = 60_000) @Scheduled(fixedDelay = 60_000)
@Transactional
public void runBatch() { public void runBatch() {
log.info("1분 배치 시작"); log.info("1분 배치 시작");
@@ -39,7 +57,7 @@ public class MapSheetInferenceJobService {
// TODO: 배치 로직 작성 // TODO: 배치 로직 작성
InferenceBatchSheet batchSheet = InferenceBatchSheet batchSheet =
inferenceResultCoreService.getInferenceResultByStatus(Status.IN_PROGRESS.getId()); inferenceResultCoreService.getInferenceResultByStatus(Status.IN_PROGRESS.getId());
if (batchSheet == null) { if (batchSheet == null) {
return; return;
@@ -66,7 +84,7 @@ public class MapSheetInferenceJobService {
String url = batchUrl + "/" + batchId; String url = batchUrl + "/" + batchId;
ExternalCallResult<String> result = ExternalCallResult<String> result =
externalHttpClient.call(url, HttpMethod.GET, null, headers, String.class); externalHttpClient.call(url, HttpMethod.GET, null, headers, String.class);
int status = result.statusCode(); int status = result.statusCode();
if (status < 200 || status >= 300) { if (status < 200 || status >= 300) {
@@ -80,19 +98,34 @@ 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);
} }
@@ -100,44 +133,92 @@ public class MapSheetInferenceJobService {
log.info("1분 배치 종료"); 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(); pred_requests_areas predRequestsAreas = new pred_requests_areas();
// List<String> mapSheetNumList = new ArrayList<>(); predRequestsAreas.setInput1_year(progressDto.getPred_requests_areas().getInput1_year());
// predRequestsAreas.setInput2_year(progressDto.getPred_requests_areas().getInput2_year());
// for (MapSheetNumDto mapSheetDto : mapSheetNum) { predRequestsAreas.setInput1_scene_path(progressDto.getPred_requests_areas().getInput1_scene_path());
// mapSheetNumList.add(mapSheetDto.getMapSheetNum()); predRequestsAreas.setInput2_scene_path(progressDto.getPred_requests_areas().getInput2_scene_path());
// }
// InferenceSendDto m = new InferenceSendDto();
// String modelComparePath = m.setModel_version(progressDto.getModelVersion());
// this.getSceneInference(String.valueOf(req.getCompareYyyy()), mapSheetNumList); m.setCd_model_path(progressDto.getCdModelPath() + "/" + progressDto.getCdModelFileName());
// String modelTargetPath = m.setCd_model_config(progressDto.getCdModelConfigPath() + "/" + progressDto.getCdModelConfigFileName());
// this.getSceneInference(String.valueOf(req.getTargetYyyy()), mapSheetNumList); m.setCls_model_path(progressDto.getCdModelClsPath() + "/" + progressDto.getCdModelClsFileName());
// m.setCls_model_version(progressDto.getClsModelVersion());
// pred_requests_areas predRequestsAreas = new pred_requests_areas(); m.setCd_model_type(type);
// predRequestsAreas.setInput1_year(req.getCompareYyyy()); m.setPriority(progressDto.getPriority());
// predRequestsAreas.setInput2_year(req.getTargetYyyy());
// predRequestsAreas.setInput1_scene_path(modelComparePath); // 추론 다음모델 실행
// predRequestsAreas.setInput2_scene_path(modelTargetPath); Long batchId = this.ensureAccepted(m);
//
// InferenceSendDto m1 = this.getModelInfo(req.getModel1Uuid()); SaveInferenceAiDto saveInferenceAiDto = new SaveInferenceAiDto();
// InferenceSendDto m2 = this.getModelInfo(req.getModel2Uuid()); saveInferenceAiDto.setUuid(uuid);
// InferenceSendDto m3 = this.getModelInfo(req.getModel3Uuid()); saveInferenceAiDto.setBatchId(batchId);
// saveInferenceAiDto.setStatus(Status.IN_PROGRESS.getId());
// m1.setPred_requests_areas(predRequestsAreas); saveInferenceAiDto.setType(type);
// m2.setPred_requests_areas(predRequestsAreas); saveInferenceAiDto.setModelStartDttm(ZonedDateTime.now());
// m3.setPred_requests_areas(predRequestsAreas); inferenceResultCoreService.update(saveInferenceAiDto);
// }
// Long batchId = this.ensureAccepted(m1);
// private Long ensureAccepted(InferenceSendDto dto) {
// SaveInferenceAiDto saveInferenceAiDto = new SaveInferenceAiDto(); log.info("dto null? {}", dto == null);
// saveInferenceAiDto.setUuid(uuid); ObjectMapper om = new ObjectMapper();
// saveInferenceAiDto.setBatchId(batchId); try {
// saveInferenceAiDto.setStatus(Status.IN_PROGRESS.getId()); log.info("dto json={}", om.writeValueAsString(dto));
// saveInferenceAiDto.setType("M1"); } catch (Exception e) {
// saveInferenceAiDto.setInferStartDttm(ZonedDateTime.now()); log.error(e.getMessage());
// inferenceResultCoreService.update(saveInferenceAiDto); }
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);
} }
} }