Changes in beneficiary dashboard api

This commit is contained in:
rajesh
2025-01-02 15:08:20 +05:30
parent e2d78dbba2
commit 252a019d5f
2 changed files with 27 additions and 13 deletions

View File

@@ -1,23 +1,20 @@
package net.gepafin.tendermanagement.dao; package net.gepafin.tendermanagement.dao;
import net.gepafin.tendermanagement.entities.CompanyEntity; import net.gepafin.tendermanagement.entities.*;
import net.gepafin.tendermanagement.entities.UserEntity;
import net.gepafin.tendermanagement.entities.UserWithCompanyEntity;
import net.gepafin.tendermanagement.enums.CallStatusEnum; import net.gepafin.tendermanagement.enums.CallStatusEnum;
import net.gepafin.tendermanagement.enums.RoleStatusEnum; import net.gepafin.tendermanagement.enums.RoleStatusEnum;
import net.gepafin.tendermanagement.enums.UserStatusEnum; import net.gepafin.tendermanagement.enums.UserStatusEnum;
import net.gepafin.tendermanagement.model.response.BeneficiaryWidgetResponseBean; import net.gepafin.tendermanagement.model.response.BeneficiaryWidgetResponseBean;
import net.gepafin.tendermanagement.model.response.Widget1; import net.gepafin.tendermanagement.model.response.Widget1;
import net.gepafin.tendermanagement.model.response.SuperAdminWidgetResponseBean; import net.gepafin.tendermanagement.model.response.SuperAdminWidgetResponseBean;
import net.gepafin.tendermanagement.repositories.ApplicationRepository; import net.gepafin.tendermanagement.repositories.*;
import net.gepafin.tendermanagement.repositories.CallRepository;
import net.gepafin.tendermanagement.repositories.CompanyRepository;
import net.gepafin.tendermanagement.repositories.UserRepository;
import net.gepafin.tendermanagement.service.CompanyService; import net.gepafin.tendermanagement.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;
@Component @Component
public class DashboardDao { public class DashboardDao {
@@ -36,6 +33,9 @@ public class DashboardDao {
@Autowired @Autowired
private CompanyService companyService; private CompanyService companyService;
@Autowired
private BeneficiaryPreferredCallRepository beneficiaryPreferredCallRepository;
public SuperAdminWidgetResponseBean getDashboardWidget(UserEntity requestedUserEntity) { public SuperAdminWidgetResponseBean getDashboardWidget(UserEntity requestedUserEntity) {
SuperAdminWidgetResponseBean widgetResponseBean = new SuperAdminWidgetResponseBean(); SuperAdminWidgetResponseBean widgetResponseBean = new SuperAdminWidgetResponseBean();
@@ -109,11 +109,23 @@ public class DashboardDao {
CompanyEntity company) { CompanyEntity company) {
BeneficiaryWidgetResponseBean beneficiaryWidgetResponseBean = BeneficiaryWidgetResponseBean.builder() BeneficiaryWidgetResponseBean beneficiaryWidgetResponseBean = BeneficiaryWidgetResponseBean.builder()
.numberOfApplications(0L).numberOfCalls(0L).numberOfIntegratedDocuments(0L).build(); .numberOfApplications(0L).numberOfCalls(0L).numberOfIntegratedDocuments(0L).build();
Long activeCalls = callRepository.countByStatusAndHubId(CallStatusEnum.PUBLISH.getValue(), userEntity.getHub().getId());
if (activeCalls != null) {
beneficiaryWidgetResponseBean.setNumberOfCalls(activeCalls);
}
UserWithCompanyEntity userWithCompanyEntity = companyService.getUserWithCompany(userEntity.getId(), company.getId()); UserWithCompanyEntity userWithCompanyEntity = companyService.getUserWithCompany(userEntity.getId(), company.getId());
List<BeneficiaryPreferredCallEntity> preferredCalls = beneficiaryPreferredCallRepository
.findByUserIdAndUserWithCompanyIdAndIsDeletedFalse(userEntity.getId(), userWithCompanyEntity.getId());
if (preferredCalls != null && !preferredCalls.isEmpty()) {
List<Long> callIds = preferredCalls.stream()
.map(BeneficiaryPreferredCallEntity::getCallId)
.collect(Collectors.toList());
List<CallEntity> callEntities = callRepository.findByIdIn(callIds);
long activeCallsCount = callEntities.stream()
.filter(call -> CallStatusEnum.PUBLISH.getValue().equals(call.getStatus())
&& userEntity.getHub().getId().equals(call.getHub().getId()))
.count();
beneficiaryWidgetResponseBean.setNumberOfCalls(activeCallsCount);
}
Long activeApplication = applicationRepository.countSubmittedApplicationsByUserId(userEntity.getId(), Long activeApplication = applicationRepository.countSubmittedApplicationsByUserId(userEntity.getId(),
userWithCompanyEntity.getId()); userWithCompanyEntity.getId());
if (activeApplication != null) { if (activeApplication != null) {

View File

@@ -47,4 +47,6 @@ public interface CallRepository extends JpaRepository<CallEntity, Long> {
BigDecimal findTotalAmountOfPublishedCallsAndHubId(@Param("hubId") Long hubId); BigDecimal findTotalAmountOfPublishedCallsAndHubId(@Param("hubId") Long hubId);
@Query("SELECT c FROM CallEntity c WHERE c.id IN :ids AND c.status IN :status") @Query("SELECT c FROM CallEntity c WHERE c.id IN :ids AND c.status IN :status")
List<CallEntity> findByIdInAndStatusIn(@Param("ids") List<Long> ids, @Param("status") List<String> status); List<CallEntity> findByIdInAndStatusIn(@Param("ids") List<Long> ids, @Param("status") List<String> status);
List<CallEntity> findByIdIn(@Param("ids") List<Long> ids);
} }