Skip to content
Extraits de code Groupes Projets
Valider 9fb947f0 rédigé par hamza.elbakkouri's avatar hamza.elbakkouri
Parcourir les fichiers

MYS-739/fix sales sessions details

parent 4da3fe9e
Branches
1 requête de fusion!114MYD-739/Fix List with sale sessions stats
...@@ -41,6 +41,13 @@ public class SaleSessionController { ...@@ -41,6 +41,13 @@ public class SaleSessionController {
return new ResponseEntity<>(saleSessions, HttpStatus.OK); return new ResponseEntity<>(saleSessions, HttpStatus.OK);
} }
@GetMapping("/rangeSaleSessions/{start}/{end}")
@PreAuthorize("@securityCustomExpressions.isClientTrusted(#requestAuthorization)")
public ResponseEntity<List<SaleSessionDTO>> rangeSaleSessions(@PathVariable LocalDateTime start,@PathVariable LocalDateTime end, @RequestHeader String requestAuthorization) {
List<SaleSessionDTO> saleSessions = saleSessionService.exportSaleSessions(start, end);
return new ResponseEntity<>(saleSessions, HttpStatus.OK);
}
@PostMapping("/addProductToCartFromLive") @PostMapping("/addProductToCartFromLive")
@PreAuthorize("@securityCustomExpressions.isClientTrusted(#requestAuthorization)") @PreAuthorize("@securityCustomExpressions.isClientTrusted(#requestAuthorization)")
public CompletableFuture<ResponseEntity<?>> addProductToCartFromLive( public CompletableFuture<ResponseEntity<?>> addProductToCartFromLive(
...@@ -125,7 +132,7 @@ public class SaleSessionController { ...@@ -125,7 +132,7 @@ public class SaleSessionController {
@DeleteMapping("/deleteSession/{id}") @DeleteMapping("/deleteSession/{id}")
@PreAuthorize("hasRole('ADMIN') and @securityCustomExpressions.isClientTrusted(#requestAuthorization)") @PreAuthorize("hasRole('ADMIN') and @securityCustomExpressions.isClientTrusted(#requestAuthorization)")
public ResponseEntity<Void> deleteSaleSessionById(@PathVariable Long id,@RequestHeader String requestAuthorization) { public ResponseEntity<Void> deleteSaleSessionById(@PathVariable Long id, @RequestHeader String requestAuthorization) {
try { try {
saleSessionService.deleteSaleSessionById(id); saleSessionService.deleteSaleSessionById(id);
return ResponseEntity.noContent().build(); return ResponseEntity.noContent().build();
...@@ -133,6 +140,7 @@ public class SaleSessionController { ...@@ -133,6 +140,7 @@ public class SaleSessionController {
return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
} }
} }
@PutMapping("/restock/{sessionId}") @PutMapping("/restock/{sessionId}")
public ResponseEntity<SaleSessionDTO> restockSaleSession(@PathVariable Long sessionId) { public ResponseEntity<SaleSessionDTO> restockSaleSession(@PathVariable Long sessionId) {
SaleSessionDTO updatedSession = saleSessionService.restockSaleSession(sessionId); SaleSessionDTO updatedSession = saleSessionService.restockSaleSession(sessionId);
......
...@@ -7,6 +7,7 @@ import org.springframework.data.jpa.repository.Query; ...@@ -7,6 +7,7 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
@Repository @Repository
...@@ -68,4 +69,6 @@ public interface SaleSessionRepository extends JpaRepository<SaleSession, Long> ...@@ -68,4 +69,6 @@ public interface SaleSessionRepository extends JpaRepository<SaleSession, Long>
"JOIN so.itemCart ic " + "JOIN so.itemCart ic " +
"WHERE ss.id = :sessionId") "WHERE ss.id = :sessionId")
Long getTotalPaidProducts(@Param("sessionId") Long sessionId); Long getTotalPaidProducts(@Param("sessionId") Long sessionId);
List<SaleSession> findByStartedDateBetween(LocalDateTime startDate, LocalDateTime endDate);
} }
...@@ -17,6 +17,7 @@ public interface SaleSessionService { ...@@ -17,6 +17,7 @@ public interface SaleSessionService {
SaleSessionDTO createSaleSession(SaleSession saleSession); SaleSessionDTO createSaleSession(SaleSession saleSession);
List<SaleSessionDTO> getAllSaleSessions(); List<SaleSessionDTO> getAllSaleSessions();
List<SaleSessionDTO> exportSaleSessions(LocalDateTime startDate, LocalDateTime endDate);
SaleSessionDTO getSaleSessionStatistics(SaleSession saleSession); SaleSessionDTO getSaleSessionStatistics(SaleSession saleSession);
......
...@@ -19,6 +19,7 @@ import com.marketingconfort.mydressin.repositories.SaleSessionRepository; ...@@ -19,6 +19,7 @@ import com.marketingconfort.mydressin.repositories.SaleSessionRepository;
import com.marketingconfort.mydressin.repositories.SessionOrderRepository; import com.marketingconfort.mydressin.repositories.SessionOrderRepository;
import com.marketingconfort.mydressin.services.*; import com.marketingconfort.mydressin.services.*;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -34,6 +35,7 @@ import java.util.stream.Collectors; ...@@ -34,6 +35,7 @@ import java.util.stream.Collectors;
@AllArgsConstructor @AllArgsConstructor
@Service @Service
@Slf4j
public class SaleSessionServiceImp implements SaleSessionService { public class SaleSessionServiceImp implements SaleSessionService {
private final SaleSessionRepository saleSessionRepository; private final SaleSessionRepository saleSessionRepository;
private final SaleSessionMapper saleSessionMapper; private final SaleSessionMapper saleSessionMapper;
...@@ -59,6 +61,13 @@ public class SaleSessionServiceImp implements SaleSessionService { ...@@ -59,6 +61,13 @@ public class SaleSessionServiceImp implements SaleSessionService {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@Override
public List<SaleSessionDTO> exportSaleSessions(LocalDateTime startDate, LocalDateTime endDate) {
return saleSessionRepository.findByStartedDateBetween(startDate, endDate).stream()
.map(this::getSaleSessionStatistics)
.collect(Collectors.toList());
}
@Override @Override
public SaleSessionDTO getSaleSessionStatistics(SaleSession saleSession) { public SaleSessionDTO getSaleSessionStatistics(SaleSession saleSession) {
...@@ -70,11 +79,13 @@ public class SaleSessionServiceImp implements SaleSessionService { ...@@ -70,11 +79,13 @@ public class SaleSessionServiceImp implements SaleSessionService {
); );
Long totalOrderProducts = saleSessionRepository.getTotalOrderProducts(saleSessionDTO.getId()); Long totalOrderProducts = saleSessionRepository.getTotalOrderProducts(saleSessionDTO.getId());
Integer totalClientsCount = saleSessionRepository.getTotalClientsCount(saleSessionDTO.getId()); Integer totalClientsCount = saleSessionRepository.getTotalClientsCount(saleSessionDTO.getId());
Double totalSalesAmount = saleSessionRepository.getTotalSalesAmount(saleSessionDTO.getId(),excludedStatuses); Double totalSalesAmount = saleSessionRepository.getTotalSalesAmount(saleSessionDTO.getId(), excludedStatuses);
Long totalConsultedProducts = saleSessionRepository.getTotalConsultedProducts(saleSessionDTO.getId()); Long totalConsultedProducts = saleSessionRepository.getTotalConsultedProducts(saleSessionDTO.getId());
Long totalDeletedProducts = saleSessionRepository.getTotalDeletedProducts(saleSessionDTO.getId()); Long totalDeletedProducts = saleSessionRepository.getTotalDeletedProducts(saleSessionDTO.getId());
Long totalPaidProducts = saleSessionRepository.getTotalPaidProducts(saleSessionDTO.getId()); Long totalPaidProducts = saleSessionRepository.getTotalPaidProducts(saleSessionDTO.getId());
saleSessionDTO.setOrderProductsNumber(totalOrderProducts != null ? totalOrderProducts : 0); saleSessionDTO.setOrderProductsNumber(totalOrderProducts != null ? totalOrderProducts : 0);
saleSessionDTO.setClientsNumber(totalClientsCount != null ? totalClientsCount : 0); saleSessionDTO.setClientsNumber(totalClientsCount != null ? totalClientsCount : 0);
saleSessionDTO.setTotalSales(totalSalesAmount != null ? totalSalesAmount : 0.0); saleSessionDTO.setTotalSales(totalSalesAmount != null ? totalSalesAmount : 0.0);
...@@ -134,18 +145,18 @@ public class SaleSessionServiceImp implements SaleSessionService { ...@@ -134,18 +145,18 @@ public class SaleSessionServiceImp implements SaleSessionService {
if (cart instanceof Cart) { if (cart instanceof Cart) {
existingItemCart = ((Cart) cart).getItems().stream() existingItemCart = ((Cart) cart).getItems().stream()
.filter(item -> item.getProductId().equals(request.getProductId()) .filter(item -> item.getProductId().equals(request.getProductId())
&& item.getSource() == ItemSource.LIVE && item.getSource() == ItemSource.LIVE
&& Objects.equals(item.getOrder().getSaleSession().getId(), request.getSessionId()) && Objects.equals(item.getOrder().getSaleSession().getId(), request.getSessionId())
&& item.getStatus() != ItemCartStatus.DELETED_BO && item.getStatus() != ItemCartStatus.DELETED_BO
&& item.getStatus() != ItemCartStatus.DELETED_SITE) && item.getStatus() != ItemCartStatus.DELETED_SITE)
.findFirst(); .findFirst();
} else { } else {
existingItemCart = ((UnregisteredCart) cart).getItems().stream() existingItemCart = ((UnregisteredCart) cart).getItems().stream()
.filter(item -> item.getProductId().equals(request.getProductId()) .filter(item -> item.getProductId().equals(request.getProductId())
&& item.getSource() == ItemSource.LIVE && item.getSource() == ItemSource.LIVE
&& Objects.equals(item.getOrder().getSaleSession().getId(), request.getSessionId()) && Objects.equals(item.getOrder().getSaleSession().getId(), request.getSessionId())
&& item.getStatus() != ItemCartStatus.DELETED_BO && item.getStatus() != ItemCartStatus.DELETED_BO
&& item.getStatus() != ItemCartStatus.DELETED_SITE) && item.getStatus() != ItemCartStatus.DELETED_SITE)
.findFirst(); .findFirst();
} }
ItemCart itemCart; ItemCart itemCart;
...@@ -169,7 +180,7 @@ public class SaleSessionServiceImp implements SaleSessionService { ...@@ -169,7 +180,7 @@ public class SaleSessionServiceImp implements SaleSessionService {
itemCart.setProduct(stockResult.getProductDTO()); itemCart.setProduct(stockResult.getProductDTO());
if (itemCart.getProduct() != null) { if (itemCart.getProduct() != null) {
double price = (itemCart.getProduct().getPromoPrice() != 0) ? itemCart.getProduct().getPromoPrice() : itemCart.getProduct().getRegularPrice(); double price = (itemCart.getProduct().getPromoPrice() != 0) ? itemCart.getProduct().getPromoPrice() : itemCart.getProduct().getRegularPrice();
order.setOrderPrice(price* itemCart.getQuantity()); order.setOrderPrice(price * itemCart.getQuantity());
} }
orderRepository.save(order); orderRepository.save(order);
......
0% ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter