Skip to content

Commit

Permalink
Merge pull request #68 from 1223v/test
Browse files Browse the repository at this point in the history
Feat: 총 매출, 주문건수 API 추가
  • Loading branch information
1223v authored Mar 6, 2024
2 parents 5adc317 + 9718319 commit 486a07f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
import com.readyvery.readyverydemo.security.jwt.dto.CustomUserDetails;
import com.readyvery.readyverydemo.src.sale.dto.SaleManagementReq;
import com.readyvery.readyverydemo.src.sale.dto.SaleManagementRes;
import com.readyvery.readyverydemo.src.sale.dto.SaleManagementTotalMoneyReq;
import com.readyvery.readyverydemo.src.sale.dto.SaleManagementTotalMoneyRes;
import com.readyvery.readyverydemo.src.sale.dto.SaleManagementTotalOrderReq;
import com.readyvery.readyverydemo.src.sale.dto.SaleManagementTotalOrderRes;
import com.readyvery.readyverydemo.src.sale.dto.TotalSaleRes;

import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -43,6 +47,35 @@ public SaleManagementRes getSaleManagement(@AuthenticationPrincipal CustomUserDe
return saleServiceImpl.getSaleManagementMoney(userDetails.getId(), request);
}

@Operation(summary = "월간, 주간 총 주문 건수 기능", description = "월간, 주간 총 주문 건수를 출력합니다.", tags = {"매출"})
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK"),
})
@PostMapping("/sale/management/order/total")
public SaleManagementTotalOrderRes getSaleManagementOrder(@AuthenticationPrincipal CustomUserDetails userDetails,
@RequestBody SaleManagementTotalOrderReq saleManagementTotalOrderReq) {
return saleServiceImpl.getSaleManagementOrder(userDetails.getId(), saleManagementTotalOrderReq);
}

@Operation(summary = "월간 총 매출 기능", description = "월간 총 매출을 출력합니다.", tags = {"매출"})
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK"),
})
@PostMapping("/sale/management/amount/monthly")
public SaleManagementTotalMoneyRes getMonthlySalesAmount(@AuthenticationPrincipal CustomUserDetails userDetails,
@RequestBody SaleManagementTotalMoneyReq saleManagementTotalMoneyReq) {
return saleServiceImpl.getMonthlySalesAmount(userDetails.getId(), saleManagementTotalMoneyReq);
}

