From a45a31ac0830408f0aa5a70e56ce5a4ef397ff8e Mon Sep 17 00:00:00 2001 From: Hoang-Nguyen-Huy Date: Mon, 28 Oct 2024 22:52:15 +0700 Subject: [PATCH 1/6] =?UTF-8?q?[PBS-65][HoangHN]=20refactor:=20?= =?UTF-8?q?=F0=9F=90=BC=20change=20the=20formate=20of=20the=20date?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/swp/PodBookingSystem/controller/AccountController.java | 2 +- .../com/swp/PodBookingSystem/controller/OrderController.java | 2 +- .../swp/PodBookingSystem/controller/OrderDetailController.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/swp/PodBookingSystem/controller/AccountController.java b/src/main/java/com/swp/PodBookingSystem/controller/AccountController.java index a834bc9e..d262a980 100644 --- a/src/main/java/com/swp/PodBookingSystem/controller/AccountController.java +++ b/src/main/java/com/swp/PodBookingSystem/controller/AccountController.java @@ -148,7 +148,7 @@ ApiResponse countCurrentCustomer() { ApiResponse countCustomer(@RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime) { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy'T'hh:mm'T'a"); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy'T'HH:mm"); LocalDateTime start = startTime != null ? LocalDateTime.parse(startTime, formatter) : null; LocalDateTime end = endTime != null ? LocalDateTime.parse(endTime, formatter) : null; diff --git a/src/main/java/com/swp/PodBookingSystem/controller/OrderController.java b/src/main/java/com/swp/PodBookingSystem/controller/OrderController.java index 4a7c6375..373f9ffa 100644 --- a/src/main/java/com/swp/PodBookingSystem/controller/OrderController.java +++ b/src/main/java/com/swp/PodBookingSystem/controller/OrderController.java @@ -151,7 +151,7 @@ ApiResponse countOrder( @RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime) { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy'T'hh:mm'T'a"); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy'T'HH:mm"); LocalDateTime start = startTime != null ? LocalDateTime.parse(startTime, formatter) : null; LocalDateTime end = endTime != null ? LocalDateTime.parse(endTime, formatter) : null; diff --git a/src/main/java/com/swp/PodBookingSystem/controller/OrderDetailController.java b/src/main/java/com/swp/PodBookingSystem/controller/OrderDetailController.java index 51a62ba6..798437bd 100644 --- a/src/main/java/com/swp/PodBookingSystem/controller/OrderDetailController.java +++ b/src/main/java/com/swp/PodBookingSystem/controller/OrderDetailController.java @@ -96,7 +96,7 @@ ApiResponse getRevenueCurrentDay() { ApiResponse getRevenue(@RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime) { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy'T'hh:mm'T'a"); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy'T'HH:mm"); LocalDateTime start = startTime != null ? LocalDateTime.parse(startTime, formatter) : null; LocalDateTime end = endTime != null ? LocalDateTime.parse(endTime, formatter) : null; From 2baa3eee327340cd1f60d2eab4da7515554d237e Mon Sep 17 00:00:00 2001 From: Hoang-Nguyen-Huy Date: Mon, 28 Oct 2024 23:02:54 +0700 Subject: [PATCH 2/6] =?UTF-8?q?[PBS-65][HoangHN]=20fix:=20=F0=9F=90=A8=20f?= =?UTF-8?q?ix=20null=20double=20response?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/OrderDetailRepository.java | 2 +- .../swp/PodBookingSystem/service/OrderDetailService.java | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/swp/PodBookingSystem/repository/OrderDetailRepository.java b/src/main/java/com/swp/PodBookingSystem/repository/OrderDetailRepository.java index a86ae961..0b4226bb 100644 --- a/src/main/java/com/swp/PodBookingSystem/repository/OrderDetailRepository.java +++ b/src/main/java/com/swp/PodBookingSystem/repository/OrderDetailRepository.java @@ -102,7 +102,7 @@ Page findOrdersByBuildingNumberAndTimeRange( "ON od.id = amenityTotal.orderDetailId " + "WHERE od.startTime >= :startTime AND od.endTime <= :endTime " + "AND od.status = com.swp.PodBookingSystem.enums.OrderStatus.Successfully") - Double calculateRevenueBetweenDateTime(@Param("startTime") LocalDateTime startTime, + Optional calculateRevenueBetweenDateTime(@Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime); @Query("SELECT NEW com.swp.PodBookingSystem.dto.respone.OrderDetail.RevenueByMonthDto(" + diff --git a/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java b/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java index f20b2c06..a383dfb1 100644 --- a/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java +++ b/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java @@ -430,13 +430,7 @@ public double calculateRevenueCurrentDay() { [GET]: /order-detail/revenue? */ public double calculateRevenue(LocalDateTime startTime, LocalDateTime endTime) { - if (startTime == null) { - startTime = LocalDate.now().atStartOfDay(); - } - if (endTime == null) { - endTime = LocalDate.now().atTime(LocalTime.MAX); - } - return orderDetailRepository.calculateRevenueBetweenDateTime(startTime, endTime); + return orderDetailRepository.calculateRevenueBetweenDateTime(startTime, endTime).orElse(0.0); } /* From 30b64e84b1ca70cbfa0015fac5683c09cf63a640 Mon Sep 17 00:00:00 2001 From: Hoang-Nguyen-Huy Date: Mon, 28 Oct 2024 23:49:07 +0700 Subject: [PATCH 3/6] =?UTF-8?q?[PBS-65][HoangHN]=20feat:=20=F0=9F=90=AF=20?= =?UTF-8?q?calculate=20revenue=20by=20day,=20month,=20quarter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/OrderDetailController.java | 20 +++++---- ...ueByMonthDto.java => RevenueChartDto.java} | 2 +- .../repository/OrderDetailRepository.java | 42 +++++++++++++++---- .../service/OrderDetailService.java | 19 +++++++-- 4 files changed, 65 insertions(+), 18 deletions(-) rename src/main/java/com/swp/PodBookingSystem/dto/respone/OrderDetail/{RevenueByMonthDto.java => RevenueChartDto.java} (88%) diff --git a/src/main/java/com/swp/PodBookingSystem/controller/OrderDetailController.java b/src/main/java/com/swp/PodBookingSystem/controller/OrderDetailController.java index 798437bd..a3898ef7 100644 --- a/src/main/java/com/swp/PodBookingSystem/controller/OrderDetailController.java +++ b/src/main/java/com/swp/PodBookingSystem/controller/OrderDetailController.java @@ -4,7 +4,7 @@ import com.swp.PodBookingSystem.dto.respone.Order.NumberOrderByBuildingDto; import com.swp.PodBookingSystem.dto.respone.OrderDetail.OrderDetailFullInfoResponse; import com.swp.PodBookingSystem.dto.respone.OrderDetail.OrderDetailResponse; -import com.swp.PodBookingSystem.dto.respone.OrderDetail.RevenueByMonthDto; +import com.swp.PodBookingSystem.dto.respone.OrderDetail.RevenueChartDto; import com.swp.PodBookingSystem.dto.respone.PaginationResponse; import com.swp.PodBookingSystem.service.OrderDetailService; import lombok.AccessLevel; @@ -14,7 +14,6 @@ import com.swp.PodBookingSystem.dto.respone.ApiResponse; import org.springframework.data.domain.Page; -import org.springframework.format.annotation.DateTimeFormat; import org.springframework.http.HttpStatus; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.bind.annotation.*; @@ -106,11 +105,18 @@ ApiResponse getRevenue(@RequestParam(required = false) String startTime, .build(); } - @GetMapping("/revenue-by-month") - ApiResponse> getRevenueByMonth() { - return ApiResponse.>builder() - .message("Doanh thu các tháng năm hiện tại") - .data(orderDetailService.calculateRevenueByMonth()) + @GetMapping("/revenue-chart") + ApiResponse> getRevenueChart(@RequestParam(required = false) String startTime, + @RequestParam(required = false) String endTime, + @RequestParam(required = false) String viewWith) { + + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy'T'HH:mm"); + LocalDateTime start = startTime != null ? LocalDateTime.parse(startTime, formatter) : null; + LocalDateTime end = endTime != null ? LocalDateTime.parse(endTime, formatter) : null; + + return ApiResponse.>builder() + .message("Doanh thu theo " + (viewWith != null ? viewWith : "ngày")) + .data(orderDetailService.calculateRevenueByMonth(start, end, viewWith)) .build(); } diff --git a/src/main/java/com/swp/PodBookingSystem/dto/respone/OrderDetail/RevenueByMonthDto.java b/src/main/java/com/swp/PodBookingSystem/dto/respone/OrderDetail/RevenueChartDto.java similarity index 88% rename from src/main/java/com/swp/PodBookingSystem/dto/respone/OrderDetail/RevenueByMonthDto.java rename to src/main/java/com/swp/PodBookingSystem/dto/respone/OrderDetail/RevenueChartDto.java index 44865edb..475a743b 100644 --- a/src/main/java/com/swp/PodBookingSystem/dto/respone/OrderDetail/RevenueByMonthDto.java +++ b/src/main/java/com/swp/PodBookingSystem/dto/respone/OrderDetail/RevenueChartDto.java @@ -8,7 +8,7 @@ @AllArgsConstructor @Builder @FieldDefaults(level = AccessLevel.PRIVATE) -public class RevenueByMonthDto { +public class RevenueChartDto { String date; Double revenue; } diff --git a/src/main/java/com/swp/PodBookingSystem/repository/OrderDetailRepository.java b/src/main/java/com/swp/PodBookingSystem/repository/OrderDetailRepository.java index 0b4226bb..5383f3d5 100644 --- a/src/main/java/com/swp/PodBookingSystem/repository/OrderDetailRepository.java +++ b/src/main/java/com/swp/PodBookingSystem/repository/OrderDetailRepository.java @@ -1,7 +1,7 @@ package com.swp.PodBookingSystem.repository; import com.swp.PodBookingSystem.dto.respone.Order.NumberOrderByBuildingDto; -import com.swp.PodBookingSystem.dto.respone.OrderDetail.RevenueByMonthDto; +import com.swp.PodBookingSystem.dto.respone.OrderDetail.RevenueChartDto; import com.swp.PodBookingSystem.entity.OrderDetail; import com.swp.PodBookingSystem.enums.OrderStatus; import org.springframework.data.domain.Page; @@ -105,20 +105,48 @@ Page findOrdersByBuildingNumberAndTimeRange( Optional calculateRevenueBetweenDateTime(@Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime); - @Query("SELECT NEW com.swp.PodBookingSystem.dto.respone.OrderDetail.RevenueByMonthDto(" + + @Query("SELECT NEW com.swp.PodBookingSystem.dto.respone.OrderDetail.RevenueChartDto(" + + "CONCAT(YEAR(:startTime), '-', LPAD(CAST(MONTH(:startTime) AS string), 2, '0'), '-', LPAD(CAST(DAY(:startTime) AS string), 2, '0')), " + + "SUM((od.priceRoom + COALESCE(amenityTotal.totalAmenityPrice, 0)) * " + + "(1 - COALESCE(od.discountPercentage, 0) / 100.0) * (1 - COALESCE(sp.discountPercentage, 0) / 100.0))) " + + "FROM OrderDetail od " + + "LEFT JOIN od.servicePackage sp " + + "LEFT JOIN (SELECT oda.orderDetail.id as orderDetailId, SUM(oda.price * oda.quantity) as totalAmenityPrice " + + " FROM OrderDetailAmenity oda GROUP BY oda.orderDetail.id) amenityTotal " + + "ON od.id = amenityTotal.orderDetailId " + + "WHERE DATE(od.startTime) = DATE(:startTime) " + + "AND od.status = com.swp.PodBookingSystem.enums.OrderStatus.Successfully") + RevenueChartDto calculateRevenueForSingleDay(@Param("startTime") LocalDateTime startTime); + + @Query("SELECT NEW com.swp.PodBookingSystem.dto.respone.OrderDetail.RevenueChartDto(" + "CONCAT(YEAR(MIN(od.startTime)), '-', LPAD(CAST(MONTH(MIN(od.startTime)) AS string), 2, '0'), '-01'), " + "SUM((od.priceRoom + COALESCE(amenityTotal.totalAmenityPrice, 0)) * " + - "(1 - COALESCE(od.discountPercentage, 0) / 100.0) * " + - "(1 - COALESCE(sp.discountPercentage, 0) / 100.0))) " + + "(1 - COALESCE(od.discountPercentage, 0) / 100.0) * (1 - COALESCE(sp.discountPercentage, 0) / 100.0))) " + + "FROM OrderDetail od " + + "LEFT JOIN od.servicePackage sp " + + "LEFT JOIN (SELECT oda.orderDetail.id as orderDetailId, SUM(oda.price * oda.quantity) as totalAmenityPrice " + + " FROM OrderDetailAmenity oda GROUP BY oda.orderDetail.id) amenityTotal " + + "ON od.id = amenityTotal.orderDetailId " + + "WHERE od.startTime BETWEEN :startTime AND :endTime " + + "AND od.status = com.swp.PodBookingSystem.enums.OrderStatus.Successfully " + + "GROUP BY YEAR(od.startTime), MONTH(od.startTime) " + + "ORDER BY YEAR(od.startTime), MONTH(od.startTime)") + List calculateRevenueByMonth(@Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime); + + @Query("SELECT NEW com.swp.PodBookingSystem.dto.respone.OrderDetail.RevenueChartDto(" + + "CONCAT(YEAR(MIN(od.startTime)), '-Q', CEILING(MONTH(MIN(od.startTime)) / 3.0)), " + + "SUM((od.priceRoom + COALESCE(amenityTotal.totalAmenityPrice, 0)) * " + + "(1 - COALESCE(od.discountPercentage, 0) / 100.0) * (1 - COALESCE(sp.discountPercentage, 0) / 100.0))) " + "FROM OrderDetail od " + "LEFT JOIN od.servicePackage sp " + "LEFT JOIN (SELECT oda.orderDetail.id as orderDetailId, SUM(oda.price * oda.quantity) as totalAmenityPrice " + " FROM OrderDetailAmenity oda GROUP BY oda.orderDetail.id) amenityTotal " + "ON od.id = amenityTotal.orderDetailId " + - "WHERE FUNCTION('YEAR', od.startTime) = FUNCTION('YEAR', CURRENT_DATE) " + + "WHERE od.startTime BETWEEN :startTime AND :endTime " + "AND od.status = com.swp.PodBookingSystem.enums.OrderStatus.Successfully " + - "GROUP BY YEAR(od.startTime), MONTH(od.startTime)") - List calculateRevenueByMonthForCurrentYear(); + "GROUP BY YEAR(od.startTime), CEILING(MONTH(od.startTime) / 3.0) " + + "ORDER BY YEAR(od.startTime), CEILING(MONTH(od.startTime) / 3.0)") + List calculateRevenueByQuarter(@Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime); @Query("SELECT NEW com.swp.PodBookingSystem.dto.respone.Order.NumberOrderByBuildingDto(" + "od.building.id, od.building.address, COUNT(DISTINCT od.order.id)" + diff --git a/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java b/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java index a383dfb1..2c351b5b 100644 --- a/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java +++ b/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java @@ -31,6 +31,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; +import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.UUID; @@ -434,10 +435,22 @@ public double calculateRevenue(LocalDateTime startTime, LocalDateTime endTime) { } /* - [GET]: /order-detail/revenue-by-month + [GET]: /order-detail/revenue-chart */ - public List calculateRevenueByMonth() { - return orderDetailRepository.calculateRevenueByMonthForCurrentYear(); + public List calculateRevenueByMonth(LocalDateTime startTime, LocalDateTime endTime, String viewWith) { + if (viewWith == null) { + return Collections.singletonList(orderDetailRepository.calculateRevenueForSingleDay(startTime)); + } + switch (viewWith.toLowerCase()) { + case "day": + return Collections.singletonList(orderDetailRepository.calculateRevenueForSingleDay(startTime)); + case "month": + return orderDetailRepository.calculateRevenueByMonth(startTime, endTime); + case "quarter": + return orderDetailRepository.calculateRevenueByQuarter(startTime, endTime); + default: + return Collections.singletonList(orderDetailRepository.calculateRevenueForSingleDay(startTime)); + } } /* From cf41e4ff28ec4ef114cee0f470e849ba4d766501 Mon Sep 17 00:00:00 2001 From: Hoang-Nguyen-Huy Date: Mon, 28 Oct 2024 23:58:46 +0700 Subject: [PATCH 4/6] =?UTF-8?q?[PBS-65][HoangHN]=20refactor:=20?= =?UTF-8?q?=F0=9F=A6=81=20calculate=20each=20day=20in=20month?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PodBookingSystem/repository/OrderDetailRepository.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/swp/PodBookingSystem/repository/OrderDetailRepository.java b/src/main/java/com/swp/PodBookingSystem/repository/OrderDetailRepository.java index 5383f3d5..67979d09 100644 --- a/src/main/java/com/swp/PodBookingSystem/repository/OrderDetailRepository.java +++ b/src/main/java/com/swp/PodBookingSystem/repository/OrderDetailRepository.java @@ -119,7 +119,7 @@ Optional calculateRevenueBetweenDateTime(@Param("startTime") LocalDateTi RevenueChartDto calculateRevenueForSingleDay(@Param("startTime") LocalDateTime startTime); @Query("SELECT NEW com.swp.PodBookingSystem.dto.respone.OrderDetail.RevenueChartDto(" + - "CONCAT(YEAR(MIN(od.startTime)), '-', LPAD(CAST(MONTH(MIN(od.startTime)) AS string), 2, '0'), '-01'), " + + "CONCAT(YEAR(od.startTime), '-', LPAD(CAST(MONTH(od.startTime) AS string), 2, '0'), '-', LPAD(CAST(DAY(od.startTime) AS string), 2, '0')), " + "SUM((od.priceRoom + COALESCE(amenityTotal.totalAmenityPrice, 0)) * " + "(1 - COALESCE(od.discountPercentage, 0) / 100.0) * (1 - COALESCE(sp.discountPercentage, 0) / 100.0))) " + "FROM OrderDetail od " + @@ -129,10 +129,11 @@ Optional calculateRevenueBetweenDateTime(@Param("startTime") LocalDateTi "ON od.id = amenityTotal.orderDetailId " + "WHERE od.startTime BETWEEN :startTime AND :endTime " + "AND od.status = com.swp.PodBookingSystem.enums.OrderStatus.Successfully " + - "GROUP BY YEAR(od.startTime), MONTH(od.startTime) " + - "ORDER BY YEAR(od.startTime), MONTH(od.startTime)") + "GROUP BY CONCAT(YEAR(od.startTime), '-', LPAD(CAST(MONTH(od.startTime) AS string), 2, '0'), '-', LPAD(CAST(DAY(od.startTime) AS string), 2, '0')) " + + "ORDER BY CONCAT(YEAR(od.startTime), '-', LPAD(CAST(MONTH(od.startTime) AS string), 2, '0'), '-', LPAD(CAST(DAY(od.startTime) AS string), 2, '0'))") List calculateRevenueByMonth(@Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime); + @Query("SELECT NEW com.swp.PodBookingSystem.dto.respone.OrderDetail.RevenueChartDto(" + "CONCAT(YEAR(MIN(od.startTime)), '-Q', CEILING(MONTH(MIN(od.startTime)) / 3.0)), " + "SUM((od.priceRoom + COALESCE(amenityTotal.totalAmenityPrice, 0)) * " + From abf1f364245f00cb47f82e6a38fa52cbb6b33f5c Mon Sep 17 00:00:00 2001 From: Hoang-Nguyen-Huy Date: Tue, 29 Oct 2024 10:51:42 +0700 Subject: [PATCH 5/6] =?UTF-8?q?[PBS-65][HoangHN]=20refactor:=20?= =?UTF-8?q?=F0=9F=90=AE=20calculate=20revenue=20within=20quarter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/OrderDetailRepository.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/swp/PodBookingSystem/repository/OrderDetailRepository.java b/src/main/java/com/swp/PodBookingSystem/repository/OrderDetailRepository.java index 67979d09..d15e2b62 100644 --- a/src/main/java/com/swp/PodBookingSystem/repository/OrderDetailRepository.java +++ b/src/main/java/com/swp/PodBookingSystem/repository/OrderDetailRepository.java @@ -135,9 +135,10 @@ Optional calculateRevenueBetweenDateTime(@Param("startTime") LocalDateTi @Query("SELECT NEW com.swp.PodBookingSystem.dto.respone.OrderDetail.RevenueChartDto(" + - "CONCAT(YEAR(MIN(od.startTime)), '-Q', CEILING(MONTH(MIN(od.startTime)) / 3.0)), " + + "CONCAT(YEAR(MIN(od.startTime)), '-', LPAD(CAST(MONTH(MIN(od.startTime)) AS string), 2, '0'), '-01'), " + "SUM((od.priceRoom + COALESCE(amenityTotal.totalAmenityPrice, 0)) * " + - "(1 - COALESCE(od.discountPercentage, 0) / 100.0) * (1 - COALESCE(sp.discountPercentage, 0) / 100.0))) " + + "(1 - COALESCE(od.discountPercentage, 0) / 100.0) * " + + "(1 - COALESCE(sp.discountPercentage, 0) / 100.0))) " + "FROM OrderDetail od " + "LEFT JOIN od.servicePackage sp " + "LEFT JOIN (SELECT oda.orderDetail.id as orderDetailId, SUM(oda.price * oda.quantity) as totalAmenityPrice " + @@ -145,10 +146,10 @@ Optional calculateRevenueBetweenDateTime(@Param("startTime") LocalDateTi "ON od.id = amenityTotal.orderDetailId " + "WHERE od.startTime BETWEEN :startTime AND :endTime " + "AND od.status = com.swp.PodBookingSystem.enums.OrderStatus.Successfully " + - "GROUP BY YEAR(od.startTime), CEILING(MONTH(od.startTime) / 3.0) " + - "ORDER BY YEAR(od.startTime), CEILING(MONTH(od.startTime) / 3.0)") + "GROUP BY YEAR(od.startTime), MONTH(od.startTime)") List calculateRevenueByQuarter(@Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime); + @Query("SELECT NEW com.swp.PodBookingSystem.dto.respone.Order.NumberOrderByBuildingDto(" + "od.building.id, od.building.address, COUNT(DISTINCT od.order.id)" + ") " + From 8b3724ae1c137a008465a6cdb67eb390060260ae Mon Sep 17 00:00:00 2001 From: Hoang-Nguyen-Huy Date: Tue, 29 Oct 2024 15:04:37 +0700 Subject: [PATCH 6/6] =?UTF-8?q?[PBS-65][HoangHN]=20refactor:=20?= =?UTF-8?q?=F0=9F=99=89=20no=20params=20situation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../swp/PodBookingSystem/service/OrderDetailService.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java b/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java index 2c351b5b..d9257eab 100644 --- a/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java +++ b/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java @@ -438,6 +438,12 @@ public double calculateRevenue(LocalDateTime startTime, LocalDateTime endTime) { [GET]: /order-detail/revenue-chart */ public List calculateRevenueByMonth(LocalDateTime startTime, LocalDateTime endTime, String viewWith) { + if (startTime == null) { + startTime = LocalDate.now().atStartOfDay(); + } + if (endTime == null) { + endTime = LocalDate.now().atTime(LocalTime.MAX); + } if (viewWith == null) { return Collections.singletonList(orderDetailRepository.calculateRevenueForSingleDay(startTime)); }