추론 결과 조회 수정

This commit is contained in:
2026-01-22 12:13:19 +09:00
parent c70abbdb6d
commit e2eb653df7
6 changed files with 530 additions and 441 deletions

View File

@@ -25,9 +25,9 @@ public class MapSheetLearnEntity {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "tb_map_sheet_learn_id_gen")
@SequenceGenerator(
name = "tb_map_sheet_learn_id_gen",
sequenceName = "tb_map_sheet_learn_uid",
allocationSize = 1)
name = "tb_map_sheet_learn_id_gen",
sequenceName = "tb_map_sheet_learn_uid",
allocationSize = 1)
@Column(name = "id", nullable = false)
private Long id;
@@ -191,18 +191,18 @@ public class MapSheetLearnEntity {
public InferenceResultDto.ResultList toDto() {
return new InferenceResultDto.ResultList(
this.uuid,
this.title,
this.stage,
this.status,
this.mapSheetCnt,
this.detectingCnt,
this.inferStartDttm,
this.inferEndDttm,
this.applyYn,
this.applyDttm,
this.compareYyyy,
this.targetYyyy,
this.uid);
this.uuid,
this.title,
this.stage,
this.status,
this.mapSheetCnt,
this.detectingCnt,
this.inferStartDttm,
this.inferEndDttm,
this.applyYn,
this.applyDttm,
this.compareYyyy,
this.targetYyyy,
this.uid);
}
}

View File

@@ -0,0 +1,51 @@
package com.kamco.cd.kamcoback.postgres.entity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.time.OffsetDateTime;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.ColumnDefault;
@Getter
@Setter
@Entity
@Table(name = "tb_pnu")
public class PnuEntity {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "tb_pnu_id_gen")
@SequenceGenerator(name = "tb_pnu_id_gen", sequenceName = "tb_pnu_uid", allocationSize = 1)
@Column(name = "id", nullable = false)
private Long id;
@NotNull
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "geo_uid", nullable = false)
private MapSheetAnalDataInferenceGeomEntity geo;
@Size(max = 19)
@Column(name = "pnu", length = 19)
private String pnu;
@Column(name = "created_dttm")
private OffsetDateTime createdDttm;
@Column(name = "created_uid")
private Long createdUid;
@ColumnDefault("false")
@Column(name = "del_yn")
private Boolean delYn;
}

View File