@Operation(summary = "주간 총 매출 기능", description = "월 총 매출을 출력합니다.", tags = {"매출"})
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK"),
})
@PostMapping("/sale/management/amount/weekly")
public SaleManagementTotalMoneyRes getWeekSaleManagementMoney(
@AuthenticationPrincipal CustomUserDetails userDetails,
@RequestBody SaleManagementTotalMoneyReq saleManagementTotalMoneyReq) {
return saleServiceImpl.getWeekSaleManagementMoney(userDetails.getId(), saleManagementTotalMoneyReq);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ SaleManagementTotalMoneyRes getWeekSaleManagementMoney(Long id,

SaleManagementTotalMoneyRes getMonthlySalesAmount(Long id, SaleManagementTotalMoneyReq saleManagementTotalMoneyReq);

SaleManagementTotalOrderRes getWeekSaleManagementOrder(Long id,
SaleManagementTotalOrderRes getSaleManagementOrder(Long id,
SaleManagementTotalOrderReq saleManagementTotalOrderReq);

SaleManagementTotalOrderRes getMonthlySalesOrder(Long id, SaleManagementTotalOrderReq saleManagementTotalOrderReq);
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,17 @@ public SaleManagementRes getSaleManagementMoney(Long id, SaleManagementReq saleM
.build();
}

// TODO: getWeekSaleManagementMoney, getMonthlySalesAmount 합치기
@Override
public SaleManagementTotalMoneyRes getWeekSaleManagementMoney(Long id,
SaleManagementTotalMoneyReq saleManagementTotalMoneyReq) {
CeoInfo ceoInfo = ceoServiceFacade.getCeoInfo(id);
Optional<Long> saleManagementTotal = sumTotalAmountByStoreIdForWeek(ceoInfo.getStore().getId(),
getStartOfMonth(convertToDateTime(saleManagementTotalMoneyReq.getMonday())),
getEndOfMonth(convertToDateTime(saleManagementTotalMoneyReq.getMonday())));
getStartOfWeek(convertToDateTime(saleManagementTotalMoneyReq.getMonday())),
getStartOfWeek(convertToDateTime(saleManagementTotalMoneyReq.getMonday())).plusDays(7));

return SaleManagementTotalMoneyRes.builder()
.message("해당 주차 매출관리 조회 성공")
.message("해당 주차 총 매출 조회 성공")
.success(true)
.totalMoney(saleManagementTotal)
.build();
Expand All @@ -84,39 +85,28 @@ public SaleManagementTotalMoneyRes getMonthlySalesAmount(Long id,
getEndOfMonth(convertToDateTime(saleManagementTotalMoneyReq.getMonday())));

return SaleManagementTotalMoneyRes.builder()
.message("해당 월 매출관리 조회 성공")
.message("해당 월 총 매출 조회 성공")
.success(true)
.totalMoney(saleManagementTotal)
.build();
}

@Override
public SaleManagementTotalOrderRes getWeekSaleManagementOrder(Long id,
public SaleManagementTotalOrderRes getSaleManagementOrder(Long id,
SaleManagementTotalOrderReq saleManagementTotalOrderReq) {
CeoInfo ceoInfo = ceoServiceFacade.getCeoInfo(id);
Long saleManagementTotal = countOrdersByStoreIdForWeek(ceoInfo.getStore().getId(),
Long saleManagementWeekTotal = countOrdersByStoreIdForWeek(ceoInfo.getStore().getId(),
getStartOfWeek(convertToDateTime(saleManagementTotalOrderReq.getMonday())),
getStartOfWeek(convertToDateTime(saleManagementTotalOrderReq.getMonday())).plusDays(7));
Long saleManagementMonthTotal = countOrdersByStoreIdForMonth(ceoInfo.getStore().getId(),
getStartOfMonth(convertToDateTime(saleManagementTotalOrderReq.getMonday())),
getEndOfMonth(convertToDateTime(saleManagementTotalOrderReq.getMonday())));

return SaleManagementTotalOrderRes.builder()
.message("해당 주차 매출관리 조회 성공")
.message("해당 주차, 월 총 주문 건수 조회 성공")
.success(true)
.totalOrder(saleManagementTotal)
.build();
}

@Override
public SaleManagementTotalOrderRes getMonthlySalesOrder(Long id,
SaleManagementTotalOrderReq saleManagementTotalOrderReq) {
CeoInfo ceoInfo = ceoServiceFacade.getCeoInfo(id);
Long saleManagementTotal = countOrdersByStoreIdForMonth(ceoInfo.getStore().getId(),
getStartOfMonth(convertToDateTime(saleManagementTotalOrderReq.getMonday())),
getEndOfMonth(convertToDateTime(saleManagementTotalOrderReq.getMonday())));

return SaleManagementTotalOrderRes.builder()
.message("해당 월 매출관리 조회 성공")
.success(true)
.totalOrder(saleManagementTotal)
.totalWeekOrder(saleManagementWeekTotal)
.totalMonthOrder(saleManagementMonthTotal)
.build();
}

Expand All @@ -132,12 +122,6 @@ public List<SaleManagementDto> getSaleMoneyManagement(Long id, LocalDateTime day
return getSaleManagementMoneyData(id, startDateTime, endDateTime);
}

public List<SaleManagementDto> getSaleOrderManagement(Long id, LocalDateTime day) {
LocalDateTime startDateTime = day;
LocalDateTime endDateTime = day.plusDays(7);
return getSaleManagementOrderData(id, startDateTime, endDateTime);
}

public Optional<Long> sumTotalAmountByStoreIdForMonth(Long storeId, LocalDateTime startOfMonth,
LocalDateTime endOfMonth) {
return orderRepository.sumTotalAmountByStoreIdForMonth(storeId, startOfMonth, endOfMonth);
Expand Down Expand Up @@ -176,24 +160,6 @@ public List<SaleManagementDto> getSaleManagementMoneyData(Long storeId, LocalDat
return resultWithAllDays;
}

public List<SaleManagementDto> getSaleManagementOrderData(Long storeId, LocalDateTime startDate,
LocalDateTime endDate) {
List<SaleManagementDto> queryResult = orderRepository.sumTotalAmountPerDayBetweenDates(storeId, startDate,
endDate);
List<SaleManagementDto> resultWithAllDays = initializeWeekData();

Map<String, SaleManagementDto> resultMap = queryResult.stream()
.collect(Collectors.toMap(SaleManagementDto::getDay, Function.identity()));

resultWithAllDays.forEach(dayDto -> {
if (resultMap.containsKey(dayDto.getDay())) {
dayDto.setSale(resultMap.get(dayDto.getDay()).getSale());
}
});

return resultWithAllDays;
}

private List<SaleManagementDto> initializeWeekData() {
return Arrays.asList(
new SaleManagementDto("Monday", 0L),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
public class SaleManagementTotalOrderRes {
private String message;
private boolean success;
private Long totalOrder;
private Long totalWeekOrder;
private Long totalMonthOrder;

}

0 comments on commit 486a07f

Please sign in to comment.