Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Production #178

Merged
merged 10 commits into from
Nov 12, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface AssignmentRepository extends JpaRepository<Assignment, String> {
Expand All @@ -22,9 +23,11 @@ public interface AssignmentRepository extends JpaRepository<Assignment, String>
"WHERE a.slot = :slot " +
"AND a.weekDate = :weekDate " +
"AND ac.buildingNumber = :buildingId")
String findStaffForMatchingOrder(@Param("slot") String slot,
@Param("weekDate") String weekDate,
@Param("buildingId") Integer buildingId);
List<String> findStaffIdsForMatchingOrder(@Param("slot") String slot,
@Param("weekDate") String weekDate,
@Param("buildingId") Integer buildingId);




@Query("SELECT a FROM Assignment a " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Page<OrderDetail> findOrdersByBuildingNumberAndTimeRange(
// integer countByBuildingId(@Param("buildingId") Integer buildingId);

@Query("SELECT SUM((od.priceRoom + COALESCE(amenityTotal.totalAmenityPrice, 0)) * " +
"(1 - COALESCE(od.discountPercentage, 0) / 100.0) * (1 - COALESCE(sp.discountPercentage, 0) / 100.0)) as grandTotal " +
"(1 - COALESCE(od.discountPercentage, 0) / 100.0)) as grandTotal " +
"FROM OrderDetail od " +
"LEFT JOIN od.servicePackage sp " +
"LEFT JOIN (SELECT oda.orderDetail.id as orderDetailId, SUM(oda.price * oda.quantity) as totalAmenityPrice " +
Expand All @@ -99,7 +99,7 @@ Page<OrderDetail> findOrdersByBuildingNumberAndTimeRange(
Double calculateRevenueCurrentDay();

@Query("SELECT SUM((od.priceRoom + COALESCE(amenityTotal.totalAmenityPrice, 0)) * " +
"(1 - COALESCE(od.discountPercentage, 0) / 100.0) * (1 - COALESCE(sp.discountPercentage, 0) / 100.0)) as grandTotal " +
"(1 - COALESCE(od.discountPercentage, 0) / 100.0)) as grandTotal " +
"FROM OrderDetail od " +
"LEFT JOIN od.servicePackage sp " +
"LEFT JOIN (SELECT oda.orderDetail.id as orderDetailId, SUM(oda.price * oda.quantity) as totalAmenityPrice " +
Expand All @@ -113,7 +113,7 @@ Optional<Double> calculateRevenueBetweenDateTime(@Param("startTime") LocalDateTi
@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))) " +
"(1 - COALESCE(od.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 " +
Expand All @@ -126,7 +126,7 @@ Optional<Double> calculateRevenueBetweenDateTime(@Param("startTime") LocalDateTi
@Query("SELECT NEW com.swp.PodBookingSystem.dto.respone.OrderDetail.RevenueChartDto(" +
"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))) " +
"(1 - COALESCE(od.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 " +
Expand All @@ -142,8 +142,8 @@ Optional<Double> calculateRevenueBetweenDateTime(@Param("startTime") LocalDateTi
@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) " +
")) " +
"FROM OrderDetail od " +
"LEFT JOIN od.servicePackage sp " +
"LEFT JOIN (SELECT oda.orderDetail.id as orderDetailId, SUM(oda.price * oda.quantity) as totalAmenityPrice " +
Expand Down Expand Up @@ -172,7 +172,7 @@ Optional<Double> calculateRevenueBetweenDateTime(@Param("startTime") LocalDateTi
"AND TIME(od.startTime) BETWEEN :slotStartTime AND :slotEndTime " +
"AND od.building.id = :buildingNumber " +
"AND od.startTime > CURRENT_TIMESTAMP " +
"AND (od.orderHandler.id != :staffId OR od.orderHandler IS NULL)")
"AND od.orderHandler IS NULL")
void assignOrdersToStaff(@Param("staffId") String staffId,
@Param("weekDay") int weekDay,
@Param("slotStartTime") String slotStartTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,10 @@ public OrderDetail createOrderDetail(OrderDetailCreationRequest request, Order o

DayOfWeek dayOfWeek = startTime.getDayOfWeek();
String weekDate = getDayLabel(dayOfWeek);
Account orderHandler;
String orderHandlerId = assignmentRepository.findStaffForMatchingOrder(slot, weekDate, building.getId());
if (orderHandlerId == null){
orderHandler = null;
} else {
orderHandler = accountRepository.getById(orderHandlerId);
}
List<String> staffIds = assignmentRepository.findStaffIdsForMatchingOrder(slot, weekDate, building.getId());
String orderHandlerId = staffIds.isEmpty() ? null : staffIds.get(0);

Account orderHandler = (orderHandlerId == null) ? null : accountRepository.getById(orderHandlerId);
OrderDetail response = new OrderDetail();

response.setCustomer(account);
Expand Down