@@ -1,8 +1,10 @@
package com.kamco.cd.kamcoback.postgres.repository.Inference;
import static com.kamco.cd.kamcoback.postgres.entity.QMapInkx50kEntity.mapInkx50kEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QMapInkx5kEntity.mapInkx5kEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QMapSheetLearn5kEntity.mapSheetLearn5kEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QMapSheetLearnEntity.mapSheetLearnEntity;
import static com.querydsl.jpa.JPAExpressions.select;
import com.kamco.cd.kamcoback.scheduler.dto.JobStatusDto;
import com.querydsl.core.BooleanBuilder;
@@ -10,7 +12,6 @@ import com.querydsl.core.types.dsl.BooleanPath;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.core.types.dsl.NumberPath;
import com.querydsl.core.types.dsl.StringPath;
import com.querydsl.jpa.JPAExpressions;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.util.List;
import java.util.UUID;
@@ -55,22 +56,22 @@ public class MapSheetLearn5kRepositoryImpl implements MapSheetLearn5kRepositoryC
}
var learnIdSubQuery =
JPAExpressions.select(mapSheetLearnEntity.id)
.from(mapSheetLearnEntity)
.where(mapSheetLearnEntity.uuid.eq(uuid));
select(mapSheetLearnEntity.id)
.from(mapSheetLearnEntity)
.where(mapSheetLearnEntity.uuid.eq(uuid));
queryFactory
.update(mapSheetLearn5kEntity)
.set(failPath, Boolean.TRUE)
.set(jobIdPath, jobDto.getId())
.set(errorMsgPath, jobDto.getErrorMessage())
.where(
mapSheetLearn5kEntity
.learn
.id
.eq(learnIdSubQuery)
.and(mapSheetLearn5kEntity.mapSheetNum.eq(Long.valueOf(jobDto.getSceneId()))))
.execute();
.update(mapSheetLearn5kEntity)
.set(failPath, Boolean.TRUE)
.set(jobIdPath, jobDto.getId())
.set(errorMsgPath, jobDto.getErrorMessage())
.where(
mapSheetLearn5kEntity
.learn
.id
.eq(learnIdSubQuery)
.and(mapSheetLearn5kEntity.mapSheetNum.eq(Long.valueOf(jobDto.getSceneId()))))
.execute();
}
@Override
@@ -102,21 +103,21 @@ public class MapSheetLearn5kRepositoryImpl implements MapSheetLearn5kRepositoryC
}
var learnIdSubQuery =
JPAExpressions.select(mapSheetLearnEntity.id)
.from(mapSheetLearnEntity)
.where(mapSheetLearnEntity.uuid.eq(uuid));
select(mapSheetLearnEntity.id)
.from(mapSheetLearnEntity)
.where(mapSheetLearnEntity.uuid.eq(uuid));
queryFactory
.update(mapSheetLearn5kEntity)
.set(failPath, Boolean.FALSE)
.set(jobIdPath, jobDto.getId())
.where(
mapSheetLearn5kEntity
.learn
.id
.eq(learnIdSubQuery)
.and(mapSheetLearn5kEntity.mapSheetNum.eq(Long.valueOf(jobDto.getSceneId()))))
.execute();
.update(mapSheetLearn5kEntity)
.set(failPath, Boolean.FALSE)
.set(jobIdPath, jobDto.getId())
.where(
mapSheetLearn5kEntity
.learn
.id
.eq(learnIdSubQuery)
.and(mapSheetLearn5kEntity.mapSheetNum.eq(Long.valueOf(jobDto.getSceneId()))))
.execute();
}
@Override
@@ -152,16 +153,16 @@ public class MapSheetLearn5kRepositoryImpl implements MapSheetLearn5kRepositoryC
}
return queryFactory
.select(jobIdPath)
.from(mapSheetLearn5kEntity)
.join(mapSheetLearn5kEntity.learn, mapSheetLearnEntity)
.where(
mapSheetLearnEntity
.uuid
.eq(uuid)
.and(failPath.isFalse().or(failPath.isNull()))
.and(jobIdPath.in(failIds)))
.fetch();
.select(jobIdPath)
.from(mapSheetLearn5kEntity)
.join(mapSheetLearn5kEntity.learn, mapSheetLearnEntity)
.where(
mapSheetLearnEntity
.uuid
.eq(uuid)
.and(failPath.isFalse().or(failPath.isNull()))
.and(jobIdPath.in(failIds)))
.fetch();
}
@Override
@@ -194,31 +195,37 @@ public class MapSheetLearn5kRepositoryImpl implements MapSheetLearn5kRepositoryC
}
return queryFactory
.select(jobIdPath)
.from(mapSheetLearn5kEntity)
.join(mapSheetLearn5kEntity.learn, mapSheetLearnEntity)
.where(mapSheetLearnEntity.uuid.eq(uuid).and(jobIdPath.in(completedIds)))
.fetch();
.select(jobIdPath)
.from(mapSheetLearn5kEntity)
.join(mapSheetLearn5kEntity.learn, mapSheetLearnEntity)
.where(mapSheetLearnEntity.uuid.eq(uuid).and(jobIdPath.in(completedIds)))
.fetch();
}
/**
* 추론 진행 도엽 목록
*
* @param uuid uuid
* @return
*/
@Override
public List<String> getInferenceRunMapId(UUID uuid) {
return queryFactory
.select(mapInkx5kEntity.mapidNm)
.from(mapSheetLearnEntity)
.innerJoin(mapSheetLearn5kEntity)
.on(mapSheetLearn5kEntity.learn.id.eq(mapSheetLearnEntity.id))
.innerJoin(mapInkx5kEntity)
.on(
Expressions.booleanTemplate(
"function('regexp_match', {0}, '^[0-9]+$') is not null",
mapInkx5kEntity.mapidcdNo)
.and(
mapSheetLearn5kEntity.mapSheetNum.eq(
Expressions.numberTemplate(
Long.class, "cast({0} as long)", mapInkx5kEntity.mapidcdNo))))
.where(mapSheetLearnEntity.uuid.eq(uuid))
.groupBy(mapInkx5kEntity.mapidNm)
.fetch();
.select(mapInkx50kEntity.mapidNm.concat(mapInkx50kEntity.mapidcdNo))
.from(mapInkx50kEntity)
.join(mapInkx5kEntity).on(mapInkx5kEntity.mapInkx50k.fid.eq(mapInkx50kEntity.fid))
.where(
mapInkx5kEntity.mapidcdNo.in(
select(
Expressions.stringTemplate("CAST({0} AS text)", mapSheetLearn5kEntity.mapSheetNum)
)
.from(mapSheetLearnEntity)
.join(mapSheetLearn5kEntity).on(mapSheetLearn5kEntity.learn.id.eq(mapSheetLearnEntity.id))
.where(mapSheetLearnEntity.uuid.eq(uuid))
)
)
.groupBy(mapInkx50kEntity.mapidcdNo, mapInkx50kEntity.mapidNm)
.orderBy(mapInkx50kEntity.mapidNm.asc())
.fetch();
}
}

