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