Merge remote-tracking branch 'origin/feat/dev_251201' into feat/dev_251201
This commit is contained in:
@@ -0,0 +1,43 @@
|
|||||||
|
package com.kamco.cd.kamcoback.model;
|
||||||
|
|
||||||
|
import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
|
||||||
|
import com.kamco.cd.kamcoback.model.dto.ModelMgmtDto;
|
||||||
|
import com.kamco.cd.kamcoback.model.service.ModelMgmtService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.transaction.Transactional;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@Tag(name = "모델 관리", description = "모델 관리 API")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/model")
|
||||||
|
@Transactional
|
||||||
|
public class ModelMgmtApiController {
|
||||||
|
|
||||||
|
private final ModelMgmtService modelMgmtService;
|
||||||
|
|
||||||
|
@Operation(summary = "모델관리 목록")
|
||||||
|
@GetMapping
|
||||||
|
public ApiResponseDto<Page<ModelMgmtDto.ModelList>> findModelMgmtList(
|
||||||
|
@RequestParam(required = false) LocalDate startDate,
|
||||||
|
@RequestParam(required = false) LocalDate endDate,
|
||||||
|
@RequestParam(required = false, defaultValue = "createCompleteDttm") String sortColumn,
|
||||||
|
@RequestParam(required = false) String modelType,
|
||||||
|
@RequestParam(required = false) String searchVal,
|
||||||
|
@RequestParam(defaultValue = "0") int page,
|
||||||
|
@RequestParam(defaultValue = "20") int size) {
|
||||||
|
ModelMgmtDto.searchReq searchReq = new ModelMgmtDto.searchReq(page, size, sortColumn + ",desc");
|
||||||
|
|
||||||
|
Page<ModelMgmtDto.ModelList> result =
|
||||||
|
modelMgmtService.findModelMgmtList(searchReq, startDate, endDate, modelType, searchVal);
|
||||||
|
|
||||||
|
return ApiResponseDto.ok(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,8 +22,9 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
@Tag(name = "모델 관리", description = "모델 관리 API")
|
@Tag(name = "모델 관리", description = "모델 관리 API")
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/model")
|
@RequestMapping("/api/model/deprecated")
|
||||||
@Transactional
|
@Transactional
|
||||||
|
@Deprecated
|
||||||
public class ModelMngApiController {
|
public class ModelMngApiController {
|
||||||
|
|
||||||
private final ModelMngService modelMngService;
|
private final ModelMngService modelMngService;
|
||||||
|
|||||||
113
src/main/java/com/kamco/cd/kamcoback/model/dto/ModelMgmtDto.java
Normal file
113
src/main/java/com/kamco/cd/kamcoback/model/dto/ModelMgmtDto.java
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
package com.kamco.cd.kamcoback.model.dto;
|
||||||
|
|
||||||
|
import com.kamco.cd.kamcoback.common.utils.interfaces.JsonFormatDttm;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
|
|
||||||
|
public class ModelMgmtDto {
|
||||||
|
|
||||||
|
@Schema(name = "ModelMgmtDto Basic", description = "모델관리 엔티티 기본 정보")
|
||||||
|
@Getter
|
||||||
|
@NoArgsConstructor
|
||||||
|
public static class Basic {
|
||||||
|
|
||||||
|
private String modelVer;
|
||||||
|
private String hyperVer;
|
||||||
|
private String epochVer;
|
||||||
|
private String dockerFileNm;
|
||||||
|
|
||||||
|
@JsonFormatDttm private ZonedDateTime createCompleteDttm;
|
||||||
|
@JsonFormatDttm private ZonedDateTime recentUseDttm;
|
||||||
|
private Boolean deleted;
|
||||||
|
@JsonFormatDttm private ZonedDateTime createdDttm;
|
||||||
|
private Long createdUid;
|
||||||
|
|
||||||
|
@JsonFormatDttm private ZonedDateTime updatedDttm;
|
||||||
|
private Long updatedUid;
|
||||||
|
|
||||||
|
public Basic(
|
||||||
|
String modelVer,
|
||||||
|
String hyperVer,
|
||||||
|
String epochVer,
|
||||||
|
String dockerFileNm,
|
||||||
|
ZonedDateTime createCompleteDttm,
|
||||||
|
ZonedDateTime recentUseDttm,
|
||||||
|
Boolean deleted,
|
||||||
|
ZonedDateTime createdDttm,
|
||||||
|
Long createdUid,
|
||||||
|
ZonedDateTime updatedDttm,
|
||||||
|
Long updatedUid) {
|
||||||
|
this.modelVer = modelVer;
|
||||||
|
this.hyperVer = hyperVer;
|
||||||
|
this.epochVer = epochVer;
|
||||||
|
this.dockerFileNm = dockerFileNm;
|
||||||
|
this.createCompleteDttm = createCompleteDttm;
|
||||||
|
this.recentUseDttm = recentUseDttm;
|
||||||
|
this.deleted = deleted;
|
||||||
|
this.createdDttm = createdDttm;
|
||||||
|
this.createdUid = createdUid;
|
||||||
|
this.updatedDttm = updatedDttm;
|
||||||
|
this.updatedUid = updatedUid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Schema(name = "ModelList", description = "모델관리 목록")
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class ModelList {
|
||||||
|
private Integer rowNum;
|
||||||
|
private String modelVer;
|
||||||
|
private String dockerFileNm;
|
||||||
|
private String modelType;
|
||||||
|
private String createCompleteDttm;
|
||||||
|
private String recentUseDttm;
|
||||||
|
private Boolean deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Schema(name = "ModelAddReq", description = "모델 등록 req")
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class AddReq {
|
||||||
|
|
||||||
|
private String modelType;
|
||||||
|
private String dockerFileNm;
|
||||||
|
private String modelVer;
|
||||||
|
private String hyperVer;
|
||||||
|
private String epochVer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Schema(name = "searchReq", description = "검색 요청")
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class searchReq {
|
||||||
|
|
||||||
|
// 페이징 파라미터
|
||||||
|
private int page = 0;
|
||||||
|
private int size = 20;
|
||||||
|
private String sort;
|
||||||
|
|
||||||
|
public Pageable toPageable() {
|
||||||
|
if (sort != null && !sort.isEmpty()) {
|
||||||
|
String[] sortParams = sort.split(",");
|
||||||
|
String property = sortParams[0];
|
||||||
|
Sort.Direction direction =
|
||||||
|
sortParams.length > 1 ? Sort.Direction.fromString(sortParams[1]) : Sort.Direction.ASC;
|
||||||
|
return PageRequest.of(page, size, Sort.by(direction, property));
|
||||||
|
}
|
||||||
|
return PageRequest.of(page, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.kamco.cd.kamcoback.model.service;
|
||||||
|
|
||||||
|
import com.kamco.cd.kamcoback.model.dto.ModelMgmtDto;
|
||||||
|
import com.kamco.cd.kamcoback.postgres.core.ModelMgmtCoreService;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class ModelMgmtService {
|
||||||
|
|
||||||
|
private final ModelMgmtCoreService modelMgmtCoreService;
|
||||||
|
|
||||||
|
public Page<ModelMgmtDto.ModelList> findModelMgmtList(
|
||||||
|
ModelMgmtDto.searchReq searchReq,
|
||||||
|
LocalDate startDate,
|
||||||
|
LocalDate endDate,
|
||||||
|
String modelType,
|
||||||
|
String searchVal) {
|
||||||
|
return modelMgmtCoreService.findModelMgmtList(
|
||||||
|
searchReq, startDate, endDate, modelType, searchVal);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.kamco.cd.kamcoback.postgres.core;
|
||||||
|
|
||||||
|
import com.kamco.cd.kamcoback.model.dto.ModelMgmtDto;
|
||||||
|
import com.kamco.cd.kamcoback.postgres.repository.model.ModelMgmtRepository;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class ModelMgmtCoreService {
|
||||||
|
|
||||||
|
private final ModelMgmtRepository modelMgmtRepository;
|
||||||
|
|
||||||
|
public Page<ModelMgmtDto.ModelList> findModelMgmtList(
|
||||||
|
ModelMgmtDto.searchReq searchReq,
|
||||||
|
LocalDate startDate,
|
||||||
|
LocalDate endDate,
|
||||||
|
String modelType,
|
||||||
|
String searchVal) {
|
||||||
|
return modelMgmtRepository.findModelMgmtList(
|
||||||
|
searchReq, startDate, endDate, modelType, searchVal);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
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_mgmt")
|
||||||
|
public class ModelMgmtEntity extends CommonDateEntity {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "model_uid")
|
||||||
|
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 = "docker_file_nm")
|
||||||
|
private String dockerFileNm;
|
||||||
|
|
||||||
|
@Column(name = "create_complete_dttm")
|
||||||
|
private ZonedDateTime createCompleteDttm;
|
||||||
|
|
||||||
|
@Column(name = "recent_use_dttm")
|
||||||
|
private ZonedDateTime recentUseDttm;
|
||||||
|
|
||||||
|
@Column(name = "deleted")
|
||||||
|
private Boolean deleted;
|
||||||
|
|
||||||
|
@Column(name = "created_uid")
|
||||||
|
private Long createdUid;
|
||||||
|
|
||||||
|
@Column(name = "updated_uid")
|
||||||
|
private Long updatedUid;
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.kamco.cd.kamcoback.postgres.repository.model;
|
||||||
|
|
||||||
|
import com.kamco.cd.kamcoback.postgres.entity.ModelMgmtEntity;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface ModelMgmtRepository
|
||||||
|
extends JpaRepository<ModelMgmtEntity, Integer>, ModelMgmtRepositoryCustom {}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.kamco.cd.kamcoback.postgres.repository.model;
|
||||||
|
|
||||||
|
import com.kamco.cd.kamcoback.model.dto.ModelMgmtDto;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
|
||||||
|
public interface ModelMgmtRepositoryCustom {
|
||||||
|
|
||||||
|
Page<ModelMgmtDto.ModelList> findModelMgmtList(
|
||||||
|
ModelMgmtDto.searchReq searchReq,
|
||||||
|
LocalDate startDate,
|
||||||
|
LocalDate endDate,
|
||||||
|
String modelType,
|
||||||
|
String searchVal);
|
||||||
|
}
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
package com.kamco.cd.kamcoback.postgres.repository.model;
|
||||||
|
|
||||||
|
import static com.kamco.cd.kamcoback.postgres.entity.QModelMgmtEntity.modelMgmtEntity;
|
||||||
|
|
||||||
|
import com.kamco.cd.kamcoback.model.dto.ModelMgmtDto;
|
||||||
|
import com.kamco.cd.kamcoback.postgres.QuerydslOrderUtil;
|
||||||
|
import com.kamco.cd.kamcoback.postgres.entity.ModelMgmtEntity;
|
||||||
|
import com.querydsl.core.BooleanBuilder;
|
||||||
|
import com.querydsl.core.types.Expression;
|
||||||
|
import com.querydsl.core.types.Projections;
|
||||||
|
import com.querydsl.core.types.dsl.BooleanExpression;
|
||||||
|
import com.querydsl.core.types.dsl.Expressions;
|
||||||
|
import com.querydsl.core.types.dsl.StringExpression;
|
||||||
|
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageImpl;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;
|
||||||
|
|
||||||
|
public class ModelMgmtRepositoryImpl extends QuerydslRepositorySupport
|
||||||
|
implements ModelMgmtRepositoryCustom {
|
||||||
|
|
||||||
|
private final JPAQueryFactory queryFactory;
|
||||||
|
private final StringExpression NULL_STRING = Expressions.stringTemplate("cast(null as text)");
|
||||||
|
|
||||||
|
public ModelMgmtRepositoryImpl(JPAQueryFactory queryFactory) {
|
||||||
|
super(ModelMgmtEntity.class);
|
||||||
|
this.queryFactory = queryFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<ModelMgmtDto.ModelList> findModelMgmtList(
|
||||||
|
ModelMgmtDto.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", modelMgmtEntity.createCompleteDttm,
|
||||||
|
"recentUseDttm", modelMgmtEntity.recentUseDttm);
|
||||||
|
|
||||||
|
if (sort.isSorted()) {
|
||||||
|
Sort.Order order = sort.iterator().next();
|
||||||
|
property = order.getProperty();
|
||||||
|
}
|
||||||
|
|
||||||
|
Expression<?> sortColumn = sortColumnMap.get(property);
|
||||||
|
|
||||||
|
List<ModelMgmtDto.ModelList> foundContent =
|
||||||
|
queryFactory
|
||||||
|
.select(
|
||||||
|
Projections.constructor(
|
||||||
|
ModelMgmtDto.ModelList.class,
|
||||||
|
Expressions.numberTemplate(
|
||||||
|
Integer.class, "row_number() over(order by {0} desc)", sortColumn),
|
||||||
|
modelMgmtEntity.modelVer,
|
||||||
|
modelMgmtEntity.dockerFileNm,
|
||||||
|
modelMgmtEntity.modelVer.as("modelType"),
|
||||||
|
Expressions.stringTemplate(
|
||||||
|
"to_char({0}, 'YYYY-MM-DD')", modelMgmtEntity.createCompleteDttm),
|
||||||
|
Expressions.stringTemplate(
|
||||||
|
"to_char({0}, 'YYYY-MM-DD')", modelMgmtEntity.recentUseDttm),
|
||||||
|
modelMgmtEntity.deleted))
|
||||||
|
.from(modelMgmtEntity)
|
||||||
|
.where(
|
||||||
|
eventEndedAtBetween(startDate, endDate, property),
|
||||||
|
searchModelVersion(modelType, searchVal))
|
||||||
|
.offset(pageable.getOffset())
|
||||||
|
.limit(pageable.getPageSize())
|
||||||
|
.orderBy(
|
||||||
|
QuerydslOrderUtil.getOrderSpecifiers(
|
||||||
|
pageable, ModelMgmtEntity.class, "modelMgmtEntity"))
|
||||||
|
.fetch();
|
||||||
|
|
||||||
|
Long countQuery =
|
||||||
|
queryFactory
|
||||||
|
.select(modelMgmtEntity.modelUid.count())
|
||||||
|
.from(modelMgmtEntity)
|
||||||
|
.where(
|
||||||
|
eventEndedAtBetween(startDate, endDate, property),
|
||||||
|
searchModelVersion(modelType, searchVal))
|
||||||
|
.fetchOne();
|
||||||
|
|
||||||
|
return new PageImpl<>(foundContent, pageable, countQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
private BooleanExpression eventEndedAtBetween(
|
||||||
|
LocalDate startDate, LocalDate endDate, String sortColumn) {
|
||||||
|
if (Objects.isNull(startDate) || Objects.isNull(endDate)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ZoneId zone = ZoneId.systemDefault();
|
||||||
|
LocalDateTime startDateTime = startDate.atStartOfDay();
|
||||||
|
LocalDateTime endDateTime = endDate.plusDays(1).atStartOfDay();
|
||||||
|
|
||||||
|
if (sortColumn.equals("createCompleteDttm")) {
|
||||||
|
return modelMgmtEntity
|
||||||
|
.createCompleteDttm
|
||||||
|
.goe(startDateTime.atZone(zone))
|
||||||
|
.and(modelMgmtEntity.createCompleteDttm.lt(endDateTime.atZone(zone)));
|
||||||
|
} else {
|
||||||
|
return modelMgmtEntity
|
||||||
|
.recentUseDttm
|
||||||
|
.goe(startDateTime.atZone(zone))
|
||||||
|
.and(modelMgmtEntity.recentUseDttm.lt(endDateTime.atZone(zone)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private BooleanBuilder searchModelVersion(String modelType, String searchVal) {
|
||||||
|
BooleanBuilder builder = new BooleanBuilder();
|
||||||
|
|
||||||
|
if (Objects.nonNull(modelType)) {
|
||||||
|
builder.and(modelMgmtEntity.modelVer.eq(modelType));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Objects.nonNull(searchVal)) {
|
||||||
|
builder.and(modelMgmtEntity.dockerFileNm.likeIgnoreCase("%" + searchVal + "%"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user