[KC-116] shp 파일 다운로드 이력 추가
This commit is contained in:
@@ -2,6 +2,7 @@ package com.kamco.cd.kamcoback.postgres.core;
|
||||
|
||||
import com.kamco.cd.kamcoback.common.service.BaseCoreService;
|
||||
import com.kamco.cd.kamcoback.log.dto.AuditLogDto;
|
||||
import com.kamco.cd.kamcoback.log.dto.AuditLogDto.DownloadReq;
|
||||
import com.kamco.cd.kamcoback.postgres.repository.log.AuditLogRepository;
|
||||
import java.time.LocalDate;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -45,6 +46,11 @@ public class AuditLogCoreService
|
||||
return auditLogRepository.findLogByAccount(searchRange, searchValue);
|
||||
}
|
||||
|
||||
public Page<AuditLogDto.Basic> findLogByAccount(
|
||||
AuditLogDto.searchReq searchReq, DownloadReq downloadReq) {
|
||||
return auditLogRepository.findDownloadLog(searchReq, downloadReq);
|
||||
}
|
||||
|
||||
public Page<AuditLogDto.DailyDetail> getLogByDailyResult(
|
||||
AuditLogDto.searchReq searchRange, LocalDate logDate) {
|
||||
return auditLogRepository.findLogByDailyResult(searchRange, logDate);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.kamco.cd.kamcoback.postgres.repository.log;
|
||||
|
||||
import com.kamco.cd.kamcoback.log.dto.AuditLogDto;
|
||||
import com.kamco.cd.kamcoback.log.dto.AuditLogDto.DownloadReq;
|
||||
import java.time.LocalDate;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
@@ -15,6 +16,8 @@ public interface AuditLogRepositoryCustom {
|
||||
Page<AuditLogDto.UserAuditList> findLogByAccount(
|
||||
AuditLogDto.searchReq searchReq, String searchValue);
|
||||
|
||||
Page<AuditLogDto.Basic> findDownloadLog(AuditLogDto.searchReq searchReq, DownloadReq downloadReq);
|
||||
|
||||
Page<AuditLogDto.DailyDetail> findLogByDailyResult(
|
||||
AuditLogDto.searchReq searchReq, LocalDate logDate);
|
||||
|
||||
|
||||
@@ -6,11 +6,13 @@ import static com.kamco.cd.kamcoback.postgres.entity.QMemberEntity.memberEntity;
|
||||
import static com.kamco.cd.kamcoback.postgres.entity.QMenuEntity.menuEntity;
|
||||
|
||||
import com.kamco.cd.kamcoback.log.dto.AuditLogDto;
|
||||
import com.kamco.cd.kamcoback.log.dto.AuditLogDto.DownloadReq;
|
||||
import com.kamco.cd.kamcoback.log.dto.ErrorLogDto;
|
||||
import com.kamco.cd.kamcoback.log.dto.EventStatus;
|
||||
import com.kamco.cd.kamcoback.log.dto.EventType;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.AuditLogEntity;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.QMenuEntity;
|
||||
import com.querydsl.core.BooleanBuilder;
|
||||
import com.querydsl.core.types.Projections;
|
||||
import com.querydsl.core.types.dsl.BooleanExpression;
|
||||
import com.querydsl.core.types.dsl.CaseBuilder;
|
||||
@@ -21,6 +23,7 @@ import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||
import io.micrometer.common.util.StringUtils;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@@ -32,6 +35,7 @@ import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport
|
||||
public class AuditLogRepositoryImpl extends QuerydslRepositorySupport
|
||||
implements AuditLogRepositoryCustom {
|
||||
|
||||
private static final ZoneId ZONE = ZoneId.of("Asia/Seoul");
|
||||
private final JPAQueryFactory queryFactory;
|
||||
private final StringExpression NULL_STRING = Expressions.stringTemplate("cast(null as text)");
|
||||
|
||||
@@ -155,6 +159,66 @@ public class AuditLogRepositoryImpl extends QuerydslRepositorySupport
|
||||
return new PageImpl<>(foundContent, pageable, countQuery);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<AuditLogDto.Basic> findDownloadLog(AuditLogDto.searchReq searchReq, DownloadReq req) {
|
||||
Pageable pageable = searchReq.toPageable();
|
||||
|
||||
BooleanBuilder whereBuilder = new BooleanBuilder();
|
||||
|
||||
whereBuilder.and(auditLogEntity.eventStatus.ne(EventStatus.valueOf("FAILED")));
|
||||
|
||||
if (req.getMenuId() != null && !req.getMenuId().isEmpty()) {
|
||||
whereBuilder.and(auditLogEntity.menuUid.eq(req.getMenuId()));
|
||||
}
|
||||
|
||||
if (req.getUuid() != null) {
|
||||
whereBuilder.and(auditLogEntity.requestUri.endsWith(String.valueOf(req.getUuid())));
|
||||
}
|
||||
|
||||
if (req.getType() != null && !req.getType().isEmpty()) {
|
||||
if (req.getType().equals(AuditLogDto.AuditType.NAME.getId())) {
|
||||
whereBuilder.and(memberEntity.name.contains(req.getSearchValue()));
|
||||
} else if (req.getType().equals(AuditLogDto.AuditType.EMPLOYEE_NO.getId())) {
|
||||
whereBuilder.and(memberEntity.employeeNo.contains(req.getSearchValue()));
|
||||
}
|
||||
}
|
||||
|
||||
List<AuditLogDto.Basic> foundContent =
|
||||
queryFactory
|
||||
.select(
|
||||
Projections.constructor(
|
||||
AuditLogDto.Basic.class,
|
||||
auditLogEntity.id,
|
||||
auditLogEntity.userUid,
|
||||
auditLogEntity.eventType,
|
||||
auditLogEntity.eventStatus,
|
||||
auditLogEntity.menuUid,
|
||||
auditLogEntity.ipAddress,
|
||||
auditLogEntity.requestUri,
|
||||
auditLogEntity.requestBody,
|
||||
auditLogEntity.errorLogUid,
|
||||
auditLogEntity.createdDate))
|
||||
.from(auditLogEntity)
|
||||
.leftJoin(memberEntity)
|
||||
.on(auditLogEntity.userUid.eq(memberEntity.id))
|
||||
.where(whereBuilder, createdDateBetween(req.getStartDate(), req.getEndDate()))
|
||||
.offset(pageable.getOffset())
|
||||
.limit(pageable.getPageSize())
|
||||
// .orderBy(auditLogEntity.eventEndedAt.max().desc())
|
||||
.fetch();
|
||||
|
||||
Long countQuery =
|
||||
queryFactory
|
||||
.select(auditLogEntity.userUid.countDistinct())
|
||||
.from(auditLogEntity)
|
||||
.leftJoin(memberEntity)
|
||||
.on(auditLogEntity.userUid.eq(memberEntity.id))
|
||||
.where(whereBuilder, createdDateBetween(req.getStartDate(), req.getEndDate()))
|
||||
.fetchOne();
|
||||
|
||||
return new PageImpl<>(foundContent, pageable, countQuery);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<AuditLogDto.DailyDetail> findLogByDailyResult(
|
||||
AuditLogDto.searchReq searchReq, LocalDate logDate) {
|
||||
@@ -365,6 +429,16 @@ public class AuditLogRepositoryImpl extends QuerydslRepositorySupport
|
||||
.and(auditLogEntity.createdDate.lt(ZonedDateTime.from(endDateTime)));
|
||||
}
|
||||
|
||||
private BooleanExpression createdDateBetween(LocalDate startDate, LocalDate endDate) {
|
||||
if (startDate == null || endDate == null) {
|
||||
return null;
|
||||
}
|
||||
ZonedDateTime start = startDate.atStartOfDay(ZONE);
|
||||
ZonedDateTime endExclusive = endDate.plusDays(1).atStartOfDay(ZONE);
|
||||
|
||||
return auditLogEntity.createdDate.goe(start).and(auditLogEntity.createdDate.lt(endExclusive));
|
||||
}
|
||||
|
||||
private BooleanExpression menuNameEquals(String searchValue) {
|
||||
if (StringUtils.isBlank(searchValue)) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user