From 1f9265666dc1766c75e217c5c5c95b948194f692 Mon Sep 17 00:00:00 2001 From: Huynh Nguyen Date: Mon, 28 Oct 2024 22:16:06 +0700 Subject: [PATCH 1/7] [PBS-85][NguyenHCP] feat: get list order of customer --- .../controller/OrderController.java | 14 +++---- .../dto/respone/PaginationResponse.java | 13 ++++--- .../repository/OrderDetailRepository.java | 6 +++ .../repository/OrderRepository.java | 18 +++++---- .../service/OrderDetailService.java | 26 +++++++++++++ .../service/OrderService.java | 39 +++++++++++++++++-- 6 files changed, 91 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/swp/PodBookingSystem/controller/OrderController.java b/src/main/java/com/swp/PodBookingSystem/controller/OrderController.java index 4a7c6375..e1523cf6 100644 --- a/src/main/java/com/swp/PodBookingSystem/controller/OrderController.java +++ b/src/main/java/com/swp/PodBookingSystem/controller/OrderController.java @@ -5,6 +5,7 @@ import com.swp.PodBookingSystem.dto.request.OrderDetail.OrderDetailCreationRequest; import com.swp.PodBookingSystem.dto.respone.ApiResponse; import com.swp.PodBookingSystem.dto.respone.Order.OrderManagementResponse; +import com.swp.PodBookingSystem.dto.respone.OrderDetail.OrderDetailResponse; import com.swp.PodBookingSystem.dto.respone.OrderResponse; import com.swp.PodBookingSystem.dto.respone.PaginationResponse; import com.swp.PodBookingSystem.entity.*; @@ -69,14 +70,11 @@ public ApiResponse>> searchOrde .build(); } -// @GetMapping("/{accountId}") -// public ApiResponse> getOrdersByAccountId(@PathVariable String accountId) { -// List orders = orderService.getOrdersByAccountId(accountId); -// logOrders(orders); -// return ApiResponse.>builder() -// .data(orders) -// .build(); -// } + @GetMapping("/{accountId}") + public PaginationResponse> getOrdersByAccountId(@PathVariable String accountId, @RequestParam(defaultValue = "0") int page, + @RequestParam(defaultValue = "5") int take, @RequestParam(defaultValue = "Successfully") String status) { + return orderService.getOrdersByAccountCustomerId(page, take, accountId, status); + } //Check room available -> yes: create order Status: Successfully // -> no: create order Status: Pending diff --git a/src/main/java/com/swp/PodBookingSystem/dto/respone/PaginationResponse.java b/src/main/java/com/swp/PodBookingSystem/dto/respone/PaginationResponse.java index fabc37f4..bcc66aea 100644 --- a/src/main/java/com/swp/PodBookingSystem/dto/respone/PaginationResponse.java +++ b/src/main/java/com/swp/PodBookingSystem/dto/respone/PaginationResponse.java @@ -12,10 +12,11 @@ @JsonInclude(JsonInclude.Include.NON_NULL) public class PaginationResponse { @Builder.Default - private int code = 200; - private T data; - private int currentPage; - private int totalPage; - private int recordPerPage; - private int totalRecord; + int code = 200; + String message; + T data; + int currentPage; + int totalPage; + int recordPerPage; + int totalRecord; } diff --git a/src/main/java/com/swp/PodBookingSystem/repository/OrderDetailRepository.java b/src/main/java/com/swp/PodBookingSystem/repository/OrderDetailRepository.java index 54950050..0cb011c5 100644 --- a/src/main/java/com/swp/PodBookingSystem/repository/OrderDetailRepository.java +++ b/src/main/java/com/swp/PodBookingSystem/repository/OrderDetailRepository.java @@ -26,6 +26,12 @@ public interface OrderDetailRepository extends JpaRepository findByOrderId(String orderId); + @Query("SELECT od FROM OrderDetail od " + + "WHERE (od.order.id = :orderId)" + + "AND (od.status = :status)" + + "ORDER BY od.startTime DESC") + List findByOrderIdAndStatus(@Param("orderId") String orderId, @Param("status") OrderStatus status); + List findByEndTime(LocalDateTime endTime); @Query(value = "SELECT od FROM OrderDetail od WHERE od.createdAt BETWEEN :startTime AND :endTime ORDER BY od.createdAt DESC") diff --git a/src/main/java/com/swp/PodBookingSystem/repository/OrderRepository.java b/src/main/java/com/swp/PodBookingSystem/repository/OrderRepository.java index 8b5343a2..0f9a2d2f 100644 --- a/src/main/java/com/swp/PodBookingSystem/repository/OrderRepository.java +++ b/src/main/java/com/swp/PodBookingSystem/repository/OrderRepository.java @@ -9,13 +9,17 @@ import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; + import java.time.LocalDateTime; import java.util.List; @Repository -public interface OrderRepository extends JpaRepository { +public interface OrderRepository extends JpaRepository { List findByAccountId(String accountId); + @Query("SELECT o FROM Order o WHERE o.account.id = :accountId") + Page findByAccountCustomerId(@Param("accountId") String accountId, Pageable pageable); + Page findAll(Pageable pageable); @Query(value = "SELECT DISTINCT o FROM Order o JOIN OrderDetail od ON o.id = od.order.id WHERE o.createdAt >= :startTime AND o.createdAt <= :endTime ORDER BY o.createdAt DESC") @@ -39,11 +43,11 @@ Page findOrdersByBuildingNumberAndTimeRange(@Param("buildingNumber") int void updateOrderUpdatedAt(String orderId, LocalDateTime updatedAt); @Query(""" - SELECT o FROM Order o - JOIN o.account a - WHERE LOWER(o.id) LIKE LOWER(CONCAT('%', :keyword, '%')) - OR LOWER(a.name) LIKE LOWER(CONCAT('%', :keyword, '%')) - """) + SELECT o FROM Order o + JOIN o.account a + WHERE LOWER(o.id) LIKE LOWER(CONCAT('%', :keyword, '%')) + OR LOWER(a.name) LIKE LOWER(CONCAT('%', :keyword, '%')) + """) Page searchByKeyword(String keyword, Pageable pageable); @Query("SELECT COUNT(DISTINCT o.id) FROM Order o " + @@ -58,5 +62,5 @@ OR LOWER(a.name) LIKE LOWER(CONCAT('%', :keyword, '%')) "AND :endTime >= od.startTime " + "AND od.status = com.swp.PodBookingSystem.enums.OrderStatus.Successfully") int countOrdersBetweenDatetime(@Param("startTime") LocalDateTime startTime, - @Param("endTime") LocalDateTime endTime); + @Param("endTime") LocalDateTime endTime); } diff --git a/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java b/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java index e0823860..38e66cb2 100644 --- a/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java +++ b/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java @@ -87,6 +87,32 @@ public OrderDetailFullInfoResponse getOrderDetailByOrderDetailId(String orderDet .build(); } + public List getOrderDetailByOrderId(String orderId, String status) { + return orderDetailRepository.findByOrderIdAndStatus(orderId, OrderStatus.valueOf(status)).stream().map(orderDetail -> { + List amenities = orderDetailAmenityService.getOrderDetailAmenitiesByOrderDetailId(orderDetail.getId()); + return OrderDetailManagementResponse.builder() + .id(orderDetail.getId()) + .roomId(orderDetail.getRoom().getId()) + .roomName(orderDetail.getRoom().getName()) + .roomPrice(orderDetail.getPriceRoom()) + .buildingAddress(orderDetail.getBuilding().getAddress()) + .buildingId(orderDetail.getBuilding().getId()) + .roomId(orderDetail.getRoom().getId()) + .orderHandler(Optional.ofNullable(orderDetail.getOrderHandler()) + .map(accountService::toAccountResponse) + .orElse(null)) + .customer(Optional.ofNullable(orderDetail.getCustomer()) + .map(accountService::toAccountResponse) + .orElse(null)) + .servicePackage(servicePackageService.toServicePackageResponse(orderDetail.getServicePackage())) + .status(orderDetail.getStatus().name()) + .startTime(orderDetail.getStartTime()) + .endTime(orderDetail.getEndTime()) + .amenities(amenities) + .build(); + }).collect(Collectors.toList()); + } + public List getOrderDetailById(String orderId) { return orderDetailRepository.findByOrderId(orderId).stream().map(orderDetail -> { List amenities = orderDetailAmenityService.getOrderDetailAmenitiesByOrderDetailId(orderDetail.getId()); diff --git a/src/main/java/com/swp/PodBookingSystem/service/OrderService.java b/src/main/java/com/swp/PodBookingSystem/service/OrderService.java index aeaff2b7..e27a18cc 100644 --- a/src/main/java/com/swp/PodBookingSystem/service/OrderService.java +++ b/src/main/java/com/swp/PodBookingSystem/service/OrderService.java @@ -1,4 +1,5 @@ package com.swp.PodBookingSystem.service; + import com.swp.PodBookingSystem.dto.request.Order.OrderUpdateRequest; import com.swp.PodBookingSystem.dto.request.Order.OrderUpdateStaffRequest; import com.swp.PodBookingSystem.dto.respone.Order.OrderManagementResponse; @@ -15,9 +16,11 @@ import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; + import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.List; +import java.util.Map; import java.util.UUID; import java.util.stream.Collectors; @@ -50,6 +53,12 @@ public List getOrdersByAccountId(String accountId) { .collect(Collectors.toList()); } + public PaginationResponse> getOrdersByAccountCustomerId(int page, int take, String accountId, String status) { + Page ordersPage; + ordersPage = orderRepository.findByAccountCustomerId(accountId, PageRequest.of(page, take)); + return convertToPaginationQueryResponse(ordersPage, status); + } + public PaginationResponse> getOrdersByRole( int page, int size, LocalDateTime startDate, LocalDateTime endDate, Account user) { Page ordersPage; @@ -101,7 +110,7 @@ public OrderResponse updateOrder(OrderUpdateRequest request) { .build(); } - public OrderResponse updateOrderHandlerWithOrder(String id, OrderUpdateStaffRequest request){ + public OrderResponse updateOrderHandlerWithOrder(String id, OrderUpdateStaffRequest request) { Order existingOrder = orderRepository.findById(id).orElseThrow(() -> new RuntimeException("Order not found with id: " + id)); if (request.getOrderHandler() == null) { throw new RuntimeException("Account handler cannot be null"); @@ -116,7 +125,7 @@ public OrderResponse updateOrderHandlerWithOrder(String id, OrderUpdateStaffRequ .build(); } - public void updateOrderUpdateAt(String orderId){ + public void updateOrderUpdateAt(String orderId) { orderRepository.updateOrderUpdatedAt(orderId, LocalDateTime.now()); } @@ -140,6 +149,7 @@ private PaginationResponse> convertToPaginationRes .build(); }).collect(Collectors.toList()); return PaginationResponse.>builder() + .message("Lấy danh sách hóa đơn thành công") .data(orderResponses) .currentPage(ordersPage.getNumber()) .totalPage(ordersPage.getTotalPages()) @@ -148,6 +158,27 @@ private PaginationResponse> convertToPaginationRes .build(); } + private PaginationResponse> convertToPaginationQueryResponse(Page ordersPage, String status) { + List orderResponses = ordersPage.getContent().stream().map(order -> { + List orderDetailDTOs = orderDetailService.getOrderDetailByOrderId(order.getId(), status); + return OrderManagementResponse.builder() + .id(order.getId()) + .createdAt(order.getCreatedAt()) + .updatedAt(order.getUpdatedAt()) + .orderDetails(orderDetailDTOs) + .build(); + }).filter(orderResponse -> !orderResponse.getOrderDetails().isEmpty()).collect(Collectors.toList()); + return PaginationResponse.>builder() + .message("Lấy danh sách hóa đơn thành công") + .data(orderResponses) + .currentPage(ordersPage.getNumber()) + .totalPage(ordersPage.getTotalPages()) + .recordPerPage(ordersPage.getSize()) + .totalRecord(orderResponses.size()) + .build(); + + } + public LocalDateTime parseDateTime(String dateTime) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm"); return LocalDateTime.parse(dateTime, formatter); @@ -156,14 +187,14 @@ public LocalDateTime parseDateTime(String dateTime) { /* [GET]: /order/number-order-current-day */ - public int countCurrentlyOrder () { + public int countCurrentlyOrder() { return orderRepository.countCurrentlyOrder(); } /* [GET]: /order/number-order */ - public int countOrder (LocalDateTime startTime, LocalDateTime endTime) { + public int countOrder(LocalDateTime startTime, LocalDateTime endTime) { return orderRepository.countOrdersBetweenDatetime(startTime, endTime); } } \ No newline at end of file From b3ffc0cb40925813eb98cc4faa3e2c802e090734 Mon Sep 17 00:00:00 2001 From: Huynh Nguyen Date: Tue, 29 Oct 2024 00:07:46 +0700 Subject: [PATCH 2/7] [PBS-85][NguyenHCP] feat: get list order by account id --- .../OrderDetailManagementResponse.java | 1 + .../repository/OrderRepository.java | 44 +++++++++++-------- .../service/OrderDetailService.java | 19 ++++---- .../service/OrderService.java | 6 +-- 4 files changed, 40 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/swp/PodBookingSystem/dto/respone/OrderDetail/OrderDetailManagementResponse.java b/src/main/java/com/swp/PodBookingSystem/dto/respone/OrderDetail/OrderDetailManagementResponse.java index f7cfd408..55b5d9ae 100644 --- a/src/main/java/com/swp/PodBookingSystem/dto/respone/OrderDetail/OrderDetailManagementResponse.java +++ b/src/main/java/com/swp/PodBookingSystem/dto/respone/OrderDetail/OrderDetailManagementResponse.java @@ -17,6 +17,7 @@ public class OrderDetailManagementResponse { private String id; private int roomId; private String roomName; + private String roomImage; private double roomPrice; private String status; private LocalDateTime startTime; diff --git a/src/main/java/com/swp/PodBookingSystem/repository/OrderRepository.java b/src/main/java/com/swp/PodBookingSystem/repository/OrderRepository.java index d9ad6a37..8da3c831 100644 --- a/src/main/java/com/swp/PodBookingSystem/repository/OrderRepository.java +++ b/src/main/java/com/swp/PodBookingSystem/repository/OrderRepository.java @@ -18,36 +18,44 @@ public interface OrderRepository extends JpaRepository { List findByAccountId(String accountId); - @Query("SELECT o FROM Order o WHERE o.account.id = :accountId") - Page findByAccountCustomerId(@Param("accountId") String accountId, Pageable pageable); + @Query(""" + SELECT DISTINCT o FROM Order o + JOIN OrderDetail od ON o.id = od.order.id + WHERE o.account.id = :accountId + AND od.status = :status + AND od.id IS NOT NULL + ORDER BY o.createdAt DESC + """) + Page findByAccountCustomerId(@Param("accountId") String accountId, @Param("status") OrderStatus status, Pageable pageable); Page findAll(Pageable pageable); @Query(""" - SELECT DISTINCT o FROM Order o - JOIN OrderDetail od ON o.id = od.order.id - WHERE o.createdAt >= :startTime - AND o.createdAt <= :endTime - AND (:status IS NULL OR od.status = :status) - AND od.id IS NOT NULL - ORDER BY o.createdAt DESC - """) + SELECT DISTINCT o FROM Order o + JOIN OrderDetail od ON o.id = od.order.id + WHERE o.createdAt >= :startTime + AND o.createdAt <= :endTime + AND (:status IS NULL OR od.status = :status) + AND od.id IS NOT NULL + ORDER BY o.createdAt DESC + """) Page findAllWithTimeRange( @Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime, @Param("status") OrderStatus status, Pageable pageable); + ; @Query(""" - SELECT DISTINCT o FROM Order o - JOIN OrderDetail od ON o.id = od.order.id - WHERE od.building.id = :buildingNumber - AND o.createdAt >= :startTime - AND o.createdAt <= :endTime - AND (:status IS NULL OR od.status = :status) - ORDER BY o.createdAt DESC -""") + SELECT DISTINCT o FROM Order o + JOIN OrderDetail od ON o.id = od.order.id + WHERE od.building.id = :buildingNumber + AND o.createdAt >= :startTime + AND o.createdAt <= :endTime + AND (:status IS NULL OR od.status = :status) + ORDER BY o.createdAt DESC + """) Page findOrdersByBuildingNumberAndTimeRange( @Param("buildingNumber") int buildingNumber, @Param("startTime") LocalDateTime startTime, diff --git a/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java b/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java index 78a2023c..d6dc2f45 100644 --- a/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java +++ b/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java @@ -121,6 +121,7 @@ public List getOrderDetailById(String orderId) { return OrderDetailManagementResponse.builder() .id(orderDetail.getId()) .roomId(orderDetail.getRoom().getId()) + .roomImage(orderDetail.getRoom().getImage()) .roomName(orderDetail.getRoom().getName()) .roomPrice(orderDetail.getPriceRoom()) .buildingAddress(orderDetail.getBuilding().getAddress()) @@ -365,24 +366,24 @@ public void updateOrderDetail(OrderUpdateRequest request) { for (OrderDetail od : orderDetails) { if (request.getStatus() != null) { od.setStatus(request.getStatus()); - if(request.getStatus().equals(OrderStatus.Rejected)){ + if (request.getStatus().equals(OrderStatus.Rejected)) { double total = 0; int countService = 0; - if(od.getServicePackage().getId() == 1){ + if (od.getServicePackage().getId() == 1) { countService = 4; - } else if(od.getServicePackage().getId() == 2){ + } else if (od.getServicePackage().getId() == 2) { countService = 30; } else { countService = 1; } - total += od.getPriceRoom() * (100- od.getDiscountPercentage()) * countService/ 100; - List listOda = orderDetailAmenityRepository.findByOrderDetailId(od.getId()); - for(OrderDetailAmenity oda : listOda){ - total += oda.getPrice() * oda.getQuantity() * (100- od.getDiscountPercentage()) * countService/ 100; - orderDetailAmenityService.updateOrderDetailAmenityStatus( new OrderDetailAmenityUpdateReq(oda.getId(), OrderDetailAmenityStatus.Canceled)); + total += od.getPriceRoom() * (100 - od.getDiscountPercentage()) * countService / 100; + List listOda = orderDetailAmenityRepository.findByOrderDetailId(od.getId()); + for (OrderDetailAmenity oda : listOda) { + total += oda.getPrice() * oda.getQuantity() * (100 - od.getDiscountPercentage()) * countService / 100; + orderDetailAmenityService.updateOrderDetailAmenityStatus(new OrderDetailAmenityUpdateReq(oda.getId(), OrderDetailAmenityStatus.Canceled)); } Account customer = od.getCustomer(); - if(customer != null){ + if (customer != null) { customer.setBalance(customer.getBalance() + total); accountRepository.save(customer); } diff --git a/src/main/java/com/swp/PodBookingSystem/service/OrderService.java b/src/main/java/com/swp/PodBookingSystem/service/OrderService.java index 04e43c7b..f80b855b 100644 --- a/src/main/java/com/swp/PodBookingSystem/service/OrderService.java +++ b/src/main/java/com/swp/PodBookingSystem/service/OrderService.java @@ -61,8 +61,8 @@ public List getOrdersByAccountId(String accountId) { public PaginationResponse> getOrdersByAccountCustomerId(int page, int take, String accountId, String status) { Page ordersPage; - ordersPage = orderRepository.findByAccountCustomerId(accountId, PageRequest.of(page, take)); - return convertToPaginationQueryResponse(ordersPage, status); + ordersPage = orderRepository.findByAccountCustomerId(accountId, OrderStatus.valueOf(status), PageRequest.of(page, take)); + return convertToPaginationResponse(ordersPage); } public PaginationResponse> getOrdersByRole( @@ -202,7 +202,7 @@ public String renderOrderID(OrderDetailCreationRequest request) { .map(room -> room.getName().replace(" ", "")) .collect(Collectors.joining("-")); String uuid = UUID.randomUUID().toString(); - return "OD-" + roomNames.toLowerCase() + "-CUS-" + customerName.replace(" ","").toString().substring(0,3).toLowerCase() + "-D-" + return "OD-" + roomNames.toLowerCase() + "-CUS-" + customerName.replace(" ", "").toString().substring(0, 3).toLowerCase() + "-D-" + request.getStartTime().getFirst().getDayOfMonth() + "-" + request.getStartTime().getFirst().getMonthValue() + "-" + uuid.substring(0, 6); From 4c9b62285830a6986f30cb3453e8a07ea93f31fe Mon Sep 17 00:00:00 2001 From: Huynh Nguyen Date: Tue, 29 Oct 2024 10:11:37 +0700 Subject: [PATCH 3/7] [PBS-85][NguyenHCP] feat: get info of order --- .../controller/OrderController.java | 9 ++++++++ .../PodBookingSystem/exception/ErrorCode.java | 1 + .../service/OrderService.java | 22 +++++++++++++++---- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/swp/PodBookingSystem/controller/OrderController.java b/src/main/java/com/swp/PodBookingSystem/controller/OrderController.java index 3d9c4097..6d905e45 100644 --- a/src/main/java/com/swp/PodBookingSystem/controller/OrderController.java +++ b/src/main/java/com/swp/PodBookingSystem/controller/OrderController.java @@ -44,6 +44,15 @@ public ApiResponse> getAllOrders() { .build(); } + @GetMapping("/order-info/{orderId}") + public ApiResponse getInfoOrder(@PathVariable String orderId) { + return ApiResponse.builder() + .message("Lấy thông tin đơn hàng thành công") + .data(orderService.getInfoOrder(orderId)) + .build(); + } + + @GetMapping("/page") public ApiResponse>> getOrdersByRole( @RequestHeader("Authorization") String token, diff --git a/src/main/java/com/swp/PodBookingSystem/exception/ErrorCode.java b/src/main/java/com/swp/PodBookingSystem/exception/ErrorCode.java index 9126d648..15675716 100644 --- a/src/main/java/com/swp/PodBookingSystem/exception/ErrorCode.java +++ b/src/main/java/com/swp/PodBookingSystem/exception/ErrorCode.java @@ -23,6 +23,7 @@ public enum ErrorCode { INVALID_TOKEN(401, "Token không đúng", HttpStatus.UNAUTHORIZED, "accessToken"), ORDER_DETAIL_NOT_EXIST(404, "Order detail không tồn tại", HttpStatus.NOT_FOUND, "orderDetailId"), ACCOUNT_NOT_ACTIVE(403, "Tài khoản đã bị cấm", HttpStatus.FORBIDDEN, "system"), + ORDER_NOT_FOUND(404, "Order không tồn tại", HttpStatus.NOT_FOUND, "orderId"), ; ErrorCode(int code, String message, HttpStatusCode statusCode, String field) { diff --git a/src/main/java/com/swp/PodBookingSystem/service/OrderService.java b/src/main/java/com/swp/PodBookingSystem/service/OrderService.java index f80b855b..a16ff4ee 100644 --- a/src/main/java/com/swp/PodBookingSystem/service/OrderService.java +++ b/src/main/java/com/swp/PodBookingSystem/service/OrderService.java @@ -10,6 +10,8 @@ import com.swp.PodBookingSystem.entity.*; import com.swp.PodBookingSystem.enums.AccountRole; import com.swp.PodBookingSystem.enums.OrderStatus; +import com.swp.PodBookingSystem.exception.AppException; +import com.swp.PodBookingSystem.exception.ErrorCode; import com.swp.PodBookingSystem.mapper.OrderMapper; import com.swp.PodBookingSystem.repository.OrderRepository; import org.slf4j.Logger; @@ -19,14 +21,11 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.Map; +import java.util.*; import java.text.Normalizer; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.util.List; -import java.util.Locale; -import java.util.UUID; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -52,6 +51,21 @@ public List getAllOrders() { .collect(Collectors.toList()); } + public OrderManagementResponse getInfoOrder(String id) { + OrderManagementResponse order = new OrderManagementResponse(); + Optional orderOptional = orderRepository.findById(id); + if (orderOptional.isEmpty()) { + throw new AppException(ErrorCode.ORDER_NOT_FOUND); + } else { + order.setId(orderOptional.get().getId()); + order.setCreatedAt(orderOptional.get().getCreatedAt()); + order.setUpdatedAt(orderOptional.get().getUpdatedAt()); + } + List orderDetailDTOs = orderDetailService.getOrderDetailById(order.getId()); + order.setOrderDetails(orderDetailDTOs); + return order; + } + public List getOrdersByAccountId(String accountId) { List orders = orderRepository.findByAccountId(accountId); return orders.stream() From b37841c41f2fd80807c85958f927523cdc328010 Mon Sep 17 00:00:00 2001 From: Huynh Nguyen Date: Tue, 29 Oct 2024 13:47:57 +0700 Subject: [PATCH 4/7] [PBS-85][NguyenHCP] feat: update order response --- .../dto/respone/OrderDetail/OrderDetailManagementResponse.java | 1 + .../com/swp/PodBookingSystem/service/OrderDetailService.java | 1 + 2 files changed, 2 insertions(+) diff --git a/src/main/java/com/swp/PodBookingSystem/dto/respone/OrderDetail/OrderDetailManagementResponse.java b/src/main/java/com/swp/PodBookingSystem/dto/respone/OrderDetail/OrderDetailManagementResponse.java index 55b5d9ae..b9817176 100644 --- a/src/main/java/com/swp/PodBookingSystem/dto/respone/OrderDetail/OrderDetailManagementResponse.java +++ b/src/main/java/com/swp/PodBookingSystem/dto/respone/OrderDetail/OrderDetailManagementResponse.java @@ -18,6 +18,7 @@ public class OrderDetailManagementResponse { private int roomId; private String roomName; private String roomImage; + private String roomTypeName; private double roomPrice; private String status; private LocalDateTime startTime; diff --git a/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java b/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java index d6dc2f45..dd513160 100644 --- a/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java +++ b/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java @@ -123,6 +123,7 @@ public List getOrderDetailById(String orderId) { .roomId(orderDetail.getRoom().getId()) .roomImage(orderDetail.getRoom().getImage()) .roomName(orderDetail.getRoom().getName()) + .roomTypeName(orderDetail.getRoom().getRoomType().getName()) .roomPrice(orderDetail.getPriceRoom()) .buildingAddress(orderDetail.getBuilding().getAddress()) .buildingId(orderDetail.getBuilding().getId()) From 38c94fccce825ca1f4ab39f894a5a3d4b6530a0e Mon Sep 17 00:00:00 2001 From: Huynh Nguyen Date: Tue, 29 Oct 2024 15:52:44 +0700 Subject: [PATCH 5/7] [PBS-85][NguyenHCP] feat: update cancel reason of order --- .../com/swp/PodBookingSystem/controller/OrderController.java | 2 +- src/main/java/com/swp/PodBookingSystem/entity/OrderDetail.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/swp/PodBookingSystem/controller/OrderController.java b/src/main/java/com/swp/PodBookingSystem/controller/OrderController.java index 6d905e45..4298e8d5 100644 --- a/src/main/java/com/swp/PodBookingSystem/controller/OrderController.java +++ b/src/main/java/com/swp/PodBookingSystem/controller/OrderController.java @@ -122,7 +122,7 @@ ApiResponse updateOrder(@RequestBody OrderUpdateRequest request) orderService.updateOrderUpdateAt(request.getId()); return ApiResponse.builder() .data(orderService.updateOrder(request)) - .message("Update order successfully") + .message("Cập nhật hóa đơn thành công") .build(); } diff --git a/src/main/java/com/swp/PodBookingSystem/entity/OrderDetail.java b/src/main/java/com/swp/PodBookingSystem/entity/OrderDetail.java index 9f10f8db..99954a4b 100644 --- a/src/main/java/com/swp/PodBookingSystem/entity/OrderDetail.java +++ b/src/main/java/com/swp/PodBookingSystem/entity/OrderDetail.java @@ -69,6 +69,9 @@ public class OrderDetail { @Temporal(TemporalType.TIMESTAMP) LocalDateTime updatedAt; + @Column(name = "cancelReason") + String cancelReason; + @PrePersist protected void onCreate() { this.createdAt = LocalDateTime.now(); From 5ff732f0dc9d5652d9178aa2d056282cbf0cb478 Mon Sep 17 00:00:00 2001 From: Huynh Nguyen Date: Tue, 29 Oct 2024 21:50:20 +0700 Subject: [PATCH 6/7] [PBS-85][NguyenHCP] feat: update cancelReason to request --- pom.xml | 7 ++++--- .../dto/request/Order/OrderUpdateRequest.java | 1 + .../swp/PodBookingSystem/service/OrderDetailService.java | 3 +++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 93593e6e..c996b9c5 100644 --- a/pom.xml +++ b/pom.xml @@ -33,7 +33,8 @@ 0.2.0 swp-pod-booking-system-server https://sonarcloud.io - ${project.build.directory}/site/jacoco/jacoco.xml + ${project.build.directory}/site/jacoco/jacoco.xml + @@ -137,8 +138,8 @@ maven-compiler-plugin ${maven-compiler-plugin.version} - 22 - 22 + ${java.version} + ${java.version} org.projectlombok diff --git a/src/main/java/com/swp/PodBookingSystem/dto/request/Order/OrderUpdateRequest.java b/src/main/java/com/swp/PodBookingSystem/dto/request/Order/OrderUpdateRequest.java index 7685ba23..2ca7200b 100644 --- a/src/main/java/com/swp/PodBookingSystem/dto/request/Order/OrderUpdateRequest.java +++ b/src/main/java/com/swp/PodBookingSystem/dto/request/Order/OrderUpdateRequest.java @@ -17,6 +17,7 @@ public class OrderUpdateRequest { String id; OrderStatus status; + String cancelReason; Account orderHandler; List orderDetails; } diff --git a/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java b/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java index dd513160..b9afe8ce 100644 --- a/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java +++ b/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java @@ -394,6 +394,9 @@ public void updateOrderDetail(OrderUpdateRequest request) { Account orderHandler = accountService.getAccountById(request.getOrderHandler().getId()); od.setOrderHandler(orderHandler); } + if (request.getCancelReason() != null) { + od.setCancelReason(request.getCancelReason()); + } if (request.getOrderDetails() != null && !request.getOrderDetails().isEmpty()) { for (OrderDetailUpdateRoomRequest odr : request.getOrderDetails()) { if (odr.getId().equals(od.getId())) { From 78f3ae3483c73bb6f8246da579215f9ae0fd2f68 Mon Sep 17 00:00:00 2001 From: Huynh Nguyen Date: Wed, 30 Oct 2024 09:45:51 +0700 Subject: [PATCH 7/7] [PBS-85][NguyenHCP] chore: update response for building controller --- .../swp/PodBookingSystem/controller/BuildingController.java | 2 +- .../swp/PodBookingSystem/repository/BuildingRepository.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/swp/PodBookingSystem/controller/BuildingController.java b/src/main/java/com/swp/PodBookingSystem/controller/BuildingController.java index 7da74e5e..1fe2c940 100644 --- a/src/main/java/com/swp/PodBookingSystem/controller/BuildingController.java +++ b/src/main/java/com/swp/PodBookingSystem/controller/BuildingController.java @@ -81,7 +81,7 @@ ApiResponse updateBuilding(@PathVariable("buildingId") int bui @RequestBody BuildingCreationRequest request) { return ApiResponse.builder() .data(buildingService.updateBuilding(buildingId, request)) - .message("Update building successfully") + .message("Cập nhật chi nhánh thành công") .build(); } diff --git a/src/main/java/com/swp/PodBookingSystem/repository/BuildingRepository.java b/src/main/java/com/swp/PodBookingSystem/repository/BuildingRepository.java index 5597a131..f7253d95 100644 --- a/src/main/java/com/swp/PodBookingSystem/repository/BuildingRepository.java +++ b/src/main/java/com/swp/PodBookingSystem/repository/BuildingRepository.java @@ -16,7 +16,8 @@ public interface BuildingRepository extends JpaRepository { List searchByKeyword(String keyword); @Query("SELECT b FROM Building b " + - "WHERE (b.address LIKE %:address%)") + "WHERE (b.address LIKE %:address%)" + + "ORDER BY b.createdAt DESC") Page findFilteredBuildings(@Param("address") String address, Pageable pageable); }