Merge pull request '[KC-108] 분석도엽 ai api호출 테스트중' (#196) from feat/infer_dev_260107 into develop
Reviewed-on: https://kamco.gitea.gs.dabeeo.com/dabeeo/kamco-dabeeo-backoffice/pulls/196
This commit is contained in:
@@ -11,7 +11,7 @@ import lombok.Setter;
|
||||
@NoArgsConstructor
|
||||
public class InferenceSendDto {
|
||||
|
||||
private PredRequestsAreas predRequestsAreas;
|
||||
private pred_requests_areas pred_requests_areas;
|
||||
private String model_version;
|
||||
private String cd_model_path;
|
||||
private String cd_model_config;
|
||||
@@ -24,7 +24,7 @@ public class InferenceSendDto {
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public static class PredRequestsAreas {
|
||||
public static class pred_requests_areas {
|
||||
|
||||
private Integer input1_year;
|
||||
private Integer input2_year;
|
||||
|
||||
@@ -14,13 +14,13 @@ import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.MapSheetNumDto;
|
||||
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.MapSheetScope;
|
||||
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.ResultList;
|
||||
import com.kamco.cd.kamcoback.inference.dto.InferenceSendDto;
|
||||
import com.kamco.cd.kamcoback.inference.dto.InferenceSendDto.pred_requests_areas;
|
||||
import com.kamco.cd.kamcoback.mapsheet.dto.MapSheetMngDto.MngListCompareDto;
|
||||
import com.kamco.cd.kamcoback.mapsheet.dto.MapSheetMngDto.MngListDto;
|
||||
import com.kamco.cd.kamcoback.model.dto.ModelMngDto.Basic;
|
||||
import com.kamco.cd.kamcoback.postgres.core.InferenceResultCoreService;
|
||||
import com.kamco.cd.kamcoback.postgres.core.MapSheetMngCoreService;
|
||||
import com.kamco.cd.kamcoback.postgres.core.ModelMngCoreService;
|
||||
import com.kamco.cd.kamcoback.scene.dto.MapInkxMngDto.Search5kReq;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -70,116 +70,131 @@ public class InferenceResultService {
|
||||
*/
|
||||
@Transactional
|
||||
public UUID saveInferenceInfo(InferenceResultDto.RegReq req) {
|
||||
// 전체일때 5k도협 가져오기
|
||||
List<MapSheetNumDto> mapSheetTargetNum = new ArrayList<>();
|
||||
List<MapSheetNumDto> mapSheetCompareNum = new ArrayList<>();
|
||||
|
||||
// 분석대상 도엽이 전체일때
|
||||
if (MapSheetScope.ALL.getId().equals(req.getMapSheetScope())) {
|
||||
Search5kReq mapReq = new Search5kReq();
|
||||
mapReq.setUseInference("USE");
|
||||
|
||||
List<String> mapTargetIds = new ArrayList<>();
|
||||
// 기준년도 조회
|
||||
List<MngListDto> targetList = mapSheetMngCoreService.getHstMapSheetList(req.getTargetYyyy());
|
||||
|
||||
targetList.forEach(
|
||||
hstMapSheet -> {
|
||||
// 비교년도는 target 년도 기준으로 가져옴 파라미터 만들기
|
||||
mapTargetIds.add(hstMapSheet.getMapSheetNum());
|
||||
//
|
||||
// mapSheetNumDto.setMapSheetNum(hstMapSheet.getMapSheetNum());
|
||||
// mapSheetNumDto.setMapSheetName(hstMapSheet.getMapSheetName());
|
||||
// mapSheetTargetNum.add(mapSheetNumDto);
|
||||
});
|
||||
|
||||
// 비교년도 조회
|
||||
List<String> mapCompareIds = new ArrayList<>();
|
||||
List<MngListCompareDto> compareList =
|
||||
mapSheetMngCoreService.getByHstMapSheetCompareList(req.getCompareYyyy(), mapTargetIds);
|
||||
|
||||
for (MngListCompareDto dto : compareList) {
|
||||
// 추론 제외일때 이전년도 파일이 없으면 제외
|
||||
if (req.getDetectOption().equals(DetectOption.EXCL.getId())) {
|
||||
int targetYear = req.getTargetYyyy() - 1;
|
||||
if (dto.getBeforeYear() != targetYear) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// 비교년도는 target 년도 기준으로 가져옴
|
||||
mapCompareIds.add(dto.getMapSheetNum());
|
||||
}
|
||||
|
||||
Set<String> compareSet =
|
||||
mapCompareIds.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(String::trim) // 공백/개행 방지
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
List<String> commonIds =
|
||||
mapTargetIds.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(String::trim)
|
||||
.filter(compareSet::contains)
|
||||
.toList();
|
||||
|
||||
System.out.println("mapTargetIds size=" + mapTargetIds.size());
|
||||
System.out.println("mapCompareIds size=" + mapCompareIds.size());
|
||||
System.out.println("commonIds size=" + commonIds.size());
|
||||
System.out.println(commonIds);
|
||||
|
||||
Set<String> commonIdSet =
|
||||
commonIds.stream().filter(Objects::nonNull).map(String::trim).collect(Collectors.toSet());
|
||||
|
||||
List<MapSheetNumDto> mapSheetNum =
|
||||
targetList.stream()
|
||||
.filter(dto -> dto.getMapSheetNum() != null)
|
||||
.filter(dto -> commonIdSet.contains(dto.getMapSheetNum().trim()))
|
||||
.map(
|
||||
dto -> {
|
||||
MapSheetNumDto mapSheetNumDto = new MapSheetNumDto();
|
||||
mapSheetNumDto.setMapSheetNum(dto.getMapSheetNum());
|
||||
mapSheetNumDto.setMapSheetName(dto.getMapSheetName());
|
||||
return mapSheetNumDto;
|
||||
})
|
||||
.toList();
|
||||
req.setMapSheetNum(this.createdMngDto(req, targetList));
|
||||
|
||||
} else {
|
||||
// 부분ㄹ
|
||||
// 부분
|
||||
|
||||
List<String> mapTargetIds = new ArrayList<>();
|
||||
req.getMapSheetNum().forEach(dto -> mapTargetIds.add(dto.getMapSheetNum()));
|
||||
|
||||
// 기준년도 조회
|
||||
List<MngListDto> targetList =
|
||||
mapSheetMngCoreService.getHstMapSheetList(req.getTargetYyyy(), mapTargetIds);
|
||||
req.setMapSheetNum(this.createdMngDto(req, targetList));
|
||||
}
|
||||
|
||||
// 추론 테이블 저장
|
||||
// UUID uuid = inferenceResultCoreService.saveInferenceInfo(req);
|
||||
//
|
||||
// List<String> mapSheetNumList = new ArrayList<>();
|
||||
// for (MapSheetNumDto mapSheetDto : mapSheetNum) {
|
||||
// mapSheetNumList.add(mapSheetDto.getMapSheetNum());
|
||||
// }
|
||||
//
|
||||
// String modelComparePath =
|
||||
// this.getSceneInference(String.valueOf(req.getCompareYyyy()), mapSheetNumList);
|
||||
// String modelTargetPath =
|
||||
// this.getSceneInference(String.valueOf(req.getTargetYyyy()), mapSheetNumList);
|
||||
//
|
||||
// PredRequestsAreas predRequestsAreas = new PredRequestsAreas();
|
||||
// predRequestsAreas.setInput1_year(req.getCompareYyyy());
|
||||
// predRequestsAreas.setInput2_year(req.getTargetYyyy());
|
||||
// predRequestsAreas.setInput1_scene_path(modelComparePath);
|
||||
// predRequestsAreas.setInput2_scene_path(modelTargetPath);
|
||||
//
|
||||
// InferenceSendDto m1 = this.getModelInfo(req.getModel1Uuid());
|
||||
// InferenceSendDto m2 = this.getModelInfo(req.getModel2Uuid());
|
||||
// InferenceSendDto m3 = this.getModelInfo(req.getModel3Uuid());
|
||||
//
|
||||
// m1.setPredRequestsAreas(predRequestsAreas);
|
||||
// m2.setPredRequestsAreas(predRequestsAreas);
|
||||
// m3.setPredRequestsAreas(predRequestsAreas);
|
||||
UUID uuid = inferenceResultCoreService.saveInferenceInfo(req);
|
||||
this.startInference(req);
|
||||
|
||||
// ensureAccepted(m1);
|
||||
// ensureAccepted(m2);
|
||||
// ensureAccepted(m3);
|
||||
return uuid;
|
||||
}
|
||||
|
||||
return null;
|
||||
// 비교년도 탐지 제이터 옵션 별로 조회하여 req에 적용
|
||||
private List<MapSheetNumDto> createdMngDto(
|
||||
InferenceResultDto.RegReq req, List<MngListDto> targetList) {
|
||||
List<String> mapTargetIds = new ArrayList<>();
|
||||
|
||||
targetList.forEach(
|
||||
hstMapSheet -> {
|
||||
// 비교년도는 target 년도 기준으로 가져옴 파라미터 만들기
|
||||
mapTargetIds.add(hstMapSheet.getMapSheetNum());
|
||||
});
|
||||
|
||||
// 비교년도 조회
|
||||
List<String> mapCompareIds = new ArrayList<>();
|
||||
List<MngListCompareDto> compareList =
|
||||
mapSheetMngCoreService.getByHstMapSheetCompareList(req.getCompareYyyy(), mapTargetIds);
|
||||
|
||||
for (MngListCompareDto dto : compareList) {
|
||||
// 추론 제외일때 이전년도 파일이 없으면 제외
|
||||
if (req.getDetectOption().equals(DetectOption.EXCL.getId())) {
|
||||
int targetYear = req.getTargetYyyy() - 1;
|
||||
if (dto.getBeforeYear() != targetYear) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// 비교년도는 target 년도 기준으로 가져옴
|
||||
mapCompareIds.add(dto.getMapSheetNum());
|
||||
}
|
||||
|
||||
Set<String> compareSet =
|
||||
mapCompareIds.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(String::trim) // 공백/개행 방지
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
// target 기준 compare 비교하여 서로 있는것만 저장
|
||||
List<String> commonIds =
|
||||
mapTargetIds.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(String::trim)
|
||||
.filter(compareSet::contains)
|
||||
.toList();
|
||||
|
||||
Set<String> commonIdSet =
|
||||
commonIds.stream().filter(Objects::nonNull).map(String::trim).collect(Collectors.toSet());
|
||||
|
||||
// 저장하기위해 파라미터 다시 구성
|
||||
List<MapSheetNumDto> mapSheetNum =
|
||||
targetList.stream()
|
||||
.filter(dto -> dto.getMapSheetNum() != null)
|
||||
.filter(dto -> commonIdSet.contains(dto.getMapSheetNum().trim()))
|
||||
.map(
|
||||
dto -> {
|
||||
MapSheetNumDto mapSheetNumDto = new MapSheetNumDto();
|
||||
mapSheetNumDto.setMapSheetNum(dto.getMapSheetNum());
|
||||
mapSheetNumDto.setMapSheetName(dto.getMapSheetName());
|
||||
return mapSheetNumDto;
|
||||
})
|
||||
.toList();
|
||||
|
||||
return mapSheetNum;
|
||||
}
|
||||
|
||||
/**
|
||||
* 추론 실행 API 호출
|
||||
*
|
||||
* @param req
|
||||
*/
|
||||
private void startInference(InferenceResultDto.RegReq req) {
|
||||
|
||||
List<MapSheetNumDto> mapSheetNum = req.getMapSheetNum();
|
||||
List<String> mapSheetNumList = new ArrayList<>();
|
||||
|
||||
for (MapSheetNumDto mapSheetDto : mapSheetNum) {
|
||||
mapSheetNumList.add(mapSheetDto.getMapSheetNum());
|
||||
}
|
||||
|
||||
String modelComparePath =
|
||||
this.getSceneInference(String.valueOf(req.getCompareYyyy()), mapSheetNumList);
|
||||
String modelTargetPath =
|
||||
this.getSceneInference(String.valueOf(req.getTargetYyyy()), mapSheetNumList);
|
||||
|
||||
pred_requests_areas predRequestsAreas = new pred_requests_areas();
|
||||
predRequestsAreas.setInput1_year(req.getCompareYyyy());
|
||||
predRequestsAreas.setInput2_year(req.getTargetYyyy());
|
||||
predRequestsAreas.setInput1_scene_path(modelComparePath);
|
||||
predRequestsAreas.setInput2_scene_path(modelTargetPath);
|
||||
|
||||
InferenceSendDto m1 = this.getModelInfo(req.getModel1Uuid());
|
||||
InferenceSendDto m2 = this.getModelInfo(req.getModel2Uuid());
|
||||
InferenceSendDto m3 = this.getModelInfo(req.getModel3Uuid());
|
||||
|
||||
m1.setPred_requests_areas(predRequestsAreas);
|
||||
m2.setPred_requests_areas(predRequestsAreas);
|
||||
m3.setPred_requests_areas(predRequestsAreas);
|
||||
|
||||
ensureAccepted(m1);
|
||||
// ensureAccepted(m2);
|
||||
// ensureAccepted(m3);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -190,7 +205,9 @@ public class InferenceResultService {
|
||||
private void ensureAccepted(InferenceSendDto dto) {
|
||||
log.info("dto null? {}", dto == null);
|
||||
ObjectMapper om = new ObjectMapper();
|
||||
String json = "";
|
||||
try {
|
||||
json = om.writeValueAsString(dto);
|
||||
log.info("dto json={}", om.writeValueAsString(dto));
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
@@ -200,7 +217,7 @@ public class InferenceResultService {
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
|
||||
ExternalCallResult result =
|
||||
externalHttpClient.call(inferenceUrl, HttpMethod.POST, dto, headers);
|
||||
externalHttpClient.call(inferenceUrl, HttpMethod.POST, json, headers);
|
||||
|
||||
if (!result.success()) {
|
||||
throw new CustomApiException("BAD_GATEWAY", HttpStatus.BAD_GATEWAY);
|
||||
|
||||
@@ -242,6 +242,10 @@ public class MapSheetMngCoreService {
|
||||
return mapSheetMngRepository.findByHstMapSheetTargetList(mngYyyy);
|
||||
}
|
||||
|
||||
public List<MngListDto> getHstMapSheetList(int mngYyyy, List<String> mapIds) {
|
||||
return mapSheetMngRepository.findByHstMapSheetTargetList(mngYyyy, mapIds);
|
||||
}
|
||||
|
||||
public List<MngListCompareDto> getByHstMapSheetCompareList(int mngYyyy, List<String> mapId) {
|
||||
return mapSheetMngRepository.findByHstMapSheetCompareList(mngYyyy, mapId);
|
||||
}
|
||||
|
||||
@@ -63,6 +63,8 @@ public interface MapSheetMngRepositoryCustom {
|
||||
|
||||
List<MngListDto> findByHstMapSheetTargetList(int mngYyyy);
|
||||
|
||||
List<MngListDto> findByHstMapSheetTargetList(int mngYyyy, List<String> mapIds);
|
||||
|
||||
List<MngListCompareDto> findByHstMapSheetCompareList(int mngYyyy, List<String> mapId);
|
||||
|
||||
MapSheetMngDto.MngFilesDto findByFileUidMapSheetFile(Long fileUid);
|
||||
|
||||
@@ -498,25 +498,46 @@ public class MapSheetMngRepositoryImpl extends QuerydslRepositorySupport
|
||||
.fetch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MngListDto> findByHstMapSheetTargetList(int mngYyyy, List<String> mapIds) {
|
||||
BooleanBuilder whereBuilder = new BooleanBuilder();
|
||||
whereBuilder.and(mapSheetMngHstEntity.mngYyyy.eq(mngYyyy));
|
||||
whereBuilder.and(mapSheetMngHstEntity.mapSheetNum.in(mapIds));
|
||||
whereBuilder.and(mapSheetMngHstEntity.dataState.eq("DONE"));
|
||||
whereBuilder.and(mapSheetMngHstEntity.syncState.eq("DONE"));
|
||||
whereBuilder.and(mapSheetMngHstEntity.useInference.eq("USE"));
|
||||
|
||||
return queryFactory
|
||||
.select(
|
||||
Projections.constructor(
|
||||
MngListDto.class,
|
||||
mapSheetMngHstEntity.mngYyyy,
|
||||
mapSheetMngHstEntity.mapSheetNum,
|
||||
mapSheetMngHstEntity.mapSheetName))
|
||||
.from(mapSheetMngHstEntity)
|
||||
.where(whereBuilder)
|
||||
.fetch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MngListCompareDto> findByHstMapSheetCompareList(int mngYyyy, List<String> mapIds) {
|
||||
|
||||
String sql =
|
||||
"""
|
||||
SELECT
|
||||
t.map_sheet_num,
|
||||
t.map_years,
|
||||
COALESCE(s.target_year, 0) AS before_year
|
||||
FROM public.tb_map_sheet_years_map t
|
||||
LEFT JOIN LATERAL (
|
||||
SELECT x::int AS target_year
|
||||
FROM unnest(string_to_array(t.map_years, '>')) AS x
|
||||
WHERE x::int <= :mngYyyy
|
||||
ORDER BY x::int DESC
|
||||
LIMIT 1
|
||||
) s ON true
|
||||
WHERE t.map_sheet_num = ANY(:mapIds)
|
||||
""";
|
||||
SELECT
|
||||
t.map_sheet_num,
|
||||
t.map_years,
|
||||
COALESCE(s.target_year, 0) AS before_year
|
||||
FROM public.tb_map_sheet_years_map t
|
||||
LEFT JOIN LATERAL (
|
||||
SELECT x::int AS target_year
|
||||
FROM unnest(string_to_array(t.map_years, '>')) AS x
|
||||
WHERE x::int <= :mngYyyy
|
||||
ORDER BY x::int DESC
|
||||
LIMIT 1
|
||||
) s ON true
|
||||
WHERE t.map_sheet_num = ANY(:mapIds)
|
||||
""";
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object[]> rows =
|
||||
|
||||
Reference in New Issue
Block a user