Skip to content

Commit

Permalink
Merge pull request #136 from phuuthanh-dev/develop
Browse files Browse the repository at this point in the history
dashboard
  • Loading branch information
phuuthanh-dev authored Jul 16, 2024
2 parents cdb58d6 + 81b0458 commit 519380d
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ public ResponseEntity<DashBoardResponse> 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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/vn/webapp/backend/auction/model/Jewelry.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Page<Auction> 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,31 @@ Page<Jewelry> findJewelryByStateAndIsHolding(
@Query("SELECT j FROM Jewelry j ORDER BY j.id DESC")
List<Jewelry> 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ Page<RequestApproval> findRequestNeedConfirmByMember(
"ORDER BY ra.isConfirm ASC")
Page<RequestApproval> 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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 519380d

Please sign in to comment.