-
Notifications
You must be signed in to change notification settings - Fork 1
[Feature] [상점] 주문 상세 및 정산내역 CRUD #205
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
bce32ac
feature #112: 상점 주문 상세내역 및 정산 내역
Moses249 9160c21
feature #112: 상점 주문 상세내역 및 정산 내역
Moses249 ab4e387
feature #112: 정산내역 CRUD
Moses249 44067f0
feature #112: 정산 수정
Moses249 606bf13
feature #112: 정산 수정
Moses249 7ecc0b5
feature #112: 정산 내역 추가
Moses249 c324911
feature #112: 정산 내역 추가
Moses249 760f886
feature #112: 오류 수정 위한 임시 커밋
Moses249 d64787b
Merge remote-tracking branch 'origin/develop' into feature/#112-store…
Moses249 d1ef014
feature #112: 주문 상세 및 정산 내역 수정
Moses249 2435911
feature #112: 주문 상세 및 정산 내역 수정
Moses249 9fd69ae
feature #112: 주문 상세 및 정산 내역 수정
Moses249 1b775cd
feature #112: 주문 상세 및 정산 내역 수정
Moses249 27c31cc
Update comment from '정산 내역' to '총 주문 내역'
Moses249 b4806a3
feature #112: 결제 엔티티 수정
Moses249 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
src/main/java/com/irum/come2us/domain/order/application/service/SalesService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| package com.irum.come2us.domain.order.application.service; | ||
|
|
||
| import com.irum.come2us.domain.member.domain.entity.Member; | ||
| import com.irum.come2us.domain.order.domain.entity.Order; | ||
| import com.irum.come2us.domain.order.domain.repository.OrderRepository; | ||
| import com.irum.come2us.domain.order.presentation.dto.response.BalanceResponse; | ||
| import com.irum.come2us.domain.order.presentation.dto.response.SalesResponse; | ||
| import com.irum.come2us.domain.refund.domain.entity.Refund; | ||
| import com.irum.come2us.domain.refund.domain.entity.enums.RefundStatus; | ||
| import com.irum.come2us.domain.refund.domain.repository.RefundRepository; | ||
| import com.irum.come2us.domain.store.domain.entity.Store; | ||
| import com.irum.come2us.domain.store.domain.repository.StoreRepository; | ||
| import com.irum.come2us.global.presentation.advice.exception.CommonException; | ||
| import com.irum.come2us.global.presentation.advice.exception.errorcode.StoreErrorCode; | ||
| import com.irum.come2us.global.util.MemberUtil; | ||
| import java.util.*; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class SalesService { | ||
| private final StoreRepository storeRepository; | ||
| private final OrderRepository orderRepository; | ||
| private final RefundRepository refundRepository; | ||
| private final MemberUtil memberUtil; | ||
|
|
||
| public SalesResponse getSalesList(UUID storeId) { | ||
| Member member = memberUtil.getCurrentMember(); | ||
| Store store = | ||
| storeRepository | ||
| .findById(storeId) | ||
| .orElseThrow(() -> new CommonException(StoreErrorCode.STORE_NOT_FOUND)); | ||
|
Bal1oon marked this conversation as resolved.
|
||
| memberUtil.assertMemberResourceAccess(store.getMember()); | ||
|
|
||
| List<Order> orders = orderRepository.findAllByMember(member); | ||
| List<SalesResponse.OrderSummary> orderList = | ||
| orders.stream().map(this::toOrderSummary).toList(); | ||
| return new SalesResponse(orderList, null, false); | ||
| } | ||
|
|
||
| private SalesResponse.OrderSummary toOrderSummary(Order order) { | ||
| String displayStatus = DisplayStatus(order); | ||
|
|
||
| List<SalesResponse.ProductSummary> productList = | ||
| order.getOrderDetails().stream() | ||
| .map( | ||
| detail -> | ||
| new SalesResponse.ProductSummary( | ||
| detail.getOrderDetailId(), | ||
| detail.getProduct().getName(), | ||
| detail.getQuantity(), | ||
| detail.getPrice(), | ||
| detail.getOptionName())) | ||
| .toList(); | ||
|
|
||
| return new SalesResponse.OrderSummary( | ||
| order.getOrderId(), | ||
| order.getDeliveryAddress().getRecipientName(), | ||
| order.getDeliveryAddress().getRecipientContact(), | ||
| order.getDeliveryAddress().getAddress().toString(), | ||
| order.getCreatedAt(), | ||
| order.getTotalPrice(), | ||
| 0, | ||
| order.getTotalPrice() + order.getDeliveryFee(), | ||
| order.getDeliveryFee(), | ||
| productList, | ||
| displayStatus); | ||
| } | ||
|
|
||
| // 환불 존재시 환불 상태 반환, 환불 존재하지 않으면 주문 상태 반환 | ||
| private String DisplayStatus(Order order) { | ||
| Optional<Refund> latestRefundOpt = | ||
| refundRepository.findFirstByOrderOrderByCreatedAtDesc(order); | ||
|
|
||
| if (latestRefundOpt.isPresent()) { | ||
| Refund latestRefund = latestRefundOpt.get(); | ||
| RefundStatus refundStatus = latestRefund.getRefundStatus(); | ||
|
|
||
| if (refundStatus != RefundStatus.REJECTED) { | ||
| return refundStatus.name(); | ||
| } | ||
| } | ||
| return order.getOrderStatusAll().name(); | ||
| } | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public BalanceResponse getBalance(UUID storeId) { | ||
| // 1. 해당 스토어의 모든 주문 가져오기 | ||
| List<Order> orders = orderRepository.findAllByMember(memberUtil.getCurrentMember()); | ||
|
|
||
| // 2. 총 결제 금액 계산 | ||
| int totalPaymentAmount = | ||
| orders.stream().map(Order::getTotalPrice).mapToInt(Integer::intValue).sum(); | ||
|
|
||
| // 3. 환불된 금액 계산 | ||
| List<Refund> refunds = | ||
| refundRepository.findAll(); // 또는 findByOrder_StoreIdAndRefundStatus(...) | ||
| int totalRefundAmount = | ||
| refunds.stream() | ||
| .filter(refund -> refund.getOrder().getStore().getId().equals(storeId)) | ||
| .mapToInt(Refund::getPrice) | ||
| .sum(); | ||
|
|
||
| // 4. 정산 금액 계산 | ||
| int settlementAmount = totalPaymentAmount - totalRefundAmount; | ||
|
|
||
| return new BalanceResponse(totalPaymentAmount, totalRefundAmount, settlementAmount); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/com/irum/come2us/domain/order/presentation/controller/SalesController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package com.irum.come2us.domain.order.presentation.controller; | ||
|
|
||
| import com.irum.come2us.domain.order.application.service.SalesService; | ||
| import com.irum.come2us.domain.order.presentation.dto.response.BalanceResponse; | ||
| import com.irum.come2us.domain.order.presentation.dto.response.SalesResponse; | ||
| import java.util.UUID; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/orders") | ||
| public class SalesController { | ||
| private final SalesService salesService; | ||
|
|
||
| // 총 주문 내역 | ||
| @GetMapping("/{storeId}/sales") | ||
| public ResponseEntity<SalesResponse> salesResponse(@PathVariable UUID storeId) { | ||
| SalesResponse response = salesService.getSalesList(storeId); | ||
| return ResponseEntity.ok(response); | ||
| } | ||
|
|
||
| // 정산 내역 조회 | ||
| @GetMapping("/{storeId}/balance") | ||
| public ResponseEntity<BalanceResponse> getBalance(@PathVariable UUID storeId) { | ||
| BalanceResponse response = salesService.getBalance(storeId); | ||
| return ResponseEntity.ok(response); | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/irum/come2us/domain/order/presentation/dto/response/BalanceResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.irum.come2us.domain.order.presentation.dto.response; | ||
|
|
||
| public record BalanceResponse( | ||
| int totalSalesAmount, // 총 결제 금액 합계 | ||
| int totalRefundAmount, // 총 환불 금액 합계 | ||
| int settlementAmount // 정산 금액 (총 금액 - 환불 금액) | ||
| ) {} |
28 changes: 28 additions & 0 deletions
28
...ava/com/irum/come2us/domain/order/presentation/dto/response/OwnerOrderDetailResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package com.irum.come2us.domain.order.presentation.dto.response; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonFormat; | ||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| public record OwnerOrderDetailResponse( | ||
| List<OrderSummary> orderList, UUID nextCursor, boolean hasNext) { | ||
| public record OrderSummary( | ||
| UUID orderId, | ||
| String recipientName, | ||
| String recipientContact, | ||
| String recipientAddress, | ||
| @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime orderDate, | ||
| int totalProductPrice, | ||
| int discountAmount, | ||
| int payingAmount, | ||
| int deliveryFee, | ||
| List<ProductSummary> productList) {} | ||
|
|
||
| public record ProductSummary( | ||
| UUID orderDetailId, | ||
| String productName, | ||
| int productCounts, | ||
| int productPrice, | ||
| String optionTitle) {} | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.