View File

@@ -7,6 +7,7 @@ import static com.kamco.cd.kamcoback.postgres.entity.QMapSheetAnalDataInferenceG
import static com.kamco.cd.kamcoback.postgres.entity.QMapSheetAnalInferenceEntity.mapSheetAnalInferenceEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QMapSheetAnalSttcEntity.mapSheetAnalSttcEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QMapSheetLearnEntity.mapSheetLearnEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QPnuEntity.pnuEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QSystemMetricEntity.systemMetricEntity;
import com.kamco.cd.kamcoback.common.exception.CustomApiException;
@@ -28,6 +29,8 @@ 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;
import com.querydsl.core.types.dsl.StringExpression;
import com.querydsl.jpa.JPAExpressions;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.time.OffsetDateTime;
import java.util.List;
@@ -55,7 +58,7 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
BooleanBuilder builder = new BooleanBuilder();
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())) {
@@ -69,10 +72,10 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
// 국유인 반영일
if (req.getStrtDttm() != null && req.getEndDttm() != null) {
builder.and(
mapSheetLearnEntity
.applyDttm
.goe(DateRange.start(req.getStrtDttm()))
.and(mapSheetLearnEntity.applyDttm.lt(DateRange.end(req.getEndDttm()))));
mapSheetLearnEntity
.applyDttm
.goe(DateRange.start(req.getStrtDttm()))
.and(mapSheetLearnEntity.applyDttm.lt(DateRange.end(req.getEndDttm()))));
}
// 제목
@@ -81,21 +84,21 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
}
List<MapSheetLearnEntity> content =
queryFactory
.select(mapSheetLearnEntity)
.from(mapSheetLearnEntity)
.where(builder)
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.orderBy(mapSheetLearnEntity.id.desc())
.fetch();
queryFactory
.select(mapSheetLearnEntity)
.from(mapSheetLearnEntity)
.where(builder)
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.orderBy(mapSheetLearnEntity.id.desc())
.fetch();
Long total =
queryFactory
.select(mapSheetLearnEntity.count())
.from(mapSheetLearnEntity)
.where(builder)
.fetchOne();
queryFactory
.select(mapSheetLearnEntity.count())
.from(mapSheetLearnEntity)
.where(builder)
.fetchOne();
return new PageImpl<>(content, pageable, total == null ? 0L : total);
}
@@ -103,10 +106,10 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
@Override
public Optional<MapSheetLearnEntity> getInferenceResultByUuid(UUID uuid) {
return Optional.ofNullable(
queryFactory
.selectFrom(mapSheetLearnEntity)
.where(mapSheetLearnEntity.uuid.eq(uuid))
.fetchOne());
queryFactory
.selectFrom(mapSheetLearnEntity)
.where(mapSheetLearnEntity.uuid.eq(uuid))
.fetchOne());
}
@Override
@@ -115,44 +118,44 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
BooleanBuilder builder = new BooleanBuilder();
List<OffsetDateTime> latestIds =
queryFactory
.select(systemMetricEntity.timestamp.max())
.from(systemMetricEntity)
.groupBy(systemMetricEntity.serverName)
.fetch();
queryFactory
.select(systemMetricEntity.timestamp.max())
.from(systemMetricEntity)
.groupBy(systemMetricEntity.serverName)
.fetch();
List<OffsetDateTime> latestGpuIds =
queryFactory
.select(gpuMetricEntity.timestamp.max())
.from(gpuMetricEntity)
.groupBy(gpuMetricEntity.serverName)
.fetch();
queryFactory
.select(gpuMetricEntity.timestamp.max())
.from(gpuMetricEntity)
.groupBy(gpuMetricEntity.serverName)
.fetch();
List<InferenceServerStatusDto> foundContent =
queryFactory
.select(
Projections.constructor(
InferenceServerStatusDto.class,
systemMetricEntity.serverName,
systemMetricEntity.cpuUser,
systemMetricEntity.cpuSystem,
systemMetricEntity.memused,
systemMetricEntity.kbmemused,
gpuMetricEntity.gpuUtil
// gpuMetricEntity.gpuMemUsed,
// gpuMetricEntity.gpuMemTotal
))
.from(systemMetricEntity)
.leftJoin(gpuMetricEntity)
.on(
gpuMetricEntity
.timestamp
.in(latestGpuIds)
.and(gpuMetricEntity.serverName.eq(systemMetricEntity.serverName)))
.where(systemMetricEntity.timestamp.in(latestIds)) // In 절 사용
.orderBy(systemMetricEntity.serverName.asc())
.limit(4)
.fetch();
queryFactory
.select(
Projections.constructor(
InferenceServerStatusDto.class,
systemMetricEntity.serverName,
systemMetricEntity.cpuUser,
systemMetricEntity.cpuSystem,
systemMetricEntity.memused,
systemMetricEntity.kbmemused,
gpuMetricEntity.gpuUtil
// gpuMetricEntity.gpuMemUsed,
// gpuMetricEntity.gpuMemTotal
))
.from(systemMetricEntity)
.leftJoin(gpuMetricEntity)
.on(
gpuMetricEntity
.timestamp
.in(latestGpuIds)
.and(gpuMetricEntity.serverName.eq(systemMetricEntity.serverName)))
.where(systemMetricEntity.timestamp.in(latestIds)) // In 절 사용
.orderBy(systemMetricEntity.serverName.asc())
.limit(4)
.fetch();
return foundContent;
}
@@ -160,11 +163,11 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
@Override
public Optional<MapSheetLearnEntity> getInferenceResultByStatus(String status) {
return Optional.ofNullable(
queryFactory
.selectFrom(mapSheetLearnEntity)
.where(mapSheetLearnEntity.status.eq(status))
.limit(1)
.fetchOne());
queryFactory
.selectFrom(mapSheetLearnEntity)
.where(mapSheetLearnEntity.status.eq(status))
.limit(1)
.fetchOne());
}
/**
@@ -183,46 +186,46 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
QModelMngEntity m3Model = new QModelMngEntity("m3Model");
InferenceStatusDetailDto foundContent =
queryFactory
.select(
Projections.constructor(
InferenceStatusDetailDto.class,
mapSheetLearnEntity.detectingCnt,
mapSheetLearnEntity.m1PendingJobs,
mapSheetLearnEntity.m2PendingJobs,
mapSheetLearnEntity.m3PendingJobs,
mapSheetLearnEntity.m1CompletedJobs,
mapSheetLearnEntity.m2CompletedJobs,
mapSheetLearnEntity.m3CompletedJobs,
mapSheetLearnEntity.m1FailedJobs,
mapSheetLearnEntity.m2FailedJobs,
mapSheetLearnEntity.m3FailedJobs,
mapSheetLearnEntity.m1ModelStartDttm,
mapSheetLearnEntity.m2ModelStartDttm,
mapSheetLearnEntity.m3ModelStartDttm,
mapSheetLearnEntity.m1ModelEndDttm,
mapSheetLearnEntity.m2ModelEndDttm,
mapSheetLearnEntity.m3ModelEndDttm,
mapSheetLearnEntity.title,
mapSheetLearnEntity.compareYyyy,
mapSheetLearnEntity.targetYyyy,
mapSheetLearnEntity.stage,
mapSheetLearnEntity.inferStartDttm,
mapSheetLearnEntity.inferEndDttm,
mapSheetLearnEntity.detectOption,
mapSheetLearnEntity.mapSheetScope,
m1Model.modelVer.as("model1Ver"),
m2Model.modelVer.as("model2Ver"),
m3Model.modelVer.as("model3Ver")))
.from(mapSheetLearnEntity)
.leftJoin(m1Model)
.on(m1Model.uuid.eq(mapSheetLearnEntity.m1ModelUuid))
.leftJoin(m2Model)
.on(m2Model.uuid.eq(mapSheetLearnEntity.m2ModelUuid))
.leftJoin(m3Model)
.on(m3Model.uuid.eq(mapSheetLearnEntity.m3ModelUuid))
.where(mapSheetLearnEntity.uuid.eq(uuid))
.fetchOne();
queryFactory
.select(
Projections.constructor(
InferenceStatusDetailDto.class,
mapSheetLearnEntity.detectingCnt,
mapSheetLearnEntity.m1PendingJobs,
mapSheetLearnEntity.m2PendingJobs,
mapSheetLearnEntity.m3PendingJobs,
mapSheetLearnEntity.m1CompletedJobs,
mapSheetLearnEntity.m2CompletedJobs,
mapSheetLearnEntity.m3CompletedJobs,
mapSheetLearnEntity.m1FailedJobs,
mapSheetLearnEntity.m2FailedJobs,
mapSheetLearnEntity.m3FailedJobs,
mapSheetLearnEntity.m1ModelStartDttm,
mapSheetLearnEntity.m2ModelStartDttm,
mapSheetLearnEntity.m3ModelStartDttm,
mapSheetLearnEntity.m1ModelEndDttm,
mapSheetLearnEntity.m2ModelEndDttm,
mapSheetLearnEntity.m3ModelEndDttm,
mapSheetLearnEntity.title,
mapSheetLearnEntity.compareYyyy,
mapSheetLearnEntity.targetYyyy,
mapSheetLearnEntity.stage,
mapSheetLearnEntity.inferStartDttm,
mapSheetLearnEntity.inferEndDttm,
mapSheetLearnEntity.detectOption,
mapSheetLearnEntity.mapSheetScope,
m1Model.modelVer.as("model1Ver"),
m2Model.modelVer.as("model2Ver"),
m3Model.modelVer.as("model3Ver")))
.from(mapSheetLearnEntity)
.leftJoin(m1Model)
.on(m1Model.uuid.eq(mapSheetLearnEntity.m1ModelUuid))
.leftJoin(m2Model)
.on(m2Model.uuid.eq(mapSheetLearnEntity.m2ModelUuid))
.leftJoin(m3Model)
.on(m3Model.uuid.eq(mapSheetLearnEntity.m3ModelUuid))
.where(mapSheetLearnEntity.uuid.eq(uuid))
.fetchOne();
return foundContent;
}
@@ -233,30 +236,30 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
QModelMngEntity model = new QModelMngEntity("model");
InferenceProgressDto dto =
queryFactory
.select(
Projections.constructor(
InferenceProgressDto.class,
Projections.constructor(
InferenceProgressDto.pred_requests_areas.class,
mapSheetLearnEntity.compareYyyy,
mapSheetLearnEntity.targetYyyy,
mapSheetLearnEntity.modelComparePath,
mapSheetLearnEntity.modelTargetPath),
model.modelVer.as("modelVer"),
model.cdModelPath.as("cdModelPath"),
model.cdModelFileName.as("cdModelFileName"),
model.cdModelConfigPath.as("cdModelConfigPath"),
model.cdModelConfigFileName.as("cdModelConfigFileName"),
model.clsModelPath,
model.clsModelFileName,
model.clsModelVersion,
model.priority))
.from(mapSheetLearnEntity)
.join(model)
.on(model.uuid.eq(modelUuid))
.where(mapSheetLearnEntity.id.eq(id))
.fetchOne();
queryFactory
.select(
Projections.constructor(
InferenceProgressDto.class,
Projections.constructor(
InferenceProgressDto.pred_requests_areas.class,
mapSheetLearnEntity.compareYyyy,
mapSheetLearnEntity.targetYyyy,
mapSheetLearnEntity.modelComparePath,
mapSheetLearnEntity.modelTargetPath),
model.modelVer.as("modelVer"),
model.cdModelPath.as("cdModelPath"),
model.cdModelFileName.as("cdModelFileName"),
model.cdModelConfigPath.as("cdModelConfigPath"),
model.cdModelConfigFileName.as("cdModelConfigFileName"),
model.clsModelPath,
model.clsModelFileName,
model.clsModelVersion,
model.priority))
.from(mapSheetLearnEntity)
.join(model)
.on(model.uuid.eq(modelUuid))
.where(mapSheetLearnEntity.id.eq(id))
.fetchOne();
return dto;
}
@@ -267,26 +270,26 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
*/
public MapSheetLearnEntity getProcessing() {
return queryFactory
.select(mapSheetLearnEntity)
.from(mapSheetLearnEntity)
.where(mapSheetLearnEntity.status.eq("IN_PROGRESS"))
.fetchOne();
.select(mapSheetLearnEntity)
.from(mapSheetLearnEntity)
.where(mapSheetLearnEntity.status.eq("IN_PROGRESS"))
.fetchOne();
}
@Override
public Integer getLearnStage(Integer compareYear, Integer targetYear) {
Integer stage =
queryFactory
.select(mapSheetLearnEntity.stage)
.from(mapSheetLearnEntity)
.where(
mapSheetLearnEntity
.compareYyyy
.eq(compareYear)
.and(mapSheetLearnEntity.targetYyyy.eq(targetYear)))
.orderBy(mapSheetLearnEntity.id.desc())
.limit(1)
.fetchOne();
queryFactory
.select(mapSheetLearnEntity.stage)
.from(mapSheetLearnEntity)
.where(
mapSheetLearnEntity
.compareYyyy
.eq(compareYear)
.and(mapSheetLearnEntity.targetYyyy.eq(targetYear)))
.orderBy(mapSheetLearnEntity.id.desc())
.limit(1)
.fetchOne();
return stage == null ? 1 : stage + 1;
}
@@ -298,30 +301,30 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
QModelMngEntity m3 = new QModelMngEntity("m3");
return queryFactory
.select(
Projections.constructor(
AnalResultInfo.class,
mapSheetLearnEntity.title,
m1.modelVer,
m2.modelVer,
m3.modelVer,
mapSheetLearnEntity.compareYyyy,
mapSheetLearnEntity.targetYyyy,
mapSheetLearnEntity.detectOption,
mapSheetLearnEntity.mapSheetScope,
mapSheetLearnEntity.inferStartDttm,
mapSheetLearnEntity.inferEndDttm,
mapSheetLearnEntity.stage,
Expressions.stringTemplate("substring({0} from 1 for 8)", mapSheetLearnEntity.uid)))
.from(mapSheetLearnEntity)
.leftJoin(m1)
.on(mapSheetLearnEntity.m1ModelUuid.eq(m1.uuid))
.leftJoin(m2)
.on(mapSheetLearnEntity.m2ModelUuid.eq(m2.uuid))
.leftJoin(m3)
.on(mapSheetLearnEntity.m3ModelUuid.eq(m3.uuid))
.where(mapSheetLearnEntity.uuid.eq(uuid))
.fetchOne();
.select(
Projections.constructor(
AnalResultInfo.class,
mapSheetLearnEntity.title,
m1.modelVer,
m2.modelVer,
m3.modelVer,
mapSheetLearnEntity.compareYyyy,
mapSheetLearnEntity.targetYyyy,
mapSheetLearnEntity.detectOption,
mapSheetLearnEntity.mapSheetScope,
mapSheetLearnEntity.inferStartDttm,
mapSheetLearnEntity.inferEndDttm,
mapSheetLearnEntity.stage,
Expressions.stringTemplate("substring({0} from 1 for 8)", mapSheetLearnEntity.uid)))
.from(mapSheetLearnEntity)
.leftJoin(m1)
.on(mapSheetLearnEntity.m1ModelUuid.eq(m1.uuid))
.leftJoin(m2)
.on(mapSheetLearnEntity.m2ModelUuid.eq(m2.uuid))
.leftJoin(m3)
.on(mapSheetLearnEntity.m3ModelUuid.eq(m3.uuid))
.where(mapSheetLearnEntity.uuid.eq(uuid))
.fetchOne();
}
@Override
@@ -329,28 +332,28 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
// analUid로 분석 정보 조회
MapSheetLearnEntity learnEntity =
queryFactory
.selectFrom(mapSheetLearnEntity)
.where(mapSheetLearnEntity.uuid.eq(uuid))
.fetchOne();
queryFactory
.selectFrom(mapSheetLearnEntity)
.where(mapSheetLearnEntity.uuid.eq(uuid))
.fetchOne();
if (Objects.isNull(learnEntity)) {
throw new CustomApiException("NOT_FOUND_DATA", HttpStatus.NOT_FOUND);
}
return queryFactory
.select(
Projections.constructor(
Dashboard.class,
mapSheetAnalSttcEntity.id.classAfterCd.toUpperCase(),
mapSheetAnalSttcEntity.classAfterCnt.sum()))
.from(mapSheetAnalInferenceEntity)
.innerJoin(mapSheetAnalSttcEntity)
.on(mapSheetAnalInferenceEntity.id.eq(mapSheetAnalSttcEntity.id.analUid))
.where(mapSheetAnalInferenceEntity.learnId.eq(learnEntity.getId()))
.groupBy(mapSheetAnalSttcEntity.id.classAfterCd)
.orderBy(mapSheetAnalSttcEntity.id.classAfterCd.asc())
.fetch();
.select(
Projections.constructor(
Dashboard.class,
mapSheetAnalSttcEntity.id.classAfterCd.toUpperCase(),
mapSheetAnalSttcEntity.classAfterCnt.sum()))
.from(mapSheetAnalInferenceEntity)
.innerJoin(mapSheetAnalSttcEntity)
.on(mapSheetAnalInferenceEntity.id.eq(mapSheetAnalSttcEntity.id.analUid))
.where(mapSheetAnalInferenceEntity.learnId.eq(learnEntity.getId()))
.groupBy(mapSheetAnalSttcEntity.id.classAfterCd)
.orderBy(mapSheetAnalSttcEntity.id.classAfterCd.asc())
.fetch();
}
/**
@@ -366,10 +369,10 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
// 1) 분석 엔티티 조회
MapSheetLearnEntity analEntity =
queryFactory
.selectFrom(mapSheetLearnEntity)
.where(mapSheetLearnEntity.uuid.eq(uuid))
.fetchOne();
queryFactory
.selectFrom(mapSheetLearnEntity)
.where(mapSheetLearnEntity.uuid.eq(uuid))
.fetchOne();
if (analEntity == null) {
throw new CustomApiException("NOT_FOUND_DATA", HttpStatus.NOT_FOUND);
@@ -380,22 +383,22 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
if (searchGeoReq.getTargetClass() != null && !searchGeoReq.getTargetClass().isBlank()) {
where.and(
mapSheetAnalDataInferenceGeomEntity.classAfterCd.eq(
searchGeoReq.getTargetClass().toLowerCase()));
mapSheetAnalDataInferenceGeomEntity.classAfterCd.eq(
searchGeoReq.getTargetClass().toLowerCase()));
}
if (searchGeoReq.getCompareClass() != null && !searchGeoReq.getCompareClass().isBlank()) {
where.and(
mapSheetAnalDataInferenceGeomEntity.classBeforeCd.eq(
searchGeoReq.getCompareClass().toLowerCase()));
mapSheetAnalDataInferenceGeomEntity.classBeforeCd.eq(
searchGeoReq.getCompareClass().toLowerCase()));
}
if (searchGeoReq.getMapSheetNum() != null) {
//
// where.and(mapSheetAnalDataInferenceGeomEntity.mapSheetNum.eq(searchGeoReq.getMapSheetNum()));
where.and(
mapSheetAnalDataInferenceGeomEntity.mapSheetNum.like(
"%" + searchGeoReq.getMapSheetNum() + "%"));
mapSheetAnalDataInferenceGeomEntity.mapSheetNum.like(
"%" + searchGeoReq.getMapSheetNum() + "%"));
}
where.and(mapSheetAnalDataInferenceGeomEntity.classAfterCd.isNotNull());
@@ -405,56 +408,66 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
// 3) inkx 조인 조건: JPQL/HQL에서 '~' 불가 → function('regexp_match', ...) 사용
BooleanExpression inkxIsNumeric =
Expressions.booleanTemplate(
"function('regexp_match', {0}, '^[0-9]+$') is not null", mapInkx5kEntity.mapidcdNo);
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);
Expressions.numberTemplate(Long.class, "cast({0} as long)", mapInkx5kEntity.mapidcdNo);
StringExpression pnu =
Expressions.stringTemplate(
"coalesce(({0}), '')",
JPAExpressions
.select(Expressions.stringTemplate("string_agg({0}, ',')", pnuEntity.pnu))
.from(pnuEntity)
.where(pnuEntity.geo.geoUid.eq(mapSheetAnalDataInferenceGeomEntity.geoUid))
);
// 4) content
List<Geom> content =
queryFactory
.select(
Projections.constructor(
Geom.class,
mapSheetAnalDataInferenceGeomEntity.uuid,
mapSheetAnalDataInferenceGeomEntity.resultUid,
mapSheetAnalDataInferenceGeomEntity.compareYyyy,
mapSheetAnalDataInferenceGeomEntity.targetYyyy,
mapSheetAnalDataInferenceGeomEntity.cdProb,
mapSheetAnalDataInferenceGeomEntity.classBeforeCd,
mapSheetAnalDataInferenceGeomEntity.classBeforeProb,
mapSheetAnalDataInferenceGeomEntity.classAfterCd,
mapSheetAnalDataInferenceGeomEntity.classAfterProb,
mapSheetAnalDataInferenceGeomEntity.mapSheetNum,
mapInkx5kEntity.mapidNm,
Expressions.stringTemplate(
"substring({0} from 1 for 8)",
mapSheetAnalDataInferenceGeomEntity.resultUid)))
.from(mapSheetAnalInferenceEntity)
.join(mapSheetAnalDataInferenceEntity)
.on(mapSheetAnalDataInferenceEntity.analUid.eq(mapSheetAnalInferenceEntity.id))
.join(mapSheetAnalDataInferenceGeomEntity)
.on(mapSheetAnalDataInferenceGeomEntity.dataUid.eq(mapSheetAnalDataInferenceEntity.id))
.join(mapInkx5kEntity)
.on(inkxIsNumeric.and(mapSheetAnalDataInferenceGeomEntity.mapSheetNum.eq(inkxNoAsLong)))
.where(where)
.orderBy(mapSheetAnalDataInferenceGeomEntity.geoUid.desc())
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();
queryFactory
.select(
Projections.constructor(
Geom.class,
mapSheetAnalDataInferenceGeomEntity.uuid,
mapSheetAnalDataInferenceGeomEntity.resultUid,
mapSheetAnalDataInferenceGeomEntity.compareYyyy,
mapSheetAnalDataInferenceGeomEntity.targetYyyy,
mapSheetAnalDataInferenceGeomEntity.cdProb,
mapSheetAnalDataInferenceGeomEntity.classBeforeCd,
mapSheetAnalDataInferenceGeomEntity.classBeforeProb,
mapSheetAnalDataInferenceGeomEntity.classAfterCd,
mapSheetAnalDataInferenceGeomEntity.classAfterProb,
mapSheetAnalDataInferenceGeomEntity.mapSheetNum,
mapInkx5kEntity.mapidNm,
Expressions.stringTemplate(
"substring({0} from 1 for 8)",
mapSheetAnalDataInferenceGeomEntity.resultUid
), pnu))
.from(mapSheetAnalInferenceEntity)
.join(mapSheetAnalDataInferenceEntity)
.on(mapSheetAnalDataInferenceEntity.analUid.eq(mapSheetAnalInferenceEntity.id))
.join(mapSheetAnalDataInferenceGeomEntity)
.on(mapSheetAnalDataInferenceGeomEntity.dataUid.eq(mapSheetAnalDataInferenceEntity.id))
.join(mapInkx5kEntity)
.on(inkxIsNumeric.and(mapSheetAnalDataInferenceGeomEntity.mapSheetNum.eq(inkxNoAsLong)))
.where(where)
.orderBy(mapSheetAnalDataInferenceGeomEntity.geoUid.desc())
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();
// 5) total (조인 최소화 유지)
Long total =
queryFactory
.select(mapSheetAnalDataInferenceGeomEntity.geoUid.count())
.from(mapSheetAnalInferenceEntity)
.join(mapSheetAnalDataInferenceEntity)
.on(mapSheetAnalDataInferenceEntity.analUid.eq(mapSheetAnalInferenceEntity.id))
.join(mapSheetAnalDataInferenceGeomEntity)
.on(mapSheetAnalDataInferenceGeomEntity.dataUid.eq(mapSheetAnalDataInferenceEntity.id))
.where(where)
.fetchOne();
queryFactory
.select(mapSheetAnalDataInferenceGeomEntity.geoUid.count())
.from(mapSheetAnalInferenceEntity)
.join(mapSheetAnalDataInferenceEntity)
.on(mapSheetAnalDataInferenceEntity.analUid.eq(mapSheetAnalInferenceEntity.id))
.join(mapSheetAnalDataInferenceGeomEntity)
.on(mapSheetAnalDataInferenceGeomEntity.dataUid.eq(mapSheetAnalDataInferenceEntity.id))
.where(where)
.fetchOne();
return new PageImpl<>(content, pageable, total == null ? 0L : total);
}