feat: format error

This commit is contained in:
2025-11-20 14:50:02 +09:00
parent 5c030869fd
commit 04678b6b6e
33 changed files with 1031 additions and 852 deletions

View File

@@ -3,11 +3,10 @@ package com.kamco.cd.kamcoback.postgres;
import jakarta.persistence.Column;
import jakarta.persistence.MappedSuperclass;
import jakarta.persistence.PrePersist;
import java.time.ZonedDateTime;
import lombok.Getter;
import org.springframework.data.annotation.CreatedDate;
import java.time.ZonedDateTime;
@Getter
@MappedSuperclass
public class CommonCreateEntity {

View File

@@ -3,24 +3,22 @@ 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.postgres.repository.log.AuditLogRepository;
import java.time.LocalDate;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDate;
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class AuditLogCoreService implements BaseCoreService<AuditLogDto.AuditList, Long, AuditLogDto.DailySearchReq> {
public class AuditLogCoreService
implements BaseCoreService<AuditLogDto.AuditList, Long, AuditLogDto.DailySearchReq> {
private final AuditLogRepository auditLogRepository;
@Override
public void remove(Long aLong) {
}
public void remove(Long aLong) {}
@Override
public AuditLogDto.AuditList getOneById(Long aLong) {
@@ -32,27 +30,33 @@ public class AuditLogCoreService implements BaseCoreService<AuditLogDto.AuditLis
return null;
}
public Page<AuditLogDto.AuditList> getLogByDaily(AuditLogDto.DailySearchReq searchRange, LocalDate startDate, LocalDate endDate) {
public Page<AuditLogDto.AuditList> getLogByDaily(
AuditLogDto.DailySearchReq searchRange, LocalDate startDate, LocalDate endDate) {
return auditLogRepository.findLogByDaily(searchRange, startDate, endDate);
}
public Page<AuditLogDto.AuditList> getLogByMenu(AuditLogDto.MenuUserSearchReq searchRange, String searchValue) {
public Page<AuditLogDto.AuditList> getLogByMenu(
AuditLogDto.MenuUserSearchReq searchRange, String searchValue) {
return auditLogRepository.findLogByMenu(searchRange, searchValue);
}
public Page<AuditLogDto.AuditList> getLogByAccount(AuditLogDto.MenuUserSearchReq searchRange, String searchValue) {
public Page<AuditLogDto.AuditList> getLogByAccount(
AuditLogDto.MenuUserSearchReq searchRange, String searchValue) {
return auditLogRepository.findLogByAccount(searchRange, searchValue);
}
public Page<AuditLogDto.AuditDetail> getLogByDailyResult(AuditLogDto.DailySearchReq searchRange, LocalDate logDate) {
public Page<AuditLogDto.AuditDetail> getLogByDailyResult(
AuditLogDto.DailySearchReq searchRange, LocalDate logDate) {
return auditLogRepository.findLogByDailyResult(searchRange, logDate);
}
public Page<AuditLogDto.AuditDetail> getLogByMenuResult(AuditLogDto.MenuUserSearchReq searchRange, String menuId) {
public Page<AuditLogDto.AuditDetail> getLogByMenuResult(
AuditLogDto.MenuUserSearchReq searchRange, String menuId) {
return auditLogRepository.findLogByMenuResult(searchRange, menuId);
}
public Page<AuditLogDto.AuditDetail> getLogByAccountResult(AuditLogDto.MenuUserSearchReq searchRange, Long accountId) {
public Page<AuditLogDto.AuditDetail> getLogByAccountResult(
AuditLogDto.MenuUserSearchReq searchRange, Long accountId) {
return auditLogRepository.findLogByAccountResult(searchRange, accountId);
}
}

View File

@@ -14,34 +14,52 @@ import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
public class CommonCodeCoreService implements BaseCoreService<CommonCodeDto.Basic, Long, SearchReq> {
public class CommonCodeCoreService
implements BaseCoreService<CommonCodeDto.Basic, Long, SearchReq> {
private final CommonCodeRepository commonCodeRepository;
public List<CommonCodeDto.Basic> findAll() {
return commonCodeRepository.findByAll().stream().map(CommonCodeEntity::toDto).toList();
}
public CommonCodeDto.Basic save(CommonCodeDto.AddReq req) {
if(req.getParentId() != null){
CommonCodeEntity parentCommonCodeEntity = commonCodeRepository.findById(req.getParentId())
.orElseThrow(() -> new EntityNotFoundException("parent id 를 찾을 수 없습니다. id : " + req.getParentId()));
if (req.getParentId() != null) {
CommonCodeEntity parentCommonCodeEntity =
commonCodeRepository
.findById(req.getParentId())
.orElseThrow(
() ->
new EntityNotFoundException(
"parent id 를 찾을 수 없습니다. id : " + req.getParentId()));
CommonCodeEntity entity = new CommonCodeEntity(req.getCode(), req.getName(), req.getDescription(), req.getOrder(), req.isUsed());
CommonCodeEntity entity =
new CommonCodeEntity(
req.getCode(), req.getName(), req.getDescription(), req.getOrder(), req.isUsed());
entity.addParent(parentCommonCodeEntity);
return commonCodeRepository.save(entity).toDto();
}
CommonCodeEntity entity = new CommonCodeEntity(req.getCode(), req.getName(), req.getDescription(), req.getOrder(), req.isUsed());
CommonCodeEntity entity =
new CommonCodeEntity(
req.getCode(), req.getName(), req.getDescription(), req.getOrder(), req.isUsed());
return commonCodeRepository.save(entity).toDto();
}
public CommonCodeDto.Basic update(Long id, CommonCodeDto.ModifyReq req) {
CommonCodeEntity found = commonCodeRepository.findByCodeId(id)
.orElseThrow(()->new EntityNotFoundException("common code 를 찾을 수 없습니다. id : " + id));
CommonCodeEntity found =
commonCodeRepository
.findByCodeId(id)
.orElseThrow(() -> new EntityNotFoundException("common code 를 찾을 수 없습니다. id : " + id));
CommonCodeEntity entity = new CommonCodeEntity( id, req.getName(), req.getDescription(), req.getOrder(), req.isUsed(), found.getDeleted());
CommonCodeEntity entity =
new CommonCodeEntity(
id,
req.getName(),
req.getDescription(),
req.getOrder(),
req.isUsed(),
found.getDeleted());
return commonCodeRepository.save(entity).toDto();
}
@@ -56,8 +74,10 @@ public class CommonCodeCoreService implements BaseCoreService<CommonCodeDto.Basi
@Override
public void remove(Long id) {
CommonCodeEntity entity = commonCodeRepository.findByCodeId(id)
.orElseThrow(()->new EntityNotFoundException("code를 찾을 수 없습니다. id " + id));
CommonCodeEntity entity =
commonCodeRepository
.findByCodeId(id)
.orElseThrow(() -> new EntityNotFoundException("code를 찾을 수 없습니다. id " + id));
// 하위 코드 deleted = false 업데이트
entity.getChildren().forEach(CommonCodeEntity::deleted);
@@ -67,8 +87,10 @@ public class CommonCodeCoreService implements BaseCoreService<CommonCodeDto.Basi
@Override
public Basic getOneById(Long id) {
CommonCodeEntity entity = commonCodeRepository.findByCodeId(id)
.orElseThrow(()->new EntityNotFoundException("code를 찾을 수 없습니다. id " + id));
CommonCodeEntity entity =
commonCodeRepository
.findByCodeId(id)
.orElseThrow(() -> new EntityNotFoundException("code를 찾을 수 없습니다. id " + id));
return entity.toDto();
}

View File

@@ -1,21 +1,18 @@
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.ErrorLogDto;
import com.kamco.cd.kamcoback.postgres.repository.log.AuditLogRepository;
import com.kamco.cd.kamcoback.postgres.repository.log.ErrorLogRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDate;
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class ErrorLogCoreService implements BaseCoreService<ErrorLogDto.Basic, Long, ErrorLogDto.ErrorSearchReq> {
public class ErrorLogCoreService
implements BaseCoreService<ErrorLogDto.Basic, Long, ErrorLogDto.ErrorSearchReq> {
private final ErrorLogRepository errorLogRepository;

View File

@@ -43,7 +43,15 @@ public class AuditLogEntity extends CommonCreateEntity {
@Column(name = "error_log_uid")
private Long errorLogUid;
public AuditLogEntity(Long userUid, EventType eventType, EventStatus eventStatus, String menuUid, String ipAddress, String requestUri, String requestBody, Long errorLogUid) {
public AuditLogEntity(
Long userUid,
EventType eventType,
EventStatus eventStatus,
String menuUid,
String ipAddress,
String requestUri,
String requestBody,
Long errorLogUid) {
this.userUid = userUid;
this.eventType = eventType;
this.eventStatus = eventStatus;
@@ -56,29 +64,37 @@ public class AuditLogEntity extends CommonCreateEntity {
public AuditLogDto.Basic toDto() {
return new AuditLogDto.Basic(
this.id,
this.userUid,
this.eventType,
this.eventStatus,
this.menuUid,
this.ipAddress,
this.requestUri,
this.requestBody,
this.errorLogUid,
super.getCreatedDate());
this.id,
this.userUid,
this.eventType,
this.eventStatus,
this.menuUid,
this.ipAddress,
this.requestUri,
this.requestBody,
this.errorLogUid,
super.getCreatedDate());
}
@Override
public String toString(){
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(this.id).append("\n")
.append(this.userUid).append("\n")
.append(this.eventType).append("\n")
.append(this.eventStatus).append("\n")
.append(this.menuUid).append("\n")
.append(this.ipAddress).append("\n")
.append(this.requestUri).append("\n")
.append(this.requestBody).append("\n")
sb.append(this.id)
.append("\n")
.append(this.userUid)
.append("\n")
.append(this.eventType)
.append("\n")
.append(this.eventStatus)
.append("\n")
.append(this.menuUid)
.append("\n")
.append(this.ipAddress)
.append("\n")
.append(this.requestUri)
.append("\n")
.append(this.requestBody)
.append("\n")
.append(this.errorLogUid);
return sb.toString();
}

View File

@@ -61,7 +61,8 @@ public class CommonCodeEntity extends CommonDateEntity {
@OneToMany(mappedBy = "parent", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private List<CommonCodeEntity> children = new ArrayList<>();
public CommonCodeEntity(String code, String name, String description, Integer order, Boolean used) {
public CommonCodeEntity(
String code, String name, String description, Integer order, Boolean used) {
this.code = code;
this.name = name;
this.description = description;
@@ -69,7 +70,8 @@ public class CommonCodeEntity extends CommonDateEntity {
this.used = used;
}
public CommonCodeEntity(Long id, String name, String description, Integer order, Boolean used, Boolean deleted) {
public CommonCodeEntity(
Long id, String name, String description, Integer order, Boolean used, Boolean deleted) {
this.id = id;
this.name = name;
this.description = description;
@@ -80,19 +82,18 @@ public class CommonCodeEntity extends CommonDateEntity {
public CommonCodeDto.Basic toDto() {
return new CommonCodeDto.Basic(
this.id,
this.code,
this.description,
this.name,
this.order,
this.used,
this.deleted,
this.children.stream().map(CommonCodeEntity::toDto).toList(),
super.getCreatedDate(),
super.getModifiedDate());
this.id,
this.code,
this.description,
this.name,
this.order,
this.used,
this.deleted,
this.children.stream().map(CommonCodeEntity::toDto).toList(),
super.getCreatedDate(),
super.getModifiedDate());
}
public void addParent(CommonCodeEntity parent) {
this.parent = parent;
}

View File

@@ -4,13 +4,11 @@ import com.kamco.cd.kamcoback.log.dto.ErrorLogDto;
import com.kamco.cd.kamcoback.log.dto.EventType;
import com.kamco.cd.kamcoback.postgres.CommonCreateEntity;
import jakarta.persistence.*;
import java.time.ZonedDateTime;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@@ -30,14 +28,22 @@ public class ErrorLogEntity extends CommonCreateEntity {
@Enumerated(EnumType.STRING)
private ErrorLogDto.LogErrorLevel errorLevel;
private String errorCode;
private String errorMessage;
private String stackTrace;
private Long handlerUid;
private ZonedDateTime handledDttm;
public ErrorLogEntity(String requestId, EventType errorType, ErrorLogDto.LogErrorLevel errorLevel, String errorCode, String errorMessage, String stackTrace
, Long handlerUid, ZonedDateTime handledDttm) {
public ErrorLogEntity(
String requestId,
EventType errorType,
ErrorLogDto.LogErrorLevel errorLevel,
String errorCode,
String errorMessage,
String stackTrace,
Long handlerUid,
ZonedDateTime handledDttm) {
this.requestId = requestId;
this.errorType = errorType;
this.errorLevel = errorLevel;

View File

@@ -1,17 +1,14 @@
package com.kamco.cd.kamcoback.postgres.entity;
import com.kamco.cd.kamcoback.log.dto.EventStatus;
import com.kamco.cd.kamcoback.log.dto.EventType;
import com.kamco.cd.kamcoback.postgres.CommonDateEntity;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import java.util.ArrayList;
import java.util.List;
@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)

View File

@@ -1,15 +1,12 @@
package com.kamco.cd.kamcoback.postgres.entity;
import com.kamco.cd.kamcoback.log.dto.ErrorLogDto;
import com.kamco.cd.kamcoback.log.dto.EventType;
import com.kamco.cd.kamcoback.postgres.CommonDateEntity;
import jakarta.persistence.*;
import java.time.ZonedDateTime;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import java.time.ZonedDateTime;
@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@@ -27,15 +24,14 @@ public class UserEntity extends CommonDateEntity {
private String userId;
@Column(name = "pswd")
private String pswd; //TODO: 암호화
private String pswd; // TODO: 암호화
//@Enumerated(EnumType.STRING)
private String state; //TODO: 추후 enum -> ACTIVE : 정상, LOCKED : 잠김, EXPIRED : 만료, WITHDRAWAL : 탈퇴
// @Enumerated(EnumType.STRING)
private String state; // TODO: 추후 enum -> ACTIVE : 정상, LOCKED : 잠김, EXPIRED : 만료, WITHDRAWAL : 탈퇴
private ZonedDateTime dateWithdrawal;
private String userEmail;
private Long createdUid;
private Long updatedUid;
}

View File

@@ -3,6 +3,5 @@ package com.kamco.cd.kamcoback.postgres.repository;
import com.kamco.cd.kamcoback.postgres.entity.CommonCodeEntity;
import org.springframework.data.jpa.repository.JpaRepository;
public interface CommonCodeRepository extends JpaRepository<CommonCodeEntity, Long>, CommonCodeRepositoryCustom {
}
public interface CommonCodeRepository
extends JpaRepository<CommonCodeEntity, Long>, CommonCodeRepositoryCustom {}

View File

@@ -7,7 +7,10 @@ import java.util.Optional;
public interface CommonCodeRepositoryCustom {
Optional<CommonCodeEntity> findByCodeId(Long id);
Optional<CommonCodeEntity> findByCode(String code);
List<CommonCodeEntity> findByAll();
void updateOrder(CommonCodeDto.OrderReq req);
}

View File

@@ -6,10 +6,7 @@ import com.kamco.cd.kamcoback.code.dto.CommonCodeDto;
import com.kamco.cd.kamcoback.code.dto.CommonCodeDto.OrderReqDetail;
import com.kamco.cd.kamcoback.postgres.entity.CommonCodeEntity;
import com.kamco.cd.kamcoback.postgres.entity.QCommonCodeEntity;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -17,7 +14,8 @@ import java.util.Set;
import java.util.stream.Collectors;
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;
public class CommonCodeRepositoryImpl extends QuerydslRepositorySupport implements CommonCodeRepositoryCustom {
public class CommonCodeRepositoryImpl extends QuerydslRepositorySupport
implements CommonCodeRepositoryCustom {
private final JPAQueryFactory queryFactory;
@@ -30,75 +28,65 @@ public class CommonCodeRepositoryImpl extends QuerydslRepositorySupport implemen
public Optional<CommonCodeEntity> findByCodeId(Long id) {
QCommonCodeEntity child = new QCommonCodeEntity("child");
return Optional.ofNullable(
queryFactory
.selectFrom(commonCodeEntity)
.leftJoin(commonCodeEntity.children, child)
.fetchJoin()
.where(
commonCodeEntity.id.eq(id),
commonCodeEntity.deleted.isFalse()
)
.orderBy(commonCodeEntity.order.asc(), child.order.asc())
.fetchOne()
);
queryFactory
.selectFrom(commonCodeEntity)
.leftJoin(commonCodeEntity.children, child)
.fetchJoin()
.where(commonCodeEntity.id.eq(id), commonCodeEntity.deleted.isFalse())
.orderBy(commonCodeEntity.order.asc(), child.order.asc())
.fetchOne());
}
@Override
public Optional<CommonCodeEntity> findByCode(String code) {
QCommonCodeEntity child = new QCommonCodeEntity("child");
return Optional.ofNullable(
queryFactory
.selectFrom(commonCodeEntity)
.leftJoin(commonCodeEntity.children, child)
.fetchJoin()
.where(
commonCodeEntity.parent.isNull(),
commonCodeEntity.code.eq(code),
commonCodeEntity.used.isTrue(),
commonCodeEntity.deleted.isFalse()
)
.orderBy(child.order.asc())
.fetchOne()
);
queryFactory
.selectFrom(commonCodeEntity)
.leftJoin(commonCodeEntity.children, child)
.fetchJoin()
.where(
commonCodeEntity.parent.isNull(),
commonCodeEntity.code.eq(code),
commonCodeEntity.used.isTrue(),
commonCodeEntity.deleted.isFalse())
.orderBy(child.order.asc())
.fetchOne());
}
@Override
public List<CommonCodeEntity> findByAll() {
QCommonCodeEntity child = new QCommonCodeEntity("child");
return queryFactory
.selectFrom(commonCodeEntity)
.leftJoin(commonCodeEntity.children, child)
.fetchJoin()
.where(
commonCodeEntity.parent.isNull(),
commonCodeEntity.deleted.isFalse()
)
.orderBy(commonCodeEntity.order.asc(), child.order.asc())
.fetch();
.selectFrom(commonCodeEntity)
.leftJoin(commonCodeEntity.children, child)
.fetchJoin()
.where(commonCodeEntity.parent.isNull(), commonCodeEntity.deleted.isFalse())
.orderBy(commonCodeEntity.order.asc(), child.order.asc())
.fetch();
}
@Override
public void updateOrder(CommonCodeDto.OrderReq req) {
Map<Long, Integer> orderMap = req.getOrders().stream().
collect(Collectors.toMap(OrderReqDetail::getId, OrderReqDetail::getOrder));
Map<Long, Integer> orderMap =
req.getOrders().stream()
.collect(Collectors.toMap(OrderReqDetail::getId, OrderReqDetail::getOrder));
List<CommonCodeEntity> entity = findAllByIds(orderMap.keySet());
entity.forEach(commonCodeEntity -> {
Integer order = orderMap.get(commonCodeEntity.getId());
if(order != null) {
commonCodeEntity.updateOrder(order);
}
});
entity.forEach(
commonCodeEntity -> {
Integer order = orderMap.get(commonCodeEntity.getId());
if (order != null) {
commonCodeEntity.updateOrder(order);
}
});
}
private List<CommonCodeEntity> findAllByIds(Set<Long> ids) {
return queryFactory
.selectFrom(commonCodeEntity)
.where(
commonCodeEntity.id.in(ids),
commonCodeEntity.deleted.isFalse()
)
.fetch();
.selectFrom(commonCodeEntity)
.where(commonCodeEntity.id.in(ids), commonCodeEntity.deleted.isFalse())
.fetch();
}
}

View File

@@ -3,4 +3,5 @@ package com.kamco.cd.kamcoback.postgres.repository.log;
import com.kamco.cd.kamcoback.postgres.entity.AuditLogEntity;
import org.springframework.data.jpa.repository.JpaRepository;
public interface AuditLogRepository extends JpaRepository<AuditLogEntity, Long>, AuditLogRepositoryCustom {}
public interface AuditLogRepository
extends JpaRepository<AuditLogEntity, Long>, AuditLogRepositoryCustom {}

View File

@@ -1,21 +1,26 @@
package com.kamco.cd.kamcoback.postgres.repository.log;
import com.kamco.cd.kamcoback.log.dto.AuditLogDto;
import org.springframework.data.domain.Page;
import java.time.LocalDate;
import org.springframework.data.domain.Page;
public interface AuditLogRepositoryCustom {
Page<AuditLogDto.AuditList> findLogByDaily(AuditLogDto.DailySearchReq searchReq, LocalDate startDate, LocalDate endDate);
Page<AuditLogDto.AuditList> findLogByDaily(
AuditLogDto.DailySearchReq searchReq, LocalDate startDate, LocalDate endDate);
Page<AuditLogDto.AuditList> findLogByMenu(AuditLogDto.MenuUserSearchReq searchReq, String searchValue);
Page<AuditLogDto.AuditList> findLogByMenu(
AuditLogDto.MenuUserSearchReq searchReq, String searchValue);
Page<AuditLogDto.AuditList> findLogByAccount(AuditLogDto.MenuUserSearchReq searchReq, String searchValue);
Page<AuditLogDto.AuditList> findLogByAccount(
AuditLogDto.MenuUserSearchReq searchReq, String searchValue);
Page<AuditLogDto.AuditDetail> findLogByDailyResult(AuditLogDto.DailySearchReq searchReq, LocalDate logDate);
Page<AuditLogDto.AuditDetail> findLogByDailyResult(
AuditLogDto.DailySearchReq searchReq, LocalDate logDate);
Page<AuditLogDto.AuditDetail> findLogByMenuResult(AuditLogDto.MenuUserSearchReq searchReq, String menuId);
Page<AuditLogDto.AuditDetail> findLogByMenuResult(
AuditLogDto.MenuUserSearchReq searchReq, String menuId);
Page<AuditLogDto.AuditDetail> findLogByAccountResult(AuditLogDto.MenuUserSearchReq searchReq, Long accountId);
Page<AuditLogDto.AuditDetail> findLogByAccountResult(
AuditLogDto.MenuUserSearchReq searchReq, Long accountId);
}

View File

@@ -1,33 +1,32 @@
package com.kamco.cd.kamcoback.postgres.repository.log;
import static com.kamco.cd.kamcoback.postgres.entity.QAuditLogEntity.auditLogEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QErrorLogEntity.errorLogEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QMenuEntity.menuEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QUserEntity.userEntity;
import com.kamco.cd.kamcoback.log.dto.AuditLogDto;
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.types.Projections;
import com.querydsl.core.types.dsl.*;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import io.micrometer.common.util.StringUtils;
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 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 static com.kamco.cd.kamcoback.postgres.entity.QUserEntity.userEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QAuditLogEntity.auditLogEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QErrorLogEntity.errorLogEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QMenuEntity.menuEntity;
import com.kamco.cd.kamcoback.postgres.entity.QMenuEntity;
public class AuditLogRepositoryImpl extends QuerydslRepositorySupport implements AuditLogRepositoryCustom {
public class AuditLogRepositoryImpl extends QuerydslRepositorySupport
implements AuditLogRepositoryCustom {
private final JPAQueryFactory queryFactory;
private final StringExpression NULL_STRING = Expressions.stringTemplate("cast(null as text)");
@@ -37,304 +36,311 @@ public class AuditLogRepositoryImpl extends QuerydslRepositorySupport implements
}
@Override
public Page<AuditLogDto.AuditList> findLogByDaily(AuditLogDto.DailySearchReq searchReq, LocalDate startDate, LocalDate endDate) {
public Page<AuditLogDto.AuditList> findLogByDaily(
AuditLogDto.DailySearchReq searchReq, LocalDate startDate, LocalDate endDate) {
DateTimeExpression<LocalDateTime> groupDateTime =
Expressions.dateTimeTemplate(LocalDateTime.class, "date_trunc('day', {0})", auditLogEntity.createdDate);
Expressions.dateTimeTemplate(
LocalDateTime.class, "date_trunc('day', {0})", auditLogEntity.createdDate);
Pageable pageable = searchReq.toPageable();
List<AuditLogDto.AuditList> foundContent = queryFactory
.select(
Projections.constructor(
AuditLogDto.AuditList.class,
groupDateTime.as("baseDate"),
readCount().as("readCount"),
cudCount().as("cudCount"),
printCount().as("printCount"),
downloadCount().as("downloadCount"),
auditLogEntity.count().as("totalCount")
)
)
.from(auditLogEntity)
.where(
eventEndedAtBetween(startDate, endDate)
)
.groupBy(groupDateTime)
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.orderBy(groupDateTime.desc())
.fetch();
List<AuditLogDto.AuditList> foundContent =
queryFactory
.select(
Projections.constructor(
AuditLogDto.AuditList.class,
groupDateTime.as("baseDate"),
readCount().as("readCount"),
cudCount().as("cudCount"),
printCount().as("printCount"),
downloadCount().as("downloadCount"),
auditLogEntity.count().as("totalCount")))
.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();
Long countQuery =
queryFactory
.select(groupDateTime.countDistinct())
.from(auditLogEntity)
.where(eventEndedAtBetween(startDate, endDate))
.fetchOne();
return new PageImpl<>(foundContent, pageable, countQuery);
}
@Override
public Page<AuditLogDto.AuditList> findLogByMenu(AuditLogDto.MenuUserSearchReq searchReq, String searchValue) {
public Page<AuditLogDto.AuditList> findLogByMenu(
AuditLogDto.MenuUserSearchReq searchReq, String searchValue) {
Pageable pageable = searchReq.toPageable();
List<AuditLogDto.AuditList> foundContent = queryFactory
.select(
Projections.constructor(
AuditLogDto.AuditList.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();
List<AuditLogDto.AuditList> foundContent =
queryFactory
.select(
Projections.constructor(
AuditLogDto.AuditList.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();
Long countQuery =
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<AuditLogDto.AuditList> findLogByAccount(AuditLogDto.MenuUserSearchReq searchReq, String searchValue) {
public Page<AuditLogDto.AuditList> findLogByAccount(
AuditLogDto.MenuUserSearchReq searchReq, String searchValue) {
Pageable pageable = searchReq.toPageable();
List<AuditLogDto.AuditList> foundContent = queryFactory
.select(
Projections.constructor(
AuditLogDto.AuditList.class,
auditLogEntity.userUid.as("accountId"),
userEntity.userId.as("loginId"),
userEntity.userNm.as("username"),
readCount().as("readCount"),
cudCount().as("cudCount"),
printCount().as("printCount"),
downloadCount().as("downloadCount"),
auditLogEntity.count().as("totalCount")
)
)
.from(auditLogEntity)
.leftJoin(userEntity).on(auditLogEntity.userUid.eq(userEntity.id))
.where(
loginIdOrUsernameContains(searchValue)
)
.groupBy(auditLogEntity.userUid, userEntity.userId, userEntity.userNm)
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
// .orderBy(auditLogEntity.eventEndedAt.max().desc())
.fetch();
List<AuditLogDto.AuditList> foundContent =
queryFactory
.select(
Projections.constructor(
AuditLogDto.AuditList.class,
auditLogEntity.userUid.as("accountId"),
userEntity.userId.as("loginId"),
userEntity.userNm.as("username"),
readCount().as("readCount"),
cudCount().as("cudCount"),
printCount().as("printCount"),
downloadCount().as("downloadCount"),
auditLogEntity.count().as("totalCount")))
.from(auditLogEntity)
.leftJoin(userEntity)
.on(auditLogEntity.userUid.eq(userEntity.id))
.where(loginIdOrUsernameContains(searchValue))
.groupBy(auditLogEntity.userUid, userEntity.userId, userEntity.userNm)
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
// .orderBy(auditLogEntity.eventEndedAt.max().desc())
.fetch();
Long countQuery = queryFactory
.select(auditLogEntity.userUid.countDistinct())
.from(auditLogEntity)
.leftJoin(userEntity).on(auditLogEntity.userUid.eq(userEntity.id))
.where(loginIdOrUsernameContains(searchValue))
.fetchOne();
Long countQuery =
queryFactory
.select(auditLogEntity.userUid.countDistinct())
.from(auditLogEntity)
.leftJoin(userEntity)
.on(auditLogEntity.userUid.eq(userEntity.id))
.where(loginIdOrUsernameContains(searchValue))
.fetchOne();
return new PageImpl<>(foundContent, pageable, countQuery);
}
@Override
public Page<AuditLogDto.AuditDetail> findLogByDailyResult(AuditLogDto.DailySearchReq searchReq, LocalDate logDate) {
public Page<AuditLogDto.AuditDetail> findLogByDailyResult(
AuditLogDto.DailySearchReq 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<AuditLogDto.AuditDetail> foundContent = queryFactory
.select(
Projections.constructor(
AuditLogDto.AuditDetail.class,
auditLogEntity.id.as("logId"),
userEntity.userNm.as("userName"),
userEntity.userId.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(userEntity).on(auditLogEntity.userUid.eq(userEntity.id))
.where(
eventEndedAtEqDate(logDate)
)
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.orderBy(auditLogEntity.createdDate.desc())
.fetch();
List<AuditLogDto.AuditDetail> foundContent =
queryFactory
.select(
Projections.constructor(
AuditLogDto.AuditDetail.class,
auditLogEntity.id.as("logId"),
userEntity.userNm.as("userName"),
userEntity.userId.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(userEntity)
.on(auditLogEntity.userUid.eq(userEntity.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(userEntity).on(auditLogEntity.userUid.eq(userEntity.id))
.where(
eventEndedAtEqDate(logDate)
)
.fetchOne();
Long countQuery =
queryFactory
.select(auditLogEntity.id.countDistinct())
.from(auditLogEntity)
.leftJoin(menuEntity)
.on(auditLogEntity.menuUid.eq(menuEntity.menuUid))
.leftJoin(menuEntity.parent, parent)
.leftJoin(userEntity)
.on(auditLogEntity.userUid.eq(userEntity.id))
.where(eventEndedAtEqDate(logDate))
.fetchOne();
return new PageImpl<>(foundContent, pageable, countQuery);
}
@Override
public Page<AuditLogDto.AuditDetail> findLogByMenuResult(AuditLogDto.MenuUserSearchReq searchReq, String menuUid) {
public Page<AuditLogDto.AuditDetail> findLogByMenuResult(
AuditLogDto.MenuUserSearchReq 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<AuditLogDto.AuditDetail> foundContent = queryFactory
.select(
Projections.constructor(
AuditLogDto.AuditDetail.class,
auditLogEntity.id.as("logId"),
auditLogEntity.createdDate.as("logDateTime"),
userEntity.userNm.as("userName"),
userEntity.userId.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(userEntity).on(auditLogEntity.userUid.eq(userEntity.id))
.where(
menuUidEq(menuUid)
)
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.orderBy(auditLogEntity.createdDate.desc())
.fetch();
List<AuditLogDto.AuditDetail> foundContent =
queryFactory
.select(
Projections.constructor(
AuditLogDto.AuditDetail.class,
auditLogEntity.id.as("logId"),
auditLogEntity.createdDate.as("logDateTime"),
userEntity.userNm.as("userName"),
userEntity.userId.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(userEntity)
.on(auditLogEntity.userUid.eq(userEntity.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(userEntity).on(auditLogEntity.userUid.eq(userEntity.id))
.where(
menuUidEq(menuUid)
).fetchOne();
Long countQuery =
queryFactory
.select(auditLogEntity.id.countDistinct())
.from(auditLogEntity)
.leftJoin(menuEntity)
.on(auditLogEntity.menuUid.eq(menuEntity.menuUid))
.leftJoin(menuEntity.parent, parent)
.leftJoin(userEntity)
.on(auditLogEntity.userUid.eq(userEntity.id))
.where(menuUidEq(menuUid))
.fetchOne();
return new PageImpl<>(foundContent, pageable, countQuery);
}
@Override
public Page<AuditLogDto.AuditDetail> findLogByAccountResult(AuditLogDto.MenuUserSearchReq searchReq, Long userUid) {
public Page<AuditLogDto.AuditDetail> findLogByAccountResult(
AuditLogDto.MenuUserSearchReq 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<AuditLogDto.AuditDetail> foundContent = queryFactory
.select(
Projections.constructor(
AuditLogDto.AuditDetail.class,
auditLogEntity.id.as("logId"),
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(userEntity).on(auditLogEntity.userUid.eq(userEntity.id))
.where(
userUidEq(userUid)
)
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.orderBy(auditLogEntity.createdDate.desc())
.fetch();
List<AuditLogDto.AuditDetail> foundContent =
queryFactory
.select(
Projections.constructor(
AuditLogDto.AuditDetail.class,
auditLogEntity.id.as("logId"),
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(userEntity)
.on(auditLogEntity.userUid.eq(userEntity.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(userEntity).on(auditLogEntity.userUid.eq(userEntity.id))
.where(
userUidEq(userUid)
)
.fetchOne();
Long countQuery =
queryFactory
.select(auditLogEntity.id.countDistinct())
.from(auditLogEntity)
.leftJoin(menuEntity)
.on(auditLogEntity.menuUid.eq(menuEntity.menuUid))
.leftJoin(menuEntity.parent, parent)
.leftJoin(userEntity)
.on(auditLogEntity.userUid.eq(userEntity.id))
.where(userUidEq(userUid))
.fetchOne();
return new PageImpl<>(foundContent, pageable, countQuery);
}
@@ -345,8 +351,10 @@ public class AuditLogRepositoryImpl extends QuerydslRepositorySupport implements
}
LocalDateTime startDateTime = startDate.atStartOfDay();
LocalDateTime endDateTime = endDate.plusDays(1).atStartOfDay();
return auditLogEntity.createdDate.goe(ZonedDateTime.from(startDateTime))
.and(auditLogEntity.createdDate.lt(ZonedDateTime.from(endDateTime)));
return auditLogEntity
.createdDate
.goe(ZonedDateTime.from(startDateTime))
.and(auditLogEntity.createdDate.lt(ZonedDateTime.from(endDateTime)));
}
private BooleanExpression menuNameEquals(String searchValue) {
@@ -383,7 +391,8 @@ public class AuditLogRepositoryImpl extends QuerydslRepositorySupport implements
private BooleanExpression eventEndedAtEqDate(LocalDate logDate) {
DateTimeExpression<LocalDateTime> eventEndedDate =
Expressions.dateTimeTemplate(LocalDateTime.class, "date_trunc('day', {0})", auditLogEntity.createdDate);
Expressions.dateTimeTemplate(
LocalDateTime.class, "date_trunc('day', {0})", auditLogEntity.createdDate);
LocalDateTime comparisonDate = logDate.atStartOfDay();
return eventEndedDate.eq(comparisonDate);
@@ -399,29 +408,33 @@ public class AuditLogRepositoryImpl extends QuerydslRepositorySupport implements
private NumberExpression<Integer> 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<Integer> 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<Integer> 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<Integer> 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();
}
}

View File

@@ -3,4 +3,5 @@ package com.kamco.cd.kamcoback.postgres.repository.log;
import com.kamco.cd.kamcoback.postgres.entity.ErrorLogEntity;
import org.springframework.data.jpa.repository.JpaRepository;
public interface ErrorLogRepository extends JpaRepository<ErrorLogEntity, Long>, ErrorLogRepositoryCustom {}
public interface ErrorLogRepository
extends JpaRepository<ErrorLogEntity, Long>, ErrorLogRepositoryCustom {}

View File

@@ -1,12 +1,8 @@
package com.kamco.cd.kamcoback.postgres.repository.log;
import com.kamco.cd.kamcoback.log.dto.AuditLogDto;
import com.kamco.cd.kamcoback.log.dto.ErrorLogDto;
import com.kamco.cd.kamcoback.postgres.entity.AuditLogEntity;
import org.springframework.data.domain.Page;
import java.time.LocalDate;
public interface ErrorLogRepositoryCustom {
public Page<ErrorLogDto.Basic> findLogByError(ErrorLogDto.ErrorSearchReq searchReq);
}

View File

@@ -1,5 +1,10 @@
package com.kamco.cd.kamcoback.postgres.repository.log;
import static com.kamco.cd.kamcoback.postgres.entity.QAuditLogEntity.auditLogEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QErrorLogEntity.errorLogEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QMenuEntity.menuEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QUserEntity.userEntity;
import com.kamco.cd.kamcoback.log.dto.ErrorLogDto;
import com.kamco.cd.kamcoback.log.dto.EventStatus;
import com.kamco.cd.kamcoback.log.dto.EventType;
@@ -9,23 +14,18 @@ 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 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 static com.kamco.cd.kamcoback.postgres.entity.QAuditLogEntity.auditLogEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QErrorLogEntity.errorLogEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QMenuEntity.menuEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QUserEntity.userEntity;
public class ErrorLogRepositoryImpl extends QuerydslRepositorySupport implements ErrorLogRepositoryCustom {
public class ErrorLogRepositoryImpl extends QuerydslRepositorySupport
implements ErrorLogRepositoryCustom {
private final JPAQueryFactory queryFactory;
private final StringExpression NULL_STRING = Expressions.stringTemplate("cast(null as text)");
@@ -37,52 +37,57 @@ public class ErrorLogRepositoryImpl extends QuerydslRepositorySupport implements
@Override
public Page<ErrorLogDto.Basic> findLogByError(ErrorLogDto.ErrorSearchReq searchReq) {
Pageable pageable = searchReq.toPageable();
List<ErrorLogDto.Basic> foundContent = queryFactory
.select(
Projections.constructor(
ErrorLogDto.Basic.class,
errorLogEntity.id.as("logId"),
Expressions.constant("한국자산관리공사"), //serviceName
menuEntity.menuNm.as("menuName"),
userEntity.userId.as("loginId"),
userEntity.userNm.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"),
errorLogEntity.createdDate
)
)
.from(errorLogEntity)
.leftJoin(auditLogEntity).on(errorLogEntity.id.eq(auditLogEntity.errorLogUid))
.leftJoin(menuEntity).on(auditLogEntity.menuUid.eq(menuEntity.menuUid))
.leftJoin(userEntity).on(errorLogEntity.handlerUid.eq(userEntity.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();
List<ErrorLogDto.Basic> foundContent =
queryFactory
.select(
Projections.constructor(
ErrorLogDto.Basic.class,
errorLogEntity.id.as("logId"),
Expressions.constant("한국자산관리공사"), // serviceName
menuEntity.menuNm.as("menuName"),
userEntity.userId.as("loginId"),
userEntity.userNm.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"),
errorLogEntity.createdDate))
.from(errorLogEntity)
.leftJoin(auditLogEntity)
.on(errorLogEntity.id.eq(auditLogEntity.errorLogUid))
.leftJoin(menuEntity)
.on(auditLogEntity.menuUid.eq(menuEntity.menuUid))
.leftJoin(userEntity)
.on(errorLogEntity.handlerUid.eq(userEntity.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(userEntity).on(errorLogEntity.handlerUid.eq(userEntity.id))
.where(
eventStatusEqFailed(),
eventEndedAtBetween(searchReq.getStartDate(), searchReq.getEndDate()),
eventTypeEq(searchReq.getEventType()),
errorLevelEq(searchReq.getErrorLevel())
)
.fetchOne();
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(userEntity)
.on(errorLogEntity.handlerUid.eq(userEntity.id))
.where(
eventStatusEqFailed(),
eventEndedAtBetween(searchReq.getStartDate(), searchReq.getEndDate()),
eventTypeEq(searchReq.getEventType()),
errorLevelEq(searchReq.getErrorLevel()))
.fetchOne();
return new PageImpl<>(foundContent, pageable, countQuery);
}
@@ -93,8 +98,10 @@ public class ErrorLogRepositoryImpl extends QuerydslRepositorySupport implements
}
LocalDateTime startDateTime = startDate.atStartOfDay();
LocalDateTime endDateTime = endDate.plusDays(1).atStartOfDay();
return auditLogEntity.createdDate.goe(ZonedDateTime.from(startDateTime))
.and(auditLogEntity.createdDate.lt(ZonedDateTime.from(endDateTime)));
return auditLogEntity
.createdDate
.goe(ZonedDateTime.from(startDateTime))
.and(auditLogEntity.createdDate.lt(ZonedDateTime.from(endDateTime)));
}
private BooleanExpression eventStatusEqFailed() {