추론 결과 geom 조회 쿼리 수정
This commit is contained in:
@@ -24,6 +24,7 @@ import com.kamco.cd.kamcoback.postgres.entity.MapSheetLearnEntity;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.QModelMngEntity;
|
||||
import com.querydsl.core.BooleanBuilder;
|
||||
import com.querydsl.core.types.Projections;
|
||||
import com.querydsl.core.types.dsl.BooleanExpression;
|
||||
import com.querydsl.core.types.dsl.CaseBuilder;
|
||||
import com.querydsl.core.types.dsl.Expressions;
|
||||
import com.querydsl.core.types.dsl.NumberExpression;
|
||||
@@ -360,42 +361,51 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
|
||||
@Override
|
||||
public Page<Geom> getInferenceGeomList(UUID uuid, SearchGeoReq searchGeoReq) {
|
||||
Pageable pageable = searchGeoReq.toPageable();
|
||||
BooleanBuilder builder = new BooleanBuilder();
|
||||
BooleanBuilder where = new BooleanBuilder();
|
||||
|
||||
// analUid로 분석 정보 조회
|
||||
// 1) 분석 엔티티 조회
|
||||
MapSheetLearnEntity analEntity =
|
||||
queryFactory
|
||||
.selectFrom(mapSheetLearnEntity)
|
||||
.where(mapSheetLearnEntity.uuid.eq(uuid))
|
||||
.fetchOne();
|
||||
|
||||
if (Objects.isNull(analEntity)) {
|
||||
if (analEntity == null) {
|
||||
throw new CustomApiException("NOT_FOUND_DATA", HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
// 추론결과 id
|
||||
builder.and(mapSheetAnalInferenceEntity.learnId.eq(analEntity.getId()));
|
||||
// 2) where 조건
|
||||
where.and(mapSheetAnalInferenceEntity.learnId.eq(analEntity.getId()));
|
||||
|
||||
// 기준년도 분류
|
||||
if (searchGeoReq.getTargetClass() != null && !searchGeoReq.getTargetClass().equals("")) {
|
||||
builder.and(
|
||||
if (searchGeoReq.getTargetClass() != null && !searchGeoReq.getTargetClass().isBlank()) {
|
||||
where.and(
|
||||
mapSheetAnalDataInferenceGeomEntity.classAfterCd.eq(
|
||||
searchGeoReq.getTargetClass().toLowerCase()));
|
||||
}
|
||||
|
||||
// 비교년도 분류
|
||||
if (searchGeoReq.getCompareClass() != null && !searchGeoReq.getCompareClass().equals("")) {
|
||||
builder.and(
|
||||
if (searchGeoReq.getCompareClass() != null && !searchGeoReq.getCompareClass().isBlank()) {
|
||||
where.and(
|
||||
mapSheetAnalDataInferenceGeomEntity.classBeforeCd.eq(
|
||||
searchGeoReq.getCompareClass().toLowerCase()));
|
||||
}
|
||||
|
||||
// 분석도엽
|
||||
if (searchGeoReq.getMapSheetNum() != null) {
|
||||
Long mapSheetNum = searchGeoReq.getMapSheetNum();
|
||||
builder.and(mapSheetAnalDataInferenceGeomEntity.mapSheetNum.like("%" + mapSheetNum + "%"));
|
||||
//
|
||||
// where.and(mapSheetAnalDataInferenceGeomEntity.mapSheetNum.eq(searchGeoReq.getMapSheetNum()));
|
||||
where.and(
|
||||
mapSheetAnalDataInferenceGeomEntity.mapSheetNum.like(
|
||||
"%" + searchGeoReq.getMapSheetNum() + "%"));
|
||||
}
|
||||
|
||||
// 3) inkx 조인 조건: JPQL/HQL에서 '~' 불가 → function('regexp_match', ...) 사용
|
||||
BooleanExpression inkxIsNumeric =
|
||||
Expressions.booleanTemplate(
|
||||
"function('regexp_match', {0}, '^[0-9]+$') is not null", mapInkx5kEntity.mapidcdNo);
|
||||
|
||||
NumberExpression<Long> inkxNoAsLong =
|
||||
Expressions.numberTemplate(Long.class, "cast({0} as long)", mapInkx5kEntity.mapidcdNo);
|
||||
|
||||
// 4) content
|
||||
List<Geom> content =
|
||||
queryFactory
|
||||
.select(
|
||||
@@ -411,45 +421,32 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
|
||||
mapSheetAnalDataInferenceGeomEntity.classAfterCd,
|
||||
mapSheetAnalDataInferenceGeomEntity.classAfterProb,
|
||||
mapSheetAnalDataInferenceGeomEntity.mapSheetNum,
|
||||
mapInkx5kEntity.mapidNm
|
||||
// Expressions.stringTemplate(
|
||||
// "ST_AsGeoJSON({0})",
|
||||
// mapSheetAnalDataInferenceGeomEntity.geom),
|
||||
// Expressions.stringTemplate(
|
||||
// "ST_AsGeoJSON({0})",
|
||||
// mapSheetAnalDataInferenceGeomEntity.geomCenter)
|
||||
))
|
||||
mapInkx5kEntity.mapidNm))
|
||||
.from(mapSheetAnalInferenceEntity)
|
||||
.join(mapSheetAnalDataInferenceEntity)
|
||||
.on(mapSheetAnalDataInferenceEntity.analUid.eq(mapSheetAnalInferenceEntity.id))
|
||||
.join(mapSheetAnalDataInferenceGeomEntity)
|
||||
.on(mapSheetAnalDataInferenceGeomEntity.dataUid.eq(mapSheetAnalDataInferenceEntity.id))
|
||||
.join(mapInkx5kEntity)
|
||||
.on(
|
||||
mapSheetAnalDataInferenceGeomEntity.mapSheetNum.eq(
|
||||
Expressions.numberTemplate(
|
||||
Long.class, "CAST({0} AS long)", mapInkx5kEntity.mapidcdNo)))
|
||||
.where(builder)
|
||||
.on(inkxIsNumeric.and(mapSheetAnalDataInferenceGeomEntity.mapSheetNum.eq(inkxNoAsLong)))
|
||||
.where(where)
|
||||
.orderBy(mapSheetAnalDataInferenceGeomEntity.geoUid.desc())
|
||||
.offset(pageable.getOffset())
|
||||
.limit(pageable.getPageSize())
|
||||
.fetch();
|
||||
|
||||
long total =
|
||||
// 5) total (조인 최소화 유지)
|
||||
Long total =
|
||||
queryFactory
|
||||
.select(mapSheetAnalDataInferenceGeomEntity.geoUid)
|
||||
.select(mapSheetAnalDataInferenceGeomEntity.geoUid.count())
|
||||
.from(mapSheetAnalInferenceEntity)
|
||||
.join(mapSheetAnalDataInferenceEntity)
|
||||
.on(mapSheetAnalDataInferenceEntity.analUid.eq(mapSheetAnalInferenceEntity.id))
|
||||
.join(mapSheetAnalDataInferenceGeomEntity)
|
||||
.on(mapSheetAnalDataInferenceGeomEntity.dataUid.eq(mapSheetAnalDataInferenceEntity.id))
|
||||
.join(mapInkx5kEntity)
|
||||
.on(
|
||||
mapSheetAnalDataInferenceGeomEntity.mapSheetNum.eq(
|
||||
Expressions.numberTemplate(
|
||||
Long.class, "CAST({0} AS long)", mapInkx5kEntity.mapidcdNo)))
|
||||
.where(builder)
|
||||
.fetchCount();
|
||||
.where(where)
|
||||
.fetchOne();
|
||||
|
||||
return new PageImpl<>(content, pageable, total);
|
||||
return new PageImpl<>(content, pageable, total == null ? 0L : total);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user