모델관리 테이블 교체하기 위한 백업본 entity 선언

This commit is contained in:
2025-12-19 09:47:55 +09:00
parent ec6e158367
commit 1162022595
12 changed files with 57 additions and 256 deletions

View File

@@ -2,18 +2,19 @@ package com.kamco.cd.kamcoback.postgres.core;
import com.kamco.cd.kamcoback.model.dto.ModelMngDto;
import com.kamco.cd.kamcoback.model.dto.ModelVerDto;
import com.kamco.cd.kamcoback.postgres.entity.ModelMngEntity;
import com.kamco.cd.kamcoback.postgres.entity.ModelMngBakEntity;
import com.kamco.cd.kamcoback.postgres.entity.ModelVerEntity;
import com.kamco.cd.kamcoback.postgres.repository.model.ModelMngRepository;
import com.kamco.cd.kamcoback.postgres.repository.model.ModelVerRepository;
import jakarta.persistence.EntityNotFoundException;
import java.time.LocalDate;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.List;
import java.util.Optional;
@Service
@RequiredArgsConstructor
public class ModelMngCoreService {
@@ -22,7 +23,7 @@ public class ModelMngCoreService {
private final ModelVerRepository modelVerRepository;
public List<ModelMngDto.Basic> findModelMngAll() {
return modelMngRepository.findModelMngAll().stream().map(ModelMngEntity::toDto).toList();
return modelMngRepository.findModelMngAll().stream().map(ModelMngBakEntity::toDto).toList();
}
public Optional<ModelMngDto.FinalModelDto> getFinalModelInfo() {
@@ -30,8 +31,8 @@ public class ModelMngCoreService {
}
public ModelVerDto.Basic save(ModelMngDto.AddReq addReq) {
ModelMngEntity modelMngEntity =
new ModelMngEntity(
ModelMngBakEntity modelMngBakEntity =
new ModelMngBakEntity(
addReq.getModelNm(),
addReq.getModelCate(),
addReq.getModelPath(),
@@ -39,7 +40,7 @@ public class ModelMngCoreService {
1L,
addReq.getModelCntnt()); // TODO: 로그인 기능 붙이면 Uid 넣어야 함
ModelMngEntity saved = modelMngRepository.save(modelMngEntity);
ModelMngBakEntity saved = modelMngRepository.save(modelMngBakEntity);
ModelVerEntity modelVerEntity =
new ModelVerEntity(
saved.getId(),

View File

@@ -1,25 +0,0 @@
package com.kamco.cd.kamcoback.postgres.entity;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@Entity
@Table(name = "tb_model_class_count")
public class ModelClassCountEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "count_uid")
private Integer countUid;
@Column(name = "model_uid")
private Integer modelUid;
@Column(name = "class_cd")
private String classCd;
@Column(name = "obj_cnt")
private Integer objCnt;
}

View File

@@ -1,20 +0,0 @@
package com.kamco.cd.kamcoback.postgres.entity;
import jakarta.persistence.Column;
import jakarta.persistence.EmbeddedId;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@Entity
@Table(name = "tb_model_dataset_mapp")
public class ModelDatasetMappEntity {
@EmbeddedId private ModelDatasetMappEntityId id;
@Column(name = "dataset_type")
private String datasetType;
}

View File

@@ -1,42 +0,0 @@
package com.kamco.cd.kamcoback.postgres.entity;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import jakarta.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Objects;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.Hibernate;
@Getter
@Setter
@Embeddable
public class ModelDatasetMappEntityId implements Serializable {
@NotNull
@Column(name = "model_uid", nullable = false)
private Integer modelUid;
@NotNull
@Column(name = "dataset_uid", nullable = false)
private Integer datasetUid;
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) {
return false;
}
ModelDatasetMappEntityId entity = (ModelDatasetMappEntityId) o;
return Objects.equals(this.modelUid, entity.modelUid)
&& Objects.equals(this.datasetUid, entity.datasetUid);
}
@Override
public int hashCode() {
return Objects.hash(modelUid, modelUid);
}
}

View File

@@ -1,40 +0,0 @@
package com.kamco.cd.kamcoback.postgres.entity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import java.time.ZonedDateTime;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@Entity
@Table(name = "tb_model_hyper_param")
public class ModelHyperParamEntity {
@Id
@Column(name = "hyper_ver")
private String hyperVer;
@Column(name = "learning_rate")
private Double learningRate;
@Column(name = "batch_size")
private Integer batchSize;
@Column(name = "dropout_ratio")
private Double dropoutRatio;
@Column(name = "cnn_filter_cnt")
private Integer cnnFilterCnt;
@Column(name = "memo", columnDefinition = "TEXT")
private String memo;
@Column(name = "del_yn")
private Character delYn;
@Column(name = "created_dttm")
private ZonedDateTime createdDttm;
}

View File

@@ -12,16 +12,12 @@ import org.hibernate.annotations.ColumnDefault;
@Getter
@Setter
@Entity
@Table(name = "tb_model_mng")
@Table(name = "tb_model_mng_bak")
@NoArgsConstructor
public class ModelMngEntity extends CommonDateEntity {
public class ModelMngBakEntity extends CommonDateEntity {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "tb_model_mng_id_gen")
@SequenceGenerator(
name = "tb_model_mng_id_gen",
sequenceName = "tb_model_mng_model_uid",
allocationSize = 1)
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "model_uid", nullable = false)
private Long id;
@@ -52,7 +48,7 @@ public class ModelMngEntity extends CommonDateEntity {
@Column(name = "bbone_ver")
private String bboneVer;
public ModelMngEntity(
public ModelMngBakEntity(
String modelNm,
String modelCate,
String modelPath,

View File

@@ -1,66 +0,0 @@
package com.kamco.cd.kamcoback.postgres.entity;
import com.kamco.cd.kamcoback.postgres.CommonDateEntity;
import jakarta.persistence.*;
import java.time.ZonedDateTime;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@Entity
@Table(name = "tb_model_train_master")
public class ModelTrainMasterEntity extends CommonDateEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "model_uid", nullable = false)
private Integer modelUid;
@Column(name = "model_ver")
private String modelVer;
@Column(name = "hyper_ver")
private String hyperVer;
@Column(name = "epoch_ver")
private String epochVer;
@Column(name = "process_step")
private String processStep;
@Column(name = "status_cd")
private String statsusCd;
@Column(name = "train_start_dttm")
private ZonedDateTime trainStartDttm;
@Column(name = "epoch_cnt")
private Integer epochCnt;
@Column(name = "dataset_ratio")
private String datasetRatio;
@Column(name = "best_epoch")
private Integer bestEpoch;
@Column(name = "step1_end_dttm")
private ZonedDateTime step1EndDttm;
@Column(name = "step1_duration")
private String step1Duration;
@Column(name = "step2_end_dttm")
private ZonedDateTime step2EndDttm;
@Column(name = "step2_duration")
private String step2Duration;
@Column(name = "del_yn")
private Character delYn;
@Column(name = "created_uid")
private Long createdUid;
@Column(name = "updated_uid")
private Long updatedUid;
}

View File

@@ -3,14 +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.Dashboard;
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.SearchGeoReq;
import com.kamco.cd.kamcoback.postgres.entity.MapSheetAnalDataEntity;
import com.kamco.cd.kamcoback.postgres.entity.MapSheetAnalDataGeomEntity;
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;
import com.kamco.cd.kamcoback.postgres.entity.QModelMngEntity;
import com.kamco.cd.kamcoback.postgres.entity.QModelVerEntity;
import com.kamco.cd.kamcoback.postgres.entity.*;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Order;
import com.querydsl.core.types.OrderSpecifier;
@@ -21,9 +14,6 @@ import com.querydsl.jpa.JPAExpressions;
import com.querydsl.jpa.JPQLQuery;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
@@ -31,12 +21,16 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Repository;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@Repository
@RequiredArgsConstructor
public class InferenceResultRepositoryImpl implements InferenceResultRepositoryCustom {
private final JPAQueryFactory queryFactory;
private final QModelMngEntity tmm = QModelMngEntity.modelMngEntity;
private final QModelMngBakEntity tmm = QModelMngBakEntity.modelMngBakEntity;
private final QModelVerEntity tmv = QModelVerEntity.modelVerEntity;
private final QMapSheetAnalEntity mapSheetAnalEntity = QMapSheetAnalEntity.mapSheetAnalEntity;
private final QMapSheetAnalDataEntity mapSheetAnalDataEntity =

View File

@@ -1,7 +1,7 @@
package com.kamco.cd.kamcoback.postgres.repository.model;
import com.kamco.cd.kamcoback.postgres.entity.ModelMngEntity;
import com.kamco.cd.kamcoback.postgres.entity.ModelMngBakEntity;
import org.springframework.data.jpa.repository.JpaRepository;
public interface ModelMngRepository
extends JpaRepository<ModelMngEntity, Long>, ModelMngRepositoryCustom {}
extends JpaRepository<ModelMngBakEntity, Long>, ModelMngRepositoryCustom {}

View File

@@ -1,15 +1,16 @@
package com.kamco.cd.kamcoback.postgres.repository.model;
import com.kamco.cd.kamcoback.model.dto.ModelMngDto;
import com.kamco.cd.kamcoback.postgres.entity.ModelMngEntity;
import com.kamco.cd.kamcoback.postgres.entity.ModelMngBakEntity;
import org.springframework.data.domain.Page;
import java.time.LocalDate;
import java.util.List;
import java.util.Optional;
import org.springframework.data.domain.Page;
public interface ModelMngRepositoryCustom {
List<ModelMngEntity> findModelMngAll();
List<ModelMngBakEntity> findModelMngAll();
Optional<ModelMngDto.FinalModelDto> getFinalModelInfo();

View File

@@ -1,12 +1,8 @@
package com.kamco.cd.kamcoback.postgres.repository.model;
import static com.kamco.cd.kamcoback.postgres.entity.QModelDeployHstEntity.modelDeployHstEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QModelMngEntity.modelMngEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QModelVerEntity.modelVerEntity;
import com.kamco.cd.kamcoback.model.dto.ModelMngDto;
import com.kamco.cd.kamcoback.postgres.QuerydslOrderUtil;
import com.kamco.cd.kamcoback.postgres.entity.ModelMngEntity;
import com.kamco.cd.kamcoback.postgres.entity.ModelMngBakEntity;
import com.kamco.cd.kamcoback.postgres.entity.ModelVerEntity;
import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.BooleanExpression;
@@ -14,16 +10,21 @@ import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.core.types.dsl.StringExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import io.micrometer.common.util.StringUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;
import static com.kamco.cd.kamcoback.postgres.entity.QModelDeployHstEntity.modelDeployHstEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QModelMngBakEntity.modelMngBakEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QModelVerEntity.modelVerEntity;
public class ModelMngRepositoryImpl extends QuerydslRepositorySupport
implements ModelMngRepositoryCustom {
@@ -32,13 +33,13 @@ public class ModelMngRepositoryImpl extends QuerydslRepositorySupport
private final StringExpression NULL_STRING = Expressions.stringTemplate("cast(null as text)");
public ModelMngRepositoryImpl(JPAQueryFactory queryFactory) {
super(ModelMngEntity.class);
super(ModelMngBakEntity.class);
this.queryFactory = queryFactory;
}
@Override
public List<ModelMngEntity> findModelMngAll() {
return queryFactory.selectFrom(modelMngEntity).orderBy(modelMngEntity.id.desc()).fetch();
public List<ModelMngBakEntity> findModelMngAll() {
return queryFactory.selectFrom(modelMngBakEntity).orderBy(modelMngBakEntity.id.desc()).fetch();
}
@Override
@@ -47,9 +48,9 @@ public class ModelMngRepositoryImpl extends QuerydslRepositorySupport
.select(
Projections.constructor(
ModelMngDto.FinalModelDto.class,
modelMngEntity.id.as("modelUid"),
modelMngEntity.modelNm,
modelMngEntity.modelCate,
modelMngBakEntity.id.as("modelUid"),
modelMngBakEntity.modelNm,
modelMngBakEntity.modelCate,
modelVerEntity.id.as("modelVerUid"),
modelVerEntity.modelVer,
Expressions.stringTemplate(
@@ -60,9 +61,9 @@ public class ModelMngRepositoryImpl extends QuerydslRepositorySupport
Expressions.stringTemplate(
"fn_codenm_to_misc({0}, {1})", 52, modelVerEntity.deployState), // 배포상태 한글 명칭
modelVerEntity.modelPath))
.from(modelMngEntity)
.from(modelMngBakEntity)
.innerJoin(modelVerEntity)
.on(modelMngEntity.id.eq(modelVerEntity.modelUid))
.on(modelMngBakEntity.id.eq(modelVerEntity.modelUid))
.where(modelVerEntity.usedState.eq("USED")) // USED 인 것 중에
.orderBy(modelVerEntity.modelVer.desc()) // Version 높은 것 기준
.stream()
@@ -79,8 +80,8 @@ public class ModelMngRepositoryImpl extends QuerydslRepositorySupport
.select(
Projections.constructor(
ModelMngDto.ModelRegHistory.class,
modelMngEntity.modelNm,
modelMngEntity.modelCate,
modelMngBakEntity.modelNm,
modelMngBakEntity.modelCate,
modelVerEntity.modelVer,
Expressions.stringTemplate(
"to_char({0}, 'YYYY-MM-DD')", modelVerEntity.createdDate)
@@ -93,9 +94,9 @@ public class ModelMngRepositoryImpl extends QuerydslRepositorySupport
Expressions.stringTemplate(
"to_char({0}, 'YYYY-MM-DD')", modelDeployHstEntity.deployDttm)
.as("deployDttm")))
.from(modelMngEntity)
.from(modelMngBakEntity)
.innerJoin(modelVerEntity)
.on(modelMngEntity.id.eq(modelVerEntity.modelUid))
.on(modelMngBakEntity.id.eq(modelVerEntity.modelUid))
.leftJoin(modelDeployHstEntity)
.on(
modelVerEntity
@@ -114,9 +115,9 @@ public class ModelMngRepositoryImpl extends QuerydslRepositorySupport
Long countQuery =
queryFactory
.select(modelVerEntity.id.count())
.from(modelMngEntity)
.from(modelMngBakEntity)
.innerJoin(modelVerEntity)
.on(modelMngEntity.id.eq(modelVerEntity.modelUid))
.on(modelMngBakEntity.id.eq(modelVerEntity.modelUid))
.where(eventEndedAtBetween(startDate, endDate), searchModelVerLike(searchVal))
.fetchOne();
@@ -129,10 +130,10 @@ public class ModelMngRepositoryImpl extends QuerydslRepositorySupport
}
LocalDateTime startDateTime = startDate.atStartOfDay();
LocalDateTime endDateTime = endDate.plusDays(1).atStartOfDay();
return modelMngEntity
return modelMngBakEntity
.createdDate
.goe(ZonedDateTime.from(startDateTime))
.and(modelMngEntity.modifiedDate.lt(ZonedDateTime.from(endDateTime)));
.and(modelMngBakEntity.modifiedDate.lt(ZonedDateTime.from(endDateTime)));
}
private BooleanExpression searchModelVerLike(String searchVal) {

View File

@@ -1,15 +1,16 @@
package com.kamco.cd.kamcoback.postgres.repository.model;
import static com.kamco.cd.kamcoback.postgres.entity.QModelVerEntity.modelVerEntity;
import com.kamco.cd.kamcoback.postgres.entity.ModelMngEntity;
import com.kamco.cd.kamcoback.postgres.entity.ModelMngBakEntity;
import com.kamco.cd.kamcoback.postgres.entity.ModelVerEntity;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.core.types.dsl.StringExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.util.Optional;
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;
import java.util.Optional;
import static com.kamco.cd.kamcoback.postgres.entity.QModelVerEntity.modelVerEntity;
public class ModelVerRepositoryImpl extends QuerydslRepositorySupport
implements ModelVerRepositoryCustom {
@@ -17,7 +18,7 @@ public class ModelVerRepositoryImpl extends QuerydslRepositorySupport
private final StringExpression NULL_STRING = Expressions.stringTemplate("cast(null as text)");
public ModelVerRepositoryImpl(JPAQueryFactory queryFactory) {
super(ModelMngEntity.class);
super(ModelMngBakEntity.class);
this.queryFactory = queryFactory;
}