This commit is contained in:
2025-12-24 11:17:53 +09:00
parent 72b8a7c41c
commit b91c0dde09
6 changed files with 113 additions and 120 deletions

View File

@@ -27,7 +27,7 @@ public class ModelMngEntity extends CommonDateEntity {
@Column(name = "create_complete_dttm")
private ZonedDateTime createCompleteDttm;
@Column(name = "recent_use_dttm")
private ZonedDateTime recentUseDttm;

View File

@@ -9,12 +9,11 @@ import org.springframework.data.domain.Page;
public interface ModelMngRepositoryCustom {
Page<ModelMngDto.ModelList> findModelMgmtList(
ModelMngDto.searchReq searchReq,
LocalDate startDate,
LocalDate endDate,
String modelType,
String searchVal);
ModelMngDto.searchReq searchReq,
LocalDate startDate,
LocalDate endDate,
String modelType,
String searchVal);
Optional<ModelMngEntity> findByModelUid(String modelVer);
}

View File

@@ -29,7 +29,7 @@ import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;
public class ModelMngRepositoryImpl extends QuerydslRepositorySupport
implements ModelMngRepositoryCustom {
implements ModelMngRepositoryCustom {
private final JPAQueryFactory queryFactory;
private final StringExpression NULL_STRING = Expressions.stringTemplate("cast(null as text)");
@@ -41,19 +41,19 @@ public class ModelMngRepositoryImpl extends QuerydslRepositorySupport
@Override
public Page<ModelMngDto.ModelList> findModelMgmtList(
ModelMngDto.searchReq searchReq,
LocalDate startDate,
LocalDate endDate,
String modelType,
String searchVal) {
ModelMngDto.searchReq searchReq,
LocalDate startDate,
LocalDate endDate,
String modelType,
String searchVal) {
Pageable pageable = searchReq.toPageable();
Sort sort = pageable.getSort();
String property = "createCompleteDttm"; // 기본으로 생성완료일 기준
Map<String, Expression<?>> sortColumnMap =
Map.of(
"createCompleteDttm", modelMngEntity.createCompleteDttm,
"recentUseDttm", modelMngEntity.recentUseDttm);
Map.of(
"createCompleteDttm", modelMngEntity.createCompleteDttm,
"recentUseDttm", modelMngEntity.recentUseDttm);
if (sort.isSorted()) {
Sort.Order order = sort.iterator().next();
@@ -63,46 +63,46 @@ public class ModelMngRepositoryImpl extends QuerydslRepositorySupport
Expression<?> sortColumn = sortColumnMap.get(property);
List<ModelMngDto.ModelList> foundContent =
queryFactory
.select(
Projections.constructor(
ModelMngDto.ModelList.class,
Expressions.numberTemplate(
Integer.class, "row_number() over(order by {0} desc)", sortColumn),
modelMngEntity.modelVer,
modelMngEntity.fileName,
modelMngEntity.modelType,
Expressions.stringTemplate(
"to_char({0}, 'YYYY-MM-DD')", modelMngEntity.createCompleteDttm),
roundNumericToPercent(modelResultMetricEntity.f1Score),
roundNumericToPercent(modelResultMetricEntity.precision),
roundNumericToPercent(modelResultMetricEntity.recall),
roundNumericToPercent(modelResultMetricEntity.loss),
roundNumericToPercent(modelResultMetricEntity.iou),
modelMngEntity.memo,
modelMngEntity.deleted))
.from(modelMngEntity)
.innerJoin(modelResultMetricEntity)
.on(modelMngEntity.modelUid.eq(modelResultMetricEntity.modelUid))
.where(
eventEndedAtBetween(startDate, endDate, property),
searchModelVersion(modelType, searchVal),
modelMngEntity.deleted.isFalse().or(modelMngEntity.deleted.isNull()))
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.orderBy(
QuerydslOrderUtil.getOrderSpecifiers(
pageable, ModelMngEntity.class, "modelMngEntity"))
.fetch();
queryFactory
.select(
Projections.constructor(
ModelMngDto.ModelList.class,
Expressions.numberTemplate(
Integer.class, "row_number() over(order by {0} desc)", sortColumn),
modelMngEntity.modelVer,
modelMngEntity.fileName,
modelMngEntity.modelType,
Expressions.stringTemplate(
"to_char({0}, 'YYYY-MM-DD')", modelMngEntity.createCompleteDttm),
roundNumericToPercent(modelResultMetricEntity.f1Score),
roundNumericToPercent(modelResultMetricEntity.precision),
roundNumericToPercent(modelResultMetricEntity.recall),
roundNumericToPercent(modelResultMetricEntity.loss),
roundNumericToPercent(modelResultMetricEntity.iou),
modelMngEntity.memo,
modelMngEntity.deleted))
.from(modelMngEntity)
.innerJoin(modelResultMetricEntity)
.on(modelMngEntity.modelUid.eq(modelResultMetricEntity.modelUid))
.where(
eventEndedAtBetween(startDate, endDate, property),
searchModelVersion(modelType, searchVal),
modelMngEntity.deleted.isFalse().or(modelMngEntity.deleted.isNull()))
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.orderBy(
QuerydslOrderUtil.getOrderSpecifiers(
pageable, ModelMngEntity.class, "modelMngEntity"))
.fetch();
Long countQuery =
queryFactory
.select(modelMngEntity.modelUid.count())
.from(modelMngEntity)
.where(
eventEndedAtBetween(startDate, endDate, property),
searchModelVersion(modelType, searchVal))
.fetchOne();
queryFactory
.select(modelMngEntity.modelUid.count())
.from(modelMngEntity)
.where(
eventEndedAtBetween(startDate, endDate, property),
searchModelVersion(modelType, searchVal))
.fetchOne();
return new PageImpl<>(foundContent, pageable, countQuery);
}
@@ -110,14 +110,14 @@ public class ModelMngRepositoryImpl extends QuerydslRepositorySupport
@Override
public Optional<ModelMngEntity> findByModelUid(String modelVer) {
return Optional.ofNullable(
queryFactory
.selectFrom(modelMngEntity)
.where(modelMngEntity.modelVer.eq(modelVer))
.fetchOne());
queryFactory
.selectFrom(modelMngEntity)
.where(modelMngEntity.modelVer.eq(modelVer))
.fetchOne());
}
private BooleanExpression eventEndedAtBetween(
LocalDate startDate, LocalDate endDate, String sortColumn) {
LocalDate startDate, LocalDate endDate, String sortColumn) {
if (Objects.isNull(startDate) || Objects.isNull(endDate)) {
return null;
}
@@ -127,14 +127,14 @@ public class ModelMngRepositoryImpl extends QuerydslRepositorySupport
if (sortColumn.equals("createCompleteDttm")) {
return modelMngEntity
.createCompleteDttm
.goe(startDateTime.atZone(zone))
.and(modelMngEntity.createCompleteDttm.lt(endDateTime.atZone(zone)));
.createCompleteDttm
.goe(startDateTime.atZone(zone))
.and(modelMngEntity.createCompleteDttm.lt(endDateTime.atZone(zone)));
} else {
return modelMngEntity
.recentUseDttm
.goe(startDateTime.atZone(zone))
.and(modelMngEntity.recentUseDttm.lt(endDateTime.atZone(zone)));
.recentUseDttm
.goe(startDateTime.atZone(zone))
.and(modelMngEntity.recentUseDttm.lt(endDateTime.atZone(zone)));
}
}