국유인in 연동 가능여부 api 수정
This commit is contained in:
@@ -7,7 +7,7 @@ import com.kamco.cd.kamcoback.gukyuin.dto.ChngDetectMastDto.ChngDetectMastSearch
|
||||
import com.kamco.cd.kamcoback.gukyuin.dto.ChngDetectMastDto.ResReturn;
|
||||
import com.kamco.cd.kamcoback.gukyuin.dto.DetectMastDto.Basic;
|
||||
import com.kamco.cd.kamcoback.gukyuin.dto.DetectMastDto.DetectMastReq;
|
||||
import com.kamco.cd.kamcoback.gukyuin.dto.GukYuinDto;
|
||||
import com.kamco.cd.kamcoback.gukyuin.dto.GukYuinDto.GukYuinLinkableRes;
|
||||
import com.kamco.cd.kamcoback.gukyuin.service.GukYuinApiService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
@@ -114,12 +114,12 @@ public class GukYuinApiController {
|
||||
mediaType = "application/json",
|
||||
schema =
|
||||
@Schema(
|
||||
implementation = GukYuinDto.isLinkDto.class,
|
||||
implementation = GukYuinLinkableRes.class,
|
||||
description = "TRUE:연동가능, FALSE:연동 불가능"))),
|
||||
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||
})
|
||||
public ApiResponseDto<GukYuinDto.isLinkDto> getIsLinkGukYuin(
|
||||
public ApiResponseDto<GukYuinLinkableRes> getIsLinkGukYuin(
|
||||
@Parameter(description = "uuid", example = "5799eb21-4780-48b0-a82e-e58dcbb8806b")
|
||||
@PathVariable
|
||||
UUID uuid) {
|
||||
|
||||
@@ -1,19 +1,48 @@
|
||||
package com.kamco.cd.kamcoback.gukyuin.dto;
|
||||
|
||||
import com.kamco.cd.kamcoback.common.utils.enums.EnumType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
public class GukYuinDto {
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class isLinkDto {
|
||||
public static class GukYuinLinkableRes {
|
||||
|
||||
private Boolean isLinkable;
|
||||
private boolean linkable;
|
||||
// private GukYuinLinkFailCode code;
|
||||
private String message;
|
||||
}
|
||||
|
||||
/** 실패 코드 enum */
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum GukYuinLinkFailCode implements EnumType {
|
||||
OK("연동 가능"),
|
||||
NOT_FOUND("대상 회차가 없습니다."),
|
||||
SCOPE_PART_NOT_ALLOWED("부분 도엽은 연동 불가능 합니다."),
|
||||
HAS_RUNNING_INFERENCE("라벨링 진행 중 회차가 있습니다."),
|
||||
OTHER_GUKYUIN_IN_PROGRESS("국유in 연동 진행 중 회차가 있습니다.");
|
||||
|
||||
private final String desc;
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
return desc;
|
||||
}
|
||||
}
|
||||
|
||||
// Repository가 반환할 Fact(조회 결과)
|
||||
public record GukYuinLinkFacts(
|
||||
boolean existsLearn,
|
||||
boolean isPartScope,
|
||||
boolean hasRunningInference,
|
||||
boolean hasOtherUnfinishedGukYuin) {}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,9 @@ import com.kamco.cd.kamcoback.config.resttemplate.ExternalHttpClient;
|
||||
import com.kamco.cd.kamcoback.config.resttemplate.ExternalHttpClient.ExternalCallResult;
|
||||
import com.kamco.cd.kamcoback.gukyuin.dto.ChngDetectMastDto;
|
||||
import com.kamco.cd.kamcoback.gukyuin.dto.ChngDetectMastDto.ResReturn;
|
||||
import com.kamco.cd.kamcoback.gukyuin.dto.GukYuinDto;
|
||||
import com.kamco.cd.kamcoback.gukyuin.dto.GukYuinDto.GukYuinLinkFacts;
|
||||
import com.kamco.cd.kamcoback.gukyuin.dto.GukYuinDto.GukYuinLinkFailCode;
|
||||
import com.kamco.cd.kamcoback.gukyuin.dto.GukYuinDto.GukYuinLinkableRes;
|
||||
import com.kamco.cd.kamcoback.postgres.core.GukYuinCoreService;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -100,7 +102,35 @@ public class GukYuinApiService {
|
||||
* @param uuid uuid
|
||||
* @return
|
||||
*/
|
||||
public GukYuinDto.isLinkDto getIsLinkGukYuin(UUID uuid) {
|
||||
return gukyuinCoreService.getIsLinkGukYuin(uuid);
|
||||
public GukYuinLinkableRes getIsLinkGukYuin(UUID uuid) {
|
||||
GukYuinLinkFacts f = gukyuinCoreService.findLinkFacts(uuid);
|
||||
GukYuinLinkFailCode code = decideCode(f);
|
||||
|
||||
GukYuinLinkableRes res = new GukYuinLinkableRes();
|
||||
// res.setCode(code);
|
||||
res.setLinkable(code == GukYuinLinkFailCode.OK);
|
||||
res.setMessage(code.getDesc());
|
||||
return res;
|
||||
}
|
||||
|
||||
private GukYuinLinkFailCode decideCode(GukYuinLinkFacts f) {
|
||||
|
||||
if (!f.existsLearn()) {
|
||||
return GukYuinLinkFailCode.NOT_FOUND;
|
||||
}
|
||||
|
||||
if (f.isPartScope()) {
|
||||
return GukYuinLinkFailCode.SCOPE_PART_NOT_ALLOWED;
|
||||
}
|
||||
|
||||
if (f.hasRunningInference()) {
|
||||
return GukYuinLinkFailCode.HAS_RUNNING_INFERENCE;
|
||||
}
|
||||
|
||||
if (f.hasOtherUnfinishedGukYuin()) {
|
||||
return GukYuinLinkFailCode.OTHER_GUKYUIN_IN_PROGRESS;
|
||||
}
|
||||
|
||||
return GukYuinLinkFailCode.OK;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.kamco.cd.kamcoback.postgres.core;
|
||||
|
||||
import com.kamco.cd.kamcoback.gukyuin.dto.GukYuinDto;
|
||||
import com.kamco.cd.kamcoback.gukyuin.dto.GukYuinDto.GukYuinLinkFacts;
|
||||
import com.kamco.cd.kamcoback.postgres.repository.Inference.MapSheetLearnRepository;
|
||||
import java.util.UUID;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -18,7 +18,7 @@ public class GukYuinCoreService {
|
||||
* @param uuid uuid
|
||||
* @return
|
||||
*/
|
||||
public GukYuinDto.isLinkDto getIsLinkGukYuin(UUID uuid) {
|
||||
return mapSheetLearnRepository.getIsLinkGukYuin(uuid);
|
||||
public GukYuinLinkFacts findLinkFacts(UUID uuid) {
|
||||
return mapSheetLearnRepository.findLinkFacts(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.kamco.cd.kamcoback.postgres.repository.Inference;
|
||||
|
||||
import com.kamco.cd.kamcoback.gukyuin.dto.GukYuinDto;
|
||||
import com.kamco.cd.kamcoback.gukyuin.dto.GukYuinDto.GukYuinLinkFacts;
|
||||
import com.kamco.cd.kamcoback.inference.dto.InferenceDetailDto.AnalResultInfo;
|
||||
import com.kamco.cd.kamcoback.inference.dto.InferenceDetailDto.BboxPointDto;
|
||||
import com.kamco.cd.kamcoback.inference.dto.InferenceDetailDto.Dashboard;
|
||||
@@ -42,5 +42,5 @@ public interface MapSheetLearnRepositoryCustom {
|
||||
|
||||
Page<Geom> getInferenceGeomList(UUID uuid, SearchGeoReq searchGeoReq);
|
||||
|
||||
GukYuinDto.isLinkDto getIsLinkGukYuin(UUID uuid);
|
||||
GukYuinLinkFacts findLinkFacts(UUID uuid);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import static com.kamco.cd.kamcoback.postgres.entity.QSystemMetricEntity.systemM
|
||||
|
||||
import com.kamco.cd.kamcoback.common.exception.CustomApiException;
|
||||
import com.kamco.cd.kamcoback.common.utils.DateRange;
|
||||
import com.kamco.cd.kamcoback.gukyuin.dto.GukYuinDto;
|
||||
import com.kamco.cd.kamcoback.gukyuin.dto.GukYuinDto.GukYuinLinkFacts;
|
||||
import com.kamco.cd.kamcoback.gukyuin.dto.GukYuinStatus;
|
||||
import com.kamco.cd.kamcoback.inference.dto.InferenceDetailDto.AnalResultInfo;
|
||||
import com.kamco.cd.kamcoback.inference.dto.InferenceDetailDto.BboxPointDto;
|
||||
@@ -26,6 +26,8 @@ import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.InferenceStatusDe
|
||||
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.MapSheetScope;
|
||||
import com.kamco.cd.kamcoback.model.service.ModelMngService;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.MapSheetLearnEntity;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.QMapSheetAnalInferenceEntity;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.QMapSheetLearnEntity;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.QModelMngEntity;
|
||||
import com.querydsl.core.BooleanBuilder;
|
||||
import com.querydsl.core.types.Expression;
|
||||
@@ -513,67 +515,49 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public GukYuinDto.isLinkDto getIsLinkGukYuin(UUID uuid) {
|
||||
GukYuinDto.isLinkDto dto = new GukYuinDto.isLinkDto();
|
||||
public GukYuinLinkFacts findLinkFacts(UUID uuid) {
|
||||
|
||||
MapSheetLearnEntity learn =
|
||||
queryFactory
|
||||
.selectFrom(mapSheetLearnEntity)
|
||||
.where(mapSheetLearnEntity.uuid.eq(uuid))
|
||||
.selectFrom(QMapSheetLearnEntity.mapSheetLearnEntity)
|
||||
.where(QMapSheetLearnEntity.mapSheetLearnEntity.uuid.eq(uuid))
|
||||
.fetchOne();
|
||||
|
||||
if (learn == null) {
|
||||
dto.setIsLinkable(false);
|
||||
dto.setMessage("데이터가 없습니다.");
|
||||
return dto;
|
||||
return new GukYuinLinkFacts(false, false, false, false);
|
||||
}
|
||||
|
||||
if (MapSheetScope.PART.getId().equals(learn.getMapSheetScope())) {
|
||||
dto.setIsLinkable(false);
|
||||
dto.setMessage("분석도엽 전체만 국유in 연동이 가능합니다.");
|
||||
return dto;
|
||||
}
|
||||
boolean isPartScope = MapSheetScope.PART.getId().equals(learn.getMapSheetScope());
|
||||
|
||||
// 같은 연도에 ASSIGNED/ING inference 존재 여부
|
||||
Boolean hasRunningInference =
|
||||
QMapSheetAnalInferenceEntity inf = QMapSheetAnalInferenceEntity.mapSheetAnalInferenceEntity;
|
||||
QMapSheetLearnEntity learn2 = new QMapSheetLearnEntity("learn2");
|
||||
QMapSheetLearnEntity learnQ = QMapSheetLearnEntity.mapSheetLearnEntity;
|
||||
|
||||
boolean hasRunningInference =
|
||||
queryFactory
|
||||
.selectOne()
|
||||
.from(mapSheetAnalInferenceEntity)
|
||||
.join(mapSheetLearnEntity)
|
||||
.on(mapSheetAnalInferenceEntity.learnId.eq(mapSheetLearnEntity.id))
|
||||
.from(inf)
|
||||
.join(learn2)
|
||||
.on(inf.learnId.eq(learn2.id))
|
||||
.where(
|
||||
mapSheetLearnEntity.compareYyyy.eq(learn.getCompareYyyy()),
|
||||
mapSheetLearnEntity.targetYyyy.eq(learn.getTargetYyyy()),
|
||||
mapSheetAnalInferenceEntity.analState.in("ASSIGNED", "ING"))
|
||||
learn2.compareYyyy.eq(learn.getCompareYyyy()),
|
||||
learn2.targetYyyy.eq(learn.getTargetYyyy()),
|
||||
inf.analState.in("ASSIGNED", "ING"))
|
||||
.fetchFirst()
|
||||
!= null;
|
||||
|
||||
if (hasRunningInference) {
|
||||
dto.setIsLinkable(false);
|
||||
dto.setMessage("라벨링 중인 회차가 있습니다.");
|
||||
return dto;
|
||||
}
|
||||
|
||||
// 같은 연도에 아직 국유인 종료 안 된 다른 learn 존재 여부
|
||||
Boolean hasOtherUnfinishedGukYuin =
|
||||
boolean hasOtherUnfinishedGukYuin =
|
||||
queryFactory
|
||||
.selectOne()
|
||||
.from(mapSheetLearnEntity)
|
||||
.from(learnQ)
|
||||
.where(
|
||||
mapSheetLearnEntity.compareYyyy.eq(learn.getCompareYyyy()),
|
||||
mapSheetLearnEntity.targetYyyy.eq(learn.getTargetYyyy()),
|
||||
mapSheetLearnEntity.applyStatus.eq(GukYuinStatus.IN_PROGRESS.getId()),
|
||||
mapSheetLearnEntity.uuid.ne(learn.getUuid()))
|
||||
learnQ.compareYyyy.eq(learn.getCompareYyyy()),
|
||||
learnQ.targetYyyy.eq(learn.getTargetYyyy()),
|
||||
learnQ.applyStatus.eq(GukYuinStatus.IN_PROGRESS.getId()),
|
||||
learnQ.uuid.ne(learn.getUuid()))
|
||||
.fetchFirst()
|
||||
!= null;
|
||||
|
||||
if (hasOtherUnfinishedGukYuin) {
|
||||
dto.setIsLinkable(false);
|
||||
dto.setMessage("국유in 연동중인 회차가 있습니다.");
|
||||
return dto;
|
||||
}
|
||||
|
||||
dto.setIsLinkable(true);
|
||||
return dto;
|
||||
return new GukYuinLinkFacts(true, isPartScope, hasRunningInference, hasOtherUnfinishedGukYuin);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user