해당 게시글은 개인 프로젝트인 "광고 관리 플랫폼 대행사 센터 제작" 중
#110 "광고 관리 페이지 (캠페인 리스트) 수정 및 통계 기능 구현" 이슈를 다루고 있습니다.
Projections.fields
를 통해 필드에 직접 값을 주입하는 방식 선택 public List<PerformanceStatisticsDto> findByClientUser_IdAndStatisticsDefault(@Param("id") String clientId,
@Param("startDate") LocalDate startDate,
@Param("lastDate") LocalDate lastDate
) {
List<PerformanceStatisticsDto> results = jpaQueryFactory
.select(Projections.fields(PerformanceStatisticsDto.class,
campaign.id.as("campaignId"),
campaign.name.as("name"),
campaign.budget.as("budget"),
campaign.deleted.as("deleted"),
performance.view.sum().as("view"),
performance.click.sum().as("click"),
performance.conversion.sum().as("conversion"),
performance.purchase.sum().as("purchase"),
performance.spend.sum().as("spend")
))
.from(performance)
.leftJoin(performance.creative, creative)
.leftJoin(creative.campaign, campaign)
.leftJoin(campaign.clientUser, clientUser)
.where(
performance.createdAt.between(startDate, lastDate),
clientUser.userId.eq(clientId),
campaign.deleted.eq(false)
)
.groupBy(campaign.id)
.fetch();
for (PerformanceStatisticsDto result : results) {
Long spend = result.getSpend();
Long view = result.getView();
Long click = result.getClick();
Long conversion = result.getConversion();
Long purchase = result.getPurchase();
result.setCampaignIndicator(spend, view, click, conversion, purchase);
}
return results;
}
public List<PerformanceStatisticsDto> findByClientUser_IdAndTotalStatisticsDefault(@Param("id") String clientId,
@Param("startDate") LocalDate startDate,
@Param("lastDate") LocalDate lastDate
) {
List<PerformanceStatisticsDto> results = jpaQueryFactory
.select(Projections.fields(PerformanceStatisticsDto.class,
performance.view.sum().as("view"),
performance.click.sum().as("click"),
performance.conversion.sum().as("conversion"),
performance.purchase.sum().as("purchase"),
performance.spend.sum().as("spend")
))
.from(performance)
.leftJoin(performance.creative, creative)
.leftJoin(creative.campaign, campaign)
.leftJoin(campaign.clientUser, clientUser)
.where(
performance.createdAt.between(startDate, lastDate),
clientUser.userId.eq(clientId),
campaign.deleted.eq(false)
)
.groupBy(clientUser.userId)
.fetch();
for (PerformanceStatisticsDto result : results) {
Long spend = result.getSpend();
Long view = result.getView();
Long click = result.getClick();
Long conversion = result.getConversion();
Long purchase = result.getPurchase();
result.setTotalIndicator(spend, view, click, conversion, purchase);
}
return results;
}