diff --git a/CHANGELOG.md b/CHANGELOG.md index 97721a4c2d126c972a23a84ab18128d22739c669..2f5bee398895c4dd60d0c8d45d0ad461b54047f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,22 @@ +## [1.0.73-RELEASE] +### Added +- MYD-739/Fix List with sale sessions stats + +### Changed +- Changes in existing functionality. + +### Deprecated +- Soon-to-be removed features. + +### Removed +- Features that have been removed. + +### Fixed +- fix item count + +### Security +- Any security improvements. + ## [1.0.72-RELEASE] ### Added - MYD-628/add pagination, sort and search for deleted sale session diff --git a/src/main/java/com/marketingconfort/mydressin/controllers/SaleSessionController.java b/src/main/java/com/marketingconfort/mydressin/controllers/SaleSessionController.java index 45b124d4ffee364c1484c51f39d729b43327679c..4f2c6cd8349442dcda7acea178d650747ab9357c 100644 --- a/src/main/java/com/marketingconfort/mydressin/controllers/SaleSessionController.java +++ b/src/main/java/com/marketingconfort/mydressin/controllers/SaleSessionController.java @@ -44,6 +44,13 @@ public class SaleSessionController { 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") @PreAuthorize("@securityCustomExpressions.isClientTrusted(#requestAuthorization)") public CompletableFuture<ResponseEntity<?>> addProductToCartFromLive( @@ -128,7 +135,7 @@ public class SaleSessionController { @DeleteMapping("/deleteSession/{id}") @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 { saleSessionService.deleteSaleSessionById(id); return ResponseEntity.noContent().build(); @@ -136,6 +143,7 @@ public class SaleSessionController { return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); } } + @PutMapping("/restock/{sessionId}") public ResponseEntity<SaleSessionDTO> restockSaleSession(@PathVariable Long sessionId) { SaleSessionDTO updatedSession = saleSessionService.restockSaleSession(sessionId); diff --git a/src/main/java/com/marketingconfort/mydressin/repositories/SaleSessionRepository.java b/src/main/java/com/marketingconfort/mydressin/repositories/SaleSessionRepository.java index 1b10344c612b2e353cfebe5c3fa01570fddee3e7..15e4d76c6867796a1bcf13e8197ec72c67cbed79 100644 --- a/src/main/java/com/marketingconfort/mydressin/repositories/SaleSessionRepository.java +++ b/src/main/java/com/marketingconfort/mydressin/repositories/SaleSessionRepository.java @@ -9,6 +9,7 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import java.time.LocalDateTime; import java.util.Date; import java.util.List; @@ -72,6 +73,8 @@ public interface SaleSessionRepository extends JpaRepository<SaleSession, Long> "WHERE ss.id = :sessionId") Long getTotalPaidProducts(@Param("sessionId") Long sessionId); + List<SaleSession> findByStartedDateBetween(LocalDateTime startDate, LocalDateTime endDate); + @Query("SELECT sl FROM SaleSession sl WHERE " + "(:name IS NULL OR :name = '' OR LOWER(sl.name) LIKE LOWER(CONCAT('%', :name, '%'))) " + "AND (:type IS NULL OR :type = '' OR LOWER(sl.type) like LOWER(CONCAT('%', :type,'%')))" + diff --git a/src/main/java/com/marketingconfort/mydressin/services/SaleSessionService.java b/src/main/java/com/marketingconfort/mydressin/services/SaleSessionService.java index 7d93f429adaf9bac6493858fc58fa45df4c19a9f..a0314fc418b52ec3a07796568b9b39deef2fde87 100644 --- a/src/main/java/com/marketingconfort/mydressin/services/SaleSessionService.java +++ b/src/main/java/com/marketingconfort/mydressin/services/SaleSessionService.java @@ -19,6 +19,7 @@ public interface SaleSessionService { SaleSessionDTO createSaleSession(SaleSession saleSession); List<SaleSessionDTO> getAllSaleSessions(); + List<SaleSessionDTO> exportSaleSessions(LocalDateTime startDate, LocalDateTime endDate); SaleSessionDTO getSaleSessionStatistics(SaleSession saleSession); diff --git a/src/main/java/com/marketingconfort/mydressin/services/impl/SaleSessionServiceImp.java b/src/main/java/com/marketingconfort/mydressin/services/impl/SaleSessionServiceImp.java index abb4cab3bd1377d8328de2402318211347fbe083..2bcc9063e872192c3f2c3fd4cf785e09a13734ec 100644 --- a/src/main/java/com/marketingconfort/mydressin/services/impl/SaleSessionServiceImp.java +++ b/src/main/java/com/marketingconfort/mydressin/services/impl/SaleSessionServiceImp.java @@ -19,6 +19,7 @@ import com.marketingconfort.mydressin.repositories.SaleSessionRepository; import com.marketingconfort.mydressin.repositories.SessionOrderRepository; import com.marketingconfort.mydressin.services.*; import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -35,6 +36,7 @@ import java.util.stream.Collectors; @AllArgsConstructor @Service +@Slf4j public class SaleSessionServiceImp implements SaleSessionService { private final SaleSessionRepository saleSessionRepository; private final SaleSessionMapper saleSessionMapper; @@ -60,6 +62,13 @@ public class SaleSessionServiceImp implements SaleSessionService { .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 public SaleSessionDTO getSaleSessionStatistics(SaleSession saleSession) { @@ -71,11 +80,13 @@ public class SaleSessionServiceImp implements SaleSessionService { ); Long totalOrderProducts = saleSessionRepository.getTotalOrderProducts(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 totalDeletedProducts = saleSessionRepository.getTotalDeletedProducts(saleSessionDTO.getId()); Long totalPaidProducts = saleSessionRepository.getTotalPaidProducts(saleSessionDTO.getId()); + + saleSessionDTO.setOrderProductsNumber(totalOrderProducts != null ? totalOrderProducts : 0); saleSessionDTO.setClientsNumber(totalClientsCount != null ? totalClientsCount : 0); saleSessionDTO.setTotalSales(totalSalesAmount != null ? totalSalesAmount : 0.0); @@ -135,18 +146,18 @@ public class SaleSessionServiceImp implements SaleSessionService { if (cart instanceof Cart) { existingItemCart = ((Cart) cart).getItems().stream() .filter(item -> item.getProductId().equals(request.getProductId()) - && item.getSource() == ItemSource.LIVE - && Objects.equals(item.getOrder().getSaleSession().getId(), request.getSessionId()) - && item.getStatus() != ItemCartStatus.DELETED_BO - && item.getStatus() != ItemCartStatus.DELETED_SITE) + && item.getSource() == ItemSource.LIVE + && Objects.equals(item.getOrder().getSaleSession().getId(), request.getSessionId()) + && item.getStatus() != ItemCartStatus.DELETED_BO + && item.getStatus() != ItemCartStatus.DELETED_SITE) .findFirst(); } else { existingItemCart = ((UnregisteredCart) cart).getItems().stream() .filter(item -> item.getProductId().equals(request.getProductId()) - && item.getSource() == ItemSource.LIVE - && Objects.equals(item.getOrder().getSaleSession().getId(), request.getSessionId()) - && item.getStatus() != ItemCartStatus.DELETED_BO - && item.getStatus() != ItemCartStatus.DELETED_SITE) + && item.getSource() == ItemSource.LIVE + && Objects.equals(item.getOrder().getSaleSession().getId(), request.getSessionId()) + && item.getStatus() != ItemCartStatus.DELETED_BO + && item.getStatus() != ItemCartStatus.DELETED_SITE) .findFirst(); } ItemCart itemCart; @@ -170,7 +181,7 @@ public class SaleSessionServiceImp implements SaleSessionService { itemCart.setProduct(stockResult.getProductDTO()); if (itemCart.getProduct() != null) { 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); @@ -254,7 +265,7 @@ public class SaleSessionServiceImp implements SaleSessionService { Pageable pageable = PageRequest.of(page, size, Sort.by(direction, sortBy)); return saleSessionRepository.getSaleSessionsPage(type,name,startDate,endDate,pageable) - .map(saleSessionMapper::toDTO); + .map(this::getSaleSessionStatistics); } @Override