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
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]
### Added
- MYD-628/add pagination, sort and search for deleted sale session
......
......@@ -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);
......
......@@ -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,'%')))" +
......
......@@ -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);
......
......@@ -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
......
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