모델 등록이력 API 진행중

This commit is contained in:
2025-11-24 18:30:51 +09:00
parent eb27462a69
commit 68090382f2
6 changed files with 165 additions and 8 deletions

View File

@@ -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)
// .orElseThrow(() -> new EntityNotFoundException("버전 id 에 대한 정보를 찾을 수 없습니다. id : " + 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);
}
}

View File

@@ -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);
}

View File

@@ -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)));
}
}