diff --git a/src/main/java/com/kamco/cd/kamcoback/inference/InferenceResultApiController.java b/src/main/java/com/kamco/cd/kamcoback/inference/InferenceResultApiController.java index f9f0096b..9ee43a3b 100644 --- a/src/main/java/com/kamco/cd/kamcoback/inference/InferenceResultApiController.java +++ b/src/main/java/com/kamco/cd/kamcoback/inference/InferenceResultApiController.java @@ -59,12 +59,9 @@ public class InferenceResultApiController { @Parameter(description = "페이지 번호 (0부터 시작)", example = "0") @RequestParam(defaultValue = "0") int page, @Parameter(description = "페이지 크기", example = "20") @RequestParam(defaultValue = "20") - int size, - @Parameter(description = "정렬 조건 (형식: 필드명,방향)", example = "name,asc") - @RequestParam(required = false) - String sort) { + int size) { InferenceResultDto.SearchReq searchReq = - new InferenceResultDto.SearchReq(statCode, title, page, size, sort); + new InferenceResultDto.SearchReq(statCode, title, page, size); Page analResList = inferenceResultService.getInferenceResultList(searchReq); return ApiResponseDto.ok(analResList); diff --git a/src/main/java/com/kamco/cd/kamcoback/inference/dto/InferenceResultDto.java b/src/main/java/com/kamco/cd/kamcoback/inference/dto/InferenceResultDto.java index d70abb60..ed45f97a 100644 --- a/src/main/java/com/kamco/cd/kamcoback/inference/dto/InferenceResultDto.java +++ b/src/main/java/com/kamco/cd/kamcoback/inference/dto/InferenceResultDto.java @@ -345,16 +345,8 @@ public class InferenceResultDto { // 페이징 파라미터 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); } } diff --git a/src/main/java/com/kamco/cd/kamcoback/postgres/repository/log/AuditLogRepositoryImpl.java b/src/main/java/com/kamco/cd/kamcoback/postgres/repository/log/AuditLogRepositoryImpl.java index 8fdfc907..45686d2c 100644 --- a/src/main/java/com/kamco/cd/kamcoback/postgres/repository/log/AuditLogRepositoryImpl.java +++ b/src/main/java/com/kamco/cd/kamcoback/postgres/repository/log/AuditLogRepositoryImpl.java @@ -30,7 +30,7 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport; public class AuditLogRepositoryImpl extends QuerydslRepositorySupport - implements AuditLogRepositoryCustom { + implements AuditLogRepositoryCustom { private final JPAQueryFactory queryFactory; private final StringExpression NULL_STRING = Expressions.stringTemplate("cast(null as text)"); @@ -42,313 +42,313 @@ public class AuditLogRepositoryImpl extends QuerydslRepositorySupport @Override public Page findLogByDaily( - AuditLogDto.searchReq searchReq, LocalDate startDate, LocalDate endDate) { + AuditLogDto.searchReq searchReq, LocalDate startDate, LocalDate endDate) { StringExpression groupDateTime = - Expressions.stringTemplate("to_char({0}, 'YYYY-MM-DD')", auditLogEntity.createdDate); + Expressions.stringTemplate("to_char({0}, 'YYYY-MM-DD')", auditLogEntity.createdDate); Pageable pageable = searchReq.toPageable(); List foundContent = - queryFactory - .select( - Projections.constructor( - AuditLogDto.DailyAuditList.class, - readCount().as("readCount"), - cudCount().as("cudCount"), - printCount().as("printCount"), - downloadCount().as("downloadCount"), - auditLogEntity.count().as("totalCount"), - groupDateTime.as("baseDate"))) - .from(auditLogEntity) - .where(eventEndedAtBetween(startDate, endDate)) - .groupBy(groupDateTime) - .offset(pageable.getOffset()) - .limit(pageable.getPageSize()) - .orderBy(groupDateTime.desc()) - .fetch(); + queryFactory + .select( + Projections.constructor( + AuditLogDto.DailyAuditList.class, + readCount().as("readCount"), + cudCount().as("cudCount"), + printCount().as("printCount"), + downloadCount().as("downloadCount"), + auditLogEntity.count().as("totalCount"), + groupDateTime.as("baseDate"))) + .from(auditLogEntity) + .where(eventEndedAtBetween(startDate, endDate)) + .groupBy(groupDateTime) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) + .orderBy(groupDateTime.desc()) + .fetch(); Long countQuery = - queryFactory - .select(groupDateTime.countDistinct()) - .from(auditLogEntity) - .where(eventEndedAtBetween(startDate, endDate)) - .fetchOne(); + queryFactory + .select(groupDateTime.countDistinct()) + .from(auditLogEntity) + .where(eventEndedAtBetween(startDate, endDate)) + .fetchOne(); return new PageImpl<>(foundContent, pageable, countQuery); } @Override public Page findLogByMenu( - AuditLogDto.searchReq searchReq, String searchValue) { + AuditLogDto.searchReq searchReq, String searchValue) { Pageable pageable = searchReq.toPageable(); List foundContent = - queryFactory - .select( - Projections.constructor( - AuditLogDto.MenuAuditList.class, - auditLogEntity.menuUid.as("menuId"), - menuEntity.menuNm.max().as("menuName"), - readCount().as("readCount"), - cudCount().as("cudCount"), - printCount().as("printCount"), - downloadCount().as("downloadCount"), - auditLogEntity.count().as("totalCount"))) - .from(auditLogEntity) - .leftJoin(menuEntity) - .on(auditLogEntity.menuUid.eq(menuEntity.menuUid)) - .where(menuNameEquals(searchValue)) - .groupBy(auditLogEntity.menuUid) - .offset(pageable.getOffset()) - .limit(pageable.getPageSize()) - .orderBy(auditLogEntity.createdDate.max().desc()) - .fetch(); + queryFactory + .select( + Projections.constructor( + AuditLogDto.MenuAuditList.class, + auditLogEntity.menuUid.as("menuId"), + menuEntity.menuNm.max().as("menuName"), + readCount().as("readCount"), + cudCount().as("cudCount"), + printCount().as("printCount"), + downloadCount().as("downloadCount"), + auditLogEntity.count().as("totalCount"))) + .from(auditLogEntity) + .leftJoin(menuEntity) + .on(auditLogEntity.menuUid.eq(menuEntity.menuUid)) + .where(menuNameEquals(searchValue)) + .groupBy(auditLogEntity.menuUid) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) + .orderBy(auditLogEntity.createdDate.max().desc()) + .fetch(); // count query group by 를 지정하면 하나의 row 가 아니라 그룹핑된 여러 row 가 나올 수 있다. // select query 의 group by 대상의 컬럼을 count query 에선 select distinct 로 처리 한다. Long countQuery = - queryFactory - .select(auditLogEntity.menuUid.countDistinct()) - .from(auditLogEntity) - .leftJoin(menuEntity) - .on(auditLogEntity.menuUid.eq(menuEntity.menuUid)) - .where(menuNameEquals(searchValue)) - .fetchOne(); + queryFactory + .select(auditLogEntity.menuUid.countDistinct()) + .from(auditLogEntity) + .leftJoin(menuEntity) + .on(auditLogEntity.menuUid.eq(menuEntity.menuUid)) + .where(menuNameEquals(searchValue)) + .fetchOne(); return new PageImpl<>(foundContent, pageable, countQuery); } @Override public Page findLogByAccount( - AuditLogDto.searchReq searchReq, String searchValue) { + AuditLogDto.searchReq searchReq, String searchValue) { Pageable pageable = searchReq.toPageable(); List foundContent = - queryFactory - .select( - Projections.constructor( - AuditLogDto.UserAuditList.class, - auditLogEntity.userUid.as("accountId"), - memberEntity.employeeNo.as("loginId"), - memberEntity.name.as("username"), - readCount().as("readCount"), - cudCount().as("cudCount"), - printCount().as("printCount"), - downloadCount().as("downloadCount"), - auditLogEntity.count().as("totalCount"))) - .from(auditLogEntity) - .leftJoin(memberEntity) - .on(auditLogEntity.userUid.eq(memberEntity.id)) - .where(loginIdOrUsernameContains(searchValue)) - .groupBy(auditLogEntity.userUid, memberEntity.employeeNo, memberEntity.name) - .offset(pageable.getOffset()) - .limit(pageable.getPageSize()) - // .orderBy(auditLogEntity.eventEndedAt.max().desc()) - .fetch(); + queryFactory + .select( + Projections.constructor( + AuditLogDto.UserAuditList.class, + auditLogEntity.userUid.as("accountId"), + memberEntity.employeeNo.as("loginId"), + memberEntity.name.as("username"), + readCount().as("readCount"), + cudCount().as("cudCount"), + printCount().as("printCount"), + downloadCount().as("downloadCount"), + auditLogEntity.count().as("totalCount"))) + .from(auditLogEntity) + .leftJoin(memberEntity) + .on(auditLogEntity.userUid.eq(memberEntity.id)) + .where(loginIdOrUsernameContains(searchValue)) + .groupBy(auditLogEntity.userUid, memberEntity.employeeNo, memberEntity.name) + .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(loginIdOrUsernameContains(searchValue)) - .fetchOne(); + queryFactory + .select(auditLogEntity.userUid.countDistinct()) + .from(auditLogEntity) + .leftJoin(memberEntity) + .on(auditLogEntity.userUid.eq(memberEntity.id)) + .where(loginIdOrUsernameContains(searchValue)) + .fetchOne(); return new PageImpl<>(foundContent, pageable, countQuery); } @Override public Page findLogByDailyResult( - AuditLogDto.searchReq searchReq, LocalDate logDate) { + AuditLogDto.searchReq searchReq, LocalDate logDate) { Pageable pageable = searchReq.toPageable(); QMenuEntity parent = new QMenuEntity("parent"); // 1depth menu name StringExpression parentMenuName = - new CaseBuilder() - .when(parent.menuUid.isNull()) - .then(menuEntity.menuNm) - .otherwise(parent.menuNm); + new CaseBuilder() + .when(parent.menuUid.isNull()) + .then(menuEntity.menuNm) + .otherwise(parent.menuNm); // 2depth menu name StringExpression menuName = - new CaseBuilder() - .when(parent.menuUid.isNull()) - .then(NULL_STRING) - .otherwise(menuEntity.menuNm); + new CaseBuilder() + .when(parent.menuUid.isNull()) + .then(NULL_STRING) + .otherwise(menuEntity.menuNm); List foundContent = - queryFactory - .select( - Projections.constructor( - AuditLogDto.DailyDetail.class, - auditLogEntity.id.as("logId"), - memberEntity.name.as("userName"), - memberEntity.employeeNo.as("loginId"), - menuEntity.menuNm.as("menuName"), - auditLogEntity.eventType.as("eventType"), - Projections.constructor( - AuditLogDto.LogDetail.class, - Expressions.constant("한국자산관리공사"), // serviceName - parentMenuName.as("parentMenuName"), - menuName, - menuEntity.menuUrl.as("menuUrl"), - menuEntity.description.as("menuDescription"), - menuEntity.menuOrder.as("sortOrder"), - menuEntity.isUse.as("used")))) - .from(auditLogEntity) - .leftJoin(menuEntity) - .on(auditLogEntity.menuUid.eq(menuEntity.menuUid)) - .leftJoin(menuEntity.parent, parent) - .leftJoin(memberEntity) - .on(auditLogEntity.userUid.eq(memberEntity.id)) - .where(eventEndedAtEqDate(logDate)) - .offset(pageable.getOffset()) - .limit(pageable.getPageSize()) - .orderBy(auditLogEntity.createdDate.desc()) - .fetch(); + queryFactory + .select( + Projections.constructor( + AuditLogDto.DailyDetail.class, + auditLogEntity.id.as("logId"), + memberEntity.name.as("userName"), + memberEntity.employeeNo.as("loginId"), + menuEntity.menuNm.as("menuName"), + auditLogEntity.eventType.as("eventType"), + Projections.constructor( + AuditLogDto.LogDetail.class, + Expressions.constant("한국자산관리공사"), // serviceName + parentMenuName.as("parentMenuName"), + menuName, + menuEntity.menuUrl.as("menuUrl"), + menuEntity.description.as("menuDescription"), + menuEntity.menuOrder.as("sortOrder"), + menuEntity.isUse.as("used")))) + .from(auditLogEntity) + .leftJoin(menuEntity) + .on(auditLogEntity.menuUid.eq(menuEntity.menuUid)) + .leftJoin(menuEntity.parent, parent) + .leftJoin(memberEntity) + .on(auditLogEntity.userUid.eq(memberEntity.id)) + .where(eventEndedAtEqDate(logDate)) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) + .orderBy(auditLogEntity.createdDate.desc()) + .fetch(); Long countQuery = - queryFactory - .select(auditLogEntity.id.countDistinct()) - .from(auditLogEntity) - .leftJoin(menuEntity) - .on(auditLogEntity.menuUid.eq(menuEntity.menuUid)) - .leftJoin(menuEntity.parent, parent) - .leftJoin(memberEntity) - .on(auditLogEntity.userUid.eq(memberEntity.id)) - .where(eventEndedAtEqDate(logDate)) - .fetchOne(); + queryFactory + .select(auditLogEntity.id.countDistinct()) + .from(auditLogEntity) + .leftJoin(menuEntity) + .on(auditLogEntity.menuUid.eq(menuEntity.menuUid)) + .leftJoin(menuEntity.parent, parent) + .leftJoin(memberEntity) + .on(auditLogEntity.userUid.eq(memberEntity.id)) + .where(eventEndedAtEqDate(logDate)) + .fetchOne(); return new PageImpl<>(foundContent, pageable, countQuery); } @Override public Page findLogByMenuResult( - AuditLogDto.searchReq searchReq, String menuUid) { + AuditLogDto.searchReq searchReq, String menuUid) { Pageable pageable = searchReq.toPageable(); QMenuEntity parent = new QMenuEntity("parent"); // 1depth menu name StringExpression parentMenuName = - new CaseBuilder() - .when(parent.menuUid.isNull()) - .then(menuEntity.menuNm) - .otherwise(parent.menuNm); + new CaseBuilder() + .when(parent.menuUid.isNull()) + .then(menuEntity.menuNm) + .otherwise(parent.menuNm); // 2depth menu name StringExpression menuName = - new CaseBuilder() - .when(parent.menuUid.isNull()) - .then(NULL_STRING) - .otherwise(menuEntity.menuNm); + new CaseBuilder() + .when(parent.menuUid.isNull()) + .then(NULL_STRING) + .otherwise(menuEntity.menuNm); List foundContent = - queryFactory - .select( - Projections.constructor( - AuditLogDto.MenuDetail.class, - auditLogEntity.id.as("logId"), - Expressions.stringTemplate( - "to_char({0}, 'YYYY-MM-DD')", auditLogEntity.createdDate) - .as("logDateTime"), // ?? - memberEntity.name.as("userName"), - memberEntity.employeeNo.as("loginId"), - auditLogEntity.eventType.as("eventType"), - Projections.constructor( - AuditLogDto.LogDetail.class, - Expressions.constant("한국자산관리공사"), // serviceName - parentMenuName.as("parentMenuName"), - menuName, - menuEntity.menuUrl.as("menuUrl"), - menuEntity.description.as("menuDescription"), - menuEntity.menuOrder.as("sortOrder"), - menuEntity.isUse.as("used")))) - .from(auditLogEntity) - .leftJoin(menuEntity) - .on(auditLogEntity.menuUid.eq(menuEntity.menuUid)) - .leftJoin(menuEntity.parent, parent) - .leftJoin(memberEntity) - .on(auditLogEntity.userUid.eq(memberEntity.id)) - .where(menuUidEq(menuUid)) - .offset(pageable.getOffset()) - .limit(pageable.getPageSize()) - .orderBy(auditLogEntity.createdDate.desc()) - .fetch(); + queryFactory + .select( + Projections.constructor( + AuditLogDto.MenuDetail.class, + auditLogEntity.id.as("logId"), + Expressions.stringTemplate( + "to_char({0}, 'YYYY-MM-DD')", auditLogEntity.createdDate) + .as("logDateTime"), // ?? + memberEntity.name.as("userName"), + memberEntity.employeeNo.as("loginId"), + auditLogEntity.eventType.as("eventType"), + Projections.constructor( + AuditLogDto.LogDetail.class, + Expressions.constant("한국자산관리공사"), // serviceName + parentMenuName.as("parentMenuName"), + menuName, + menuEntity.menuUrl.as("menuUrl"), + menuEntity.description.as("menuDescription"), + menuEntity.menuOrder.as("sortOrder"), + menuEntity.isUse.as("used")))) + .from(auditLogEntity) + .leftJoin(menuEntity) + .on(auditLogEntity.menuUid.eq(menuEntity.menuUid)) + .leftJoin(menuEntity.parent, parent) + .leftJoin(memberEntity) + .on(auditLogEntity.userUid.eq(memberEntity.id)) + .where(menuUidEq(menuUid)) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) + .orderBy(auditLogEntity.createdDate.desc()) + .fetch(); Long countQuery = - queryFactory - .select(auditLogEntity.id.countDistinct()) - .from(auditLogEntity) - .leftJoin(menuEntity) - .on(auditLogEntity.menuUid.eq(menuEntity.menuUid)) - .leftJoin(menuEntity.parent, parent) - .leftJoin(memberEntity) - .on(auditLogEntity.userUid.eq(memberEntity.id)) - .where(menuUidEq(menuUid)) - .fetchOne(); + queryFactory + .select(auditLogEntity.id.countDistinct()) + .from(auditLogEntity) + .leftJoin(menuEntity) + .on(auditLogEntity.menuUid.eq(menuEntity.menuUid)) + .leftJoin(menuEntity.parent, parent) + .leftJoin(memberEntity) + .on(auditLogEntity.userUid.eq(memberEntity.id)) + .where(menuUidEq(menuUid)) + .fetchOne(); return new PageImpl<>(foundContent, pageable, countQuery); } @Override public Page findLogByAccountResult( - AuditLogDto.searchReq searchReq, Long userUid) { + AuditLogDto.searchReq searchReq, Long userUid) { Pageable pageable = searchReq.toPageable(); QMenuEntity parent = new QMenuEntity("parent"); // 1depth menu name StringExpression parentMenuName = - new CaseBuilder() - .when(parent.menuUid.isNull()) - .then(menuEntity.menuNm) - .otherwise(parent.menuNm); + new CaseBuilder() + .when(parent.menuUid.isNull()) + .then(menuEntity.menuNm) + .otherwise(parent.menuNm); // 2depth menu name StringExpression menuName = - new CaseBuilder() - .when(parent.menuUid.isNull()) - .then(NULL_STRING) - .otherwise(menuEntity.menuNm); + new CaseBuilder() + .when(parent.menuUid.isNull()) + .then(NULL_STRING) + .otherwise(menuEntity.menuNm); List foundContent = - queryFactory - .select( - Projections.constructor( - AuditLogDto.UserDetail.class, - auditLogEntity.id.as("logId"), - Expressions.stringTemplate( - "to_char({0}, 'YYYY-MM-DD')", auditLogEntity.createdDate) - .as("logDateTime"), - menuEntity.menuNm.as("menuName"), - auditLogEntity.eventType.as("eventType"), - Projections.constructor( - AuditLogDto.LogDetail.class, - Expressions.constant("한국자산관리공사"), // serviceName - parentMenuName.as("parentMenuName"), - menuName, - menuEntity.menuUrl.as("menuUrl"), - menuEntity.description.as("menuDescription"), - menuEntity.menuOrder.as("sortOrder"), - menuEntity.isUse.as("used")))) - .from(auditLogEntity) - .leftJoin(menuEntity) - .on(auditLogEntity.menuUid.eq(menuEntity.menuUid)) - .leftJoin(menuEntity.parent, parent) - .leftJoin(memberEntity) - .on(auditLogEntity.userUid.eq(memberEntity.id)) - .where(userUidEq(userUid)) - .offset(pageable.getOffset()) - .limit(pageable.getPageSize()) - .orderBy(auditLogEntity.createdDate.desc()) - .fetch(); + queryFactory + .select( + Projections.constructor( + AuditLogDto.UserDetail.class, + auditLogEntity.id.as("logId"), + Expressions.stringTemplate( + "to_char({0}, 'YYYY-MM-DD')", auditLogEntity.createdDate) + .as("logDateTime"), + menuEntity.menuNm.as("menuName"), + auditLogEntity.eventType.as("eventType"), + Projections.constructor( + AuditLogDto.LogDetail.class, + Expressions.constant("한국자산관리공사"), // serviceName + parentMenuName.as("parentMenuName"), + menuName, + menuEntity.menuUrl.as("menuUrl"), + menuEntity.description.as("menuDescription"), + menuEntity.menuOrder.as("sortOrder"), + menuEntity.isUse.as("used")))) + .from(auditLogEntity) + .leftJoin(menuEntity) + .on(auditLogEntity.menuUid.eq(menuEntity.menuUid)) + .leftJoin(menuEntity.parent, parent) + .leftJoin(memberEntity) + .on(auditLogEntity.userUid.eq(memberEntity.id)) + .where(userUidEq(userUid)) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) + .orderBy(auditLogEntity.createdDate.desc()) + .fetch(); Long countQuery = - queryFactory - .select(auditLogEntity.id.countDistinct()) - .from(auditLogEntity) - .leftJoin(menuEntity) - .on(auditLogEntity.menuUid.eq(menuEntity.menuUid)) - .leftJoin(menuEntity.parent, parent) - .leftJoin(memberEntity) - .on(auditLogEntity.userUid.eq(memberEntity.id)) - .where(userUidEq(userUid)) - .fetchOne(); + queryFactory + .select(auditLogEntity.id.countDistinct()) + .from(auditLogEntity) + .leftJoin(menuEntity) + .on(auditLogEntity.menuUid.eq(menuEntity.menuUid)) + .leftJoin(menuEntity.parent, parent) + .leftJoin(memberEntity) + .on(auditLogEntity.userUid.eq(memberEntity.id)) + .where(userUidEq(userUid)) + .fetchOne(); return new PageImpl<>(foundContent, pageable, countQuery); } @@ -360,9 +360,9 @@ public class AuditLogRepositoryImpl extends QuerydslRepositorySupport LocalDateTime startDateTime = startDate.atStartOfDay(); LocalDateTime endDateTime = endDate.plusDays(1).atStartOfDay(); return auditLogEntity - .createdDate - .goe(ZonedDateTime.from(startDateTime)) - .and(auditLogEntity.createdDate.lt(ZonedDateTime.from(endDateTime))); + .createdDate + .goe(ZonedDateTime.from(startDateTime)) + .and(auditLogEntity.createdDate.lt(ZonedDateTime.from(endDateTime))); } private BooleanExpression menuNameEquals(String searchValue) { @@ -376,7 +376,10 @@ public class AuditLogRepositoryImpl extends QuerydslRepositorySupport if (StringUtils.isBlank(searchValue)) { return null; } - return memberEntity.employeeNo.contains(searchValue).or(memberEntity.name.contains(searchValue)); + return memberEntity + .employeeNo + .contains(searchValue) + .or(memberEntity.name.contains(searchValue)); } private BooleanExpression eventStatusEqFailed() { @@ -399,7 +402,7 @@ public class AuditLogRepositoryImpl extends QuerydslRepositorySupport private BooleanExpression eventEndedAtEqDate(LocalDate logDate) { StringExpression eventEndedDate = - Expressions.stringTemplate("to_char({0}, 'YYYY-MM-DD')", auditLogEntity.createdDate); + Expressions.stringTemplate("to_char({0}, 'YYYY-MM-DD')", auditLogEntity.createdDate); LocalDateTime comparisonDate = logDate.atStartOfDay(); return eventEndedDate.eq(comparisonDate.toString()); @@ -415,33 +418,33 @@ public class AuditLogRepositoryImpl extends QuerydslRepositorySupport private NumberExpression readCount() { return new CaseBuilder() - .when(auditLogEntity.eventType.eq(EventType.READ)) - .then(1) - .otherwise(0) - .sum(); + .when(auditLogEntity.eventType.eq(EventType.READ)) + .then(1) + .otherwise(0) + .sum(); } private NumberExpression cudCount() { return new CaseBuilder() - .when(auditLogEntity.eventType.in(EventType.CREATE, EventType.UPDATE, EventType.DELETE)) - .then(1) - .otherwise(0) - .sum(); + .when(auditLogEntity.eventType.in(EventType.CREATE, EventType.UPDATE, EventType.DELETE)) + .then(1) + .otherwise(0) + .sum(); } private NumberExpression printCount() { return new CaseBuilder() - .when(auditLogEntity.eventType.eq(EventType.PRINT)) - .then(1) - .otherwise(0) - .sum(); + .when(auditLogEntity.eventType.eq(EventType.PRINT)) + .then(1) + .otherwise(0) + .sum(); } private NumberExpression downloadCount() { return new CaseBuilder() - .when(auditLogEntity.eventType.eq(EventType.DOWNLOAD)) - .then(1) - .otherwise(0) - .sum(); + .when(auditLogEntity.eventType.eq(EventType.DOWNLOAD)) + .then(1) + .otherwise(0) + .sum(); } } diff --git a/src/main/java/com/kamco/cd/kamcoback/postgres/repository/log/ErrorLogRepositoryImpl.java b/src/main/java/com/kamco/cd/kamcoback/postgres/repository/log/ErrorLogRepositoryImpl.java index af13cd2c..de42f7c9 100644 --- a/src/main/java/com/kamco/cd/kamcoback/postgres/repository/log/ErrorLogRepositoryImpl.java +++ b/src/main/java/com/kamco/cd/kamcoback/postgres/repository/log/ErrorLogRepositoryImpl.java @@ -25,7 +25,7 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport; public class ErrorLogRepositoryImpl extends QuerydslRepositorySupport - implements ErrorLogRepositoryCustom { + implements ErrorLogRepositoryCustom { private final JPAQueryFactory queryFactory; private final StringExpression NULL_STRING = Expressions.stringTemplate("cast(null as text)"); @@ -39,57 +39,57 @@ public class ErrorLogRepositoryImpl extends QuerydslRepositorySupport public Page findLogByError(ErrorLogDto.ErrorSearchReq searchReq) { Pageable pageable = searchReq.toPageable(); List foundContent = - queryFactory - .select( - Projections.constructor( - ErrorLogDto.Basic.class, - errorLogEntity.id.as("logId"), - Expressions.stringTemplate("{0}", "한국자산관리공사"), // serviceName - menuEntity.menuNm.as("menuName"), - memberEntity.employeeNo.as("loginId"), - memberEntity.name.as("userName"), - errorLogEntity.errorType.as("eventType"), - errorLogEntity.errorMessage.as( - "errorName"), // 기존에는 errorName 값이 있었는데 신규 테이블에는 없음. 에러 메세지와 동일 - errorLogEntity.errorLevel.as("errorLevel"), - errorLogEntity.errorCode.as("errorCode"), - errorLogEntity.errorMessage.as("errorMessage"), - errorLogEntity.stackTrace.as("errorDetail"), - Expressions.stringTemplate( - "to_char({0}, 'YYYY-MM-DD')", errorLogEntity.createdDate))) - .from(errorLogEntity) - .leftJoin(auditLogEntity) - .on(errorLogEntity.id.eq(auditLogEntity.errorLogUid)) - .leftJoin(menuEntity) - .on(auditLogEntity.menuUid.eq(menuEntity.menuUid)) - .leftJoin(memberEntity) - .on(errorLogEntity.handlerUid.eq(memberEntity.id)) - .where( - eventStatusEqFailed(), - eventEndedAtBetween(searchReq.getStartDate(), searchReq.getEndDate()), - eventTypeEq(searchReq.getEventType()), - errorLevelEq(searchReq.getErrorLevel())) - .offset(pageable.getOffset()) - .limit(pageable.getPageSize()) - .orderBy(errorLogEntity.createdDate.desc()) - .fetch(); + queryFactory + .select( + Projections.constructor( + ErrorLogDto.Basic.class, + errorLogEntity.id.as("logId"), + Expressions.stringTemplate("{0}", "한국자산관리공사"), // serviceName + menuEntity.menuNm.as("menuName"), + memberEntity.employeeNo.as("loginId"), + memberEntity.name.as("userName"), + errorLogEntity.errorType.as("eventType"), + errorLogEntity.errorMessage.as( + "errorName"), // 기존에는 errorName 값이 있었는데 신규 테이블에는 없음. 에러 메세지와 동일 + errorLogEntity.errorLevel.as("errorLevel"), + errorLogEntity.errorCode.as("errorCode"), + errorLogEntity.errorMessage.as("errorMessage"), + errorLogEntity.stackTrace.as("errorDetail"), + Expressions.stringTemplate( + "to_char({0}, 'YYYY-MM-DD')", errorLogEntity.createdDate))) + .from(errorLogEntity) + .leftJoin(auditLogEntity) + .on(errorLogEntity.id.eq(auditLogEntity.errorLogUid)) + .leftJoin(menuEntity) + .on(auditLogEntity.menuUid.eq(menuEntity.menuUid)) + .leftJoin(memberEntity) + .on(errorLogEntity.handlerUid.eq(memberEntity.id)) + .where( + eventStatusEqFailed(), + eventEndedAtBetween(searchReq.getStartDate(), searchReq.getEndDate()), + eventTypeEq(searchReq.getEventType()), + errorLevelEq(searchReq.getErrorLevel())) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) + .orderBy(errorLogEntity.createdDate.desc()) + .fetch(); Long countQuery = - queryFactory - .select(errorLogEntity.id.countDistinct()) - .from(errorLogEntity) - .leftJoin(auditLogEntity) - .on(errorLogEntity.id.eq(auditLogEntity.errorLogUid)) - .leftJoin(menuEntity) - .on(auditLogEntity.menuUid.eq(menuEntity.menuUid)) - .leftJoin(memberEntity) - .on(errorLogEntity.handlerUid.eq(memberEntity.id)) - .where( - eventStatusEqFailed(), - eventEndedAtBetween(searchReq.getStartDate(), searchReq.getEndDate()), - eventTypeEq(searchReq.getEventType()), - errorLevelEq(searchReq.getErrorLevel())) - .fetchOne(); + queryFactory + .select(errorLogEntity.id.countDistinct()) + .from(errorLogEntity) + .leftJoin(auditLogEntity) + .on(errorLogEntity.id.eq(auditLogEntity.errorLogUid)) + .leftJoin(menuEntity) + .on(auditLogEntity.menuUid.eq(menuEntity.menuUid)) + .leftJoin(memberEntity) + .on(errorLogEntity.handlerUid.eq(memberEntity.id)) + .where( + eventStatusEqFailed(), + eventEndedAtBetween(searchReq.getStartDate(), searchReq.getEndDate()), + eventTypeEq(searchReq.getEventType()), + errorLevelEq(searchReq.getErrorLevel())) + .fetchOne(); return new PageImpl<>(foundContent, pageable, countQuery); } @@ -101,9 +101,9 @@ public class ErrorLogRepositoryImpl extends QuerydslRepositorySupport LocalDateTime startDateTime = startDate.atStartOfDay(); LocalDateTime endDateTime = endDate.plusDays(1).atStartOfDay(); return auditLogEntity - .createdDate - .goe(ZonedDateTime.from(startDateTime)) - .and(auditLogEntity.createdDate.lt(ZonedDateTime.from(endDateTime))); + .createdDate + .goe(ZonedDateTime.from(startDateTime)) + .and(auditLogEntity.createdDate.lt(ZonedDateTime.from(endDateTime))); } private BooleanExpression eventStatusEqFailed() {