sttc 엔티티 수정

This commit is contained in:
2025-11-28 12:01:43 +09:00
parent 7ee3afb8f0
commit c13cd3661b
6 changed files with 192 additions and 188 deletions

View File

@@ -2,7 +2,6 @@ package com.kamco.cd.kamcoback.postgres.core;
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto;
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.Dashboard;
import com.kamco.cd.kamcoback.postgres.entity.MapSheetAnalSttcEntity;
import com.kamco.cd.kamcoback.postgres.repository.Inference.InferenceResultRepository;
import jakarta.persistence.EntityNotFoundException;
import java.util.List;
@@ -23,7 +22,7 @@ public class InferenceResultCoreService {
* @return
*/
public Page<InferenceResultDto.AnalResList> getInferenceResultList(
InferenceResultDto.SearchReq searchReq) {
InferenceResultDto.SearchReq searchReq) {
return inferenceResultRepository.getInferenceResultList(searchReq);
}
@@ -35,9 +34,9 @@ public class InferenceResultCoreService {
*/
public InferenceResultDto.AnalResSummary getInferenceResultSummary(Long id) {
InferenceResultDto.AnalResSummary summary =
inferenceResultRepository
.getInferenceResultSummary(id)
.orElseThrow(() -> new EntityNotFoundException("요약정보를 찾을 수 없습니다. " + id));
inferenceResultRepository
.getInferenceResultSummary(id)
.orElseThrow(() -> new EntityNotFoundException("요약정보를 찾을 수 없습니다. " + id));
return summary;
}
@@ -48,9 +47,10 @@ public class InferenceResultCoreService {
* @return
*/
public List<Dashboard> getInferenceResultDashboard(Long id) {
return inferenceResultRepository.getInferenceResultDashboard(id).stream()
.map(MapSheetAnalSttcEntity::toDto)
.toList();
return null;
// inferenceResultRepository.getInferenceResultDashboard(id).stream()
// .map(MapSheetAnalSttcEntity::toDto)
// .toList();
}
/**
@@ -60,7 +60,12 @@ public class InferenceResultCoreService {
* @return
*/
public Page<InferenceResultDto.Geom> getInferenceResultGeomList(
InferenceResultDto.SearchGeoReq searchGeoReq) {
InferenceResultDto.SearchGeoReq searchGeoReq) {
return inferenceResultRepository.getInferenceGeomList(searchGeoReq);
}
//
// public List<Long> getSheets(
// return inferenceResultRepository.get
//
// }
}

View File

@@ -1,12 +1,12 @@
package com.kamco.cd.kamcoback.postgres.entity;
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto;
import jakarta.persistence.Column;
import jakarta.persistence.EmbeddedId;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotNull;
import java.time.ZonedDateTime;
import jakarta.validation.constraints.Size;
import java.time.OffsetDateTime;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.ColumnDefault;
@@ -17,26 +17,29 @@ import org.hibernate.annotations.ColumnDefault;
@Table(name = "tb_map_sheet_anal_sttc")
public class MapSheetAnalSttcEntity {
@EmbeddedId private MapSheetAnalSttcEntityId id;
@EmbeddedId
private MapSheetAnalSttcEntityId id;
@ColumnDefault("0")
@Column(name = "class_before_cnt")
private Long classBeforeCnt;
@ColumnDefault("0")
@Column(name = "class_after_cnt")
private Long classAfterCnt;
@ColumnDefault("now()")
@Column(name = "created_dttm")
private ZonedDateTime createdDttm;
private OffsetDateTime createdDttm;
@Column(name = "created_uid")
private Long createdUid;
@ColumnDefault("now()")
@Column(name = "updated_dttm")
private ZonedDateTime updatedDttm;
private OffsetDateTime updatedDttm;
@Column(name = "updated_uid", length = Integer.MAX_VALUE)
@Column(name = "updated_uid")
private Long updatedUid;
@NotNull
@@ -47,26 +50,12 @@ public class MapSheetAnalSttcEntity {
@Column(name = "data_uid", nullable = false)
private Long dataUid;
@Column(name = "class_before_cd")
@Size(max = 30)
@Column(name = "class_before_cd", length = 30)
private String classBeforeCd;
@Column(name = "class_after_cd")
@Size(max = 30)
@Column(name = "class_after_cd", length = 30)
private String classAfterCd;
public InferenceResultDto.Dashboard toDto() {
return new InferenceResultDto.Dashboard(
id.getCompareYyyy(),
id.getTargetYyyy(),
id.getMapSheetNum(),
id.getClassBeforeName(),
id.getClassAfterName(),
this.classBeforeCnt,
this.classAfterCnt,
this.createdDttm,
this.createdUid,
this.updatedDttm,
this.updatedUid,
this.refMapSheetNum,
this.dataUid);
}
}

View File

@@ -3,7 +3,6 @@ package com.kamco.cd.kamcoback.postgres.entity;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.io.Serializable;
import java.util.Objects;
import lombok.Getter;
@@ -15,8 +14,7 @@ import org.hibernate.Hibernate;
@Embeddable
public class MapSheetAnalSttcEntityId implements Serializable {
private static final long serialVersionUID = -8630519290255405042L;
private static final long serialVersionUID = 2285491656408229553L;
@NotNull
@Column(name = "compare_yyyy", nullable = false)
private Integer compareYyyy;
@@ -29,16 +27,6 @@ public class MapSheetAnalSttcEntityId implements Serializable {
@Column(name = "map_sheet_num", nullable = false)
private Long mapSheetNum;
@Size(max = 64)
@NotNull
@Column(name = "class_before_name", nullable = false, length = 64)
private String classBeforeName;
@Size(max = 64)
@NotNull
@Column(name = "class_after_name", nullable = false, length = 64)
private String classAfterName;
@Override
public boolean equals(Object o) {
if (this == o) {
@@ -48,15 +36,14 @@ public class MapSheetAnalSttcEntityId implements Serializable {
return false;
}
MapSheetAnalSttcEntityId entity = (MapSheetAnalSttcEntityId) o;
return Objects.equals(this.targetYyyy, entity.targetYyyy)
&& Objects.equals(this.classBeforeName, entity.classBeforeName)
&& Objects.equals(this.classAfterName, entity.classAfterName)
&& Objects.equals(this.compareYyyy, entity.compareYyyy)
&& Objects.equals(this.mapSheetNum, entity.mapSheetNum);
return Objects.equals(this.targetYyyy, entity.targetYyyy) &&
Objects.equals(this.compareYyyy, entity.compareYyyy) &&
Objects.equals(this.mapSheetNum, entity.mapSheetNum);
}
@Override
public int hashCode() {
return Objects.hash(targetYyyy, classBeforeName, classAfterName, compareYyyy, mapSheetNum);
return Objects.hash(targetYyyy, compareYyyy, mapSheetNum);
}
}

View File

@@ -7,12 +7,15 @@ import java.util.Optional;
import org.springframework.data.domain.Page;
public interface InferenceResultRepositoryCustom {
Page<InferenceResultDto.AnalResList> getInferenceResultList(
InferenceResultDto.SearchReq searchReq);
InferenceResultDto.SearchReq searchReq);
Optional<InferenceResultDto.AnalResSummary> getInferenceResultSummary(Long id);
List<MapSheetAnalSttcEntity> getInferenceResultDashboard(Long id);
Page<InferenceResultDto.Geom> getInferenceGeomList(InferenceResultDto.SearchGeoReq searchGeoReq);
List<Long> getSheets(Long id);
}

View File

@@ -3,6 +3,7 @@ package com.kamco.cd.kamcoback.postgres.repository.Inference;
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto;
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.SearchGeoReq;
import com.kamco.cd.kamcoback.postgres.entity.MapSheetAnalSttcEntity;
import com.kamco.cd.kamcoback.postgres.entity.QMapSheetAnalDataEntity;
import com.kamco.cd.kamcoback.postgres.entity.QMapSheetAnalDataGeomEntity;
import com.kamco.cd.kamcoback.postgres.entity.QMapSheetAnalEntity;
import com.kamco.cd.kamcoback.postgres.entity.QMapSheetAnalSttcEntity;
@@ -27,13 +28,14 @@ import org.springframework.stereotype.Repository;
public class InferenceResultRepositoryImpl implements InferenceResultRepositoryCustom {
private final JPAQueryFactory queryFactory;
private final QMapSheetAnalEntity mapSheetAnal = QMapSheetAnalEntity.mapSheetAnalEntity;
private final QModelMngEntity tmm = QModelMngEntity.modelMngEntity;
private final QModelVerEntity tmv = QModelVerEntity.modelVerEntity;
private final QMapSheetAnalEntity mapSheetAnal = QMapSheetAnalEntity.mapSheetAnalEntity;
private final QMapSheetAnalDataEntity mapSheetAnalEntity = QMapSheetAnalDataEntity.mapSheetAnalDataEntity;
private final QMapSheetAnalSttcEntity mapSheetAnalSttc =
QMapSheetAnalSttcEntity.mapSheetAnalSttcEntity;
QMapSheetAnalSttcEntity.mapSheetAnalSttcEntity;
private final QMapSheetAnalDataGeomEntity mapSheetAnalDataGeom =
QMapSheetAnalDataGeomEntity.mapSheetAnalDataGeomEntity;
QMapSheetAnalDataGeomEntity.mapSheetAnalDataGeomEntity;
/**
* 분석결과 목록 조회
@@ -43,7 +45,7 @@ public class InferenceResultRepositoryImpl implements InferenceResultRepositoryC
*/
@Override
public Page<InferenceResultDto.AnalResList> getInferenceResultList(
InferenceResultDto.SearchReq searchReq) {
InferenceResultDto.SearchReq searchReq) {
Pageable pageable = searchReq.toPageable();
// "0000" 전체조회
BooleanBuilder builder = new BooleanBuilder();
@@ -57,31 +59,31 @@ public class InferenceResultRepositoryImpl implements InferenceResultRepositoryC
}
List<InferenceResultDto.AnalResList> content =
queryFactory
.select(
Projections.constructor(
InferenceResultDto.AnalResList.class,
mapSheetAnal.id,
mapSheetAnal.analTitle,
mapSheetAnal.analMapSheet,
mapSheetAnal.detectingCnt,
mapSheetAnal.analStrtDttm,
mapSheetAnal.analEndDttm,
mapSheetAnal.analSec,
mapSheetAnal.analPredSec,
mapSheetAnal.analState,
Expressions.stringTemplate(
"fn_code_name({0}, {1})", "0002", mapSheetAnal.analState),
mapSheetAnal.gukyuinUsed))
.from(mapSheetAnal)
.where(builder)
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.orderBy(mapSheetAnal.createdDttm.desc())
.fetch();
queryFactory
.select(
Projections.constructor(
InferenceResultDto.AnalResList.class,
mapSheetAnal.id,
mapSheetAnal.analTitle,
mapSheetAnal.analMapSheet,
mapSheetAnal.detectingCnt,
mapSheetAnal.analStrtDttm,
mapSheetAnal.analEndDttm,
mapSheetAnal.analSec,
mapSheetAnal.analPredSec,
mapSheetAnal.analState,
Expressions.stringTemplate(
"fn_code_name({0}, {1})", "0002", mapSheetAnal.analState),
mapSheetAnal.gukyuinUsed))
.from(mapSheetAnal)
.where(builder)
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.orderBy(mapSheetAnal.createdDttm.desc())
.fetch();
long total =
queryFactory.select(mapSheetAnal.id).from(mapSheetAnal).where(builder).fetchCount();
queryFactory.select(mapSheetAnal.id).from(mapSheetAnal).where(builder).fetchCount();
return new PageImpl<>(content, pageable, total);
}
@@ -97,37 +99,37 @@ public class InferenceResultRepositoryImpl implements InferenceResultRepositoryC
// 1. 최신 버전 UID를 가져오는 서브쿼리
JPQLQuery<Long> latestVerUidSub =
JPAExpressions.select(tmv.id.max()).from(tmv).where(tmv.modelUid.eq(tmm.id));
JPAExpressions.select(tmv.id.max()).from(tmv).where(tmv.modelUid.eq(tmm.id));
Optional<InferenceResultDto.AnalResSummary> content =
Optional.ofNullable(
queryFactory
.select(
Projections.constructor(
InferenceResultDto.AnalResSummary.class,
mapSheetAnal.id,
mapSheetAnal.analTitle,
tmm.modelNm.concat(" ").concat(tmv.modelVer).as("modelInfo"),
mapSheetAnal.targetYyyy,
mapSheetAnal.compareYyyy,
mapSheetAnal.analMapSheet,
mapSheetAnal.analStrtDttm,
mapSheetAnal.analEndDttm,
mapSheetAnal.analSec,
mapSheetAnal.analPredSec,
mapSheetAnal.resultUrl,
mapSheetAnal.detectingCnt,
mapSheetAnal.accuracy,
mapSheetAnal.analState,
Expressions.stringTemplate(
"fn_code_name({0}, {1})", "0002", mapSheetAnal.analState)))
.from(mapSheetAnal)
.leftJoin(tmm)
.on(mapSheetAnal.modelUid.eq(tmm.id))
.leftJoin(tmv)
.on(tmv.modelUid.eq(tmm.id).and(tmv.id.eq(latestVerUidSub)))
.where(mapSheetAnal.id.eq(id))
.fetchOne());
Optional.ofNullable(
queryFactory
.select(
Projections.constructor(
InferenceResultDto.AnalResSummary.class,
mapSheetAnal.id,
mapSheetAnal.analTitle,
tmm.modelNm.concat(" ").concat(tmv.modelVer).as("modelInfo"),
mapSheetAnal.targetYyyy,
mapSheetAnal.compareYyyy,
mapSheetAnal.analMapSheet,
mapSheetAnal.analStrtDttm,
mapSheetAnal.analEndDttm,
mapSheetAnal.analSec,
mapSheetAnal.analPredSec,
mapSheetAnal.resultUrl,
mapSheetAnal.detectingCnt,
mapSheetAnal.accuracy,
mapSheetAnal.analState,
Expressions.stringTemplate(
"fn_code_name({0}, {1})", "0002", mapSheetAnal.analState)))
.from(mapSheetAnal)
.leftJoin(tmm)
.on(mapSheetAnal.modelUid.eq(tmm.id))
.leftJoin(tmv)
.on(tmv.modelUid.eq(tmm.id).and(tmv.id.eq(latestVerUidSub)))
.where(mapSheetAnal.id.eq(id))
.fetchOne());
return content;
}
@@ -140,10 +142,10 @@ public class InferenceResultRepositoryImpl implements InferenceResultRepositoryC
@Override
public List<MapSheetAnalSttcEntity> getInferenceResultDashboard(Long id) {
return queryFactory
.select(mapSheetAnalSttc)
.from(mapSheetAnalSttc)
.where(mapSheetAnalSttc.dataUid.eq(id))
.fetch();
.select(mapSheetAnalSttc)
.from(mapSheetAnalSttc)
.where(mapSheetAnalSttc.dataUid.eq(id))
.fetch();
}
/**
@@ -174,32 +176,50 @@ public class InferenceResultRepositoryImpl implements InferenceResultRepositoryC
}
List<InferenceResultDto.Geom> content =
queryFactory
.select(
Projections.constructor(
InferenceResultDto.Geom.class,
mapSheetAnalDataGeom.compareYyyy,
mapSheetAnalDataGeom.targetYyyy,
mapSheetAnalDataGeom.classBeforeCd,
Expressions.stringTemplate(
"fn_code_name({0}, {1})", "0000", mapSheetAnalDataGeom.classBeforeCd),
mapSheetAnalDataGeom.classBeforeProb,
mapSheetAnalDataGeom.classAfterCd,
Expressions.stringTemplate(
"fn_code_name({0}, {1})", "0000", mapSheetAnalDataGeom.classAfterCd),
mapSheetAnalDataGeom.classAfterProb,
mapSheetAnalDataGeom.mapSheetNum))
.from(mapSheetAnalDataGeom)
.where(builder)
.fetch();
queryFactory
.select(
Projections.constructor(
InferenceResultDto.Geom.class,
mapSheetAnalDataGeom.compareYyyy,
mapSheetAnalDataGeom.targetYyyy,
mapSheetAnalDataGeom.classBeforeCd,
Expressions.stringTemplate(
"fn_code_name({0}, {1})", "0000", mapSheetAnalDataGeom.classBeforeCd),
mapSheetAnalDataGeom.classBeforeProb,
mapSheetAnalDataGeom.classAfterCd,
Expressions.stringTemplate(
"fn_code_name({0}, {1})", "0000", mapSheetAnalDataGeom.classAfterCd),
mapSheetAnalDataGeom.classAfterProb,
mapSheetAnalDataGeom.mapSheetNum))
.from(mapSheetAnalDataGeom)
.where(builder)
.fetch();
long total =
queryFactory
.select(mapSheetAnalDataGeom.id)
.from(mapSheetAnalDataGeom)
.where(builder)
.fetchCount();
queryFactory
.select(mapSheetAnalDataGeom.id)
.from(mapSheetAnalDataGeom)
.where(builder)
.fetchCount();
return new PageImpl<>(content, pageable, total);
}
/**
* 추론된 5000:1 도엽 목록
*
* @param id
* @return
*/
@Override
public List<Long> getSheets(Long id) {
return queryFactory
.select(mapSheetAnalDataGeom.mapSheetNum)
.from(mapSheetAnal)
.join(mapSheetAnalEntity).on(mapSheetAnalEntity.analUid.eq(mapSheetAnal.id))
.join(mapSheetAnalDataGeom).on(mapSheetAnalDataGeom.dataUid.eq(mapSheetAnalEntity.id))
.where(mapSheetAnal.id.eq(id))
.groupBy(mapSheetAnalDataGeom.mapSheetNum)
.fetch();
}
}

View File

@@ -18,7 +18,7 @@ import java.util.List;
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;
public class ChangeDetectionRepositoryImpl extends QuerydslRepositorySupport
implements ChangeDetectionRepositoryCustom {
implements ChangeDetectionRepositoryCustom {
private final JPAQueryFactory queryFactory;
@@ -36,75 +36,75 @@ public class ChangeDetectionRepositoryImpl extends QuerydslRepositorySupport
@Override
public List<String> findPolygonJson() {
return queryFactory
.select(Expressions.stringTemplate("ST_AsGeoJSON({0})", mapSheetAnalDataGeomEntity.geom))
.from(mapSheetAnalDataGeomEntity)
.orderBy(mapSheetAnalDataGeomEntity.id.desc())
.fetch();
.select(Expressions.stringTemplate("ST_AsGeoJSON({0})", mapSheetAnalDataGeomEntity.geom))
.from(mapSheetAnalDataGeomEntity)
.orderBy(mapSheetAnalDataGeomEntity.id.desc())
.fetch();
}
@Override
public List<ChangeDetectionDto.CountDto> getChangeDetectionClassCount(Long id) {
return queryFactory
.select(
Projections.constructor(
ChangeDetectionDto.CountDto.class,
mapSheetAnalSttcEntity.classAfterCd.toUpperCase(),
mapSheetAnalSttcEntity.id.classAfterName,
mapSheetAnalSttcEntity.classAfterCnt.sum()))
.from(mapSheetAnalEntity)
.innerJoin(mapSheetAnalDataEntity)
.on(mapSheetAnalDataEntity.analUid.eq(mapSheetAnalEntity.id))
.innerJoin(mapSheetAnalSttcEntity)
.on(mapSheetAnalSttcEntity.dataUid.eq(mapSheetAnalDataEntity.id))
.where(mapSheetAnalEntity.id.eq(id))
.groupBy(mapSheetAnalSttcEntity.classAfterCd, mapSheetAnalSttcEntity.id.classAfterName)
.fetch();
.select(
Projections.constructor(
ChangeDetectionDto.CountDto.class,
mapSheetAnalSttcEntity.classAfterCd.toUpperCase(),
null, // TOOD classAfterName 삭제해서 수정 필요
mapSheetAnalSttcEntity.classAfterCnt.sum()))
.from(mapSheetAnalEntity)
.innerJoin(mapSheetAnalDataEntity)
.on(mapSheetAnalDataEntity.analUid.eq(mapSheetAnalEntity.id))
.innerJoin(mapSheetAnalSttcEntity)
.on(mapSheetAnalSttcEntity.dataUid.eq(mapSheetAnalDataEntity.id))
.where(mapSheetAnalEntity.id.eq(id))
.groupBy(mapSheetAnalSttcEntity.classAfterCd)
.fetch();
}
@Override
public ChangeDetectionDto.CogUrlDto getChangeDetectionCogUrl(ChangeDetectionDto.CogUrlReq req) {
return queryFactory
.select(
Projections.constructor(
ChangeDetectionDto.CogUrlDto.class,
makeCogUrl(req.getBeforeYear()).max().as("beforeCogUrl"),
makeCogUrl(req.getAfterYear()).max().as("afterCogUrl"),
mapInkx5kEntity.geom.as("bbox")))
.from(imageryEntity)
.innerJoin(mapInkx5kEntity)
.on(imageryEntity.scene5k.eq(mapInkx5kEntity.mapidcdNo))
.where(
imageryEntity
.year
.eq(req.getBeforeYear())
.or(imageryEntity.year.eq(req.getAfterYear())),
imageryEntity.scene5k.eq(req.getMapSheetNum()))
.groupBy(mapInkx5kEntity.geom)
.fetchOne();
.select(
Projections.constructor(
ChangeDetectionDto.CogUrlDto.class,
makeCogUrl(req.getBeforeYear()).max().as("beforeCogUrl"),
makeCogUrl(req.getAfterYear()).max().as("afterCogUrl"),
mapInkx5kEntity.geom.as("bbox")))
.from(imageryEntity)
.innerJoin(mapInkx5kEntity)
.on(imageryEntity.scene5k.eq(mapInkx5kEntity.mapidcdNo))
.where(
imageryEntity
.year
.eq(req.getBeforeYear())
.or(imageryEntity.year.eq(req.getAfterYear())),
imageryEntity.scene5k.eq(req.getMapSheetNum()))
.groupBy(mapInkx5kEntity.geom)
.fetchOne();
}
@Override
public List<ChangeDetectionDto.AnalYearList> getChangeDetectionYearList() {
return queryFactory
.select(
Projections.constructor(
ChangeDetectionDto.AnalYearList.class,
mapSheetAnalEntity.id,
mapSheetAnalEntity.analTitle,
mapSheetAnalEntity.compareYyyy.as("beforeYear"),
mapSheetAnalEntity.targetYyyy.as("afterYear"),
mapSheetAnalEntity.baseMapSheetNum))
.from(mapSheetAnalEntity)
.orderBy(mapSheetAnalEntity.id.asc())
.fetch();
.select(
Projections.constructor(
ChangeDetectionDto.AnalYearList.class,
mapSheetAnalEntity.id,
mapSheetAnalEntity.analTitle,
mapSheetAnalEntity.compareYyyy.as("beforeYear"),
mapSheetAnalEntity.targetYyyy.as("afterYear"),
mapSheetAnalEntity.baseMapSheetNum))
.from(mapSheetAnalEntity)
.orderBy(mapSheetAnalEntity.id.asc())
.fetch();
}
private StringExpression makeCogUrl(Integer year) {
return new CaseBuilder()
.when(imageryEntity.year.eq(year))
.then(
Expressions.stringTemplate(
"{0} || {1}", imageryEntity.cogMiddlePath, imageryEntity.cogFilename))
.otherwise("");
.when(imageryEntity.year.eq(year))
.then(
Expressions.stringTemplate(
"{0} || {1}", imageryEntity.cogMiddlePath, imageryEntity.cogFilename))
.otherwise("");
}
}