Skip to content

Commit

Permalink
FEAT:fiing
Browse files Browse the repository at this point in the history
  • Loading branch information
rivopelu committed Nov 28, 2024
1 parent 54c015e commit 98ade90
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class AnalyticsControllerImpl implements AnalyticsController {

@Override
public BaseResponse getAnalyticsSummary() {

return ResponseHelper.createBaseResponse(analyticsService.getAnalyticsSummary());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.math.BigInteger;
import java.util.Arrays;
import java.util.List;

public interface OrderProductRepository extends JpaRepository<OrderProduct, String> {
List<OrderProduct> findAllByOrderId(String order_id);

@Query(value = "select sum(op.qty) from OrderProduct as op where op.clientId = :clientId")
BigInteger getSumQty(String clientId);

}
2 changes: 2 additions & 0 deletions src/main/java/com/pos/app/repositories/OrderRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public interface OrderRepository extends JpaRepository<Order, String> {


List<Order> findAllByClientIdAndStatusOrderByUpdatedDateAsc(String clientId, OrderStatusEnum status);

BigInteger countByClientId(String clientId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.math.BigInteger;
import java.util.List;

public interface TransactionRepository extends JpaRepository<Transaction, String> {
List<Transaction> findAllByOrderId(String order_id);

@Query(value = "select sum(t.totalTransaction) from Transaction as t where t.clientId = :clientId")
BigInteger sumTransactionByClientId(String clientId);
}
31 changes: 30 additions & 1 deletion src/main/java/com/pos/app/service/impl/AnalyticsServiceImpl.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,42 @@
package com.pos.app.service.impl;

import com.pos.app.exception.SystemErrorException;
import com.pos.app.model.response.ResponseAnalyticsSummary;
import com.pos.app.repositories.OrderProductRepository;
import com.pos.app.repositories.OrderRepository;
import com.pos.app.repositories.TransactionRepository;
import com.pos.app.service.AccountService;
import com.pos.app.service.AnalyticsService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.math.BigInteger;

@Service
@RequiredArgsConstructor
public class AnalyticsServiceImpl implements AnalyticsService {

private final OrderRepository orderRepository;
private final AccountService accountService;
private final TransactionRepository transactionRepository;
private final OrderProductRepository orderProductRepository;

@Override
public ResponseAnalyticsSummary getAnalyticsSummary() {
return null;
String clientId = accountService.getCurrentClientIdOrNull();
try {
BigInteger getCountTotalOrder = orderRepository.countByClientId(clientId);
BigInteger getTotalRevenue = transactionRepository.sumTransactionByClientId(clientId);
BigInteger getTotalItems = orderProductRepository.getSumQty(clientId);

return ResponseAnalyticsSummary.builder()
.totalOrder(getCountTotalOrder)
.totalRevenue(getTotalRevenue)
.totalItems(getTotalItems)
.build();

} catch (Exception e) {
throw new SystemErrorException(e);
}
}
}

0 comments on commit 98ade90

Please sign in to comment.