Skip to content
Extraits de code Groupes Projets
Valider c23820c9 rédigé par Mohamed Lemine BAILLAHI's avatar Mohamed Lemine BAILLAHI
Parcourir les fichiers

Merge branch 'feature/MYD-739' into 'develop'

MYD-739/Fix List with sale sessions stats

Closes MYD-739

See merge request !114
parents 3b0f0dbe 29339dcc
Branches
Étiquettes 0.0.94-RELEASE
1 requête de fusion!114MYD-739/Fix List with sale sessions stats
Pipeline #12140 en échec avec les étapes
in 27 secondes
## [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] ## [1.0.72-RELEASE]
### Added ### Added
- MYD-628/add pagination, sort and search for deleted sale session - MYD-628/add pagination, sort and search for deleted sale session
......
...@@ -44,6 +44,13 @@ public class SaleSessionController { ...@@ -44,6 +44,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(
...@@ -128,7 +135,7 @@ public class SaleSessionController { ...@@ -128,7 +135,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();
...@@ -136,6 +143,7 @@ public class SaleSessionController { ...@@ -136,6 +143,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);
......
...@@ -9,6 +9,7 @@ import org.springframework.data.jpa.repository.Query; ...@@ -9,6 +9,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.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -72,6 +73,8 @@ public interface SaleSessionRepository extends JpaRepository<SaleSession, Long> ...@@ -72,6 +73,8 @@ public interface SaleSessionRepository extends JpaRepository<SaleSession, Long>
"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);
@Query("SELECT sl FROM SaleSession sl WHERE " + @Query("SELECT sl FROM SaleSession sl WHERE " +
"(:name IS NULL OR :name = '' OR LOWER(sl.name) LIKE LOWER(CONCAT('%', :name, '%'))) " + "(: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,'%')))" + "AND (:type IS NULL OR :type = '' OR LOWER(sl.type) like LOWER(CONCAT('%', :type,'%')))" +
......
...@@ -19,6 +19,7 @@ public interface SaleSessionService { ...@@ -19,6 +19,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.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
...@@ -35,6 +36,7 @@ import java.util.stream.Collectors; ...@@ -35,6 +36,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;
...@@ -60,6 +62,13 @@ public class SaleSessionServiceImp implements SaleSessionService { ...@@ -60,6 +62,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) {
...@@ -71,11 +80,13 @@ public class SaleSessionServiceImp implements SaleSessionService { ...@@ -71,11 +80,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);
...@@ -135,18 +146,18 @@ public class SaleSessionServiceImp implements SaleSessionService { ...@@ -135,18 +146,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;
...@@ -170,7 +181,7 @@ public class SaleSessionServiceImp implements SaleSessionService { ...@@ -170,7 +181,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);
...@@ -254,7 +265,7 @@ public class SaleSessionServiceImp implements SaleSessionService { ...@@ -254,7 +265,7 @@ public class SaleSessionServiceImp implements SaleSessionService {
Pageable pageable = PageRequest.of(page, size, Sort.by(direction, sortBy)); Pageable pageable = PageRequest.of(page, size, Sort.by(direction, sortBy));
return saleSessionRepository.getSaleSessionsPage(type,name,startDate,endDate,pageable) return saleSessionRepository.getSaleSessionsPage(type,name,startDate,endDate,pageable)
.map(saleSessionMapper::toDTO); .map(this::getSaleSessionStatistics);
} }
@Override @Override
......
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