모델 등록이력 API 진행중
This commit is contained in:
@@ -2,6 +2,7 @@ package com.kamco.cd.kamcoback.model;
|
||||
|
||||
import com.kamco.cd.kamcoback.code.dto.CommonCodeDto;
|
||||
import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
|
||||
import com.kamco.cd.kamcoback.log.dto.AuditLogDto;
|
||||
import com.kamco.cd.kamcoback.model.dto.ModelMngDto;
|
||||
import com.kamco.cd.kamcoback.model.dto.ModelVerDto;
|
||||
import com.kamco.cd.kamcoback.model.service.ModelMngService;
|
||||
@@ -13,8 +14,10 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.transaction.Transactional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -66,8 +69,34 @@ public class ModelMngApiController {
|
||||
return ApiResponseDto.createOK(modelMngService.save(addReq));
|
||||
}
|
||||
|
||||
@Operation(summary = "모델 수정", description = "모델 수정")
|
||||
@PutMapping("/{id}")
|
||||
public ApiResponseDto<Long> update(@PathVariable Long id, @RequestBody ModelMngDto.AddReq addReq) {
|
||||
return ApiResponseDto.ok(modelMngService.update(id, addReq));
|
||||
}
|
||||
|
||||
@Operation(summary = "모델 삭제", description = "모델 삭제")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResponseDto<Long> delete(@PathVariable Long id) {
|
||||
return ApiResponseDto.deleteOk(modelMngService.delete(id));
|
||||
}
|
||||
|
||||
@Operation(summary = "모델 등록 이력", description = "모델 등록 이력")
|
||||
@GetMapping("/reg-history")
|
||||
public ApiResponseDto<Page<ModelMngDto.ModelRegHistory>> getRegHistoryList(
|
||||
@RequestParam(required = false) LocalDate startDate,
|
||||
@RequestParam(required = false) LocalDate endDate,
|
||||
@RequestParam int page,
|
||||
@RequestParam(defaultValue = "20") int size,
|
||||
@RequestParam(required = false) String searchVal,
|
||||
@RequestParam String searchColumn
|
||||
) {
|
||||
ModelMngDto.searchReq searchReq =
|
||||
new ModelMngDto.searchReq(page, size, searchColumn + ",desc");
|
||||
|
||||
Page<ModelMngDto.ModelRegHistory> result =
|
||||
modelMngService.getRegHistoryList(searchReq, startDate, endDate);
|
||||
|
||||
return ApiResponseDto.ok(result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@ 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;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
@@ -96,4 +99,42 @@ public class ModelMngDto {
|
||||
@NotEmpty private String modelVer;
|
||||
private String modelCntnt;
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
@Schema(name = "ModelRegHistory", description = "모델 등록 이력")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class ModelRegHistory {
|
||||
private String modelNm;
|
||||
private String modelCate;
|
||||
private String modelVer;
|
||||
private String strCreatedDttm;
|
||||
private String usedState;
|
||||
private String strDeployDttm;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
package com.kamco.cd.kamcoback.model.service;
|
||||
|
||||
import com.kamco.cd.kamcoback.log.dto.AuditLogDto;
|
||||
import com.kamco.cd.kamcoback.model.dto.ModelMngDto;
|
||||
import com.kamco.cd.kamcoback.model.dto.ModelVerDto;
|
||||
import com.kamco.cd.kamcoback.postgres.core.ModelMngCoreService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -32,4 +35,12 @@ public class ModelMngService {
|
||||
public Long update(Long id, ModelMngDto.AddReq addReq) {
|
||||
return modelMngCoreService.update(id, addReq);
|
||||
}
|
||||
|
||||
public Long delete(Long id) {
|
||||
return modelMngCoreService.delete(id);
|
||||
}
|
||||
|
||||
public Page<ModelMngDto.ModelRegHistory> getRegHistoryList(ModelMngDto.searchReq searchReq, LocalDate startDate, LocalDate endDate) {
|
||||
return modelMngCoreService.getRegHistoryList(searchReq, startDate, endDate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,10 @@ import com.kamco.cd.kamcoback.postgres.repository.model.ModelMngRepository;
|
||||
import com.kamco.cd.kamcoback.postgres.repository.model.ModelVerRepository;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
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;
|
||||
|
||||
@@ -40,11 +42,25 @@ public class ModelMngCoreService {
|
||||
|
||||
public Long update(Long id, ModelMngDto.AddReq addReq) {
|
||||
//조회
|
||||
return null;
|
||||
// ModelVerEntity existData = modelVerRepository.findModelVerById(id)
|
||||
ModelVerEntity existData = modelVerRepository.findModelVerById(id)
|
||||
.orElseThrow(() -> new EntityNotFoundException("버전 id 에 대한 정보를 찾을 수 없습니다. id : " + id));
|
||||
|
||||
ModelVerEntity modelVerEntity = new ModelVerEntity(existData.getId(), addReq.getModelCate(), addReq.getModelVer(), "NONE", "NONE",
|
||||
0.0, "NONE", addReq.getModelPath(), 1L, 1L);
|
||||
return modelVerRepository.save(modelVerEntity).getId();
|
||||
}
|
||||
|
||||
public Long delete(Long id) {
|
||||
//조회
|
||||
// ModelVerEntity entity = modelVerRepository.findModelVerById(id)
|
||||
// .orElseThrow(() -> new EntityNotFoundException("버전 id 에 대한 정보를 찾을 수 없습니다. id : " + id));
|
||||
//
|
||||
// ModelVerEntity modelVerEntity = new ModelVerEntity(saved.getId(), addReq.getModelCate(), addReq.getModelVer(), "NONE", "NONE",
|
||||
// 0.0, "NONE", addReq.getModelPath(), 1L, 1L);
|
||||
// // id 코드 deleted = false 업데이트
|
||||
// entity.deleted();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Page<ModelMngDto.ModelRegHistory> getRegHistoryList(ModelMngDto.searchReq searchReq, LocalDate startDate, LocalDate endDate) {
|
||||
return modelMngRepository.getRegHistoryList(searchReq, startDate, endDate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@ 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 org.springframework.data.domain.Page;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -11,4 +13,6 @@ public interface ModelMngRepositoryCustom {
|
||||
List<ModelMngEntity> findModelMngAll();
|
||||
|
||||
Optional<ModelMngDto.FinalModelDto> getFinalModelInfo();
|
||||
|
||||
Page<ModelMngDto.ModelRegHistory> getRegHistoryList(ModelMngDto.searchReq searchReq, LocalDate startDate, LocalDate endDate);
|
||||
}
|
||||
|
||||
@@ -3,17 +3,25 @@ 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.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 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 static com.kamco.cd.kamcoback.postgres.entity.QModelMngEntity.modelMngEntity;
|
||||
import static com.kamco.cd.kamcoback.postgres.entity.QModelVerEntity.modelVerEntity;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ModelMngRepositoryImpl extends QuerydslRepositorySupport
|
||||
implements ModelMngRepositoryCustom {
|
||||
|
||||
@@ -59,4 +67,52 @@ public class ModelMngRepositoryImpl extends QuerydslRepositorySupport
|
||||
.fetchOne()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ModelMngDto.ModelRegHistory> getRegHistoryList(ModelMngDto.searchReq searchReq, LocalDate startDate, LocalDate endDate) {
|
||||
|
||||
Pageable pageable = searchReq.toPageable();
|
||||
List<ModelMngDto.ModelRegHistory> foundContent =
|
||||
queryFactory
|
||||
.select(
|
||||
Projections.constructor(
|
||||
ModelMngDto.ModelRegHistory.class,
|
||||
modelMngEntity.modelNm,
|
||||
modelMngEntity.modelCate,
|
||||
modelVerEntity.modelVer,
|
||||
Expressions.stringTemplate("to_char({0}, 'YYYY-MM-DD')", modelVerEntity.createdDate).as("strCreatedDttm"),
|
||||
modelVerEntity.usedState,
|
||||
Expressions.stringTemplate("to_char({0}, 'YYYY-MM-DD')", modelVerEntity.createdDate).as("strDeployDttm") //TODO: 배포일자 나오면 다시
|
||||
)
|
||||
)
|
||||
.from(modelMngEntity)
|
||||
.innerJoin(modelVerEntity)
|
||||
.on(modelMngEntity.id.eq(modelVerEntity.modelUid))
|
||||
.where(eventEndedAtBetween(startDate, endDate))
|
||||
.offset(pageable.getOffset())
|
||||
.limit(pageable.getPageSize())
|
||||
// .orderBy() //TODO : sort column 으로 desc 하기
|
||||
.fetch();
|
||||
|
||||
Long countQuery =
|
||||
queryFactory
|
||||
.select(modelVerEntity.id.count())
|
||||
.from(modelMngEntity)
|
||||
.innerJoin(modelVerEntity)
|
||||
.on(modelMngEntity.id.eq(modelVerEntity.modelUid))
|
||||
.where(eventEndedAtBetween(startDate, endDate))
|
||||
.fetchOne();
|
||||
|
||||
return new PageImpl<>(foundContent, pageable, countQuery);
|
||||
}
|
||||
|
||||
private BooleanExpression eventEndedAtBetween(LocalDate startDate, LocalDate endDate) {
|
||||
if (Objects.isNull(startDate) || Objects.isNull(endDate)) {
|
||||
return null;
|
||||
}
|
||||
LocalDateTime startDateTime = startDate.atStartOfDay();
|
||||
LocalDateTime endDateTime = endDate.plusDays(1).atStartOfDay();
|
||||
return modelMngEntity.createdDate.goe(ZonedDateTime.from(startDateTime))
|
||||
.and(modelMngEntity.modifiedDate.lt(ZonedDateTime.from(endDateTime)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user