From 81b045841c5920caaa11506a3252591b73ec65da Mon Sep 17 00:00:00 2001 From: Phung Huu Thanh <102614541+phuuthanh2003@users.noreply.github.com> Date: Tue, 16 Jul 2024 21:12:28 +0700 Subject: [PATCH] dashboard --- .../controller/DashBoardController.java | 4 ++- .../auction/dto/DashBoardResponse.java | 7 ++++-- .../webapp/backend/auction/model/Jewelry.java | 3 +++ .../AuctionRegistrationRepository.java | 1 - .../auction/repository/AuctionRepository.java | 2 +- .../auction/repository/JewelryRepository.java | 25 +++++++++++++++++++ .../repository/RequestApprovalRepository.java | 6 +++-- .../service/dashboard/DashBoardService.java | 17 ++++++++----- .../service/jewelry/JewelryServiceImpl.java | 3 ++- 9 files changed, 54 insertions(+), 14 deletions(-) diff --git a/src/main/java/vn/webapp/backend/auction/controller/DashBoardController.java b/src/main/java/vn/webapp/backend/auction/controller/DashBoardController.java index 719db2b..834da1e 100644 --- a/src/main/java/vn/webapp/backend/auction/controller/DashBoardController.java +++ b/src/main/java/vn/webapp/backend/auction/controller/DashBoardController.java @@ -21,10 +21,12 @@ public ResponseEntity getDashBoardTotal( @RequestParam("yearGetRevenue") Integer yearGetRevenue, @RequestParam("yearGetAuctionFailedAndSuccess") Integer yearGetAuctionFailedAndSuccess, @RequestParam("monthGetAuctionFailedAndSuccess") Integer monthGetAuctionFailedAndSuccess, + @RequestParam("yearGetJewelry") Integer yearGetJewelry, + @RequestParam("monthGetJewelry") Integer monthGetJewelry, @RequestParam("yearGetUserJoinAuction") Integer yearGetUserJoinAuction ) { return ResponseEntity.ok(dashBoardService.getInformation(yearGetRegisterAccount, yearGetAuction, yearGetRevenue, - yearGetAuctionFailedAndSuccess, monthGetAuctionFailedAndSuccess, + yearGetAuctionFailedAndSuccess, monthGetAuctionFailedAndSuccess, yearGetJewelry, monthGetJewelry, yearGetUserJoinAuction)); } } diff --git a/src/main/java/vn/webapp/backend/auction/dto/DashBoardResponse.java b/src/main/java/vn/webapp/backend/auction/dto/DashBoardResponse.java index 1e1b059..ec93156 100644 --- a/src/main/java/vn/webapp/backend/auction/dto/DashBoardResponse.java +++ b/src/main/java/vn/webapp/backend/auction/dto/DashBoardResponse.java @@ -12,8 +12,11 @@ public class DashBoardResponse { private Double totalRevenueToday; private Integer totalUser; - private Integer totalJewelryActive; - private Integer totalJewelryWaitApproving; + private Integer totalJewelryPricing; + private Integer totalJewelryPriced; + private Integer totalJewelryNotHasAuction; + private Integer totalJewelryHasAuction; + private Integer totalJewelryHandover; private Integer totalAuctionJewelry; private Integer totalUsersVerified; private Integer totalUsersActive; diff --git a/src/main/java/vn/webapp/backend/auction/model/Jewelry.java b/src/main/java/vn/webapp/backend/auction/model/Jewelry.java index a59e042..7ebf1d3 100644 --- a/src/main/java/vn/webapp/backend/auction/model/Jewelry.java +++ b/src/main/java/vn/webapp/backend/auction/model/Jewelry.java @@ -50,6 +50,9 @@ public class Jewelry { @Column(name = "delivery_date") private Timestamp deliveryDate; + @Column(name = "create_date") + private Timestamp createDate; + @Column(name = "state", nullable = false) @Enumerated(EnumType.STRING) private JewelryState state; diff --git a/src/main/java/vn/webapp/backend/auction/repository/AuctionRegistrationRepository.java b/src/main/java/vn/webapp/backend/auction/repository/AuctionRegistrationRepository.java index 4750ec2..2074d2e 100644 --- a/src/main/java/vn/webapp/backend/auction/repository/AuctionRegistrationRepository.java +++ b/src/main/java/vn/webapp/backend/auction/repository/AuctionRegistrationRepository.java @@ -5,7 +5,6 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; -import vn.webapp.backend.auction.enums.AuctionRegistrationState; import vn.webapp.backend.auction.model.AuctionRegistration; import java.util.List; diff --git a/src/main/java/vn/webapp/backend/auction/repository/AuctionRepository.java b/src/main/java/vn/webapp/backend/auction/repository/AuctionRepository.java index e026632..8edb20e 100644 --- a/src/main/java/vn/webapp/backend/auction/repository/AuctionRepository.java +++ b/src/main/java/vn/webapp/backend/auction/repository/AuctionRepository.java @@ -53,7 +53,7 @@ Page findByStateAndCategoryNotDeletedOrEmptyState( @Query("SELECT COUNT(a) FROM Auction a WHERE a.state = 'FINISHED'") Integer countAllAuctionsFinished(); - @Query("SELECT COUNT(a) FROM Auction a WHERE a.state = 'FINISHED' " + + @Query("SELECT COUNT(a) FROM Auction a WHERE a.state = 'FINISHED' AND a.lastPrice IS NULL " + "AND a.id NOT IN (SELECT ah.auction.id FROM AuctionHistory ah) AND YEAR(a.endDate) = :year AND MONTH(a.endDate) = :month") Integer countAllAuctionsFailed(@Param("month") Integer month, @Param("year") Integer year); diff --git a/src/main/java/vn/webapp/backend/auction/repository/JewelryRepository.java b/src/main/java/vn/webapp/backend/auction/repository/JewelryRepository.java index f83c1c5..aec18a5 100644 --- a/src/main/java/vn/webapp/backend/auction/repository/JewelryRepository.java +++ b/src/main/java/vn/webapp/backend/auction/repository/JewelryRepository.java @@ -48,6 +48,31 @@ Page findJewelryByStateAndIsHolding( @Query("SELECT j FROM Jewelry j ORDER BY j.id DESC") List findLatestJewelry(); + @Query("SELECT COUNT(j) FROM Jewelry j WHERE j.isHolding IS NULL AND " + + "j.state = 'APPROVING' AND j.receivedDate IS NULL AND j.deliveryDate IS NULL " + + "AND MONTH(j.createDate) = :month AND YEAR(j.createDate) = :year") + Integer countAllJewelriesNeedPricing(@Param("month") Integer month, @Param("year") Integer year); + + @Query("SELECT COUNT(j) FROM Jewelry j WHERE j.isHolding = false AND " + + "j.state = 'ACTIVE' AND j.receivedDate IS NULL AND j.deliveryDate IS NULL " + + "AND MONTH(j.createDate) = :month AND YEAR(j.createDate) = :year") + Integer countAllJewelriesPriced(@Param("month") Integer month, @Param("year") Integer year); + + @Query("SELECT COUNT(j) FROM Jewelry j WHERE j.isHolding = true AND " + + "j.state = 'ACTIVE' AND j.receivedDate IS NOT NULL AND j.deliveryDate IS NULL " + + "AND MONTH(j.createDate) = :month AND YEAR(j.createDate) = :year") + Integer countAllJewelriesNotHasAuction(@Param("month") Integer month, @Param("year") Integer year); + + @Query("SELECT COUNT(j) FROM Jewelry j WHERE j.isHolding = true AND " + + "j.state = 'AUCTION' AND j.receivedDate IS NOT NULL AND j.deliveryDate IS NULL " + + "AND MONTH(j.createDate) = :month AND YEAR(j.createDate) = :year") + Integer countAllJewelriesHasAuction(@Param("month") Integer month, @Param("year") Integer year); + + @Query("SELECT COUNT(j) FROM Jewelry j WHERE j.isHolding = false AND " + + "j.state = 'AUCTION' AND j.receivedDate IS NOT NULL AND j.deliveryDate IS NOT NULL " + + "AND MONTH(j.createDate) = :month AND YEAR(j.createDate) = :year") + Integer countAllJewelriesHandOver(@Param("month") Integer month, @Param("year") Integer year); + @Query("SELECT COUNT(j) FROM Jewelry j WHERE j.state = :state") Integer countAllJewelriesByState(@Param("state") JewelryState state); diff --git a/src/main/java/vn/webapp/backend/auction/repository/RequestApprovalRepository.java b/src/main/java/vn/webapp/backend/auction/repository/RequestApprovalRepository.java index 18e88d3..19f4c0e 100644 --- a/src/main/java/vn/webapp/backend/auction/repository/RequestApprovalRepository.java +++ b/src/main/java/vn/webapp/backend/auction/repository/RequestApprovalRepository.java @@ -35,8 +35,10 @@ Page findRequestNeedConfirmByMember( "ORDER BY ra.isConfirm ASC") Page findRequestApprovalByUserId(@Param("id") Integer id, @Param("jewelryName") String jewelryName,@Param("category") String category, Pageable pageable); - @Query("SELECT ra FROM RequestApproval ra WHERE ra.sender.role = 'MANAGER' " + - "AND (:jewelryName IS NULL OR ra.jewelry.name LIKE %:jewelryName%) " + + @Query("SELECT ra FROM RequestApproval ra " + + "WHERE " + + "ra.sender.role = 'MANAGER' AND " + + "(:jewelryName IS NULL OR ra.jewelry.name LIKE %:jewelryName%) " + "AND (:category IS NULL OR ra.jewelry.category.name = :category) " + "AND ra.isConfirm = true AND ra.state = 'ACTIVE' " + "AND ra.jewelry.state = 'ACTIVE' AND ra.jewelry.isHolding = true") diff --git a/src/main/java/vn/webapp/backend/auction/service/dashboard/DashBoardService.java b/src/main/java/vn/webapp/backend/auction/service/dashboard/DashBoardService.java index e2e9a06..5de8245 100644 --- a/src/main/java/vn/webapp/backend/auction/service/dashboard/DashBoardService.java +++ b/src/main/java/vn/webapp/backend/auction/service/dashboard/DashBoardService.java @@ -25,15 +25,18 @@ public class DashBoardService { public DashBoardResponse getInformation(Integer yearGetRegisterAccount, Integer yearGetAuction, Integer yearGetRevenue, Integer yearGetAuctionFailedAndSuccess, Integer monthGetAuctionFailedAndSuccess, + Integer yearGetJewelry, Integer monthGetJewelry, Integer yearGetUserJoinAuction) { LocalDateTime startOfDay = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0).withNano(0); LocalDateTime startOfNextDay = startOfDay.plusDays(1); // Total counts Integer totalUser = userRepository.getTotalUser(); - Integer totalActiveJewelry = jewelryRepository.countAllJewelriesByState(JewelryState.ACTIVE); - Integer totalApprovingJewelry = jewelryRepository.countAllJewelriesByState(JewelryState.APPROVING); - Integer totalAuctionJewelry = jewelryRepository.countAllJewelriesByState(JewelryState.AUCTION); + Integer totalJewelryPricing = jewelryRepository.countAllJewelriesNeedPricing(monthGetJewelry, yearGetJewelry); + Integer totalJewelryPriced = jewelryRepository.countAllJewelriesPriced(monthGetJewelry, yearGetJewelry); + Integer totalJewelryNotHasAuction = jewelryRepository.countAllJewelriesNotHasAuction(monthGetJewelry, yearGetJewelry); + Integer totalJewelryHasAuction = jewelryRepository.countAllJewelriesHasAuction(monthGetJewelry, yearGetJewelry); + Integer totalJewelryHandover = jewelryRepository.countAllJewelriesHandOver(monthGetJewelry, yearGetJewelry); Integer auctionFailed = auctionRepository.countAllAuctionsFailed(monthGetAuctionFailedAndSuccess, yearGetAuctionFailedAndSuccess); Integer auctionSuccess = auctionRepository.countAllAuctionsSuccessful(monthGetAuctionFailedAndSuccess, yearGetAuctionFailedAndSuccess); Integer totalUsersVerified = userRepository.getTotalUserByState(AccountState.VERIFIED); @@ -87,9 +90,11 @@ public DashBoardResponse getInformation(Integer yearGetRegisterAccount, Integer return DashBoardResponse.builder() .totalUser(totalUser) .totalRevenueToday(totalRevenueToday) - .totalJewelryActive(totalActiveJewelry) - .totalJewelryWaitApproving(totalApprovingJewelry) - .totalAuctionJewelry(totalAuctionJewelry) + .totalJewelryPricing(totalJewelryPricing) + .totalJewelryPriced(totalJewelryPriced) + .totalJewelryNotHasAuction(totalJewelryNotHasAuction) + .totalJewelryHasAuction(totalJewelryHasAuction) + .totalJewelryHandover(totalJewelryHandover) .totalUsersVerified(totalUsersVerified) .totalUsersActive(totalUsersActive) .totalUsersInActive(totalUsersInActive) diff --git a/src/main/java/vn/webapp/backend/auction/service/jewelry/JewelryServiceImpl.java b/src/main/java/vn/webapp/backend/auction/service/jewelry/JewelryServiceImpl.java index e1b4363..5ea7c33 100644 --- a/src/main/java/vn/webapp/backend/auction/service/jewelry/JewelryServiceImpl.java +++ b/src/main/java/vn/webapp/backend/auction/service/jewelry/JewelryServiceImpl.java @@ -79,8 +79,9 @@ public Jewelry requestJewelry(SendJewelryFromUserRequest request) { jewelry.setWeight(request.weight()); jewelry.setCategory(category); jewelry.setBrand(request.brand()); - jewelry.setIsHolding(false); +// jewelry.setIsHolding(false); jewelry.setName(request.name()); + jewelry.setCreateDate(Timestamp.from(Instant.now())); jewelry.setState(JewelryState.APPROVING); jewelryRepository.save(jewelry);